From patchwork Fri Sep 27 09:17:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lulu Cai X-Patchwork-Id: 98045 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 09A083858280 for ; Fri, 27 Sep 2024 09:18:33 +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 A54453858C60 for ; Fri, 27 Sep 2024 09:17:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A54453858C60 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 A54453858C60 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=1727428683; cv=none; b=LbY6ZYgknToTnTYNULdhU1uk0zIdGcFuZUfsatxBrUo44B3mUAY4SxWaTZqe55EFJhNe7OBnzx+2E4BEVJLFrimmuQD0764kAVt8G1+WKo6q4vKQKkW6pHQMiJly/jeNojGODttCyiKyc+W1PSZovYxOBHuUoW2HXoNcbhciSeQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727428683; c=relaxed/simple; bh=oZuxNGR1dXZVJikjDt2SY12BKyQaK8+RCfBq3+BLbOY=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=VwdLGqDstQUSxls1LVvy+rYy3Wea2VwAUYsHjxoSjTOcwu2Hxlgy84KKIqimVbAJmyFQaUSkzGHoUHQ8A1A5ZXF9VHgayDC0xO3RkW5UZPJOk2h0il+yeorWz8Vg4w9C23mpYcixISzsS5phAM/s+8kxXfUmTL+eaI+V4m3z8W0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from loongson.cn (unknown [10.2.6.5]) by gateway (Coremail) with SMTP id _____8DxhbBCePZmewQCAA--.762S3; Fri, 27 Sep 2024 17:17:54 +0800 (CST) Received: from 5.5.5 (unknown [10.2.6.5]) by front1 (Coremail) with SMTP id qMiowMBxXuRAePZmHyESAA--.39472S4; Fri, 27 Sep 2024 17:17:53 +0800 (CST) From: Lulu Cai To: binutils@sourceware.org Cc: xuchenghua@loongson.cn, chenglulu@loongson.cn, mengqinggang@loongson.cn, xry111@xry111.site, i.swmail@xen0n.name, maskray@google.com, luweining@loongson.cn, hejinyang@loongson.cn, wangxin03@loongson.cn, Lulu Cai Subject: [PATCH] LoongArch: Fixed R_LARCH_[32/64]_PCREL generation bug Date: Fri, 27 Sep 2024 17:17:37 +0800 Message-Id: <20240927091737.1697911-1-cailulu@loongson.cn> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 X-CM-TRANSID: qMiowMBxXuRAePZmHyESAA--.39472S4 X-CM-SenderInfo: xfdlz3tox6z05rqj20fqof0/1tbiAgENB2b1Tp8WzQABsR X-Coremail-Antispam: 1Uk129KBj93XoWxGF1DXry7tFyDKw4ktr43urX_yoW5Wr4Dpr y7ZF18KrW0kF97Ar1DK34UXr1fXw4xAF42vFySqw1I9rs7Jry0vw1Iq3srXFs0qw4UKana vr4Yqw1jvFyDtwcCm3ZEXasCq-sJn29KB7ZKAUJUUUU5529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUvIb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_JFI_Gr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x0267AK xVW8Jr0_Cr1UM2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12xvs2x26I8E6xACxx 1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1Y6r17McIj6I8E87Iv 67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2 Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1l4IxYO2xFxVAFwI0_Jrv_JF1lx2IqxVAq x4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r 43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF 7I0E14v26r1j6r4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxV WUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r1j6r4UYxBIdaVFxhVjvjDU0xZFpf9x07UN vtZUUUUU= X-Spam-Status: No, score=-13.1 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~patchwork=sourceware.org@sourceware.org The enum BFD_RELOC_[32/64] was mistakenly used in the macro instead of the relocation in fixp. This can cause the second relocation of a pair to be deleted when -mthin-add-sub is enabled. Apply the correct macro to fix this. Also sets the initial value of -mthin-add-sub. --- gas/config/tc-loongarch.h | 3 ++- gas/testsuite/gas/loongarch/no_thin_add_sub_8_16.d | 12 ++++++++++++ gas/testsuite/gas/loongarch/no_thin_add_sub_8_16.s | 6 ++++++ opcodes/loongarch-opc.c | 3 ++- 4 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 gas/testsuite/gas/loongarch/no_thin_add_sub_8_16.d create mode 100644 gas/testsuite/gas/loongarch/no_thin_add_sub_8_16.s diff --git a/gas/config/tc-loongarch.h b/gas/config/tc-loongarch.h index 20434ac8a01..64d95e44277 100644 --- a/gas/config/tc-loongarch.h +++ b/gas/config/tc-loongarch.h @@ -79,7 +79,8 @@ extern bool loongarch_frag_align_code (int, int); SEC_CODE, we generate 32/64_PCREL. */ #define TC_FORCE_RELOCATION_SUB_LOCAL(FIX, SEG) \ (!(LARCH_opts.thin_add_sub \ - && (BFD_RELOC_32 || BFD_RELOC_64) \ + && ((FIX)->fx_r_type == BFD_RELOC_32 \ + ||(FIX)->fx_r_type == BFD_RELOC_64) \ && (!LARCH_opts.relax \ || S_GET_VALUE (FIX->fx_subsy) \ == FIX->fx_frag->fr_address + FIX->fx_where \ diff --git a/gas/testsuite/gas/loongarch/no_thin_add_sub_8_16.d b/gas/testsuite/gas/loongarch/no_thin_add_sub_8_16.d new file mode 100644 index 00000000000..334d1742361 --- /dev/null +++ b/gas/testsuite/gas/loongarch/no_thin_add_sub_8_16.d @@ -0,0 +1,12 @@ +#as: -mthin-add-sub +#readelf: -rW +#skip: loongarch32-*-* + +Relocation section '.rela.text' at offset 0x108 contains 6 entries: +.* +0+0 000000060000002f R_LARCH_ADD8 0+0 global_a \+ 0 +0+0 0000000400000034 R_LARCH_SUB8 0+0 L0\^A \+ 0 +0+1 0000000600000030 R_LARCH_ADD16 0+0 global_a \+ 0 +0+1 0000000500000035 R_LARCH_SUB16 0+1 L0\^A \+ 0 +0+3 0000000600000063 R_LARCH_32_PCREL 0+0 global_a \+ 0 +0+7 000000060000006d R_LARCH_64_PCREL 0+0 global_a \+ 0 diff --git a/gas/testsuite/gas/loongarch/no_thin_add_sub_8_16.s b/gas/testsuite/gas/loongarch/no_thin_add_sub_8_16.s new file mode 100644 index 00000000000..68f3655c7ea --- /dev/null +++ b/gas/testsuite/gas/loongarch/no_thin_add_sub_8_16.s @@ -0,0 +1,6 @@ + .text +.L1: + .byte global_a - . + .2byte global_a - . + .4byte global_a - . + .8byte global_a - . diff --git a/opcodes/loongarch-opc.c b/opcodes/loongarch-opc.c index 6bd436fa1fe..0ba745f7d0a 100644 --- a/opcodes/loongarch-opc.c +++ b/opcodes/loongarch-opc.c @@ -24,7 +24,8 @@ struct loongarch_ASEs_option LARCH_opts = { - .relax = 1 + .relax = 1, + .thin_add_sub = 0 }; size_t