From: "H.J. Lu" <hjl.tools@gmail.com>
To: libc-alpha@sourceware.org
Subject: [PATCH v4 0/2] x86: Update _dl_tlsdesc_dynamic to preserve caller-saved registers
Date: Mon, 12 Feb 2024 20:14:59 -0800 [thread overview]
Message-ID: <20240213041501.2494232-1-hjl.tools@gmail.com> (raw)
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 (2):
x86-64: Save APX registers in ld.so trampoline
x86: Update _dl_tlsdesc_dynamic to preserve caller-saved registers
elf/Makefile | 19 ++
elf/malloc-for-test.c | 32 ++++
elf/malloc-for-test.map | 6 +
elf/tst-gnu2-tls2.c | 97 ++++++++++
elf/tst-gnu2-tls2.h | 26 +++
elf/tst-gnu2-tls2mod0.c | 28 +++
elf/tst-gnu2-tls2mod1.c | 28 +++
elf/tst-gnu2-tls2mod2.c | 28 +++
sysdeps/i386/dl-machine.h | 2 +-
sysdeps/i386/dl-tlsdesc-dynamic.h | 187 +++++++++++++++++++
sysdeps/i386/dl-tlsdesc.S | 115 +++++-------
sysdeps/i386/tst-gnu2-tls2.c | 5 +
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/malloc-for-test.c | 33 ++++
sysdeps/x86/sysdep.h | 54 +++++-
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 +---
27 files changed, 973 insertions(+), 218 deletions(-)
create mode 100644 elf/malloc-for-test.c
create mode 100644 elf/malloc-for-test.map
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
create mode 100644 sysdeps/i386/tst-gnu2-tls2.c
rename sysdeps/{x86_64 => x86}/features-offsets.sym (89%)
create mode 100644 sysdeps/x86/malloc-for-test.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.0
next reply other threads:[~2024-02-13 4:15 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-13 4:14 H.J. Lu [this message]
2024-02-13 4:15 ` [PATCH v4 1/2] x86-64: Save APX registers in ld.so trampoline H.J. Lu
2024-02-13 4:15 ` [PATCH v4 2/2] x86: Update _dl_tlsdesc_dynamic to preserve caller-saved registers H.J. Lu
2024-02-14 22:44 ` Noah Goldstein
2024-02-14 23:21 ` H.J. Lu
2024-02-14 23:57 ` Noah Goldstein
2024-02-15 0:23 ` H.J. Lu
2024-02-15 23:05 ` Adhemerval Zanella Netto
2024-02-15 23:15 ` H.J. Lu
2024-02-16 6:23 ` Florian Weimer
2024-02-16 11:59 ` H.J. Lu
2024-02-16 12:18 ` Florian Weimer
2024-02-16 12:20 ` H.J. Lu
2024-02-16 12:37 ` H.J. Lu
2024-02-16 12:47 ` Adhemerval Zanella Netto
2024-02-16 12:58 ` H.J. Lu
2024-02-16 13:24 ` Adhemerval Zanella Netto
2024-02-16 14:25 ` H.J. Lu
2024-02-16 13:06 ` Florian Weimer
2024-02-16 13:24 ` H.J. Lu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240213041501.2494232-1-hjl.tools@gmail.com \
--to=hjl.tools@gmail.com \
--cc=libc-alpha@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).