From 634b2757c1a8b5203906c3f60a243f10e165d2f0 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Fri, 31 Jul 2026 05:47:15 +0800
Subject: [PATCH] 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' is 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>
---
bfd/elf32-i386.c | 9 ++++-----
bfd/elf64-x86-64.c | 9 ++++-----
bfd/elfxx-x86.c | 33 +++++++++++++++++++++++++++++++++
bfd/elfxx-x86.h | 4 ++++
4 files changed, 45 insertions(+), 10 deletions(-)
@@ -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;
}
}
@@ -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;
}
}
@@ -3424,6 +3424,39 @@ _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)
+{
+ switch (status)
+ {
+ case bfd_reloc_outofrange:
+ _bfd_error_handler
+ /* xgettext:c-format */
+ (_("%pB(%pA+%#" PRIx64 "): relocation `%s' against `%s' is "
+ "out of section range"), abfd, sec, (uint64_t) rel->r_offset,
+ howto->name, name);
+ break;
+
+ case bfd_reloc_notsupported:
+ _bfd_error_handler
+ /* xgettext:c-format */
+ (_("%pB(%pA+%#" PRIx64 "): relocation `%s' against `%s' is "
+ "not supported"), abfd, sec, (uint64_t) rel->r_offset,
+ howto->name, name);
+ break;
+
+ default:
+ abort ();
+ break;
+ }
+}
+
/* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
bool
@@ -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 *,
--
2.55.0