+2022-03-01 Di Chen <dichen@redhat.com>
+
+ * readelf.c (get_dyn_ents): New function.
+ (handle_dynamic): Use get_dyn_ents to get the actual number of
+ Dynamic entries in the section.
+
2022-03-27 Mark Wielaard <mark@klomp.org>
* addr2line.c: Replace error (EXIT_FAILURE, ...) with error_exit(...).
}
+static size_t
+get_dyn_ents (Elf_Data * dyn_data)
+{
+ GElf_Dyn *dyn;
+ size_t dyn_idx = 0;
+ do
+ {
+ GElf_Dyn dyn_mem;
+ dyn = gelf_getdyn(dyn_data, dyn_idx, &dyn_mem);
+ if (dyn != NULL)
+ ++dyn_idx;
+ }
+ while (dyn != NULL && dyn->d_tag != DT_NULL);
+
+ return dyn_idx;
+}
+
+
static void
handle_dynamic (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr)
{
Elf_Data *data;
size_t cnt;
size_t shstrndx;
- size_t sh_entsize;
+ size_t dyn_ents;
/* Get the data of the section. */
data = elf_getdata (scn, NULL);
if (data == NULL)
return;
+ /* Get the dynamic section entry number */
+ dyn_ents = get_dyn_ents (data);
+
/* Get the section header string table index. */
if (unlikely (elf_getshdrstrndx (ebl->elf, &shstrndx) < 0))
error_exit (0, _("cannot get section header string table index"));
- sh_entsize = gelf_fsize (ebl->elf, ELF_T_DYN, 1, EV_CURRENT);
-
glink = gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link), &glink_mem);
if (glink == NULL)
error_exit (0, _("invalid sh_link value in section %zu"),
\nDynamic segment contains %lu entry:\n Addr: %#0*" PRIx64 " Offset: %#08" PRIx64 " Link to section: [%2u] '%s'\n",
"\
\nDynamic segment contains %lu entries:\n Addr: %#0*" PRIx64 " Offset: %#08" PRIx64 " Link to section: [%2u] '%s'\n",
- shdr->sh_size / sh_entsize),
- (unsigned long int) (shdr->sh_size / sh_entsize),
+ dyn_ents),
+ (unsigned long int) dyn_ents,
class == ELFCLASS32 ? 10 : 18, shdr->sh_addr,
shdr->sh_offset,
(int) shdr->sh_link,
elf_strptr (ebl->elf, shstrndx, glink->sh_name));
fputs_unlocked (_(" Type Value\n"), stdout);
- for (cnt = 0; cnt < shdr->sh_size / sh_entsize; ++cnt)
+ for (cnt = 0; cnt < dyn_ents; ++cnt)
{
GElf_Dyn dynmem;
GElf_Dyn *dyn = gelf_getdyn (data, cnt, &dynmem);
+2022-03-01 Di Chen <dichen@redhat.com>
+
+ * alldts.c (dtflags): Put DT_NULL last.
+ * run-alldts.sh: NULL comes last.
+ * run-readelf-d.sh: Adjust Dynamic entries, remove DT_NULL
+ padding.
+
2022-04-14 Mark Wielaard <mark@klomp.org>
* run-debuginfod-federation-sqlite.sh: Don't try to corrupt
Dwelf_Strent *shstrtabse;
const Elf32_Sword dtflags[] =
{
- DT_NULL, DT_NEEDED, DT_PLTRELSZ, DT_PLTGOT,
+ DT_NEEDED, DT_PLTRELSZ, DT_PLTGOT,
DT_HASH, DT_STRTAB, DT_SYMTAB, DT_RELA,
DT_RELASZ, DT_RELAENT, DT_STRSZ, DT_SYMENT,
DT_INIT, DT_FINI, DT_SONAME, DT_RPATH,
DT_GNU_LIBLIST, DT_CONFIG, DT_DEPAUDIT, DT_AUDIT,
DT_PLTPAD, DT_MOVETAB, DT_SYMINFO, DT_RELACOUNT,
DT_RELCOUNT, DT_FLAGS_1, DT_VERDEF, DT_VERDEFNUM,
- DT_VERNEED, DT_VERNEEDNUM, DT_AUXILIARY, DT_FILTER
+ DT_VERNEED, DT_VERNEEDNUM, DT_AUXILIARY, DT_FILTER,
+ DT_NULL
};
const int ndtflags = sizeof (dtflags) / sizeof (dtflags[0]);
Dynamic segment contains 66 entries:
Addr: 0x000001a0 Offset: 0x000078 Link to section: [ 0] ''
Type Value
- NULL
NEEDED Shared library: [(null)]
PLTRELSZ 3735928559 (bytes)
PLTGOT 0xdeadbeef
VERNEEDNUM 3735928559
AUXILIARY 0xdeadbeef
FILTER 0xdeadbeef
+ NULL
EOF
exit 0
testrun_compare ${abs_top_builddir}/src/readelf -d testlib_dynseg.so <<\EOF
-Dynamic segment contains 28 entries:
+Dynamic segment contains 23 entries:
Addr: 0x00000000000017e0 Offset: 0x0007e0 Link to section: [ 3] '.dynstr'
Type Value
PLTGOT 0x00000000000019c8
VERNEED 0x0000000000000498
VERNEEDNUM 2
NULL
- NULL
- NULL
- NULL
- NULL
- NULL
EOF
exit 0