From patchwork Wed Feb 21 03:10:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: chenglulu X-Patchwork-Id: 203878 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp804363dyc; Tue, 20 Feb 2024 19:12:39 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVVaHwss7QN0Cd9OQ8RDEH7DmoRb2jTstv4Fdh30APwfnVootjOohFB92hbDCzrNkjJat06P/Pq3s1q678K3RLW39xvQw== X-Google-Smtp-Source: AGHT+IFOC/cLRQCJozMp4zn5sMDyHyO3qE1P8z0J/iU/tIUDsugk8vPZ3igNkEc1RBkS63ZX8PIf X-Received: by 2002:a05:622a:13d1:b0:42e:273:39fe with SMTP id p17-20020a05622a13d100b0042e027339femr15035776qtk.1.1708485159371; Tue, 20 Feb 2024 19:12:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708485159; cv=pass; d=google.com; s=arc-20160816; b=JtJvbaSXKH6GmH/RWhIZRzrQydcD3aFWEQcbVyalWPAzIO48owhDNBiNfIA+PEb7C8 V/PeeXyE5b3TDRqqqZbTNKrOpL4ChzJZfAp8/N5AHi7F0zxCmoioJW8641OXvcuYmffr 8thtzXOqwmwL4GBMbbJX2F4u2M7wJQNmQhqVl3jhNbn1Vsnv3BWlK0hKc4IGfxaEN0ue lTzqy12+Osi4DsBLczNX3uFMobeAwsUHJq4+WH2xQFjg+aMdM5OyaQlVQdkuNLqTQ0yd iYDIic3Z2yVT+zQTv77XHtFl0RCheaovrqyCFmlzdQ/SFajG6etV+RTh+haL8qHuU3En 43iw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to; bh=sAdCbvScUTRobayozzbFouINeKxl3iv709HwXhcEyY4=; fh=wYRiZnn9nDBltyuQH1H/s7FMOEBgw7D5UzXRQ9Hnwic=; b=FvYPcK8zwtxwdRoo+4oadHX5wzUtN0kw+4A1V4pPouhJJEUWhsb8NoO+Co8SPzkIAC fWqT04Gs6s/r+SpaGD7F4T8PTa4LmQukMQE+bCj5AD3Nm9zUPUD/Yv5rc9FrX/en+D/p y4vASEZQrgJzGV1Mj2U8Cb6l9rJKeLlSg0qEnL82es2gNDSom0pbzPZXRRECXiqMomIk Vtabt7MmZoiIvrpJUF1n8ctxuiOHUySKK1b3A79mCPRG0AU++82mmqng41b9IHcHbzhi YSrsnXeGiC3ZpHN4XxWeiscpoLurNwJL2fuWUcIzqoX/JjkRdOITnXlCO45vSbwbFOXs NkTQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id d12-20020ac847cc000000b0042de91c4276si9752582qtr.567.2024.02.20.19.12.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 19:12:39 -0800 (PST) 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; arc=pass (i=1); 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 07AA2385840F for ; Wed, 21 Feb 2024 03:12:39 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by sourceware.org (Postfix) with ESMTP id EC23F3858C66 for ; Wed, 21 Feb 2024 03:11:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EC23F3858C66 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=loongson.cn ARC-Filter: OpenARC Filter v1.0.0 sourceware.org EC23F3858C66 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=114.242.206.163 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708485104; cv=none; b=KsqyHQgM0ODNrd8OKLBlTXn4nlK1ZoeSCloIlujPHACgX4eycR9hSVeBo2xql9twVx45Dp2oIJqK2COMWtxmskCTsWA7/KVoxhatpi9dqtY+Mvjvyjl0IrmhtjU9QlTVo+/o67rxWZBZCNN9O9dDUVYeMDcWIYbC4SilUSofSDk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708485104; c=relaxed/simple; bh=r6kIL6i8tu/eznPHtijIZn2iCjRGV+OBy/ImDoHg0VU=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=PK5DbXSIuqvm5gnxW/k6L1wnNoyMj/PBe8ArVnfsfAatWXIFdSiXPXr8XK1YezvNGqw3mNLwwWf9hM1z3nW0Y8vQ+xIU2ZjyjzW1yz9erWVxYyWjOlPXZ0ruSnH62Lhz7mHD677RO89e+2wZn9qwOKJuKXPSCD6uiXys31V1TXk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from loongson.cn (unknown [10.20.4.107]) by gateway (Coremail) with SMTP id _____8CxF+jqadVl+acPAA--.20858S3; Wed, 21 Feb 2024 11:11:38 +0800 (CST) Received: from loongson-pc.loongson.cn (unknown [10.20.4.107]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Cxbs3LadVlN209AA--.25488S4; Wed, 21 Feb 2024 11:11:37 +0800 (CST) From: Lulu Cheng To: gcc-patches@gcc.gnu.org Cc: xry111@xry111.site, i@xen0n.name, xuchenghua@loongson.cn, chenglulu@loongson.cn Subject: [PATCH v1 2/4] LoongArch: Check whether binutils supports the relax function. If supported, explicit relocs are turned off by default. Date: Wed, 21 Feb 2024 11:10:48 +0800 Message-Id: <20240221031050.24343-3-chenglulu@loongson.cn> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20240221031050.24343-1-chenglulu@loongson.cn> References: <20240221031050.24343-1-chenglulu@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Cxbs3LadVlN209AA--.25488S4 X-CM-SenderInfo: xfkh0wpoxo3qxorr0wxvrqhubq/ X-Coremail-Antispam: 1Uk129KBj93XoW3Gr48uFWrtr1kCF1Utr4rtFc_yoWxWFyDpr 9rZw1ayF48Grs3Gr4Dta4fWwn3Jr97Wr12va13Xr18Ca15Xr10vF40yrnrXFy7Xw4rWry2 vr1rKa129a1kAwbCm3ZEXasCq-sJn29KB7ZKAUJUUUUx529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUB2b4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVWxJVW8Jr1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6r4UJVWxJr1ln4kS14v26r126r1DM2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12 xvs2x26I8E6xACxx1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26rWY 6Fy7McIj6I8E87Iv67AKxVW8JVWxJwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64 vIr41lc7CjxVAaw2AFwI0_JF0_Jw1l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_ Jr0_Gr1l4IxYO2xFxVAFwI0_Jw0_GFylx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8Gjc xK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0 cI8IcVAFwI0_Xr0_Ar1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8V AvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6xkF7I0E 14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxUVWrXDUUUU X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, 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: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791476534519795835 X-GMAIL-MSGID: 1791476534519795835 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. (cherry picked from commint 9bab65a77049edcc7afc59532173206ee816e726) --- gcc/config.in | 12 +++++++ gcc/config/loongarch/genopts/loongarch.opt.in | 5 +++ gcc/config/loongarch/gnu-user.h | 4 +-- gcc/config/loongarch/loongarch-opts.h | 4 +++ gcc/config/loongarch/loongarch.opt | 5 +++ gcc/configure | 31 +++++++++++++++++++ gcc/configure.ac | 4 +++ 7 files changed, 63 insertions(+), 2 deletions(-) diff --git a/gcc/config.in b/gcc/config.in index cc638759a40..f5b6287a96a 100644 --- a/gcc/config.in +++ b/gcc/config.in @@ -630,6 +630,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 @@ -2214,6 +2220,12 @@ #endif +/* Define which stat syscall is able to handle 64bit indodes. */ +#ifndef USED_FOR_TARGET +#undef HOST_STAT_FOR_64BIT_INODES +#endif + + /* Define as const if the declaration of iconv() needs const. */ #ifndef USED_FOR_TARGET #undef ICONV_CONST diff --git a/gcc/config/loongarch/genopts/loongarch.opt.in b/gcc/config/loongarch/genopts/loongarch.opt.in index 61e7d72a0a1..edc2ed045d7 100644 --- a/gcc/config/loongarch/genopts/loongarch.opt.in +++ b/gcc/config/loongarch/genopts/loongarch.opt.in @@ -177,3 +177,8 @@ Enum(cmodel) String(@@STR_CMODEL_EXTREME@@) Value(CMODEL_EXTREME) mcmodel= Target RejectNegative Joined Enum(cmodel) Var(la_opt_cmodel) Init(CMODEL_NORMAL) Specify the code model. + +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 f050078da52..28ac8b0e1f6 100644 --- a/gcc/config/loongarch/gnu-user.h +++ b/gcc/config/loongarch/gnu-user.h @@ -46,8 +46,8 @@ along with GCC; see the file COPYING3. If not see #define GNU_USER_TARGET_LINK_SPEC \ "%{G*} %{shared} -m " GNU_USER_LINK_EMULATION \ "%{!shared: %{static} %{!static: %{rdynamic:-export-dynamic} " \ - "-dynamic-linker " GNU_USER_DYNAMIC_LINKER "}}" - + "-dynamic-linker " GNU_USER_DYNAMIC_LINKER "}}" \ + "%{mno-relax: --no-relax}" /* Similar to standard Linux, but adding -ffast-math support. */ #undef GNU_USER_TARGET_MATHFILE_SPEC diff --git a/gcc/config/loongarch/loongarch-opts.h b/gcc/config/loongarch/loongarch-opts.h index eaa6fc07448..60e682f57a0 100644 --- a/gcc/config/loongarch/loongarch-opts.h +++ b/gcc/config/loongarch/loongarch-opts.h @@ -87,4 +87,8 @@ loongarch_config_target (struct loongarch_target *target, while -m[no]-memcpy imposes a global constraint. */ #define TARGET_DO_OPTIMIZE_BLOCK_MOVE_P loongarch_do_optimize_block_move_p() +#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 3ff0d860413..78b5e0cc452 100644 --- a/gcc/config/loongarch/loongarch.opt +++ b/gcc/config/loongarch/loongarch.opt @@ -184,3 +184,8 @@ Enum(cmodel) String(extreme) Value(CMODEL_EXTREME) mcmodel= Target RejectNegative Joined Enum(cmodel) Var(la_opt_cmodel) Init(CMODEL_NORMAL) Specify the code model. + +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 b4907d258be..67cdd92a4f3 100755 --- a/gcc/configure +++ b/gcc/configure @@ -28871,6 +28871,37 @@ if test $gcc_cv_as_loongarch_dtprelword != yes; then $as_echo "#define HAVE_AS_DTPRELWORD 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 + ;; s390*-*-*) { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for .gnu_attribute support" >&5 diff --git a/gcc/configure.ac b/gcc/configure.ac index d369c4717b2..e08ac5f4b49 100644 --- a/gcc/configure.ac +++ b/gcc/configure.ac @@ -5336,6 +5336,10 @@ x: .dtprelword x+0x8000],, [AC_DEFINE(HAVE_AS_DTPRELWORD, 1, [Define if your assembler supports .dtprelword.])]) + 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],