aboutsummaryrefslogtreecommitdiff
path: root/bfd/elfxx-x86.c
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2021-01-15 18:06:48 -0800
committerH.J. Lu <hjl.tools@gmail.com>2021-01-15 18:07:07 -0800
commit68b007788a6cc5376708af42bc220f540e8c4b8a (patch)
treeea89e2a6a9e242932f93752ba6df8c19a15caf79 /bfd/elfxx-x86.c
parentad92f33d386e050304bf5986f28071ede9dd2284 (diff)
downloadgdb-68b007788a6cc5376708af42bc220f540e8c4b8a.zip
gdb-68b007788a6cc5376708af42bc220f540e8c4b8a.tar.gz
gdb-68b007788a6cc5376708af42bc220f540e8c4b8a.tar.bz2
ld/x86: Add -z report-relative-reloc
Linker generated relative relocations don't have symbol info: [hjl@gnu-cfl-2 tmpdir]$ readelf -rW dump Relocation section '.rela.dyn' at offset 0x180 contains 2 entries: Offset Info Type Sym. Value Symbol's Name + Addend 00002f70 00000008 R_X86_64_RELATIVE 1000 00002f68 00000025 R_X86_64_IRELATIVE 1007 [hjl@gnu-cfl-2 tmpdir]$ Add -z report-relative-reloc to x86 ELF linker to report dynamic relative relocations: [hjl@gnu-cfl-2 tmpdir]$ ../ld-new -pie -melf32_x86_64 -z report-relative-reloc -o dump report-reloc-1.o dump: R_X86_64_IRELATIVE (offset: 0x00002f68, info: 0x00000025, addend: 0x00001007) against 'ifunc' for section '.data.rel.ro.local' in report-reloc-1.o dump: R_X86_64_RELATIVE (offset: 0x00002f70, info: 0x00000008, addend: 0x00001000) against '_start' for section '.data.rel.ro.local' in report-reloc-1.o [hjl@gnu-cfl-2 tmpdir]$ It can be used to map relative relocations to corresponding symbols. bfd/ * elf-linker-x86.h (elf_linker_x86_params): Add report_relative_reloc. * elf32-i386.c (elf_i386_relocate_section): Call _bfd_x86_elf_link_report_relative_reloc to report relative relocations for -z report-relative-reloc. (elf_i386_finish_dynamic_symbol): Likewse. * elf64-x86-64.c (elf_x86_64_relocate_section): Likewse. (elf_x86_64_finish_dynamic_symbol): Likewse. * elfxx-x86.c (_bfd_x86_elf_link_report_relative_reloc): New function. * elfxx-x86.h (_bfd_x86_elf_link_report_relative_reloc): New prototype. ld/ * NEWS: Mention -z report-relative-reloc. * ld.texi: Document -z report-relative-reloc. * emulparams/elf32_x86_64.sh: Source x86-report-relative.sh. * emulparams/elf_i386.sh: Likewse. * emulparams/elf_x86_64.sh: Likewse. * emulparams/x86-report-relative.sh: New file. * testsuite/ld-i386/report-reloc-1.d: Likewse. * testsuite/ld-i386/report-reloc-1.l: Likewse. * testsuite/ld-i386/report-reloc-1.s: Likewse. * testsuite/ld-x86-64/report-reloc-1-x32.d: Likewse. * testsuite/ld-x86-64/report-reloc-1.d: Likewse. * testsuite/ld-x86-64/report-reloc-1.l: Likewse. * testsuite/ld-x86-64/report-reloc-1.s: Likewse. * testsuite/ld-i386/i386.exp: Run report-reloc-1. * testsuite/ld-x86-64/x86-64.exp: Run report-reloc-1 and report-reloc-1-x32.
Diffstat (limited to 'bfd/elfxx-x86.c')
-rw-r--r--bfd/elfxx-x86.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/bfd/elfxx-x86.c b/bfd/elfxx-x86.c
index 3a0dffc..8cda8d2 100644
--- a/bfd/elfxx-x86.c
+++ b/bfd/elfxx-x86.c
@@ -1742,6 +1742,53 @@ _bfd_x86_elf_link_fixup_ifunc_symbol (struct bfd_link_info *info,
}
}
+/* Report relative relocation. */
+
+void
+_bfd_x86_elf_link_report_relative_reloc
+ (struct bfd_link_info *info, asection *asect,
+ struct elf_link_hash_entry *h, Elf_Internal_Sym *sym,
+ const char *reloc_name, const void *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)
+ abfd = info->output_bfd;
+ else
+ abfd = asect->owner;
+
+ if (h != NULL && h->root.root.string != NULL)
+ name = h->root.root.string;
+ 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);
+ }
+ else
+ info->callbacks->einfo
+ (_("%pB: %s (offset: 0x%s, info: 0x%s) against '%s' for section "
+ "'%pA' in %pB\n"),
+ info->output_bfd, reloc_name, r_offset, r_info, name,
+ asect, abfd);
+}
+
/* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
bfd_boolean