summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorriastradh <riastradh@NetBSD.org>2023-05-31 00:18:44 +0000
committerriastradh <riastradh@NetBSD.org>2023-05-31 00:18:44 +0000
commit8f4e92485fadf48b2386d5447c1db17823ca6e3b (patch)
treeb4cc4df4747f3b4f99931b6b02e69bf168f6a038
parent75dc982d29ff88c1fe5fb2ede34af8be80a234be (diff)
ld.elf_so: New test for extern initial-exec TLS, PR toolchain/50277.
XXX pullup-10
-rw-r--r--distrib/sets/lists/tests/mi3
-rw-r--r--distrib/sets/lists/tests/shl.mi6
-rw-r--r--tests/libexec/ld.elf_so/Makefile7
-rw-r--r--tests/libexec/ld.elf_so/helper_def_static/Makefile19
-rw-r--r--tests/libexec/ld.elf_so/helper_def_static/h_def_static.c37
-rw-r--r--tests/libexec/ld.elf_so/helper_use_static/Makefile19
-rw-r--r--tests/libexec/ld.elf_so/helper_use_static/h_use_static.c37
-rw-r--r--tests/libexec/ld.elf_so/t_tls_extern.c66
8 files changed, 191 insertions, 3 deletions
diff --git a/distrib/sets/lists/tests/mi b/distrib/sets/lists/tests/mi
index 21489102951..e77b818c1ff 100644
--- a/distrib/sets/lists/tests/mi
+++ b/distrib/sets/lists/tests/mi
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1264 2023/05/20 21:32:05 rillig Exp $
+# $NetBSD: mi,v 1.1265 2023/05/31 00:18:44 riastradh Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -4168,6 +4168,7 @@
./usr/tests/libexec/ld.elf_so/t_ifunc tests-libexec-tests compattestfile,atf,pic
./usr/tests/libexec/ld.elf_so/t_rtld_r_debug tests-libexec-tests compattestfile,atf,pic
./usr/tests/libexec/ld.elf_so/t_thread_local_dtor tests-libexec-tests compattestfile,atf,pic
+./usr/tests/libexec/ld.elf_so/t_tls_extern tests-libexec-tests compattestfile,atf,pic
./usr/tests/modules tests-sys-tests compattestfile,atf
./usr/tests/net tests-net-tests compattestfile,atf
./usr/tests/net/Atffile tests-net-tests compattestfile,atf
diff --git a/distrib/sets/lists/tests/shl.mi b/distrib/sets/lists/tests/shl.mi
index 234702c92a1..83f11efa133 100644
--- a/distrib/sets/lists/tests/shl.mi
+++ b/distrib/sets/lists/tests/shl.mi
@@ -1,4 +1,4 @@
-# $NetBSD: shl.mi,v 1.11 2017/07/11 15:21:32 joerg Exp $
+# $NetBSD: shl.mi,v 1.12 2023/05/31 00:18:44 riastradh Exp $
#
./usr/tests/lib/csu/h_initfini3_dso.so tests-lib-tests compattestfile,atf
./usr/tests/lib/csu/h_initfini3_dso.so.1 tests-lib-tests compattestfile,atf
@@ -16,6 +16,8 @@
./usr/tests/libexec/ld.elf_so/h_helper_symver_dso1/libh_helper_symver_dso.so.1 tests-libexec-tests compattestfile,atf
./usr/tests/libexec/ld.elf_so/h_helper_symver_dso2/libh_helper_symver_dso.so tests-libexec-tests compattestfile,atf
./usr/tests/libexec/ld.elf_so/h_helper_symver_dso2/libh_helper_symver_dso.so.1 tests-libexec-tests compattestfile,atf
+./usr/tests/libexec/ld.elf_so/libh_def_static.so tests-libexec-tests compattestfile,atf
+./usr/tests/libexec/ld.elf_so/libh_def_static.so.1 tests-libexec-tests compattestfile,atf
./usr/tests/libexec/ld.elf_so/libh_helper_dso1.so tests-libexec-tests compattestfile,atf
./usr/tests/libexec/ld.elf_so/libh_helper_dso1.so.1 tests-libexec-tests compattestfile,atf
./usr/tests/libexec/ld.elf_so/libh_helper_dso2.so tests-libexec-tests compattestfile,atf
@@ -24,5 +26,7 @@
./usr/tests/libexec/ld.elf_so/libh_helper_dso3.so.1 tests-libexec-tests compattestfile,atf
./usr/tests/libexec/ld.elf_so/libh_helper_ifunc_dso.so tests-libexec-tests compattestfile,atf
./usr/tests/libexec/ld.elf_so/libh_helper_ifunc_dso.so.1 tests-libexec-tests compattestfile,atf
+./usr/tests/libexec/ld.elf_so/libh_use_static.so tests-libexec-tests compattestfile,atf
+./usr/tests/libexec/ld.elf_so/libh_use_static.so.1 tests-libexec-tests compattestfile,atf
./usr/tests/util/id/libfake.so.0 tests-obsolete obsolete
./usr/tests/util/id/libfake.so.0.0 tests-obsolete obsolete
diff --git a/tests/libexec/ld.elf_so/Makefile b/tests/libexec/ld.elf_so/Makefile
index 0c0c6df12c5..c0b9cb7e0cf 100644
--- a/tests/libexec/ld.elf_so/Makefile
+++ b/tests/libexec/ld.elf_so/Makefile
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.12 2021/05/30 02:26:51 joerg Exp $
+# $NetBSD: Makefile,v 1.13 2023/05/31 00:18:44 riastradh Exp $
#
NOMAN= # defined
@@ -13,10 +13,14 @@ SUBDIR+= helper_dso1 helper_dso3 .WAIT helper_dso2 .WAIT \
helper_symver_dso2 .WAIT \
data
+SUBDIR+= helper_def_static
+SUBDIR+= helper_use_static
+
TESTSDIR= ${TESTSBASE}/libexec/ld.elf_so
TESTS_C+= t_dlerror-cleared t_dlerror-false t_dlinfo t_dlvsym t_ifunc
TESTS_C+= t_rtld_r_debug
+TESTS_C+= t_tls_extern
COPTS.t_rtld_r_debug.c += ${${ACTIVE_CC} == "gcc" :? -Wno-maybe-uninitialized :}
@@ -24,6 +28,7 @@ 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}
+LDADD.t_tls_extern+= -Wl,-rpath,${TESTSDIR}
TESTS_SH+= t_df_1_noopen t_dl_symver t_thread_local_dtor
diff --git a/tests/libexec/ld.elf_so/helper_def_static/Makefile b/tests/libexec/ld.elf_so/helper_def_static/Makefile
new file mode 100644
index 00000000000..fccd464e59c
--- /dev/null
+++ b/tests/libexec/ld.elf_so/helper_def_static/Makefile
@@ -0,0 +1,19 @@
+# $NetBSD: Makefile,v 1.1 2023/05/31 00:18:44 riastradh Exp $
+
+.include <bsd.own.mk>
+
+LIB= h_def_static
+SRCS= h_def_static.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/tests/libexec/ld.elf_so/helper_def_static/h_def_static.c b/tests/libexec/ld.elf_so/helper_def_static/h_def_static.c
new file mode 100644
index 00000000000..05ed48aad51
--- /dev/null
+++ b/tests/libexec/ld.elf_so/helper_def_static/h_def_static.c
@@ -0,0 +1,37 @@
+/* $NetBSD: h_def_static.c,v 1.1 2023/05/31 00:18:44 riastradh Exp $ */
+
+/*-
+ * Copyright (c) 2023 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.
+ */
+
+__thread int mysym __attribute__((tls_model("initial-exec"))) = 0;
+
+int *fdef(void);
+int *
+fdef(void)
+{
+
+ return &mysym;
+}
diff --git a/tests/libexec/ld.elf_so/helper_use_static/Makefile b/tests/libexec/ld.elf_so/helper_use_static/Makefile
new file mode 100644
index 00000000000..56b61d538a8
--- /dev/null
+++ b/tests/libexec/ld.elf_so/helper_use_static/Makefile
@@ -0,0 +1,19 @@
+# $NetBSD: Makefile,v 1.1 2023/05/31 00:18:44 riastradh Exp $
+
+.include <bsd.own.mk>
+
+LIB= h_use_static
+SRCS= h_use_static.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/tests/libexec/ld.elf_so/helper_use_static/h_use_static.c b/tests/libexec/ld.elf_so/helper_use_static/h_use_static.c
new file mode 100644
index 00000000000..c732fae4c6e
--- /dev/null
+++ b/tests/libexec/ld.elf_so/helper_use_static/h_use_static.c
@@ -0,0 +1,37 @@
+/* $NetBSD: h_use_static.c,v 1.1 2023/05/31 00:18:44 riastradh Exp $ */
+
+/*-
+ * Copyright (c) 2023 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.
+ */
+
+__thread int mysym __attribute__((tls_model("initial-exec"))) = 0;
+
+int *fuse(void);
+int *
+fuse(void)
+{
+
+ return &mysym;
+}
diff --git a/tests/libexec/ld.elf_so/t_tls_extern.c b/tests/libexec/ld.elf_so/t_tls_extern.c
new file mode 100644
index 00000000000..89b4c7ca3de
--- /dev/null
+++ b/tests/libexec/ld.elf_so/t_tls_extern.c
@@ -0,0 +1,66 @@
+/* $NetBSD: t_tls_extern.c,v 1.1 2023/05/31 00:18:44 riastradh Exp $ */
+
+/*-
+ * Copyright (c) 2023 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>
+
+#define ATF_CHECK_DL(x) ATF_CHECK_MSG(x, "%s: %s", #x, dlerror())
+
+ATF_TC(tls_extern_static);
+ATF_TC_HEAD(tls_extern_static, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "extern __thread for static TLS works");
+}
+ATF_TC_BODY(tls_extern_static, tc)
+{
+ void *def, *use;
+ int *(*fdef)(void), *(*fuse)(void);
+ int *pdef, *puse;
+
+ (void)dlerror();
+ ATF_CHECK_DL(def = dlopen("libh_def_static.so", RTLD_LAZY));
+ ATF_CHECK_DL(use = dlopen("libh_use_static.so", RTLD_LAZY));
+ ATF_CHECK_DL(fdef = dlsym(def, "fdef"));
+ ATF_CHECK_DL(fuse = dlsym(use, "fuse"));
+
+ pdef = (*fdef)();
+ puse = (*fuse)();
+ atf_tc_expect_fail("PR toolchain/50277:"
+ " rtld relocation bug with thread local storage");
+ ATF_CHECK_EQ_MSG(pdef, puse,
+ "%p in defining library != %p in using library",
+ pdef, puse);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+ ATF_TP_ADD_TC(tp, tls_extern_static);
+ return atf_no_error();
+}