[PATCH v10 0/1] x86: Update _dl_tlsdesc_dynamic to preserve caller-saved registers
H.J. Lu
hjl.tools@gmail.com
Mon Feb 26 14:37:02 GMT 2024
Changes in v10:
1. Change the test to xfail.
Changes in v9:
1. Drop the first patch which has been merged into master branch.
2. Correct BEFORE_TLSDESC_CALL placement in test.
3. Define MOD only if undefined in test.
Changes in v8:
1. Remove malloc-for-test.c and move malloc to tst-gnu2-tls2.c.
2. Add malloc_counter to verify malloc in tst-gnu2-tls2.c is called for
TLSDESC call.
3. Add BEFORE_TLSDESC_CALL and AFTER_TLSDESC_CALL.
4. Use /* ... */ in assembly code comments.
Changes in v7:
1. Generate malloc-for-test.map at build time to get the correct version
map for malloc.
Changes in v6:
1. Drop Tile registers.
Changes in v5:
1. Also preserve Tile registers.
2. Add an error check in i386 dl-tlsdesc-dynamic.h.
Changes in v4:
1. Add APX registers to STATE_SAVE_MASK so that APX registers are saved
in ld.so trampoline.
2. Also save x87 FPU stack registers for TLSDESC_CALL and TLS_DESC_CALL.
3. Change i386 _dl_tlsdesc_dynamic to IFUNC.
4. Rename GLRO(dl_x86_64_tlsdesc_dynamic) to GLRO(dl_x86_tlsdesc_dynamic)
for both i386 and x86-64.
5. Update the testcase for i386 with a simple malloc interceptor.
Changes in v3:
1. Don't add GLRO(dl_x86_64_tlsdesc_dynamic) to libc.a.
Changes in v2:
1. Add GLRO(dl_x86_64_runtime_resolve) to optimize
elf_machine_runtime_setup.
---
Add APX registers to STATE_SAVE_MASK so that APX registers are saved in
ld.so trampoline. This fixes BZ #31371.
Compiler generates the following instruction sequence for GNU2 dynamic
TLS access:
leaq tls_var@TLSDESC(%rip), %rax
call *tls_var@TLSCALL(%rax)
or
leal tls_var@TLSDESC(%ebx), %eax
call *tls_var@TLSCALL(%eax)
CALL instruction is transparent to compiler which assumes all registers,
except for EFLAGS and RAX/EAX, are unchanged after CALL. When
_dl_tlsdesc_dynamic is called, it calls __tls_get_addr on the slow
path. __tls_get_addr is a normal function which doesn't preserve any
caller-saved registers. _dl_tlsdesc_dynamic saved and restored integer
caller-saved registers, but didn't preserve any other caller-saved
registers. Add _dl_tlsdesc_dynamic IFUNC functions for FNSAVE, FXSAVE,
XSAVE and XSAVEC to save and restore all caller-saved registers. This
fixes BZ #31372.
Add GLRO(dl_x86_64_runtime_resolve) with GLRO(dl_x86_tlsdesc_dynamic)
to optimize elf_machine_runtime_setup.
H.J. Lu (1):
x86: Update _dl_tlsdesc_dynamic to preserve caller-saved registers
elf/Makefile | 18 ++
elf/tst-gnu2-tls2.c | 122 ++++++++++++
elf/tst-gnu2-tls2.h | 36 ++++
elf/tst-gnu2-tls2mod0.c | 31 +++
elf/tst-gnu2-tls2mod1.c | 31 +++
elf/tst-gnu2-tls2mod2.c | 31 +++
sysdeps/i386/dl-machine.h | 2 +-
sysdeps/i386/dl-tlsdesc-dynamic.h | 190 +++++++++++++++++++
sysdeps/i386/dl-tlsdesc.S | 115 +++++------
sysdeps/x86/Makefile | 7 +-
sysdeps/x86/cpu-features.c | 56 +++++-
sysdeps/x86/dl-procinfo.c | 16 ++
sysdeps/{x86_64 => x86}/features-offsets.sym | 2 +
sysdeps/x86/sysdep.h | 6 +
sysdeps/x86/tst-gnu2-tls2.c | 20 ++
sysdeps/x86_64/Makefile | 2 +-
sysdeps/x86_64/dl-machine.h | 19 +-
sysdeps/x86_64/dl-procinfo.c | 16 ++
sysdeps/x86_64/dl-tlsdesc-dynamic.h | 166 ++++++++++++++++
sysdeps/x86_64/dl-tlsdesc.S | 108 ++++-------
sysdeps/x86_64/dl-trampoline-save.h | 34 ++++
sysdeps/x86_64/dl-trampoline-state.h | 51 +++++
sysdeps/x86_64/dl-trampoline.S | 20 +-
sysdeps/x86_64/dl-trampoline.h | 34 +---
24 files changed, 920 insertions(+), 213 deletions(-)
create mode 100644 elf/tst-gnu2-tls2.c
create mode 100644 elf/tst-gnu2-tls2.h
create mode 100644 elf/tst-gnu2-tls2mod0.c
create mode 100644 elf/tst-gnu2-tls2mod1.c
create mode 100644 elf/tst-gnu2-tls2mod2.c
create mode 100644 sysdeps/i386/dl-tlsdesc-dynamic.h
rename sysdeps/{x86_64 => x86}/features-offsets.sym (89%)
create mode 100644 sysdeps/x86/tst-gnu2-tls2.c
create mode 100644 sysdeps/x86_64/dl-tlsdesc-dynamic.h
create mode 100644 sysdeps/x86_64/dl-trampoline-save.h
create mode 100644 sysdeps/x86_64/dl-trampoline-state.h
--
2.43.2
More information about the Libc-alpha
mailing list