diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2025-08-27 13:17:07 -0700 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2025-08-27 18:07:50 -0700 |
commit | f83ec9ae4a854cc9ba453e88cc7621de5a7a5091 (patch) | |
tree | 03e1d3aee33a5bdfb6af351e208bf774e64860cc | |
parent | 83679675ce5d991f121262c7c786b1aa913404bb (diff) | |
download | binutils-f83ec9ae4a854cc9ba453e88cc7621de5a7a5091.zip binutils-f83ec9ae4a854cc9ba453e88cc7621de5a7a5091.tar.gz binutils-f83ec9ae4a854cc9ba453e88cc7621de5a7a5091.tar.bz2 |
readelf: Update "-D -r" to dump DT_RELR
1. Update dump_relr_relocations to take relr_size, relr_entsize and
relr_offset, instead of a pointer to Elf_Internal_Shdr, as function
arguments.
2. Update process_relocs to call dump_relr_relocations if relocation
type is reltype_relr.
binutils/
PR binutils/33328
* readelf.c (dump_relr_relocations): Replace a pointer to
Elf_Internal_Shdr argument with relr_size, relr_entsize and
relr_offset.
(display_relocations): Update the dump_relr_relocations call.
(process_relocs): Call dump_relr_relocations if relocation type
is reltype_relr.
ld/
PR binutils/33328
* testsuite/ld-i386/dt-relr-1c.d: New file.
* testsuite/ld-i386/dt-relr-1d.d: Likewise.
* testsuite/ld-x86-64/dt-relr-1c-x32.d: Likewise.
* testsuite/ld-x86-64/dt-relr-1c.d: Likewise.
* testsuite/ld-x86-64/dt-relr-1d-x32.d: Likewise.
* testsuite/ld-x86-64/dt-relr-1d.d: Likewise.
* testsuite/ld-i386/i386.exp: Run PR binutils/33328 tests.
* testsuite/ld-x86-64/x86-64.exp: Likewise.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
-rw-r--r-- | binutils/readelf.c | 106 | ||||
-rw-r--r-- | ld/testsuite/ld-i386/dt-relr-1c.d | 26 | ||||
-rw-r--r-- | ld/testsuite/ld-i386/dt-relr-1d.d | 26 | ||||
-rw-r--r-- | ld/testsuite/ld-i386/i386.exp | 2 | ||||
-rw-r--r-- | ld/testsuite/ld-x86-64/dt-relr-1c-x32.d | 26 | ||||
-rw-r--r-- | ld/testsuite/ld-x86-64/dt-relr-1c.d | 26 | ||||
-rw-r--r-- | ld/testsuite/ld-x86-64/dt-relr-1d-x32.d | 26 | ||||
-rw-r--r-- | ld/testsuite/ld-x86-64/dt-relr-1d.d | 26 | ||||
-rw-r--r-- | ld/testsuite/ld-x86-64/x86-64.exp | 4 |
9 files changed, 222 insertions, 46 deletions
diff --git a/binutils/readelf.c b/binutils/readelf.c index bb81c82..68e1934 100644 --- a/binutils/readelf.c +++ b/binutils/readelf.c @@ -1832,7 +1832,9 @@ count_relr_relocations (Filedata * filedata, static bool dump_relr_relocations (Filedata * filedata, - Elf_Internal_Shdr * section, + uint64_t relr_size, + int relr_entsize, + uint64_t relr_offset, Elf_Internal_Sym * symtab, uint64_t nsyms, char * strtab, @@ -1840,9 +1842,6 @@ dump_relr_relocations (Filedata * filedata, { uint64_t * relrs; uint64_t nentries, i; - uint64_t relr_size = section->sh_size; - int relr_entsize = section->sh_entsize; - uint64_t relr_offset = section->sh_offset; uint64_t where = 0; int num_bits_in_entry; @@ -9522,7 +9521,10 @@ display_relocations (Elf_Internal_Shdr * section, bool res; if (rel_type == reltype_relr) - res = dump_relr_relocations (filedata, section, symtab, nsyms, strtab, strtablen); + res = dump_relr_relocations (filedata, section->sh_size, + section->sh_entsize, + section->sh_offset, + symtab, nsyms, strtab, strtablen); else res = dump_relocations (filedata, rel_offset, rel_size, symtab, nsyms, strtab, strtablen, @@ -9556,55 +9558,67 @@ process_relocs (Filedata * filedata) for (i = 0; i < ARRAY_SIZE (dynamic_relocations); i++) { + rel_size = filedata->dynamic_info[dynamic_relocations [i].size]; + + if (!rel_size) + continue; + + has_dynamic_reloc = true; + rel_type = dynamic_relocations [i].rel_type; name = dynamic_relocations [i].name; - rel_size = filedata->dynamic_info[dynamic_relocations [i].size]; rel_offset = filedata->dynamic_info[dynamic_relocations [i].reloc]; - if (rel_size) - has_dynamic_reloc = true; - if (rel_type == reltype_unknown) { - if (dynamic_relocations [i].reloc == DT_JMPREL) - switch (filedata->dynamic_info[DT_PLTREL]) - { - case DT_REL: - rel_type = reltype_rel; - break; - case DT_RELA: - rel_type = reltype_rela; - break; - } - } - - if (rel_size) - { - if (filedata->is_separate) - printf - (_("\nIn linked file '%s' section '%s' at offset %#" PRIx64 - " contains %" PRId64 " bytes:\n"), - filedata->file_name, name, rel_offset, rel_size); - else - printf - (_("\n'%s' relocation section at offset %#" PRIx64 - " contains %" PRId64 " bytes:\n"), - name, rel_offset, rel_size); - - dump_relocations (filedata, - offset_from_vma (filedata, rel_offset, rel_size), - rel_size, - filedata->dynamic_symbols, - filedata->num_dynamic_syms, - filedata->dynamic_strings, - filedata->dynamic_strings_length, - rel_type, true /* is_dynamic */); + if (dynamic_relocations [i].reloc != DT_JMPREL) + abort (); + switch (filedata->dynamic_info[DT_PLTREL]) + { + case DT_REL: + rel_type = reltype_rel; + break; + case DT_RELA: + rel_type = reltype_rela; + break; + } } - } - if (is_ia64_vms (filedata)) - if (process_ia64_vms_dynamic_relocs (filedata)) - has_dynamic_reloc = true; + if (filedata->is_separate) + printf + (_("\nIn linked file '%s' section '%s' at offset %#" PRIx64 + " contains %" PRId64 " bytes:\n"), + filedata->file_name, name, rel_offset, rel_size); + else + printf + (_("\n'%s' relocation section at offset %#" PRIx64 + " contains %" PRId64 " bytes:\n"), + name, rel_offset, rel_size); + + if (rel_type == reltype_relr) + dump_relr_relocations (filedata, + filedata->dynamic_info[DT_RELRSZ], + filedata->dynamic_info[DT_RELRENT], + filedata->dynamic_info[DT_RELR], + filedata->dynamic_symbols, + filedata->num_dynamic_syms, + filedata->dynamic_strings, + filedata->dynamic_strings_length); + else + dump_relocations (filedata, + offset_from_vma (filedata, rel_offset, + rel_size), + rel_size, + filedata->dynamic_symbols, + filedata->num_dynamic_syms, + filedata->dynamic_strings, + filedata->dynamic_strings_length, + rel_type, true /* is_dynamic */); + } + + if (is_ia64_vms (filedata) + && process_ia64_vms_dynamic_relocs (filedata)) + has_dynamic_reloc = true; if (! has_dynamic_reloc) { diff --git a/ld/testsuite/ld-i386/dt-relr-1c.d b/ld/testsuite/ld-i386/dt-relr-1c.d new file mode 100644 index 0000000..b64860f --- /dev/null +++ b/ld/testsuite/ld-i386/dt-relr-1c.d @@ -0,0 +1,26 @@ +#source: dt-relr-1.s +#as: --32 +#ld: -shared -melf_i386 $DT_RELR_LDFLAGS --hash-style=sysv +#readelf: -D -r -s --wide +#target: x86_64-*-linux* i?86-*-linux-gnu i?86-*-gnu* + +'REL' relocation section at offset [0x0-9a-f]+ contains 16 bytes: + +Offset +Info +Type +Sym. Value +Symbol's Name +[0-9a-f]+ +[0-9a-f]+ +R_386_32 +0+ +data1 +[0-9a-f]+ +[0-9a-f]+ +R_386_32 +0+ +data1 + +'RELR' relocation section at offset 0x[a-f0-9]+ contains 8 bytes: +#... +0000: +[0-9a-f]+ [0-9a-f]+ +.* +0001: +[0-9a-f]+ [0-9a-f]+ +.* + +[0-9a-f]+ +.* +#... +'PLT' relocation section at offset 0x[0-9a-f]+ contains 8 bytes: + +Offset +Info +Type +Sym. Value +Symbol's Name +[0-9a-f]+ +[0-9a-f]+ +R_386_JUMP_SLOT +0+ +func1 + +Symbol table for image contains [0-9]+ entries: + Num: Value Size Type Bind Vis Ndx Name +#... + +[0-9]+: 0+ +0 +NOTYPE +GLOBAL +DEFAULT +UND +func1 +#pass diff --git a/ld/testsuite/ld-i386/dt-relr-1d.d b/ld/testsuite/ld-i386/dt-relr-1d.d new file mode 100644 index 0000000..37df7c5 --- /dev/null +++ b/ld/testsuite/ld-i386/dt-relr-1d.d @@ -0,0 +1,26 @@ +#source: dt-relr-1.s +#as: --32 +#ld: -shared -melf_i386 $DT_RELR_LDFLAGS -z nocombreloc --hash-style=sysv +#readelf: -D -r -s --wide +#target: x86_64-*-linux* i?86-*-linux-gnu i?86-*-gnu* + +'REL' relocation section at offset [0x0-9a-f]+ contains 16 bytes: + +Offset +Info +Type +Sym. Value +Symbol's Name +[0-9a-f]+ +[0-9a-f]+ +R_386_32 +0+ +data1 +[0-9a-f]+ +[0-9a-f]+ +R_386_32 +0+ +data1 + +'RELR' relocation section at offset 0x[a-f0-9]+ contains 8 bytes: +#... +0000: +[0-9a-f]+ [0-9a-f]+ +.* +0001: +[0-9a-f]+ [0-9a-f]+ +.* + +[0-9a-f]+ +.* +#... +'PLT' relocation section at offset 0x[0-9a-f]+ contains 8 bytes: + +Offset +Info +Type +Sym. Value +Symbol's Name +[0-9a-f]+ +[0-9a-f]+ +R_386_JUMP_SLOT +0+ +func1 + +Symbol table for image contains [0-9]+ entries: + Num: Value Size Type Bind Vis Ndx Name +#... + +[0-9]+: 0+ +0 +NOTYPE +GLOBAL +DEFAULT +UND +func1 +#pass diff --git a/ld/testsuite/ld-i386/i386.exp b/ld/testsuite/ld-i386/i386.exp index 4ea46bb..44ba418 100644 --- a/ld/testsuite/ld-i386/i386.exp +++ b/ld/testsuite/ld-i386/i386.exp @@ -515,6 +515,8 @@ run_dump_test "pr27491-3" run_dump_test "pr27491-4" run_dump_test "dt-relr-1a" run_dump_test "dt-relr-1b" +run_dump_test "dt-relr-1c" +run_dump_test "dt-relr-1d" run_dump_test "pr28870" run_dump_test "pr28894" run_dump_test "pr30787" diff --git a/ld/testsuite/ld-x86-64/dt-relr-1c-x32.d b/ld/testsuite/ld-x86-64/dt-relr-1c-x32.d new file mode 100644 index 0000000..7e3ce293 --- /dev/null +++ b/ld/testsuite/ld-x86-64/dt-relr-1c-x32.d @@ -0,0 +1,26 @@ +#source: dt-relr-1.s +#as: --x32 +#ld: -shared -melf32_x86_64 $DT_RELR_LDFLAGS -z nomark-plt --hash-style=sysv +#readelf: -D -r -s --wide +#target: x86_64-*-linux* + +'RELA' relocation section at offset 0x[0-9a-f]+ contains 24 bytes: + +Offset +Info +Type +Sym. Value +Symbol's Name \+ Addend +[0-9a-f]+ +[0-9a-f]+ +R_X86_64_32 +0+ +data1 \+ 0 +[0-9a-f]+ +[0-9a-f]+ +R_X86_64_32 +0+ +data1 \+ 0 + +'RELR' relocation section at offset 0x[a-f0-9]+ contains 8 bytes: +#... +0000: +[0-9a-f]+ [0-9a-f]+ +.* +0001: +[0-9a-f]+ [0-9a-f]+ +.* + +[0-9a-f]+ +.* +#... +'PLT' relocation section at offset 0x[0-9a-f]+ contains 12 bytes: + +Offset +Info +Type +Sym. Value +Symbol's Name \+ Addend +[0-9a-f]+ +[0-9a-f]+ +R_X86_64_JUMP_SLOT +0+ +func1 \+ 0 + +Symbol table for image contains [0-9]+ entries: + +Num: +Value +Size Type +Bind +Vis +Ndx Name +#... + +[0-9]+: 0+ +0 +NOTYPE +GLOBAL +DEFAULT +UND +func1 +#pass diff --git a/ld/testsuite/ld-x86-64/dt-relr-1c.d b/ld/testsuite/ld-x86-64/dt-relr-1c.d new file mode 100644 index 0000000..12fb99e --- /dev/null +++ b/ld/testsuite/ld-x86-64/dt-relr-1c.d @@ -0,0 +1,26 @@ +#source: dt-relr-1.s +#as: --64 +#ld: -shared -melf_x86_64 $DT_RELR_LDFLAGS -z nomark-plt --hash-style=sysv +#readelf: -D -r -s --wide +#target: x86_64-*-linux* + +'RELA' relocation section at offset 0x[0-9a-f]+ contains 48 bytes: + +Offset +Info +Type +Symbol's Value +Symbol's Name \+ Addend +[0-9a-f]+ +[0-9a-f]+ +R_X86_64_64 +0+ +data1 \+ 0 +[0-9a-f]+ +[0-9a-f]+ +R_X86_64_64 +0+ +data1 \+ 0 + +'RELR' relocation section at offset 0x[a-f0-9]+ contains 16 bytes: +#... +0000: +[0-9a-f]+ [0-9a-f]+ +.* +0001: +[0-9a-f]+ [0-9a-f]+ +.* + +[0-9a-f]+ +.* +#... +'PLT' relocation section at offset 0x[0-9a-f]+ contains 24 bytes: + +Offset +Info +Type +Symbol's Value +Symbol's Name \+ Addend +[0-9a-f]+ +[0-9a-f]+ +R_X86_64_JUMP_SLOT +0+ +func1 \+ 0 + +Symbol table for image contains [0-9]+ entries: + +Num: +Value +Size Type +Bind +Vis +Ndx Name +#... + +[0-9]+: 0+ +0 +NOTYPE +GLOBAL +DEFAULT +UND +func1 +#pass diff --git a/ld/testsuite/ld-x86-64/dt-relr-1d-x32.d b/ld/testsuite/ld-x86-64/dt-relr-1d-x32.d new file mode 100644 index 0000000..2327796 --- /dev/null +++ b/ld/testsuite/ld-x86-64/dt-relr-1d-x32.d @@ -0,0 +1,26 @@ +#source: dt-relr-1.s +#as: --x32 +#ld: -shared -melf32_x86_64 $DT_RELR_LDFLAGS -z nocombreloc -z nomark-plt --hash-style=sysv +#readelf: -D -r -s --wide +#target: x86_64-*-linux* + +'RELA' relocation section at offset 0x[0-9a-f]+ contains 24 bytes: + +Offset +Info +Type +Sym. Value +Symbol's Name \+ Addend +[0-9a-f]+ +[0-9a-f]+ +R_X86_64_32 +0+ +data1 \+ 0 +[0-9a-f]+ +[0-9a-f]+ +R_X86_64_32 +0+ +data1 \+ 0 + +'RELR' relocation section at offset 0x[a-f0-9]+ contains 8 bytes: +#... +0000: +[0-9a-f]+ [0-9a-f]+ +.* +0001: +[0-9a-f]+ [0-9a-f]+ +.* + +[0-9a-f]+ +.* +#... +'PLT' relocation section at offset 0x[0-9a-f]+ contains 12 bytes: + +Offset +Info +Type +Sym. Value +Symbol's Name \+ Addend +[0-9a-f]+ +[0-9a-f]+ +R_X86_64_JUMP_SLOT +0+ +func1 \+ 0 + +Symbol table for image contains [0-9]+ entries: + +Num: +Value +Size Type +Bind +Vis +Ndx Name +#... + +[0-9]+: 0+ +0 +NOTYPE +GLOBAL +DEFAULT +UND +func1 +#pass diff --git a/ld/testsuite/ld-x86-64/dt-relr-1d.d b/ld/testsuite/ld-x86-64/dt-relr-1d.d new file mode 100644 index 0000000..15b9f56 --- /dev/null +++ b/ld/testsuite/ld-x86-64/dt-relr-1d.d @@ -0,0 +1,26 @@ +#source: dt-relr-1.s +#as: --64 +#ld: -shared -melf_x86_64 $DT_RELR_LDFLAGS -z nocombreloc -z nomark-plt --hash-style=sysv +#readelf: -D -r -s --wide +#target: x86_64-*-linux* + +'RELA' relocation section at offset 0x[0-9a-f]+ contains 48 bytes: + +Offset +Info +Type +Symbol's Value +Symbol's Name \+ Addend +[0-9a-f]+ +[0-9a-f]+ +R_X86_64_64 +0+ +data1 \+ 0 +[0-9a-f]+ +[0-9a-f]+ +R_X86_64_64 +0+ +data1 \+ 0 + +'RELR' relocation section at offset 0x[a-f0-9]+ contains 16 bytes: +#... +0000: +[0-9a-f]+ [0-9a-f]+ +.* +0001: +[0-9a-f]+ [0-9a-f]+ +.* + +[0-9a-f]+ +.* +#... +'PLT' relocation section at offset 0x[0-9a-f]+ contains 24 bytes: + +Offset +Info +Type +Symbol's Value +Symbol's Name \+ Addend +[0-9a-f]+ +[0-9a-f]+ +R_X86_64_JUMP_SLOT +0+ +func1 \+ 0 + +Symbol table for image contains [0-9]+ entries: + +Num: +Value +Size Type +Bind +Vis +Ndx Name +#... + +[0-9]+: 0+ +0 +NOTYPE +GLOBAL +DEFAULT +UND +func1 +#pass diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp index 5b759d8..acdcbaf 100644 --- a/ld/testsuite/ld-x86-64/x86-64.exp +++ b/ld/testsuite/ld-x86-64/x86-64.exp @@ -534,6 +534,10 @@ run_dump_test "dt-relr-1a" run_dump_test "dt-relr-1a-x32" run_dump_test "dt-relr-1b" run_dump_test "dt-relr-1b-x32" +run_dump_test "dt-relr-1c" +run_dump_test "dt-relr-1c-x32" +run_dump_test "dt-relr-1d" +run_dump_test "dt-relr-1d-x32" run_dump_test "pr30787" run_dump_test "pr31047" run_dump_test "pr31047-x32" |