Fix bootstrap linker library searching
For the bootstrap linker, insert /system/${LIB}/bootstrap in front of
/system/${LIB} in any namespace search path.
Bug: http://b/152572170
Test: bionic unit tests
Change-Id: Ia359d9f2063f4b6fff3f79b51b500ba968a18247
diff --git a/linker/linker.cpp b/linker/linker.cpp
index 090e7f0..e34c796 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -1062,14 +1062,6 @@
}
}
- // For the bootstrap linker, search for the bootstrap bionic libraries (e.g. libc.so).
-#if !defined(__ANDROID_APEX__)
- if (fd == -1) {
- std::vector<std::string> bootstrap_paths = { std::string(kSystemLibDir) + "/bootstrap" };
- fd = open_library_on_paths(zip_archive_cache, name, file_offset, bootstrap_paths, realpath);
- }
-#endif
-
// Finally search the namespace's main search path list.
if (fd == -1) {
fd = open_library_on_paths(zip_archive_cache, name, file_offset, ns->get_default_library_paths(), realpath);
@@ -2424,6 +2416,21 @@
}
}
+std::vector<std::string> fix_lib_paths(std::vector<std::string> paths) {
+ // For the bootstrap linker, insert /system/${LIB}/bootstrap in front of /system/${LIB} in any
+ // namespace search path. The bootstrap linker should prefer to use the bootstrap bionic libraries
+ // (e.g. libc.so).
+#if !defined(__ANDROID_APEX__)
+ for (size_t i = 0; i < paths.size(); ++i) {
+ if (paths[i] == kSystemLibDir) {
+ paths.insert(paths.begin() + i, std::string(kSystemLibDir) + "/bootstrap");
+ ++i;
+ }
+ }
+#endif
+ return paths;
+}
+
android_namespace_t* create_namespace(const void* caller_addr,
const char* name,
const char* ld_library_path,