glibc/sysdeps/i386
H.J. Lu 848f0e46f0 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>
2025-06-19 04:30:31 +08:00
..
fpu math: Remove i386 ilogb/ilogbf/llogb/llogbf 2025-06-02 13:32:19 -03:00
htl Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
i586 Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
i686 math: Refactor how to use libm-test-ulps 2025-03-12 13:40:07 -03:00
i786
nptl nptl: Introduce <rseq-access.h> for RSEQ_* accessors 2025-01-10 20:20:17 +00:00
sys Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
Implies
Makefile i386: Update ___tls_get_addr to preserve vector registers 2025-06-19 04:30:31 +08:00
Versions
____longjmp_chk.S
__longjmp.S Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
abort-instr.h
add_n.S Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
addmul_1.S Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
asm-syntax.h Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
backtrace.c Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
bsd-_setjmp.S Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
bsd-setjmp.S Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
configure Convert to autoconf 2.72 (vanilla release, no distribution patches) 2024-06-17 21:15:28 +02:00
configure.ac i386: Fail if configured with --enable-cet 2024-01-09 13:55:51 -03:00
crti.S Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
crtn.S Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
dl-fixup-attribute.h Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
dl-irel.h Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
dl-machine-rel.h Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
dl-machine.h Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
dl-procinfo.c Remove unused dl-procinfo.h 2025-02-28 16:55:18 +00:00
dl-tls-get-addr.c i386: Update ___tls_get_addr to preserve vector registers 2025-06-19 04:30:31 +08:00
dl-tls.h i386: Update ___tls_get_addr to preserve vector registers 2025-06-19 04:30:31 +08:00
dl-tlsdesc-dynamic.h i386: Update ___tls_get_addr to preserve vector registers 2025-06-19 04:30:31 +08:00
dl-tlsdesc.S i386: Update ___tls_get_addr to preserve vector registers 2025-06-19 04:30:31 +08:00
dl-tlsdesc.h Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
dl-trampoline.S Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
gccframe.h Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
i386-mcount.S Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
isa.h Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
jmpbuf-offsets.h Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
jmpbuf-unwind.h Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
link-defines.sym
lshift.S Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
machine-gmon.h Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
malloc-alignment.h Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
math-use-builtins-ffs.h string: Use builtins for ffs and ffsll 2024-02-01 09:31:33 -03:00
memchr.S Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
memcmp.S Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
memcopy.h Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
memcpy.S Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
memcpy_chk.S Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
memmove.S
memmove_chk.S Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
mempcpy.S
mempcpy_chk.S Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
memset.S Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
memset_chk.S Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
mp_clz_tab.c
mul_1.S Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
preconfigure
pthread_spin_trylock.S Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
rawmemchr.S Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
rshift.S Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
setfpucw.c Remove dl-procinfo.h 2025-03-05 11:22:09 -03:00
setjmp.S Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
stackguard-macros.h
stackinfo.h Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
start.S Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
stpcpy.S Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
stpncpy.S Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
strcat.S Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
strchr.S Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
strchrnul.S Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
strcspn.S Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
string-inlines.c Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
string-opthr.h Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
strlen.S Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
strlen.c Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
strpbrk.S Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
strrchr.S Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
strspn.S Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
sub_n.S Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
submul_1.S Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
symbol-hacks.h Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
sysdep.h Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
tls-get-addr-wrapper.h i386: Update ___tls_get_addr to preserve vector registers 2025-06-19 04:30:31 +08:00
tls_get_addr.S i386: Update ___tls_get_addr to preserve vector registers 2025-06-19 04:30:31 +08:00
tls_get_addr.h i386: Update ___tls_get_addr to preserve vector registers 2025-06-19 04:30:31 +08:00
tlsdesc.c Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
tlsdesc.sym
tst-audit.h Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
tst-audit3.c Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
tst-audit3.h Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
tst-auditmod3a.c Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
tst-auditmod3b.c Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
tst-ld-sse-use.sh Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
unwind-arch.h Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00