From patchwork Fri Jul 29 04:02:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: chenglulu X-Patchwork-Id: 284 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6a10:b5d6:b0:2b9:3548:2db5 with SMTP id v22csp600081pxt; Thu, 28 Jul 2022 21:03:08 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tvNPEHRt327ed42CfkOymJrBtS8tpjXpnuVZ/tq0orS2Jb/MyTiyg5ke1ZY0lrb1/0PpWX X-Received: by 2002:a17:907:1b1f:b0:72f:56db:cce9 with SMTP id mp31-20020a1709071b1f00b0072f56dbcce9mr1401772ejc.605.1659067387948; Thu, 28 Jul 2022 21:03:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659067387; cv=none; d=google.com; s=arc-20160816; b=kVJsghptzylZkrwsRRH1UIbLBfzorDy3b+Qcgds/ku869tG2Wr85eUQRY1eJLlisgm 5m02ixHt3e9Dog38Na81qJZ/zIT783Uz4xqz2YpshnJmPLnCBqgcnwJGYUZ4i0/8OCTh IyvfBsl8XdgAh0s4gfvv/5651pkEWMEsdSJfxS+BM5kiYdpwM6+2KtmAShec+W96lVoT EqjSnmbciZcb+VnUsDLNyyT++t+f+t7q/bDwEWGr0LxWdwKjvycjux5sA9MhBojyAvRX 9a0FpD3VYNpQelvCMIywWJQIs9SbEyA8Akzj7/hH0eemLzJDWFq/T521cDVkdWq7qIAz tPJw== 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=Cng6K4IBfFLtuXEjyQ6GmvBqfxwKsJuLszVOVJPeyk8=; b=URRNPLY58qT5Sv9HQF+W+ohfIyPbYRJSd2TQXUKxAeiKiszuP3iPlojxu5A5psLz0e G/6exdmgxHgRL7Tr/p8bDjuE8/wio7Wu/32kefxanOqtUtrx/jUt1uqbFSZL2NpJnvZa hrp1unONQhUh/EIvhyMaT15x82IWpIR2vHAzFofgNn2PKUynALGiIlizjYVUCEwrh4Zv gGeXBHh5yZOXrOI1zSz1Uh8BrnGAtyYy8reXJWf3DEk2+eD+V0Byf286bRZCSbfhVHJd VIOiUuYzZFPcI5OBnMeo1Ve4LSZdx9SBB21+BKFW2jgGfJHW0yrQpfiPKVxizWK01drW CV1g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id qw10-20020a1709066a0a00b0072aba37b6aasi2762114ejc.108.2022.07.28.21.03.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Jul 2022 21:03:07 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 379573853830 for ; Fri, 29 Jul 2022 04:03:00 +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 0CD77385840A for ; Fri, 29 Jul 2022 04:02:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0CD77385840A 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 AQAAf9AxeeDOW+Ni9PpAAA--.27341S2; Fri, 29 Jul 2022 12:02:26 +0800 (CST) From: Lulu Cheng To: gcc-patches@gcc.gnu.org Subject: [PATCH v2] LoongArch: Define the macro ASM_PREFERRED_EH_DATA_FORMAT by checking the assembler's support for eh_frame encoding. Date: Fri, 29 Jul 2022 12:02:20 +0800 Message-Id: <20220729040220.436005-1-chenglulu@loongson.cn> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-CM-TRANSID: AQAAf9AxeeDOW+Ni9PpAAA--.27341S2 X-Coremail-Antispam: 1UD129KBjvJXoW3Ar48JFWktw13WF13Kr4Uurg_yoW7tF1xpF yfZwnxtrWkWr1xCw4DXF4fGr4ftr97ury29aya9F48CayUJFy0vw1rtFnrXr18Wa93Jrya vw1rKr47W3s8Aa7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkv14x267AKxVWUJVW8JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26ryj6F1UM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26F4j 6r4UJwA2z4x0Y4vEx4A2jsIE14v26r4UJVWxJr1l84ACjcxK6I8E87Iv6xkF7I0E14v26r xl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj 6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr 0_Gr1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7MxkIecxEwVCm-wCF 04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r 18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIxkGc2Ij64vI r41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr 1lIxAIcVCF04k26cxKx2IYs7xG6rWUJVWrZr1UMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF 0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUywZ7UUUUU= 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?1739658245365535105?= X-GMAIL-MSGID: =?utf-8?q?1739658245365535105?= 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 | 34 ++++++++++++++++++++++++++++++++ gcc/configure.ac | 8 ++++++++ 4 files changed, 54 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..05efa5b01ef 100755 --- a/gcc/configure +++ b/gcc/configure @@ -28836,6 +28836,40 @@ 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 '.cfi_startproc + .cfi_personality 0x9b,a + .cfi_lsda 0x1b,b + .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..f70b6c24fda 100644 --- a/gcc/configure.ac +++ b/gcc/configure.ac @@ -5302,6 +5302,14 @@ 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,, + [.cfi_startproc + .cfi_personality 0x9b,a + .cfi_lsda 0x1b,b + .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],