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: 151095 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp260843vqb; Tue, 10 Oct 2023 19:20:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEpxbo4Pan8QBrP3nFpGE50aAQSryAdpSGGw/5GtBdf8i+cTouVg6I5BPsg9qOzkNZRe41c X-Received: by 2002:a5d:6909:0:b0:314:dc0:2fca with SMTP id t9-20020a5d6909000000b003140dc02fcamr17292930wru.29.1696990858745; Tue, 10 Oct 2023 19:20:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696990858; cv=none; d=google.com; s=arc-20160816; b=c4rvdbRoAjfiZBDBtUfvqkSDYY3J4hMMmpBGwln3gXX4fHs2hVkH69K4WPykv0+amX IWEaCu80fNLioCsG5evyYWLxJdJdbODJbMC9aWwoVj5IFiJmdQuC29jheXy6w0MEKdbb GrNXv7W4y/RiVVo3auIp+3PgmB+3HjxCPArD2I4ODQnSYWQs2/ASEJP5irTNYjfN2O6V CVUig+BfkiswHeApgF1shT0SH33vAcGpY44mFz6J4mhsVg7WM/MHEdai3SYo/ObHPDV8 Ko3Nu6Ysuol0CZA8eIygzCoY9hg6IFMJntDKZZIraTRlM+lPn5+J3nJRVR17t+LpzXWG J6HQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:delivered-to; bh=vGd/jRbGEHg3CF4uL9dVtqGM1hc8JXvCHejQKu6e7Lg=; fh=DMl6b2Diyq+8PtsEIVjGfhZIW0JkBkdnqSiV7t/s/KA=; b=V/ANAmyzDb8POANa4YkzmsUqcMvviOsHSOMYh4pGcvmcLwctxuV9czIU+xtX5kgxN0 Vz2G0l+S/pemCT5iHG5FFJUlp/Z2bKeVdHWymh2d7Q/rdX14k7BYFVBvSZ4qmH5j4Pxx ssbAK56qOMADHGWYBPTueu/NPfVjLAGKQpgBFEOrZ4kelP5fEjjObhsFzuO7l8uniN2w evtv0/w0UCzQlvYra1U2Vy50gdm18w33Z9YHiL0mWDFbwbzo4/IB8P1c0kCDX7ctOAFg hB2IovrcdvSWiOQ2XAQIJVhEAWyk3Cb3hZq6ojvXTuK/Ba0DAi/Ke7k+i4j125OHfoPZ LLVA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org" Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id o17-20020aa7d3d1000000b005362e6df6b0si5649436edr.465.2023.10.10.19.20.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 19:20:58 -0700 (PDT) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 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 009F93857707 for ; Wed, 11 Oct 2023 02:20:57 +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: xfdlz3tox6z05rqj20fqof0/1tbiAQAAB2UktKUHcQADsj X-Coremail-Antispam: 1Uk129KBj93XoW3GF43Ww1UKF4rAry5tw4fZwc_yoW7WF4rp3 y3uF1qkr48GFnrXr1DKa45XFn7Aw4xCrya9as3t34xuryxXFyav3Wktry3WFZ8J3yDG3yS qw4FqF1UZF15tagCm3ZEXasCq-sJn29KB7ZKAUJUUUUr529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUU9Yb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x0267AK xVW8Jr0_Cr1UM2kKe7AKxVWUXVWUAwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07 AIYIkI8VC2zVCFFI0UMc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWU XVWUAwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7V AKI48JMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMxCIbckI1I0E14v2 6r1Y6r17MI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17 CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF 0xvE2Ix0cI8IcVCY1x0267AKxVWUJVW8JwCI42IY6xAIw20EY4v20xvaj40_Jr0_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+ouuuleilei=gmail.com@sourceware.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779242088348327966 X-GMAIL-MSGID: 1779423886362086467 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