From patchwork Thu Sep 28 08:01:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lulu Cai X-Patchwork-Id: 145841 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp3145206vqu; Thu, 28 Sep 2023 01:02:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEPAQ439y6gDzLT/grjDyOxKIZIrJxJ+iewSNFyvsBE3LD9jdh0sbGiFPn4SuCHtdNrE8iu X-Received: by 2002:a17:907:1def:b0:9a9:e71b:cd65 with SMTP id og47-20020a1709071def00b009a9e71bcd65mr538797ejc.6.1695888133228; Thu, 28 Sep 2023 01:02:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695888133; cv=none; d=google.com; s=arc-20160816; b=BNFZXZkLzZoG3wRIMWHLZOjYQxfo1slNPDKAd4EOED1TGzBkVQbueBrW6LIfTUAWV1 wlSLfulIgaHB95OqykMmaf33Hf5MsHK9JE2mvyxas7Hk5Ln00OPibYgbIJO4XwpCEN0n q++ftKPDrkm/oTD8AY9MiW5p9dxy+RDPRkAQ3oNaQNh3rRItIjyvFU0qvwc6blg0sVWX 6s7a/X7U+qBlTumqP9nCQkXSjTCpLx8Et9YWSVXuBIvohrovrxEGCSqjMeoNYI9htf1k DM4iKcM8LjVTNqt1Ljm9s9FbFA8GSkvvnog+nsfThGz3Pr2rys8TD+iO7YgBqsHREM6a qkyw== 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=fOoNy0eF5HdGJeBJ0T8P5Rk2BpTAorojyoz5xUcp+uU=; fh=QpykPZvl8YOjxJLNdAbPbZH5o/33CLekOvWxiufftr0=; b=PQW6yNSP2C4vLcbn+r2POukF/YRhOtH3vuPUmeTPCT+TdOBvLZjmDQLE5gBu/lrJg9 XC5b7oH3eq/gMCw6pWRWHG74X2w6JkPirmd8rH+UlCnu8gYOFiWopzX3suXBHbPAKpeU W2T4hsXZevtmQLcl7cvFWwc263MIcJ3Aj6MX1v76ABiSnJhagTKp3vsJkTpHypVDQtqm GBNjP0XtnC0Ljg6I6OGvFdi5kcvQNsROnIua1GN23lerzSE/mCqNkC3qMF5ZR6+PpEeU uL/nJHcjPBFhO4wzBK5K0KZlrcLdQYavTYkh7FSxJRNEhW9z2CosTcX5gjtBdW7MSu/0 3qaQ== 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 server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id dc17-20020a170906c7d100b0099347270140si14742344ejb.565.2023.09.28.01.02.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 01:02:13 -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 95F50386185B for ; Thu, 28 Sep 2023 08:02:10 +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 355043858D20 for ; Thu, 28 Sep 2023 08:01:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 355043858D20 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.6.5]) by gateway (Coremail) with SMTP id _____8Dxg_DzMhVlK7otAA--.22441S3; Thu, 28 Sep 2023 16:01:55 +0800 (CST) Received: from 5.5.5 (unknown [10.2.6.5]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Bxni_zMhVl3CUVAA--.43623S4; Thu, 28 Sep 2023 16:01:55 +0800 (CST) From: Lulu Cai To: binutils@sourceware.org Cc: xuchenghua@loongson.cn, chenglulu@loongson.cn, liuzhensong@loongson.cn, mengqinggang@loongson.cn, xry111@xry111.site, i.swmail@xen0n.name, maskray@google.com, cailulu Subject: [PATCH 1/2] as: add option for generate R_LARCH_32/64_PCREL. Date: Thu, 28 Sep 2023 16:01:52 +0800 Message-Id: <20230928080153.3626326-1-cailulu@loongson.cn> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Bxni_zMhVl3CUVAA--.43623S4 X-CM-SenderInfo: xfdlz3tox6z05rqj20fqof0/1tbiAQAIB2UU4qQG3QAFsn X-Coremail-Antispam: 1Uk129KBj93XoWxCFWfXr4fuw4kJFyUGFy3GFX_yoWrZFWUpa 47Z3ZIyF48AFZ3uF9IqasYga43Za4xG3y2vryaq3WxCwsxJ34Ygw42yr93XF1qvw4vkF42 vFyFqw15GFyDAFgCm3ZEXasCq-sJn29KB7ZKAUJUUUUr529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUU90b4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x0267AK xVWxJr0_GcWln4kS14v26r1Y6r17M2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12 xvs2x26I8E6xACxx1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r12 6r1DMcIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64 vIr41l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1l4IxYO2xFxVAFwI0_ Jrv_JF1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1V AY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAI cVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42 IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r1j6r4UYxBIdaVFxhVj vjDU0xZFpf9x07j5xhLUUUUU= X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, 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 X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 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: INBOX X-GMAIL-THRID: 1778267595355162771 X-GMAIL-MSGID: 1778267595355162771 From: cailulu Some older kernels cannot handle the newly generated R_LARCH_32/64_PCREL, so the assembler generates R_LARCH_ADD32/64+R_LARCH_SUB32/64 by default, and use the assembler option mthin-add-sub to generate R_LARCH_32/64_PCREL as much as possible. The Option of mthin-add-sub does not affect the generation of R_LARCH_32_PCREL relocation in .eh_frame. --- gas/config/tc-loongarch.c | 29 +++++++++++++++++++++++++++++ gas/config/tc-loongarch.h | 13 +++++++------ include/opcode/loongarch.h | 1 + 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/gas/config/tc-loongarch.c b/gas/config/tc-loongarch.c index 57faffeb14d..d1d21fadb77 100644 --- a/gas/config/tc-loongarch.c +++ b/gas/config/tc-loongarch.c @@ -120,6 +120,7 @@ enum options OPTION_LA_GLOBAL_WITH_ABS, OPTION_RELAX, OPTION_NO_RELAX, + OPTION_THIN_ADD_SUB, OPTION_END_OF_ENUM, }; @@ -136,6 +137,7 @@ struct option md_longopts[] = { "mrelax", no_argument, NULL, OPTION_RELAX }, { "mno-relax", no_argument, NULL, OPTION_NO_RELAX }, + { "mthin-add-sub", no_argument, NULL, OPTION_THIN_ADD_SUB}, { NULL, no_argument, NULL, 0 } }; @@ -214,6 +216,10 @@ md_parse_option (int c, const char *arg) LARCH_opts.relax = 0; break; + case OPTION_THIN_ADD_SUB: + LARCH_opts.thin_add_sub = 1; + break; + case OPTION_IGNORE: break; @@ -1195,6 +1201,7 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED) static int64_t stack_top; static int last_reloc_is_sop_push_pcrel_1 = 0; int last_reloc_is_sop_push_pcrel = last_reloc_is_sop_push_pcrel_1; + segT sub_segment; last_reloc_is_sop_push_pcrel_1 = 0; char *buf = fixP->fx_frag->fr_literal + fixP->fx_where; @@ -1287,6 +1294,23 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED) } } + /* If symbol in .eh_frame the address may be adjusted, and contents of + .eh_frame will be adjusted, so use pc-relative relocation for FDE + initial location. + The Option of mthin-add-sub does not affect the generation of + R_LARCH_32_PCREL relocation in .eh_frame. */ + if (fixP->fx_r_type == BFD_RELOC_32 + && fixP->fx_addsy && fixP->fx_subsy + && (sub_segment = S_GET_SEGMENT (fixP->fx_subsy)) + && strcmp (sub_segment->name, ".eh_frame") == 0 + && S_GET_VALUE (fixP->fx_subsy) + == fixP->fx_frag->fr_address + fixP->fx_where) + { + fixP->fx_r_type = BFD_RELOC_LARCH_32_PCREL; + fixP->fx_subsy = NULL; + break; + } + if (fixP->fx_addsy && fixP->fx_subsy) { fixP->fx_next = xmemdup (fixP, sizeof (*fixP), sizeof (*fixP)); @@ -1589,6 +1613,11 @@ md_show_usage (FILE *stream) { fprintf (stream, _("LARCH options:\n")); /* FIXME */ + fprintf (stream, _("\ + -mthin-add-sub Convert a pair of R_LARCH_ADD32/64 and R_LARCH_SUB32/64 to\n\ + R_LARCH_32/64_PCREL as much as possible\n\ + The option does not affect the generation of R_LARCH_32_PCREL\n\ + relocations in .eh_frame\n")); } static void diff --git a/gas/config/tc-loongarch.h b/gas/config/tc-loongarch.h index fd09435640b..4afa38422d6 100644 --- a/gas/config/tc-loongarch.h +++ b/gas/config/tc-loongarch.h @@ -75,12 +75,13 @@ extern bool loongarch_frag_align_code (int); or PC at start of subsy or with relax but sub_symbol_segment not in SEC_CODE, we generate 32/64_PCREL. */ #define TC_FORCE_RELOCATION_SUB_LOCAL(FIX, SEG) \ - (!((BFD_RELOC_32 || BFD_RELOC_64) \ - &&(!LARCH_opts.relax \ - || S_GET_VALUE (FIX->fx_subsy) \ - == FIX->fx_frag->fr_address + FIX->fx_where \ - || (LARCH_opts.relax \ - && ((S_GET_SEGMENT (FIX->fx_subsy)->flags & SEC_CODE) == 0))))) + (!(LARCH_opts.thin_add_sub \ + && (BFD_RELOC_32 || BFD_RELOC_64) \ + && (!LARCH_opts.relax \ + || S_GET_VALUE (FIX->fx_subsy) \ + == FIX->fx_frag->fr_address + FIX->fx_where \ + || (LARCH_opts.relax \ + && ((S_GET_SEGMENT (FIX->fx_subsy)->flags & SEC_CODE) == 0))))) #define TC_VALIDATE_FIX_SUB(FIX, SEG) 1 #define DIFF_EXPR_OK 1 diff --git a/include/opcode/loongarch.h b/include/opcode/loongarch.h index e145db5e8a6..2ed4082cf43 100644 --- a/include/opcode/loongarch.h +++ b/include/opcode/loongarch.h @@ -236,6 +236,7 @@ dec2 : [1-9][0-9]? #define ase_gabs isa.use_la_global_with_abs int relax; + int thin_add_sub; } LARCH_opts; extern size_t loongarch_insn_length (insn_t insn);