aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/development/ldso/deepbind/lib.c
diff options
context:
space:
mode:
authorJohannes Stoelp <johannes.stoelp@gmail.com>2024-04-06 23:17:02 +0200
committerJohannes Stoelp <johannes.stoelp@gmail.com>2024-04-06 23:17:02 +0200
commit6d2292f2431ec9405b8789c28c81e8e711c15b2d (patch)
tree31cd471b7e3443af75fdddec619c51ad2db6c199 /src/development/ldso/deepbind/lib.c
parent3de8cfbc28ff4f7619c20d5552e03ca96aab4b01 (diff)
downloadnotes-6d2292f2431ec9405b8789c28c81e8e711c15b2d.tar.gz
notes-6d2292f2431ec9405b8789c28c81e8e711c15b2d.zip
ld.so: add RTLD_LOCAL, RTLD_DEEPBIND notes + example
Diffstat (limited to 'src/development/ldso/deepbind/lib.c')
-rw-r--r--src/development/ldso/deepbind/lib.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/development/ldso/deepbind/lib.c b/src/development/ldso/deepbind/lib.c
new file mode 100644
index 0000000..e18a4ce
--- /dev/null
+++ b/src/development/ldso/deepbind/lib.c
@@ -0,0 +1,23 @@
+#define _GNU_SOURCE
+#include <dlfcn.h>
+#include <stdio.h>
+
+#ifndef NAME
+#define NAME ""
+#endif
+
+void test() {
+ puts(NAME ":test()");
+
+ // Lookup next symbol from the libraries scope, which will search only in the
+ // libraries LOCAL scope, starting from the next object after the current one.
+ (void)dlsym(RTLD_NEXT, "next_lib" NAME);
+
+ // Global lookup from the libraries scope, which will search libraries in the
+ // GLOBAL scope and the libraries LOCAL scope. The order in which the scopes
+ // are searched depends on whether the library was loaded (a) with DEEPBIND or
+ // (b) not. whether this library was loaded with DEEPBIND). In the first case,
+ // the LOCAL scope is searched first, where in the latter, the GLOBAL scope is
+ // searched first.
+ (void)dlsym(RTLD_DEFAULT, "default_lib" NAME);
+}