glibc/sysdeps/x86
H.J. Lu 1ea16a207c i386: Update ___tls_get_addr to preserve vector registers
Compiler generates the following instruction sequence for dynamic TLS
access:

	leal	tls_var@tlsgd(,%ebx,1), %eax
	call	___tls_get_addr@PLT

CALL instruction is transparent to compiler which assumes all registers,
except for EFLAGS, AX, CX, and DX, are unchanged after CALL.  But
___tls_get_addr is a normal function which doesn't preserve any vector
registers.

1. Rename the generic __tls_get_addr function to ___tls_get_addr_internal.
2. Change ___tls_get_addr to a wrapper function with implementations for
FNSAVE, FXSAVE, XSAVE and XSAVEC to save and restore all vector registers.
3. dl-tlsdesc-dynamic.h has:

_dl_tlsdesc_dynamic:
	/* Like all TLS resolvers, preserve call-clobbered registers.
	   We need two scratch regs anyway.  */
	subl	$32, %esp
	cfi_adjust_cfa_offset (32)

It is wrong to use

	movl	%ebx, -28(%esp)
	movl	%esp, %ebx
	cfi_def_cfa_register(%ebx)
	...
	mov	%ebx, %esp
	cfi_def_cfa_register(%esp)
	movl	-28(%esp), %ebx

to preserve EBX on stack.  Fix it with:

	movl	%ebx, 28(%esp)
	movl	%esp, %ebx
	cfi_def_cfa_register(%ebx)
	...
	mov	%ebx, %esp
	cfi_def_cfa_register(%esp)
	movl	28(%esp), %ebx

4. Update _dl_tlsdesc_dynamic to call ___tls_get_addr_internal directly.
5. Add have-test-mtls-traditional to compile tst-tls23-mod.c with
traditional TLS variant to verify the fix.
6. Define DL_RUNTIME_RESOLVE_REALIGN_STACK in sysdeps/x86/sysdep.h.

This fixes BZ #32996.

Co-Authored-By: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
(cherry picked from commit 848f0e46f0)
2025-08-20 11:09:07 -07:00
..
bits x86-64/cet: Make CET feature check specific to Linux/x86 2025-08-19 15:39:23 -07:00
fpu Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
htl Fix a few more typos I missed in previous round -- BZ 25337 2023-06-02 23:46:32 +00:00
include x86: Use separate variable for TLSDESC XSAVE/XSAVEC state size (bug 32810) 2025-08-20 06:14:48 -07:00
nptl Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
sys/platform x86-64/cet: Make CET feature check specific to Linux/x86 2025-08-19 15:39:23 -07:00
Makeconfig
Makefile i386: Update ___tls_get_addr to preserve vector registers 2025-08-20 11:09:07 -07:00
Versions
__longjmp_cancel.S x86-64/cet: Check the restore token in longjmp 2025-08-19 15:39:23 -07:00
abi-note.c Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
atomic-machine.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
cacheinfo.c Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
cacheinfo.h Remove --enable-tunables configure option 2023-03-29 14:33:06 -03:00
configure i386: Ignore --enable-cet 2025-08-19 15:39:23 -07:00
configure.ac i386: Ignore --enable-cet 2025-08-19 15:39:23 -07:00
cpu-features-offsets.sym x86-64: Update _dl_tlsdesc_dynamic to preserve AMX registers 2025-08-19 18:22:00 -07:00
cpu-features.c x86: Optimize xstate size calculation 2025-08-20 11:09:07 -07:00
cpu-tunables.c x86: Use separate variable for TLSDESC XSAVE/XSAVEC state size (bug 32810) 2025-08-20 06:14:48 -07:00
dl-cacheinfo.h x86: Check the lower byte of EAX of CPUID leaf 2 [BZ #30643] 2025-01-09 07:31:17 -08:00
dl-diagnostics-cpu.c x86: Use separate variable for TLSDESC XSAVE/XSAVEC state size (bug 32810) 2025-08-20 06:14:48 -07:00
dl-get-cpu-features.c Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
dl-hwcap.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
dl-hwcap2.h x86: Set FSGSBASE to active if enabled by kernel 2023-04-03 11:36:48 -07:00
dl-isa-level.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
dl-lookupcfg.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
dl-minsigstacksize.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
dl-new-hash.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
dl-procinfo.c x86: Update _dl_tlsdesc_dynamic to preserve caller-saved registers 2025-08-19 18:22:00 -07:00
dl-procinfo.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
dl-prop.h Fix misspellings in sysdeps/ -- BZ 25337 2023-05-30 23:02:29 +00:00
dl-tunables.list Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
elf-initfini.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
elide.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
features-offsets.sym x86: Update _dl_tlsdesc_dynamic to preserve caller-saved registers 2025-08-19 18:22:00 -07:00
float128-abi.h
fpu_control.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
get-cpuid-feature-leaf.c x86-64/cet: Make CET feature check specific to Linux/x86 2025-08-19 15:39:23 -07:00
get-isa-level.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
hp-timing.h Fix misspellings in sysdeps/ -- BZ 25337 2023-05-30 23:02:29 +00:00
init-arch.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
isa-ifunc-macros.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
isa-level.c Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
isa-level.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
jmp_buf-ssp.sym
ldbl2mpn.c Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
ldsodefs.h i386: Remove CET support bits 2025-08-19 15:39:23 -07:00
libc-start.c Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
libc-start.h x86/cet: Enable shadow stack during startup 2025-08-19 15:39:23 -07:00
link_map.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
linkmap.h
longjmp.c Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
readelflib.c x86: Make dl-cache.h and readelflib.c not Linux-specific 2023-06-26 10:04:31 -03:00
sysdep.h i386: Update ___tls_get_addr to preserve vector registers 2025-08-20 11:09:07 -07:00
tininess.h
tst-cpu-features-cpuinfo-static.c
tst-cpu-features-cpuinfo.c x86/cet: Check user_shstk in /proc/cpuinfo 2025-08-19 15:39:23 -07:00
tst-cpu-features-supports-static.c
tst-cpu-features-supports.c i386: Disable Intel Xeon Phi tests for GCC 15 and above (BZ 31782) 2024-05-28 09:33:22 -07:00
tst-get-cpu-features-static.c
tst-get-cpu-features.c <sys/platform/x86.h>: Add APX support 2023-07-27 08:42:32 -07:00
tst-gnu2-tls2-x86-noxsave.c x86: Use separate variable for TLSDESC XSAVE/XSAVEC state size (bug 32810) 2025-08-20 06:14:48 -07:00
tst-gnu2-tls2-x86-noxsavec.c x86: Use separate variable for TLSDESC XSAVE/XSAVEC state size (bug 32810) 2025-08-20 06:14:48 -07:00
tst-gnu2-tls2-x86-noxsavexsavec.c x86: Use separate variable for TLSDESC XSAVE/XSAVEC state size (bug 32810) 2025-08-20 06:14:48 -07:00
tst-gnu2-tls2.c x86: Update _dl_tlsdesc_dynamic to preserve caller-saved registers 2025-08-19 18:22:00 -07:00
tst-ifunc-isa-1-static.c
tst-ifunc-isa-1.c Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
tst-ifunc-isa-2-static.c
tst-ifunc-isa-2.c Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
tst-ifunc-isa.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
tst-isa-level-1.c Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
tst-isa-level-mod-1-baseline.c
tst-isa-level-mod-1-v2.c
tst-isa-level-mod-1-v3.c
tst-isa-level-mod-1-v4.c
tst-isa-level-mod-1.c Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
tst-ldbl-nonnormal-printf.c Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
tst-memchr-rtm.c Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
tst-memcmp-rtm.c Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
tst-memmove-rtm.c Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
tst-memrchr-rtm.c Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
tst-memset-rtm.c Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
tst-setjmp-cet.c
tst-stack-align.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
tst-strcasecmp-rtm.c Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
tst-strchr-rtm.c Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
tst-strcmp-rtm.c Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
tst-strcpy-rtm.c Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
tst-string-rtm.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
tst-strlen-rtm.c Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
tst-strncasecmp-rtm.c Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
tst-strncmp-rtm.c Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
tst-strrchr-rtm.c Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
tst-sysconf-cache-linesize-static.c
tst-sysconf-cache-linesize.c Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
tst-tls23.c i386: Update ___tls_get_addr to preserve vector registers 2025-08-20 11:09:07 -07:00
tst-tls23.h i386: Update ___tls_get_addr to preserve vector registers 2025-08-20 11:09:07 -07:00
tst-wcscmp-rtm.c Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
tst-wcsncmp-rtm.c Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
utmp-size.h login: Check default sizes of structs utmp, utmpx, lastlog 2024-04-19 18:38:23 +02:00