am 00dce525: Revert "Fix relocation to look for symbols in local group"
				
					
				
			* commit '00dce525530c5d26c20750863f3e9890b468787a': Revert "Fix relocation to look for symbols in local group"
This commit is contained in:
		@@ -86,7 +86,7 @@ class LinkedList {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  template<typename F>
 | 
					  template<typename F>
 | 
				
			||||||
  void for_each(F action) const {
 | 
					  void for_each(F action) {
 | 
				
			||||||
    visit([&] (T* si) {
 | 
					    visit([&] (T* si) {
 | 
				
			||||||
      action(si);
 | 
					      action(si);
 | 
				
			||||||
      return true;
 | 
					      return true;
 | 
				
			||||||
@@ -94,7 +94,7 @@ class LinkedList {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  template<typename F>
 | 
					  template<typename F>
 | 
				
			||||||
  bool visit(F action) const {
 | 
					  bool visit(F action) {
 | 
				
			||||||
    for (LinkedListEntry<T>* e = head_; e != nullptr; e = e->next) {
 | 
					    for (LinkedListEntry<T>* e = head_; e != nullptr; e = e->next) {
 | 
				
			||||||
      if (!action(e->element)) {
 | 
					      if (!action(e->element)) {
 | 
				
			||||||
        return false;
 | 
					        return false;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -415,7 +415,7 @@ int dl_iterate_phdr(int (*cb)(dl_phdr_info* info, size_t size, void* data), void
 | 
				
			|||||||
  return rv;
 | 
					  return rv;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static ElfW(Sym)* soinfo_elf_lookup(const soinfo* si, unsigned hash, const char* name) {
 | 
					static ElfW(Sym)* soinfo_elf_lookup(soinfo* si, unsigned hash, const char* name) {
 | 
				
			||||||
  ElfW(Sym)* symtab = si->symtab;
 | 
					  ElfW(Sym)* symtab = si->symtab;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  TRACE_TYPE(LOOKUP, "SEARCH %s in %s@%p %x %zd",
 | 
					  TRACE_TYPE(LOOKUP, "SEARCH %s in %s@%p %x %zd",
 | 
				
			||||||
@@ -481,7 +481,7 @@ static unsigned elfhash(const char* _name) {
 | 
				
			|||||||
  return h;
 | 
					  return h;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static ElfW(Sym)* soinfo_do_lookup(soinfo* si, const char* name, soinfo** lsi, const soinfo::soinfo_list_t& local_group) {
 | 
					static ElfW(Sym)* soinfo_do_lookup(soinfo* si, const char* name, soinfo** lsi) {
 | 
				
			||||||
  unsigned elf_hash = elfhash(name);
 | 
					  unsigned elf_hash = elfhash(name);
 | 
				
			||||||
  ElfW(Sym)* s = nullptr;
 | 
					  ElfW(Sym)* s = nullptr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -527,21 +527,16 @@ static ElfW(Sym)* soinfo_do_lookup(soinfo* si, const char* name, soinfo** lsi, c
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // 3. Look for it in the local group
 | 
					  /* Look for symbols in the local scope (the object who is
 | 
				
			||||||
  if (s == nullptr) {
 | 
					   * searching). This happens with C++ templates on x86 for some
 | 
				
			||||||
    local_group.visit([&](soinfo* local_si) {
 | 
					   * reason.
 | 
				
			||||||
      DEBUG("%s: looking up %s in %s (from local group)", si->name, name, local_si->name);
 | 
					   *
 | 
				
			||||||
      s = soinfo_elf_lookup(local_si, elf_hash, name);
 | 
					   * Notes on weak symbols:
 | 
				
			||||||
      if (s != nullptr) {
 | 
					   * The ELF specs are ambiguous about treatment of weak definitions in
 | 
				
			||||||
        *lsi = local_si;
 | 
					   * dynamic linking.  Some systems return the first definition found
 | 
				
			||||||
        return false;
 | 
					   * and some the first non-weak definition.   This is system dependent.
 | 
				
			||||||
      }
 | 
					   * Here we return the first definition found for simplicity.  */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      return true;
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // 4. Look for it in this library (unless we already did it because of DT_SYMBOLIC)
 | 
					 | 
				
			||||||
  if (s == nullptr && !si->has_DT_SYMBOLIC) {
 | 
					  if (s == nullptr && !si->has_DT_SYMBOLIC) {
 | 
				
			||||||
    DEBUG("%s: looking up %s in local scope", si->name, name);
 | 
					    DEBUG("%s: looking up %s in local scope", si->name, name);
 | 
				
			||||||
    s = soinfo_elf_lookup(si, elf_hash, name);
 | 
					    s = soinfo_elf_lookup(si, elf_hash, name);
 | 
				
			||||||
@@ -550,7 +545,6 @@ static ElfW(Sym)* soinfo_do_lookup(soinfo* si, const char* name, soinfo** lsi, c
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // 5. Dependencies
 | 
					 | 
				
			||||||
  if (s == nullptr) {
 | 
					  if (s == nullptr) {
 | 
				
			||||||
    si->get_children().visit([&](soinfo* child) {
 | 
					    si->get_children().visit([&](soinfo* child) {
 | 
				
			||||||
      DEBUG("%s: looking up %s in %s", si->name, name, child->name);
 | 
					      DEBUG("%s: looking up %s in %s", si->name, name, child->name);
 | 
				
			||||||
@@ -649,61 +643,33 @@ typedef linked_list_t<const char> StringLinkedList;
 | 
				
			|||||||
typedef linked_list_t<LoadTask> LoadTaskList;
 | 
					typedef linked_list_t<LoadTask> LoadTaskList;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// This function walks down the tree of soinfo dependencies
 | 
					// This is used by dlsym(3).  It performs symbol lookup only within the
 | 
				
			||||||
// in breadth-first order and
 | 
					// specified soinfo object and its dependencies in breadth first order.
 | 
				
			||||||
//   * calls action(soinfo* si) for each node, and
 | 
					ElfW(Sym)* dlsym_handle_lookup(soinfo* si, soinfo** found, const char* name) {
 | 
				
			||||||
//   * terminates walk if action returns false.
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
// walk_dependencies_tree returns false if walk was terminated
 | 
					 | 
				
			||||||
// by the action and true otherwise.
 | 
					 | 
				
			||||||
template<typename F>
 | 
					 | 
				
			||||||
static bool walk_dependencies_tree(soinfo* root_soinfos[], size_t root_soinfos_size, F action) {
 | 
					 | 
				
			||||||
  SoinfoLinkedList visit_list;
 | 
					  SoinfoLinkedList visit_list;
 | 
				
			||||||
  SoinfoLinkedList visited;
 | 
					  SoinfoLinkedList visited;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  for (size_t i = 0; i < root_soinfos_size; ++i) {
 | 
					  visit_list.push_back(si);
 | 
				
			||||||
    visit_list.push_back(root_soinfos[i]);
 | 
					  soinfo* current_soinfo;
 | 
				
			||||||
  }
 | 
					  while ((current_soinfo = visit_list.pop_front()) != nullptr) {
 | 
				
			||||||
 | 
					    if (visited.contains(current_soinfo)) {
 | 
				
			||||||
  soinfo* si;
 | 
					 | 
				
			||||||
  while ((si = visit_list.pop_front()) != nullptr) {
 | 
					 | 
				
			||||||
    if (visited.contains(si)) {
 | 
					 | 
				
			||||||
      continue;
 | 
					      continue;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!action(si)) {
 | 
					    ElfW(Sym)* result = soinfo_elf_lookup(current_soinfo, elfhash(name), name);
 | 
				
			||||||
      return false;
 | 
					
 | 
				
			||||||
 | 
					    if (result != nullptr) {
 | 
				
			||||||
 | 
					      *found = current_soinfo;
 | 
				
			||||||
 | 
					      return result;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    visited.push_back(current_soinfo);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    visited.push_back(si);
 | 
					    current_soinfo->get_children().for_each([&](soinfo* child) {
 | 
				
			||||||
 | 
					 | 
				
			||||||
    si->get_children().for_each([&](soinfo* child) {
 | 
					 | 
				
			||||||
      visit_list.push_back(child);
 | 
					      visit_list.push_back(child);
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return true;
 | 
					  return nullptr;
 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// This is used by dlsym(3).  It performs symbol lookup only within the
 | 
					 | 
				
			||||||
// specified soinfo object and its dependencies in breadth first order.
 | 
					 | 
				
			||||||
ElfW(Sym)* dlsym_handle_lookup(soinfo* si, soinfo** found, const char* name) {
 | 
					 | 
				
			||||||
  ElfW(Sym)* result = nullptr;
 | 
					 | 
				
			||||||
  uint32_t elf_hash = elfhash(name);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  walk_dependencies_tree(&si, 1, [&](soinfo* current_soinfo) {
 | 
					 | 
				
			||||||
    result = soinfo_elf_lookup(current_soinfo, elf_hash, name);
 | 
					 | 
				
			||||||
    if (result != nullptr) {
 | 
					 | 
				
			||||||
      *found = current_soinfo;
 | 
					 | 
				
			||||||
      return false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    return true;
 | 
					 | 
				
			||||||
  });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  return result;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* This is used by dlsym(3) to performs a global symbol lookup. If the
 | 
					/* This is used by dlsym(3) to performs a global symbol lookup. If the
 | 
				
			||||||
@@ -933,30 +899,19 @@ static bool is_recursive(soinfo* si, soinfo* parent) {
 | 
				
			|||||||
  });
 | 
					  });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static bool find_libraries(soinfo* start_with, const char* const library_names[], size_t library_names_count, soinfo* soinfos[],
 | 
					static bool find_libraries(const char* const library_names[], size_t library_names_size, soinfo* soinfos[],
 | 
				
			||||||
    soinfo* ld_preloads[], size_t ld_preloads_count, int rtld_flags, const android_dlextinfo* extinfo) {
 | 
					    soinfo* ld_preloads[], size_t ld_preloads_size, int rtld_flags, const android_dlextinfo* extinfo) {
 | 
				
			||||||
  // Step 0: prepare.
 | 
					  // Step 0: prepare.
 | 
				
			||||||
  LoadTaskList load_tasks;
 | 
					  LoadTaskList load_tasks;
 | 
				
			||||||
  for (size_t i = 0; i < library_names_count; ++i) {
 | 
					  for (size_t i = 0; i < library_names_size; ++i) {
 | 
				
			||||||
    const char* name = library_names[i];
 | 
					    const char* name = library_names[i];
 | 
				
			||||||
    load_tasks.push_back(LoadTask::create(name, start_with));
 | 
					    load_tasks.push_back(LoadTask::create(name, nullptr));
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // If soinfos array is null allocate one on stack.
 | 
					  // Libraries added to this list in reverse order so that we can
 | 
				
			||||||
  // The array is needed in case of failure; for example
 | 
					  // start linking from bottom-up - see step 2.
 | 
				
			||||||
  // when library_names[] = {libone.so, libtwo.so} and libone.so
 | 
					  SoinfoLinkedList found_libs;
 | 
				
			||||||
  // is loaded correctly but libtwo.so failed for some reason.
 | 
					  size_t soinfos_size = 0;
 | 
				
			||||||
  // In this case libone.so should be unloaded on return.
 | 
					 | 
				
			||||||
  // See also implementation of failure_guard below.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if (soinfos == nullptr) {
 | 
					 | 
				
			||||||
    size_t soinfos_size = sizeof(soinfo*)*library_names_count;
 | 
					 | 
				
			||||||
    soinfos = reinterpret_cast<soinfo**>(alloca(soinfos_size));
 | 
					 | 
				
			||||||
    memset(soinfos, 0, soinfos_size);
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // list of libraries to link - see step 2.
 | 
					 | 
				
			||||||
  size_t soinfos_count = 0;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  auto failure_guard = make_scope_guard([&]() {
 | 
					  auto failure_guard = make_scope_guard([&]() {
 | 
				
			||||||
    // Housekeeping
 | 
					    // Housekeeping
 | 
				
			||||||
@@ -964,7 +919,7 @@ static bool find_libraries(soinfo* start_with, const char* const library_names[]
 | 
				
			|||||||
      LoadTask::deleter(t);
 | 
					      LoadTask::deleter(t);
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (size_t i = 0; i<soinfos_count; ++i) {
 | 
					    for (size_t i = 0; i<soinfos_size; ++i) {
 | 
				
			||||||
      soinfo_unload(soinfos[i]);
 | 
					      soinfo_unload(soinfos[i]);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
@@ -986,44 +941,34 @@ static bool find_libraries(soinfo* start_with, const char* const library_names[]
 | 
				
			|||||||
    if (needed_by != nullptr) {
 | 
					    if (needed_by != nullptr) {
 | 
				
			||||||
      needed_by->add_child(si);
 | 
					      needed_by->add_child(si);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    found_libs.push_front(si);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // When ld_preloads is not null, the first
 | 
					    // When ld_preloads is not null first
 | 
				
			||||||
    // ld_preloads_count libs are in fact ld_preloads.
 | 
					    // ld_preloads_size libs are in fact ld_preloads.
 | 
				
			||||||
    if (ld_preloads != nullptr && soinfos_count < ld_preloads_count) {
 | 
					    if (ld_preloads != nullptr && soinfos_size < ld_preloads_size) {
 | 
				
			||||||
      ld_preloads[soinfos_count] = si;
 | 
					      ld_preloads[soinfos_size] = si;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (soinfos_count < library_names_count) {
 | 
					    if (soinfos_size<library_names_size) {
 | 
				
			||||||
      soinfos[soinfos_count++] = si;
 | 
					      soinfos[soinfos_size++] = si;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Step 2: link libraries.
 | 
					  // Step 2: link libraries.
 | 
				
			||||||
  soinfo::soinfo_list_t local_group;
 | 
					  soinfo* si;
 | 
				
			||||||
  walk_dependencies_tree(
 | 
					  while ((si = found_libs.pop_front()) != nullptr) {
 | 
				
			||||||
      start_with == nullptr ? soinfos : &start_with,
 | 
					 | 
				
			||||||
      start_with == nullptr ? soinfos_count : 1,
 | 
					 | 
				
			||||||
      [&] (soinfo* si) {
 | 
					 | 
				
			||||||
    local_group.push_back(si);
 | 
					 | 
				
			||||||
    return true;
 | 
					 | 
				
			||||||
  });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  bool linked = local_group.visit([&](soinfo* si) {
 | 
					 | 
				
			||||||
    if ((si->flags & FLAG_LINKED) == 0) {
 | 
					    if ((si->flags & FLAG_LINKED) == 0) {
 | 
				
			||||||
      if (!si->LinkImage(local_group, extinfo)) {
 | 
					      if (!si->LinkImage(extinfo)) {
 | 
				
			||||||
        return false;
 | 
					        return false;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      si->flags |= FLAG_LINKED;
 | 
					      si->flags |= FLAG_LINKED;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					 | 
				
			||||||
    return true;
 | 
					 | 
				
			||||||
  });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if (linked) {
 | 
					 | 
				
			||||||
    failure_guard.disable();
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return linked;
 | 
					  // All is well - found_libs and load_tasks are empty at this point
 | 
				
			||||||
 | 
					  // and all libs are successfully linked.
 | 
				
			||||||
 | 
					  failure_guard.disable();
 | 
				
			||||||
 | 
					  return true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static soinfo* find_library(const char* name, int rtld_flags, const android_dlextinfo* extinfo) {
 | 
					static soinfo* find_library(const char* name, int rtld_flags, const android_dlextinfo* extinfo) {
 | 
				
			||||||
@@ -1034,7 +979,7 @@ static soinfo* find_library(const char* name, int rtld_flags, const android_dlex
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  soinfo* si;
 | 
					  soinfo* si;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!find_libraries(nullptr, &name, 1, &si, nullptr, 0, rtld_flags, extinfo)) {
 | 
					  if (!find_libraries(&name, 1, &si, nullptr, 0, rtld_flags, extinfo)) {
 | 
				
			||||||
    return nullptr;
 | 
					    return nullptr;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1145,7 +1090,7 @@ static ElfW(Addr) call_ifunc_resolver(ElfW(Addr) resolver_addr) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(USE_RELA)
 | 
					#if defined(USE_RELA)
 | 
				
			||||||
int soinfo::Relocate(ElfW(Rela)* rela, unsigned count, const soinfo_list_t& local_group) {
 | 
					int soinfo::Relocate(ElfW(Rela)* rela, unsigned count) {
 | 
				
			||||||
  for (size_t idx = 0; idx < count; ++idx, ++rela) {
 | 
					  for (size_t idx = 0; idx < count; ++idx, ++rela) {
 | 
				
			||||||
    unsigned type = ELFW(R_TYPE)(rela->r_info);
 | 
					    unsigned type = ELFW(R_TYPE)(rela->r_info);
 | 
				
			||||||
    unsigned sym = ELFW(R_SYM)(rela->r_info);
 | 
					    unsigned sym = ELFW(R_SYM)(rela->r_info);
 | 
				
			||||||
@@ -1163,7 +1108,7 @@ int soinfo::Relocate(ElfW(Rela)* rela, unsigned count, const soinfo_list_t& loca
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    if (sym != 0) {
 | 
					    if (sym != 0) {
 | 
				
			||||||
      sym_name = get_string(symtab[sym].st_name);
 | 
					      sym_name = get_string(symtab[sym].st_name);
 | 
				
			||||||
      s = soinfo_do_lookup(this, sym_name, &lsi, local_group);
 | 
					      s = soinfo_do_lookup(this, sym_name, &lsi);
 | 
				
			||||||
      if (s == nullptr) {
 | 
					      if (s == nullptr) {
 | 
				
			||||||
        // We only allow an undefined symbol if this is a weak reference...
 | 
					        // We only allow an undefined symbol if this is a weak reference...
 | 
				
			||||||
        s = &symtab[sym];
 | 
					        s = &symtab[sym];
 | 
				
			||||||
@@ -1422,7 +1367,7 @@ int soinfo::Relocate(ElfW(Rela)* rela, unsigned count, const soinfo_list_t& loca
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#else // REL, not RELA.
 | 
					#else // REL, not RELA.
 | 
				
			||||||
int soinfo::Relocate(ElfW(Rel)* rel, unsigned count, const soinfo_list_t& local_group) {
 | 
					int soinfo::Relocate(ElfW(Rel)* rel, unsigned count) {
 | 
				
			||||||
  for (size_t idx = 0; idx < count; ++idx, ++rel) {
 | 
					  for (size_t idx = 0; idx < count; ++idx, ++rel) {
 | 
				
			||||||
    unsigned type = ELFW(R_TYPE)(rel->r_info);
 | 
					    unsigned type = ELFW(R_TYPE)(rel->r_info);
 | 
				
			||||||
    // TODO: don't use unsigned for 'sym'. Use uint32_t or ElfW(Addr) instead.
 | 
					    // TODO: don't use unsigned for 'sym'. Use uint32_t or ElfW(Addr) instead.
 | 
				
			||||||
@@ -1441,7 +1386,7 @@ int soinfo::Relocate(ElfW(Rel)* rel, unsigned count, const soinfo_list_t& local_
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    if (sym != 0) {
 | 
					    if (sym != 0) {
 | 
				
			||||||
      sym_name = get_string(symtab[sym].st_name);
 | 
					      sym_name = get_string(symtab[sym].st_name);
 | 
				
			||||||
      s = soinfo_do_lookup(this, sym_name, &lsi, local_group);
 | 
					      s = soinfo_do_lookup(this, sym_name, &lsi);
 | 
				
			||||||
      if (s == nullptr) {
 | 
					      if (s == nullptr) {
 | 
				
			||||||
        // We only allow an undefined symbol if this is a weak reference...
 | 
					        // We only allow an undefined symbol if this is a weak reference...
 | 
				
			||||||
        s = &symtab[sym];
 | 
					        s = &symtab[sym];
 | 
				
			||||||
@@ -1627,7 +1572,7 @@ int soinfo::Relocate(ElfW(Rel)* rel, unsigned count, const soinfo_list_t& local_
 | 
				
			|||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(__mips__)
 | 
					#if defined(__mips__)
 | 
				
			||||||
static bool mips_relocate_got(soinfo* si, const soinfo::soinfo_list_t& local_group) {
 | 
					static bool mips_relocate_got(soinfo* si) {
 | 
				
			||||||
  ElfW(Addr)** got = si->plt_got;
 | 
					  ElfW(Addr)** got = si->plt_got;
 | 
				
			||||||
  if (got == nullptr) {
 | 
					  if (got == nullptr) {
 | 
				
			||||||
    return true;
 | 
					    return true;
 | 
				
			||||||
@@ -1660,7 +1605,7 @@ static bool mips_relocate_got(soinfo* si, const soinfo::soinfo_list_t& local_gro
 | 
				
			|||||||
    // This is an undefined reference... try to locate it.
 | 
					    // This is an undefined reference... try to locate it.
 | 
				
			||||||
    const char* sym_name = si->get_string(sym->st_name);
 | 
					    const char* sym_name = si->get_string(sym->st_name);
 | 
				
			||||||
    soinfo* lsi = nullptr;
 | 
					    soinfo* lsi = nullptr;
 | 
				
			||||||
    ElfW(Sym)* s = soinfo_do_lookup(si, sym_name, &lsi, local_group);
 | 
					    ElfW(Sym)* s = soinfo_do_lookup(si, sym_name, &lsi);
 | 
				
			||||||
    if (s == nullptr) {
 | 
					    if (s == nullptr) {
 | 
				
			||||||
      // We only allow an undefined symbol if this is a weak reference.
 | 
					      // We only allow an undefined symbol if this is a weak reference.
 | 
				
			||||||
      s = &symtab[g];
 | 
					      s = &symtab[g];
 | 
				
			||||||
@@ -2253,7 +2198,7 @@ bool soinfo::PrelinkImage() {
 | 
				
			|||||||
  return true;
 | 
					  return true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool soinfo::LinkImage(const soinfo_list_t& local_group, const android_dlextinfo* extinfo) {
 | 
					bool soinfo::LinkImage(const android_dlextinfo* extinfo) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if !defined(__LP64__)
 | 
					#if !defined(__LP64__)
 | 
				
			||||||
  if (has_text_relocations) {
 | 
					  if (has_text_relocations) {
 | 
				
			||||||
@@ -2272,26 +2217,26 @@ bool soinfo::LinkImage(const soinfo_list_t& local_group, const android_dlextinfo
 | 
				
			|||||||
#if defined(USE_RELA)
 | 
					#if defined(USE_RELA)
 | 
				
			||||||
  if (rela != nullptr) {
 | 
					  if (rela != nullptr) {
 | 
				
			||||||
    DEBUG("[ relocating %s ]", name);
 | 
					    DEBUG("[ relocating %s ]", name);
 | 
				
			||||||
    if (Relocate(rela, rela_count, local_group)) {
 | 
					    if (Relocate(rela, rela_count)) {
 | 
				
			||||||
      return false;
 | 
					      return false;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  if (plt_rela != nullptr) {
 | 
					  if (plt_rela != nullptr) {
 | 
				
			||||||
    DEBUG("[ relocating %s plt ]", name);
 | 
					    DEBUG("[ relocating %s plt ]", name);
 | 
				
			||||||
    if (Relocate(plt_rela, plt_rela_count, local_group)) {
 | 
					    if (Relocate(plt_rela, plt_rela_count)) {
 | 
				
			||||||
      return false;
 | 
					      return false;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
  if (rel != nullptr) {
 | 
					  if (rel != nullptr) {
 | 
				
			||||||
    DEBUG("[ relocating %s ]", name);
 | 
					    DEBUG("[ relocating %s ]", name);
 | 
				
			||||||
    if (Relocate(rel, rel_count, local_group)) {
 | 
					    if (Relocate(rel, rel_count)) {
 | 
				
			||||||
      return false;
 | 
					      return false;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  if (plt_rel != nullptr) {
 | 
					  if (plt_rel != nullptr) {
 | 
				
			||||||
    DEBUG("[ relocating %s plt ]", name);
 | 
					    DEBUG("[ relocating %s plt ]", name);
 | 
				
			||||||
    if (Relocate(plt_rel, plt_rel_count, local_group)) {
 | 
					    if (Relocate(plt_rel, plt_rel_count)) {
 | 
				
			||||||
      return false;
 | 
					      return false;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@@ -2365,7 +2310,7 @@ static void add_vdso(KernelArgumentBlock& args __unused) {
 | 
				
			|||||||
  si->load_bias = get_elf_exec_load_bias(ehdr_vdso);
 | 
					  si->load_bias = get_elf_exec_load_bias(ehdr_vdso);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  si->PrelinkImage();
 | 
					  si->PrelinkImage();
 | 
				
			||||||
  si->LinkImage(g_empty_list, nullptr);
 | 
					  si->LinkImage(nullptr);
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -2511,11 +2456,21 @@ static ElfW(Addr) __linker_init_post_relocation(KernelArgumentBlock& args, ElfW(
 | 
				
			|||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const char* needed_library_names[needed_libraries_count];
 | 
					  const char* needed_library_names[needed_libraries_count];
 | 
				
			||||||
 | 
					  soinfo* needed_library_si[needed_libraries_count];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  memset(needed_library_names, 0, sizeof(needed_library_names));
 | 
					  memset(needed_library_names, 0, sizeof(needed_library_names));
 | 
				
			||||||
  needed_library_name_list.copy_to_array(needed_library_names, needed_libraries_count);
 | 
					  needed_library_name_list.copy_to_array(needed_library_names, needed_libraries_count);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (needed_libraries_count > 0 && !find_libraries(si, needed_library_names, needed_libraries_count, nullptr, g_ld_preloads, ld_preloads_count, RTLD_GLOBAL, nullptr)) {
 | 
					  if (needed_libraries_count > 0 && !find_libraries(needed_library_names, needed_libraries_count, needed_library_si, g_ld_preloads, ld_preloads_count, RTLD_GLOBAL, nullptr)) {
 | 
				
			||||||
 | 
					    __libc_format_fd(2, "CANNOT LINK EXECUTABLE DEPENDENCIES: %s\n", linker_get_error_buffer());
 | 
				
			||||||
 | 
					    exit(EXIT_FAILURE);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  for (size_t i = 0; i<needed_libraries_count; ++i) {
 | 
				
			||||||
 | 
					    si->add_child(needed_library_si[i]);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (!si->LinkImage(nullptr)) {
 | 
				
			||||||
    __libc_format_fd(2, "CANNOT LINK EXECUTABLE: %s\n", linker_get_error_buffer());
 | 
					    __libc_format_fd(2, "CANNOT LINK EXECUTABLE: %s\n", linker_get_error_buffer());
 | 
				
			||||||
    exit(EXIT_FAILURE);
 | 
					    exit(EXIT_FAILURE);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@@ -2639,7 +2594,7 @@ extern "C" ElfW(Addr) __linker_init(void* raw_args) {
 | 
				
			|||||||
  linker_so.phnum = elf_hdr->e_phnum;
 | 
					  linker_so.phnum = elf_hdr->e_phnum;
 | 
				
			||||||
  linker_so.flags |= FLAG_LINKER;
 | 
					  linker_so.flags |= FLAG_LINKER;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!(linker_so.PrelinkImage() && linker_so.LinkImage(g_empty_list, nullptr))) {
 | 
					  if (!(linker_so.PrelinkImage() && linker_so.LinkImage(nullptr))) {
 | 
				
			||||||
    // It would be nice to print an error message, but if the linker
 | 
					    // It would be nice to print an error message, but if the linker
 | 
				
			||||||
    // can't link itself, there's no guarantee that we'll be able to
 | 
					    // can't link itself, there's no guarantee that we'll be able to
 | 
				
			||||||
    // call write() (because it involves a GOT reference). We may as
 | 
					    // call write() (because it involves a GOT reference). We may as
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -207,7 +207,7 @@ struct soinfo {
 | 
				
			|||||||
  void CallDestructors();
 | 
					  void CallDestructors();
 | 
				
			||||||
  void CallPreInitConstructors();
 | 
					  void CallPreInitConstructors();
 | 
				
			||||||
  bool PrelinkImage();
 | 
					  bool PrelinkImage();
 | 
				
			||||||
  bool LinkImage(const soinfo_list_t& local_group, const android_dlextinfo* extinfo);
 | 
					  bool LinkImage(const android_dlextinfo* extinfo);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void add_child(soinfo* child);
 | 
					  void add_child(soinfo* child);
 | 
				
			||||||
  void remove_all_links();
 | 
					  void remove_all_links();
 | 
				
			||||||
@@ -234,9 +234,9 @@ struct soinfo {
 | 
				
			|||||||
  void CallArray(const char* array_name, linker_function_t* functions, size_t count, bool reverse);
 | 
					  void CallArray(const char* array_name, linker_function_t* functions, size_t count, bool reverse);
 | 
				
			||||||
  void CallFunction(const char* function_name, linker_function_t function);
 | 
					  void CallFunction(const char* function_name, linker_function_t function);
 | 
				
			||||||
#if defined(USE_RELA)
 | 
					#if defined(USE_RELA)
 | 
				
			||||||
  int Relocate(ElfW(Rela)* rela, unsigned count, const soinfo_list_t& local_group);
 | 
					  int Relocate(ElfW(Rela)* rela, unsigned count);
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
  int Relocate(ElfW(Rel)* rel, unsigned count, const soinfo_list_t& local_group);
 | 
					  int Relocate(ElfW(Rel)* rel, unsigned count);
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 private:
 | 
					 private:
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -162,39 +162,39 @@ TEST(dlfcn, dlopen_check_relocation_dt_needed_order) {
 | 
				
			|||||||
  ASSERT_EQ(1, fn());
 | 
					  ASSERT_EQ(1, fn());
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
TEST(dlfcn, dlopen_check_order_dlsym) {
 | 
					TEST(dlfcn, dlopen_check_order) {
 | 
				
			||||||
  // Here is how the test library and its dt_needed
 | 
					  // Here is how the test library and its dt_needed
 | 
				
			||||||
  // libraries are arranged
 | 
					  // libraries are arranged
 | 
				
			||||||
  //
 | 
					  //
 | 
				
			||||||
  //  libtest_check_order_children.so
 | 
					  //  libtest_check_order.so
 | 
				
			||||||
  //  |
 | 
					  //  |
 | 
				
			||||||
  //  +-> ..._1_left.so
 | 
					  //  +-> libtest_check_order_1_left.so
 | 
				
			||||||
  //  |   |
 | 
					  //  |   |
 | 
				
			||||||
  //  |   +-> ..._a.so
 | 
					  //  |   +-> libtest_check_order_a.so
 | 
				
			||||||
  //  |   |
 | 
					  //  |   |
 | 
				
			||||||
  //  |   +-> ...r_b.so
 | 
					  //  |   +-> libtest_check_order_b.so
 | 
				
			||||||
  //  |
 | 
					  //  |
 | 
				
			||||||
  //  +-> ..._2_right.so
 | 
					  //  +-> libtest_check_order_2_right.so
 | 
				
			||||||
  //  |   |
 | 
					  //  |   |
 | 
				
			||||||
  //  |   +-> ..._d.so
 | 
					  //  |   +-> libtest_check_order_d.so
 | 
				
			||||||
  //  |       |
 | 
					  //  |       |
 | 
				
			||||||
  //  |       +-> ..._b.so
 | 
					  //  |       +-> libtest_check_order_b.so
 | 
				
			||||||
  //  |
 | 
					  //  |
 | 
				
			||||||
  //  +-> ..._3_c.so
 | 
					  //  +-> libtest_check_order_3_c.so
 | 
				
			||||||
  //
 | 
					  //
 | 
				
			||||||
  //  load order should be (1, 2, 3, a, b, d)
 | 
					  //  load order should be (1, 2, 3, a, b, d)
 | 
				
			||||||
  //
 | 
					  //
 | 
				
			||||||
  // get_answer() is defined in (2, 3, a, b, c)
 | 
					  // get_answer() is defined in (2, 3, a, b, c)
 | 
				
			||||||
  // get_answer2() is defined in (b, d)
 | 
					  // get_answer2() is defined in (b, d)
 | 
				
			||||||
  void* sym = dlsym(RTLD_DEFAULT, "check_order_dlsym_get_answer");
 | 
					  void* sym = dlsym(RTLD_DEFAULT, "dlopen_test_get_answer");
 | 
				
			||||||
  ASSERT_TRUE(sym == nullptr);
 | 
					  ASSERT_TRUE(sym == nullptr);
 | 
				
			||||||
  void* handle = dlopen("libtest_check_order_dlsym.so", RTLD_NOW | RTLD_GLOBAL);
 | 
					  void* handle = dlopen("libtest_check_order.so", RTLD_NOW | RTLD_GLOBAL);
 | 
				
			||||||
  ASSERT_TRUE(handle != nullptr) << dlerror();
 | 
					  ASSERT_TRUE(handle != nullptr);
 | 
				
			||||||
  typedef int (*fn_t) (void);
 | 
					  typedef int (*fn_t) (void);
 | 
				
			||||||
  fn_t fn, fn2;
 | 
					  fn_t fn, fn2;
 | 
				
			||||||
  fn = reinterpret_cast<fn_t>(dlsym(RTLD_DEFAULT, "check_order_dlsym_get_answer"));
 | 
					  fn = reinterpret_cast<fn_t>(dlsym(RTLD_DEFAULT, "dlopen_test_get_answer"));
 | 
				
			||||||
  ASSERT_TRUE(fn != NULL) << dlerror();
 | 
					  ASSERT_TRUE(fn != NULL) << dlerror();
 | 
				
			||||||
  fn2 = reinterpret_cast<fn_t>(dlsym(RTLD_DEFAULT, "check_order_dlsym_get_answer2"));
 | 
					  fn2 = reinterpret_cast<fn_t>(dlsym(RTLD_DEFAULT, "dlopen_test_get_answer2"));
 | 
				
			||||||
  ASSERT_TRUE(fn2 != NULL) << dlerror();
 | 
					  ASSERT_TRUE(fn2 != NULL) << dlerror();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  ASSERT_EQ(42, fn());
 | 
					  ASSERT_EQ(42, fn());
 | 
				
			||||||
@@ -202,163 +202,6 @@ TEST(dlfcn, dlopen_check_order_dlsym) {
 | 
				
			|||||||
  dlclose(handle);
 | 
					  dlclose(handle);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
TEST(dlfcn, dlopen_check_order_reloc_siblings) {
 | 
					 | 
				
			||||||
  // This is how this one works:
 | 
					 | 
				
			||||||
  // we lookup and call get_answer which is defined in '_2.so'
 | 
					 | 
				
			||||||
  // and in turn calls external get_answer_impl() defined in _1.so and in '_[a-f].so'
 | 
					 | 
				
			||||||
  // the correct _impl() is implemented by '_a.so';
 | 
					 | 
				
			||||||
  //
 | 
					 | 
				
			||||||
  // Note that this is test for RTLD_LOCAL (TODO: test for GLOBAL?)
 | 
					 | 
				
			||||||
  //
 | 
					 | 
				
			||||||
  // Here is the picture:
 | 
					 | 
				
			||||||
  //
 | 
					 | 
				
			||||||
  // libtest_check_order_reloc_siblings.so
 | 
					 | 
				
			||||||
  // |
 | 
					 | 
				
			||||||
  // +-> ..._1.so <- empty
 | 
					 | 
				
			||||||
  // |   |
 | 
					 | 
				
			||||||
  // |   +-> ..._a.so <- exports correct answer_impl()
 | 
					 | 
				
			||||||
  // |   |
 | 
					 | 
				
			||||||
  // |   +-> ..._b.so <- every other letter exporting incorrect one.
 | 
					 | 
				
			||||||
  // |
 | 
					 | 
				
			||||||
  // +-> ..._2.so <- empty
 | 
					 | 
				
			||||||
  // |   |
 | 
					 | 
				
			||||||
  // |   +-> ..._c.so
 | 
					 | 
				
			||||||
  // |   |
 | 
					 | 
				
			||||||
  // |   +-> ..._d.so
 | 
					 | 
				
			||||||
  // |
 | 
					 | 
				
			||||||
  // +-> ..._3.so <- empty
 | 
					 | 
				
			||||||
  //     |
 | 
					 | 
				
			||||||
  //     +-> ..._e.so
 | 
					 | 
				
			||||||
  //     |
 | 
					 | 
				
			||||||
  //     +-> ..._f.so <- exports get_answer() that calls get_anser_impl();
 | 
					 | 
				
			||||||
  //                     implements incorrect get_answer_impl()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  void* handle = dlopen("libtest_check_order_reloc_siblings.so", RTLD_NOW | RTLD_NOLOAD);
 | 
					 | 
				
			||||||
  ASSERT_TRUE(handle == nullptr);
 | 
					 | 
				
			||||||
#ifdef __BIONIC__
 | 
					 | 
				
			||||||
  // TODO: glibc returns nullptr on dlerror() here. Is it bug?
 | 
					 | 
				
			||||||
  ASSERT_STREQ("dlopen failed: library \"libtest_check_order_reloc_siblings.so\" wasn't loaded and RTLD_NOLOAD prevented it", dlerror());
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  handle = dlopen("libtest_check_order_reloc_siblings.so", RTLD_NOW | RTLD_LOCAL);
 | 
					 | 
				
			||||||
  ASSERT_TRUE(handle != nullptr) << dlerror();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  typedef int (*fn_t) (void);
 | 
					 | 
				
			||||||
  fn_t fn = reinterpret_cast<fn_t>(dlsym(handle, "check_order_reloc_get_answer"));
 | 
					 | 
				
			||||||
  ASSERT_TRUE(fn != nullptr) << dlerror();
 | 
					 | 
				
			||||||
  ASSERT_EQ(42, fn());
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  ASSERT_EQ(0, dlclose(handle));
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
TEST(dlfcn, dlopen_check_order_reloc_siblings_with_preload) {
 | 
					 | 
				
			||||||
  // This test uses the same library as dlopen_check_order_reloc_siblings.
 | 
					 | 
				
			||||||
  // Unlike dlopen_check_order_reloc_siblings it preloads
 | 
					 | 
				
			||||||
  // libtest_check_order_reloc_siblings_1.so (first dependency) prior to
 | 
					 | 
				
			||||||
  // dlopen(libtest_check_order_reloc_siblings.so)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  void* handle = dlopen("libtest_check_order_reloc_siblings.so", RTLD_NOW | RTLD_NOLOAD);
 | 
					 | 
				
			||||||
  ASSERT_TRUE(handle == nullptr);
 | 
					 | 
				
			||||||
  handle = dlopen("libtest_check_order_reloc_siblings_1.so", RTLD_NOW | RTLD_NOLOAD);
 | 
					 | 
				
			||||||
  ASSERT_TRUE(handle == nullptr);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  void* handle_for_1 = dlopen("libtest_check_order_reloc_siblings_1.so", RTLD_NOW | RTLD_LOCAL);
 | 
					 | 
				
			||||||
  ASSERT_TRUE(handle_for_1 != nullptr) << dlerror();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  handle = dlopen("libtest_check_order_reloc_siblings.so", RTLD_NOW | RTLD_LOCAL);
 | 
					 | 
				
			||||||
  ASSERT_TRUE(handle != nullptr) << dlerror();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  ASSERT_EQ(0, dlclose(handle_for_1));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  typedef int (*fn_t) (void);
 | 
					 | 
				
			||||||
  fn_t fn = reinterpret_cast<fn_t>(dlsym(handle, "check_order_reloc_get_answer"));
 | 
					 | 
				
			||||||
  ASSERT_TRUE(fn != nullptr) << dlerror();
 | 
					 | 
				
			||||||
  ASSERT_EQ(42, fn());
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  ASSERT_EQ(0, dlclose(handle));
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
TEST(dlfcn, dlopen_check_order_reloc_nephew) {
 | 
					 | 
				
			||||||
  // This is how this one works:
 | 
					 | 
				
			||||||
  // we lookup and call nephew_get_answer which is defined in '_2.so'
 | 
					 | 
				
			||||||
  // and in turn calls external get_answer_impl() defined in '_[a-f].so'
 | 
					 | 
				
			||||||
  // the correct _impl() is implemented by '_a.so';
 | 
					 | 
				
			||||||
  //
 | 
					 | 
				
			||||||
  // Here is the picture:
 | 
					 | 
				
			||||||
  //
 | 
					 | 
				
			||||||
  // libtest_check_order_reloc_siblings.so
 | 
					 | 
				
			||||||
  // |
 | 
					 | 
				
			||||||
  // +-> ..._1.so <- empty
 | 
					 | 
				
			||||||
  // |   |
 | 
					 | 
				
			||||||
  // |   +-> ..._a.so <- exports correct answer_impl()
 | 
					 | 
				
			||||||
  // |   |
 | 
					 | 
				
			||||||
  // |   +-> ..._b.so <- every other letter exporting incorrect one.
 | 
					 | 
				
			||||||
  // |
 | 
					 | 
				
			||||||
  // +-> ..._2.so <- empty
 | 
					 | 
				
			||||||
  // |   |
 | 
					 | 
				
			||||||
  // |   +-> ..._c.so
 | 
					 | 
				
			||||||
  // |   |
 | 
					 | 
				
			||||||
  // |   +-> ..._d.so
 | 
					 | 
				
			||||||
  // |
 | 
					 | 
				
			||||||
  // +-> ..._3.so <- nephew_get_answer() that calls get_answer_impl();
 | 
					 | 
				
			||||||
  //     |
 | 
					 | 
				
			||||||
  //     +-> ..._e.so
 | 
					 | 
				
			||||||
  //     |
 | 
					 | 
				
			||||||
  //     +-> ..._f.so
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  void* handle = dlopen("libtest_check_order_reloc_siblings.so", RTLD_NOW | RTLD_NOLOAD);
 | 
					 | 
				
			||||||
  ASSERT_TRUE(handle == nullptr);
 | 
					 | 
				
			||||||
#ifdef __BIONIC__
 | 
					 | 
				
			||||||
  // TODO: glibc returns nullptr on dlerror() here. Is it bug?
 | 
					 | 
				
			||||||
  ASSERT_STREQ("dlopen failed: library \"libtest_check_order_reloc_siblings.so\" wasn't loaded and RTLD_NOLOAD prevented it", dlerror());
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  handle = dlopen("libtest_check_order_reloc_siblings.so", RTLD_NOW | RTLD_LOCAL);
 | 
					 | 
				
			||||||
  ASSERT_TRUE(handle != nullptr) << dlerror();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  typedef int (*fn_t) (void);
 | 
					 | 
				
			||||||
  fn_t fn = reinterpret_cast<fn_t>(dlsym(handle, "check_order_reloc_nephew_get_answer"));
 | 
					 | 
				
			||||||
  ASSERT_TRUE(fn != nullptr) << dlerror();
 | 
					 | 
				
			||||||
  ASSERT_EQ(42, fn());
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  ASSERT_EQ(0, dlclose(handle));
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
extern "C" int check_order_reloc_root_get_answer_impl() {
 | 
					 | 
				
			||||||
  return 42;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
TEST(dlfcn, dlopen_check_order_reloc_main_executable) {
 | 
					 | 
				
			||||||
  // This is how this one works:
 | 
					 | 
				
			||||||
  // we lookup and call get_answer3 which is defined in 'root.so'
 | 
					 | 
				
			||||||
  // and in turn calls external root_get_answer_impl() defined in _2.so and
 | 
					 | 
				
			||||||
  // above the correct _impl() is one in the executable.
 | 
					 | 
				
			||||||
  //
 | 
					 | 
				
			||||||
  // libtest_check_order_reloc_root.so
 | 
					 | 
				
			||||||
  // |
 | 
					 | 
				
			||||||
  // +-> ..._1.so <- empty
 | 
					 | 
				
			||||||
  // |
 | 
					 | 
				
			||||||
  // +-> ..._2.so <- gives incorrect answer for answer_main_impl()
 | 
					 | 
				
			||||||
  //
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  void* handle = dlopen("libtest_check_order_reloc_root.so", RTLD_NOW | RTLD_NOLOAD);
 | 
					 | 
				
			||||||
  ASSERT_TRUE(handle == nullptr);
 | 
					 | 
				
			||||||
#ifdef __BIONIC__
 | 
					 | 
				
			||||||
  // TODO: glibc returns nullptr on dlerror() here. Is it bug?
 | 
					 | 
				
			||||||
  ASSERT_STREQ("dlopen failed: library \"libtest_check_order_reloc_root.so\" wasn't loaded and RTLD_NOLOAD prevented it", dlerror());
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  handle = dlopen("libtest_check_order_reloc_root.so", RTLD_NOW | RTLD_LOCAL);
 | 
					 | 
				
			||||||
  ASSERT_TRUE(handle != nullptr) << dlerror();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  typedef int (*fn_t) (void);
 | 
					 | 
				
			||||||
  fn_t fn = reinterpret_cast<fn_t>(dlsym(handle, "check_order_reloc_root_get_answer"));
 | 
					 | 
				
			||||||
  ASSERT_TRUE(fn != nullptr) << dlerror();
 | 
					 | 
				
			||||||
  ASSERT_EQ(42, fn());
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  ASSERT_EQ(0, dlclose(handle));
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
TEST(dlfcn, dlopen_check_rtld_local) {
 | 
					TEST(dlfcn, dlopen_check_rtld_local) {
 | 
				
			||||||
  void* sym = dlsym(RTLD_DEFAULT, "dlopen_testlib_simple_func");
 | 
					  void* sym = dlsym(RTLD_DEFAULT, "dlopen_testlib_simple_func");
 | 
				
			||||||
  ASSERT_TRUE(sym == nullptr);
 | 
					  ASSERT_TRUE(sym == nullptr);
 | 
				
			||||||
@@ -499,6 +342,7 @@ TEST(dlfcn, dlopen_nodelete_dt_flags_1) {
 | 
				
			|||||||
  ASSERT_TRUE(!is_unloaded);
 | 
					  ASSERT_TRUE(!is_unloaded);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
TEST(dlfcn, dlopen_failure) {
 | 
					TEST(dlfcn, dlopen_failure) {
 | 
				
			||||||
  void* self = dlopen("/does/not/exist", RTLD_NOW);
 | 
					  void* self = dlopen("/does/not/exist", RTLD_NOW);
 | 
				
			||||||
  ASSERT_TRUE(self == NULL);
 | 
					  ASSERT_TRUE(self == NULL);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,90 +0,0 @@
 | 
				
			|||||||
#
 | 
					 | 
				
			||||||
# Copyright (C) 2012 The Android Open Source Project
 | 
					 | 
				
			||||||
#
 | 
					 | 
				
			||||||
# Licensed under the Apache License, Version 2.0 (the "License");
 | 
					 | 
				
			||||||
# you may not use this file except in compliance with the License.
 | 
					 | 
				
			||||||
# You may obtain a copy of the License at
 | 
					 | 
				
			||||||
#
 | 
					 | 
				
			||||||
#      http://www.apache.org/licenses/LICENSE-2.0
 | 
					 | 
				
			||||||
#
 | 
					 | 
				
			||||||
# Unless required by applicable law or agreed to in writing, software
 | 
					 | 
				
			||||||
# distributed under the License is distributed on an "AS IS" BASIS,
 | 
					 | 
				
			||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
					 | 
				
			||||||
# See the License for the specific language governing permissions and
 | 
					 | 
				
			||||||
# limitations under the License.
 | 
					 | 
				
			||||||
#
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# -----------------------------------------------------------------------------
 | 
					 | 
				
			||||||
# Libraries used by dlfcn tests to verify correct load order:
 | 
					 | 
				
			||||||
# libtest_check_order_2_right.so
 | 
					 | 
				
			||||||
# -----------------------------------------------------------------------------
 | 
					 | 
				
			||||||
libtest_check_order_dlsym_2_right_src_files := \
 | 
					 | 
				
			||||||
    dlopen_check_order_dlsym_answer.cpp
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
libtest_check_order_dlsym_2_right_cflags := -D__ANSWER=42
 | 
					 | 
				
			||||||
module := libtest_check_order_dlsym_2_right
 | 
					 | 
				
			||||||
include $(LOCAL_PATH)/Android.build.testlib.mk
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# -----------------------------------------------------------------------------
 | 
					 | 
				
			||||||
# libtest_check_order_a.so
 | 
					 | 
				
			||||||
# -----------------------------------------------------------------------------
 | 
					 | 
				
			||||||
libtest_check_order_dlsym_a_src_files := \
 | 
					 | 
				
			||||||
    dlopen_check_order_dlsym_answer.cpp
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
libtest_check_order_dlsym_a_cflags := -D__ANSWER=1
 | 
					 | 
				
			||||||
module := libtest_check_order_dlsym_a
 | 
					 | 
				
			||||||
include $(LOCAL_PATH)/Android.build.testlib.mk
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# -----------------------------------------------------------------------------
 | 
					 | 
				
			||||||
# libtest_check_order_b.so
 | 
					 | 
				
			||||||
# -----------------------------------------------------------------------------
 | 
					 | 
				
			||||||
libtest_check_order_dlsym_b_src_files := \
 | 
					 | 
				
			||||||
    dlopen_check_order_dlsym_answer.cpp
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
libtest_check_order_dlsym_b_cflags := -D__ANSWER=2 -D__ANSWER2=43
 | 
					 | 
				
			||||||
module := libtest_check_order_dlsym_b
 | 
					 | 
				
			||||||
include $(LOCAL_PATH)/Android.build.testlib.mk
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# -----------------------------------------------------------------------------
 | 
					 | 
				
			||||||
# libtest_check_order_c.so
 | 
					 | 
				
			||||||
# -----------------------------------------------------------------------------
 | 
					 | 
				
			||||||
libtest_check_order_dlsym_3_c_src_files := \
 | 
					 | 
				
			||||||
    dlopen_check_order_dlsym_answer.cpp
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
libtest_check_order_dlsym_3_c_cflags := -D__ANSWER=3
 | 
					 | 
				
			||||||
module := libtest_check_order_dlsym_3_c
 | 
					 | 
				
			||||||
include $(LOCAL_PATH)/Android.build.testlib.mk
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# -----------------------------------------------------------------------------
 | 
					 | 
				
			||||||
# libtest_check_order_d.so
 | 
					 | 
				
			||||||
# -----------------------------------------------------------------------------
 | 
					 | 
				
			||||||
libtest_check_order_dlsym_d_src_files := \
 | 
					 | 
				
			||||||
   dlopen_check_order_dlsym_answer.cpp
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
libtest_check_order_dlsym_d_shared_libraries := libtest_check_order_dlsym_b
 | 
					 | 
				
			||||||
libtest_check_order_dlsym_d_cflags := -D__ANSWER=4 -D__ANSWER2=4
 | 
					 | 
				
			||||||
module := libtest_check_order_dlsym_d
 | 
					 | 
				
			||||||
include $(LOCAL_PATH)/Android.build.testlib.mk
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# -----------------------------------------------------------------------------
 | 
					 | 
				
			||||||
# libtest_check_order_left.so
 | 
					 | 
				
			||||||
# -----------------------------------------------------------------------------
 | 
					 | 
				
			||||||
libtest_check_order_dlsym_1_left_src_files := \
 | 
					 | 
				
			||||||
    empty.cpp
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
libtest_check_order_dlsym_1_left_shared_libraries := libtest_check_order_dlsym_a libtest_check_order_dlsym_b
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
module := libtest_check_order_dlsym_1_left
 | 
					 | 
				
			||||||
include $(LOCAL_PATH)/Android.build.testlib.mk
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# -----------------------------------------------------------------------------
 | 
					 | 
				
			||||||
# libtest_check_order.so
 | 
					 | 
				
			||||||
# -----------------------------------------------------------------------------
 | 
					 | 
				
			||||||
libtest_check_order_dlsym_src_files := \
 | 
					 | 
				
			||||||
    empty.cpp
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
libtest_check_order_dlsym_shared_libraries := libtest_check_order_dlsym_1_left \
 | 
					 | 
				
			||||||
  libtest_check_order_dlsym_2_right libtest_check_order_dlsym_3_c
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
module := libtest_check_order_dlsym
 | 
					 | 
				
			||||||
include $(LOCAL_PATH)/Android.build.testlib.mk
 | 
					 | 
				
			||||||
@@ -1,56 +0,0 @@
 | 
				
			|||||||
#
 | 
					 | 
				
			||||||
# Copyright (C) 2012 The Android Open Source Project
 | 
					 | 
				
			||||||
#
 | 
					 | 
				
			||||||
# Licensed under the Apache License, Version 2.0 (the "License");
 | 
					 | 
				
			||||||
# you may not use this file except in compliance with the License.
 | 
					 | 
				
			||||||
# You may obtain a copy of the License at
 | 
					 | 
				
			||||||
#
 | 
					 | 
				
			||||||
#      http://www.apache.org/licenses/LICENSE-2.0
 | 
					 | 
				
			||||||
#
 | 
					 | 
				
			||||||
# Unless required by applicable law or agreed to in writing, software
 | 
					 | 
				
			||||||
# distributed under the License is distributed on an "AS IS" BASIS,
 | 
					 | 
				
			||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
					 | 
				
			||||||
# See the License for the specific language governing permissions and
 | 
					 | 
				
			||||||
# limitations under the License.
 | 
					 | 
				
			||||||
#
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# -----------------------------------------------------------------------------
 | 
					 | 
				
			||||||
# Libraries used by dlfcn tests to verify correct relocation order:
 | 
					 | 
				
			||||||
# libtest_check_order_reloc_root*.so
 | 
					 | 
				
			||||||
# -----------------------------------------------------------------------------
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# -----------------------------------------------------------------------------
 | 
					 | 
				
			||||||
# ..._1.so - empty
 | 
					 | 
				
			||||||
# -----------------------------------------------------------------------------
 | 
					 | 
				
			||||||
libtest_check_order_reloc_root_1_src_files := \
 | 
					 | 
				
			||||||
    empty.cpp
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
module := libtest_check_order_reloc_root_1
 | 
					 | 
				
			||||||
include $(LOCAL_PATH)/Android.build.testlib.mk
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# -----------------------------------------------------------------------------
 | 
					 | 
				
			||||||
# ..._2.so - this one has the incorrect answer
 | 
					 | 
				
			||||||
# -----------------------------------------------------------------------------
 | 
					 | 
				
			||||||
libtest_check_order_reloc_root_2_src_files := \
 | 
					 | 
				
			||||||
    dlopen_check_order_reloc_root_answer_impl.cpp
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
libtest_check_order_reloc_root_2_cflags := -D__ANSWER=2
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
module := libtest_check_order_reloc_root_2
 | 
					 | 
				
			||||||
include $(LOCAL_PATH)/Android.build.testlib.mk
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# -----------------------------------------------------------------------------
 | 
					 | 
				
			||||||
# libtest_check_order_reloc_root.so <- implements get_answer3()
 | 
					 | 
				
			||||||
# -----------------------------------------------------------------------------
 | 
					 | 
				
			||||||
libtest_check_order_reloc_root_src_files := \
 | 
					 | 
				
			||||||
    dlopen_check_order_reloc_root_answer.cpp
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
libtest_check_order_reloc_root_shared_libraries := \
 | 
					 | 
				
			||||||
    libtest_check_order_reloc_root_1 \
 | 
					 | 
				
			||||||
    libtest_check_order_reloc_root_2
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
module := libtest_check_order_reloc_root
 | 
					 | 
				
			||||||
include $(LOCAL_PATH)/Android.build.testlib.mk
 | 
					 | 
				
			||||||
@@ -1,133 +0,0 @@
 | 
				
			|||||||
#
 | 
					 | 
				
			||||||
# Copyright (C) 2014 The Android Open Source Project
 | 
					 | 
				
			||||||
#
 | 
					 | 
				
			||||||
# Licensed under the Apache License, Version 2.0 (the "License");
 | 
					 | 
				
			||||||
# you may not use this file except in compliance with the License.
 | 
					 | 
				
			||||||
# You may obtain a copy of the License at
 | 
					 | 
				
			||||||
#
 | 
					 | 
				
			||||||
#      http://www.apache.org/licenses/LICENSE-2.0
 | 
					 | 
				
			||||||
#
 | 
					 | 
				
			||||||
# Unless required by applicable law or agreed to in writing, software
 | 
					 | 
				
			||||||
# distributed under the License is distributed on an "AS IS" BASIS,
 | 
					 | 
				
			||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
					 | 
				
			||||||
# See the License for the specific language governing permissions and
 | 
					 | 
				
			||||||
# limitations under the License.
 | 
					 | 
				
			||||||
#
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# -----------------------------------------------------------------------------
 | 
					 | 
				
			||||||
# Libraries used by dlfcn tests to verify correct relocation order:
 | 
					 | 
				
			||||||
# libtest_check_order_reloc_siblings*.so
 | 
					 | 
				
			||||||
# -----------------------------------------------------------------------------
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# -----------------------------------------------------------------------------
 | 
					 | 
				
			||||||
# ..._1.so - empty
 | 
					 | 
				
			||||||
# -----------------------------------------------------------------------------
 | 
					 | 
				
			||||||
libtest_check_order_reloc_siblings_1_src_files := \
 | 
					 | 
				
			||||||
    empty.cpp
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
libtest_check_order_reloc_siblings_1_shared_libraries := \
 | 
					 | 
				
			||||||
    libtest_check_order_reloc_siblings_a \
 | 
					 | 
				
			||||||
    libtest_check_order_reloc_siblings_b
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
module := libtest_check_order_reloc_siblings_1
 | 
					 | 
				
			||||||
include $(LOCAL_PATH)/Android.build.testlib.mk
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# -----------------------------------------------------------------------------
 | 
					 | 
				
			||||||
# ..._2.so - empty
 | 
					 | 
				
			||||||
# -----------------------------------------------------------------------------
 | 
					 | 
				
			||||||
libtest_check_order_reloc_siblings_2_src_files := \
 | 
					 | 
				
			||||||
    empty.cpp
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
libtest_check_order_reloc_siblings_2_shared_libraries := \
 | 
					 | 
				
			||||||
    libtest_check_order_reloc_siblings_c \
 | 
					 | 
				
			||||||
    libtest_check_order_reloc_siblings_d
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
module := libtest_check_order_reloc_siblings_2
 | 
					 | 
				
			||||||
include $(LOCAL_PATH)/Android.build.testlib.mk
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# -----------------------------------------------------------------------------
 | 
					 | 
				
			||||||
# ..._3.so - get_answer2();
 | 
					 | 
				
			||||||
# -----------------------------------------------------------------------------
 | 
					 | 
				
			||||||
libtest_check_order_reloc_siblings_3_src_files := \
 | 
					 | 
				
			||||||
    dlopen_check_order_reloc_nephew_answer.cpp
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
libtest_check_order_reloc_siblings_3_shared_libraries := \
 | 
					 | 
				
			||||||
    libtest_check_order_reloc_siblings_e \
 | 
					 | 
				
			||||||
    libtest_check_order_reloc_siblings_f
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
module := libtest_check_order_reloc_siblings_3
 | 
					 | 
				
			||||||
include $(LOCAL_PATH)/Android.build.testlib.mk
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# -----------------------------------------------------------------------------
 | 
					 | 
				
			||||||
# ..._a.so <- correct impl
 | 
					 | 
				
			||||||
# -----------------------------------------------------------------------------
 | 
					 | 
				
			||||||
libtest_check_order_reloc_siblings_a_src_files := \
 | 
					 | 
				
			||||||
    dlopen_check_order_reloc_answer_impl.cpp
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
libtest_check_order_reloc_siblings_a_cflags := -D__ANSWER=42
 | 
					 | 
				
			||||||
module := libtest_check_order_reloc_siblings_a
 | 
					 | 
				
			||||||
include $(LOCAL_PATH)/Android.build.testlib.mk
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# -----------------------------------------------------------------------------
 | 
					 | 
				
			||||||
# ..._b.so
 | 
					 | 
				
			||||||
# -----------------------------------------------------------------------------
 | 
					 | 
				
			||||||
libtest_check_order_reloc_siblings_b_src_files := \
 | 
					 | 
				
			||||||
    dlopen_check_order_reloc_answer_impl.cpp
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
libtest_check_order_reloc_siblings_b_cflags := -D__ANSWER=1
 | 
					 | 
				
			||||||
module := libtest_check_order_reloc_siblings_b
 | 
					 | 
				
			||||||
include $(LOCAL_PATH)/Android.build.testlib.mk
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# -----------------------------------------------------------------------------
 | 
					 | 
				
			||||||
# ..._c.so
 | 
					 | 
				
			||||||
# -----------------------------------------------------------------------------
 | 
					 | 
				
			||||||
libtest_check_order_reloc_siblings_c_src_files := \
 | 
					 | 
				
			||||||
    dlopen_check_order_reloc_answer_impl.cpp
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
libtest_check_order_reloc_siblings_c_cflags := -D__ANSWER=2
 | 
					 | 
				
			||||||
module := libtest_check_order_reloc_siblings_c
 | 
					 | 
				
			||||||
include $(LOCAL_PATH)/Android.build.testlib.mk
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# -----------------------------------------------------------------------------
 | 
					 | 
				
			||||||
# ..._d.so
 | 
					 | 
				
			||||||
# -----------------------------------------------------------------------------
 | 
					 | 
				
			||||||
libtest_check_order_reloc_siblings_d_src_files := \
 | 
					 | 
				
			||||||
    dlopen_check_order_reloc_answer_impl.cpp
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
libtest_check_order_reloc_siblings_d_cflags := -D__ANSWER=3
 | 
					 | 
				
			||||||
module := libtest_check_order_reloc_siblings_d
 | 
					 | 
				
			||||||
include $(LOCAL_PATH)/Android.build.testlib.mk
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# -----------------------------------------------------------------------------
 | 
					 | 
				
			||||||
# ..._e.so
 | 
					 | 
				
			||||||
# -----------------------------------------------------------------------------
 | 
					 | 
				
			||||||
libtest_check_order_reloc_siblings_e_src_files := \
 | 
					 | 
				
			||||||
    dlopen_check_order_reloc_answer_impl.cpp
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
libtest_check_order_reloc_siblings_e_cflags := -D__ANSWER=4
 | 
					 | 
				
			||||||
module := libtest_check_order_reloc_siblings_e
 | 
					 | 
				
			||||||
include $(LOCAL_PATH)/Android.build.testlib.mk
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# -----------------------------------------------------------------------------
 | 
					 | 
				
			||||||
# ..._f.so <- get_answer()
 | 
					 | 
				
			||||||
# -----------------------------------------------------------------------------
 | 
					 | 
				
			||||||
libtest_check_order_reloc_siblings_f_src_files := \
 | 
					 | 
				
			||||||
    dlopen_check_order_reloc_answer.cpp
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
module := libtest_check_order_reloc_siblings_f
 | 
					 | 
				
			||||||
include $(LOCAL_PATH)/Android.build.testlib.mk
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# -----------------------------------------------------------------------------
 | 
					 | 
				
			||||||
# libtest_check_order_reloc_siblings.so
 | 
					 | 
				
			||||||
# -----------------------------------------------------------------------------
 | 
					 | 
				
			||||||
libtest_check_order_reloc_siblings_src_files := \
 | 
					 | 
				
			||||||
    empty.cpp
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
libtest_check_order_reloc_siblings_shared_libraries := \
 | 
					 | 
				
			||||||
    libtest_check_order_reloc_siblings_1 \
 | 
					 | 
				
			||||||
    libtest_check_order_reloc_siblings_2 \
 | 
					 | 
				
			||||||
    libtest_check_order_reloc_siblings_3
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
module := libtest_check_order_reloc_siblings
 | 
					 | 
				
			||||||
include $(LOCAL_PATH)/Android.build.testlib.mk
 | 
					 | 
				
			||||||
@@ -21,9 +21,6 @@ common_cppflags += -std=gnu++11
 | 
				
			|||||||
common_additional_dependencies := \
 | 
					common_additional_dependencies := \
 | 
				
			||||||
    $(LOCAL_PATH)/Android.mk \
 | 
					    $(LOCAL_PATH)/Android.mk \
 | 
				
			||||||
    $(LOCAL_PATH)/Android.build.dlext_testzip.mk \
 | 
					    $(LOCAL_PATH)/Android.build.dlext_testzip.mk \
 | 
				
			||||||
    $(LOCAL_PATH)/Android.build.dlopen_check_order_dlsym.mk \
 | 
					 | 
				
			||||||
    $(LOCAL_PATH)/Android.build.dlopen_check_order_reloc_siblings.mk \
 | 
					 | 
				
			||||||
    $(LOCAL_PATH)/Android.build.dlopen_check_order_reloc_main_executable.mk \
 | 
					 | 
				
			||||||
    $(LOCAL_PATH)/Android.build.testlib.mk \
 | 
					    $(LOCAL_PATH)/Android.build.testlib.mk \
 | 
				
			||||||
    $(TEST_PATH)/Android.build.mk
 | 
					    $(TEST_PATH)/Android.build.mk
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -153,19 +150,79 @@ module := libtest_nodelete_dt_flags_1
 | 
				
			|||||||
include $(LOCAL_PATH)/Android.build.testlib.mk
 | 
					include $(LOCAL_PATH)/Android.build.testlib.mk
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# -----------------------------------------------------------------------------
 | 
					# -----------------------------------------------------------------------------
 | 
				
			||||||
# Build libtest_check_order_dlsym.so with its dependencies.
 | 
					# Libraries used by dlfcn tests to verify correct load order:
 | 
				
			||||||
 | 
					# libtest_check_order_2_right.so
 | 
				
			||||||
# -----------------------------------------------------------------------------
 | 
					# -----------------------------------------------------------------------------
 | 
				
			||||||
include $(LOCAL_PATH)/Android.build.dlopen_check_order_dlsym.mk
 | 
					libtest_check_order_2_right_src_files := \
 | 
				
			||||||
 | 
					    dlopen_testlib_answer.cpp
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					libtest_check_order_2_right_cflags := -D__ANSWER=42
 | 
				
			||||||
 | 
					module := libtest_check_order_2_right
 | 
				
			||||||
 | 
					include $(LOCAL_PATH)/Android.build.testlib.mk
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# -----------------------------------------------------------------------------
 | 
					# -----------------------------------------------------------------------------
 | 
				
			||||||
# Build libtest_check_order_siblings.so with its dependencies.
 | 
					# libtest_check_order_a.so
 | 
				
			||||||
# -----------------------------------------------------------------------------
 | 
					# -----------------------------------------------------------------------------
 | 
				
			||||||
include $(LOCAL_PATH)/Android.build.dlopen_check_order_reloc_siblings.mk
 | 
					libtest_check_order_a_src_files := \
 | 
				
			||||||
 | 
					    dlopen_testlib_answer.cpp
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					libtest_check_order_a_cflags := -D__ANSWER=1
 | 
				
			||||||
 | 
					module := libtest_check_order_a
 | 
				
			||||||
 | 
					include $(LOCAL_PATH)/Android.build.testlib.mk
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# -----------------------------------------------------------------------------
 | 
					# -----------------------------------------------------------------------------
 | 
				
			||||||
# Build libtest_check_order_root.so with its dependencies.
 | 
					# libtest_check_order_b.so
 | 
				
			||||||
# -----------------------------------------------------------------------------
 | 
					# -----------------------------------------------------------------------------
 | 
				
			||||||
include $(LOCAL_PATH)/Android.build.dlopen_check_order_reloc_main_executable.mk
 | 
					libtest_check_order_b_src_files := \
 | 
				
			||||||
 | 
					    dlopen_testlib_answer.cpp
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					libtest_check_order_b_cflags := -D__ANSWER=2 -D__ANSWER2=43
 | 
				
			||||||
 | 
					module := libtest_check_order_b
 | 
				
			||||||
 | 
					include $(LOCAL_PATH)/Android.build.testlib.mk
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# -----------------------------------------------------------------------------
 | 
				
			||||||
 | 
					# libtest_check_order_c.so
 | 
				
			||||||
 | 
					# -----------------------------------------------------------------------------
 | 
				
			||||||
 | 
					libtest_check_order_3_c_src_files := \
 | 
				
			||||||
 | 
					    dlopen_testlib_answer.cpp
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					libtest_check_order_3_c_cflags := -D__ANSWER=3
 | 
				
			||||||
 | 
					module := libtest_check_order_3_c
 | 
				
			||||||
 | 
					include $(LOCAL_PATH)/Android.build.testlib.mk
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# -----------------------------------------------------------------------------
 | 
				
			||||||
 | 
					# libtest_check_order_d.so
 | 
				
			||||||
 | 
					# -----------------------------------------------------------------------------
 | 
				
			||||||
 | 
					libtest_check_order_d_src_files := \
 | 
				
			||||||
 | 
					   dlopen_testlib_answer.cpp
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					libtest_check_order_d_shared_libraries := libtest_check_order_b
 | 
				
			||||||
 | 
					libtest_check_order_d_cflags := -D__ANSWER=4 -D__ANSWER2=4
 | 
				
			||||||
 | 
					module := libtest_check_order_d
 | 
				
			||||||
 | 
					include $(LOCAL_PATH)/Android.build.testlib.mk
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# -----------------------------------------------------------------------------
 | 
				
			||||||
 | 
					# libtest_check_order_left.so
 | 
				
			||||||
 | 
					# -----------------------------------------------------------------------------
 | 
				
			||||||
 | 
					libtest_check_order_1_left_src_files := \
 | 
				
			||||||
 | 
					    empty.cpp
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					libtest_check_order_1_left_shared_libraries := libtest_check_order_a libtest_check_order_b
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					module := libtest_check_order_1_left
 | 
				
			||||||
 | 
					include $(LOCAL_PATH)/Android.build.testlib.mk
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# -----------------------------------------------------------------------------
 | 
				
			||||||
 | 
					# libtest_check_order.so
 | 
				
			||||||
 | 
					# -----------------------------------------------------------------------------
 | 
				
			||||||
 | 
					libtest_check_order_src_files := \
 | 
				
			||||||
 | 
					    empty.cpp
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					libtest_check_order_shared_libraries := libtest_check_order_1_left \
 | 
				
			||||||
 | 
					  libtest_check_order_2_right libtest_check_order_3_c
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					module := libtest_check_order
 | 
				
			||||||
 | 
					include $(LOCAL_PATH)/Android.build.testlib.mk
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# -----------------------------------------------------------------------------
 | 
					# -----------------------------------------------------------------------------
 | 
				
			||||||
# Library with dependency loop used by dlfcn tests
 | 
					# Library with dependency loop used by dlfcn tests
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,23 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2014 The Android Open Source Project
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * Licensed under the Apache License, Version 2.0 (the "License");
 | 
					 | 
				
			||||||
 * you may not use this file except in compliance with the License.
 | 
					 | 
				
			||||||
 * You may obtain a copy of the License at
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 *      http://www.apache.org/licenses/LICENSE-2.0
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * Unless required by applicable law or agreed to in writing, software
 | 
					 | 
				
			||||||
 * distributed under the License is distributed on an "AS IS" BASIS,
 | 
					 | 
				
			||||||
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
					 | 
				
			||||||
 * See the License for the specific language governing permissions and
 | 
					 | 
				
			||||||
 * limitations under the License.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
extern "C" int __attribute__((weak)) check_order_reloc_get_answer_impl() {
 | 
					 | 
				
			||||||
  return 0;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
extern "C" int check_order_reloc_get_answer() {
 | 
					 | 
				
			||||||
  return check_order_reloc_get_answer_impl();
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,19 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2014 The Android Open Source Project
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * Licensed under the Apache License, Version 2.0 (the "License");
 | 
					 | 
				
			||||||
 * you may not use this file except in compliance with the License.
 | 
					 | 
				
			||||||
 * You may obtain a copy of the License at
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 *      http://www.apache.org/licenses/LICENSE-2.0
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * Unless required by applicable law or agreed to in writing, software
 | 
					 | 
				
			||||||
 * distributed under the License is distributed on an "AS IS" BASIS,
 | 
					 | 
				
			||||||
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
					 | 
				
			||||||
 * See the License for the specific language governing permissions and
 | 
					 | 
				
			||||||
 * limitations under the License.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
extern "C" int check_order_reloc_get_answer_impl() {
 | 
					 | 
				
			||||||
  return __ANSWER;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,21 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2014 The Android Open Source Project
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * Licensed under the Apache License, Version 2.0 (the "License");
 | 
					 | 
				
			||||||
 * you may not use this file except in compliance with the License.
 | 
					 | 
				
			||||||
 * You may obtain a copy of the License at
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 *      http://www.apache.org/licenses/LICENSE-2.0
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * Unless required by applicable law or agreed to in writing, software
 | 
					 | 
				
			||||||
 * distributed under the License is distributed on an "AS IS" BASIS,
 | 
					 | 
				
			||||||
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
					 | 
				
			||||||
 * See the License for the specific language governing permissions and
 | 
					 | 
				
			||||||
 * limitations under the License.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
extern "C" int check_order_reloc_get_answer_impl();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
extern "C" int check_order_reloc_nephew_get_answer() {
 | 
					 | 
				
			||||||
  return check_order_reloc_get_answer_impl();
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,21 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2014 The Android Open Source Project
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * Licensed under the Apache License, Version 2.0 (the "License");
 | 
					 | 
				
			||||||
 * you may not use this file except in compliance with the License.
 | 
					 | 
				
			||||||
 * You may obtain a copy of the License at
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 *      http://www.apache.org/licenses/LICENSE-2.0
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * Unless required by applicable law or agreed to in writing, software
 | 
					 | 
				
			||||||
 * distributed under the License is distributed on an "AS IS" BASIS,
 | 
					 | 
				
			||||||
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
					 | 
				
			||||||
 * See the License for the specific language governing permissions and
 | 
					 | 
				
			||||||
 * limitations under the License.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
extern "C" int check_order_reloc_root_get_answer_impl();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
extern "C" int check_order_reloc_root_get_answer() {
 | 
					 | 
				
			||||||
  return check_order_reloc_root_get_answer_impl();
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,19 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2014 The Android Open Source Project
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * Licensed under the Apache License, Version 2.0 (the "License");
 | 
					 | 
				
			||||||
 * you may not use this file except in compliance with the License.
 | 
					 | 
				
			||||||
 * You may obtain a copy of the License at
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 *      http://www.apache.org/licenses/LICENSE-2.0
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * Unless required by applicable law or agreed to in writing, software
 | 
					 | 
				
			||||||
 * distributed under the License is distributed on an "AS IS" BASIS,
 | 
					 | 
				
			||||||
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
					 | 
				
			||||||
 * See the License for the specific language governing permissions and
 | 
					 | 
				
			||||||
 * limitations under the License.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
extern "C" int check_order_reloc_root_get_answer_impl() {
 | 
					 | 
				
			||||||
  return __ANSWER;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -14,12 +14,12 @@
 | 
				
			|||||||
 * limitations under the License.
 | 
					 * limitations under the License.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern "C" int check_order_dlsym_get_answer() {
 | 
					extern "C" int dlopen_test_get_answer() {
 | 
				
			||||||
  return __ANSWER;
 | 
					  return __ANSWER;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef __ANSWER2
 | 
					#ifdef __ANSWER2
 | 
				
			||||||
extern "C" int check_order_dlsym_get_answer2() {
 | 
					extern "C" int dlopen_test_get_answer2() {
 | 
				
			||||||
  return __ANSWER2;
 | 
					  return __ANSWER2;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
		Reference in New Issue
	
	Block a user