summaryrefslogtreecommitdiff
path: root/libexec
diff options
context:
space:
mode:
Diffstat (limited to 'libexec')
-rw-r--r--libexec/Makefile12
-rw-r--r--libexec/Makefile.inc1
-rw-r--r--libexec/ld.elf_so/Makefile66
-rw-r--r--libexec/ld.elf_so/Makefile.inc1
-rw-r--r--libexec/ld.elf_so/data/Makefile28
-rw-r--r--libexec/ld.elf_so/data/symver-output-ref-stderr.v0-v00
-rw-r--r--libexec/ld.elf_so/data/symver-output-ref-stderr.v0-v10
-rw-r--r--libexec/ld.elf_so/data/symver-output-ref-stderr.v0-v20
-rw-r--r--libexec/ld.elf_so/data/symver-output-ref-stderr.v1-v01
-rw-r--r--libexec/ld.elf_so/data/symver-output-ref-stderr.v1-v10
-rw-r--r--libexec/ld.elf_so/data/symver-output-ref-stderr.v1-v20
-rw-r--r--libexec/ld.elf_so/data/symver-output-ref-stderr.v2-v01
-rw-r--r--libexec/ld.elf_so/data/symver-output-ref-stderr.v2-v11
-rw-r--r--libexec/ld.elf_so/data/symver-output-ref-stderr.v2-v20
-rw-r--r--libexec/ld.elf_so/data/symver-output-ref-stdout.v0-v01
-rw-r--r--libexec/ld.elf_so/data/symver-output-ref-stdout.v0-v11
-rw-r--r--libexec/ld.elf_so/data/symver-output-ref-stdout.v0-v21
-rw-r--r--libexec/ld.elf_so/data/symver-output-ref-stdout.v1-v00
-rw-r--r--libexec/ld.elf_so/data/symver-output-ref-stdout.v1-v11
-rw-r--r--libexec/ld.elf_so/data/symver-output-ref-stdout.v1-v21
-rw-r--r--libexec/ld.elf_so/data/symver-output-ref-stdout.v2-v00
-rw-r--r--libexec/ld.elf_so/data/symver-output-ref-stdout.v2-v10
-rw-r--r--libexec/ld.elf_so/data/symver-output-ref-stdout.v2-v21
-rw-r--r--libexec/ld.elf_so/h_df_1_noopen.c46
-rw-r--r--libexec/ld.elf_so/h_dl_symver.c42
-rw-r--r--libexec/ld.elf_so/h_ifunc.c43
-rw-r--r--libexec/ld.elf_so/h_locking.c149
-rw-r--r--libexec/ld.elf_so/helper_dso1/Makefile19
-rw-r--r--libexec/ld.elf_so/helper_dso1/h_helper_dso1.c70
-rw-r--r--libexec/ld.elf_so/helper_dso2/Makefile22
-rw-r--r--libexec/ld.elf_so/helper_dso2/h_helper_dso2.c57
-rw-r--r--libexec/ld.elf_so/helper_ifunc_dso/Makefile19
-rw-r--r--libexec/ld.elf_so/helper_ifunc_dso/h_helper_ifunc.c52
-rw-r--r--libexec/ld.elf_so/helper_symver_dso0/Makefile21
-rw-r--r--libexec/ld.elf_so/helper_symver_dso0/h_helper_symver_dso0.c39
-rw-r--r--libexec/ld.elf_so/helper_symver_dso1/Makefile24
-rw-r--r--libexec/ld.elf_so/helper_symver_dso1/h_helper_symver_dso1.c41
-rw-r--r--libexec/ld.elf_so/helper_symver_dso1/h_helper_symver_dso1.map5
-rw-r--r--libexec/ld.elf_so/helper_symver_dso2/Makefile23
-rw-r--r--libexec/ld.elf_so/helper_symver_dso2/h_helper_symver_dso2.c59
-rw-r--r--libexec/ld.elf_so/helper_symver_dso2/h_helper_symver_dso2.map13
-rwxr-xr-xlibexec/ld.elf_so/t_df_1_noopen.sh63
-rwxr-xr-xlibexec/ld.elf_so/t_dl_symver.sh55
-rw-r--r--libexec/ld.elf_so/t_dlerror-cleared.c67
-rw-r--r--libexec/ld.elf_so/t_dlerror-false.c79
-rw-r--r--libexec/ld.elf_so/t_dlinfo.c120
-rw-r--r--libexec/ld.elf_so/t_dlvsym.c203
-rw-r--r--libexec/ld.elf_so/t_ifunc.c92
48 files changed, 1540 insertions, 0 deletions
diff --git a/libexec/Makefile b/libexec/Makefile
new file mode 100644
index 000000000000..5a046dcaba89
--- /dev/null
+++ b/libexec/Makefile
@@ -0,0 +1,12 @@
+# $NetBSD: Makefile,v 1.4 2014/06/10 04:28:39 he Exp $
+#
+.include "Makefile.inc"
+.include <bsd.own.mk>
+
+.if ${MACHINE_ARCH} != "m68000"
+TESTS_SUBDIRS= ld.elf_so
+.endif
+
+TESTSDIR= ${TESTSBASE}/libexec
+
+.include <bsd.test.mk>
diff --git a/libexec/Makefile.inc b/libexec/Makefile.inc
new file mode 100644
index 000000000000..01b5f23410c8
--- /dev/null
+++ b/libexec/Makefile.inc
@@ -0,0 +1 @@
+.include "../Makefile.inc"
diff --git a/libexec/ld.elf_so/Makefile b/libexec/ld.elf_so/Makefile
new file mode 100644
index 000000000000..c68aec98f1e7
--- /dev/null
+++ b/libexec/ld.elf_so/Makefile
@@ -0,0 +1,66 @@
+# $NetBSD: Makefile,v 1.8 2014/08/25 20:40:53 joerg Exp $
+#
+
+NOMAN= # defined
+
+.include <bsd.own.mk>
+
+.if ${MKPIC} != "no"
+
+SUBDIR+= helper_dso1 .WAIT helper_dso2 .WAIT \
+ helper_ifunc_dso \
+ helper_symver_dso0 .WAIT helper_symver_dso1 .WAIT \
+ helper_symver_dso2 .WAIT \
+ data
+
+TESTSDIR= ${TESTSBASE}/libexec/ld.elf_so
+
+TESTS_C+= t_dlerror-cleared t_dlerror-false t_dlinfo t_dlvsym t_ifunc
+
+LDADD.t_dlerror-false= -Wl,-rpath,/var/nonexistent/lib
+LDADD.t_dlvsym= -Wl,-rpath,${TESTSDIR}/h_helper_symver_dso2
+LDADD.t_ifunc= -Wl,-rpath,${TESTSDIR} -lutil
+DPADD.t_ifunc= ${LIBUTIL}
+
+TESTS_SH+= t_df_1_noopen t_dl_symver
+
+BINDIR= ${TESTSDIR}
+PROGS+= h_df_1_noopen1
+SRCS.h_df_1_noopen1= h_df_1_noopen.c
+
+PROGS+= h_df_1_noopen2
+SRCS.h_df_1_noopen2= h_df_1_noopen.c
+LDADD.h_df_1_noopen2= -lpthread
+
+PROGS+= h_ifunc
+SRCS.h_ifunc= h_ifunc.c
+IFUNCDIR!= cd ${.CURDIR}/helper_ifunc_dso && ${PRINTOBJDIR}
+LDADD.h_ifunc= -Wl,-rpath,${TESTSDIR} -L${IFUNCDIR} -lh_helper_ifunc_dso
+
+PROGS+= h_locking
+SRCS.h_locking= h_locking.c
+LDADD.h_locking= -lpthread -Wl,--export-dynamic -Wl,-rpath,${TESTSDIR}
+
+PROGS+= h_dl_symver_v0
+SRCS.h_dl_symver_v0= h_dl_symver.c
+V0ODIR!= cd ${.CURDIR}/helper_symver_dso0 && ${PRINTOBJDIR}
+LDADD.h_dl_symver_v0= -L${V0ODIR} -lh_helper_symver_dso
+
+PROGS+= h_dl_symver_v1
+SRCS.h_dl_symver_v1= h_dl_symver.c
+V1ODIR!= cd ${.CURDIR}/helper_symver_dso1 && ${PRINTOBJDIR}
+LDADD.h_dl_symver_v1= -L${V1ODIR} -lh_helper_symver_dso
+
+PROGS+= h_dl_symver_v2
+SRCS.h_dl_symver_v2= h_dl_symver.c
+V2ODIR!= cd ${.CURDIR}/helper_symver_dso2 && ${PRINTOBJDIR}
+LDADD.h_dl_symver_v2= -L${V2ODIR} -lh_helper_symver_dso
+
+.include <bsd.test.mk>
+
+.else
+
+NOPROG= # defined
+.include <bsd.prog.mk>
+
+.endif
diff --git a/libexec/ld.elf_so/Makefile.inc b/libexec/ld.elf_so/Makefile.inc
new file mode 100644
index 000000000000..01b5f23410c8
--- /dev/null
+++ b/libexec/ld.elf_so/Makefile.inc
@@ -0,0 +1 @@
+.include "../Makefile.inc"
diff --git a/libexec/ld.elf_so/data/Makefile b/libexec/ld.elf_so/data/Makefile
new file mode 100644
index 000000000000..286e5e974e14
--- /dev/null
+++ b/libexec/ld.elf_so/data/Makefile
@@ -0,0 +1,28 @@
+# $NetBSD: Makefile,v 1.1 2011/06/25 05:45:13 nonaka Exp $
+
+TESTSDIR= ${TESTSBASE}/libexec/ld.elf_so
+ATFFILE= no
+
+FILESDIR= ${TESTSDIR}/data
+FILES= symver-output-ref-stderr.v0-v0
+FILES+= symver-output-ref-stderr.v0-v1
+FILES+= symver-output-ref-stderr.v0-v2
+FILES+= symver-output-ref-stderr.v1-v0
+FILES+= symver-output-ref-stderr.v1-v1
+FILES+= symver-output-ref-stderr.v1-v2
+FILES+= symver-output-ref-stderr.v2-v0
+FILES+= symver-output-ref-stderr.v2-v1
+FILES+= symver-output-ref-stderr.v2-v2
+FILES+= symver-output-ref-stdout.v0-v0
+FILES+= symver-output-ref-stdout.v0-v1
+FILES+= symver-output-ref-stdout.v0-v2
+FILES+= symver-output-ref-stdout.v1-v0
+FILES+= symver-output-ref-stdout.v1-v1
+FILES+= symver-output-ref-stdout.v1-v2
+FILES+= symver-output-ref-stdout.v2-v0
+FILES+= symver-output-ref-stdout.v2-v1
+FILES+= symver-output-ref-stdout.v2-v2
+
+.include <bsd.test.mk>
+.include <bsd.files.mk>
+.include <bsd.prog.mk>
diff --git a/libexec/ld.elf_so/data/symver-output-ref-stderr.v0-v0 b/libexec/ld.elf_so/data/symver-output-ref-stderr.v0-v0
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/libexec/ld.elf_so/data/symver-output-ref-stderr.v0-v0
diff --git a/libexec/ld.elf_so/data/symver-output-ref-stderr.v0-v1 b/libexec/ld.elf_so/data/symver-output-ref-stderr.v0-v1
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/libexec/ld.elf_so/data/symver-output-ref-stderr.v0-v1
diff --git a/libexec/ld.elf_so/data/symver-output-ref-stderr.v0-v2 b/libexec/ld.elf_so/data/symver-output-ref-stderr.v0-v2
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/libexec/ld.elf_so/data/symver-output-ref-stderr.v0-v2
diff --git a/libexec/ld.elf_so/data/symver-output-ref-stderr.v1-v0 b/libexec/ld.elf_so/data/symver-output-ref-stderr.v1-v0
new file mode 100644
index 000000000000..8cfcf2793b6c
--- /dev/null
+++ b/libexec/ld.elf_so/data/symver-output-ref-stderr.v1-v0
@@ -0,0 +1 @@
+/usr/tests/libexec/ld.elf_so/h_helper_symver_dso0/libh_helper_symver_dso.so.1: version V_1 required by /usr/tests/libexec/ld.elf_so/h_dl_symver_v1 not defined
diff --git a/libexec/ld.elf_so/data/symver-output-ref-stderr.v1-v1 b/libexec/ld.elf_so/data/symver-output-ref-stderr.v1-v1
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/libexec/ld.elf_so/data/symver-output-ref-stderr.v1-v1
diff --git a/libexec/ld.elf_so/data/symver-output-ref-stderr.v1-v2 b/libexec/ld.elf_so/data/symver-output-ref-stderr.v1-v2
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/libexec/ld.elf_so/data/symver-output-ref-stderr.v1-v2
diff --git a/libexec/ld.elf_so/data/symver-output-ref-stderr.v2-v0 b/libexec/ld.elf_so/data/symver-output-ref-stderr.v2-v0
new file mode 100644
index 000000000000..e43fc56a274e
--- /dev/null
+++ b/libexec/ld.elf_so/data/symver-output-ref-stderr.v2-v0
@@ -0,0 +1 @@
+/usr/tests/libexec/ld.elf_so/h_helper_symver_dso0/libh_helper_symver_dso.so.1: version V_3 required by /usr/tests/libexec/ld.elf_so/h_dl_symver_v2 not defined
diff --git a/libexec/ld.elf_so/data/symver-output-ref-stderr.v2-v1 b/libexec/ld.elf_so/data/symver-output-ref-stderr.v2-v1
new file mode 100644
index 000000000000..494c3212f0f0
--- /dev/null
+++ b/libexec/ld.elf_so/data/symver-output-ref-stderr.v2-v1
@@ -0,0 +1 @@
+/usr/tests/libexec/ld.elf_so/h_helper_symver_dso1/libh_helper_symver_dso.so.1: version V_3 required by /usr/tests/libexec/ld.elf_so/h_dl_symver_v2 not found
diff --git a/libexec/ld.elf_so/data/symver-output-ref-stderr.v2-v2 b/libexec/ld.elf_so/data/symver-output-ref-stderr.v2-v2
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/libexec/ld.elf_so/data/symver-output-ref-stderr.v2-v2
diff --git a/libexec/ld.elf_so/data/symver-output-ref-stdout.v0-v0 b/libexec/ld.elf_so/data/symver-output-ref-stdout.v0-v0
new file mode 100644
index 000000000000..573541ac9702
--- /dev/null
+++ b/libexec/ld.elf_so/data/symver-output-ref-stdout.v0-v0
@@ -0,0 +1 @@
+0
diff --git a/libexec/ld.elf_so/data/symver-output-ref-stdout.v0-v1 b/libexec/ld.elf_so/data/symver-output-ref-stdout.v0-v1
new file mode 100644
index 000000000000..d00491fd7e5b
--- /dev/null
+++ b/libexec/ld.elf_so/data/symver-output-ref-stdout.v0-v1
@@ -0,0 +1 @@
+1
diff --git a/libexec/ld.elf_so/data/symver-output-ref-stdout.v0-v2 b/libexec/ld.elf_so/data/symver-output-ref-stdout.v0-v2
new file mode 100644
index 000000000000..d00491fd7e5b
--- /dev/null
+++ b/libexec/ld.elf_so/data/symver-output-ref-stdout.v0-v2
@@ -0,0 +1 @@
+1
diff --git a/libexec/ld.elf_so/data/symver-output-ref-stdout.v1-v0 b/libexec/ld.elf_so/data/symver-output-ref-stdout.v1-v0
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/libexec/ld.elf_so/data/symver-output-ref-stdout.v1-v0
diff --git a/libexec/ld.elf_so/data/symver-output-ref-stdout.v1-v1 b/libexec/ld.elf_so/data/symver-output-ref-stdout.v1-v1
new file mode 100644
index 000000000000..d00491fd7e5b
--- /dev/null
+++ b/libexec/ld.elf_so/data/symver-output-ref-stdout.v1-v1
@@ -0,0 +1 @@
+1
diff --git a/libexec/ld.elf_so/data/symver-output-ref-stdout.v1-v2 b/libexec/ld.elf_so/data/symver-output-ref-stdout.v1-v2
new file mode 100644
index 000000000000..d00491fd7e5b
--- /dev/null
+++ b/libexec/ld.elf_so/data/symver-output-ref-stdout.v1-v2
@@ -0,0 +1 @@
+1
diff --git a/libexec/ld.elf_so/data/symver-output-ref-stdout.v2-v0 b/libexec/ld.elf_so/data/symver-output-ref-stdout.v2-v0
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/libexec/ld.elf_so/data/symver-output-ref-stdout.v2-v0
diff --git a/libexec/ld.elf_so/data/symver-output-ref-stdout.v2-v1 b/libexec/ld.elf_so/data/symver-output-ref-stdout.v2-v1
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/libexec/ld.elf_so/data/symver-output-ref-stdout.v2-v1
diff --git a/libexec/ld.elf_so/data/symver-output-ref-stdout.v2-v2 b/libexec/ld.elf_so/data/symver-output-ref-stdout.v2-v2
new file mode 100644
index 000000000000..00750edc07d6
--- /dev/null
+++ b/libexec/ld.elf_so/data/symver-output-ref-stdout.v2-v2
@@ -0,0 +1 @@
+3
diff --git a/libexec/ld.elf_so/h_df_1_noopen.c b/libexec/ld.elf_so/h_df_1_noopen.c
new file mode 100644
index 000000000000..518f39bca83f
--- /dev/null
+++ b/libexec/ld.elf_so/h_df_1_noopen.c
@@ -0,0 +1,46 @@
+/*-
+ * Copyright (c) 2010 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Nick Hudson.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <dlfcn.h>
+#include <err.h>
+#include <unistd.h>
+
+int
+main(void)
+{
+ void *handle;
+
+ handle = dlopen("libpthread.so", RTLD_NOLOAD);
+ if (handle == NULL)
+ errx(1, "%s", dlerror());
+
+ printf("libpthread loaded successfully\n");
+ return 0;
+}
diff --git a/libexec/ld.elf_so/h_dl_symver.c b/libexec/ld.elf_so/h_dl_symver.c
new file mode 100644
index 000000000000..71e4dc19a7ee
--- /dev/null
+++ b/libexec/ld.elf_so/h_dl_symver.c
@@ -0,0 +1,42 @@
+/* $NetBSD: h_dl_symver.c,v 1.1 2011/06/25 05:45:13 nonaka Exp $ */
+
+/*-
+ * Copyright (c) 2011 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by NONAKA Kimihiro.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+
+extern int testfunc(void);
+
+int
+main(void)
+{
+
+ printf("%d\n", testfunc());
+ return 0;
+}
diff --git a/libexec/ld.elf_so/h_ifunc.c b/libexec/ld.elf_so/h_ifunc.c
new file mode 100644
index 000000000000..ac446fa2a0e0
--- /dev/null
+++ b/libexec/ld.elf_so/h_ifunc.c
@@ -0,0 +1,43 @@
+/* $NetBSD: h_ifunc.c,v 1.1 2014/08/25 20:40:53 joerg Exp $ */
+
+/*-
+ * Copyright (c) 2014 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Joerg Sonnenberger.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdlib.h>
+
+extern int ifunc(void);
+
+int
+main(int argc, char **argv)
+{
+
+ if (argc != 2)
+ return 1;
+ return ifunc() != atoi(argv[1]);
+}
diff --git a/libexec/ld.elf_so/h_locking.c b/libexec/ld.elf_so/h_locking.c
new file mode 100644
index 000000000000..4ff3fc4f0765
--- /dev/null
+++ b/libexec/ld.elf_so/h_locking.c
@@ -0,0 +1,149 @@
+/*-
+ * Copyright (c) 2011 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Joerg Sonnenberger.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <dlfcn.h>
+#include <link_elf.h>
+#include <pthread.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+int sleep_init;
+int sleep_fini;
+int dlopen_cookie;
+int dlclose_cookie;
+
+void (*tls_callback_sym)(void);
+
+static int
+dl_iterate_phdr_cb(struct dl_phdr_info *info, size_t size, void *data)
+{
+ (*tls_callback_sym)();
+ return 0;
+}
+
+static void *
+test_dl_iterate_phdr_helper(void *dummy)
+{
+ sleep(10);
+ _exit(1);
+}
+
+static void
+test_dl_iterate_phdr(void)
+{
+ pthread_t t;
+ void *dso;
+ sleep_init = 0;
+ sleep_fini = 0;
+ if ((dso = dlopen("libh_helper_dso2.so", RTLD_LAZY)) == NULL) {
+ fprintf(stderr, "opening helper failed\n");
+ _exit(1);
+ }
+ tls_callback_sym = dlsym(dso, "tls_callback");
+ if (tls_callback_sym == NULL) {
+ fprintf(stderr, "bad helper\n");
+ _exit(1);
+ }
+ pthread_create(&t, NULL, test_dl_iterate_phdr_helper, NULL);
+ if (dl_iterate_phdr(dl_iterate_phdr_cb, NULL))
+ _exit(1);
+ _exit(0);
+}
+
+static void *
+init_fini_helper(void *arg)
+{
+ void *dso;
+ if ((dso = dlopen(arg, RTLD_LAZY)) == NULL) {
+ fprintf(stderr, "opening %s failed\n", (char *)arg);
+ exit(1);
+ }
+ dlclose(dso);
+ return NULL;
+}
+
+static void
+test_dlopen(void)
+{
+ pthread_t t1, t2;
+ sleep_init = 1;
+ sleep_fini = 0;
+ printf("%d\n", dlopen_cookie);
+ pthread_create(&t1, NULL, init_fini_helper,
+ __UNCONST("libh_helper_dso2.so"));
+ sleep(1);
+ printf("%d\n", dlopen_cookie);
+ if (dlopen_cookie != 1)
+ _exit(1);
+ sleep(1);
+ pthread_create(&t2, NULL, init_fini_helper,
+ __UNCONST("libutil.so"));
+ printf("%d\n", dlopen_cookie);
+ if (dlopen_cookie != 1)
+ _exit(1);
+ _exit(0);
+}
+
+static void
+test_dlclose(void)
+{
+ pthread_t t1, t2;
+ sleep_init = 0;
+ sleep_fini = 1;
+ printf("%d\n", dlclose_cookie);
+ pthread_create(&t1, NULL, init_fini_helper,
+ __UNCONST("libh_helper_dso2.so"));
+ sleep(1);
+ printf("%d\n", dlclose_cookie);
+ if (dlclose_cookie != 2)
+ _exit(1);
+ pthread_create(&t2, NULL, init_fini_helper,
+ __UNCONST("libutil.so"));
+ sleep(1);
+ printf("%d\n", dlclose_cookie);
+ if (dlclose_cookie != 2)
+ _exit(1);
+ _exit(0);
+}
+
+int
+main(int argc, char **argv)
+{
+ if (argc != 2)
+ return 1;
+ if (strcmp(argv[1], "dl_iterate_phdr") == 0)
+ test_dl_iterate_phdr();
+ if (strcmp(argv[1], "dlopen") == 0)
+ test_dlopen();
+ if (strcmp(argv[1], "dlclose") == 0)
+ test_dlclose();
+ return 1;
+}
diff --git a/libexec/ld.elf_so/helper_dso1/Makefile b/libexec/ld.elf_so/helper_dso1/Makefile
new file mode 100644
index 000000000000..b7c14073eea4
--- /dev/null
+++ b/libexec/ld.elf_so/helper_dso1/Makefile
@@ -0,0 +1,19 @@
+# $NetBSD: Makefile,v 1.1 2011/03/31 23:34:48 joerg Exp $
+
+.include <bsd.own.mk>
+
+LIB= h_helper_dso1
+SRCS= h_helper_dso1.c
+
+LIBDIR= ${TESTSBASE}/libexec/ld.elf_so
+SHLIBDIR= ${TESTSBASE}/libexec/ld.elf_so
+SHLIB_MAJOR= 1
+
+MKSTATICLIB= no
+MKPROFILE= no
+MKPICINSTALL= no
+MKLINT= no
+
+NOMAN= # defined
+
+.include <bsd.lib.mk>
diff --git a/libexec/ld.elf_so/helper_dso1/h_helper_dso1.c b/libexec/ld.elf_so/helper_dso1/h_helper_dso1.c
new file mode 100644
index 000000000000..e89e3ff4b777
--- /dev/null
+++ b/libexec/ld.elf_so/helper_dso1/h_helper_dso1.c
@@ -0,0 +1,70 @@
+/*-
+ * Copyright (c) 2011 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Joerg Sonnenberger.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <poll.h>
+#include <stddef.h>
+#include <sys/tls.h>
+
+#ifdef __HAVE_NO___THREAD
+#define __thread
+#endif
+
+extern int sleep_init;
+extern int sleep_fini;
+extern int dlopen_cookie;
+
+static void __attribute__((__constructor__))
+init1(void)
+{
+ dlopen_cookie = 1;
+ if (!sleep_init)
+ return;
+ for (;;)
+ poll(NULL, 0, -1);
+}
+
+extern int dlclose_cookie;
+
+static void __attribute__((__destructor__))
+fini1(void)
+{
+ dlclose_cookie = 1;
+ if (!sleep_fini)
+ return;
+ for (;;)
+ poll(NULL, 0, -1);
+}
+
+static __thread int tls_callback_var;
+
+static void __attribute__((__used__))
+tls_callback(void)
+{
+ tls_callback_var = 1;
+}
diff --git a/libexec/ld.elf_so/helper_dso2/Makefile b/libexec/ld.elf_so/helper_dso2/Makefile
new file mode 100644
index 000000000000..a7b7bc359be8
--- /dev/null
+++ b/libexec/ld.elf_so/helper_dso2/Makefile
@@ -0,0 +1,22 @@
+# $NetBSD: Makefile,v 1.1 2011/03/31 23:34:48 joerg Exp $
+
+.include <bsd.own.mk>
+
+LIB= h_helper_dso2
+SRCS= h_helper_dso2.c
+
+DSO1DIR!= cd ${.CURDIR}/../helper_dso1 && ${PRINTOBJDIR}
+LDADD+= -Wl,-rpath,${TESTSDIR} -L${DSO1DIR} -lh_helper_dso1
+
+LIBDIR= ${TESTSBASE}/libexec/ld.elf_so
+SHLIBDIR= ${TESTSBASE}/libexec/ld.elf_so
+SHLIB_MAJOR= 1
+
+MKSTATICLIB= no
+MKPROFILE= no
+MKPICINSTALL= no
+MKLINT= no
+
+NOMAN= # defined
+
+.include <bsd.lib.mk>
diff --git a/libexec/ld.elf_so/helper_dso2/h_helper_dso2.c b/libexec/ld.elf_so/helper_dso2/h_helper_dso2.c
new file mode 100644
index 000000000000..adeef6b5a715
--- /dev/null
+++ b/libexec/ld.elf_so/helper_dso2/h_helper_dso2.c
@@ -0,0 +1,57 @@
+/*-
+ * Copyright (c) 2011 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Joerg Sonnenberger.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <poll.h>
+#include <stddef.h>
+
+extern int sleep_init;
+extern int sleep_fini;
+extern int dlopen_cookie;
+
+static void __attribute__((__constructor__))
+init2(void)
+{
+ dlopen_cookie = 2;
+ if (!sleep_init)
+ return;
+ for (;;)
+ poll(NULL, 0, -1);
+}
+
+extern int dlclose_cookie;
+
+static void __attribute__((__destructor__))
+fini2(void)
+{
+ dlclose_cookie = 2;
+ if (!sleep_fini)
+ return;
+ for (;;)
+ poll(NULL, 0, -1);
+}
diff --git a/libexec/ld.elf_so/helper_ifunc_dso/Makefile b/libexec/ld.elf_so/helper_ifunc_dso/Makefile
new file mode 100644
index 000000000000..5bbe52f9ac22
--- /dev/null
+++ b/libexec/ld.elf_so/helper_ifunc_dso/Makefile
@@ -0,0 +1,19 @@
+# $NetBSD: Makefile,v 1.1 2014/08/25 20:40:53 joerg Exp $
+
+.include <bsd.own.mk>
+
+LIB= h_helper_ifunc_dso
+SRCS= h_helper_ifunc.c
+
+LIBDIR= ${TESTSBASE}/libexec/ld.elf_so
+SHLIBDIR= ${TESTSBASE}/libexec/ld.elf_so
+SHLIB_MAJOR= 1
+
+MKSTATICLIB= no
+MKPROFILE= no
+MKPICINSTALL= no
+MKLINT= no
+
+NOMAN= # defined
+
+.include <bsd.lib.mk>
diff --git a/libexec/ld.elf_so/helper_ifunc_dso/h_helper_ifunc.c b/libexec/ld.elf_so/helper_ifunc_dso/h_helper_ifunc.c
new file mode 100644
index 000000000000..c04f77547e71
--- /dev/null
+++ b/libexec/ld.elf_so/helper_ifunc_dso/h_helper_ifunc.c
@@ -0,0 +1,52 @@
+/*-
+ * Copyright (c) 2014 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Joerg Sonnenberger.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+static int
+ifunc1(void)
+{
+ return 0xdeadbeef;
+}
+
+static int
+ifunc2(void)
+{
+ return 0xbeefdead;
+}
+
+static __attribute__((used))
+int (*resolve_ifunc(void))(void)
+{
+ const char *e = getenv("USE_IFUNC2");
+ return e && strcmp(e, "1") == 0 ? ifunc2 : ifunc1;
+}
+
+__ifunc(ifunc, resolve_ifunc);
diff --git a/libexec/ld.elf_so/helper_symver_dso0/Makefile b/libexec/ld.elf_so/helper_symver_dso0/Makefile
new file mode 100644
index 000000000000..3cd32c5a608b
--- /dev/null
+++ b/libexec/ld.elf_so/helper_symver_dso0/Makefile
@@ -0,0 +1,21 @@
+# $NetBSD: Makefile,v 1.1 2011/06/25 05:45:13 nonaka Exp $
+
+.include <bsd.own.mk>
+
+LIB= h_helper_symver_dso
+SRCS= h_helper_symver_dso0.c
+
+LIBDIR= ${TESTSBASE}/libexec/ld.elf_so/h_helper_symver_dso0
+SHLIBDIR= ${TESTSBASE}/libexec/ld.elf_so/h_helper_symver_dso0
+SHLIB_MAJOR= 1
+
+MKSTATICLIB= no
+MKPROFILE= no
+MKPICINSTALL= no
+MKLINT= no
+
+NOMAN= # defined
+
+FILESDIR= ${TESTSBASE}/libexec/ld.elf_so/h_helper_symver_dso0
+
+.include <bsd.lib.mk>
diff --git a/libexec/ld.elf_so/helper_symver_dso0/h_helper_symver_dso0.c b/libexec/ld.elf_so/helper_symver_dso0/h_helper_symver_dso0.c
new file mode 100644
index 000000000000..a34bf3164678
--- /dev/null
+++ b/libexec/ld.elf_so/helper_symver_dso0/h_helper_symver_dso0.c
@@ -0,0 +1,39 @@
+/* $NetBSD: h_helper_symver_dso0.c,v 1.1 2011/06/25 05:45:13 nonaka Exp $ */
+
+/*-
+ * Copyright (c) 2011 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by NONAKA Kimihiro.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+int testfunc(void);
+
+int
+testfunc(void)
+{
+
+ return 0;
+}
diff --git a/libexec/ld.elf_so/helper_symver_dso1/Makefile b/libexec/ld.elf_so/helper_symver_dso1/Makefile
new file mode 100644
index 000000000000..1307fbc7d7ee
--- /dev/null
+++ b/libexec/ld.elf_so/helper_symver_dso1/Makefile
@@ -0,0 +1,24 @@
+# $NetBSD: Makefile,v 1.3 2014/02/14 20:33:32 joerg Exp $
+
+.include <bsd.own.mk>
+
+LIB= h_helper_symver_dso
+SRCS= h_helper_symver_dso1.c
+
+LIBDIR= ${TESTSBASE}/libexec/ld.elf_so/h_helper_symver_dso1
+SHLIBDIR= ${TESTSBASE}/libexec/ld.elf_so/h_helper_symver_dso1
+SHLIB_MAJOR= 1
+
+MKSTATICLIB= no
+MKPROFILE= no
+MKPICINSTALL= no
+MKLINT= no
+
+NOMAN= # defined
+
+FILESDIR= ${TESTSBASE}/libexec/ld.elf_so/h_helper_symver_dso1
+
+LDFLAGS.lib${LIB} += -Wl,--version-script=${.CURDIR}/h_helper_symver_dso1.map
+
+.include <bsd.lib.mk>
+
diff --git a/libexec/ld.elf_so/helper_symver_dso1/h_helper_symver_dso1.c b/libexec/ld.elf_so/helper_symver_dso1/h_helper_symver_dso1.c
new file mode 100644
index 000000000000..615816b362d8
--- /dev/null
+++ b/libexec/ld.elf_so/helper_symver_dso1/h_helper_symver_dso1.c
@@ -0,0 +1,41 @@
+/* $NetBSD: h_helper_symver_dso1.c,v 1.1 2011/06/25 05:45:13 nonaka Exp $ */
+
+/*-
+ * Copyright (c) 2011 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by NONAKA Kimihiro.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+__asm(".symver testfunc_new, testfunc@@V_1");
+
+int testfunc_new(void);
+
+int
+testfunc_new(void)
+{
+
+ return 1;
+}
diff --git a/libexec/ld.elf_so/helper_symver_dso1/h_helper_symver_dso1.map b/libexec/ld.elf_so/helper_symver_dso1/h_helper_symver_dso1.map
new file mode 100644
index 000000000000..c813f5d4e43e
--- /dev/null
+++ b/libexec/ld.elf_so/helper_symver_dso1/h_helper_symver_dso1.map
@@ -0,0 +1,5 @@
+# $NetBSD: h_helper_symver_dso1.map,v 1.1 2011/06/25 05:45:13 nonaka Exp $
+
+V_1 {
+ testfunc;
+};
diff --git a/libexec/ld.elf_so/helper_symver_dso2/Makefile b/libexec/ld.elf_so/helper_symver_dso2/Makefile
new file mode 100644
index 000000000000..512075229198
--- /dev/null
+++ b/libexec/ld.elf_so/helper_symver_dso2/Makefile
@@ -0,0 +1,23 @@
+# $NetBSD: Makefile,v 1.3 2014/02/14 20:33:32 joerg Exp $
+
+.include <bsd.own.mk>
+
+LIB= h_helper_symver_dso
+SRCS= h_helper_symver_dso2.c
+
+LIBDIR= ${TESTSBASE}/libexec/ld.elf_so/h_helper_symver_dso2
+SHLIBDIR= ${TESTSBASE}/libexec/ld.elf_so/h_helper_symver_dso2
+SHLIB_MAJOR= 1
+
+MKSTATICLIB= no
+MKPROFILE= no
+MKPICINSTALL= no
+MKLINT= no
+
+NOMAN= # defined
+
+FILESDIR= ${TESTSBASE}/libexec/ld.elf_so/h_helper_symver_dso2
+
+LDFLAGS.lib${LIB} += -Wl,--version-script=${.CURDIR}/h_helper_symver_dso2.map
+
+.include <bsd.lib.mk>
diff --git a/libexec/ld.elf_so/helper_symver_dso2/h_helper_symver_dso2.c b/libexec/ld.elf_so/helper_symver_dso2/h_helper_symver_dso2.c
new file mode 100644
index 000000000000..f5ae4c86a244
--- /dev/null
+++ b/libexec/ld.elf_so/helper_symver_dso2/h_helper_symver_dso2.c
@@ -0,0 +1,59 @@
+/* $NetBSD: h_helper_symver_dso2.c,v 1.1 2011/06/25 05:45:13 nonaka Exp $ */
+
+/*-
+ * Copyright (c) 2011 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by NONAKA Kimihiro.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+__asm(".symver testfunc_new, testfunc@@V_3");
+__asm(".symver testfunc_compat1, testfunc@V_1");
+__asm(".symver testfunc_compat2, testfunc@V_2");
+
+int testfunc_new(void);
+int testfunc_compat1(void);
+int testfunc_compat2(void);
+
+int
+testfunc_new(void)
+{
+
+ return 3;
+}
+
+int
+testfunc_compat1(void)
+{
+
+ return 1;
+}
+
+int
+testfunc_compat2(void)
+{
+
+ return 2;
+}
diff --git a/libexec/ld.elf_so/helper_symver_dso2/h_helper_symver_dso2.map b/libexec/ld.elf_so/helper_symver_dso2/h_helper_symver_dso2.map
new file mode 100644
index 000000000000..518c76b693fb
--- /dev/null
+++ b/libexec/ld.elf_so/helper_symver_dso2/h_helper_symver_dso2.map
@@ -0,0 +1,13 @@
+# $NetBSD: h_helper_symver_dso2.map,v 1.1 2011/06/25 05:45:13 nonaka Exp $
+
+V_1 {
+ testfunc;
+};
+
+V_2 {
+ testfunc;
+};
+
+V_3 {
+ testfunc;
+};
diff --git a/libexec/ld.elf_so/t_df_1_noopen.sh b/libexec/ld.elf_so/t_df_1_noopen.sh
new file mode 100755
index 000000000000..31851f490dab
--- /dev/null
+++ b/libexec/ld.elf_so/t_df_1_noopen.sh
@@ -0,0 +1,63 @@
+# $NetBSD: t_df_1_noopen.sh,v 1.3 2011/03/17 15:59:32 skrll Exp $
+#
+# Copyright (c) 2010 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Nick Hudson.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+atf_test_case df_1_noopen1
+df_1_noopen1_head()
+{
+ atf_set "descr" "Checks DF_1_NOOPEN prevents dlopening of library"
+}
+df_1_noopen1_body()
+{
+ cat >expout <<EOF
+h_df_1_noopen1: Cannot dlopen non-loadable /usr/lib/libpthread.so
+EOF
+
+ atf_check -s exit:1 -e file:expout "$(atf_get_srcdir)/h_df_1_noopen1"
+}
+
+atf_test_case df_1_noopen2
+df_1_noopen2_head()
+{
+ atf_set "descr" "Checks DF_1_NOOPEN is allowed on already loaded library"
+}
+df_1_noopen2_body()
+{
+ cat >expout <<EOF
+libpthread loaded successfully
+EOF
+
+ atf_check -o file:expout "$(atf_get_srcdir)/h_df_1_noopen2"
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case df_1_noopen1
+ atf_add_test_case df_1_noopen2
+}
diff --git a/libexec/ld.elf_so/t_dl_symver.sh b/libexec/ld.elf_so/t_dl_symver.sh
new file mode 100755
index 000000000000..afca0f69dc1e
--- /dev/null
+++ b/libexec/ld.elf_so/t_dl_symver.sh
@@ -0,0 +1,55 @@
+# $NetBSD: t_dl_symver.sh,v 1.1 2011/06/25 05:45:13 nonaka Exp $
+#
+# Copyright (c) 2011 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by NONAKA Kimihiro.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+datadir() {
+ echo "$(atf_get_srcdir)/data"
+}
+
+atf_test_case dl_symver
+dl_symver_head()
+{
+ atf_set "descr" "Checks ELF symbol versioning functions"
+}
+dl_symver_body()
+{
+ for tv in 0 1 2; do
+ for lv in 0 1 2; do
+ atf_check -s ignore \
+ -o file:$(datadir)/symver-output-ref-stdout.v$tv-v$lv \
+ -e file:$(datadir)/symver-output-ref-stderr.v$tv-v$lv \
+ -x "LD_LIBRARY_PATH=$(atf_get_srcdir)/h_helper_symver_dso$lv $(atf_get_srcdir)/h_dl_symver_v$tv"
+ done
+ done
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case dl_symver
+}
diff --git a/libexec/ld.elf_so/t_dlerror-cleared.c b/libexec/ld.elf_so/t_dlerror-cleared.c
new file mode 100644
index 000000000000..03940c2de013
--- /dev/null
+++ b/libexec/ld.elf_so/t_dlerror-cleared.c
@@ -0,0 +1,67 @@
+/* $NetBSD: t_dlerror-cleared.c,v 1.1 2010/12/14 05:57:32 skrll Exp $ */
+
+/*
+ * Copyright (c) 2009 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
+ * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+ * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+
+#include <atf-c.h>
+#include <dlfcn.h>
+#include <link_elf.h>
+
+#include "../../h_macros.h"
+
+ATF_TC(rtld_dlerror_cleared);
+ATF_TC_HEAD(rtld_dlerror_cleared, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "error set by dlopen persists past a successful dlopen call");
+}
+
+ATF_TC_BODY(rtld_dlerror_cleared, tc)
+{
+ void *handle;
+ char *error;
+
+ /*
+ * Test that an error set by dlopen() persists past a successful
+ * dlopen() call.
+ */
+ handle = dlopen("libnonexistent.so", RTLD_LAZY);
+ ATF_CHECK(handle == NULL);
+ handle = dlopen("libm.so", RTLD_NOW);
+ ATF_CHECK(handle);
+ error = dlerror();
+ ATF_CHECK(error);
+
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+ ATF_TP_ADD_TC(tp, rtld_dlerror_cleared);
+ return 0;
+}
diff --git a/libexec/ld.elf_so/t_dlerror-false.c b/libexec/ld.elf_so/t_dlerror-false.c
new file mode 100644
index 000000000000..8b80c260d630
--- /dev/null
+++ b/libexec/ld.elf_so/t_dlerror-false.c
@@ -0,0 +1,79 @@
+/* $NetBSD: t_dlerror-false.c,v 1.1 2010/12/14 05:57:32 skrll Exp $ */
+
+/*
+ * Copyright (c) 2009 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
+ * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+ * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+
+#include <atf-c.h>
+#include <dlfcn.h>
+#include <link_elf.h>
+
+#include "../../h_macros.h"
+
+ATF_TC(rtld_dlerror_false);
+ATF_TC_HEAD(rtld_dlerror_false, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "error set by dlopen persists past a successful dlopen call");
+}
+
+ATF_TC_BODY(rtld_dlerror_false, tc)
+{
+ void *handle, *sym;
+ char *error;
+
+ /*
+ *
+ * Test for dlerror() being set by a successful library open.
+ * Requires that the rpath be set to something that does not
+ * include libm.so.
+ */
+
+ handle = dlopen("libm.so", RTLD_LAZY);
+ error = dlerror();
+ ATF_CHECK(error == NULL);
+ ATF_CHECK(handle != NULL);
+
+ sym = dlsym(handle, "sin");
+ error = dlerror();
+ ATF_CHECK(sym != NULL);
+ ATF_CHECK(error == NULL);
+
+ dlclose(handle);
+ error = dlerror();
+
+ ATF_CHECK(error == NULL);
+
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+ ATF_TP_ADD_TC(tp, rtld_dlerror_false);
+
+ return atf_no_error();
+}
diff --git a/libexec/ld.elf_so/t_dlinfo.c b/libexec/ld.elf_so/t_dlinfo.c
new file mode 100644
index 000000000000..a15ba5d5a909
--- /dev/null
+++ b/libexec/ld.elf_so/t_dlinfo.c
@@ -0,0 +1,120 @@
+/* $NetBSD: t_dlinfo.c,v 1.4 2011/03/25 14:47:31 pooka Exp $ */
+
+/*
+ * Copyright (c) 2009 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
+ * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+ * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+
+#include <atf-c.h>
+#include <dlfcn.h>
+#include <link_elf.h>
+
+#include "../../h_macros.h"
+
+ATF_TC(rtld_dlinfo_linkmap_self);
+ATF_TC_HEAD(rtld_dlinfo_linkmap_self, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "dlinfo with RTLD_SELF handle works");
+}
+ATF_TC_BODY(rtld_dlinfo_linkmap_self, tc)
+{
+ struct link_map *map;
+ int rv;
+
+ rv = dlinfo(RTLD_SELF, RTLD_DI_LINKMAP, &map);
+ ATF_CHECK_EQ(rv, 0);
+ ATF_CHECK((strstr(map->l_name, "t_dlinfo") != NULL));
+}
+
+ATF_TC(rtld_dlinfo_linkmap_inval);
+ATF_TC_HEAD(rtld_dlinfo_linkmap_inval, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "dlinfo with invalid handle fails");
+}
+ATF_TC_BODY(rtld_dlinfo_linkmap_inval, tc)
+{
+ void *v;
+ int rv;
+
+ rv = dlinfo(NULL, RTLD_DI_LINKMAP, &v);
+ ATF_CHECK_EQ(rv, -1);
+}
+
+ATF_TC(rtld_dlinfo_linkmap_dlopen);
+ATF_TC_HEAD(rtld_dlinfo_linkmap_dlopen, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "dlinfo dlopen'd handle works");
+}
+ATF_TC_BODY(rtld_dlinfo_linkmap_dlopen, tc)
+{
+ struct link_map *map;
+ void *handle;
+ int rv;
+
+ handle = dlopen("libutil.so", RTLD_LAZY);
+ ATF_CHECK(handle);
+
+ rv = dlinfo(handle, RTLD_DI_LINKMAP, &map);
+ ATF_CHECK_EQ(rv, 0);
+ ATF_CHECK((strstr(map->l_name, "libutil.so") != NULL));
+ dlclose(handle);
+}
+
+ATF_TC(rtld_dlinfo_linkmap_dlopen_iter);
+ATF_TC_HEAD(rtld_dlinfo_linkmap_dlopen_iter, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "dlopen'd dso's show up in the list");
+}
+ATF_TC_BODY(rtld_dlinfo_linkmap_dlopen_iter, tc)
+{
+ struct link_map *map;
+ void *handle;
+
+ handle = dlopen("libutil.so", RTLD_LAZY);
+ ATF_CHECK(handle);
+
+ RZ(dlinfo(RTLD_SELF, RTLD_DI_LINKMAP, &map));
+
+ for (; map->l_next; map = map->l_next)
+ continue;
+ for (; map; map = map->l_prev)
+ if (strstr(map->l_name, "libutil.so") != NULL)
+ break;
+
+ ATF_REQUIRE_MSG(map, "dlopen()d object not found from linkmap");
+ ATF_REQUIRE_MSG(dlopen(map->l_name, RTLD_LAZY) != NULL,
+ "could not dlopen() name in linkmap");
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+ ATF_TP_ADD_TC(tp, rtld_dlinfo_linkmap_self);
+ ATF_TP_ADD_TC(tp, rtld_dlinfo_linkmap_inval);
+ ATF_TP_ADD_TC(tp, rtld_dlinfo_linkmap_dlopen);
+ ATF_TP_ADD_TC(tp, rtld_dlinfo_linkmap_dlopen_iter);
+ return 0;
+}
diff --git a/libexec/ld.elf_so/t_dlvsym.c b/libexec/ld.elf_so/t_dlvsym.c
new file mode 100644
index 000000000000..ce437d45904c
--- /dev/null
+++ b/libexec/ld.elf_so/t_dlvsym.c
@@ -0,0 +1,203 @@
+/* $NetBSD: t_dlvsym.c,v 1.1 2011/06/25 05:45:13 nonaka Exp $ */
+
+/*-
+ * Copyright (c) 2011 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by NONAKA Kimihiro.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+
+#include <atf-c.h>
+#include <stdlib.h>
+#include <dlfcn.h>
+
+ATF_TC(rtld_dlvsym_v1);
+ATF_TC_HEAD(rtld_dlvsym_v1, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Check dlvsym() function (V_1)");
+}
+ATF_TC_BODY(rtld_dlvsym_v1, tc)
+{
+ void *handle;
+ char *error;
+ int (*sym)(void);
+ int result;
+
+ /* Clear previous error */
+ (void) dlerror();
+
+ handle = dlopen("libh_helper_symver_dso.so", RTLD_LAZY);
+ error = dlerror();
+ ATF_CHECK(error == NULL);
+ ATF_CHECK(handle != NULL);
+
+ sym = dlvsym(handle, "testfunc", "V_1");
+ error = dlerror();
+ ATF_CHECK(error == NULL);
+
+ result = (*sym)();
+ ATF_CHECK(result == 1);
+
+ dlclose(handle);
+ error = dlerror();
+ ATF_CHECK(error == NULL);
+}
+
+ATF_TC(rtld_dlvsym_v3);
+ATF_TC_HEAD(rtld_dlvsym_v3, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Check dlvsym() function (V_3)");
+}
+ATF_TC_BODY(rtld_dlvsym_v3, tc)
+{
+ void *handle;
+ char *error;
+ int (*sym)(void);
+ int result;
+
+ /* Clear previous error */
+ (void) dlerror();
+
+ handle = dlopen("libh_helper_symver_dso.so", RTLD_LAZY);
+ error = dlerror();
+ ATF_CHECK(error == NULL);
+ ATF_CHECK(handle != NULL);
+
+ sym = dlvsym(handle, "testfunc", "V_3");
+ error = dlerror();
+ ATF_CHECK(error == NULL);
+
+ result = (*sym)();
+ ATF_CHECK(result == 3);
+
+ dlclose(handle);
+ error = dlerror();
+ ATF_CHECK(error == NULL);
+}
+
+ATF_TC(rtld_dlvsym_symbol_nonexistent);
+ATF_TC_HEAD(rtld_dlvsym_symbol_nonexistent, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Check dlvsym() function (symbol is nonexistent)");
+}
+ATF_TC_BODY(rtld_dlvsym_symbol_nonexistent, tc)
+{
+ void *handle;
+ char *error;
+ int (*sym)(void);
+
+ /* Clear previous error */
+ (void) dlerror();
+
+ handle = dlopen("libh_helper_symver_dso.so", RTLD_LAZY);
+ error = dlerror();
+ ATF_CHECK(error == NULL);
+ ATF_CHECK(handle != NULL);
+
+ sym = dlvsym(handle, "symbol_nonexistent", "V_3");
+ error = dlerror();
+ ATF_CHECK(sym == NULL);
+ ATF_CHECK(error != NULL);
+
+ dlclose(handle);
+ error = dlerror();
+ ATF_CHECK(error == NULL);
+}
+
+ATF_TC(rtld_dlvsym_version_nonexistent);
+ATF_TC_HEAD(rtld_dlvsym_version_nonexistent, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Check dlvsym() function (version is nonexistent)");
+}
+ATF_TC_BODY(rtld_dlvsym_version_nonexistent, tc)
+{
+ void *handle;
+ char *error;
+ int (*sym)(void);
+
+ /* Clear previous error */
+ (void) dlerror();
+
+ handle = dlopen("libh_helper_symver_dso.so", RTLD_LAZY);
+ error = dlerror();
+ ATF_CHECK(error == NULL);
+ ATF_CHECK(handle != NULL);
+
+ sym = dlvsym(handle, "testfunc", "");
+ error = dlerror();
+ ATF_CHECK(sym == NULL);
+ ATF_CHECK(error != NULL);
+
+ dlclose(handle);
+ error = dlerror();
+ ATF_CHECK(error == NULL);
+}
+
+ATF_TC(rtld_dlvsym_version_null);
+ATF_TC_HEAD(rtld_dlvsym_version_null, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Check dlvsym() function (version is NULL)");
+}
+ATF_TC_BODY(rtld_dlvsym_version_null, tc)
+{
+ void *handle;
+ char *error;
+ int (*sym)(void);
+ int result;
+
+ /* Clear previous error */
+ (void) dlerror();
+
+ handle = dlopen("libh_helper_symver_dso.so", RTLD_LAZY);
+ error = dlerror();
+ ATF_CHECK(error == NULL);
+ ATF_CHECK(handle != NULL);
+
+ sym = dlvsym(handle, "testfunc", NULL);
+ error = dlerror();
+ ATF_CHECK(error == NULL);
+
+ result = (*sym)();
+ ATF_CHECK(result == 3);
+
+ dlclose(handle);
+ error = dlerror();
+ ATF_CHECK(error == NULL);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+ ATF_TP_ADD_TC(tp, rtld_dlvsym_v1);
+ ATF_TP_ADD_TC(tp, rtld_dlvsym_v3);
+ ATF_TP_ADD_TC(tp, rtld_dlvsym_symbol_nonexistent);
+ ATF_TP_ADD_TC(tp, rtld_dlvsym_version_nonexistent);
+ ATF_TP_ADD_TC(tp, rtld_dlvsym_version_null);
+ return atf_no_error();
+}
diff --git a/libexec/ld.elf_so/t_ifunc.c b/libexec/ld.elf_so/t_ifunc.c
new file mode 100644
index 000000000000..1c85672af5f7
--- /dev/null
+++ b/libexec/ld.elf_so/t_ifunc.c
@@ -0,0 +1,92 @@
+/* $NetBSD: t_ifunc.c,v 1.1 2014/08/25 20:40:53 joerg Exp $ */
+
+/*
+ * Copyright (c) 2014 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
+ * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+ * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+
+#include <atf-c.h>
+#include <dlfcn.h>
+#include <util.h>
+
+#include "../../h_macros.h"
+
+ATF_TC(rtld_ifunc);
+
+ATF_TC_HEAD(rtld_ifunc, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "ifunc functions are resolved");
+}
+
+ATF_TC_BODY(rtld_ifunc, tc)
+{
+ const char *envstr[] = {
+ "0", "1"
+ };
+ int expected_result[] = {
+ 0xdeadbeef, 0xbeefdead
+ };
+ void *handle;
+ int (*sym)(void);
+ int result;
+ const char *error;
+ size_t i;
+
+ for (i = 0; i < __arraycount(envstr); ++i) {
+ setenv("USE_IFUNC2", envstr[i], 1);
+
+ handle = dlopen("libh_helper_ifunc_dso.so", RTLD_LAZY);
+ error = dlerror();
+ ATF_CHECK(error == NULL);
+ ATF_CHECK(handle != NULL);
+
+ sym = dlsym(handle, "ifunc");
+ error = dlerror();
+ ATF_CHECK(error == NULL);
+ ATF_CHECK(sym != NULL);
+
+ result = (*sym)();
+ ATF_CHECK(result == expected_result[i]);
+
+ dlclose(handle);
+ error = dlerror();
+ ATF_CHECK(error == NULL);
+
+ char *command;
+ easprintf(&command, "%s/h_ifunc %d",
+ atf_tc_get_config_var(tc, "srcdir"), expected_result[i]);
+ if (system(command) != EXIT_SUCCESS)
+ atf_tc_fail("Test failed; see output for details");
+ free(command);
+ }
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+ ATF_TP_ADD_TC(tp, rtld_ifunc);
+ return 0;
+}