public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Lulu Cai <cailulu@loongson.cn>
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 <cailulu@loongson.cn>
Subject: [PATCH] as: fixed internal error when immediate value of relocation overflow.
Date: Mon,  9 Oct 2023 10:11:09 +0800	[thread overview]
Message-ID: <20231009021109.2980562-1-cailulu@loongson.cn> (raw)

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;
     }
 
diff --git a/gas/testsuite/gas/loongarch/imm_overflow.d b/gas/testsuite/gas/loongarch/imm_overflow.d
new file mode 100644
index 00000000000..1ead2c9a74f
--- /dev/null
+++ b/gas/testsuite/gas/loongarch/imm_overflow.d
@@ -0,0 +1,3 @@
+#as:
+#source: imm_overflow.s
+#warning_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..3dd4d90ffa1
--- /dev/null
+++ b/gas/testsuite/gas/loongarch/imm_overflow.l
@@ -0,0 +1,2 @@
+.*Assembler messages:
+.*Warning: 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..2be688bd25a
--- /dev/null
+++ b/gas/testsuite/gas/loongarch/imm_overflow.s
@@ -0,0 +1,4 @@
+.L1:
+  nop
+  .fill 0x12345, 4, 0
+  blt $r3, $r4, .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..df1a8cf6041
--- /dev/null
+++ b/gas/testsuite/gas/loongarch/imm_unalign.d
@@ -0,0 +1,3 @@
+#as:
+#source: imm_unalign.s
+#warning_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..3dd4d90ffa1
--- /dev/null
+++ b/gas/testsuite/gas/loongarch/imm_unalign.l
@@ -0,0 +1,2 @@
+.*Assembler messages:
+.*Warning: 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..d97ada04d9f
--- /dev/null
+++ b/gas/testsuite/gas/loongarch/imm_unalign.s
@@ -0,0 +1,6 @@
+.L1:
+  .2byte 0x12
+
+.L2:
+  .fill 1, 4, 0
+  blt $r3, $r4, .L1
-- 
2.31.1


             reply	other threads:[~2023-10-09  2:11 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-09  2:11 Lulu Cai [this message]
2023-10-10  0:25 ` WANG Xuerui
2023-10-10  9:55   ` Lulu Cai
2023-10-11  2:20 ` Lulu Cai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231009021109.2980562-1-cailulu@loongson.cn \
    --to=cailulu@loongson.cn \
    --cc=binutils@sourceware.org \
    --cc=chenglulu@loongson.cn \
    --cc=i.swmail@xen0n.name \
    --cc=liuzhensong@loongson.cn \
    --cc=maskray@google.com \
    --cc=mengqinggang@loongson.cn \
    --cc=xry111@xry111.site \
    --cc=xuchenghua@loongson.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).