From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by sourceware.org (Postfix) with ESMTP id 9226D385840A for ; Fri, 29 Jul 2022 07:02:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9226D385840A 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 [10.20.4.52] (unknown [10.20.4.52]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9BxM9D9heNiAFpBAA--.27717S2; Fri, 29 Jul 2022 15:02:21 +0800 (CST) Subject: Re: [PATCH v2] LoongArch: Define the macro ASM_PREFERRED_EH_DATA_FORMAT by checking the assembler's support for eh_frame encoding. To: gcc-patches@gcc.gnu.org Cc: xry111@xry111.site, i@xen0n.name, xuchenghua@loongson.cn References: <20220729040220.436005-1-chenglulu@loongson.cn> From: Lulu Cheng Message-ID: Date: Fri, 29 Jul 2022 15:02:21 +0800 User-Agent: Mozilla/5.0 (X11; Linux mips64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <20220729040220.436005-1-chenglulu@loongson.cn> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-CM-TRANSID: AQAAf9BxM9D9heNiAFpBAA--.27717S2 X-Coremail-Antispam: 1UD129KBjvJXoW3Xw13XF4fAry7ZFyDXFWUJwb_yoWxJFyrpF yfZwnxJr4DWr1xCw4DXa1rGr4ftr97Wr129aya9a18Ca17Ja4vqr45tFsrWr4kWa93Jr12 v3WrKr47G398AFDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvv14x267AKxVWUJVW8JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26F1j6w1UM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4U JVWxJr1l84ACjcxK6I8E87Iv67AKxVWxJr0_GcWl84ACjcxK6I8E87Iv6xkF7I0E14v26r xl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj 6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr 0_Gr1lF7xvr2IY64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7Mxk0xIA0c2IEe2xFo4CE bIxvr21lc2xSY4AK6svPMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI 8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AK xVWUAVWUtwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI 8IcVCY1x0267AKxVWUJVW8JwCI42IY6xAIw20EY4v20xvaj40_WFyUJVCq3wCI42IY6I8E 87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73Uj IFyTuYvjfU5WlkUUUUU X-CM-SenderInfo: xfkh0wpoxo3qxorr0wxvrqhubq/ X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, BODY_8BITS, GIT_PATCH_0, KAM_DMARC_STATUS, NICE_REPLY_A, 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: , X-List-Received-Date: Fri, 29 Jul 2022 07:02:33 -0000 在 2022/7/29 下午12:02, Lulu Cheng 写道: > 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], Pushed r13-1885.