public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Xi Ruoyao <xry111@xry111.site>
To: mengqinggang <mengqinggang@loongson.cn>, libc-alpha@sourceware.org
Cc: adhemerval.zanella@linaro.org, xuchenghua@loongson.cn,
	caiyinyu@loongson.cn,  chenglulu@loongson.cn,
	cailulu@loongson.cn, i.swmail@xen0n.name,  maskray@google.com,
	luweining@loongson.cn, wanglei@loongson.cn,
	 hejinyang@loongson.cn
Subject: Re: [PATCH v6] LoongArch: Add support for TLS Descriptors
Date: Tue, 07 May 2024 19:41:56 +0800	[thread overview]
Message-ID: <c9f4fd5b7a3f202f6e29c23befa42a2502bbaa95.camel@xry111.site> (raw)
In-Reply-To: <7ce5fe6ee84503a167a35ef41018e2c030581367.camel@xry111.site>

On Tue, 2024-05-07 at 17:58 +0800, Xi Ruoyao wrote:
> On Tue, 2024-05-07 at 17:21 +0800, Xi Ruoyao wrote:
> > Unfortunately I'm getting a test failure:
> > 
> > FAIL: elf/tst-gnu2-tls2
> > original exit status 1
> > open tst-gnu2-tls2mod0.so
> > open tst-gnu2-tls2mod1.so
> > open tst-gnu2-tls2mod2.so
> > close tst-gnu2-tls2mod0.so
> > close tst-gnu2-tls2mod1.so
> > open tst-gnu2-tls2mod0.so
> > open tst-gnu2-tls2mod1.so
> > Didn't expect signal from child: got `Aborted'
> > 
> > The problem is GCC 14.1 has LSX enabled by default (!) and for
> > "tls_var1[1] = *p;" we get something like:
> > 
> >  17c:   1a000004        pcalau12i       $a0, 0
> >                         17c: R_LARCH_TLS_DESC_PC_HI20   .LANCHOR0
> >                         17c: R_LARCH_RELAX      *ABS*
> >  180:   02c00084        addi.d          $a0, $a0, 0
> >                         180: R_LARCH_TLS_DESC_PC_LO12   .LANCHOR0
> >                         180: R_LARCH_RELAX      *ABS*
> >  184:   28c00081        ld.d            $ra, $a0, 0
> >                         184: R_LARCH_TLS_DESC_LD        .LANCHOR0
> >                         184: R_LARCH_RELAX      *ABS*
> >  188:   4c000021        jirl            $ra, $ra, 0
> >                         188: R_LARCH_TLS_DESC_CALL      .LANCHOR0
> >                         188: R_LARCH_RELAX      *ABS*
> > 
> > 000000000000018c <L0^A>:
> >  18c:   2c004300        vld             $vr0, $s1, 16
> >  190:   2c000301        vld             $vr1, $s1, 0
> >  194:   0010888c        add.d           $t0, $a0, $tp
> >  198:   38440881        vstx            $vr1, $a0, $tp
> >  19c:   2c404180        vst             $vr0, $t0, 16
> > 
> > Thus the tlsdesc call does not clobber vr0 and vr1, but storing into
> > tls_var1[1] clobbers them.
> > 
> > While I don't think GCC should enable LSX by default (I've complained at
> > https://gcc.gnu.org/pipermail/gcc-patches/2024-May/650909.html),

FWIW: I was wrong.  It's clearly documented in the LoongArch Toolchain
Convention manual.  So we definitely to work this around in Glibc.

> > downstream may still build Glibc with LSX enabled (AFAIK AOSC
> > deliberately enables LSX building packages for LoongArch).  Maybe
> > disable LSX for tst-gnu2-tls2mod{0,1,2}.c ?
> 
> This fixes the issue for me:
> 
> diff --git a/sysdeps/loongarch/Makefile b/sysdeps/loongarch/Makefile
> index 86ede3534b..a4ee915eff 100644
> --- a/sysdeps/loongarch/Makefile
> +++ b/sysdeps/loongarch/Makefile
> @@ -31,6 +31,13 @@ ifeq ($(subdir),elf)
>  sysdep-dl-routines += \
>    dl-get-cpu-features \
>    # sysdep-dl-routines
> +
> +# Disable the compiler from using LSX for TLS descriptor tests, or storing into
> +# 16B TLS variable may clobber FP/vector registers and prevent us from checking
> +# their contents.
> +CFLAGS-tst-gnu2-tls2mod0.c += -mno-lsx
> +CFLAGS-tst-gnu2-tls2mod1.c += -mno-lsx
> +CFLAGS-tst-gnu2-tls2mod2.c += -mno-lsx
>  endif
>  
>  # LoongArch's assembler also needs to know about PIC as it changes the
> 
> But I'm not sure if this is the best way.
> 

-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University

      reply	other threads:[~2024-05-07 11:42 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-07  2:02 mengqinggang
2024-05-07  9:21 ` Xi Ruoyao
2024-05-07  9:58   ` Xi Ruoyao
2024-05-07 11:41     ` Xi Ruoyao [this message]

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=c9f4fd5b7a3f202f6e29c23befa42a2502bbaa95.camel@xry111.site \
    --to=xry111@xry111.site \
    --cc=adhemerval.zanella@linaro.org \
    --cc=cailulu@loongson.cn \
    --cc=caiyinyu@loongson.cn \
    --cc=chenglulu@loongson.cn \
    --cc=hejinyang@loongson.cn \
    --cc=i.swmail@xen0n.name \
    --cc=libc-alpha@sourceware.org \
    --cc=luweining@loongson.cn \
    --cc=maskray@google.com \
    --cc=mengqinggang@loongson.cn \
    --cc=wanglei@loongson.cn \
    --cc=xuchenghua@loongson.cn \
    /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).