[binutils-gdb] x86: Improve relocation error reporting
H.J. Lu
hjl@sourceware.org
Wed Aug 5 23:08:27 GMT 2026
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=283d3198beda5110a8417fd09b336a34bbd2705c
commit 283d3198beda5110a8417fd09b336a34bbd2705c
Author: H.J. Lu <hjl.tools@gmail.com>
Date: Fri Jul 31 05:47:15 2026 +0800
x86: Improve relocation error reporting
For bfd_reloc_outofrange relocation error, instead of
ld: pr34448-bug_4.o(.debug_addr+0x7f000008): reloc against `.text.get_tls': error 4
linker now reports:
ld: pr34448-bug_4.o(.debug_addr+0x7f000008): relocation `R_X86_64_64' against `.text.get_tls': out of section range
PR ld/34448
* elf32-i386.c (elf_i386_relocate_section): Call
_bfd_x86_elf_link_report_relocation_error for relocation error.
* elf64-x86-64.c (elf_x86_64_relocate_section): Likewise.
* elfxx-x86.c (_bfd_x86_elf_link_report_relocation_error): New.
* elfxx-x86.h (_bfd_x86_elf_link_report_relocation_error): New.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Diff:
---
bfd/elf32-i386.c | 9 ++++-----
bfd/elf64-x86-64.c | 9 ++++-----
bfd/elfxx-x86.c | 31 +++++++++++++++++++++++++++++++
bfd/elfxx-x86.h | 4 ++++
4 files changed, 43 insertions(+), 10 deletions(-)
diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c
index 8ad5cb4e354..36a957d03f1 100644
--- a/bfd/elf32-i386.c
+++ b/bfd/elf32-i386.c
@@ -3648,11 +3648,10 @@ elf_i386_relocate_section (struct bfd_link_info *info,
(bfd_vma) 0, input_bfd, input_section, rel->r_offset);
else
{
- _bfd_error_handler
- /* xgettext:c-format */
- (_("%pB(%pA+%#" PRIx64 "): reloc against `%s': error %d"),
- input_bfd, input_section,
- (uint64_t) rel->r_offset, name, (int) r);
+ _bfd_x86_elf_link_report_relocation_error (input_bfd,
+ input_section,
+ name, rel,
+ howto, r);
return false;
}
}
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index 878feb20b85..2d40e8fc6d8 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -5152,11 +5152,10 @@ elf_x86_64_relocate_section (struct bfd_link_info *info,
}
else
{
- _bfd_error_handler
- /* xgettext:c-format */
- (_("%pB(%pA+%#" PRIx64 "): reloc against `%s': error %d"),
- input_bfd, input_section,
- (uint64_t) rel->r_offset, name, (int) r);
+ _bfd_x86_elf_link_report_relocation_error (input_bfd,
+ input_section,
+ name, rel,
+ howto, r);
return false;
}
}
diff --git a/bfd/elfxx-x86.c b/bfd/elfxx-x86.c
index e08fec52636..da5fc3886ce 100644
--- a/bfd/elfxx-x86.c
+++ b/bfd/elfxx-x86.c
@@ -3424,6 +3424,37 @@ _bfd_x86_elf_link_report_error
bfd_set_error (bfd_error_bad_value);
}
+/* Report link relocation error. */
+
+void
+_bfd_x86_elf_link_report_relocation_error (bfd *abfd, asection *sec,
+ const char *name,
+ Elf_Internal_Rela *rel,
+ reloc_howto_type *howto,
+ bfd_reloc_status_type status)
+{
+ const char *error_msg;
+
+ switch (status)
+ {
+ case bfd_reloc_outofrange:
+ error_msg = _("out of section range");
+ break;
+
+ case bfd_reloc_notsupported:
+ error_msg = _("not supported");
+ break;
+
+ default:
+ abort ();
+ }
+
+ _bfd_error_handler
+ /* xgettext:c-format */
+ (_("%pB(%pA+%#" PRIx64 "): relocation `%s' against `%s': %s"),
+ abfd, sec, (uint64_t) rel->r_offset, howto->name, name, error_msg);
+}
+
/* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
bool
diff --git a/bfd/elfxx-x86.h b/bfd/elfxx-x86.h
index 430d61d3097..48e8ab4ad73 100644
--- a/bfd/elfxx-x86.h
+++ b/bfd/elfxx-x86.h
@@ -962,6 +962,10 @@ extern void _bfd_x86_elf_link_report_error
Elf_Internal_Sym *, reloc_howto_type *,
enum elf_x86_error_type) ATTRIBUTE_HIDDEN;
+extern void _bfd_x86_elf_link_report_relocation_error
+ (bfd *, asection *, const char *, Elf_Internal_Rela *,
+ reloc_howto_type *, bfd_reloc_status_type) ATTRIBUTE_HIDDEN;
+
extern bool
_bfd_elf_x86_copy_special_section_fields
(const bfd *, bfd *, const Elf_Internal_Shdr *,
More information about the Binutils-cvs
mailing list