From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oa1-x2c.google.com (mail-oa1-x2c.google.com [IPv6:2001:4860:4864:20::2c]) by sourceware.org (Postfix) with ESMTPS id DDA073858D32 for ; Mon, 29 Aug 2022 12:41:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DDA073858D32 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-oa1-x2c.google.com with SMTP id 586e51a60fabf-11eb8b133fbso5762513fac.0 for ; Mon, 29 Aug 2022 05:41:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:in-reply-to:organization:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc; bh=guQaV63JGsJF1tBqagHN3SReEaxJ+iRte2jj/WtIbd0=; b=dmvobY71U7XPB8FOYemlxHSjOI5TSkXUEJeyMgVSeN8KKcezgIa2YwNrNPiSKN3kns AdDImwuhYCOWhB/mQ4dYV7sB6byKKb3Yl0tFtu3UsPRogHsvVOWaVzYvLaNPDM/4s7Cy p037+s7z9U8v9aamI7Gjzlx+rtvxMXNxw7APiUk9ZybnefiekExaPo3VSp5EJhh6T8HW B4b4ZprgLfGRenphKLUhP3KMtjou8dXEx9qGmspxvIqbrr8Wko2q0q73lXFo6or1HOOK yfrUdZm3XEGLbXiYDif+Q+6/iB2fUdMOS51kRjNUA0c2V7WezgfnxMpGvCPSpJ7Z9blL MALQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:organization:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-message-state:from:to:cc; bh=guQaV63JGsJF1tBqagHN3SReEaxJ+iRte2jj/WtIbd0=; b=Xu++blBk2B7yW7cLii5EDTdFO5Y93bHL2PRnaa4y9A3M0uxMgzZoTEkqO33ZCpLjtK cwlipircA3FGv0r3/JxUu53v8AjkOn5DzdSU0PR+pbwsU+GZnKOFFXHfqWKeIVdMm9Qt LAHaRG+/VPU+pvXyH7bWgUnr0ygWdj0x7hRr+9NuRJYy3hmv385VDDFyikIPY9TCOGVj glwP/4t6nGoGHtqk4aVRWrmcfGUbyq6t30M22tv0HqfkcugFkauK+mr4l+87WaE61STL 8fi8u2bUGYle/arj2CtYYk/3itDSFVTfa/MXFzX3X9Gw8LZ2FSKjGz6uopkM5CejzYCT qjSQ== X-Gm-Message-State: ACgBeo0qvBAzHhga0/M44RURgUnjVCs3wjYkN3slneOxSdUlXez1rrYQ IEJuQ3hQ0Rth79xY2pEFWpfj4g== X-Google-Smtp-Source: AA6agR6OGkhBzSoVOIq8iD2HAU4XsPi0yVz/KwG+uRVQZRKGq5dV2y7SrLxrseitmLw6v6R5dM8X8Q== X-Received: by 2002:a05:6870:b520:b0:11d:5228:d87c with SMTP id v32-20020a056870b52000b0011d5228d87cmr7612895oap.13.1661776893185; Mon, 29 Aug 2022 05:41:33 -0700 (PDT) Received: from ?IPV6:2804:1b3:a7c0:745e:189c:ed50:a343:6adf? ([2804:1b3:a7c0:745e:189c:ed50:a343:6adf]) by smtp.gmail.com with ESMTPSA id m4-20020a4ad504000000b00425678b9c4bsm5102304oos.0.2022.08.29.05.41.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 29 Aug 2022 05:41:32 -0700 (PDT) Message-ID: <16ced1ba-c95e-8b1f-e75d-8ab45ed3949a@linaro.org> Date: Mon, 29 Aug 2022 09:41:29 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.2.0 Subject: Re: [PATCH 1/1] LoongArch: Fix ptr mangling/demangling features. To: Xi Ruoyao , caiyinyu , libc-alpha@sourceware.org, joseph_myers@mentor.com, carlos@redhat.com, i.swmail@xen0n.name Cc: xuchenghua@loongson.cn References: <20220826080339.2859494-1-caiyinyu@loongson.cn> <022a9844080de124bee3e921f9ddb3b6a4c937da.camel@xry111.site> Content-Language: en-US From: Adhemerval Zanella Netto Organization: Linaro In-Reply-To: <022a9844080de124bee3e921f9ddb3b6a4c937da.camel@xry111.site> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00,BODY_8BITS,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 29/08/22 04:08, Xi Ruoyao wrote: > I'm OK with either this or the simplified version w/o ac check. > > Not sure about Glibc policy about committing a change (does a port > maintainer needs approval to commit a change within this port?) Afaik as long the arch-maintainer is ok with the change and there is no blocker it should be ok to push. I stil prefer to just use la.pcrel, since it way simpler and I am really sceptical that using pcalau12i will yield any real performance difference, but it is not a blocker from my part. > > On Fri, 2022-08-26 at 16:03 +0800, caiyinyu wrote: >> Co-authored-by: Xi Ruoyao >> --- >>  config.h.in                                |  3 ++ >>  sysdeps/loongarch/__longjmp.S              |  2 +- >>  sysdeps/loongarch/configure                | 26 ++++++++++++++ >>  sysdeps/loongarch/configure.ac             | 14 ++++++++ >>  sysdeps/loongarch/setjmp.S                 |  2 +- >>  sysdeps/unix/sysv/linux/loongarch/sysdep.h | 40 +++++++++++++-------- >> - >>  6 files changed, 68 insertions(+), 19 deletions(-) >> >> diff --git a/config.h.in b/config.h.in >> index 43d32518ab..b182de0e91 100644 >> --- a/config.h.in >> +++ b/config.h.in >> @@ -138,6 +138,9 @@ >>  /* LOONGARCH floating-point ABI for ld.so.  */ >>  #undef LOONGARCH_ABI_FRLEN >>   >> +/* To Indicate whether we can use explicit relocs or not.  */ >> +#undef HAVE_LOONGARCH_EXPLICIT_RELOCS >> + >>  /* Linux specific: minimum supported kernel version.  */ >>  #undef __LINUX_KERNEL_VERSION >>   >> diff --git a/sysdeps/loongarch/__longjmp.S >> b/sysdeps/loongarch/__longjmp.S >> index c2c5b56a80..4207376f5e 100644 >> --- a/sysdeps/loongarch/__longjmp.S >> +++ b/sysdeps/loongarch/__longjmp.S >> @@ -22,7 +22,7 @@ >>  ENTRY (__longjmp) >>  #ifdef PTR_MANGLE >>         REG_L t0, a0, 0*SZREG >> -       PTR_DEMANGLE (ra, t0, t1, t2) >> +       PTR_DEMANGLE (ra, t0, t1) >>         REG_L t0, a0, 1*SZREG >>         PTR_DEMANGLE2 (sp, t0, t1) >>  #else >> diff --git a/sysdeps/loongarch/configure b/sysdeps/loongarch/configure >> index 43b54d4965..54385786d2 100644 >> --- a/sysdeps/loongarch/configure >> +++ b/sysdeps/loongarch/configure >> @@ -3,3 +3,29 @@ >>   >>  $as_echo "#define HIDDEN_VAR_NEEDS_DYNAMIC_RELOC 1" >>confdefs.h >>   >> + >> +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether explicit >> relocs can be used" >&5 >> +$as_echo_n "checking whether explicit relocs can be used... " >&6; } >> +if ${libc_cv_loongarch_explicit_relocs+:} false; then : >> +  $as_echo_n "(cached) " >&6 >> +else >> +  cat > conftest.s << EOF >> +x: pcalau12i \$t0, %pc_hi20(x) >> +EOF >> +libc_cv_loongarch_explicit_relocs=no >> +if { ac_try='${CC-cc} -c $CFLAGS conftest.s -o conftest.o 1>&5' >> +  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >>> &5 >> +  (eval $ac_try) 2>&5 >> +  ac_status=$? >> +  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 >> +  test $ac_status = 0; }; }; then >> +  libc_cv_loongarch_explicit_relocs=yes >> +fi >> +rm -f conftest* >> +fi >> +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: >> $libc_cv_loongarch_explicit_relocs" >&5 >> +$as_echo "$libc_cv_loongarch_explicit_relocs" >&6; } >> +if test $libc_cv_loongarch_explicit_relocs = yes; then >> +  $as_echo "#define HAVE_LOONGARCH_EXPLICIT_RELOCS 1" >>confdefs.h >> + >> +fi >> diff --git a/sysdeps/loongarch/configure.ac >> b/sysdeps/loongarch/configure.ac >> index f744367bf3..c5d3cb5ead 100644 >> --- a/sysdeps/loongarch/configure.ac >> +++ b/sysdeps/loongarch/configure.ac >> @@ -4,3 +4,17 @@ GLIBC_PROVIDES dnl See aclocal.m4 in the top level >> source directory. >>  dnl It is always possible to access static and hidden symbols in an >>  dnl position independent way. >>  AC_DEFINE(HIDDEN_VAR_NEEDS_DYNAMIC_RELOC) >> + >> +AC_CACHE_CHECK(whether explicit relocs can be used, >> +               libc_cv_loongarch_explicit_relocs, [dnl >> +cat > conftest.s << EOF >> +x: pcalau12i \$t0, %pc_hi20(x) >> +EOF >> +libc_cv_loongarch_explicit_relocs=no >> +if AC_TRY_COMMAND(${CC-cc} -c $CFLAGS conftest.s -o conftest.o >> 1>&AS_MESSAGE_LOG_FD); then >> +  libc_cv_loongarch_explicit_relocs=yes >> +fi >> +rm -f conftest*]) >> +if test $libc_cv_loongarch_explicit_relocs = yes; then >> +  AC_DEFINE(HAVE_LOONGARCH_EXPLICIT_RELOCS) >> +fi >> diff --git a/sysdeps/loongarch/setjmp.S b/sysdeps/loongarch/setjmp.S >> index ec4ddc72da..298bb02a82 100644 >> --- a/sysdeps/loongarch/setjmp.S >> +++ b/sysdeps/loongarch/setjmp.S >> @@ -30,7 +30,7 @@ END (setjmp) >>   >>  ENTRY (__sigsetjmp) >>  #ifdef PTR_MANGLE >> -       PTR_MANGLE (t0, ra, t1, t2) >> +       PTR_MANGLE (t0, ra, t1) >>         REG_S t0, a0, 0*SZREG >>         PTR_MANGLE2 (t0, sp, t1) >>         REG_S t0, a0, 1*SZREG >> diff --git a/sysdeps/unix/sysv/linux/loongarch/sysdep.h >> b/sysdeps/unix/sysv/linux/loongarch/sysdep.h >> index 157cbd6c6b..0a8773c38d 100644 >> --- a/sysdeps/unix/sysv/linux/loongarch/sysdep.h >> +++ b/sysdeps/unix/sysv/linux/loongarch/sysdep.h >> @@ -316,29 +316,35 @@ extern long int __syscall_error (long int >> neg_errno); >>   >>  /* Pointer mangling is supported for LoongArch.  */ >>   >> -/* Load or store to/from a got-relative EXPR into/from G, using T. >> +/* Load a got-relative EXPR into G, using T. >>     Note G and T are register names.  */ >> -#define LDST_GLOBAL(OP, G, T,  EXPR) \ >> -  pcalau12i T, %got_pc_hi20(EXPR); \ >> -  OP       T, T, %got_pc_lo12(EXPR); \ >> -  OP       G, T, 0; >> +#define LD_GLOBAL(G, EXPR) \ >> +  la.global G, EXPR; \ >> +  REG_L            G,  G,  0; >>   >> -/* Load or store to/from a pc-relative EXPR into/from G, using T. >> +/* Load a pc-relative EXPR into G, using T. >>     Note G and T are register names.  */ >> -#define LDST_PCREL(OP, G, T,  EXPR) \ >> -  pcalau12i T, %pc_hi20(EXPR); \ >> -  OP       G, T, %pc_lo12(EXPR); >> + >> +#ifdef HAVE_LOONGARCH_EXPLICIT_RELOCS >> +#define LD_PCREL(G, EXPR) \ >> +  pcalau12i G, %pc_hi20(EXPR); \ >> +  REG_L            G,  G,  %pc_lo12(EXPR); >> +#else >> +#define LD_PCREL(G, EXPR) \ >> +  la.pcrel  G, EXPR; \ >> +  REG_L            G,  G,  0; >> +#endif >>   >>  #if (IS_IN (rtld) \ >>       || (!defined SHARED && (IS_IN (libc) \ >>       || IS_IN (libpthread)))) >>   >>  #ifdef __ASSEMBLER__ >> -#define PTR_MANGLE(dst, src, guard, tmp) \ >> -  LDST_PCREL (REG_L, guard, tmp, __pointer_chk_guard_local); \ >> +#define PTR_MANGLE(dst, src, guard) \ >> +  LD_PCREL (guard, __pointer_chk_guard_local); \ >>    PTR_MANGLE2 (dst, src, guard); >> -#define PTR_DEMANGLE(dst, src, guard, tmp) \ >> -  LDST_PCREL (REG_L, guard, tmp, __pointer_chk_guard_local); \ >> +#define PTR_DEMANGLE(dst, src, guard) \ >> +  LD_PCREL (guard, __pointer_chk_guard_local); \ >>    PTR_DEMANGLE2 (dst, src, guard); >>  /* Use PTR_MANGLE2 for efficiency if guard is already loaded.  */ >>  #define PTR_MANGLE2(dst, src, guard) \ >> @@ -355,11 +361,11 @@ extern uintptr_t __pointer_chk_guard_local >> attribute_relro attribute_hidden; >>  #else >>   >>  #ifdef __ASSEMBLER__ >> -#define PTR_MANGLE(dst, src, guard, tmp) \ >> -  LDST_GLOBAL (REG_L, guard, tmp, __pointer_chk_guard); \ >> +#define PTR_MANGLE(dst, src, guard) \ >> +  LD_GLOBAL (guard, __pointer_chk_guard); \ >>    PTR_MANGLE2 (dst, src, guard); >> -#define PTR_DEMANGLE(dst, src, guard, tmp) \ >> -  LDST_GLOBAL (REG_L, guard, tmp, __pointer_chk_guard); \ >> +#define PTR_DEMANGLE(dst, src, guard) \ >> +  LD_GLOBAL (guard, __pointer_chk_guard); \ >>    PTR_DEMANGLE2 (dst, src, guard); >>  /* Use PTR_MANGLE2 for efficiency if guard is already loaded.  */ >>  #define PTR_MANGLE2(dst, src, guard) \ >