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 327613858D33 for ; Thu, 22 Feb 2024 12:42:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 327613858D33 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 327613858D33 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=1708605761; cv=none; b=llVSNKQDQYXSIKVNdZfmXfZyD206QwHepaPg+r9Yc1zqE7f5o0sRPF6sAlzyse7ZrlBwcG/Tsnu3fBrsg1ATFybRCDyAfvDylDIvWHE9rSADDGZCLYiDHHk2ptIHPnoOKO3Ms/aI/t5WPgLlfMkguzZB9ogT3TgHG1UhGAKaZuM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708605761; c=relaxed/simple; bh=tPEXZfO7CrRpXidm7zd/t4oida8pHotVuH3bYeqAcl4=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=aUx98fgl7HwOAiJy4siCBC2EUdzy2s9y4RCnBd2jQjF7GrfVta0YJ7UYpEs03C8Z1XIEDoWpx4tcZGBUqIxA6OxYc8CAIVCM888tC8dtNarVSZbEjDk+D/SsBlfxUI/8TZ6FSyDKhywa/KIdZw2hX+n1GDMtpo0GRi8c/Svk7g8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from loongson.cn (unknown [10.2.6.5]) by gateway (Coremail) with SMTP id _____8CxG+k6QddlnTcQAA--.23556S3; Thu, 22 Feb 2024 20:42:35 +0800 (CST) Received: from 5.5.5 (unknown [10.2.6.5]) by localhost.localdomain (Coremail) with SMTP id AQAAf8BxXs05QddllNE+AA--.28904S2; Thu, 22 Feb 2024 20:42:33 +0800 (CST) From: mengqinggang To: binutils@sourceware.org Cc: xuchenghua@loongson.cn, chenglulu@loongson.cn, liuzhensong@loongson.cn, cailulu@loongson.cn, xry111@xry111.site, i.swmail@xen0n.name, maskray@google.com, luweining@loongson.cn, wanglei@loongson.cn, hejinyang@loongson.cn, mengqinggang@loongson.cn Subject: [PATCH v2] LoongArch: gas: Try to avoid R_LARCH_ALIGN associate with a symbol Date: Thu, 22 Feb 2024 20:42:32 +0800 Message-Id: <20240222124232.2925221-1-mengqinggang@loongson.cn> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:AQAAf8BxXs05QddllNE+AA--.28904S2 X-CM-SenderInfo: 5phqw15lqjwttqj6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBj93XoWxtw4DAry7Gr1UKw1kJw1xXrc_yoW7WFy5pr yjvFs0kay8CF1vgw1jyw13Aw17Xw4xuFW7t3y8tr1I9rWkJr9Yy3WUCFW3WF1Dur1DC34r Xr1q93WjqF92kwbCm3ZEXasCq-sJn29KB7ZKAUJUUUU7529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUU9Yb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_JFI_Gr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Jr0_Gr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x0267AK xVWxJr0_GcWln4kS14v26r1Y6r17M2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12 xvs2x26I8E6xACxx1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r12 6r1DMcIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64 vIr41l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1l4IxYO2xFxVAFwI0_ Jrv_JF1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1V AY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAI cVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42 IY6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIev Ja73UjIFyTuYvjxU7fMaUUUUU X-Spam-Status: No, score=-12.7 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 List-Id: The R_LARCH_ALIGN need to associated with a symbol if .align has the first and third expressions. If R_LARCH_ALIGN associate with a symbol, the addend can represent the first and third expression of .align. For '.align 3', the addend of R_LARCH_ALIGN only need to represent the alignment and R_LARCH_ALIGN not need to associate with a symbol. For '.align x, , y', R_LARCH_ALIGN need to associate with a symbol if 0 < y < 2^x - 4. --- v1 -> v2: - For '.align x, , y', R_LARCH_ALIGN need to associate with a symbol if 0 < y < 2^x - 4. v1 link: https://sourceware.org/pipermail/binutils/2024-February/132306.html gas/config/tc-loongarch.c | 27 +++++++--- gas/testsuite/gas/loongarch/relax_align.d | 64 +++++++++++++---------- gas/testsuite/gas/loongarch/relax_align.s | 20 +++++-- 3 files changed, 72 insertions(+), 39 deletions(-) diff --git a/gas/config/tc-loongarch.c b/gas/config/tc-loongarch.c index 91f5f1d0681..de92366eda4 100644 --- a/gas/config/tc-loongarch.c +++ b/gas/config/tc-loongarch.c @@ -1746,14 +1746,25 @@ loongarch_frag_align_code (int n, int max) nops = frag_more (worst_case_bytes); - s = symbol_find (".Lla-relax-align"); - if (s == NULL) - s = (symbolS *)local_symbol_make (".Lla-relax-align", now_seg, - &zero_address_frag, 0); - - ex.X_add_symbol = s; - ex.X_op = O_symbol; - ex.X_add_number = (max << 8) | n; + /* If max <= 0, ignore max. + If max >= worst_case_bytes, max has no effect. + Similar to gas/write.c relax_segment function rs_align_code case: + if (fragP->fr_subtype != 0 && offset > fragP->fr_subtype). */ + if (max > 0 && (bfd_vma) max < worst_case_bytes) + { + s = symbol_find (".Lla-relax-align"); + if (s == NULL) + s = (symbolS *)local_symbol_make (".Lla-relax-align", now_seg, + &zero_address_frag, 0); + ex.X_add_symbol = s; + ex.X_op = O_symbol; + ex.X_add_number = (max << 8) | n; + } + else + { + ex.X_op = O_constant; + ex.X_add_number = worst_case_bytes; + } loongarch_make_nops (nops, worst_case_bytes); diff --git a/gas/testsuite/gas/loongarch/relax_align.d b/gas/testsuite/gas/loongarch/relax_align.d index 2cc6c86d38a..fc1fd032611 100644 --- a/gas/testsuite/gas/loongarch/relax_align.d +++ b/gas/testsuite/gas/loongarch/relax_align.d @@ -1,4 +1,4 @@ -#as: --no-warn +#as: #objdump: -dr #skip: loongarch32-*-* @@ -8,29 +8,39 @@ Disassembly of section .text: [ ]*0000000000000000 <.Lla-relax-align>: -[ ]+0:[ ]+1a000004[ ]+pcalau12i[ ]+\$a0, 0 -[ ]+0: R_LARCH_PCALA_HI20[ ]+L1 -[ ]+0: R_LARCH_RELAX[ ]+\*ABS\* -[ ]+4:[ ]+02c00084[ ]+addi.d[ ]+\$a0, \$a0, 0 -[ ]+4: R_LARCH_PCALA_LO12[ ]+L1 -[ ]+4: R_LARCH_RELAX[ ]+\*ABS\* -[ ]+8:[ ]+03400000[ ]+nop.* -[ ]+8: R_LARCH_ALIGN[ ]+.Lla-relax-align\+0x4 -[ ]+c:[ ]+03400000[ ]+nop.* -[ ]+10:[ ]+03400000[ ]+nop.* -[ ]+14:[ ]+1a000004[ ]+pcalau12i[ ]+\$a0, 0 -[ ]+14: R_LARCH_PCALA_HI20[ ]+L1 -[ ]+14: R_LARCH_RELAX[ ]+\*ABS\* -[ ]+18:[ ]+02c00084[ ]+addi.d[ ]+\$a0, \$a0, 0 -[ ]+18: R_LARCH_PCALA_LO12[ ]+L1 -[ ]+18: R_LARCH_RELAX[ ]+\*ABS\* -[ ]+1c:[ ]+03400000[ ]+nop.* -[ ]+1c: R_LARCH_ALIGN[ ]+.Lla-relax-align\+0x404 -[ ]+20:[ ]+03400000[ ]+nop.* -[ ]+24:[ ]+03400000[ ]+nop.* -[ ]+28:[ ]+1a000004[ ]+pcalau12i[ ]+\$a0, 0 -[ ]+28: R_LARCH_PCALA_HI20[ ]+L1 -[ ]+28: R_LARCH_RELAX[ ]+\*ABS\* -[ ]+2c:[ ]+02c00084[ ]+addi.d[ ]+\$a0, \$a0, 0 -[ ]+2c: R_LARCH_PCALA_LO12[ ]+L1 -[ ]+2c: R_LARCH_RELAX[ ]+\*ABS\* +[ ]+0:[ ]+4c000020[ ]+ret +[ ]+4:[ ]+03400000[ ]+nop +[ ]+4: R_LARCH_ALIGN[ ]+\*ABS\*\+0xc +[ ]+8:[ ]+03400000[ ]+nop +[ ]+c:[ ]+03400000[ ]+nop +[ ]+10:[ ]+4c000020[ ]+ret +[ ]+14:[ ]+03400000[ ]+nop +[ ]+14: R_LARCH_ALIGN[ ]+\*ABS\*\+0xc +[ ]+18:[ ]+03400000[ ]+nop +[ ]+1c:[ ]+03400000[ ]+nop +[ ]+20:[ ]+4c000020[ ]+ret +[ ]+24:[ ]+03400000[ ]+nop +[ ]+24: R_LARCH_ALIGN[ ]+.Lla-relax-align\+0x104 +[ ]+28:[ ]+03400000[ ]+nop +[ ]+2c:[ ]+03400000[ ]+nop +[ ]+30:[ ]+4c000020[ ]+ret +[ ]+34:[ ]+03400000[ ]+nop +[ ]+34: R_LARCH_ALIGN[ ]+.Lla-relax-align\+0xb04 +[ ]+38:[ ]+03400000[ ]+nop +[ ]+3c:[ ]+03400000[ ]+nop +[ ]+40:[ ]+4c000020[ ]+ret +[ ]+44:[ ]+03400000[ ]+nop +[ ]+44: R_LARCH_ALIGN[ ]+\*ABS\*\+0xc +[ ]+48:[ ]+03400000[ ]+nop +[ ]+4c:[ ]+03400000[ ]+nop +[ ]+50:[ ]+4c000020[ ]+ret +[ ]+54:[ ]+03400000[ ]+nop +[ ]+54: R_LARCH_ALIGN[ ]+\*ABS\*\+0xc +[ ]+58:[ ]+03400000[ ]+nop +[ ]+5c:[ ]+03400000[ ]+nop +[ ]+60:[ ]+4c000020[ ]+ret +[ ]+64:[ ]+03400000[ ]+nop +[ ]+64: R_LARCH_ALIGN[ ]+\*ABS\*\+0xc +[ ]+68:[ ]+03400000[ ]+nop +[ ]+6c:[ ]+03400000[ ]+nop +[ ]+70:[ ]+4c000020[ ]+ret diff --git a/gas/testsuite/gas/loongarch/relax_align.s b/gas/testsuite/gas/loongarch/relax_align.s index c0177c88fc1..4f4867fb209 100644 --- a/gas/testsuite/gas/loongarch/relax_align.s +++ b/gas/testsuite/gas/loongarch/relax_align.s @@ -1,7 +1,19 @@ +# If max < -0x80000000, max becomes a positive number because type conversion +# (bfd_signed_vma -> unsigned int). .text .L1: - la.local $a0, L1 + ret .align 4 - la.local $a0, L1 - .align 4, , 4 - la.local $a0, L1 + ret + .align 4, , 0 + ret + .align 4, , 1 + ret + .align 4, , 11 + ret + .align 4, , 12 + ret + .align 4, , -1 + ret + .align 4, , -0x80000000 + ret -- 2.36.0