summaryrefslogtreecommitdiff
path: root/tests/libs/ld_config_test_helper_lib1.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/libs/ld_config_test_helper_lib1.cpp')
-rw-r--r--tests/libs/ld_config_test_helper_lib1.cpp21
1 files changed, 18 insertions, 3 deletions
diff --git a/tests/libs/ld_config_test_helper_lib1.cpp b/tests/libs/ld_config_test_helper_lib1.cpp
index fc5401a26..ffa9a457f 100644
--- a/tests/libs/ld_config_test_helper_lib1.cpp
+++ b/tests/libs/ld_config_test_helper_lib1.cpp
@@ -1,4 +1,19 @@
-extern int get_value_from_another_lib();
-int get_value_from_lib() {
- return get_value_from_another_lib();
+#include <dlfcn.h>
+#include <stdio.h>
+
+// Mark foo and bar weak so that Clang allows the run-time linker to decide which DSO's symbol to
+// use.
+
+__attribute__((weak)) extern "C" void foo() {
+ printf("foo lib1\n");
+ void (*next)(void) = reinterpret_cast<void (*)()>(dlsym(RTLD_NEXT, "foo"));
+ if (next != nullptr) next();
+}
+
+__attribute__((weak)) extern "C" void bar();
+
+void lib1_call_funcs() {
+ printf("lib1_call_funcs\n");
+ foo();
+ bar();
}