]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
x86: Improve relocation error reporting
authorH.J. Lu <hjl.tools@gmail.com>
Thu, 30 Jul 2026 21:47:15 +0000 (05:47 +0800)
committerH.J. Lu <hjl.tools@gmail.com>
Wed, 5 Aug 2026 21:53:58 +0000 (05:53 +0800)
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>
bfd/elf32-i386.c
bfd/elf64-x86-64.c
bfd/elfxx-x86.c
bfd/elfxx-x86.h

index 8ad5cb4e354bb58a22f546604a95ec699857eae8..36a957d03f119a957a03f029edb87a08538b7c37 100644 (file)
@@ -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;
            }
        }
index 878feb20b85f08769782e5bc261f226fbee67696..2d40e8fc6d845e9962ed29e0e8769af70f69e467 100644 (file)
@@ -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;
            }
        }
index e08fec52636ccb144b3d95014068053dae08a6c6..da5fc3886ce5557e0d1d8382ac8227af56e74878 100644 (file)
@@ -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
index 430d61d30970e116ace4a66866a09be290d04ad7..48e8ab4ad73f64e9a7058d36035cb4c76a95bb46 100644 (file)
@@ -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 *,