]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
readelf: Update "-D -r" to dump DT_RELR
authorH.J. Lu <hjl.tools@gmail.com>
Wed, 27 Aug 2025 20:17:07 +0000 (13:17 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Thu, 28 Aug 2025 01:07:50 +0000 (18:07 -0700)
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>
binutils/readelf.c
ld/testsuite/ld-i386/dt-relr-1c.d [new file with mode: 0644]
ld/testsuite/ld-i386/dt-relr-1d.d [new file with mode: 0644]
ld/testsuite/ld-i386/i386.exp
ld/testsuite/ld-x86-64/dt-relr-1c-x32.d [new file with mode: 0644]
ld/testsuite/ld-x86-64/dt-relr-1c.d [new file with mode: 0644]
ld/testsuite/ld-x86-64/dt-relr-1d-x32.d [new file with mode: 0644]
ld/testsuite/ld-x86-64/dt-relr-1d.d [new file with mode: 0644]
ld/testsuite/ld-x86-64/x86-64.exp

index bb81c824ac3b5b98217e8ebc20c47bdda1c75561..68e193415f2a69236c751c623b833f946cb23236 100644 (file)
@@ -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 (file)
index 0000000..b64860f
--- /dev/null
@@ -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 (file)
index 0000000..37df7c5
--- /dev/null
@@ -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
index 4ea46bbe90193d21c0a058c17b11940661649a2f..44ba418e5b5f536bb7cc09ee3ef3eca966f314a1 100644 (file)
@@ -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 (file)
index 0000000..7e3ce29
--- /dev/null
@@ -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 (file)
index 0000000..12fb99e
--- /dev/null
@@ -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 (file)
index 0000000..2327796
--- /dev/null
@@ -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 (file)
index 0000000..15b9f56
--- /dev/null
@@ -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
index 5b759d8a5d0f435617653acacecabbd0f6900b01..acdcbaf20a02910ff59afadd93e833a638148767 100644 (file)
@@ -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"