public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] x86-64: Fix the dtv field load for x32 [BZ #31184]
@ 2023-12-21  0:31 H.J. Lu
  2023-12-21 16:08 ` H.J. Lu
  0 siblings, 1 reply; 2+ messages in thread
From: H.J. Lu @ 2023-12-21  0:31 UTC (permalink / raw)
  To: libc-alpha

On x32, I got

FAIL: elf/tst-tlsgap

$ gdb elf/tst-tlsgap
...
open tst-tlsgap-mod1.so

Thread 2 "tst-tlsgap" received signal SIGSEGV, Segmentation fault.
[Switching to LWP 2268754]
_dl_tlsdesc_dynamic () at ../sysdeps/x86_64/dl-tlsdesc.S:108
108		movq	(%rsi), %rax
(gdb) p/x $rsi
$4 = 0xf7dbf9005655fb18
(gdb)

This is caused by

_dl_tlsdesc_dynamic:
        _CET_ENDBR
        /* Preserve call-clobbered registers that we modify.
           We need two scratch regs anyway.  */
        movq    %rsi, -16(%rsp)
        movq    %fs:DTV_OFFSET, %rsi

Since the dtv field in TCB is a pointer, %fs:DTV_OFFSET is a 32-bit
location, not 64-bit.  Load the dtv field to RSI_LP instead of rsi.
This fixes BZ #31184.
---
 sysdeps/x86_64/dl-tlsdesc.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sysdeps/x86_64/dl-tlsdesc.S b/sysdeps/x86_64/dl-tlsdesc.S
index 5593897e29..c4823547d7 100644
--- a/sysdeps/x86_64/dl-tlsdesc.S
+++ b/sysdeps/x86_64/dl-tlsdesc.S
@@ -102,7 +102,7 @@ _dl_tlsdesc_dynamic:
 	/* Preserve call-clobbered registers that we modify.
 	   We need two scratch regs anyway.  */
 	movq	%rsi, -16(%rsp)
-	movq	%fs:DTV_OFFSET, %rsi
+	mov	%fs:DTV_OFFSET, %RSI_LP
 	movq	%rdi, -8(%rsp)
 	movq	TLSDESC_ARG(%rax), %rdi
 	movq	(%rsi), %rax
-- 
2.43.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] x86-64: Fix the dtv field load for x32 [BZ #31184]
  2023-12-21  0:31 [PATCH] x86-64: Fix the dtv field load for x32 [BZ #31184] H.J. Lu
@ 2023-12-21 16:08 ` H.J. Lu
  0 siblings, 0 replies; 2+ messages in thread
From: H.J. Lu @ 2023-12-21 16:08 UTC (permalink / raw)
  To: libc-alpha, Libc-stable Mailing List

On Wed, Dec 20, 2023 at 4:31 PM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On x32, I got
>
> FAIL: elf/tst-tlsgap
>
> $ gdb elf/tst-tlsgap
> ...
> open tst-tlsgap-mod1.so
>
> Thread 2 "tst-tlsgap" received signal SIGSEGV, Segmentation fault.
> [Switching to LWP 2268754]
> _dl_tlsdesc_dynamic () at ../sysdeps/x86_64/dl-tlsdesc.S:108
> 108             movq    (%rsi), %rax
> (gdb) p/x $rsi
> $4 = 0xf7dbf9005655fb18
> (gdb)
>
> This is caused by
>
> _dl_tlsdesc_dynamic:
>         _CET_ENDBR
>         /* Preserve call-clobbered registers that we modify.
>            We need two scratch regs anyway.  */
>         movq    %rsi, -16(%rsp)
>         movq    %fs:DTV_OFFSET, %rsi
>
> Since the dtv field in TCB is a pointer, %fs:DTV_OFFSET is a 32-bit
> location, not 64-bit.  Load the dtv field to RSI_LP instead of rsi.
> This fixes BZ #31184.
> ---
>  sysdeps/x86_64/dl-tlsdesc.S | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/sysdeps/x86_64/dl-tlsdesc.S b/sysdeps/x86_64/dl-tlsdesc.S
> index 5593897e29..c4823547d7 100644
> --- a/sysdeps/x86_64/dl-tlsdesc.S
> +++ b/sysdeps/x86_64/dl-tlsdesc.S
> @@ -102,7 +102,7 @@ _dl_tlsdesc_dynamic:
>         /* Preserve call-clobbered registers that we modify.
>            We need two scratch regs anyway.  */
>         movq    %rsi, -16(%rsp)
> -       movq    %fs:DTV_OFFSET, %rsi
> +       mov     %fs:DTV_OFFSET, %RSI_LP
>         movq    %rdi, -8(%rsp)
>         movq    TLSDESC_ARG(%rax), %rdi
>         movq    (%rsi), %rax
> --
> 2.43.0
>

I will check it in tomorrow and back it to release branches later.

Thanks.

-- 
H.J.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-12-21 16:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-21  0:31 [PATCH] x86-64: Fix the dtv field load for x32 [BZ #31184] H.J. Lu
2023-12-21 16:08 ` H.J. Lu

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).