public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc/google/grte/v5-2.27/master] Add basic testsuite for dlopen_with_offset
@ 2021-08-28 0:41 Fangrui Song
0 siblings, 0 replies; only message in thread
From: Fangrui Song @ 2021-08-28 0:41 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=d57236debc46317a95c1741702252f4e44b90070
commit d57236debc46317a95c1741702252f4e44b90070
Author: Stan Shebs <stanshebs@google.com>
Date: Thu Mar 29 11:48:37 2018 -0700
Add basic testsuite for dlopen_with_offset
Diff:
---
elf/Makefile | 9 +++
elf/tst-dlopen-offset-mod1.c | 15 +++++
elf/tst-dlopen-offset-mod2.c | 8 +++
elf/tst-dlopen-offset-mod3.c | 8 +++
elf/tst-dlopen-offset.c | 144 +++++++++++++++++++++++++++++++++++++++++++
5 files changed, 184 insertions(+)
diff --git a/elf/Makefile b/elf/Makefile
index f1fda1d61d..8f16690c25 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -180,6 +180,7 @@ tests += restest1 preloadtest loadfail multiload origtest resolvfail \
tst-tls16 tst-tls17 tst-tls18 tst-tls19 tst-tls-dlinfo \
tst-align tst-align2 $(tests-execstack-$(have-z-execstack)) \
tst-dlmodcount tst-dlopenrpath tst-deep1 \
+ tst-dlopen-offset \
tst-dlmopen1 tst-dlmopen3 \
unload3 unload4 unload5 unload6 unload7 unload8 tst-global1 order2 \
tst-audit1 tst-audit2 tst-audit8 tst-audit9 \
@@ -277,6 +278,7 @@ modules-names = testobj1 testobj2 testobj3 testobj4 testobj5 testobj6 \
tst-audit12mod1 tst-audit12mod2 tst-audit12mod3 tst-auditmod12 \
tst-latepthreadmod $(tst-tls-many-dynamic-modules) \
tst-nodelete-dlclose-dso tst-nodelete-dlclose-plugin \
+ tst-dlopen-offset-mod1 tst-dlopen-offset-mod2 tst-dlopen-offset-mod3 \
tst-main1mod tst-libc_dlvsym-dso
ifeq (yes,$(have-mtls-dialect-gnu2))
tests += tst-gnu2-tls1
@@ -1457,3 +1459,10 @@ $(objpfx)tst-libc_dlvsym-static: $(common-objpfx)dlfcn/libdl.a
tst-libc_dlvsym-static-ENV = \
LD_LIBRARY_PATH=$(objpfx):$(common-objpfx):$(common-objpfx)dlfcn
$(objpfx)tst-libc_dlvsym-static.out: $(objpfx)tst-libc_dlvsym-dso.so
+
+$(objpfx)tst-dlopen-offset: $(libdl)
+$(objpfx)tst-dlopen-offset.out: $(objpfx)tst-dlopen-offset-comb.so
+$(objpfx)tst-dlopen-offset-comb.so: $(objpfx)tst-dlopen-offset-mod1.so $(objpfx)tst-dlopen-offset-mod2.so $(objpfx)tst-dlopen-offset-mod3.so
+ dd if=$(objpfx)tst-dlopen-offset-mod1.so of=$(objpfx)tst-dlopen-offset-comb.so bs=1024 seek=64
+ dd if=$(objpfx)tst-dlopen-offset-mod2.so of=$(objpfx)tst-dlopen-offset-comb.so bs=1024 seek=128
+ dd if=$(objpfx)tst-dlopen-offset-mod3.so of=$(objpfx)tst-dlopen-offset-comb.so bs=1024 seek=192
diff --git a/elf/tst-dlopen-offset-mod1.c b/elf/tst-dlopen-offset-mod1.c
new file mode 100644
index 0000000000..e46ced868f
--- /dev/null
+++ b/elf/tst-dlopen-offset-mod1.c
@@ -0,0 +1,15 @@
+#include <stdio.h>
+
+int
+foo (void)
+{
+ printf ("In %s:%s\n", __FILE__, __func__);
+ return 1;
+}
+
+int
+foosub (void)
+{
+ printf ("In %s:%s\n", __FILE__, __func__);
+ return 20;
+}
diff --git a/elf/tst-dlopen-offset-mod2.c b/elf/tst-dlopen-offset-mod2.c
new file mode 100644
index 0000000000..d126ae2fc1
--- /dev/null
+++ b/elf/tst-dlopen-offset-mod2.c
@@ -0,0 +1,8 @@
+#include <stdio.h>
+
+int
+bar (void)
+{
+ printf ("In %s:%s\n", __FILE__, __func__);
+ return 123;
+}
diff --git a/elf/tst-dlopen-offset-mod3.c b/elf/tst-dlopen-offset-mod3.c
new file mode 100644
index 0000000000..9916dc8101
--- /dev/null
+++ b/elf/tst-dlopen-offset-mod3.c
@@ -0,0 +1,8 @@
+#include <stdio.h>
+
+int
+xyzzy (void)
+{
+ printf ("In %s:%s\n", __FILE__, __func__);
+ return 21;
+}
diff --git a/elf/tst-dlopen-offset.c b/elf/tst-dlopen-offset.c
new file mode 100644
index 0000000000..78dd7ca892
--- /dev/null
+++ b/elf/tst-dlopen-offset.c
@@ -0,0 +1,144 @@
+#include <dlfcn.h>
+#include <stdio.h>
+
+/* These numbers need to be coordinated with the offsets passed to make the combined .so. */
+int offa = 64;
+int offb = 128;
+int offc = 192;
+
+int
+do_test (void)
+{
+ void *p1 = __google_dlopen_with_offset ("$ORIGIN/tst-dlopen-offset-comb.so", offa * 1024, RTLD_LAZY);
+
+ if (!p1)
+ {
+ puts (dlerror ());
+ return 1;
+ }
+
+ int (*f) (void) = dlsym (p1, "foo");
+ if (f)
+ {
+ (*f)();
+ }
+ else
+ {
+ puts (dlerror ());
+ return 1;
+ }
+
+ void *p2 = __google_dlopen_with_offset ("$ORIGIN/tst-dlopen-offset-comb.so", offb * 1024, RTLD_LAZY);
+
+ int (*bar) (void) = dlsym (p2, "bar");
+ if (bar)
+ {
+ (*bar)();
+ }
+ else
+ {
+ puts (dlerror ());
+ return 1;
+ }
+
+ void *p3 = __google_dlopen_with_offset ("$ORIGIN/tst-dlopen-offset-comb.so", offc * 1024, RTLD_LAZY);
+
+ int (*xyzzy) (void) = dlsym (p3, "xyzzy");
+ if (xyzzy)
+ {
+ (*xyzzy)();
+ }
+ else
+ {
+ puts (dlerror ());
+ return 1;
+ }
+
+ if (p1)
+ dlclose (p1);
+
+ p1 = __google_dlopen_with_offset ("$ORIGIN/tst-dlopen-offset-comb.so", offa * 1024, RTLD_LAZY);
+
+ f = dlsym (p1, "someothersym");
+ if (!f)
+ {
+ puts (dlerror ());
+ puts (" (expected)");
+ }
+ else
+ {
+ puts ("Symbol found unexpectedly");
+ return 1;
+ }
+
+ f = dlsym (p1, "xyzzy");
+ if (!f)
+ {
+ puts (dlerror ());
+ puts (" (expected)");
+ }
+ else
+ {
+ puts ("Symbol found unexpectedly");
+ return 1;
+ }
+
+ p1 = __google_dlopen_with_offset ("$ORIGIN/tst-dlopen-offset-comb.so", offa * 1024, RTLD_LAZY);
+
+ f = dlsym (p1, "foo");
+ if (f)
+ {
+ (*f)();
+ }
+ else
+ {
+ puts (dlerror ());
+ return 1;
+ }
+
+ void *px = __google_dlopen_with_offset ("$ORIGIN/tst-dlopen-offset-comb.so", 0, RTLD_LAZY);
+
+ if (!px)
+ {
+ puts (dlerror ());
+ puts (" (expected)");
+ }
+ else
+ {
+ puts ("dlopen_with_offset succeeded unexpectedly");
+ return 1;
+ }
+
+ px = __google_dlopen_with_offset ("$ORIGIN/tst-dlopen-offset-mod1.so", 0, RTLD_LAZY);
+
+ f = dlsym (px, "foo");
+ if (f)
+ {
+ (*f)();
+ }
+ else
+ {
+ puts (dlerror ());
+ return 1;
+ }
+
+ px = __google_dlopen_with_offset ("$ORIGIN/nonexistent.so", 0, RTLD_LAZY);
+
+ if (!px)
+ {
+ puts (dlerror ());
+ puts (" (expected)");
+ }
+ else
+ {
+ puts ("dlopen_with_offset succeeded unexpectedly");
+ return 1;
+ }
+
+ return 0;
+}
+
+#define TIMEOUT 100
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-08-28 0:41 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-28 0:41 [glibc/google/grte/v5-2.27/master] Add basic testsuite for dlopen_with_offset Fangrui Song
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).