aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLulu Cai <cailulu@loongson.cn>2023-10-11 10:20:45 +0800
committerliuzhensong <liuzhensong@loongson.cn>2024-02-23 11:11:04 +0800
commit1900793bab0f8febb2566293ea932708d89b82e7 (patch)
tree460ded419c55284942d5140212c25ffb6816394d
parent5937f5172a34503ddf7f637621dc07abcbbc2a30 (diff)
downloadgdb-binutils-2_41-branch.zip
gdb-binutils-2_41-branch.tar.gz
gdb-binutils-2_41-branch.tar.bz2
as: fixed internal error when immediate value of relocation overflow.binutils-2_41-branch
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. (cherry picked from commit f87cf663af71e5d78c8d647fa48562102f3b0615)
-rw-r--r--bfd/elfxx-loongarch.c22
-rw-r--r--gas/config/tc-loongarch.c2
-rw-r--r--gas/testsuite/gas/loongarch/imm_overflow.d3
-rw-r--r--gas/testsuite/gas/loongarch/imm_overflow.l2
-rw-r--r--gas/testsuite/gas/loongarch/imm_overflow.s4
-rw-r--r--gas/testsuite/gas/loongarch/imm_unalign.d3
-rw-r--r--gas/testsuite/gas/loongarch/imm_unalign.l2
-rw-r--r--gas/testsuite/gas/loongarch/imm_unalign.s6
8 files changed, 37 insertions, 7 deletions
diff --git a/bfd/elfxx-loongarch.c b/bfd/elfxx-loongarch.c
index 2d29905..45ba9dd 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 2e8a259..c577c04 100644
--- a/gas/config/tc-loongarch.c
+++ b/gas/config/tc-loongarch.c
@@ -1181,7 +1181,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 0000000..50a65b7
--- /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 0000000..449b3c2
--- /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 0000000..9aac396
--- /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 0000000..1deb502
--- /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 0000000..449b3c2
--- /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 0000000..a853bdc
--- /dev/null
+++ b/gas/testsuite/gas/loongarch/imm_unalign.s
@@ -0,0 +1,6 @@
+.L1:
+ .2byte 0x12
+
+.L2:
+ .fill 1, 4, 0
+ b .L1