From patchwork Fri Jun 2 09:24:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: mengqinggang X-Patchwork-Id: 102407 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp896923vqr; Fri, 2 Jun 2023 02:24:32 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6ScSHy4pQoMtQrsjYvirZFjbWGsi1/cYa34P6rXrfK+zurIM3yiovDd/tWFgS4YTyrLVAz X-Received: by 2002:aa7:c486:0:b0:514:8d88:7b70 with SMTP id m6-20020aa7c486000000b005148d887b70mr1285047edq.6.1685697872388; Fri, 02 Jun 2023 02:24:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685697872; cv=none; d=google.com; s=arc-20160816; b=byt+DmT4TXlYU4zqIuw/tyiS8CYXqJt12AvJlpolCHSeOfFu/EVdpQEBZdjG56Y2Ql 8NPwWXaL5o0RrnH1oqJ5m00hrhwY1+QCrpC269BKy+mxOUnkbQQiUOUT0mzkax51Qjg3 d2nuS6XPO2cxlKHRDgQLkFjoEW3hSc1sqxJ5JNb7RfzEeLPfA+w1Hq8DAFaurEeSjyn8 t7JlM5ylP3g4stVgGabxOPU6nxPq2LGGomV1iRx7vByjFUgiBfUIIOANmp7GRGWnoqKD GCj1reph5ujVm/pIxCzZeDKYMgT9zwjNOJoc/6zbUMxOejc5+BKQi/x8t4rqdi5F/wdW zfCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dmarc-filter :delivered-to; bh=0xd1athg3jo+mUkfQwY0PEvQz32M3Ra3+iq2KKCcxK4=; b=QfBvyVxrgGoZolnZmGSxjja1zN3tnd+WhVrMxUo4bLTxNFJsiL+JU66Y+PjyY8PrEe csN/PMdXQBaUmvvR9WyHR2Zjp05bURWZerFzVGWoz6xpJaZhL8Wio1tzA4k6RMBT3czO bPu3r9/IBy1xxGHGz3kLUQgWcagL6cSftcCqbHVIXteGSP/StYj5hTc8NYV3e9XGR7sK T2Siul1xIhPt2wMtbzVFzLXSU/d9fv4opLXzDAFAOW0wEM8z4t78q5btjjXcp1HXxOUG Bo0d3/IXEJ81koIFlbOljpoKU1nR7RuCktsv5GAeipIbuGRSrDSVtbQg/jT3BNYcmZqX VqCw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id r17-20020aa7da11000000b0050bd245d39asi618693eds.160.2023.06.02.02.24.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jun 2023 02:24:32 -0700 (PDT) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.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; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 60D37385696A for ; Fri, 2 Jun 2023 09:24:30 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by sourceware.org (Postfix) with ESMTP id ED9813858C53 for ; Fri, 2 Jun 2023 09:24:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ED9813858C53 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.2.5.5]) by gateway (Coremail) with SMTP id _____8AxyfFEtXlksZQDAA--.8017S3; Fri, 02 Jun 2023 17:24:21 +0800 (CST) Received: from 5.5.5 (unknown [10.2.5.5]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Dx97U8tXlkNbGFAA--.19440S2; Fri, 02 Jun 2023 17:24:19 +0800 (CST) From: mengqinggang To: binutils@sourceware.org Cc: xuchenghua@loongson.cn, chenglulu@loongson.cn, liuzhensong@loongson.cn, xry111@xry111.site, i.swmail@xen0n.name, maskray@google.com, changjiachen@stu.xupt.edu.cn, mengqinggang Subject: [PATCH] LoongArch: gas: Relocations simplification when -mno-relax Date: Fri, 2 Jun 2023 17:24:10 +0800 Message-Id: <20230602092410.2841184-1-mengqinggang@loongson.cn> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Dx97U8tXlkNbGFAA--.19440S2 X-CM-SenderInfo: 5phqw15lqjwttqj6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBjvJXoWxWr4UtFW5KryxuF15CrWrGrg_yoWrJr1rpr ZFy3WUtF4kXFnag395ta4rXrn8Za92gr42qFyavr4xuFZ8Jryqq398trZ5XFWjqaykurWI qryxt3WjqFWqvFDanT9S1TB71UUUUUJqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU b3xYFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s 1l1IIY67AEw4v_Jr0_Jr4l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVW5JVW7JwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwA2z4 x0Y4vEx4A2jsIE14v26r4UJVWxJr1l84ACjcxK6I8E87Iv6xkF7I0E14v26F4UJVW0owAa w2AFwI0_Jrv_JF1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2xF0cIa020Ex4CE44 I27wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_JF0_Jw1lYx0Ex4A2 jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwCF04k20x vY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwCFI7km07C267AKxVWUXVWUAwC20s02 6c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw 0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvE c7CjxVAFwI0_Jr0_Gr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14 v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Jr0_GrUvcSsGvfC2KfnxnUUI43ZEXa7I U8ewZ7UUUUU== X-Spam-Status: No, score=-12.3 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: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767582331975243390?= X-GMAIL-MSGID: =?utf-8?q?1767582331975243390?= Gas does not emit ADD/SUB relocation pairs for label differences when -mno-relax. --- gas/config/tc-loongarch.c | 11 ++++++++--- gas/config/tc-loongarch.h | 24 ++++++++++++++++++------ 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/gas/config/tc-loongarch.c b/gas/config/tc-loongarch.c index c55d4ee234a..5ca9de47629 100644 --- a/gas/config/tc-loongarch.c +++ b/gas/config/tc-loongarch.c @@ -915,8 +915,9 @@ append_fixp_and_insn (struct loongarch_cl_insn *ip) symbol is not in the same frag, it will generate relocs to calculate symbol subtraction. (gas/dw2gencfi.c:output_cfi_insn: if (symbol_get_frag (to) == symbol_get_frag (from))) */ - if (BFD_RELOC_LARCH_PCALA_HI20 == reloc_info[0].type - || BFD_RELOC_LARCH_GOT_PC_HI20 == reloc_info[0].type) + if (LARCH_opts.relax + && (BFD_RELOC_LARCH_PCALA_HI20 == reloc_info[0].type + || BFD_RELOC_LARCH_GOT_PC_HI20 == reloc_info[0].type)) { frag_wane (frag_now); frag_new (0); @@ -1470,6 +1471,9 @@ loongarch_pre_output_hook (void) const frchainS *frch; segT s; + if (!LARCH_opts.relax) + return; + /* Save the current segment info. */ segT seg = now_seg; subsegT subseg = now_subseg; @@ -1665,7 +1669,8 @@ loongarch_md_finish (void) { /* Insert relocations for uleb128 directives, so the values can be recomputed at link time. */ - bfd_map_over_sections (stdoutput, loongarch_insert_uleb128_fixes, NULL); + if (LARCH_opts.relax) + bfd_map_over_sections (stdoutput, loongarch_insert_uleb128_fixes, NULL); } void diff --git a/gas/config/tc-loongarch.h b/gas/config/tc-loongarch.h index 8517bdebf13..a9f2a0a17cc 100644 --- a/gas/config/tc-loongarch.h +++ b/gas/config/tc-loongarch.h @@ -21,6 +21,8 @@ #ifndef TC_LOONGARCH #define TC_LOONGARCH +#include "opcode/loongarch.h" + #define TARGET_BYTES_BIG_ENDIAN 0 #define TARGET_ARCH bfd_arch_loongarch @@ -57,23 +59,33 @@ extern bool loongarch_frag_align_code (int); /* The following two macros let the linker resolve all the relocs due to relaxation. + This is called to see whether a reloc against a defined symbol - should be converted into a reloc against a section. */ + should be converted into a reloc against a section. + + If relax and norelax have different value may cause ld ".eh_frame_hdr + refers to overlapping FDEs" error when link relax .o and norelax .o. */ #define tc_fix_adjustable(fixp) 0 -/* The difference between same-section symbols may be affected by linker + +/* Tne difference between same-section symbols may be affected by linker relaxation, so do not resolve such expressions in the assembler. */ #define md_allow_local_subtract(l,r,s) 0 /* Values passed to md_apply_fix don't include symbol values. */ #define TC_FORCE_RELOCATION_SUB_LOCAL(FIX, SEG) 1 + #define TC_VALIDATE_FIX_SUB(FIX, SEG) 1 #define DIFF_EXPR_OK 1 +/* Postpone text-section label subtraction calculation until linking, since + linker relaxations might change the deltas. */ #define TC_FORCE_RELOCATION_SUB_SAME(FIX, SEC) \ - (GENERIC_FORCE_RELOCATION_SUB_SAME (FIX, SEC) \ - || ((SEC)->flags & SEC_CODE) != 0 \ - || ((SEC)->flags & SEC_DEBUGGING) != 0 \ - || TC_FORCE_RELOCATION (FIX)) + (LARCH_opts.relax ? \ + (GENERIC_FORCE_RELOCATION_SUB_SAME (FIX, SEC) \ + || ((SEC)->flags & SEC_CODE) != 0 \ + || ((SEC)->flags & SEC_DEBUGGING) != 0 \ + || TC_FORCE_RELOCATION (FIX)) \ + : (GENERIC_FORCE_RELOCATION_SUB_SAME (FIX, SEC))) \ #define TC_LINKRELAX_FIXUP(seg) ((seg->flags & SEC_CODE) \ || (seg->flags & SEC_DEBUGGING))