summaryrefslogtreecommitdiff
path: root/tests/libs/ld_config_test_helper.cpp
diff options
context:
space:
mode:
authorRyan Prichard <rprichard@google.com>2020-12-17 22:59:04 -0800
committerRyan Prichard <rprichard@google.com>2021-01-22 03:27:43 -0800
commit058eb8fa4ef22f6cdc5a25bf42e4766fbf5812ce (patch)
treec4dcd7b1955a848d40daec8618fb336e97fa3f51 /tests/libs/ld_config_test_helper.cpp
parentfcd9c78534b865951eb70b02eb3a424f08ecd6a6 (diff)
Ensure same order of global group members in all NS's
During "step 1" of find_libraries, the linker finds the transitive closure of dependencies, in BFS order. As it finds each library, it adds the library to its primary namespace (so that, if some other library also depends on it, find_loaded_library_by_soname can find the library in the process of being loaded). LD_PRELOAD libraries are automatically marked DF_1_GLOBAL, and any DF_1_GLOBAL library is added to every linker namespace. Previously, this secondary namespace registration happened after step 1. The result is that across different namespaces, the order of libraries could vary. In general, a namespace's primary members will all appear before secondary members. This is undesirable for libsigchain.so, which we want to have appear before any other non-preloaded library. Instead, when an soinfo is added to its primary namespace, immediately add it to all the other namespaces, too. This ensures that the order of soinfo objects is the same across namespaces. Expand the dl.exec_with_ld_config_file_with_ld_preload and dl.exec_with_ld_config_file tests to cover the new behavior. Mark lib1.so DF_1_GLOBAL and use a "foo" symbol to mimic the behavior of a signal API interposed by (e.g.) libsigchain.so and a ASAN preload. Test: bionic unit tests Bug: http://b/143219447 Change-Id: I9fd90f6f0d14caf1aca6d414b3e9aab77deca3ff
Diffstat (limited to 'tests/libs/ld_config_test_helper.cpp')
-rw-r--r--tests/libs/ld_config_test_helper.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/tests/libs/ld_config_test_helper.cpp b/tests/libs/ld_config_test_helper.cpp
index 87e512eff..124912180 100644
--- a/tests/libs/ld_config_test_helper.cpp
+++ b/tests/libs/ld_config_test_helper.cpp
@@ -22,7 +22,9 @@
#endif
#include <unistd.h>
-extern int get_value_from_lib();
+extern "C" void foo();
+void lib1_call_funcs();
+__attribute__((weak)) void lib3_call_funcs();
int main() {
bool skip_vdso_check = false;
@@ -45,6 +47,9 @@ int main() {
dlclose(handle);
}
- printf("%d", get_value_from_lib());
+ foo();
+ lib1_call_funcs();
+ if (lib3_call_funcs) lib3_call_funcs();
+
return 0;
}