summaryrefslogtreecommitdiff
path: root/regress/libexec/ld.so
diff options
context:
space:
mode:
authorMatthieu Herrb <matthieu@cvs.openbsd.org>2008-01-02 18:37:00 +0000
committerMatthieu Herrb <matthieu@cvs.openbsd.org>2008-01-02 18:37:00 +0000
commit3b012d66113430740c600ed7c90dc077ef2baea7 (patch)
tree2f6a809bbe4ab5f9c084bcc00422cff160c6c7a7 /regress/libexec/ld.so
parent55d7cbba94b38ffd71c55b2ed72c2ac03c06cb25 (diff)
regression test for lazy binding.
"people need never hold off on adding stuff to regress" deraadt@
Diffstat (limited to 'regress/libexec/ld.so')
-rw-r--r--regress/libexec/ld.so/lazy/Makefile7
-rw-r--r--regress/libexec/ld.so/lazy/libbar/Makefile8
-rw-r--r--regress/libexec/ld.so/lazy/libbar/bar.c11
-rw-r--r--regress/libexec/ld.so/lazy/libbar/shlib_version2
-rw-r--r--regress/libexec/ld.so/lazy/libfoo/Makefile18
-rw-r--r--regress/libexec/ld.so/lazy/libfoo/foo.c26
-rw-r--r--regress/libexec/ld.so/lazy/libfoo/shlib_version2
-rw-r--r--regress/libexec/ld.so/lazy/prog/Makefile15
-rw-r--r--regress/libexec/ld.so/lazy/prog/prog.c29
9 files changed, 118 insertions, 0 deletions
diff --git a/regress/libexec/ld.so/lazy/Makefile b/regress/libexec/ld.so/lazy/Makefile
new file mode 100644
index 00000000000..7250aeb59c9
--- /dev/null
+++ b/regress/libexec/ld.so/lazy/Makefile
@@ -0,0 +1,7 @@
+# $OpenBSD: Makefile,v 1.1.1.1 2008/01/02 18:36:59 matthieu Exp $
+
+SUBDIR += libfoo libbar prog
+
+install:
+
+.include <bsd.subdir.mk>
diff --git a/regress/libexec/ld.so/lazy/libbar/Makefile b/regress/libexec/ld.so/lazy/libbar/Makefile
new file mode 100644
index 00000000000..9e0c88f762b
--- /dev/null
+++ b/regress/libexec/ld.so/lazy/libbar/Makefile
@@ -0,0 +1,8 @@
+# $OpenBSD: Makefile,v 1.1.1.1 2008/01/02 18:36:59 matthieu Exp $
+
+LIB= bar
+SRCS= bar.c
+
+regress: all
+
+.include <bsd.lib.mk>
diff --git a/regress/libexec/ld.so/lazy/libbar/bar.c b/regress/libexec/ld.so/lazy/libbar/bar.c
new file mode 100644
index 00000000000..8121a302369
--- /dev/null
+++ b/regress/libexec/ld.so/lazy/libbar/bar.c
@@ -0,0 +1,11 @@
+/* $OpenBSD: bar.c,v 1.1.1.1 2008/01/02 18:36:59 matthieu Exp $ */
+/* Public Domain, 2008, Matthieu Herrb */
+
+#include <stdio.h>
+
+int
+bar(void)
+{
+ printf("bar\n");
+ return 0;
+}
diff --git a/regress/libexec/ld.so/lazy/libbar/shlib_version b/regress/libexec/ld.so/lazy/libbar/shlib_version
new file mode 100644
index 00000000000..97c9f92d6b8
--- /dev/null
+++ b/regress/libexec/ld.so/lazy/libbar/shlib_version
@@ -0,0 +1,2 @@
+major=0
+minor=0
diff --git a/regress/libexec/ld.so/lazy/libfoo/Makefile b/regress/libexec/ld.so/lazy/libfoo/Makefile
new file mode 100644
index 00000000000..73761a60432
--- /dev/null
+++ b/regress/libexec/ld.so/lazy/libfoo/Makefile
@@ -0,0 +1,18 @@
+# $OpenBSD: Makefile,v 1.1.1.1 2008/01/02 18:36:59 matthieu Exp $
+
+.include <bsd.obj.mk>
+
+LIB= foo
+SRCS= foo.c
+
+BARDIR!= if test -d ${.CURDIR}/../libbar/${__objdir}; then \
+ echo "${.CURDIR}/../libbar/${__objdir}"; \
+ else \
+ echo "${.CURDIR}/../libbar"; \
+ fi
+
+CPPFLAGS= -DBAR=\"${BARDIR}/libbar.so\"
+
+regress: all
+
+.include <bsd.lib.mk>
diff --git a/regress/libexec/ld.so/lazy/libfoo/foo.c b/regress/libexec/ld.so/lazy/libfoo/foo.c
new file mode 100644
index 00000000000..39f9214448d
--- /dev/null
+++ b/regress/libexec/ld.so/lazy/libfoo/foo.c
@@ -0,0 +1,26 @@
+/* $OpenBSD: foo.c,v 1.1.1.1 2008/01/02 18:36:59 matthieu Exp $ */
+/* Public domain. 2008, Matthieu Herrb */
+
+#include <dlfcn.h>
+#include <stdio.h>
+
+static void *h = NULL;
+
+void
+foo_init(void)
+{
+ printf("loading %s\n", BAR);
+ h = dlopen(BAR, RTLD_LAZY|RTLD_GLOBAL);
+ if (h == NULL)
+ errx(1, "dlopen %s: %s\n", BAR, dlerror());
+ printf("loaded: %s\n", BAR);
+}
+
+int
+foo(void)
+{
+ if (h == NULL)
+ foo_init();
+
+ return bar();
+}
diff --git a/regress/libexec/ld.so/lazy/libfoo/shlib_version b/regress/libexec/ld.so/lazy/libfoo/shlib_version
new file mode 100644
index 00000000000..97c9f92d6b8
--- /dev/null
+++ b/regress/libexec/ld.so/lazy/libfoo/shlib_version
@@ -0,0 +1,2 @@
+major=0
+minor=0
diff --git a/regress/libexec/ld.so/lazy/prog/Makefile b/regress/libexec/ld.so/lazy/prog/Makefile
new file mode 100644
index 00000000000..3f7e1f00ed6
--- /dev/null
+++ b/regress/libexec/ld.so/lazy/prog/Makefile
@@ -0,0 +1,15 @@
+# $OpenBSD: Makefile,v 1.1.1.1 2008/01/02 18:36:59 matthieu Exp $
+
+.include <bsd.obj.mk>
+
+PROG= prog
+
+FOODIR!= if test -d ${.CURDIR}/../libfoo/${__objdir}; then \
+ echo "${.CURDIR}/../libfoo/${__objdir}"; \
+ else \
+ echo "${.CURDIR}/../libfoo"; \
+ fi
+
+CPPFLAGS= -DFOO=\"${FOODIR}/libfoo.so\"
+
+.include <bsd.regress.mk>
diff --git a/regress/libexec/ld.so/lazy/prog/prog.c b/regress/libexec/ld.so/lazy/prog/prog.c
new file mode 100644
index 00000000000..285a8c94d98
--- /dev/null
+++ b/regress/libexec/ld.so/lazy/prog/prog.c
@@ -0,0 +1,29 @@
+/* $OpenBSD: prog.c,v 1.1.1.1 2008/01/02 18:36:59 matthieu Exp $ */
+/* Public Domain, 2008, Matthieu Herrb */
+
+#include <dlfcn.h>
+#include <stdio.h>
+
+void *handle = NULL;
+
+typedef int (*foofunc)(void);
+
+int
+main(int argc, char *argv[])
+{
+ foofunc foo;
+ int i;
+
+ printf("loading: %s\n", FOO);
+ handle = dlopen(FOO, RTLD_LAZY|RTLD_GLOBAL);
+ if (handle == NULL) {
+ errx(1, "dlopen: %s: %s\n", FOO, dlerror());
+ }
+ printf("loaded: %s\n", FOO);
+ printf("looking up foo\n");
+ foo = (foofunc)dlsym(handle, "foo");
+ printf("found %p - calling it\n", foo);
+ i = foo();
+ printf("done.\n");
+ exit(i);
+}