From patchwork Fri Jul 29 02:43:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: chenglulu X-Patchwork-Id: 283 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6a10:b5d6:b0:2b9:3548:2db5 with SMTP id v22csp575896pxt; Thu, 28 Jul 2022 19:44:30 -0700 (PDT) X-Google-Smtp-Source: AGRyM1u943l/rRPR25C1HKrUfQuLYcu7ZvzHRxHiuQCxhPwPE7D+jOALgg10XuaR9vXqGqTLLDfJ X-Received: by 2002:a17:907:1c11:b0:72f:20:e1ea with SMTP id nc17-20020a1709071c1100b0072f0020e1eamr1264354ejc.427.1659062670260; Thu, 28 Jul 2022 19:44:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659062670; cv=none; d=google.com; s=arc-20160816; b=0DQs/tq5WPu4V23EFzXIEAxS12c1rz7Bgp3PluWu0J/GuUjgrnB5Hqrs4Gcs9U+Piz pOsfBwt7f+X9R7Tk3LaT9Y7Amm0N8lNbOetUndoHYw8rYRKrVXjlDupJVfufkXiTwiQ2 yQd3yiBWuSwdqRkfs8zzoUvbnV/ETFs2PzpnfoeRhETcv2Irwoa4LL8f5bmQffJeBfJz cj8Mqgru8O1luEDvC1XK0xpwD3lfwHShV1rqW5kIFDjXLUBM4eNkhEsu8vZTfzF6MzXC eTzrbPA4y4zXEbgosYf5lAqn0poLGSkp9IWoKfkibGfQS4gdT0CIGEzjesf9qowMErCV /1SA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dmarc-filter :delivered-to; bh=T+69slfmWgUIIyHt/8rGBRvehyLJkf1ne4AjwHA4evg=; b=RyaWazfdfNfoL2+HRM8yo2eMB4aw9MdtxAWnzRODQWP5vOLPeHlIOW8KcwAJeddoHl RcWmwaZES79P8vWMYqBZESafzJdu/Y4omGDqauEq1Rc8TBQYv2lpg7W8C5ngyqA4nlEY jrBPbCFRVVPL3/TplERaQuihkLqPQLJ/L4m1FTZ9SPWSLsYuriqcinQ0Vq1Wo05/ZAWn 7jDFmsYvX4QRxerHp/CFn8DWtArNpAE20Yx/USeU714yx9kXP088MTHrzOQwfrBQk7Hm 2MvCAWQUFzMsWKRsaU92qV2J+h9cCcl09zr1Z+alY6iQ+SSQ8UcmhJRKP5FT2MFCbeCu Rvnw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id y13-20020aa7d50d000000b0043a6e795a19si1867228edq.517.2022.07.28.19.44.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Jul 2022 19:44:30 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7F27C385381A for ; Fri, 29 Jul 2022 02:44:25 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by sourceware.org (Postfix) with ESMTP id C9E1A385840A for ; Fri, 29 Jul 2022 02:43:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C9E1A385840A 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 mail.loongson.cn (Coremail) with SMTP id AQAAf9DxL9FkSeNiv9FAAA--.3449S2; Fri, 29 Jul 2022 10:43:53 +0800 (CST) From: Lulu Cheng To: gcc-patches@gcc.gnu.org Subject: [PATCH v1] LoongArch: Define the macro ASM_PREFERRED_EH_DATA_FORMAT by checking the assembler's support for eh_frame encoding. Date: Fri, 29 Jul 2022 10:43:38 +0800 Message-Id: <20220729024337.4182683-1-chenglulu@loongson.cn> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-CM-TRANSID: AQAAf9DxL9FkSeNiv9FAAA--.3449S2 X-Coremail-Antispam: 1UD129KBjvJXoW3Ar48JFWktw13WF13Kr4Uurg_yoW7KrWfpF yfZwn8trWkWr1xGw4DXF4fGws3tr97ury29ay3uF48Cay7JFy0vw15tFsxXr18Wa93Jrya vr1rKr47W3s8AFDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUka14x267AKxVWUJVW8JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26F1j6w1UM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26F4j 6r4UJwA2z4x0Y4vEx4A2jsIE14v26r4UJVWxJr1l84ACjcxK6I8E87Iv6xkF7I0E14v26r xl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj 6xIIjxv20xvE14v26r1Y6r17McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr 0_Gr1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7MxkIecxEwVCm-wCF 04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r 18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIxkGc2Ij64vI r41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr 1lIxAIcVCF04k26cxKx2IYs7xG6Fyj6rWUJwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY 6I8E87Iv6xkF7I0E14v26r1j6r4UYxBIdaVFxhVjvjDU0xZFpf9x0JU9189UUUUU= X-CM-SenderInfo: xfkh0wpoxo3qxorr0wxvrqhubq/ X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, BODY_8BITS, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP 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: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: xuchenghua@loongson.cn, Lulu Cheng , i@xen0n.name Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1739653298230018162?= X-GMAIL-MSGID: =?utf-8?q?1739653298230018162?= The ASM_PREFERRED_EH_DATA_FORMAT macro before and after modification is as follows: #define ASM_PREFERRED_EH_DATA_FORMAT(CODE, GLOBAL) \ - (((GLOBAL) ? DW_EH_PE_indirect : 0) | DW_EH_PE_absptr) + (((GLOBAL) ? DW_EH_PE_indirect : 0) | DW_EH_PE_pcrel | DW_EH_PE_sdata4) Use the following tests to describe the effect of modifying this macro on the generated assembly code: #include #include using namespace std; int main() {   try {   throw 1;   }   catch (int i)   {     cout << i << endl;   } } The main comparisons related to the eh_frame section are as follows:        OLD NEW .LFB1997 = . | .LFB1780 = . .cfi_startproc | .cfi_startproc .cfi_personality 0x80,DW.ref.__gxx_personality_v0 | .cfi_personality 0x9b,DW.ref.__gxx_personality_v0 .cfi_lsda 0,.LLSDA1997 | .cfi_lsda 0x1b,.LLSDA1780 If the assembly file generated by the new gcc is compiled with the binutils of version 2.38, the following error will be reported: test.s:74: Error: invalid or unsupported encoding in .cfi_personality test.s:75: Error: invalid or unsupported encoding in .cfi_lsda So I think I should judge whether binutils supports this encoding when gcc is configured, and then choose how to define macro ASM_PREFERRED_EH_DATA_FORMAT. ------------ .eh_frame DW_EH_PE_pcrel encoding format is not supported by gas <= 2.39. Check if the assembler support DW_EH_PE_PCREL encoding and define .eh_frame encoding type. gcc/ChangeLog: * config.in: Regenerate. * config/loongarch/loongarch.h (ASM_PREFERRED_EH_DATA_FORMAT): Select the value of the macro definition according to whether HAVE_AS_EH_FRAME_PCREL_ENCODING_SUPPORT is defined. * configure: Regenerate. * configure.ac: Reinstate HAVE_AS_EH_FRAME_PCREL_ENCODING_SUPPORT test. --- gcc/config.in | 8 +++++++- gcc/config/loongarch/loongarch.h | 5 +++++ gcc/configure | 35 ++++++++++++++++++++++++++++++++ gcc/configure.ac | 9 ++++++++ 4 files changed, 56 insertions(+), 1 deletion(-) diff --git a/gcc/config.in b/gcc/config.in index 16bb963b45b..413b2bd36cb 100644 --- a/gcc/config.in +++ b/gcc/config.in @@ -404,13 +404,19 @@ #endif +/* Define if your assembler supports eh_frame pcrel encoding. */ +#ifndef USED_FOR_TARGET +#undef HAVE_AS_EH_FRAME_PCREL_ENCODING_SUPPORT +#endif + + /* Define if your assembler supports the R_PPC64_ENTRY relocation. */ #ifndef USED_FOR_TARGET #undef HAVE_AS_ENTRY_MARKERS #endif -/* Define if your assembler supports explicit relocations. */ +/* Define if your assembler supports explicit relocation. */ #ifndef USED_FOR_TARGET #undef HAVE_AS_EXPLICIT_RELOCS #endif diff --git a/gcc/config/loongarch/loongarch.h b/gcc/config/loongarch/loongarch.h index 89a5bd728fe..8b1288961e4 100644 --- a/gcc/config/loongarch/loongarch.h +++ b/gcc/config/loongarch/loongarch.h @@ -1127,8 +1127,13 @@ struct GTY (()) machine_function }; #endif +#ifdef HAVE_AS_EH_FRAME_PCREL_ENCODING_SUPPORT +#define ASM_PREFERRED_EH_DATA_FORMAT(CODE, GLOBAL) \ + (((GLOBAL) ? DW_EH_PE_indirect : 0) | DW_EH_PE_pcrel | DW_EH_PE_sdata4) +#else #define ASM_PREFERRED_EH_DATA_FORMAT(CODE, GLOBAL) \ (((GLOBAL) ? DW_EH_PE_indirect : 0) | DW_EH_PE_absptr) +#endif /* Do emit .note.GNU-stack by default. */ #ifndef NEED_INDICATE_EXEC_STACK diff --git a/gcc/configure b/gcc/configure index 7eb9479ae8e..1e1a264b92a 100755 --- a/gcc/configure +++ b/gcc/configure @@ -28836,6 +28836,41 @@ if test $gcc_cv_as_loongarch_explicit_relocs = yes; then $as_echo "#define HAVE_AS_EXPLICIT_RELOCS 1" >>confdefs.h +fi + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for eh_frame pcrel encoding support" >&5 +$as_echo_n "checking assembler for eh_frame pcrel encoding support... " >&6; } +if ${gcc_cv_as_loongarch_eh_frame_pcrel_encoding_support+:} false; then : + $as_echo_n "(cached) " >&6 +else + gcc_cv_as_loongarch_eh_frame_pcrel_encoding_support=no + if test x$gcc_cv_as != x; then + $as_echo '.LFB1780 = . + .cfi_startproc + .cfi_personality 0x9b,DW.ref.__gxx_personality_v0 + .cfi_lsda 0x1b,.LLSDA1780 + .cfi_endproc' > conftest.s + if { ac_try='$gcc_cv_as $gcc_cv_as_flags -o conftest.o conftest.s >&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 + gcc_cv_as_loongarch_eh_frame_pcrel_encoding_support=yes + else + echo "configure: failed program was" >&5 + cat conftest.s >&5 + fi + rm -f conftest.o conftest.s + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_as_loongarch_eh_frame_pcrel_encoding_support" >&5 +$as_echo "$gcc_cv_as_loongarch_eh_frame_pcrel_encoding_support" >&6; } +if test $gcc_cv_as_loongarch_eh_frame_pcrel_encoding_support = yes; then + +$as_echo "#define HAVE_AS_EH_FRAME_PCREL_ENCODING_SUPPORT 1" >>confdefs.h + fi ;; diff --git a/gcc/configure.ac b/gcc/configure.ac index e5f708c6b38..eb9e79ef8e3 100644 --- a/gcc/configure.ac +++ b/gcc/configure.ac @@ -5302,6 +5302,15 @@ x: [a:pcalau12i $t0,%pc_hi20(a)],, [AC_DEFINE(HAVE_AS_EXPLICIT_RELOCS, 1, [Define if your assembler supports explicit relocation.])]) + gcc_GAS_CHECK_FEATURE([eh_frame pcrel encoding support], + gcc_cv_as_loongarch_eh_frame_pcrel_encoding_support,, + [.LFB1780 = . + .cfi_startproc + .cfi_personality 0x9b,DW.ref.__gxx_personality_v0 + .cfi_lsda 0x1b,.LLSDA1780 + .cfi_endproc],, + [AC_DEFINE(HAVE_AS_EH_FRAME_PCREL_ENCODING_SUPPORT, 1, + [Define if your assembler supports eh_frame pcrel encoding.])]) ;; s390*-*-*) gcc_GAS_CHECK_FEATURE([.gnu_attribute support],