From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by sourceware.org (Postfix) with ESMTP id 0D3753858D20 for ; Wed, 20 Sep 2023 01:24:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0D3753858D20 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 loongson.cn (unknown [10.20.4.107]) by gateway (Coremail) with SMTP id _____8AxjuvISQpl3RwqAA--.12790S3; Wed, 20 Sep 2023 09:24:24 +0800 (CST) Received: from [10.20.4.107] (unknown [10.20.4.107]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Axzy_GSQplVSEMAA--.24125S3; Wed, 20 Sep 2023 09:24:22 +0800 (CST) Subject: Re: [pushed][PATCH v1] LoongArch: Check whether binutils supports the relax function. If supported, explicit relocs are turned off by default. To: gcc-patches@gcc.gnu.org Cc: xry111@xry111.site, i@xen0n.name, xuchenghua@loongson.cn References: <20230915024000.20344-1-chenglulu@loongson.cn> From: chenglulu Message-ID: Date: Wed, 20 Sep 2023 09:24:22 +0800 User-Agent: Mozilla/5.0 (X11; Linux loongarch64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <20230915024000.20344-1-chenglulu@loongson.cn> Content-Type: text/plain; charset=gbk; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-CM-TRANSID:AQAAf8Axzy_GSQplVSEMAA--.24125S3 X-CM-SenderInfo: xfkh0wpoxo3qxorr0wxvrqhubq/ X-Coremail-Antispam: 1Uk129KBj93XoWxtF4Dtw47Ww18AF15CryUJwc_yoW3WryrpF 9rZw1ayF48Gr4fGw4Dt34fWws5Ar9rGr129a13tF48Ca15Zr10vF18JrnrXFyDuw4rWry2 qrn5Ka1a9a1DJ3cCm3ZEXasCq-sJn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUv2b4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x0267AK xVW8Jr0_Cr1UM2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12xvs2x26I8E6xACxx 1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv 67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IY64vIr41lc7I2V7IY0VAS07 AlzVAYIcxG8wCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02 F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw 1lIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7Cj xVAFwI0_Jr0_Gr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r 1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Jr0_GrUvcSsGvfC2KfnxnUUI43ZEXa7IU8xu ctUUUUU== X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00,GIT_PATCH_0,KAM_DMARC_STATUS,MIME_CHARSET_FARAWAY,NICE_REPLY_A,SPF_HELO_NONE,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 List-Id: Pushed to r14-4160. ÔÚ 2023/9/15 ÉÏÎç10:40, Lulu Cheng дµÀ: > gcc/ChangeLog: > > * config.in: Regenerate. > * config/loongarch/genopts/loongarch.opt.in: Add compilation option > mrelax. And set the initial value of explicit-relocs according to the > detection status. > * config/loongarch/gnu-user.h: When compiling with -mno-relax, pass the > --no-relax option to the linker. > * config/loongarch/loongarch-driver.h (ASM_SPEC): When compiling with > -mno-relax, pass the -mno-relax option to the assembler. > * config/loongarch/loongarch-opts.h (HAVE_AS_MRELAX_OPTION): Define macro. > * config/loongarch/loongarch.opt: Regenerate. > * configure: Regenerate. > * configure.ac: Add detection of support for binutils relax function. > --- > gcc/config.in | 6 ++++ > gcc/config/loongarch/genopts/loongarch.opt.in | 7 ++++- > gcc/config/loongarch/gnu-user.h | 3 +- > gcc/config/loongarch/loongarch-driver.h | 2 +- > gcc/config/loongarch/loongarch-opts.h | 4 +++ > gcc/config/loongarch/loongarch.opt | 7 ++++- > gcc/configure | 31 +++++++++++++++++++ > gcc/configure.ac | 4 +++ > 8 files changed, 60 insertions(+), 4 deletions(-) > > diff --git a/gcc/config.in b/gcc/config.in > index f0071456f03..d04718ad128 100644 > --- a/gcc/config.in > +++ b/gcc/config.in > @@ -634,6 +634,12 @@ > #endif > > > +/* Define if your assembler supports -mrelax option. */ > +#ifndef USED_FOR_TARGET > +#undef HAVE_AS_MRELAX_OPTION > +#endif > + > + > /* Define if your assembler supports .mspabi_attribute. */ > #ifndef USED_FOR_TARGET > #undef HAVE_AS_MSPABI_ATTRIBUTE > diff --git a/gcc/config/loongarch/genopts/loongarch.opt.in b/gcc/config/loongarch/genopts/loongarch.opt.in > index 78a27dac806..9f98f2d845a 100644 > --- a/gcc/config/loongarch/genopts/loongarch.opt.in > +++ b/gcc/config/loongarch/genopts/loongarch.opt.in > @@ -175,7 +175,7 @@ Target Joined RejectNegative UInteger Var(loongarch_max_inline_memcpy_size) Init > -mmax-inline-memcpy-size=SIZE Set the max size of memcpy to inline, default is 1024. > > mexplicit-relocs > -Target Var(TARGET_EXPLICIT_RELOCS) Init(HAVE_AS_EXPLICIT_RELOCS) > +Target Var(TARGET_EXPLICIT_RELOCS) Init(HAVE_AS_EXPLICIT_RELOCS & !HAVE_AS_MRELAX_OPTION) > Use %reloc() assembly operators. > > ; The code model option names for -mcmodel. > @@ -208,3 +208,8 @@ Specify the code model. > mdirect-extern-access > Target Var(TARGET_DIRECT_EXTERN_ACCESS) Init(0) > Avoid using the GOT to access external symbols. > + > +mrelax > +Target Var(loongarch_mrelax) Init(HAVE_AS_MRELAX_OPTION) > +Take advantage of linker relaxations to reduce the number of instructions > +required to materialize symbol addresses. > diff --git a/gcc/config/loongarch/gnu-user.h b/gcc/config/loongarch/gnu-user.h > index fa1a5211419..9616d6e8a0b 100644 > --- a/gcc/config/loongarch/gnu-user.h > +++ b/gcc/config/loongarch/gnu-user.h > @@ -48,7 +48,8 @@ along with GCC; see the file COPYING3. If not see > "%{!shared: %{static} " \ > "%{!static: %{!static-pie: %{rdynamic:-export-dynamic} " \ > "-dynamic-linker " GNU_USER_DYNAMIC_LINKER "}} " \ > - "%{static-pie: -static -pie --no-dynamic-linker -z text}}" > + "%{static-pie: -static -pie --no-dynamic-linker -z text}}" \ > + "%{mno-relax: --no-relax}" > > > /* Similar to standard Linux, but adding -ffast-math support. */ > diff --git a/gcc/config/loongarch/loongarch-driver.h b/gcc/config/loongarch/loongarch-driver.h > index d917fcabd37..d859afcc9fe 100644 > --- a/gcc/config/loongarch/loongarch-driver.h > +++ b/gcc/config/loongarch/loongarch-driver.h > @@ -53,7 +53,7 @@ along with GCC; see the file COPYING3. If not see > > #undef ASM_SPEC > #define ASM_SPEC \ > - "%{mabi=*} %(subtarget_asm_spec)" > + "%{mabi=*} %{mno-relax} %(subtarget_asm_spec)" > > > extern const char* > diff --git a/gcc/config/loongarch/loongarch-opts.h b/gcc/config/loongarch/loongarch-opts.h > index 3c6ff2e0d44..2756939b05d 100644 > --- a/gcc/config/loongarch/loongarch-opts.h > +++ b/gcc/config/loongarch/loongarch-opts.h > @@ -97,4 +97,8 @@ loongarch_update_gcc_opt_status (struct loongarch_target *target, > #define HAVE_AS_EXPLICIT_RELOCS 0 > #endif > > +#ifndef HAVE_AS_MRELAX_OPTION > +#define HAVE_AS_MRELAX_OPTION 0 > +#endif > + > #endif /* LOONGARCH_OPTS_H */ > diff --git a/gcc/config/loongarch/loongarch.opt b/gcc/config/loongarch/loongarch.opt > index b06b58b5ba2..e1b085ae87c 100644 > --- a/gcc/config/loongarch/loongarch.opt > +++ b/gcc/config/loongarch/loongarch.opt > @@ -182,7 +182,7 @@ Target Joined RejectNegative UInteger Var(loongarch_max_inline_memcpy_size) Init > -mmax-inline-memcpy-size=SIZE Set the max size of memcpy to inline, default is 1024. > > mexplicit-relocs > -Target Var(TARGET_EXPLICIT_RELOCS) Init(HAVE_AS_EXPLICIT_RELOCS) > +Target Var(TARGET_EXPLICIT_RELOCS) Init(HAVE_AS_EXPLICIT_RELOCS & !HAVE_AS_MRELAX_OPTION) > Use %reloc() assembly operators. > > ; The code model option names for -mcmodel. > @@ -215,3 +215,8 @@ Specify the code model. > mdirect-extern-access > Target Var(TARGET_DIRECT_EXTERN_ACCESS) Init(0) > Avoid using the GOT to access external symbols. > + > +mrelax > +Target Var(loongarch_mrelax) Init(HAVE_AS_MRELAX_OPTION) > +Take advantage of linker relaxations to reduce the number of instructions > +required to materialize symbol addresses. > diff --git a/gcc/configure b/gcc/configure > index 07e8a64afbb..d5e218e9a16 100755 > --- a/gcc/configure > +++ b/gcc/configure > @@ -29073,6 +29073,37 @@ 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 > + > + { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for -mrelax option" >&5 > +$as_echo_n "checking assembler for -mrelax option... " >&6; } > +if ${gcc_cv_as_loongarch_relax+:} false; then : > + $as_echo_n "(cached) " >&6 > +else > + gcc_cv_as_loongarch_relax=no > + if test x$gcc_cv_as != x; then > + $as_echo '.text' > conftest.s > + if { ac_try='$gcc_cv_as $gcc_cv_as_flags -mrelax -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_relax=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_relax" >&5 > +$as_echo "$gcc_cv_as_loongarch_relax" >&6; } > +if test $gcc_cv_as_loongarch_relax = yes; then > + > +$as_echo "#define HAVE_AS_MRELAX_OPTION 1" >>confdefs.h > + > fi > > ;; > diff --git a/gcc/configure.ac b/gcc/configure.ac > index cb4be11facd..019d0375a2f 100644 > --- a/gcc/configure.ac > +++ b/gcc/configure.ac > @@ -5348,6 +5348,10 @@ x: > .cfi_endproc],, > [AC_DEFINE(HAVE_AS_EH_FRAME_PCREL_ENCODING_SUPPORT, 1, > [Define if your assembler supports eh_frame pcrel encoding.])]) > + gcc_GAS_CHECK_FEATURE([-mrelax option], gcc_cv_as_loongarch_relax, > + [-mrelax], [.text],, > + [AC_DEFINE(HAVE_AS_MRELAX_OPTION, 1, > + [Define if your assembler supports -mrelax option.])]) > ;; > s390*-*-*) > gcc_GAS_CHECK_FEATURE([.gnu_attribute support],