From patchwork Tue Aug 23 12:28:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: caiyinyu X-Patchwork-Id: 1669276 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MBpSZ5YWpz1ygF for ; Tue, 23 Aug 2022 22:29:18 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BB37C3856951 for ; Tue, 23 Aug 2022 12:29:16 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by sourceware.org (Postfix) with ESMTP id 515CD3858D3C for ; Tue, 23 Aug 2022 12:28:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 515CD3858D3C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=loongson.cn Received: from 5.5.5 (unknown [10.2.5.5]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Bx5OHyxwRjSfoHAA--.35812S3; Tue, 23 Aug 2022 20:28:37 +0800 (CST) From: caiyinyu To: adhemerval.zanella@linaro.org, libc-alpha@sourceware.org, joseph_myers@mentor.com, carlos@redhat.com, i.swmail@xen0n.name, xry111@xry111.site Subject: [PATCH 1/2] LoongArch: Fix ptr mangling/demangling features. Date: Tue, 23 Aug 2022 20:28:32 +0800 Message-Id: <20220823122833.1561228-2-caiyinyu@loongson.cn> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220823122833.1561228-1-caiyinyu@loongson.cn> References: <20220823122833.1561228-1-caiyinyu@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Bx5OHyxwRjSfoHAA--.35812S3 X-Coremail-Antispam: 1UD129KBjvJXoW3Gw1xtryUWFyfJFW8XF1fWFg_yoW7Kw4rpr y7uF4rtFs7W3WfGrWqva4SgFn5JF4rGry7u3WSyr48AF4UAw1rZwsayr93Xayjgas5G3y0 vr1rK3WUu3Z8ZwUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUB214x267AKxVW5JVWrJwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_Jr4l82xGYIkIc2 x26xkF7I0E14v26r1I6r4UM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Cr0_Gr1UM2 8EF7xvwVC2z280aVAFwI0_Cr1j6rxdM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAS 0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2 IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0 Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCY02Avz4vE-syl42xK82IYc2 Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s02 6x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0x vE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE 42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6x kF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjfU5SoXUUUUU X-CM-SenderInfo: 5fdl5xhq1xqz5rrqw2lrqou0/ X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_PASS, 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 X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: xuchenghua@loongson.cn, caiyinyu Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" Co-authored-by: Xi Ruoyao --- 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 +++++++++++++--------- 5 files changed, 65 insertions(+), 19 deletions(-) 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) \ From patchwork Tue Aug 23 12:28:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: caiyinyu X-Patchwork-Id: 1669274 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MBpS91XCPz1ygF for ; Tue, 23 Aug 2022 22:28:57 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 736FE385782A for ; Tue, 23 Aug 2022 12:28:54 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by sourceware.org (Postfix) with ESMTP id 4D0FE3858D37 for ; Tue, 23 Aug 2022 12:28:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4D0FE3858D37 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=loongson.cn Received: from 5.5.5 (unknown [10.2.5.5]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Bx5OHyxwRjSfoHAA--.35812S4; Tue, 23 Aug 2022 20:28:39 +0800 (CST) From: caiyinyu To: adhemerval.zanella@linaro.org, libc-alpha@sourceware.org, joseph_myers@mentor.com, carlos@redhat.com, i.swmail@xen0n.name, xry111@xry111.site Subject: [PATCH 2/2] LoongArch: Add HAVE_LOONGARCH_EXPLICIT_RELOCS in config.h.in. Date: Tue, 23 Aug 2022 20:28:33 +0800 Message-Id: <20220823122833.1561228-3-caiyinyu@loongson.cn> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220823122833.1561228-1-caiyinyu@loongson.cn> References: <20220823122833.1561228-1-caiyinyu@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Bx5OHyxwRjSfoHAA--.35812S4 X-Coremail-Antispam: 1UD129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7v73 VFW2AGmfu7bjvjm3AaLaJ3UjIYCTnIWjp_UUUYA7AC8VAFwI0_Wr0E3s1l1xkIjI8I6I8E 6xAIw20EY4v20xvaj40_Wr0E3s1l1IIY67AEw4v_Jr0_Jr4l82xGYIkIc2x26280x7IE14 v26r15M28IrcIa0xkI8VCY1x0267AKxVW8JVW5JwA2ocxC64kIII0Yj41l84x0c7CEw4AK 67xGY2AK021l84ACjcxK6xIIjxv20xvE14v26F1j6w1UM28EF7xvwVC0I7IYx2IY6xkF7I 0E14v26F4j6r4UJwA2z4x0Y4vEx4A2jsIE14v26F4UJVW0owA2z4x0Y4vEx4A2jsIEc7Cj xVAFwI0_GcCE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrV C2j2WlYx0E2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE 7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lc2xSY4 AK6svPMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAF wI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc4 0Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AK xVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr 1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7VUjYiiDUU UUU== X-CM-SenderInfo: 5fdl5xhq1xqz5rrqw2lrqou0/ X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_PASS, 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 X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: xuchenghua@loongson.cn, caiyinyu Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" --- config.h.in | 3 +++ 1 file changed, 3 insertions(+) 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