aboutsummaryrefslogtreecommitdiff
path: root/lib/mlibc/tests/rtdl/scope2
diff options
context:
space:
mode:
Diffstat (limited to 'lib/mlibc/tests/rtdl/scope2')
-rw-r--r--lib/mlibc/tests/rtdl/scope2/libbar.c5
-rw-r--r--lib/mlibc/tests/rtdl/scope2/libbaz.c3
-rw-r--r--lib/mlibc/tests/rtdl/scope2/libfoo.c3
-rw-r--r--lib/mlibc/tests/rtdl/scope2/meson.build9
-rw-r--r--lib/mlibc/tests/rtdl/scope2/test.c36
5 files changed, 56 insertions, 0 deletions
diff --git a/lib/mlibc/tests/rtdl/scope2/libbar.c b/lib/mlibc/tests/rtdl/scope2/libbar.c
new file mode 100644
index 0000000..4783c58
--- /dev/null
+++ b/lib/mlibc/tests/rtdl/scope2/libbar.c
@@ -0,0 +1,5 @@
+char *foo_baz_conflict(void);
+
+char *bar_calls_foo_baz_conflict() {
+ return foo_baz_conflict();
+}
diff --git a/lib/mlibc/tests/rtdl/scope2/libbaz.c b/lib/mlibc/tests/rtdl/scope2/libbaz.c
new file mode 100644
index 0000000..fc73adc
--- /dev/null
+++ b/lib/mlibc/tests/rtdl/scope2/libbaz.c
@@ -0,0 +1,3 @@
+char *foo_baz_conflict() {
+ return "resolved to baz";
+}
diff --git a/lib/mlibc/tests/rtdl/scope2/libfoo.c b/lib/mlibc/tests/rtdl/scope2/libfoo.c
new file mode 100644
index 0000000..9f7b881
--- /dev/null
+++ b/lib/mlibc/tests/rtdl/scope2/libfoo.c
@@ -0,0 +1,3 @@
+char *foo_baz_conflict() {
+ return "resolved to foo";
+}
diff --git a/lib/mlibc/tests/rtdl/scope2/meson.build b/lib/mlibc/tests/rtdl/scope2/meson.build
new file mode 100644
index 0000000..938272c
--- /dev/null
+++ b/lib/mlibc/tests/rtdl/scope2/meson.build
@@ -0,0 +1,9 @@
+libfoo = shared_library('foo', 'libfoo.c')
+libbar = shared_library('bar', 'libbar.c', build_rpath: test_rpath, link_with: libfoo)
+libbaz = shared_library('baz', 'libbaz.c')
+test_depends = [libfoo, libbar, libbaz]
+
+libfoo_native = shared_library('native-foo', 'libfoo.c', native: true)
+libbar_native = shared_library('native-bar', 'libbar.c', build_rpath: test_rpath, link_with: libfoo_native, native: true)
+libbaz_native = shared_library('native-baz', 'libbaz.c', native: true)
+test_native_depends = [libfoo_native, libbar_native, libbaz_native]
diff --git a/lib/mlibc/tests/rtdl/scope2/test.c b/lib/mlibc/tests/rtdl/scope2/test.c
new file mode 100644
index 0000000..f4f42dc
--- /dev/null
+++ b/lib/mlibc/tests/rtdl/scope2/test.c
@@ -0,0 +1,36 @@
+#include <stddef.h>
+#include <dlfcn.h>
+#include <assert.h>
+#include <string.h>
+#include <stdio.h>
+
+#ifdef USE_HOST_LIBC
+#define LIBBAR "libnative-bar.so"
+#define LIBBAZ "libnative-baz.so"
+#else
+#define LIBBAR "libbar.so"
+#define LIBBAZ "libbaz.so"
+#endif
+
+typedef char *strfn(void);
+
+int main() {
+ void *baz = dlopen(LIBBAZ, RTLD_LAZY | RTLD_GLOBAL);
+ assert(baz);
+
+ // At this point, baz is loaded in the global scope. When we load bar locally,
+ // there is a relocation to `foo_baz_conflict` which is defined in both
+ // foo (which is a dependency of bar), and baz. In this case baz should win
+ // since we search the global scope first.
+
+ void *bar = dlopen(LIBBAR, RTLD_LAZY | RTLD_LOCAL);
+ assert(bar);
+
+ strfn *bfn = dlsym(bar, "bar_calls_foo_baz_conflict");
+ assert(!strcmp(bfn(), "resolved to baz"));
+
+ // TODO: Test RTLD_DEEPBIND and DT_SYMBOLIC once we implement it.
+
+ dlclose(bar);
+ dlclose(baz);
+}