ld/x86: Update -z report-relative-reloc

Message ID 20220104191306.1387622-1-hjl.tools@gmail.com
State New
Headers show
Series
  • ld/x86: Update -z report-relative-reloc
Related show

Commit Message

H.J. Lu via Binutils Jan. 4, 2022, 7:13 p.m.
Use 0x%v, instead of bfd_sprintf_vma, to report relative relocations.
Change linker relative relocations report from

tmpdir/dump: R_X86_64_IRELATIVE (offset: 0x0000000000002000, info: 0x0000000000000025, addend: 0x0000000000001007) against 'ifunc' for section '.data.rel.ro.local' in tmpdir/report-reloc-1.o

to

tmpdir/dump: R_X86_64_IRELATIVE (offset: 0x2000, info: 0x25, addend: 0x1007) against 'ifunc' for section '.data.rel.ro.local' in tmpdir/report-reloc-1.o

bfd/

	* elfxx-x86.c (_bfd_x86_elf_link_report_relative_reloc): Use
	0x%v instead of bfd_sprintf_vma.

ld/

	* testsuite/ld-i386/report-reloc-1.l: Updated.
	* testsuite/ld-x86-64/report-reloc-1.l: Likewise.
---
 bfd/elfxx-x86.c                         | 24 +++++++-----------------
 ld/testsuite/ld-i386/report-reloc-1.l   |  4 ++--
 ld/testsuite/ld-x86-64/report-reloc-1.l |  4 ++--
 3 files changed, 11 insertions(+), 21 deletions(-)

-- 
2.33.1

Patch

diff --git a/bfd/elfxx-x86.c b/bfd/elfxx-x86.c
index ca5b624cd6c..ca4b90e22cc 100644
--- a/bfd/elfxx-x86.c
+++ b/bfd/elfxx-x86.c
@@ -1754,7 +1754,6 @@  _bfd_x86_elf_link_report_relative_reloc
   const char *name;
   bfd *abfd;
   const Elf_Internal_Rela *rel = (const Elf_Internal_Rela *) reloc;
-  char r_offset[30], r_info[30];
 
   /* Use the output BFD for linker created sections.  */
   if ((asect->flags & SEC_LINKER_CREATED) != 0)
@@ -1767,26 +1766,17 @@  _bfd_x86_elf_link_report_relative_reloc
   else
     name = bfd_elf_sym_name (abfd, &elf_symtab_hdr (abfd), sym, NULL);
 
-  bfd_sprintf_vma (abfd, r_offset, rel->r_offset);
-  bfd_sprintf_vma (abfd, r_info, rel->r_info);
-
   if (asect->use_rela_p)
-    {
-      char r_addend[30];
-
-      bfd_sprintf_vma (abfd, r_addend, rel->r_addend);
-
-      info->callbacks->einfo
-	(_("%pB: %s (offset: 0x%s, info: 0x%s, addend: 0x%s) against "
-	   "'%s' " "for section '%pA' in %pB\n"),
-	 info->output_bfd, reloc_name, r_offset, r_info, r_addend,
-	 name, asect, abfd);
-    }
+    info->callbacks->einfo
+      (_("%pB: %s (offset: 0x%v, info: 0x%v, addend: 0x%v) against "
+	 "'%s' " "for section '%pA' in %pB\n"),
+       info->output_bfd, reloc_name, rel->r_offset, rel->r_info,
+       rel->r_addend, name, asect, abfd);
   else
     info->callbacks->einfo
-      (_("%pB: %s (offset: 0x%s, info: 0x%s) against '%s' for section "
+      (_("%pB: %s (offset: 0x%v, info: 0x%v) against '%s' for section "
 	 "'%pA' in %pB\n"),
-       info->output_bfd, reloc_name, r_offset, r_info, name,
+       info->output_bfd, reloc_name, rel->r_offset, rel->r_info, name,
        asect, abfd);
 }
 
diff --git a/ld/testsuite/ld-i386/report-reloc-1.l b/ld/testsuite/ld-i386/report-reloc-1.l
index d141e06e08d..75e7330708b 100644
--- a/ld/testsuite/ld-i386/report-reloc-1.l
+++ b/ld/testsuite/ld-i386/report-reloc-1.l
@@ -1,2 +1,2 @@ 
-tmpdir/dump: R_386_IRELATIVE \(offset: 0x[0-9a-f]+, info: 0x0+2a\) against 'ifunc' for section '.data.rel.ro.local' in tmpdir/report-reloc-1.o
-tmpdir/dump: R_386_RELATIVE \(offset: 0x[0-9a-f]+, info: 0x0+8\) against '_start' for section '.data.rel.ro.local' in tmpdir/report-reloc-1.o
+tmpdir/dump: R_386_IRELATIVE \(offset: 0x[0-9a-f]+, info: 0x2a\) against 'ifunc' for section '.data.rel.ro.local' in tmpdir/report-reloc-1.o
+tmpdir/dump: R_386_RELATIVE \(offset: 0x[0-9a-f]+, info: 0x8\) against '_start' for section '.data.rel.ro.local' in tmpdir/report-reloc-1.o
diff --git a/ld/testsuite/ld-x86-64/report-reloc-1.l b/ld/testsuite/ld-x86-64/report-reloc-1.l
index 21e9b1ee870..35653794e32 100644
--- a/ld/testsuite/ld-x86-64/report-reloc-1.l
+++ b/ld/testsuite/ld-x86-64/report-reloc-1.l
@@ -1,2 +1,2 @@ 
-tmpdir/dump: R_X86_64_IRELATIVE \(offset: 0x[0-9a-f]+, info: 0x0+25, addend: 0x[0-9a-f]+\) against 'ifunc' for section '.data.rel.ro.local' in tmpdir/report-reloc-1.o
-tmpdir/dump: R_X86_64_RELATIVE \(offset: 0x[0-9a-f]+, info: 0x0+8, addend: 0x[0-9a-f]+\) against '_start' for section '.data.rel.ro.local' in tmpdir/report-reloc-1.o
+tmpdir/dump: R_X86_64_IRELATIVE \(offset: 0x[0-9a-f]+, info: 0x25, addend: 0x[0-9a-f]+\) against 'ifunc' for section '.data.rel.ro.local' in tmpdir/report-reloc-1.o
+tmpdir/dump: R_X86_64_RELATIVE \(offset: 0x[0-9a-f]+, info: 0x8, addend: 0x[0-9a-f]+\) against '_start' for section '.data.rel.ro.local' in tmpdir/report-reloc-1.o