From 05e97b5a426adc075e368468687ee751938a703b Mon Sep 17 00:00:00 2001 From: riastradh Date: Thu, 1 Jun 2023 20:50:18 +0000 Subject: [PATCH] ld.elf_so: Test extern dynamic TLS too. XXX pullup-10 --- distrib/sets/lists/debug/shl.mi | 4 +- distrib/sets/lists/tests/shl.mi | 6 +- tests/libexec/ld.elf_so/Makefile | 4 +- .../ld.elf_so/helper_def_dynamic/Makefile | 19 ++++ .../helper_def_dynamic/h_def_dynamic.c | 37 ++++++++ .../ld.elf_so/helper_use_dynamic/Makefile | 22 +++++ .../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(-) create mode 100644 tests/libexec/ld.elf_so/helper_def_dynamic/Makefile create mode 100644 tests/libexec/ld.elf_so/helper_def_dynamic/h_def_dynamic.c create mode 100644 tests/libexec/ld.elf_so/helper_use_dynamic/Makefile create mode 100644 tests/libexec/ld.elf_so/helper_use_dynamic/h_use_dynamic.c diff --git a/distrib/sets/lists/debug/shl.mi b/distrib/sets/lists/debug/shl.mi index 62aa8ce0c93d..ff1ca42c7333 100644 --- a/distrib/sets/lists/debug/shl.mi +++ b/distrib/sets/lists/debug/shl.mi @@ -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 --git a/distrib/sets/lists/tests/shl.mi b/distrib/sets/lists/tests/shl.mi index 83f11efa133a..491109bca2b1 100644 --- a/distrib/sets/lists/tests/shl.mi +++ b/distrib/sets/lists/tests/shl.mi @@ -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 --git a/tests/libexec/ld.elf_so/Makefile b/tests/libexec/ld.elf_so/Makefile index 916ea9fe4618..f3286f57e1f3 100644 --- a/tests/libexec/ld.elf_so/Makefile +++ b/tests/libexec/ld.elf_so/Makefile @@ -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 helper_dso2 .WAIT \ 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 --git a/tests/libexec/ld.elf_so/helper_def_dynamic/Makefile b/tests/libexec/ld.elf_so/helper_def_dynamic/Makefile new file mode 100644 index 000000000000..f01c22ee5ea1 --- /dev/null +++ b/tests/libexec/ld.elf_so/helper_def_dynamic/Makefile @@ -0,0 +1,19 @@ +# $NetBSD: Makefile,v 1.1 2023/06/01 20:50:18 riastradh Exp $ + +.include + +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 diff --git a/tests/libexec/ld.elf_so/helper_def_dynamic/h_def_dynamic.c b/tests/libexec/ld.elf_so/helper_def_dynamic/h_def_dynamic.c new file mode 100644 index 000000000000..cbbd2df9e545 --- /dev/null +++ b/tests/libexec/ld.elf_so/helper_def_dynamic/h_def_dynamic.c @@ -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 --git a/tests/libexec/ld.elf_so/helper_use_dynamic/Makefile b/tests/libexec/ld.elf_so/helper_use_dynamic/Makefile new file mode 100644 index 000000000000..e7815dee077a --- /dev/null +++ b/tests/libexec/ld.elf_so/helper_use_dynamic/Makefile @@ -0,0 +1,22 @@ +# $NetBSD: Makefile,v 1.1 2023/06/01 20:50:19 riastradh Exp $ + +.include + +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 diff --git a/tests/libexec/ld.elf_so/helper_use_dynamic/h_use_dynamic.c b/tests/libexec/ld.elf_so/helper_use_dynamic/h_use_dynamic.c new file mode 100644 index 000000000000..e3d4ef85e916 --- /dev/null +++ b/tests/libexec/ld.elf_so/helper_use_dynamic/h_use_dynamic.c @@ -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 --git a/tests/libexec/ld.elf_so/t_tls_extern.c b/tests/libexec/ld.elf_so/t_tls_extern.c index 03a1c1111caa..731477d3688d 100644 --- a/tests/libexec/ld.elf_so/t_tls_extern.c +++ b/tests/libexec/ld.elf_so/t_tls_extern.c @@ -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_usedefnoload, tc) ATF_TP_ADD_TCS(tp) { + ATF_TP_ADD_TC(tp, tls_extern_dynamic_defuse); + ATF_TP_ADD_TC(tp, tls_extern_dynamic_usedef); + ATF_TP_ADD_TC(tp, tls_extern_dynamic_usedefnoload); ATF_TP_ADD_TC(tp, tls_extern_static_defuse); ATF_TP_ADD_TC(tp, tls_extern_static_usedef); ATF_TP_ADD_TC(tp, tls_extern_static_usedefnoload);