aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitry Ivanov <dimitry@google.com>2018-05-12 08:55:08 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2018-05-12 08:55:08 +0000
commit9b76571684253bef0f8b697f231ba96d76cfc927 (patch)
treef92e0a47c3a0c617e7a98fca6878e21aa5adf743
parent3f54e7dc6f3eda273e515cf6f54bc46273a2317e (diff)
parent69c68c46ac18a440bf1c0447d8343a6dbad595f1 (diff)
downloadbionic-9b76571684253bef0f8b697f231ba96d76cfc927.tar.gz
Merge changes I8eae0c98,I09d32dcb into pi-dev
* changes: vdso should be available in all namespaces Unhardcode /system/lib
-rw-r--r--linker/linker.cpp6
-rw-r--r--linker/linker_main.cpp11
-rw-r--r--linker/linker_main.h1
-rw-r--r--tests/dl_test.cpp6
-rw-r--r--tests/libs/ld_config_test_helper.cpp24
5 files changed, 45 insertions, 3 deletions
diff --git a/linker/linker.cpp b/linker/linker.cpp
index 32df9113d..a0205dc3c 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -3826,8 +3826,14 @@ std::vector<android_namespace_t*> init_default_namespaces(const char* executable
// we can no longer rely on the fact that libdl.so is part of default namespace
// this is why we want to add ld-android.so to all namespaces from ld.config.txt
soinfo* ld_android_so = solist_get_head();
+
+ // we also need vdso to be available for all namespaces (if present)
+ soinfo* vdso = solist_get_vdso();
for (auto it : namespaces) {
it.second->add_soinfo(ld_android_so);
+ if (vdso != nullptr) {
+ it.second->add_soinfo(vdso);
+ }
// somain and ld_preloads are added to these namespaces after LD_PRELOAD libs are linked
}
diff --git a/linker/linker_main.cpp b/linker/linker_main.cpp
index dc1fa7550..00c72d02a 100644
--- a/linker/linker_main.cpp
+++ b/linker/linker_main.cpp
@@ -64,6 +64,7 @@ static ElfW(Addr) get_elf_exec_load_bias(const ElfW(Ehdr)* elf);
static soinfo* solist;
static soinfo* sonext;
static soinfo* somain; // main process, always the one after libdl_info
+static soinfo* vdso; // vdso if present
void solist_add_soinfo(soinfo* si) {
sonext->next = si;
@@ -104,6 +105,10 @@ soinfo* solist_get_somain() {
return somain;
}
+soinfo* solist_get_vdso() {
+ return vdso;
+}
+
int g_ld_debug_verbosity;
abort_msg_t* g_abort_message = nullptr; // For debuggerd.
@@ -158,6 +163,8 @@ static void add_vdso(KernelArgumentBlock& args) {
si->set_dt_flags_1(si->get_dt_flags_1() | DF_1_NODELETE);
si->set_linked();
si->call_constructors();
+
+ vdso = si;
}
/* gdb expects the linker to be in the debug shared object list.
@@ -280,6 +287,8 @@ static ElfW(Addr) __linker_init_post_relocation(KernelArgumentBlock& args) {
}
}
+ add_vdso(args);
+
struct stat file_stat;
// Stat "/proc/self/exe" instead of executable_path because
// the executable could be unlinked by this point and it should
@@ -366,8 +375,6 @@ static ElfW(Addr) __linker_init_post_relocation(KernelArgumentBlock& args) {
}
}
- add_vdso(args);
-
// Load ld_preloads and dependencies.
std::vector<const char*> needed_library_name_list;
size_t ld_preloads_count = 0;
diff --git a/linker/linker_main.h b/linker/linker_main.h
index 8d486e846..b37b9472f 100644
--- a/linker/linker_main.h
+++ b/linker/linker_main.h
@@ -70,3 +70,4 @@ void solist_add_soinfo(soinfo* si);
bool solist_remove_soinfo(soinfo* si);
soinfo* solist_get_head();
soinfo* solist_get_somain();
+soinfo* solist_get_vdso();
diff --git a/tests/dl_test.cpp b/tests/dl_test.cpp
index 38d778332..25341f42b 100644
--- a/tests/dl_test.cpp
+++ b/tests/dl_test.cpp
@@ -168,7 +168,11 @@ TEST(dl, exec_without_ld_config_file) {
}
#if defined(__BIONIC__)
+extern "C" void android_get_LD_LIBRARY_PATH(char*, size_t);
static void create_ld_config_file(const char* config_file) {
+ char default_search_paths[PATH_MAX];
+ android_get_LD_LIBRARY_PATH(default_search_paths, sizeof(default_search_paths));
+
std::ofstream fout(config_file, std::ios::out);
fout << "dir.test = " << get_testlib_root() << "/ld_config_test_helper/" << std::endl
<< "[test]" << std::endl
@@ -176,7 +180,7 @@ static void create_ld_config_file(const char* config_file) {
<< "namespace.default.search.paths = " << get_testlib_root() << std::endl
<< "namespace.default.links = ns2" << std::endl
<< "namespace.default.link.ns2.shared_libs = libc.so:libm.so:libdl.so:ld_config_test_helper_lib1.so" << std::endl
- << "namespace.ns2.search.paths = /system/${LIB}:" << get_testlib_root() << "/ns2" << std::endl;
+ << "namespace.ns2.search.paths = " << default_search_paths << ":" << get_testlib_root() << "/ns2" << std::endl;
fout.close();
}
#endif
diff --git a/tests/libs/ld_config_test_helper.cpp b/tests/libs/ld_config_test_helper.cpp
index 592e8c0b1..87e512eff 100644
--- a/tests/libs/ld_config_test_helper.cpp
+++ b/tests/libs/ld_config_test_helper.cpp
@@ -14,13 +14,37 @@
* limitations under the License.
*/
+#include <dlfcn.h>
#include <errno.h>
#include <stdio.h>
+#if __has_include(<sys/auxv.h>)
+#include <sys/auxv.h>
+#endif
#include <unistd.h>
extern int get_value_from_lib();
int main() {
+ bool skip_vdso_check = false;
+#if __has_include(<sys/auxv.h>)
+ if (getauxval(AT_SYSINFO_EHDR) == 0) {
+ skip_vdso_check = true;
+ }
+#endif
+
+ if (!skip_vdso_check) {
+ const char* vdso_name = "linux-vdso.so.1";
+#if defined(__i386__)
+ vdso_name = "linux-gate.so.1";
+#endif
+ void* handle = dlopen(vdso_name, RTLD_NOW);
+ if (handle == nullptr) {
+ printf("%s", dlerror());
+ return 1;
+ }
+ dlclose(handle);
+ }
+
printf("%d", get_value_from_lib());
return 0;
}