summaryrefslogtreecommitdiff
path: root/regress/libexec
diff options
context:
space:
mode:
authorSebastien Marie <semarie@cvs.openbsd.org>2021-06-02 07:32:35 +0000
committerSebastien Marie <semarie@cvs.openbsd.org>2021-06-02 07:32:35 +0000
commitfb1d75e87a17d5bb2ad93b39386312bb56a2a485 (patch)
tree8f95800297abd04739053b5c5b9262bb99e5ad1d /regress/libexec
parent6aba35cb7390dc08a110c21478ea78f1597adba5 (diff)
add regress test for RTLD_NODELETE support
Diffstat (limited to 'regress/libexec')
-rw-r--r--regress/libexec/ld.so/Makefile4
-rw-r--r--regress/libexec/ld.so/nodelete/Makefile5
-rw-r--r--regress/libexec/ld.so/nodelete/liba/Makefile7
-rw-r--r--regress/libexec/ld.so/nodelete/liba/liba.c4
-rw-r--r--regress/libexec/ld.so/nodelete/liba/shlib_version2
-rw-r--r--regress/libexec/ld.so/nodelete/test1/Makefile13
-rw-r--r--regress/libexec/ld.so/nodelete/test1/test1.c60
7 files changed, 93 insertions, 2 deletions
diff --git a/regress/libexec/ld.so/Makefile b/regress/libexec/ld.so/Makefile
index dc5bb9abf52..1b169b5dc2f 100644
--- a/regress/libexec/ld.so/Makefile
+++ b/regress/libexec/ld.so/Makefile
@@ -1,10 +1,10 @@
-# $OpenBSD: Makefile,v 1.17 2016/09/27 06:52:50 kettenis Exp $
+# $OpenBSD: Makefile,v 1.18 2021/06/02 07:32:34 semarie Exp $
SUBDIR+= elf hidden weak dlsym dlopen dlclose lazy
SUBDIR+= constructor
SUBDIR+= link-order edgecases initfirst
SUBDIR+= df_1_noopen randomdata subst dependencies
-SUBDIR+= init-env
+SUBDIR+= init-env nodelete
install:
diff --git a/regress/libexec/ld.so/nodelete/Makefile b/regress/libexec/ld.so/nodelete/Makefile
new file mode 100644
index 00000000000..844d3474bd3
--- /dev/null
+++ b/regress/libexec/ld.so/nodelete/Makefile
@@ -0,0 +1,5 @@
+# $OpenBSD: Makefile,v 1.1 2021/06/02 07:32:34 semarie Exp $
+
+SUBDIR += liba test1
+
+.include <bsd.subdir.mk>
diff --git a/regress/libexec/ld.so/nodelete/liba/Makefile b/regress/libexec/ld.so/nodelete/liba/Makefile
new file mode 100644
index 00000000000..ae82bfad5e9
--- /dev/null
+++ b/regress/libexec/ld.so/nodelete/liba/Makefile
@@ -0,0 +1,7 @@
+# $OpenBSD: Makefile,v 1.1 2021/06/02 07:32:34 semarie Exp $
+
+LIB = a
+SRCS = liba.c
+
+.include <bsd.lib.mk>
+
diff --git a/regress/libexec/ld.so/nodelete/liba/liba.c b/regress/libexec/ld.so/nodelete/liba/liba.c
new file mode 100644
index 00000000000..cf3eb355578
--- /dev/null
+++ b/regress/libexec/ld.so/nodelete/liba/liba.c
@@ -0,0 +1,4 @@
+void
+function(void)
+{
+}
diff --git a/regress/libexec/ld.so/nodelete/liba/shlib_version b/regress/libexec/ld.so/nodelete/liba/shlib_version
new file mode 100644
index 00000000000..97c9f92d6b8
--- /dev/null
+++ b/regress/libexec/ld.so/nodelete/liba/shlib_version
@@ -0,0 +1,2 @@
+major=0
+minor=0
diff --git a/regress/libexec/ld.so/nodelete/test1/Makefile b/regress/libexec/ld.so/nodelete/test1/Makefile
new file mode 100644
index 00000000000..ed6efd7ffc7
--- /dev/null
+++ b/regress/libexec/ld.so/nodelete/test1/Makefile
@@ -0,0 +1,13 @@
+# $OpenBSD: Makefile,v 1.1 2021/06/02 07:32:34 semarie Exp $
+
+PROG = test1
+
+ADIR != if test -d ${.CURDIR}/../liba/${__objdir}; then \
+ echo "${.CURDIR}/../liba/${__objdir}"; \
+ else \
+ echo "${.CURDIR}/../liba"; \
+ fi
+
+CFLAGS += -DLIBNAME=\"${ADIR}/liba.so.0.0\"
+
+.include <bsd.regress.mk>
diff --git a/regress/libexec/ld.so/nodelete/test1/test1.c b/regress/libexec/ld.so/nodelete/test1/test1.c
new file mode 100644
index 00000000000..75dd8a5a826
--- /dev/null
+++ b/regress/libexec/ld.so/nodelete/test1/test1.c
@@ -0,0 +1,60 @@
+
+#include <err.h>
+#include <dlfcn.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#ifndef LIBNAME
+#error "LIBNAME undefined"
+#endif
+
+#ifndef SYMBOL
+#define SYMBOL "function"
+#endif
+
+int
+checksym(const char *name)
+{
+ void *sym = dlsym(RTLD_DEFAULT, name);
+
+ if (sym != NULL) {
+ printf("symbol present: %s\n", name);
+ return 1;
+ } else {
+ printf("symbol absent: %s\n", name);
+ return 0;
+ }
+}
+
+int
+main(int argc, char *argv[])
+{
+ void *h1;
+ void *h2;
+
+ /* symbol should not be here at startup */
+ if (checksym(SYMBOL) == 1)
+ errx(1, "symbol found: %s", SYMBOL);
+
+ printf("opening\n");
+ if ((h1 = dlopen(LIBNAME, RTLD_GLOBAL)) == NULL)
+ errx(1, "dlopen: h1: %s: %s", LIBNAME, dlerror());
+ if ((h2 = dlopen(LIBNAME, RTLD_GLOBAL|RTLD_NODELETE)) == NULL)
+ errx(1, "dlopen: h2: %s: %s", LIBNAME, dlerror());
+
+ /* symbol should be here after loading */
+ if (checksym(SYMBOL) == 0)
+ errx(1, "symbol not found: %s", SYMBOL);
+
+ printf("closing\n");
+ if (dlclose(h2) != 0)
+ errx(1, "dlclose: h2: %s", dlerror());
+ if (dlclose(h1) != 0)
+ errx(1, "dlclose: h1: %s", dlerror());
+
+ /* symbol should be still here, as one dlopen(3) had RTLD_NODELETE */
+ if (checksym(SYMBOL) == 0)
+ errx(1, "symbol not found: %s", SYMBOL);
+
+ return 0;
+}