glibc/sysdeps/loongarch
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
..
bits Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
fpu math: Optimize float ilogb/llogb 2025-06-02 13:32:19 -03:00
lp64 math: Refactor how to use libm-test-ulps 2025-03-12 13:40:07 -03:00
nofpu Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
nptl Move <thread_pointer.h> to kernel-independent sysdeps directories 2025-01-09 19:30:16 +01:00
sys Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
Implies LoongArch: Build Infrastructure 2022-07-26 12:35:12 -03:00
Makefile LoongArch: Fix tst-gnu2-tls2 compiler error 2024-05-21 11:23:03 +08:00
__longjmp.S Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
abort-instr.h LoongArch: Linux Syscall Interface 2022-07-26 12:35:12 -03:00
bsd-_setjmp.c
bsd-setjmp.c
configure Convert to autoconf 2.72 (vanilla release, no distribution patches) 2024-06-17 21:15:28 +02:00
configure.ac LoongArch: Fix tst-gnu2-tls2 compiler error 2024-05-21 11:23:03 +08:00
cpu-tunables.c Fix typo in comment 2025-03-31 10:54:52 -03:00
dl-audit-check.h Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
dl-get-cpu-features.c 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-link.sym LoongArch: Add lasx/lsx support for _dl_runtime_profile. 2023-09-15 09:07:42 +08:00
dl-machine.h Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
dl-tls.h elf: Remove the remaining uses of GET_ADDR_OFFSET 2025-01-02 13:45:27 +01:00
dl-tlsdesc-dynamic.h Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
dl-tlsdesc.S Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -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
dl-trampoline.h Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
dl-tunables.list Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
e_sqrtl.c Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
fenv_private.h Implement C23 pown 2025-03-27 10:44:44 +00:00
fpu_control.h Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
hp-timing.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
ldsodefs.h Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
libc-tls.c elf: Remove the remaining uses of GET_ADDR_OFFSET 2025-01-02 13:45:27 +01:00
linkmap.h 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
math-use-builtins-ffs.h LoongArch: Use builtins for ffs and ffsll 2024-02-05 15:19:41 -03:00
preconfigure i386: Update ___tls_get_addr to preserve vector registers 2025-06-19 04:30:31 +08:00
preconfigure.ac i386: Update ___tls_get_addr to preserve vector registers 2025-06-19 04:30:31 +08:00
setjmp.S Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
sfp-machine.h Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
sotruss-lib.c 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
thread_pointer.h Move <thread_pointer.h> to kernel-independent sysdeps directories 2025-01-09 19:30:16 +01:00
tininess.h LoongArch: Generic <math.h> and soft-fp Routines 2022-07-26 12:35:12 -03:00
tlsdesc.c Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
tlsdesc.sym LoongArch: Add cfi instructions for _dl_tlsdesc_dynamic 2024-08-09 09:06:17 +08:00
tst-audit.h Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
tst-gnu2-tls2.h Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
tst-hwcap-tunables.c Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00