Index: distrib/sets/lists/debug/mi =================================================================== RCS file: /cvsroot/src/distrib/sets/lists/debug/mi,v retrieving revision 1.505 diff -u -p -r1.505 mi --- distrib/sets/lists/debug/mi 28 Dec 2025 19:07:43 -0000 1.505 +++ distrib/sets/lists/debug/mi 15 Jan 2026 08:03:00 -0000 @@ -2492,6 +2492,7 @@ ./usr/libdata/debug/usr/tests/libexec/ld.elf_so/t_rtld_r_debug.debug tests-libexec-debug debug,atf,pic,compattestfile ./usr/libdata/debug/usr/tests/libexec/ld.elf_so/t_rtld_r_debug_nopie.debug tests-libexec-debug debug,atf,pic,compattestfile ./usr/libdata/debug/usr/tests/libexec/ld.elf_so/t_tls_alignment.debug tests-libexec-debug debug,atf,pic,compattestfile +./usr/libdata/debug/usr/tests/libexec/ld.elf_so/libh_tls_alignment.so.1.debug tests-libexec-debug debug,atf,pic,compattestfile ./usr/libdata/debug/usr/tests/libexec/ld.elf_so/t_tls_extern.debug tests-libexec-debug debug,atf,pic,compattestfile ./usr/libdata/debug/usr/tests/net/bpf/t_bpf.debug tests-net-debug debug,atf,rump ./usr/libdata/debug/usr/tests/net/bpf/t_div-by-zero.debug tests-net-debug debug,atf,rump Index: distrib/sets/lists/tests/mi =================================================================== RCS file: /cvsroot/src/distrib/sets/lists/tests/mi,v retrieving revision 1.1406 diff -u -p -r1.1406 mi --- distrib/sets/lists/tests/mi 28 Dec 2025 16:50:21 -0000 1.1406 +++ distrib/sets/lists/tests/mi 15 Jan 2026 08:03:09 -0000 @@ -4390,6 +4390,8 @@ ./usr/tests/libexec/ld.elf_so/t_rtld_r_debug_nopie 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_alignment tests-libexec-tests compattestfile,atf,pic +./usr/tests/libexec/ld.elf_so/libh_tls_alignment.so tests-libexec-tests compattestfile,atf,pic +./usr/tests/libexec/ld.elf_so/libh_tls_alignment.so.1 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 Index: tests/libexec/ld.elf_so/Makefile =================================================================== RCS file: /cvsroot/src/tests/libexec/ld.elf_so/Makefile,v retrieving revision 1.35 diff -u -p -r1.35 Makefile --- tests/libexec/ld.elf_so/Makefile 21 Dec 2025 19:08:09 -0000 1.35 +++ tests/libexec/ld.elf_so/Makefile 15 Jan 2026 08:05:18 -0000 @@ -32,6 +32,7 @@ SUBDIR+= helper_onlyuse_dynamic SUBDIR+= helper_onlyuse_static SUBDIR+= helper_use_dynamic SUBDIR+= helper_use_static +SUBDIR+= helper_tls_alignment TESTSDIR= ${TESTSBASE}/libexec/ld.elf_so Index: tests/libexec/ld.elf_so/magic.h =================================================================== RCS file: tests/libexec/ld.elf_so/magic.h diff -N tests/libexec/ld.elf_so/magic.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ tests/libexec/ld.elf_so/magic.h 15 Jan 2026 08:05:18 -0000 @@ -0,0 +1,39 @@ +/*- + * Copyright (c) 2026 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. + */ + +#ifndef _MAGIC_H +#define _MAGIC_H + +#define MAGIC1 0xaa55aa55aa55aa55 +#define MAGIC2 0xc0ffeeeeeeeeeeee +#define MAGIC3 0xff00ff00ff00ff00 + +#endif + + Index: tests/libexec/ld.elf_so/t_tls_alignment.c =================================================================== RCS file: /cvsroot/src/tests/libexec/ld.elf_so/t_tls_alignment.c,v retrieving revision 1.1 diff -u -p -r1.1 t_tls_alignment.c --- tests/libexec/ld.elf_so/t_tls_alignment.c 6 Dec 2025 10:35:20 -0000 1.1 +++ tests/libexec/ld.elf_so/t_tls_alignment.c 15 Jan 2026 08:05:18 -0000 @@ -30,12 +30,12 @@ #include #include +#include +#include -#define ALIGNMENT 64 +#include "magic.h" -#define MAGIC1 0xaa55aa55aa55aa55 -#define MAGIC2 0xc0ffeeeeeeeeeeee -#define MAGIC3 0xff00ff00ff00ff00 +#define ALIGNMENT 64 __thread struct { @@ -57,18 +57,50 @@ ATF_TC_HEAD(tls_alignment, tc) ATF_TC_BODY(tls_alignment, tc) { -#ifdef __HAVE_TLS_VARIANT_I - atf_tc_expect_fail("PR toolchain/59652"); -#endif - ATF_CHECK(tls_data.magic1 == MAGIC1); ATF_CHECK(tls_data.magic2 == MAGIC2); ATF_CHECK(tls_data.magic3 == MAGIC3); } +#define ATF_REQUIRE_DL(x) \ + ATF_REQUIRE_MSG((x) != 0, "%s: %s", #x, dlerror()) + +#define ATF_REQUIRE_MAGIC(m1, m2) \ + ATF_CHECK_EQ_MSG(m1, m2, "%#" PRIx64 " dso != %#" PRIx64, m1, m2); + + +ATF_TC(tls_alignment_dso); +ATF_TC_HEAD(tls_alignment_dso, tc) +{ + atf_tc_set_md_var(tc, "descr", "loading DSO with large TLS alignment"); +} +ATF_TC_BODY(tls_alignment_dso, tc) +{ + void *dso; + uint64_t (*h_magic1)(void), magic1; + uint64_t (*h_magic2)(void), magic2; + uint64_t (*h_magic3)(void), magic3; + + (void)dlerror(); + + ATF_REQUIRE_DL(dso = dlopen("libh_tls_alignment.so", 0)); + ATF_REQUIRE_DL(h_magic1 = dlsym(dso, "helper_tls_alignment_magic1")); + ATF_REQUIRE_DL(h_magic2 = dlsym(dso, "helper_tls_alignment_magic2")); + ATF_REQUIRE_DL(h_magic3 = dlsym(dso, "helper_tls_alignment_magic3")); + + magic1 = (*h_magic1)(); + magic2 = (*h_magic2)(); + magic3 = (*h_magic3)(); + + ATF_REQUIRE_MAGIC(magic1, MAGIC1); + ATF_REQUIRE_MAGIC(magic2, MAGIC2); + ATF_REQUIRE_MAGIC(magic3, MAGIC3); +} + ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, tls_alignment); + ATF_TP_ADD_TC(tp, tls_alignment_dso); return atf_no_error(); } Index: tests/libexec/ld.elf_so/helper_tls_alignment/Makefile =================================================================== RCS file: tests/libexec/ld.elf_so/helper_tls_alignment/Makefile diff -N tests/libexec/ld.elf_so/helper_tls_alignment/Makefile --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ tests/libexec/ld.elf_so/helper_tls_alignment/Makefile 15 Jan 2026 08:05:18 -0000 @@ -0,0 +1,8 @@ +# $NetBSD$ + +CPPFLAGS+= -I${.CURDIR}/.. + +LIB= h_tls_alignment +SRCS= h_tls_alignment.c + +.include "../helper.mk" Index: tests/libexec/ld.elf_so/helper_tls_alignment/h_tls_alignment.c =================================================================== RCS file: tests/libexec/ld.elf_so/helper_tls_alignment/h_tls_alignment.c diff -N tests/libexec/ld.elf_so/helper_tls_alignment/h_tls_alignment.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ tests/libexec/ld.elf_so/helper_tls_alignment/h_tls_alignment.c 15 Jan 2026 08:05:18 -0000 @@ -0,0 +1,70 @@ +/*- + * Copyright (c) 2025 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 +#include + +#include "magic.h" + +#define ALIGNMENT 4096 + +struct helper_struct { + uint64_t magic1; + uint64_t magic2[ALIGNMENT / sizeof(uint64_t)] __attribute__((aligned(ALIGNMENT))); + uint64_t magic3; +}; + +__thread struct helper_struct mystruct = { + .magic1 = MAGIC1, + .magic2 = { MAGIC2 }, + .magic3 = MAGIC3, +}; + +uint64_t helper_tls_alignment_magic1(void); +uint64_t helper_tls_alignment_magic2(void); +uint64_t helper_tls_alignment_magic3(void); + + +uint64_t +helper_tls_alignment_magic1(void) +{ + return mystruct.magic1; +} + +uint64_t +helper_tls_alignment_magic2(void) +{ + return mystruct.magic2[0]; +} + +uint64_t +helper_tls_alignment_magic3(void) +{ + return mystruct.magic3; +}