static uint64_t
count_relr_relocations (Filedata * filedata,
- Elf_Internal_Shdr * section)
+ Elf_Internal_Shdr * section,
+ uint64_t ** relrs_p)
{
uint64_t * relrs;
uint64_t nentries;
if (nentries == 0)
return 0;
- /* FIXME: This call to get_data duplicates one that follows in
- dump_relr_relocations(). They could be combined into just
- one call. */
relrs = get_data (NULL, filedata, section->sh_offset, 1,
section->sh_size, _("RELR relocation data"));
if (relrs == NULL)
}
}
- free (relrs);
+ *relrs_p = relrs;
+
return count;
}
uint64_t relr_size,
int relr_entsize,
uint64_t relr_offset,
- Elf_Internal_Sym * symtab,
+ uint64_t * relrs,
+ const Elf_Internal_Sym * symtab_p,
uint64_t nsyms,
char * strtab,
uint64_t strtablen,
bool dump_reloc)
{
- uint64_t * relrs;
uint64_t nentries, i;
uint64_t where = 0;
int num_bits_in_entry;
return false;
}
- relrs = get_data (NULL, filedata, relr_offset, 1, relr_size, _("RELR relocation data"));
if (relrs == NULL)
- return false;
+ {
+ relrs = get_data (NULL, filedata, relr_offset, 1, relr_size,
+ _("RELR relocation data"));
+ if (relrs == NULL)
+ return false;
+ }
/* Paranoia. */
if (strtab == NULL)
strtablen = 0;
- if (symtab == NULL)
+ if (symtab_p == NULL)
nsyms = 0;
const char *rtype = NULL;
break;
}
- if (symtab != NULL)
+ Elf_Internal_Sym *symtab = NULL;
+ if (symtab_p != NULL)
{
/* Symbol tables are not sorted on address, but we want a quick lookup
for the symbol associated with each address computed below, so sort
- the table then filter out unwanted entries. FIXME: This assumes that
- the symbol table will not be used later on for some other purpose. */
+ the table then filter out unwanted entries. */
+ size_t sz = nsyms * sizeof (*symtab);
+ symtab = xmemdup (symtab_p, sz, sz);
qsort (symtab, nsyms, sizeof (Elf_Internal_Sym), symcmp);
nsyms = filter_display_syms (filedata, symtab, nsyms, strtab, strtablen);
}
}
}
+ free (symtab);
free (relrs);
return true;
}
uint64_t rel_offset = section->sh_offset;
uint64_t num_rela = rel_size / section->sh_entsize;
uint64_t num_reloc;
+ uint64_t *relrs = NULL;
if (rel_type == reltype_relr)
{
the number of words in the compressed RELR format. So also provide
the number of locations affected. */
- num_reloc = count_relr_relocations (filedata, section);
+ num_reloc = count_relr_relocations (filedata, section, &relrs);
if (dump_reloc)
{
bool res;
if (rel_type == reltype_relr)
- res = dump_relr_relocations (filedata, section->sh_size,
- section->sh_entsize,
- section->sh_offset,
- symtab, nsyms, strtab, strtablen,
- dump_reloc);
+ {
+ res = dump_relr_relocations (filedata, section->sh_size,
+ section->sh_entsize,
+ section->sh_offset,
+ relrs,
+ symtab, nsyms, strtab, strtablen,
+ dump_reloc);
+ /* RELRS has been freed by dump_relr_relocations. */
+ relrs = NULL;
+ }
else
res = dump_relocations (filedata, rel_offset, rel_size,
symtab, nsyms, strtab, strtablen,
filedata->dynamic_info[DT_RELRSZ],
filedata->dynamic_info[DT_RELRENT],
filedata->dynamic_info[DT_RELR],
+ NULL,
filedata->dynamic_symbols,
filedata->num_dynamic_syms,
filedata->dynamic_strings,
--- /dev/null
+#source: dt-relr-2.s
+#as: --32
+#ld: -shared -melf_i386 $DT_RELR_LDFLAGS --hash-style=sysv
+#readelf: -D -r --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 16 bytes:
+ +Offset +Info +Type +Sym. Value +Symbol's Name
+[0-9a-f]+ +[0-9a-f]+ +R_386_JUMP_SLOT +[0-9a-f]+ +func1
+[0-9a-f]+ +[0-9a-f]+ +R_386_JUMP_SLOT +[0-9a-f]+ +func2
--- /dev/null
+#source: dt-relr-2.s
+#as: --x32
+#ld: -shared -melf32_x86_64 $DT_RELR_LDFLAGS -z nomark-plt --hash-style=sysv
+#readelf: -D -r --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 24 bytes:
+ +Offset +Info +Type +Sym. Value +Symbol's Name \+ Addend
+[0-9a-f]+ +[0-9a-f]+ +R_X86_64_JUMP_SLOT +[0-9a-f]+ +func1 \+ 0
+[0-9a-f]+ +[0-9a-f]+ +R_X86_64_JUMP_SLOT +[0-9a-f]+ +func2 \+ 0
--- /dev/null
+#source: dt-relr-2.s
+#as: --64
+#ld: -shared -melf_x86_64 $DT_RELR_LDFLAGS -z nomark-plt --hash-style=sysv
+#readelf: -D -r --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 48 bytes:
+ +Offset +Info +Type +Symbol's Value +Symbol's Name \+ Addend
+[0-9a-f]+ +[0-9a-f]+ +R_X86_64_JUMP_SLOT +[0-9a-f]+ +func1 \+ 0
+[0-9a-f]+ +[0-9a-f]+ +R_X86_64_JUMP_SLOT +[0-9a-f]+ +func2 \+ 0