Fix the handling for weak binds

Obviously, seen_weak_bind_iter may be invalidated while relocation...
This commit is contained in:
Shinichiro Hamaji 2011-11-13 18:05:38 +09:00
parent 45906e0f9d
commit 545c157d2b

View File

@ -498,9 +498,7 @@ class MachOLoader {
void doBind(const MachO& mach, intptr slide) { void doBind(const MachO& mach, intptr slide) {
string last_weak_name = ""; string last_weak_name = "";
char* last_weak_sym = NULL; char* last_weak_sym = NULL;
vector<pair<string, char*> >::iterator size_t seen_weak_bind_index = 0;
seen_weak_bind_iter = seen_weak_binds_.begin(),
seen_weak_bind_end = seen_weak_binds_.end();
size_t seen_weak_binds_orig_size = seen_weak_binds_.size(); size_t seen_weak_binds_orig_size = seen_weak_binds_.size();
unsigned int common_code_size = (unsigned int)trampoline_.size(); unsigned int common_code_size = (unsigned int)trampoline_.size();
@ -526,17 +524,20 @@ class MachOLoader {
sym = last_weak_sym; sym = last_weak_sym;
} else { } else {
last_weak_name = name; last_weak_name = name;
if (seen_weak_bind_iter != seen_weak_bind_end && if (seen_weak_bind_index != seen_weak_binds_orig_size &&
!strcmp(seen_weak_bind_iter->first.c_str(), name.c_str())) { !strcmp(seen_weak_binds_[seen_weak_bind_index].first.c_str(),
last_weak_sym = sym = seen_weak_bind_iter->second; name.c_str())) {
seen_weak_bind_iter++; last_weak_sym = sym =
seen_weak_binds_[seen_weak_bind_index].second;
seen_weak_bind_index++;
} else { } else {
last_weak_sym = (char*)*ptr; last_weak_sym = (char*)*ptr;
seen_weak_binds_.push_back(make_pair(name, last_weak_sym)); seen_weak_binds_.push_back(make_pair(name, last_weak_sym));
while (seen_weak_bind_iter != seen_weak_bind_end && while (seen_weak_bind_index != seen_weak_binds_orig_size &&
strcmp(seen_weak_bind_iter->first.c_str(), strcmp(
seen_weak_binds_[seen_weak_bind_index].first.c_str(),
name.c_str()) <= 0) { name.c_str()) <= 0) {
seen_weak_bind_iter++; seen_weak_bind_index++;
} }
continue; continue;
} }