public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: "H.J. Lu" <hjl.tools@gmail.com>
To: libc-alpha@sourceware.org
Cc: goldstein.w.n@gmail.com, fweimer@redhat.com,
	adhemerval.zanella@linaro.org
Subject: [PATCH v8 0/2] x86: Update _dl_tlsdesc_dynamic to preserve caller-saved registers
Date: Fri, 16 Feb 2024 07:17:09 -0800	[thread overview]
Message-ID: <20240216151711.2742988-1-hjl.tools@gmail.com> (raw)

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 (2):
  x86-64: Save APX registers in ld.so trampoline
  x86: Update _dl_tlsdesc_dynamic to preserve caller-saved registers

 elf/Makefile                                 |  14 ++
 elf/tst-gnu2-tls2.c                          | 120 ++++++++++++
 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                         |  56 +++++-
 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, 959 insertions(+), 218 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.0


             reply	other threads:[~2024-02-16 15:17 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-16 15:17 H.J. Lu [this message]
2024-02-16 15:17 ` [PATCH v8 1/2] x86-64: Save APX registers in ld.so trampoline H.J. Lu
2024-02-24 19:01   ` Noah Goldstein
2024-03-08 20:09     ` H.J. Lu
2024-03-09 17:39       ` Noah Goldstein
2024-02-16 15:17 ` [PATCH v8 2/2] x86: Update _dl_tlsdesc_dynamic to preserve caller-saved registers H.J. Lu
2024-02-24 17:09   ` Noah Goldstein
2024-02-24 17:30     ` H.J. Lu
2024-02-24 17:39       ` Noah Goldstein
2024-02-24 18:00         ` H.J. Lu
2024-02-24 18:45           ` Noah Goldstein
2024-02-24 18:52             ` H.J. Lu
2024-02-24 18:59               ` Noah Goldstein
2024-02-24 19:00   ` Noah Goldstein
2024-02-24 19:10     ` H.J. Lu
2024-02-22 20:24 ` PING: [PATCH v8 0/2] " 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=20240216151711.2742988-1-hjl.tools@gmail.com \
    --to=hjl.tools@gmail.com \
    --cc=adhemerval.zanella@linaro.org \
    --cc=fweimer@redhat.com \
    --cc=goldstein.w.n@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).