Module Name: src Committed By: riastradh Date: Fri Jun 2 19:08:49 UTC 2023
Modified Files: src/distrib/sets/lists/debug: shl.mi src/distrib/sets/lists/tests: shl.mi src/tests/libexec/ld.elf_so: Makefile t_tls_extern.c Added Files: src/tests/libexec/ld.elf_so/helper_onlydef: Makefile h_onlydef.c src/tests/libexec/ld.elf_so/helper_onlydef_static: Makefile h_onlydef_static.c src/tests/libexec/ld.elf_so/helper_onlyuse_dynamic: Makefile h_onlyuse_dynamic.c src/tests/libexec/ld.elf_so/helper_onlyuse_static: Makefile h_onlyuse_static.c Log Message: ld.elf_so: Test another edge case of mismatched TLS models. One library defines a symbol and _doesn't_ use it, so it has no indication of whether the symbol is for static TLS or dynamic TLS, and then two other libraries use it in different ways. XXX pullup-10 To generate a diff of this commit: cvs rdiff -u -r1.308 -r1.309 src/distrib/sets/lists/debug/shl.mi cvs rdiff -u -r1.14 -r1.15 src/distrib/sets/lists/tests/shl.mi cvs rdiff -u -r1.17 -r1.18 src/tests/libexec/ld.elf_so/Makefile cvs rdiff -u -r1.9 -r1.10 src/tests/libexec/ld.elf_so/t_tls_extern.c cvs rdiff -u -r0 -r1.1 src/tests/libexec/ld.elf_so/helper_onlydef/Makefile \ src/tests/libexec/ld.elf_so/helper_onlydef/h_onlydef.c cvs rdiff -u -r0 -r1.1 \ src/tests/libexec/ld.elf_so/helper_onlydef_static/Makefile \ src/tests/libexec/ld.elf_so/helper_onlydef_static/h_onlydef_static.c cvs rdiff -u -r0 -r1.1 \ src/tests/libexec/ld.elf_so/helper_onlyuse_dynamic/Makefile \ src/tests/libexec/ld.elf_so/helper_onlyuse_dynamic/h_onlyuse_dynamic.c cvs rdiff -u -r0 -r1.1 \ src/tests/libexec/ld.elf_so/helper_onlyuse_static/Makefile \ src/tests/libexec/ld.elf_so/helper_onlyuse_static/h_onlyuse_static.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/distrib/sets/lists/debug/shl.mi diff -u src/distrib/sets/lists/debug/shl.mi:1.308 src/distrib/sets/lists/debug/shl.mi:1.309 --- src/distrib/sets/lists/debug/shl.mi:1.308 Fri Jun 2 12:08:26 2023 +++ src/distrib/sets/lists/debug/shl.mi Fri Jun 2 19:08:48 2023 @@ -1,4 +1,4 @@ -# $NetBSD: shl.mi,v 1.308 2023/06/02 12:08:26 riastradh Exp $ +# $NetBSD: shl.mi,v 1.309 2023/06/02 19:08:48 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 @@ -371,6 +371,9 @@ ./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_onlydef.so.1.debug tests-libexec-debug debug,compattestfile,atf +./usr/libdata/debug/usr/tests/libexec/ld.elf_so/libh_onlyuse_dynamic.so.1.debug tests-libexec-debug debug,compattestfile,atf +./usr/libdata/debug/usr/tests/libexec/ld.elf_so/libh_onlyuse_static.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 Index: src/distrib/sets/lists/tests/shl.mi diff -u src/distrib/sets/lists/tests/shl.mi:1.14 src/distrib/sets/lists/tests/shl.mi:1.15 --- src/distrib/sets/lists/tests/shl.mi:1.14 Thu Jun 1 22:26:40 2023 +++ src/distrib/sets/lists/tests/shl.mi Fri Jun 2 19:08:48 2023 @@ -1,4 +1,4 @@ -# $NetBSD: shl.mi,v 1.14 2023/06/01 22:26:40 riastradh Exp $ +# $NetBSD: shl.mi,v 1.15 2023/06/02 19:08:48 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 @@ -32,6 +32,12 @@ ./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_onlydef.so tests-libexec-tests compattestfile,atf +./usr/tests/libexec/ld.elf_so/libh_onlydef.so.1 tests-libexec-tests compattestfile,atf +./usr/tests/libexec/ld.elf_so/libh_onlyuse_dynamic.so tests-libexec-tests compattestfile,atf +./usr/tests/libexec/ld.elf_so/libh_onlyuse_dynamic.so.1 tests-libexec-tests compattestfile,atf +./usr/tests/libexec/ld.elf_so/libh_onlyuse_static.so tests-libexec-tests compattestfile,atf +./usr/tests/libexec/ld.elf_so/libh_onlyuse_static.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 Index: src/tests/libexec/ld.elf_so/Makefile diff -u src/tests/libexec/ld.elf_so/Makefile:1.17 src/tests/libexec/ld.elf_so/Makefile:1.18 --- src/tests/libexec/ld.elf_so/Makefile:1.17 Thu Jun 1 22:26:40 2023 +++ src/tests/libexec/ld.elf_so/Makefile Fri Jun 2 19:08:48 2023 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.17 2023/06/01 22:26:40 riastradh Exp $ +# $NetBSD: Makefile,v 1.18 2023/06/02 19:08:48 riastradh Exp $ # NOMAN= # defined @@ -15,9 +15,12 @@ SUBDIR+= helper_dso1 helper_dso3 .WAIT h SUBDIR+= helper_def_dynamic SUBDIR+= helper_def_static +SUBDIR+= helper_onlydef SUBDIR+= .WAIT SUBDIR+= helper_abuse_dynamic SUBDIR+= helper_abuse_static +SUBDIR+= helper_onlyuse_dynamic +SUBDIR+= helper_onlyuse_static SUBDIR+= helper_use_dynamic SUBDIR+= helper_use_static Index: src/tests/libexec/ld.elf_so/t_tls_extern.c diff -u src/tests/libexec/ld.elf_so/t_tls_extern.c:1.9 src/tests/libexec/ld.elf_so/t_tls_extern.c:1.10 --- src/tests/libexec/ld.elf_so/t_tls_extern.c:1.9 Fri Jun 2 19:08:01 2023 +++ src/tests/libexec/ld.elf_so/t_tls_extern.c Fri Jun 2 19:08:48 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: t_tls_extern.c,v 1.9 2023/06/02 19:08:01 riastradh Exp $ */ +/* $NetBSD: t_tls_extern.c,v 1.10 2023/06/02 19:08:48 riastradh Exp $ */ /*- * Copyright (c) 2023 The NetBSD Foundation, Inc. @@ -285,6 +285,103 @@ ATF_TC_BODY(static_usedefnoload, tc) USE_DEF_NOLOAD, /*xfail*/true); } +ATF_TC(onlydef_dynamic_static_eager); +ATF_TC_HEAD(onlydef_dynamic_static_eager, tc) +{ + atf_tc_set_md_var(tc, "descr", "definition-only library," + " dynamic load and use, then static load fails"); +} +ATF_TC_BODY(onlydef_dynamic_static_eager, tc) +{ + void *use_dynamic; + int *(*fdynamic)(void); + + ATF_REQUIRE_DL(use_dynamic = dlopen("libh_onlyuse_dynamic.so", 0)); + ATF_REQUIRE_DL(fdynamic = dlsym(use_dynamic, "fdynamic")); + (void)(*fdynamic)(); + atf_tc_expect_fail("rtld fails to detect dynamic-then-static abuse"); + ATF_CHECK_EQ_MSG(NULL, dlopen("libh_onlyuse_static.so", 0), + "dlopen failed to detect dynamic-then-static abuse"); +} + +ATF_TC(onlydef_dynamic_static_lazy); +ATF_TC_HEAD(onlydef_dynamic_static_lazy, tc) +{ + atf_tc_set_md_var(tc, "descr", "extern __thread for TLS works," + " with definition-only library, dynamic and static load and use"); +} +ATF_TC_BODY(onlydef_dynamic_static_lazy, tc) +{ + void *use_dynamic, *use_static; + int *(*fdynamic)(void), *(*fstatic)(void); + int *pdynamic, *pstatic; + + ATF_REQUIRE_DL(use_dynamic = dlopen("libh_onlyuse_dynamic.so", 0)); + ATF_REQUIRE_DL(use_static = dlopen("libh_onlyuse_static.so", 0)); + ATF_REQUIRE_DL(fdynamic = dlsym(use_dynamic, "fdynamic")); + ATF_REQUIRE_DL(fstatic = dlsym(use_static, "fstatic")); + pdynamic = (*fdynamic)(); + pstatic = (*fstatic)(); + atf_tc_expect_fail("PR toolchain/50277:" + " rtld relocation bug with thread local storage"); + ATF_CHECK_EQ_MSG(pdynamic, pstatic, + "%p in dynamic tls user != %p in static tls user", + pdynamic, pstatic); +} + +ATF_TC(onlydef_static_dynamic_eager); +ATF_TC_HEAD(onlydef_static_dynamic_eager, tc) +{ + atf_tc_set_md_var(tc, "descr", "extern __thread for TLS works," + " with definition-only library," + " static load and use, then dynamic load and use"); +} +ATF_TC_BODY(onlydef_static_dynamic_eager, tc) +{ + void *use_static, *use_dynamic; + int *(*fstatic)(void), *(*fdynamic)(void); + int *pstatic, *pdynamic; + + ATF_REQUIRE_DL(dlopen("libh_onlydef.so", 0)); + ATF_REQUIRE_DL(use_static = dlopen("libh_onlyuse_static.so", 0)); + ATF_REQUIRE_DL(fstatic = dlsym(use_static, "fstatic")); + pstatic = (*fstatic)(); + ATF_REQUIRE_DL(use_dynamic = dlopen("libh_onlyuse_dynamic.so", 0)); + ATF_REQUIRE_DL(fdynamic = dlsym(use_dynamic, "fdynamic")); + pdynamic = (*fdynamic)(); + atf_tc_expect_fail("PR toolchain/50277:" + " rtld relocation bug with thread local storage"); + ATF_CHECK_EQ_MSG(pstatic, pdynamic, + "%p in static tls user != %p in dynamic tls user", + pstatic, pdynamic); +} + +ATF_TC(onlydef_static_dynamic_lazy); +ATF_TC_HEAD(onlydef_static_dynamic_lazy, tc) +{ + atf_tc_set_md_var(tc, "descr", "extern __thread for TLS works," + " with definition-only library, static and dynamic load and use"); +} +ATF_TC_BODY(onlydef_static_dynamic_lazy, tc) +{ + void *use_static, *use_dynamic; + int *(*fstatic)(void), *(*fdynamic)(void); + int *pstatic, *pdynamic; + + ATF_REQUIRE_DL(dlopen("libh_onlydef.so", 0)); + ATF_REQUIRE_DL(use_static = dlopen("libh_onlyuse_static.so", 0)); + ATF_REQUIRE_DL(use_dynamic = dlopen("libh_onlyuse_dynamic.so", 0)); + ATF_REQUIRE_DL(fstatic = dlsym(use_static, "fstatic")); + ATF_REQUIRE_DL(fdynamic = dlsym(use_dynamic, "fdynamic")); + pstatic = (*fstatic)(); + pdynamic = (*fdynamic)(); + atf_tc_expect_fail("PR toolchain/50277:" + " rtld relocation bug with thread local storage"); + ATF_CHECK_EQ_MSG(pstatic, pdynamic, + "%p in static tls user != %p in dynamic tls user", + pstatic, pdynamic); +} + ATF_TP_ADD_TCS(tp) { @@ -296,6 +393,10 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC(tp, dynamic_defuse_lazy); ATF_TP_ADD_TC(tp, dynamic_usedef); ATF_TP_ADD_TC(tp, dynamic_usedefnoload); + ATF_TP_ADD_TC(tp, onlydef_dynamic_static_eager); + ATF_TP_ADD_TC(tp, onlydef_dynamic_static_lazy); + ATF_TP_ADD_TC(tp, onlydef_static_dynamic_eager); + ATF_TP_ADD_TC(tp, onlydef_static_dynamic_lazy); ATF_TP_ADD_TC(tp, static_abusedef); ATF_TP_ADD_TC(tp, static_abusedefnoload); ATF_TP_ADD_TC(tp, static_defabuse_eager); Added files: Index: src/tests/libexec/ld.elf_so/helper_onlydef/Makefile diff -u /dev/null src/tests/libexec/ld.elf_so/helper_onlydef/Makefile:1.1 --- /dev/null Fri Jun 2 19:08:49 2023 +++ src/tests/libexec/ld.elf_so/helper_onlydef/Makefile Fri Jun 2 19:08:49 2023 @@ -0,0 +1,19 @@ +# $NetBSD: Makefile,v 1.1 2023/06/02 19:08:49 riastradh Exp $ + +.include <bsd.own.mk> + +LIB= h_onlydef +SRCS= h_onlydef.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> Index: src/tests/libexec/ld.elf_so/helper_onlydef/h_onlydef.c diff -u /dev/null src/tests/libexec/ld.elf_so/helper_onlydef/h_onlydef.c:1.1 --- /dev/null Fri Jun 2 19:08:49 2023 +++ src/tests/libexec/ld.elf_so/helper_onlydef/h_onlydef.c Fri Jun 2 19:08:49 2023 @@ -0,0 +1,29 @@ +/* $NetBSD: h_onlydef.c,v 1.1 2023/06/02 19:08:49 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 = 0; Index: src/tests/libexec/ld.elf_so/helper_onlydef_static/Makefile diff -u /dev/null src/tests/libexec/ld.elf_so/helper_onlydef_static/Makefile:1.1 --- /dev/null Fri Jun 2 19:08:49 2023 +++ src/tests/libexec/ld.elf_so/helper_onlydef_static/Makefile Fri Jun 2 19:08:49 2023 @@ -0,0 +1,19 @@ +# $NetBSD: Makefile,v 1.1 2023/06/02 19:08:49 riastradh Exp $ + +.include <bsd.own.mk> + +LIB= h_onlydef_static +SRCS= h_onlydef_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> Index: src/tests/libexec/ld.elf_so/helper_onlydef_static/h_onlydef_static.c diff -u /dev/null src/tests/libexec/ld.elf_so/helper_onlydef_static/h_onlydef_static.c:1.1 --- /dev/null Fri Jun 2 19:08:49 2023 +++ src/tests/libexec/ld.elf_so/helper_onlydef_static/h_onlydef_static.c Fri Jun 2 19:08:49 2023 @@ -0,0 +1,29 @@ +/* $NetBSD: h_onlydef_static.c,v 1.1 2023/06/02 19:08:49 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; Index: src/tests/libexec/ld.elf_so/helper_onlyuse_dynamic/Makefile diff -u /dev/null src/tests/libexec/ld.elf_so/helper_onlyuse_dynamic/Makefile:1.1 --- /dev/null Fri Jun 2 19:08:49 2023 +++ src/tests/libexec/ld.elf_so/helper_onlyuse_dynamic/Makefile Fri Jun 2 19:08:49 2023 @@ -0,0 +1,22 @@ +# $NetBSD: Makefile,v 1.1 2023/06/02 19:08:49 riastradh Exp $ + +.include <bsd.own.mk> + +LIB= h_onlyuse_dynamic +SRCS= h_onlyuse_dynamic.c + +DEF_DIR!= cd ${.CURDIR}/../helper_onlydef && ${PRINTOBJDIR} +LDADD+= -Wl,-rpath,${TESTSDIR} -L${DEF_DIR} -lh_onlydef + +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> Index: src/tests/libexec/ld.elf_so/helper_onlyuse_dynamic/h_onlyuse_dynamic.c diff -u /dev/null src/tests/libexec/ld.elf_so/helper_onlyuse_dynamic/h_onlyuse_dynamic.c:1.1 --- /dev/null Fri Jun 2 19:08:49 2023 +++ src/tests/libexec/ld.elf_so/helper_onlyuse_dynamic/h_onlyuse_dynamic.c Fri Jun 2 19:08:49 2023 @@ -0,0 +1,37 @@ +/* $NetBSD: h_onlyuse_dynamic.c,v 1.1 2023/06/02 19:08:49 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 mysym; /* dynamic */ + +int *fdynamic(void); +int * +fdynamic(void) +{ + + return &mysym; +} Index: src/tests/libexec/ld.elf_so/helper_onlyuse_static/Makefile diff -u /dev/null src/tests/libexec/ld.elf_so/helper_onlyuse_static/Makefile:1.1 --- /dev/null Fri Jun 2 19:08:49 2023 +++ src/tests/libexec/ld.elf_so/helper_onlyuse_static/Makefile Fri Jun 2 19:08:49 2023 @@ -0,0 +1,22 @@ +# $NetBSD: Makefile,v 1.1 2023/06/02 19:08:49 riastradh Exp $ + +.include <bsd.own.mk> + +LIB= h_onlyuse_static +SRCS= h_onlyuse_static.c + +DEF_DIR!= cd ${.CURDIR}/../helper_onlydef && ${PRINTOBJDIR} +LDADD+= -Wl,-rpath,${TESTSDIR} -L${DEF_DIR} -lh_onlydef + +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> Index: src/tests/libexec/ld.elf_so/helper_onlyuse_static/h_onlyuse_static.c diff -u /dev/null src/tests/libexec/ld.elf_so/helper_onlyuse_static/h_onlyuse_static.c:1.1 --- /dev/null Fri Jun 2 19:08:49 2023 +++ src/tests/libexec/ld.elf_so/helper_onlyuse_static/h_onlyuse_static.c Fri Jun 2 19:08:49 2023 @@ -0,0 +1,37 @@ +/* $NetBSD: h_onlyuse_static.c,v 1.1 2023/06/02 19:08:49 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 mysym __attribute__((tls_model("initial-exec"))); + +int *fstatic(void); +int * +fstatic(void) +{ + + return &mysym; +}