Respect caller DT_RUNPATH in dlopen().
When dlopen-ing a library, add the caller's DT_RUNPATH to the directory search
list. This fixes dlfcn.dt_runpath in bionic-unit-tests-glibc(32|64).
Bug: 21899363
Change-Id: Ife6a7e192939292cf4dc291b7e6b95945761cde3
diff --git a/linker/dlfcn.cpp b/linker/dlfcn.cpp
index ef454ab..4993568 100644
--- a/linker/dlfcn.cpp
+++ b/linker/dlfcn.cpp
@@ -67,9 +67,10 @@
do_android_update_LD_LIBRARY_PATH(ld_library_path);
}
-static void* dlopen_ext(const char* filename, int flags, const android_dlextinfo* extinfo) {
+static void* dlopen_ext(const char* filename, int flags,
+ const android_dlextinfo* extinfo, soinfo* caller) {
ScopedPthreadMutexLocker locker(&g_dl_mutex);
- soinfo* result = do_dlopen(filename, flags, extinfo);
+ soinfo* result = do_dlopen(filename, flags, extinfo, caller);
if (result == nullptr) {
__bionic_format_dlerror("dlopen failed", linker_get_error_buffer());
return nullptr;
@@ -78,11 +79,15 @@
}
void* android_dlopen_ext(const char* filename, int flags, const android_dlextinfo* extinfo) {
- return dlopen_ext(filename, flags, extinfo);
+ void* caller_addr = __builtin_return_address(0);
+ soinfo* caller = find_containing_library(caller_addr);
+ return dlopen_ext(filename, flags, extinfo, caller);
}
void* dlopen(const char* filename, int flags) {
- return dlopen_ext(filename, flags, nullptr);
+ void* caller_addr = __builtin_return_address(0);
+ soinfo* caller = find_containing_library(caller_addr);
+ return dlopen_ext(filename, flags, nullptr, caller);
}
void* dlsym(void* handle, const char* symbol) {