summaryrefslogtreecommitdiff
path: root/regress
diff options
context:
space:
mode:
authorKurt Miller <kurt@cvs.openbsd.org>2005-09-15 22:16:28 +0000
committerKurt Miller <kurt@cvs.openbsd.org>2005-09-15 22:16:28 +0000
commit5497e686c8e251cfa2e48e6634925f7585a2f941 (patch)
tree1830510281e22ae2becae2d3b41a660b16aec4a5 /regress
parent412b8858d226637856e09d97b6535b7e85cb2a96 (diff)
add more complex tests for dlsym. some tests may change after more
discussion.
Diffstat (limited to 'regress')
-rw-r--r--regress/libexec/ld.so/dlsym/test2/Makefile5
-rw-r--r--regress/libexec/ld.so/dlsym/test2/Makefile.inc22
-rw-r--r--regress/libexec/ld.so/dlsym/test2/libaa/Makefile3
-rw-r--r--regress/libexec/ld.so/dlsym/test2/libaa/aa.c19
-rw-r--r--regress/libexec/ld.so/dlsym/test2/libaa/shlib_version2
-rw-r--r--regress/libexec/ld.so/dlsym/test2/libbb/Makefile16
-rw-r--r--regress/libexec/ld.so/dlsym/test2/libbb/bb.c97
-rw-r--r--regress/libexec/ld.so/dlsym/test2/libbb/shlib_version2
-rw-r--r--regress/libexec/ld.so/dlsym/test2/libcc/Makefile3
-rw-r--r--regress/libexec/ld.so/dlsym/test2/libcc/cc.c22
-rw-r--r--regress/libexec/ld.so/dlsym/test2/libcc/shlib_version2
-rw-r--r--regress/libexec/ld.so/dlsym/test2/prog1/Makefile9
-rw-r--r--regress/libexec/ld.so/dlsym/test2/prog1/main.c74
-rw-r--r--regress/libexec/ld.so/dlsym/test2/prog2/Makefile9
-rw-r--r--regress/libexec/ld.so/dlsym/test2/prog2/main.c42
-rw-r--r--regress/libexec/ld.so/dlsym/test2/prog3/Makefile9
-rw-r--r--regress/libexec/ld.so/dlsym/test2/prog3/main.c75
17 files changed, 411 insertions, 0 deletions
diff --git a/regress/libexec/ld.so/dlsym/test2/Makefile b/regress/libexec/ld.so/dlsym/test2/Makefile
new file mode 100644
index 00000000000..d2c8f18f9fd
--- /dev/null
+++ b/regress/libexec/ld.so/dlsym/test2/Makefile
@@ -0,0 +1,5 @@
+# $OpenBSD: Makefile,v 1.1 2005/09/15 22:16:27 kurt Exp $
+
+SUBDIR+= libcc libbb libaa prog1 prog2 prog3
+
+.include <bsd.subdir.mk>
diff --git a/regress/libexec/ld.so/dlsym/test2/Makefile.inc b/regress/libexec/ld.so/dlsym/test2/Makefile.inc
new file mode 100644
index 00000000000..ac94979fffb
--- /dev/null
+++ b/regress/libexec/ld.so/dlsym/test2/Makefile.inc
@@ -0,0 +1,22 @@
+# $OpenBSD: Makefile.inc,v 1.1 2005/09/15 22:16:27 kurt Exp $
+
+.include <bsd.obj.mk>
+
+AA_DIR=${.CURDIR}/../libaa
+
+AA_OBJDIR!= if [ -d $(AA_DIR)/${__objdir} ]; then \
+ echo "$(AA_DIR)/${__objdir}"; \
+ else \
+ echo "$(AA_DIR)"; \
+ fi
+
+BB_DIR=${.CURDIR}/../libbb
+
+BB_OBJDIR!= if [ -d $(BB_DIR)/${__objdir} ]; then \
+ echo "$(BB_DIR)/${__objdir}"; \
+ else \
+ echo "$(BB_DIR)"; \
+ fi
+
+run-regress-${PROG}: ${PROG}
+ LD_LIBRARY_PATH=$(BB_OBJDIR) ./${PROG}
diff --git a/regress/libexec/ld.so/dlsym/test2/libaa/Makefile b/regress/libexec/ld.so/dlsym/test2/libaa/Makefile
new file mode 100644
index 00000000000..0c867307e08
--- /dev/null
+++ b/regress/libexec/ld.so/dlsym/test2/libaa/Makefile
@@ -0,0 +1,3 @@
+LIB=aa
+SRCS= aa.c
+.include <bsd.lib.mk>
diff --git a/regress/libexec/ld.so/dlsym/test2/libaa/aa.c b/regress/libexec/ld.so/dlsym/test2/libaa/aa.c
new file mode 100644
index 00000000000..62fe34ebd9f
--- /dev/null
+++ b/regress/libexec/ld.so/dlsym/test2/libaa/aa.c
@@ -0,0 +1,19 @@
+/* $OpenBSD: aa.c,v 1.1.1.1 2005/09/15 22:16:27 kurt Exp $ */
+
+/*
+ * Copyright (c) 2005 Kurt Miller <kurt@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+int aaSymbol;
diff --git a/regress/libexec/ld.so/dlsym/test2/libaa/shlib_version b/regress/libexec/ld.so/dlsym/test2/libaa/shlib_version
new file mode 100644
index 00000000000..987ef746955
--- /dev/null
+++ b/regress/libexec/ld.so/dlsym/test2/libaa/shlib_version
@@ -0,0 +1,2 @@
+major=1
+minor=0
diff --git a/regress/libexec/ld.so/dlsym/test2/libbb/Makefile b/regress/libexec/ld.so/dlsym/test2/libbb/Makefile
new file mode 100644
index 00000000000..73bc8aae150
--- /dev/null
+++ b/regress/libexec/ld.so/dlsym/test2/libbb/Makefile
@@ -0,0 +1,16 @@
+# $OpenBSD: Makefile,v 1.1 2005/09/15 22:16:27 kurt Exp $
+
+.include <bsd.obj.mk>
+
+CC_DIR=${.CURDIR}/../libcc
+
+CC_OBJDIR!= if [ -d $(CC_DIR)/${__objdir} ]; then \
+ echo "$(CC_DIR)/${__objdir}"; \
+ else \
+ echo "$(CC_DIR)"; \
+ fi
+
+LIB=bb
+SRCS= bb.c
+LDADD= -Wl,-E -Wl,-rpath,$(CC_OBJDIR) -L$(CC_OBJDIR) -lcc
+.include <bsd.lib.mk>
diff --git a/regress/libexec/ld.so/dlsym/test2/libbb/bb.c b/regress/libexec/ld.so/dlsym/test2/libbb/bb.c
new file mode 100644
index 00000000000..f6c98cfdde6
--- /dev/null
+++ b/regress/libexec/ld.so/dlsym/test2/libbb/bb.c
@@ -0,0 +1,97 @@
+/* $OpenBSD: bb.c,v 1.1 2005/09/15 22:16:27 kurt Exp $ */
+
+/*
+ * Copyright (c) 2005 Kurt Miller <kurt@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <dlfcn.h>
+#include <stdio.h>
+
+int bbSymbol;
+
+/*
+ * bbTest1 checks dlsym symbol visibility from a single dlopened object
+ * group that looks like libbb -> libcc. This was opened from libaa in
+ * the main object group. So the default search order will be prog2 ->
+ * libaa -> libbb -> libcc. only dlsym(RTLD_DEFAULT,...) should see
+ * symbols in prog2 and libaa. the rest are limited to libbb and libcc.
+ */
+int
+bbTest1(void *libbb)
+{
+ int ret = 0;
+
+ /* check RTLD_DEFAULT can see symbols in main object group */
+ if (dlsym(RTLD_DEFAULT, "mainSymbol") == NULL) {
+ printf("dlsym(RTLD_DEFAULT, \"mainSymbol\") == NULL\n");
+ ret = -1;
+ }
+
+ /* check RTLD_SELF can *not* see symbols in main object group */
+ if (dlsym(RTLD_SELF, "aaSymbol") != NULL) {
+ printf("dlsym(RTLD_SELF, \"aaSymbol\") != NULL\n");
+ ret = -1;
+ }
+
+ /* check RTLD_NEXT can *not* see symbols in main object group */
+ if (dlsym(RTLD_NEXT, "aaSymbol") != NULL) {
+ printf("dlsym(RTLD_NEXT, \"aaSymbol\") != NULL\n");
+ ret = -1;
+ }
+
+ /* check NULL can *not* see symbols in main object group */
+ if (dlsym(NULL, "aaSymbol") != NULL) {
+ printf("dlsym(NULL, \"aaSymbol\") != NULL\n");
+ ret = -1;
+ }
+
+ /* check RTLD_SELF can see symbols in local object group */
+ if (dlsym(RTLD_SELF, "ccSymbol") == NULL) {
+ printf("dlsym(RTLD_SELF, \"ccSymbol\") == NULL\n");
+ ret = -1;
+ }
+
+ /* check RTLD_NEXT can see symbols in local object group */
+ if (dlsym(RTLD_NEXT, "ccSymbol") == NULL) {
+ printf("dlsym(RTLD_NEXT, \"ccSymbol\") == NULL\n");
+ ret = -1;
+ }
+
+ /* check NULL can see symbols in local object group */
+ if (dlsym(NULL, "ccSymbol") == NULL) {
+ printf("dlsym(NULL, \"ccSymbol\") == NULL\n");
+ ret = -1;
+ }
+
+ /* check RTLD_NEXT skips libbb and can't find bbSymbol */
+ if (dlsym(RTLD_NEXT, "bbSymbol") != NULL) {
+ printf("dlsym(RTLD_NEXT, \"bbSymbol\") != NULL\n");
+ ret = -1;
+ }
+
+ /* check dlsym(libbb,..) can *not* see symbols in libaa */
+ if (dlsym(libbb, "aaSymbol") != NULL) {
+ printf("dlsym(libbb, \"aaSymbol\") != NULL\n");
+ ret = -1;
+ }
+
+ /* check dlsym(libbb,..) can see symbols in libcc */
+ if (dlsym(libbb, "ccSymbol") == NULL) {
+ printf("dlsym(libbb, \"ccSymbol\") == NULL\n");
+ ret = -1;
+ }
+
+ return (ret);
+}
diff --git a/regress/libexec/ld.so/dlsym/test2/libbb/shlib_version b/regress/libexec/ld.so/dlsym/test2/libbb/shlib_version
new file mode 100644
index 00000000000..987ef746955
--- /dev/null
+++ b/regress/libexec/ld.so/dlsym/test2/libbb/shlib_version
@@ -0,0 +1,2 @@
+major=1
+minor=0
diff --git a/regress/libexec/ld.so/dlsym/test2/libcc/Makefile b/regress/libexec/ld.so/dlsym/test2/libcc/Makefile
new file mode 100644
index 00000000000..f29ad1eb83b
--- /dev/null
+++ b/regress/libexec/ld.so/dlsym/test2/libcc/Makefile
@@ -0,0 +1,3 @@
+LIB=cc
+SRCS= cc.c
+.include <bsd.lib.mk>
diff --git a/regress/libexec/ld.so/dlsym/test2/libcc/cc.c b/regress/libexec/ld.so/dlsym/test2/libcc/cc.c
new file mode 100644
index 00000000000..2690904eecb
--- /dev/null
+++ b/regress/libexec/ld.so/dlsym/test2/libcc/cc.c
@@ -0,0 +1,22 @@
+/* $OpenBSD: cc.c,v 1.1 2005/09/15 22:16:27 kurt Exp $ */
+
+/*
+ * Copyright (c) 2005 Kurt Miller <kurt@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <dlfcn.h>
+#include <stdio.h>
+
+int ccSymbol;
diff --git a/regress/libexec/ld.so/dlsym/test2/libcc/shlib_version b/regress/libexec/ld.so/dlsym/test2/libcc/shlib_version
new file mode 100644
index 00000000000..987ef746955
--- /dev/null
+++ b/regress/libexec/ld.so/dlsym/test2/libcc/shlib_version
@@ -0,0 +1,2 @@
+major=1
+minor=0
diff --git a/regress/libexec/ld.so/dlsym/test2/prog1/Makefile b/regress/libexec/ld.so/dlsym/test2/prog1/Makefile
new file mode 100644
index 00000000000..2fbbf1322f9
--- /dev/null
+++ b/regress/libexec/ld.so/dlsym/test2/prog1/Makefile
@@ -0,0 +1,9 @@
+# $OpenBSD: Makefile,v 1.1 2005/09/15 22:16:27 kurt Exp $
+
+.include <../Makefile.inc>
+
+PROG= prog1
+SRCS= main.c
+LDADD= -Wl,-E -Wl,-rpath,$(AA_OBJDIR) -L$(AA_OBJDIR) -laa
+
+.include <bsd.regress.mk>
diff --git a/regress/libexec/ld.so/dlsym/test2/prog1/main.c b/regress/libexec/ld.so/dlsym/test2/prog1/main.c
new file mode 100644
index 00000000000..10cd73a06ae
--- /dev/null
+++ b/regress/libexec/ld.so/dlsym/test2/prog1/main.c
@@ -0,0 +1,74 @@
+/* $OpenBSD: main.c,v 1.1 2005/09/15 22:16:27 kurt Exp $ */
+
+/*
+ * Copyright (c) 2005 Kurt Miller <kurt@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <dlfcn.h>
+#include <stdio.h>
+
+int mainSymbol;
+
+/*
+ * This tests that the main object group can not see the symbols in
+ * objects dlopened by it using RTLD_{SELF,NEXT}, NULL and with a handle.
+ */
+int
+main()
+{
+ int ret = 0;
+ void *exe_handle = dlopen(NULL, RTLD_LAZY);
+ void *libbb = dlopen("libbb.so", RTLD_LAZY);
+
+ if (libbb == NULL) {
+ printf("dlopen(\"libbb.so\", RTLD_LAZY) FAILED\n");
+ return (-1);
+ }
+
+ /* RTLD_DEFAULT should see bbSymbol */
+ if (dlsym(RTLD_DEFAULT, "bbSymbol") == NULL) {
+ printf("dlsym(RTLD_DEFAULT, \"bbSymbol\") == NULL\n");
+ ret = -1;
+ }
+
+ /* RTLD_SELF should *not* see bbSymbol (different load group) */
+ if (dlsym(RTLD_SELF, "bbSymbol") != NULL) {
+ printf("dlsym(RTLD_SELF, \"bbSymbol\") != NULL\n");
+ ret = -1;
+ }
+
+ /* RTLD_NEXT should *not* see bbSymbol (different load group) */
+ if (dlsym(RTLD_NEXT, "bbSymbol") != NULL) {
+ printf("dlsym(RTLD_NEXT, \"bbSymbol\") != NULL\n");
+ ret = -1;
+ }
+
+ /* NULL should *not* see bbSymbol (different load group) */
+ if (dlsym(NULL, "bbSymbol") != NULL) {
+ printf("dlsym(NULL, \"bbSymbol\") != NULL\n");
+ ret = -1;
+ }
+
+ /* exe handle should *not* see bbSymbol (different load group) */
+ if (dlsym(exe_handle, "bbSymbol") != NULL) {
+ printf("dlsym(exe_handle, \"bbSymbol\") != NULL\n");
+ ret = -1;
+ }
+
+ dlclose(exe_handle);
+ dlclose(libbb);
+
+ return (ret);
+}
diff --git a/regress/libexec/ld.so/dlsym/test2/prog2/Makefile b/regress/libexec/ld.so/dlsym/test2/prog2/Makefile
new file mode 100644
index 00000000000..fe86ca612ab
--- /dev/null
+++ b/regress/libexec/ld.so/dlsym/test2/prog2/Makefile
@@ -0,0 +1,9 @@
+# $OpenBSD: Makefile,v 1.1 2005/09/15 22:16:27 kurt Exp $
+
+.include <../Makefile.inc>
+
+PROG= prog2
+SRCS= main.c
+LDADD= -Wl,-E -Wl,-rpath,$(AA_OBJDIR) -L$(AA_OBJDIR) -laa
+
+.include <bsd.regress.mk>
diff --git a/regress/libexec/ld.so/dlsym/test2/prog2/main.c b/regress/libexec/ld.so/dlsym/test2/prog2/main.c
new file mode 100644
index 00000000000..fc007ebc6b2
--- /dev/null
+++ b/regress/libexec/ld.so/dlsym/test2/prog2/main.c
@@ -0,0 +1,42 @@
+/* $OpenBSD: main.c,v 1.1 2005/09/15 22:16:27 kurt Exp $ */
+
+/*
+ * Copyright (c) 2005 Kurt Miller <kurt@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <dlfcn.h>
+#include <stdio.h>
+
+int mainSymbol;
+
+int
+main()
+{
+ int ret = 0;
+ void *libbb = dlopen("libbb.so", RTLD_LAZY);
+
+ if (libbb == NULL) {
+ printf("dlopen(\"libbb.so\", RTLD_LAZY) FAILED\n");
+ return (-1);
+ }
+
+ int (*bbTest1)(void *) = dlsym(libbb, "bbTest1");
+
+ ret = (*bbTest1)(libbb);
+
+ dlclose(libbb);
+
+ return (ret);
+}
diff --git a/regress/libexec/ld.so/dlsym/test2/prog3/Makefile b/regress/libexec/ld.so/dlsym/test2/prog3/Makefile
new file mode 100644
index 00000000000..69b61832b45
--- /dev/null
+++ b/regress/libexec/ld.so/dlsym/test2/prog3/Makefile
@@ -0,0 +1,9 @@
+# $OpenBSD: Makefile,v 1.1 2005/09/15 22:16:27 kurt Exp $
+
+.include <../Makefile.inc>
+
+PROG= prog3
+SRCS= main.c
+LDADD= -Wl,-E -Wl,-rpath,$(AA_OBJDIR) -L$(AA_OBJDIR) -laa
+
+.include <bsd.regress.mk>
diff --git a/regress/libexec/ld.so/dlsym/test2/prog3/main.c b/regress/libexec/ld.so/dlsym/test2/prog3/main.c
new file mode 100644
index 00000000000..c23e95850b2
--- /dev/null
+++ b/regress/libexec/ld.so/dlsym/test2/prog3/main.c
@@ -0,0 +1,75 @@
+/* $OpenBSD: main.c,v 1.1 2005/09/15 22:16:27 kurt Exp $ */
+
+/*
+ * Copyright (c) 2005 Kurt Miller <kurt@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <dlfcn.h>
+#include <stdio.h>
+
+int mainSymbol;
+
+/*
+ * This tests that the main object group can see the symbols in
+ * objects dlopened with RTLD_GLOBAL for RTLD_{DEFAULT,NEXT,SELF},
+ * but not with NULL, or with a handle.
+ */
+int
+main()
+{
+ int ret = 0;
+ void *exe_handle = dlopen(NULL, RTLD_LAZY);
+ void *libbb = dlopen("libbb.so", RTLD_LAZY|RTLD_GLOBAL);
+
+ if (libbb == NULL) {
+ printf("dlopen(\"libbb.so\", RTLD_LAZY|RTLD_GLOBAL) FAILED\n");
+ return (-1);
+ }
+
+ /* RTLD_DEFAULT should see bbSymbol */
+ if (dlsym(RTLD_DEFAULT, "bbSymbol") == NULL) {
+ printf("dlsym(RTLD_DEFAULT, \"bbSymbol\") == NULL\n");
+ ret = -1;
+ }
+
+ /* RTLD_SELF should see bbSymbol (RTLD_GLOBAL load group) */
+ if (dlsym(RTLD_SELF, "bbSymbol") == NULL) {
+ printf("dlsym(RTLD_SELF, \"bbSymbol\") == NULL\n");
+ ret = -1;
+ }
+
+ /* RTLD_NEXT should see bbSymbol (RTLD_GLOBAL load group) */
+ if (dlsym(RTLD_NEXT, "bbSymbol") == NULL) {
+ printf("dlsym(RTLD_NEXT, \"bbSymbol\") == NULL\n");
+ ret = -1;
+ }
+
+ /* NULL should *not* see bbSymbol (different load group) */
+ if (dlsym(NULL, "bbSymbol") != NULL) {
+ printf("dlsym(NULL, \"bbSymbol\") != NULL\n");
+ ret = -1;
+ }
+
+ /* exe handle should *not* see bbSymbol (different load group) */
+ if (dlsym(exe_handle, "bbSymbol") != NULL) {
+ printf("dlsym(exe_handle, \"bbSymbol\") != NULL\n");
+ ret = -1;
+ }
+
+ dlclose(exe_handle);
+ dlclose(libbb);
+
+ return (ret);
+}