diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2021-01-15 18:06:48 -0800 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2021-01-15 18:07:07 -0800 |
commit | 68b007788a6cc5376708af42bc220f540e8c4b8a (patch) | |
tree | ea89e2a6a9e242932f93752ba6df8c19a15caf79 /ld | |
parent | ad92f33d386e050304bf5986f28071ede9dd2284 (diff) | |
download | gdb-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 'ld')
-rw-r--r-- | ld/ChangeLog | 19 | ||||
-rw-r--r-- | ld/NEWS | 3 | ||||
-rw-r--r-- | ld/emulparams/elf32_x86_64.sh | 1 | ||||
-rw-r--r-- | ld/emulparams/elf_i386.sh | 1 | ||||
-rw-r--r-- | ld/emulparams/elf_x86_64.sh | 1 | ||||
-rw-r--r-- | ld/emulparams/x86-report-relative.sh | 11 | ||||
-rw-r--r-- | ld/ld.texi | 4 | ||||
-rw-r--r-- | ld/testsuite/ld-i386/i386.exp | 1 | ||||
-rw-r--r-- | ld/testsuite/ld-i386/report-reloc-1.d | 10 | ||||
-rw-r--r-- | ld/testsuite/ld-i386/report-reloc-1.l | 2 | ||||
-rw-r--r-- | ld/testsuite/ld-i386/report-reloc-1.s | 12 | ||||
-rw-r--r-- | ld/testsuite/ld-x86-64/report-reloc-1-x32.d | 10 | ||||
-rw-r--r-- | ld/testsuite/ld-x86-64/report-reloc-1.d | 10 | ||||
-rw-r--r-- | ld/testsuite/ld-x86-64/report-reloc-1.l | 2 | ||||
-rw-r--r-- | ld/testsuite/ld-x86-64/report-reloc-1.s | 12 | ||||
-rw-r--r-- | ld/testsuite/ld-x86-64/x86-64.exp | 2 |
16 files changed, 101 insertions, 0 deletions
diff --git a/ld/ChangeLog b/ld/ChangeLog index c412eb6..6e53414 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,22 @@ +2021-01-15 H.J. Lu <hongjiu.lu@intel.com> + + * 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. + 2021-01-16 Alan Modra <amodra@gmail.com> PR 26002 @@ -1,5 +1,8 @@ -*- text -*- +* Add -z report-relative-reloc to x86 ELF linker to report dynamic + relative relocations. + Changes in 2.36: * Add libdep plugin, for linking dependencies of static libraries that diff --git a/ld/emulparams/elf32_x86_64.sh b/ld/emulparams/elf32_x86_64.sh index 0d7c714..ac0a7aa 100644 --- a/ld/emulparams/elf32_x86_64.sh +++ b/ld/emulparams/elf32_x86_64.sh @@ -4,6 +4,7 @@ source_sh ${srcdir}/emulparams/dynamic_undefined_weak.sh source_sh ${srcdir}/emulparams/reloc_overflow.sh source_sh ${srcdir}/emulparams/call_nop.sh source_sh ${srcdir}/emulparams/cet.sh +source_sh ${srcdir}/emulparams/x86-report-relative.sh source_sh ${srcdir}/emulparams/x86-64-level.sh source_sh ${srcdir}/emulparams/static.sh SCRIPT_NAME=elf diff --git a/ld/emulparams/elf_i386.sh b/ld/emulparams/elf_i386.sh index 741633f..98532e5 100644 --- a/ld/emulparams/elf_i386.sh +++ b/ld/emulparams/elf_i386.sh @@ -3,6 +3,7 @@ source_sh ${srcdir}/emulparams/extern_protected_data.sh source_sh ${srcdir}/emulparams/dynamic_undefined_weak.sh source_sh ${srcdir}/emulparams/call_nop.sh source_sh ${srcdir}/emulparams/cet.sh +source_sh ${srcdir}/emulparams/x86-report-relative.sh source_sh ${srcdir}/emulparams/x86-64-level.sh source_sh ${srcdir}/emulparams/static.sh SCRIPT_NAME=elf diff --git a/ld/emulparams/elf_x86_64.sh b/ld/emulparams/elf_x86_64.sh index 664ff18..6e31d22 100644 --- a/ld/emulparams/elf_x86_64.sh +++ b/ld/emulparams/elf_x86_64.sh @@ -4,6 +4,7 @@ source_sh ${srcdir}/emulparams/dynamic_undefined_weak.sh source_sh ${srcdir}/emulparams/reloc_overflow.sh source_sh ${srcdir}/emulparams/call_nop.sh source_sh ${srcdir}/emulparams/cet.sh +source_sh ${srcdir}/emulparams/x86-report-relative.sh source_sh ${srcdir}/emulparams/x86-64-level.sh source_sh ${srcdir}/emulparams/x86-64-lam.sh source_sh ${srcdir}/emulparams/static.sh diff --git a/ld/emulparams/x86-report-relative.sh b/ld/emulparams/x86-report-relative.sh new file mode 100644 index 0000000..426bb8b --- /dev/null +++ b/ld/emulparams/x86-report-relative.sh @@ -0,0 +1,11 @@ +PARSE_AND_LIST_OPTIONS_X86_REPORT_RELATIVE=' + fprintf (file, _("\ + -z report-relative-reloc Report relative relocations\n")); +' +PARSE_AND_LIST_ARGS_CASE_Z_X86_REPORT_RELATIVE=' + else if (strcmp (optarg, "report-relative-reloc") == 0) + params.report_relative_reloc = 1; +' + +PARSE_AND_LIST_OPTIONS="$PARSE_AND_LIST_OPTIONS $PARSE_AND_LIST_OPTIONS_X86_REPORT_RELATIVE" +PARSE_AND_LIST_ARGS_CASE_Z="$PARSE_AND_LIST_ARGS_CASE_Z $PARSE_AND_LIST_ARGS_CASE_Z_X86_REPORT_RELATIVE" @@ -1426,6 +1426,10 @@ relocation, if supported. Specifying @samp{common-page-size} smaller than the system page size will render this protection ineffective. Don't create an ELF @code{PT_GNU_RELRO} segment if @samp{norelro}. +@item report-relative-reloc +Report dynamic relative relocations generated by linker. Supported for +Linux/i386 and Linux/x86_64. + @item separate-code @itemx noseparate-code Create separate code @code{PT_LOAD} segment header in the object. This diff --git a/ld/testsuite/ld-i386/i386.exp b/ld/testsuite/ld-i386/i386.exp index 655f83d..f3e62a4 100644 --- a/ld/testsuite/ld-i386/i386.exp +++ b/ld/testsuite/ld-i386/i386.exp @@ -506,6 +506,7 @@ run_dump_test "pr18815" run_dump_test "pr19939a" run_dump_test "pr19939b" run_dump_test "tlsdesc2" +run_dump_test "report-reloc-1" proc undefined_weak {cflags ldflags} { set testname "Undefined weak symbol" diff --git a/ld/testsuite/ld-i386/report-reloc-1.d b/ld/testsuite/ld-i386/report-reloc-1.d new file mode 100644 index 0000000..51fbbd8 --- /dev/null +++ b/ld/testsuite/ld-i386/report-reloc-1.d @@ -0,0 +1,10 @@ +#source: report-reloc-1.s +#as: --32 +#ld: -pie -melf_i386 -z report-relative-reloc +#warning_output: report-reloc-1.l +#readelf: -r --wide + +Relocation section '.rel.dyn' at offset 0x[0-9a-f]+ contains 2 entries: + +Offset +Info +Type +Sym.* Value +Symbol's Name +[0-9a-f]+ +[0-9a-f]+ +R_386_RELATIVE + +[0-9a-f]+ +[0-9a-f]+ +R_386_IRELATIVE + diff --git a/ld/testsuite/ld-i386/report-reloc-1.l b/ld/testsuite/ld-i386/report-reloc-1.l new file mode 100644 index 0000000..a0293bc --- /dev/null +++ b/ld/testsuite/ld-i386/report-reloc-1.l @@ -0,0 +1,2 @@ +tmpdir/dump: R_386_IRELATIVE \(offset: 0x0+2000, info: 0x0+2a\) against 'ifunc' for section '.data.rel.ro.local' in tmpdir/report-reloc-1.o +tmpdir/dump: R_386_RELATIVE \(offset: 0x0+2004, info: 0x0+8\) against '_start' for section '.data.rel.ro.local' in tmpdir/report-reloc-1.o diff --git a/ld/testsuite/ld-i386/report-reloc-1.s b/ld/testsuite/ld-i386/report-reloc-1.s new file mode 100644 index 0000000..689cb69 --- /dev/null +++ b/ld/testsuite/ld-i386/report-reloc-1.s @@ -0,0 +1,12 @@ + .text + .globl _start + .type ifunc, @gnu_indirect_function +_start: + lea .Ljmp@GOTOFF(%ebx), %eax +ifunc: + jmp *(%eax) + .section .data.rel.ro.local,"aw",@progbits + .align 4 +.Ljmp: + .long ifunc + .long _start diff --git a/ld/testsuite/ld-x86-64/report-reloc-1-x32.d b/ld/testsuite/ld-x86-64/report-reloc-1-x32.d new file mode 100644 index 0000000..c66f956 --- /dev/null +++ b/ld/testsuite/ld-x86-64/report-reloc-1-x32.d @@ -0,0 +1,10 @@ +#source: report-reloc-1.s +#as: --x32 +#ld: -pie -melf32_x86_64 -z report-relative-reloc +#warning_output: report-reloc-1.l +#readelf: -r --wide + +Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 2 entries: + +Offset +Info +Type +Sym.* Value +Symbol's Name \+ Addend +[0-9a-f]+ +[0-9a-f]+ +R_X86_64_RELATIVE +[0-9a-f]+ +[0-9a-f]+ +[0-9a-f]+ +R_X86_64_IRELATIVE +[0-9a-f]+ diff --git a/ld/testsuite/ld-x86-64/report-reloc-1.d b/ld/testsuite/ld-x86-64/report-reloc-1.d new file mode 100644 index 0000000..1b5f91f --- /dev/null +++ b/ld/testsuite/ld-x86-64/report-reloc-1.d @@ -0,0 +1,10 @@ +#source: report-reloc-1.s +#as: --64 +#ld: -pie -melf_x86_64 -z report-relative-reloc +#warning_output: report-reloc-1.l +#readelf: -r --wide + +Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 2 entries: + +Offset +Info +Type +Sym.* Value +Symbol's Name \+ Addend +[0-9a-f]+ +[0-9a-f]+ +R_X86_64_RELATIVE +[0-9a-f]+ +[0-9a-f]+ +[0-9a-f]+ +R_X86_64_IRELATIVE +[0-9a-f]+ diff --git a/ld/testsuite/ld-x86-64/report-reloc-1.l b/ld/testsuite/ld-x86-64/report-reloc-1.l new file mode 100644 index 0000000..669dff4 --- /dev/null +++ b/ld/testsuite/ld-x86-64/report-reloc-1.l @@ -0,0 +1,2 @@ +tmpdir/dump: R_X86_64_IRELATIVE \(offset: 0x0+2000, info: 0x0+25, addend: 0x0+1007\) against 'ifunc' for section '.data.rel.ro.local' in tmpdir/report-reloc-1.o +tmpdir/dump: R_X86_64_RELATIVE \(offset: 0x0+2008, info: 0x0+8, addend: 0x0+1000\) 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.s b/ld/testsuite/ld-x86-64/report-reloc-1.s new file mode 100644 index 0000000..8a5809a --- /dev/null +++ b/ld/testsuite/ld-x86-64/report-reloc-1.s @@ -0,0 +1,12 @@ + .text + .globl _start + .type ifunc, @gnu_indirect_function +_start: + lea .Ljmp(%rip), %rax +ifunc: + jmp *(%rax) + .section .data.rel.ro.local,"aw",@progbits + .align 8 +.Ljmp: + .quad ifunc + .quad _start diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp index 83fdaa7..662d349 100644 --- a/ld/testsuite/ld-x86-64/x86-64.exp +++ b/ld/testsuite/ld-x86-64/x86-64.exp @@ -677,6 +677,8 @@ run_dump_test "pr26939" run_dump_test "pr26939-x32" run_dump_test "pr27016a" run_dump_test "pr27016b" +run_dump_test "report-reloc-1" +run_dump_test "report-reloc-1-x32" proc undefined_weak {cflags ldflags} { set testname "Undefined weak symbol" |