Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src ld.elf_so: Test extern dynamic TLS too.



details:   https://anonhg.NetBSD.org/src/rev/37d76b1992e3
branches:  trunk
changeset: 376112:37d76b1992e3
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Thu Jun 01 20:50:18 2023 +0000

description:
ld.elf_so: Test extern dynamic TLS too.

XXX pullup-10

diffstat:

 distrib/sets/lists/debug/shl.mi                            |   4 +-
 distrib/sets/lists/tests/shl.mi                            |   6 +-
 tests/libexec/ld.elf_so/Makefile                           |   4 +-
 tests/libexec/ld.elf_so/helper_def_dynamic/Makefile        |  19 +++
 tests/libexec/ld.elf_so/helper_def_dynamic/h_def_dynamic.c |  37 ++++++
 tests/libexec/ld.elf_so/helper_use_dynamic/Makefile        |  22 +++
 tests/libexec/ld.elf_so/helper_use_dynamic/h_use_dynamic.c |  37 ++++++
 tests/libexec/ld.elf_so/t_tls_extern.c                     |  86 +++++++++++++-
 8 files changed, 211 insertions(+), 4 deletions(-)

diffs (truncated from 308 to 300 lines):

diff -r c06c55bd18a4 -r 37d76b1992e3 distrib/sets/lists/debug/shl.mi
--- a/distrib/sets/lists/debug/shl.mi   Thu Jun 01 20:48:30 2023 +0000
+++ b/distrib/sets/lists/debug/shl.mi   Thu Jun 01 20:50:18 2023 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: shl.mi,v 1.306 2023/05/31 13:02:10 riastradh Exp $
+# $NetBSD: shl.mi,v 1.307 2023/06/01 20:50:18 riastradh Exp $
 ./usr/lib/libbfd_g.a                                           comp-c-debuglib debuglib,compatfile,binutils
 ./usr/libdata/debug/lib                                                base-sys-usr    debug,dynamicroot,compatdir
 ./usr/libdata/debug/lib/libavl.so.0.0.debug                    comp-zfs-debug  debug,dynamicroot,zfs
@@ -363,11 +363,13 @@
 ./usr/libdata/debug/usr/tests/libexec/ld.elf_so/h_helper_symver_dso1/libh_helper_symver_dso.so.1.debug tests-libexec-debug     debug,compattestfile,atf
 ./usr/libdata/debug/usr/tests/libexec/ld.elf_so/h_helper_symver_dso2/libh_helper_symver_dso.so.1.debug tests-libexec-debug     debug,compattestfile,atf
 ./usr/libdata/debug/usr/tests/libexec/ld.elf_so/h_thread_local_dtor.debug      tests-libexec-debug     debug,compattestfile,atf
+./usr/libdata/debug/usr/tests/libexec/ld.elf_so/libh_def_dynamic.so.1.debug    tests-libexec-debug     debug,compattestfile,atf
 ./usr/libdata/debug/usr/tests/libexec/ld.elf_so/libh_def_static.so.1.debug     tests-libexec-debug     debug,compattestfile,atf
 ./usr/libdata/debug/usr/tests/libexec/ld.elf_so/libh_helper_dso1.so.1.debug    tests-libexec-debug     debug,compattestfile,atf
 ./usr/libdata/debug/usr/tests/libexec/ld.elf_so/libh_helper_dso2.so.1.debug    tests-libexec-debug     debug,compattestfile,atf
 ./usr/libdata/debug/usr/tests/libexec/ld.elf_so/libh_helper_dso3.so.1.debug    tests-libexec-debug     debug,compattestfile,atf
 ./usr/libdata/debug/usr/tests/libexec/ld.elf_so/libh_helper_ifunc_dso.so.1.debug       tests-libexec-debug     debug,compattestfile,atf
+./usr/libdata/debug/usr/tests/libexec/ld.elf_so/libh_use_dynamic.so.1.debug    tests-libexec-debug     debug,compattestfile,atf
 ./usr/libdata/debug/usr/tests/libexec/ld.elf_so/libh_use_static.so.1.debug     tests-libexec-debug     debug,compattestfile,atf
 ./usr/tests/libexec/ld.elf_so/h_helper_symver_dso0/libh_helper_symver_dso_g.a  comp-c-debuglib atf,debuglib,compattestfile
 ./usr/tests/libexec/ld.elf_so/h_helper_symver_dso1/libh_helper_symver_dso_g.a  comp-c-debuglib atf,debuglib,compattestfile
diff -r c06c55bd18a4 -r 37d76b1992e3 distrib/sets/lists/tests/shl.mi
--- a/distrib/sets/lists/tests/shl.mi   Thu Jun 01 20:48:30 2023 +0000
+++ b/distrib/sets/lists/tests/shl.mi   Thu Jun 01 20:50:18 2023 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: shl.mi,v 1.12 2023/05/31 00:18:44 riastradh Exp $
+# $NetBSD: shl.mi,v 1.13 2023/06/01 20:50:18 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_dynamic.so                              tests-libexec-tests     compattestfile,atf
+./usr/tests/libexec/ld.elf_so/libh_def_dynamic.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
@@ -26,6 +28,8 @@
 ./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_dynamic.so                              tests-libexec-tests     compattestfile,atf
+./usr/tests/libexec/ld.elf_so/libh_use_dynamic.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
diff -r c06c55bd18a4 -r 37d76b1992e3 tests/libexec/ld.elf_so/Makefile
--- a/tests/libexec/ld.elf_so/Makefile  Thu Jun 01 20:48:30 2023 +0000
+++ b/tests/libexec/ld.elf_so/Makefile  Thu Jun 01 20:50:18 2023 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.15 2023/05/31 01:06:43 riastradh Exp $
+# $NetBSD: Makefile,v 1.16 2023/06/01 20:50:18 riastradh Exp $
 #
 
 NOMAN=         # defined
@@ -13,8 +13,10 @@ SUBDIR+=     helper_dso1 helper_dso3 .WAIT h
                helper_symver_dso2 .WAIT \
                data
 
+SUBDIR+=       helper_def_dynamic
 SUBDIR+=       helper_def_static
 SUBDIR+=       .WAIT
+SUBDIR+=       helper_use_dynamic
 SUBDIR+=       helper_use_static
 
 TESTSDIR=      ${TESTSBASE}/libexec/ld.elf_so
diff -r c06c55bd18a4 -r 37d76b1992e3 tests/libexec/ld.elf_so/helper_def_dynamic/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/libexec/ld.elf_so/helper_def_dynamic/Makefile       Thu Jun 01 20:50:18 2023 +0000
@@ -0,0 +1,19 @@
+#      $NetBSD: Makefile,v 1.1 2023/06/01 20:50:18 riastradh Exp $
+
+.include <bsd.own.mk>
+
+LIB=           h_def_dynamic
+SRCS=          h_def_dynamic.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 -r c06c55bd18a4 -r 37d76b1992e3 tests/libexec/ld.elf_so/helper_def_dynamic/h_def_dynamic.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/libexec/ld.elf_so/helper_def_dynamic/h_def_dynamic.c        Thu Jun 01 20:50:18 2023 +0000
@@ -0,0 +1,37 @@
+/*     $NetBSD: h_def_dynamic.c,v 1.1 2023/06/01 20:50:18 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 mydynsym = 0;
+
+int *fdef(void);
+int *
+fdef(void)
+{
+
+       return &mydynsym;
+}
diff -r c06c55bd18a4 -r 37d76b1992e3 tests/libexec/ld.elf_so/helper_use_dynamic/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/libexec/ld.elf_so/helper_use_dynamic/Makefile       Thu Jun 01 20:50:18 2023 +0000
@@ -0,0 +1,22 @@
+#      $NetBSD: Makefile,v 1.1 2023/06/01 20:50:19 riastradh Exp $
+
+.include <bsd.own.mk>
+
+LIB=           h_use_dynamic
+SRCS=          h_use_dynamic.c
+
+DEF_DIR!=      cd ${.CURDIR}/../helper_def_dynamic && ${PRINTOBJDIR}
+LDADD+=                -Wl,-rpath,${TESTSDIR} -L${DEF_DIR} -lh_def_dynamic
+
+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 -r c06c55bd18a4 -r 37d76b1992e3 tests/libexec/ld.elf_so/helper_use_dynamic/h_use_dynamic.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/libexec/ld.elf_so/helper_use_dynamic/h_use_dynamic.c        Thu Jun 01 20:50:18 2023 +0000
@@ -0,0 +1,37 @@
+/*     $NetBSD: h_use_dynamic.c,v 1.1 2023/06/01 20:50:19 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.
+ */
+
+extern __thread int mydynsym;
+
+int *fuse(void);
+int *
+fuse(void)
+{
+
+       return &mydynsym;
+}
diff -r c06c55bd18a4 -r 37d76b1992e3 tests/libexec/ld.elf_so/t_tls_extern.c
--- a/tests/libexec/ld.elf_so/t_tls_extern.c    Thu Jun 01 20:48:30 2023 +0000
+++ b/tests/libexec/ld.elf_so/t_tls_extern.c    Thu Jun 01 20:50:18 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_tls_extern.c,v 1.3 2023/06/01 20:48:30 riastradh Exp $       */
+/*     $NetBSD: t_tls_extern.c,v 1.4 2023/06/01 20:50:18 riastradh Exp $       */
 
 /*-
  * Copyright (c) 2023 The NetBSD Foundation, Inc.
@@ -33,6 +33,87 @@
 
 #define        ATF_REQUIRE_DL(x)       ATF_REQUIRE_MSG(x, "%s: %s", #x, dlerror())
 
+ATF_TC(tls_extern_dynamic_defuse);
+ATF_TC_HEAD(tls_extern_dynamic_defuse, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "extern __thread for dynamic TLS works,"
+           " loading def then use");
+}
+ATF_TC_BODY(tls_extern_dynamic_defuse, tc)
+{
+       void *def, *use;
+       int *(*fdef)(void), *(*fuse)(void);
+       int *pdef, *puse;
+
+       (void)dlerror();
+
+       ATF_REQUIRE_DL(def = dlopen("libh_def_dynamic.so", 0));
+       ATF_REQUIRE_DL(use = dlopen("libh_use_dynamic.so", 0));
+
+       ATF_REQUIRE_DL(fdef = dlsym(def, "fdef"));
+       ATF_REQUIRE_DL(fuse = dlsym(use, "fuse"));
+
+       pdef = (*fdef)();
+       puse = (*fuse)();
+       ATF_CHECK_EQ_MSG(pdef, puse,
+           "%p in defining library != %p in using library",
+           pdef, puse);
+}
+
+ATF_TC(tls_extern_dynamic_usedef);
+ATF_TC_HEAD(tls_extern_dynamic_usedef, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "extern __thread for dynamic TLS works,"
+           " loading use then def");
+}
+ATF_TC_BODY(tls_extern_dynamic_usedef, tc)
+{
+       void *def, *use;
+       int *(*fdef)(void), *(*fuse)(void);
+       int *pdef, *puse;
+
+       (void)dlerror();
+
+       ATF_REQUIRE_DL(use = dlopen("libh_use_dynamic.so", 0));
+       ATF_REQUIRE_DL(def = dlopen("libh_def_dynamic.so", 0));
+
+       ATF_REQUIRE_DL(fdef = dlsym(def, "fdef"));
+       ATF_REQUIRE_DL(fuse = dlsym(use, "fuse"));
+
+       pdef = (*fdef)();
+       puse = (*fuse)();
+       ATF_CHECK_EQ_MSG(pdef, puse,
+           "%p in defining library != %p in using library",
+           pdef, puse);
+}
+
+ATF_TC(tls_extern_dynamic_usedefnoload);
+ATF_TC_HEAD(tls_extern_dynamic_usedefnoload, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "extern __thread for dynamic TLS works,"
+           " loading use then def with RTLD_NOLOAD");
+}
+ATF_TC_BODY(tls_extern_dynamic_usedefnoload, tc)
+{
+       void *def, *use;
+       int *(*fdef)(void), *(*fuse)(void);
+       int *pdef, *puse;
+
+       (void)dlerror();
+
+       ATF_REQUIRE_DL(use = dlopen("libh_use_dynamic.so", 0));
+       ATF_REQUIRE_DL(def = dlopen("libh_def_dynamic.so", RTLD_NOLOAD));
+
+       ATF_REQUIRE_DL(fdef = dlsym(def, "fdef"));
+       ATF_REQUIRE_DL(fuse = dlsym(use, "fuse"));
+
+       pdef = (*fdef)();
+       puse = (*fuse)();
+       ATF_CHECK_EQ_MSG(pdef, puse,
+           "%p in defining library != %p in using library",
+           pdef, puse);
+}
+
 ATF_TC(tls_extern_static_defuse);
 ATF_TC_HEAD(tls_extern_static_defuse, tc)
 {
@@ -121,6 +202,9 @@ ATF_TC_BODY(tls_extern_static_usedefnolo
 ATF_TP_ADD_TCS(tp)



Home | Main Index | Thread Index | Old Index