From patchwork Tue Jul 26 14:15:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xi Ruoyao X-Patchwork-Id: 188 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6a10:b5d6:b0:2b9:3548:2db5 with SMTP id v22csp2291462pxt; Tue, 26 Jul 2022 07:16:18 -0700 (PDT) X-Google-Smtp-Source: AGRyM1t5qZfznwOZRNoLRLEwHujQVLZXrxSFwRW6BfBBipJxiB0Dnsr17YiRJx1grnDh1zIDNFUF X-Received: by 2002:a17:907:9485:b0:72f:97d9:9799 with SMTP id dm5-20020a170907948500b0072f97d99799mr14390658ejc.328.1658844978024; Tue, 26 Jul 2022 07:16:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658844978; cv=none; d=google.com; s=arc-20160816; b=1CU0uMQlUbHO/qNmDR7/cfPirVC4vGlpGsCMx9VEoyJXH6r21FiSeCFLEQtR0prxSv Dbrv6g4JL1UU7pUnKq0JKaqlLCl48FHEpTEs6VwY0t8WTvdS6lGbz4SXoy4yHjLjAs+A Hd9Mw1RETjebP3mvLKJrm/n7r0dcogxRW9se+tFOP+jTnvBf9kpkVAaRdzM4iNt+8rWA 1eym7Qnkfx/hLcjQXdP+joHgNU7crSmC80Vt0FmGXG7HH/wHSb31MdOqupQauF+9Ye1I Dl2PzVTMr9eOfglwwfFcu6ZKhrRijZESacb+VekoJxfqj89SzaaUgPK8uv2F36TB/Eq3 kJnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:subject:message-id:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=RxVzxkAdaaCxu3gE91KAHw5afRPwkzApvQj08/pNFwg=; b=fA0kX514BAR/NZ5eFu2L70kiG9kVvAnJgsdPU08mfrU5plF67ziGYiFdMJDeTemogp ClSi9D4LGrLGrOpEP7hTjEK7wyEFVJzP4cpy1fBaCZWGzvBxtmhJh6AmrLwzswPByuCX lejyYZIP5mXa13MyGWX6Jit2EdM+0hgwHPqNo2FTrBpZ6k4Hgrk4lCmaVbg+Xm4hg2eg 0Qfu/5HO+z7BdCOdNwecZLXRUhhwM4G3FSmTW80NZhohE9lN48Gs9NQribwSV+RQfhKG y3Yf6IyPgliooyR+j5CJkGuF/myHTlGxKD8VJcBehJWAkdUxjX6BguMue8j+6AANNkul 0lsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=u+tvHohz; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id gs10-20020a1709072d0a00b0072b53db6bf0si17532257ejc.621.2022.07.26.07.16.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jul 2022 07:16:18 -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; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=u+tvHohz; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 87696385828C for ; Tue, 26 Jul 2022 14:16:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 87696385828C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1658844976; bh=RxVzxkAdaaCxu3gE91KAHw5afRPwkzApvQj08/pNFwg=; h=Subject:To:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=u+tvHohzOun1OWobglwhbuzPnfugY279vJ5joGQe/4yZ+BAwzgsFHcICTo67o5106 jYv6aK6koULIeKWza230odSjJxzWABN/otLl7TY1HzHu1FK14X16YyvEBLC/mdvuSk +aPC/XIB8zcPT9tjm7nnk05m4CTwudEUtHhDNqPA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from xry111.site (xry111.site [89.208.246.23]) by sourceware.org (Postfix) with ESMTPS id 0E0B43858C83 for ; Tue, 26 Jul 2022 14:15:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0E0B43858C83 Received: from localhost.localdomain (xry111.site [IPv6:2001:470:683e::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-384)) (Client did not present a certificate) (Authenticated sender: xry111@xry111.site) by xry111.site (Postfix) with ESMTPSA id 40C2566887; Tue, 26 Jul 2022 10:15:27 -0400 (EDT) Message-ID: Subject: [PATCH] LoongArch: adjust the default of -mexplicit-relocs by checking gas feature To: Lulu Cheng , gcc-patches@gcc.gnu.org Date: Tue, 26 Jul 2022 22:15:25 +0800 In-Reply-To: <653cf06d-da9c-419d-8c70-55962163b155@loongson.cn> References: <20220726072119.2910839-1-chenglulu@loongson.cn> <25a7d2fcac8194083e58ed960eaf0f42dafc0559.camel@xry111.site> <93f7b58a-d7a7-543a-21e1-19d237593426@loongson.cn> <653cf06d-da9c-419d-8c70-55962163b155@loongson.cn> User-Agent: Evolution 3.44.3 MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FROM_SUSPICIOUS_NTLD, GIT_PATCH_0, LIKELY_SPAM_FROM, PDS_OTHER_BAD_TLD, 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-Patchwork-Original-From: Xi Ruoyao via Gcc-patches From: Xi Ruoyao Reply-To: Xi Ruoyao Cc: xuchenghua@loongson.cn, Wang Xuerui 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?1739425031482484811?= X-GMAIL-MSGID: =?utf-8?q?1739425031482484811?= > > Maybe we can add a check in gcc/configure.ac to see if gcc_cv_ld > > supports %got_pc_hi20 and adjust the default for -m[no]-explicit-relocs? > I think this is a good way, I'll look at adding a check. The following should work. I've tested it locally by building GCC with both old (2.38 with patch) and new (trunk) Binutils. Ok for trunk? I simply checked as instead of ld. If as supports explicitly relocations, the produced .o file won't be supported by an old ld even if we use -mno-explicit-relocs (because as will generate new relocation types for la.local etc). So such a mismatch between as and ld can be considered "completely broken" and we don't need to support it. And, the Alpha port also check the assembler for the default of -mexplicit- relocs. This should be documented in invoke.texi, but currently it does not mention -mexplicit-relocs for LoongArch at all. So I'll submit the doclater in another patch. -- >8 -- The assembly produced with -mexplicit-relocs is not supported by gas <= 2.39. Check if the assembler supports explicit relocations and set the default accordingly. gcc/ChangeLog: * configure.ac (HAVE_AS_EXPLICIT_RELOCS): Define to 1 if the assembler supports explicit relocation for LoongArch. * configure: Regenerate. * config/loongarch/loongarch-opts.h (HAVE_AS_EXPLICIT_RELOCS): Define to 0 if not defined. * config/loongarch/genopts/loongarch.opt.in (TARGET_EXPLICIT_RELOCS): Default to HAVE_AS_EXPLICIT_RELOCS. * config/loongarch/loongarch.opt: Regenerate. --- gcc/config/loongarch/genopts/loongarch.opt.in | 2 +- gcc/config/loongarch/loongarch-opts.h | 4 ++ gcc/config/loongarch/loongarch.opt | 2 +- gcc/configure | 37 +++++++++++++++++-- gcc/configure.ac | 7 +++- 5 files changed, 46 insertions(+), 6 deletions(-) diff --git a/gcc/config/loongarch/genopts/loongarch.opt.in b/gcc/config/loongarch/genopts/loongarch.opt.in index 6f39500935d..a571b6b7524 100644 --- a/gcc/config/loongarch/genopts/loongarch.opt.in +++ b/gcc/config/loongarch/genopts/loongarch.opt.in @@ -155,7 +155,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(1) +Target Var(TARGET_EXPLICIT_RELOCS) Init(HAVE_AS_EXPLICIT_RELOCS) Use %reloc() assembly operators. ; The code model option names for -mcmodel. diff --git a/gcc/config/loongarch/loongarch-opts.h b/gcc/config/loongarch/loongarch-opts.h index eaa6fc07448..da24ecd2b50 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_EXPLICIT_RELOCS +#define HAVE_AS_EXPLICIT_RELOCS 0 +#endif + #endif /* LOONGARCH_OPTS_H */ diff --git a/gcc/config/loongarch/loongarch.opt b/gcc/config/loongarch/loongarch.opt index 7a8c5b44418..9df7e187283 100644 --- a/gcc/config/loongarch/loongarch.opt +++ b/gcc/config/loongarch/loongarch.opt @@ -162,7 +162,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(1) +Target Var(TARGET_EXPLICIT_RELOCS) Init(HAVE_AS_EXPLICIT_RELOCS) Use %reloc() assembly operators. ; The code model option names for -mcmodel. diff --git a/gcc/configure b/gcc/configure index 62872d132ea..7eb9479ae8e 100755 --- a/gcc/configure +++ b/gcc/configure @@ -19674,7 +19674,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 19679 "configure" +#line 19677 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -19780,7 +19780,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 19785 "configure" +#line 19783 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -28771,7 +28771,7 @@ $as_echo "#define HAVE_AS_MARCH_ZIFENCEI 1" >>confdefs.h fi ;; - loongarch*-*-*) + loongarch*-*-*) { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for .dtprelword support" >&5 $as_echo_n "checking assembler for .dtprelword support... " >&6; } if ${gcc_cv_as_loongarch_dtprelword+:} false; then : @@ -28807,6 +28807,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 explicit relocation support" >&5 +$as_echo_n "checking assembler for explicit relocation support... " >&6; } +if ${gcc_cv_as_loongarch_explicit_relocs+:} false; then : + $as_echo_n "(cached) " >&6 +else + gcc_cv_as_loongarch_explicit_relocs=no + if test x$gcc_cv_as != x; then + $as_echo 'a:pcalau12i $t0,%pc_hi20(a)' > 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_explicit_relocs=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_explicit_relocs" >&5 +$as_echo "$gcc_cv_as_loongarch_explicit_relocs" >&6; } +if test $gcc_cv_as_loongarch_explicit_relocs = yes; then + +$as_echo "#define HAVE_AS_EXPLICIT_RELOCS 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 446747311a6..e5f708c6b38 100644 --- a/gcc/configure.ac +++ b/gcc/configure.ac @@ -5287,7 +5287,7 @@ configured with --enable-newlib-nano-formatted-io.]) [AC_DEFINE(HAVE_AS_MARCH_ZIFENCEI, 1, [Define if the assembler understands -march=rv*_zifencei.])]) ;; - loongarch*-*-*) + loongarch*-*-*) gcc_GAS_CHECK_FEATURE([.dtprelword support], gcc_cv_as_loongarch_dtprelword, [2,18,0],, [.section .tdata,"awT",@progbits @@ -5297,6 +5297,11 @@ x: .dtprelword x+0x8000],, [AC_DEFINE(HAVE_AS_DTPRELWORD, 1, [Define if your assembler supports .dtprelword.])]) + gcc_GAS_CHECK_FEATURE([explicit relocation support], + gcc_cv_as_loongarch_explicit_relocs,, + [a:pcalau12i $t0,%pc_hi20(a)],, + [AC_DEFINE(HAVE_AS_EXPLICIT_RELOCS, 1, + [Define if your assembler supports explicit relocation.])]) ;; s390*-*-*) gcc_GAS_CHECK_FEATURE([.gnu_attribute support],