[glibc] x86: Update tst-gnu2-tls2 tests

H.J. Lu hjl@sourceware.org
Wed Jun 18 21:47:39 GMT 2025


https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=0ef7965e5b251473f7d451739324c45b0fefaf1a

commit 0ef7965e5b251473f7d451739324c45b0fefaf1a
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Mon Jun 9 08:17:49 2025 +0800

    x86: Update tst-gnu2-tls2 tests
    
    Update tst-gnu2-tls2 tests to set XMM0...XMM7 to all 1s in malloc to
    verify that XMM registers are preserved when _dl_tlsdesc_dynamic is
    called by clearing vectors with zeroed XMM registers before
    _dl_tlsdesc_dynamic and using these XMM registers to clear vectors
    after _dl_tlsdesc_dynamic.  This improves the BZ #31372 test.
    
    Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
    Reviewed-by: Sam James <sam@gentoo.org>

Diff:
---
 elf/tst-gnu2-tls2.c                           |  4 +--
 sysdeps/unix/sysv/linux/x86_64/Makefile       |  8 +++---
 sysdeps/x86/Makefile                          | 16 +++++++++---
 sysdeps/x86/tst-gnu2-tls2-x86-noxsave.c       |  2 +-
 sysdeps/x86/tst-gnu2-tls2-x86-noxsavec.c      |  2 +-
 sysdeps/x86/tst-gnu2-tls2-x86-noxsavexsavec.c |  2 +-
 sysdeps/x86/tst-gnu2-tls2.c                   | 36 +++++++++++++++-----------
 sysdeps/x86/tst-gnu2-tls2.h                   | 37 +++++++++++++++++++++++++++
 8 files changed, 79 insertions(+), 28 deletions(-)

diff --git a/elf/tst-gnu2-tls2.c b/elf/tst-gnu2-tls2.c
index 74637ee19e..6a253c9b94 100644
--- a/elf/tst-gnu2-tls2.c
+++ b/elf/tst-gnu2-tls2.c
@@ -25,7 +25,7 @@
 #include <support/xthread.h>
 #include <support/check.h>
 #include <support/test-driver.h>
-#include "tst-gnu2-tls2.h"
+#include <tst-gnu2-tls2.h>
 
 #ifndef IS_SUPPORTED
 # define IS_SUPPORTED() true
@@ -75,7 +75,7 @@ close_mod (int i)
 static void
 access_mod (int i, const char *sym)
 {
-  struct tls var = { -1, -1, -1, -1 };
+  struct tls var = { -4, -4, -4, -4 };
   struct tls *(*f) (struct tls *) = xdlsym (mod[i], sym);
   /* Check that our malloc is called.  */
   malloc_counter = 0;
diff --git a/sysdeps/unix/sysv/linux/x86_64/Makefile b/sysdeps/unix/sysv/linux/x86_64/Makefile
index fb834a7089..6938382801 100644
--- a/sysdeps/unix/sysv/linux/x86_64/Makefile
+++ b/sysdeps/unix/sysv/linux/x86_64/Makefile
@@ -87,10 +87,10 @@ $(objpfx)tst-gnu2-tls2-amx-mod0.so: $(libsupport)
 $(objpfx)tst-gnu2-tls2-amx-mod1.so: $(libsupport)
 $(objpfx)tst-gnu2-tls2-amx-mod2.so: $(libsupport)
 
-CFLAGS-tst-gnu2-tls2-amx.c += -mamx-tile
-CFLAGS-tst-gnu2-tls2-amx-mod0.c += -mamx-tile -mtls-dialect=gnu2
-CFLAGS-tst-gnu2-tls2-amx-mod1.c += -mamx-tile -mtls-dialect=gnu2
-CFLAGS-tst-gnu2-tls2-amx-mod2.c += -mamx-tile -mtls-dialect=gnu2
+CFLAGS-tst-gnu2-tls2-amx.c += -mamx-tile -DTEST_AMX
+CFLAGS-tst-gnu2-tls2-amx-mod0.c += -mamx-tile -DTEST_AMX -mtls-dialect=gnu2
+CFLAGS-tst-gnu2-tls2-amx-mod1.c += -mamx-tile -DTEST_AMX -mtls-dialect=gnu2
+CFLAGS-tst-gnu2-tls2-amx-mod2.c += -mamx-tile -DTEST_AMX -mtls-dialect=gnu2
 endif
 
 endif # $(subdir) == elf
diff --git a/sysdeps/x86/Makefile b/sysdeps/x86/Makefile
index f64cee3cd9..2aca36c1f0 100644
--- a/sysdeps/x86/Makefile
+++ b/sysdeps/x86/Makefile
@@ -96,14 +96,22 @@ tst-ifunc-isa-2-ENV = GLIBC_TUNABLES=glibc.cpu.hwcaps=-SSE4_2,-AVX,-AVX2,-AVX512
 tst-ifunc-isa-2-static-ENV = $(tst-ifunc-isa-2-ENV)
 tst-hwcap-tunables-ARGS = -- $(host-test-program-cmd)
 
-CFLAGS-tst-gnu2-tls2.c += -msse
+CFLAGS-tst-gnu2-tls2.c += -msse2
 CFLAGS-tst-gnu2-tls2mod0.c += -msse2 -mtune=haswell
 CFLAGS-tst-gnu2-tls2mod1.c += -msse2 -mtune=haswell
 CFLAGS-tst-gnu2-tls2mod2.c += -msse2 -mtune=haswell
 
-LDFLAGS-tst-gnu2-tls2-x86-noxsave += -Wl,-z,lazy
-LDFLAGS-tst-gnu2-tls2-x86-noxsavec += -Wl,-z,lazy
-LDFLAGS-tst-gnu2-tls2-x86-noxsavexsavec += -Wl,-z,lazy
+LDFLAGS-tst-gnu2-tls2 += -rdynamic
+LDFLAGS-tst-gnu2-tls2mod0.so += -Wl,-z,undefs
+LDFLAGS-tst-gnu2-tls2mod1.so += -Wl,-z,undefs
+LDFLAGS-tst-gnu2-tls2mod2.so += -Wl,-z,undefs
+
+CFLAGS-tst-gnu2-tls2-x86-noxsave.c += -msse2
+CFLAGS-tst-gnu2-tls2-x86-noxsavec.c += -msse2
+CFLAGS-tst-gnu2-tls2-x86-noxsavexsavec.c += -msse2
+LDFLAGS-tst-gnu2-tls2-x86-noxsave += -Wl,-z,lazy -rdynamic
+LDFLAGS-tst-gnu2-tls2-x86-noxsavec += -Wl,-z,lazy -rdynamic
+LDFLAGS-tst-gnu2-tls2-x86-noxsavexsavec += -Wl,-z,lazy -rdynamic
 
 # Test for bug 32810: incorrect XSAVE state size if XSAVEC is disabled
 # via tunable.
diff --git a/sysdeps/x86/tst-gnu2-tls2-x86-noxsave.c b/sysdeps/x86/tst-gnu2-tls2-x86-noxsave.c
index f0024c143d..963c4f3811 100644
--- a/sysdeps/x86/tst-gnu2-tls2-x86-noxsave.c
+++ b/sysdeps/x86/tst-gnu2-tls2-x86-noxsave.c
@@ -1 +1 @@
-#include <elf/tst-gnu2-tls2.c>
+#include <tst-gnu2-tls2.c>
diff --git a/sysdeps/x86/tst-gnu2-tls2-x86-noxsavec.c b/sysdeps/x86/tst-gnu2-tls2-x86-noxsavec.c
index f0024c143d..963c4f3811 100644
--- a/sysdeps/x86/tst-gnu2-tls2-x86-noxsavec.c
+++ b/sysdeps/x86/tst-gnu2-tls2-x86-noxsavec.c
@@ -1 +1 @@
-#include <elf/tst-gnu2-tls2.c>
+#include <tst-gnu2-tls2.c>
diff --git a/sysdeps/x86/tst-gnu2-tls2-x86-noxsavexsavec.c b/sysdeps/x86/tst-gnu2-tls2-x86-noxsavexsavec.c
index f0024c143d..963c4f3811 100644
--- a/sysdeps/x86/tst-gnu2-tls2-x86-noxsavexsavec.c
+++ b/sysdeps/x86/tst-gnu2-tls2-x86-noxsavexsavec.c
@@ -1 +1 @@
-#include <elf/tst-gnu2-tls2.c>
+#include <tst-gnu2-tls2.c>
diff --git a/sysdeps/x86/tst-gnu2-tls2.c b/sysdeps/x86/tst-gnu2-tls2.c
index de900a423b..b3195fff2e 100644
--- a/sysdeps/x86/tst-gnu2-tls2.c
+++ b/sysdeps/x86/tst-gnu2-tls2.c
@@ -1,20 +1,26 @@
-#ifndef __x86_64__
-#include <sys/platform/x86.h>
+#ifndef TEST_AMX
+# ifndef __x86_64__
+# include <sys/platform/x86.h>
 
-#define IS_SUPPORTED() CPU_FEATURE_ACTIVE (SSE2)
-#endif
+# define IS_SUPPORTED() CPU_FEATURE_ACTIVE (SSE2)
+# endif
 
-/* Clear XMM0...XMM7  */
-#define PREPARE_MALLOC()				\
-{							\
-  asm volatile ("xorps %%xmm0, %%xmm0" : : : "xmm0" );	\
-  asm volatile ("xorps %%xmm1, %%xmm1" : : : "xmm1" );	\
-  asm volatile ("xorps %%xmm2, %%xmm2" : : : "xmm2" );	\
-  asm volatile ("xorps %%xmm3, %%xmm3" : : : "xmm3" );	\
-  asm volatile ("xorps %%xmm4, %%xmm4" : : : "xmm4" );	\
-  asm volatile ("xorps %%xmm5, %%xmm5" : : : "xmm5" );	\
-  asm volatile ("xorps %%xmm6, %%xmm6" : : : "xmm6" );	\
-  asm volatile ("xorps %%xmm7, %%xmm7" : : : "xmm7" );	\
+/* Set XMM0...XMM7 to all 1s.  */
+# define PREPARE_MALLOC()					\
+{								\
+  asm volatile ("pcmpeqd %%xmm0, %%xmm0" : : : "xmm0" );	\
+  asm volatile ("pcmpeqd %%xmm1, %%xmm1" : : : "xmm1" );	\
+  asm volatile ("pcmpeqd %%xmm2, %%xmm2" : : : "xmm2" );	\
+  asm volatile ("pcmpeqd %%xmm3, %%xmm3" : : : "xmm3" );	\
+  asm volatile ("pcmpeqd %%xmm4, %%xmm4" : : : "xmm4" );	\
+  asm volatile ("pcmpeqd %%xmm5, %%xmm5" : : : "xmm5" );	\
+  asm volatile ("pcmpeqd %%xmm6, %%xmm6" : : : "xmm6" );	\
+  asm volatile ("pcmpeqd %%xmm7, %%xmm7" : : : "xmm7" );	\
 }
+#endif
 
 #include <elf/tst-gnu2-tls2.c>
+
+#ifndef TEST_AMX
+v2di v1, v2, v3;
+#endif
diff --git a/sysdeps/x86/tst-gnu2-tls2.h b/sysdeps/x86/tst-gnu2-tls2.h
new file mode 100644
index 0000000000..fdbb56500c
--- /dev/null
+++ b/sysdeps/x86/tst-gnu2-tls2.h
@@ -0,0 +1,37 @@
+/* Test TLSDESC relocation, x86 version.
+   Copyright (C) 2025 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#ifndef TEST_AMX
+# include <support/check.h>
+
+typedef long long v2di __attribute__((vector_size(16)));
+extern v2di v1, v2, v3;
+
+# define BEFORE_TLSDESC_CALL()					\
+  v1 = __extension__(v2di){0, 0};				\
+  v2 = __extension__(v2di){0, 0};
+
+# define AFTER_TLSDESC_CALL()					\
+  v3 = __extension__(v2di){0, 0};				\
+  asm volatile ("" : "+x" (v3));				\
+  union { v2di x; long long a[2]; } u;				\
+  u.x = v3;							\
+  TEST_VERIFY_EXIT (u.a[0] == 0 && u.a[1] == 0);
+#endif
+
+#include <elf/tst-gnu2-tls2.h>


More information about the Glibc-cvs mailing list