From patchwork Wed Oct 11 02:20:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lulu Cai X-Patchwork-Id: 77511 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 DC68738582A3 for ; Wed, 11 Oct 2023 02:21:08 +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 ABE813858423 for ; Wed, 11 Oct 2023 02:20:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ABE813858423 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 _____8CxLOt_BiZle90wAA--.23035S3; Wed, 11 Oct 2023 10:20:47 +0800 (CST) Received: from 5.5.5 (unknown [10.2.6.5]) by localhost.localdomain (Coremail) with SMTP id AQAAf8AxH91_BiZljpUfAA--.3128S4; Wed, 11 Oct 2023 10:20:47 +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, Lulu Cai Subject: [PATCH] as: fixed internal error when immediate value of relocation overflow. Date: Wed, 11 Oct 2023 10:20:45 +0800 Message-Id: <20231011022045.3320754-1-cailulu@loongson.cn> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20231009021109.2980562-1-cailulu@loongson.cn> References: <20231009021109.2980562-1-cailulu@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8AxH91_BiZljpUfAA--.3128S4 X-CM-SenderInfo: xfdlz3t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0_JF4lIx AIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVWUJVW8JbIYCTnIWIev Ja73UjIFyTuYvjxU2MKZDUUUU X-Spam-Status: No, score=-13.7 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 as and ld use _bfd_error_handler to output error messages when checking relocation alignment and relocation overflow. However, the abfd value passed by as to the function is NULL, resulting in an internal error. The ld passes a non-null value to the function, so it can output an error message normally. --- bfd/elfxx-loongarch.c | 22 ++++++++++++++++------ gas/config/tc-loongarch.c | 2 +- gas/testsuite/gas/loongarch/imm_overflow.d | 3 +++ gas/testsuite/gas/loongarch/imm_overflow.l | 2 ++ gas/testsuite/gas/loongarch/imm_overflow.s | 4 ++++ gas/testsuite/gas/loongarch/imm_unalign.d | 3 +++ gas/testsuite/gas/loongarch/imm_unalign.l | 2 ++ gas/testsuite/gas/loongarch/imm_unalign.s | 6 ++++++ 8 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 gas/testsuite/gas/loongarch/imm_overflow.d create mode 100644 gas/testsuite/gas/loongarch/imm_overflow.l create mode 100644 gas/testsuite/gas/loongarch/imm_overflow.s create mode 100644 gas/testsuite/gas/loongarch/imm_unalign.d create mode 100644 gas/testsuite/gas/loongarch/imm_unalign.l create mode 100644 gas/testsuite/gas/loongarch/imm_unalign.s diff --git a/bfd/elfxx-loongarch.c b/bfd/elfxx-loongarch.c index 0a595eb87d5..a970a257aa9 100644 --- a/bfd/elfxx-loongarch.c +++ b/bfd/elfxx-loongarch.c @@ -1682,9 +1682,14 @@ reloc_sign_bits (bfd *abfd, reloc_howto_type *howto, bfd_vma *fix_val) if (howto->rightshift && (val & ((((bfd_signed_vma) 1) << howto->rightshift) - 1))) { - (*_bfd_error_handler) (_("%pB: relocation %s right shift %d error 0x%lx"), - abfd, howto->name, howto->rightshift, (long) val); - bfd_set_error (bfd_error_bad_value); + /* The as passes NULL casued internal error, so it can not use _bfd_error_handler + output details, ld is not affected. */ + if (abfd != NULL) + { + (*_bfd_error_handler) (_("%pB: relocation %s right shift %d error 0x%lx"), + abfd, howto->name, howto->rightshift, (long) val); + bfd_set_error (bfd_error_bad_value); + } return false; } @@ -1696,9 +1701,14 @@ reloc_sign_bits (bfd *abfd, reloc_howto_type *howto, bfd_vma *fix_val) high part: from sign bit to highest bit. */ if ((val & ~mask) && ((val & ~mask) != ~mask)) { - (*_bfd_error_handler) (_("%pB: relocation %s overflow 0x%lx"), - abfd, howto->name, (long) val); - bfd_set_error (bfd_error_bad_value); + /* The as passes NULL casued internal error, so it can not use _bfd_error_handler + output details, ld is not affected. */ + if (abfd != NULL) + { + (*_bfd_error_handler) (_("%pB: relocation %s overflow 0x%lx"), + abfd, howto->name, (long) val); + bfd_set_error (bfd_error_bad_value); + } return false; } diff --git a/gas/config/tc-loongarch.c b/gas/config/tc-loongarch.c index b563982b933..33f3e71ce2f 100644 --- a/gas/config/tc-loongarch.c +++ b/gas/config/tc-loongarch.c @@ -1234,7 +1234,7 @@ static void fix_reloc_insn (fixS *fixP, bfd_vma reloc_val, char *buf) insn = bfd_getl32 (buf); if (!loongarch_adjust_reloc_bitsfield (NULL, howto, &reloc_val)) - as_warn_where (fixP->fx_file, fixP->fx_line, "Reloc overflow"); + as_bad_where (fixP->fx_file, fixP->fx_line, "Reloc overflow"); insn = (insn & (insn_t)howto->src_mask) | ((insn & (~(insn_t)howto->dst_mask)) | reloc_val); diff --git a/gas/testsuite/gas/loongarch/imm_overflow.d b/gas/testsuite/gas/loongarch/imm_overflow.d new file mode 100644 index 00000000000..50a65b7c4ae --- /dev/null +++ b/gas/testsuite/gas/loongarch/imm_overflow.d @@ -0,0 +1,3 @@ +#as: +#source: imm_overflow.s +#error_output: imm_overflow.l diff --git a/gas/testsuite/gas/loongarch/imm_overflow.l b/gas/testsuite/gas/loongarch/imm_overflow.l new file mode 100644 index 00000000000..449b3c2adea --- /dev/null +++ b/gas/testsuite/gas/loongarch/imm_overflow.l @@ -0,0 +1,2 @@ +.*Assembler messages: +.*Error: Reloc overflow diff --git a/gas/testsuite/gas/loongarch/imm_overflow.s b/gas/testsuite/gas/loongarch/imm_overflow.s new file mode 100644 index 00000000000..9aac396ad50 --- /dev/null +++ b/gas/testsuite/gas/loongarch/imm_overflow.s @@ -0,0 +1,4 @@ +.L1: + nop + .fill 0x3ffffff, 4, 0 + b .L1 diff --git a/gas/testsuite/gas/loongarch/imm_unalign.d b/gas/testsuite/gas/loongarch/imm_unalign.d new file mode 100644 index 00000000000..1deb502589e --- /dev/null +++ b/gas/testsuite/gas/loongarch/imm_unalign.d @@ -0,0 +1,3 @@ +#as: +#source: imm_unalign.s +#error_output: imm_unalign.l diff --git a/gas/testsuite/gas/loongarch/imm_unalign.l b/gas/testsuite/gas/loongarch/imm_unalign.l new file mode 100644 index 00000000000..449b3c2adea --- /dev/null +++ b/gas/testsuite/gas/loongarch/imm_unalign.l @@ -0,0 +1,2 @@ +.*Assembler messages: +.*Error: Reloc overflow diff --git a/gas/testsuite/gas/loongarch/imm_unalign.s b/gas/testsuite/gas/loongarch/imm_unalign.s new file mode 100644 index 00000000000..a853bdcbf0a --- /dev/null +++ b/gas/testsuite/gas/loongarch/imm_unalign.s @@ -0,0 +1,6 @@ +.L1: + .2byte 0x12 + +.L2: + .fill 1, 4, 0 + b .L1