diff options
author | Stan Shebs <stanshebs@google.com> | 2018-03-29 11:48:37 -0700 |
---|---|---|
committer | Stan Shebs <stanshebs@google.com> | 2018-03-29 11:48:37 -0700 |
commit | d57236debc46317a95c1741702252f4e44b90070 (patch) | |
tree | f2e5d1f57fff017c53403b8a50034e5538c1c97d | |
parent | 641cae4c36e4d34ebc14690f5db05b3330be46f5 (diff) | |
download | glibc-d57236debc46317a95c1741702252f4e44b90070.zip glibc-d57236debc46317a95c1741702252f4e44b90070.tar.gz glibc-d57236debc46317a95c1741702252f4e44b90070.tar.bz2 |
Add basic testsuite for dlopen_with_offset
-rw-r--r-- | elf/Makefile | 9 | ||||
-rw-r--r-- | elf/tst-dlopen-offset-mod1.c | 15 | ||||
-rw-r--r-- | elf/tst-dlopen-offset-mod2.c | 8 | ||||
-rw-r--r-- | elf/tst-dlopen-offset-mod3.c | 8 | ||||
-rw-r--r-- | elf/tst-dlopen-offset.c | 144 |
5 files changed, 184 insertions, 0 deletions
diff --git a/elf/Makefile b/elf/Makefile index f1fda1d..8f16690 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 0000000..e46ced8 --- /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 0000000..d126ae2 --- /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 0000000..9916dc8 --- /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 0000000..78dd7ca --- /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" |