summaryrefslogtreecommitdiff
path: root/test/ldso
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2001-06-29 22:48:24 +0000
committerEric Andersen <andersen@codepoet.org>2001-06-29 22:48:24 +0000
commitd9ea262db5f34295c2ad4c42559faf958abccf1b (patch)
treeaa29097e1564112b7caa21bfa5ccd1faaf332a98 /test/ldso
parent2f98c4258bada4b7de8dc4401dded43ade7f1c60 (diff)
Add a dlopen test
Diffstat (limited to 'test/ldso')
-rw-r--r--test/ldso/Makefile20
-rw-r--r--test/ldso/dltest.c39
-rw-r--r--test/ldso/howdy.c7
3 files changed, 66 insertions, 0 deletions
diff --git a/test/ldso/Makefile b/test/ldso/Makefile
new file mode 100644
index 000000000..3131a715a
--- /dev/null
+++ b/test/ldso/Makefile
@@ -0,0 +1,20 @@
+TESTDIR=../
+include $(TESTDIR)/Rules.mak
+
+all: dltest shared run
+
+dltest:
+ $(TESTCC) $(TEST_CFLAGS) -c dltest.c -o dltest.o
+ $(TESTCC) $(TEST_CFLAGS) -c howdy.c -o howdy.o
+
+shared:
+ $(TESTCC) $(TEST_CFLAGS) -shared -o libhowdy.so -Wl,-soname,libhowdy.so howdy.o
+ $(TESTCC) $(TEST_CFLAGS) -o dltest dltest.o -ldl
+
+run:
+ @echo Running dltest
+ ./dltest
+
+clean:
+ rm -f *.o *.so dltest core
+
diff --git a/test/ldso/dltest.c b/test/ldso/dltest.c
new file mode 100644
index 000000000..676e1ae55
--- /dev/null
+++ b/test/ldso/dltest.c
@@ -0,0 +1,39 @@
+#include <fcntl.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <dlfcn.h>
+
+extern void _dlinfo();
+
+int main(int argc, char **argv) {
+ void *handle;
+ int (*myhowdy)(const char *s);
+ char *error;
+
+#ifdef __UCLIBC__
+ _dlinfo(); /* not supported by ld.so.2 */
+#endif
+
+ handle = dlopen ("./libhowdy.so", RTLD_LAZY);
+
+ if (!handle) {
+ fputs (dlerror(), stderr);
+ exit(1);
+ }
+
+ myhowdy = dlsym(handle, "howdy");
+ if ((error = dlerror()) != NULL) {
+ fputs(error, stderr);
+ exit(1);
+ }
+
+ myhowdy("hello world!\n");
+
+#ifdef __UCLIBC__
+ _dlinfo(); /* not supported by ld.so.2 */
+#endif
+
+ dlclose(handle);
+
+ return EXIT_SUCCESS;
+}
diff --git a/test/ldso/howdy.c b/test/ldso/howdy.c
new file mode 100644
index 000000000..00a144b30
--- /dev/null
+++ b/test/ldso/howdy.c
@@ -0,0 +1,7 @@
+#include <stdio.h>
+
+int howdy(const char *s)
+{
+ return printf("howdy: %s\n", s);
+}
+