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 9A1A13861920 for ; Tue, 10 Oct 2023 09:56:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9A1A13861920 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.20.4.103]) by gateway (Coremail) with SMTP id _____8AxJujOHyVlgJwwAA--.34556S3; Tue, 10 Oct 2023 17:56:31 +0800 (CST) Received: from [10.20.4.103] (unknown [10.20.4.103]) by localhost.localdomain (Coremail) with SMTP id AQAAf8DxS9zOHyVlGUkeAA--.63741S3; Tue, 10 Oct 2023 17:56:30 +0800 (CST) Subject: Re: [PATCH] as: fixed internal error when immediate value of relocation overflow. To: WANG Xuerui , binutils@sourceware.org Cc: xuchenghua@loongson.cn, chenglulu@loongson.cn, liuzhensong@loongson.cn, mengqinggang@loongson.cn, xry111@xry111.site, maskray@google.com References: <20231009021109.2980562-1-cailulu@loongson.cn> <284beedb-72a8-4333-b80e-55330dc0a25d@xen0n.name> From: Lulu Cai Message-ID: Date: Tue, 10 Oct 2023 17:55:53 +0800 User-Agent: Mozilla/5.0 (X11; Linux loongarch64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <284beedb-72a8-4333-b80e-55330dc0a25d@xen0n.name> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-CM-TRANSID:AQAAf8DxS9zOHyVlGUkeAA--.63741S3 X-CM-SenderInfo: xfdlz3tox6z05rqj20fqof0/1tbiAQAAB2UktKUHcQAAsg X-Coremail-Antispam: 1Uk129KBj93XoWxZrWUWw1ftr4kXrWkWFyrZrc_yoWrXFy7pr ZYk34qyrZ5Cr4kXr1jqry5WFy8Jw4xGw15W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X-Spam-Status: No, score=-13.9 required=5.0 tests=BAYES_00,BODY_8BITS,GIT_PATCH_0,KAM_DMARC_STATUS,NICE_REPLY_A,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 List-Id: 在 2023/10/10 上午8:25, WANG Xuerui 写道: > Hi, > > On 10/9/23 10:11, Lulu Cai wrote: >> The as reports an internal error when the relocation >> overflow or is misaligned. Delete _bfd_error_handler >> can avoid it and reports Reloc overflow. >> --- >>   bfd/elfxx-loongarch.c                      | 8 +------- >>   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 ++++++ >>   7 files changed, 21 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..c20efe82f31 100644 >> --- a/bfd/elfxx-loongarch.c >> +++ b/bfd/elfxx-loongarch.c >> @@ -1671,7 +1671,7 @@ reloc_bits (bfd *abfd ATTRIBUTE_UNUSED, >>   } >>     static bool >> -reloc_sign_bits (bfd *abfd, reloc_howto_type *howto, bfd_vma *fix_val) >> +reloc_sign_bits (bfd *abfd ATTRIBUTE_UNUSED, reloc_howto_type >> *howto, bfd_vma *fix_val) >>   { >>     if (howto->complain_on_overflow != complain_overflow_signed) >>       return false; >> @@ -1682,9 +1682,6 @@ 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); >>         return false; >>       } >>   @@ -1696,9 +1693,6 @@ 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); >>         return false; >>       } > > Isn't this only removing the error (downgrading it to a warning it > seems) but not touching anything else? This will make the programmer > errors slip through (apparently because no one reads warnings heh, > it's especially worse for many devs not comfortable with English that > I know of), and the problematic case you had in mind is still left > unfixed. > > I think it's better to, at least, add the previously rejected code > you're meaning to make acceptable, so the intent is clear; then we can > figure out a better way forward than simply deleting checks. Both the as and ld call the same function and use _bfd_error_handler to output error messages when relocating overflow. However, as passed NULL to the function when it was called, resulting in an internal error. ld passes a non-null value when called and can output error messages without internal errors. So I consider not simply deleting this function. When as passes null, the function is not called and reports a "Reloc overflow" error instead of a warning. ld can call this function to output detailed information.