bool implicit;
};
-/* Number of sections in the file. */
+/* Numbers of sections and program headers in the file. */
static size_t shnum;
+static size_t phnum;
/* Declarations of local functions. */
static void print_shdr (Ebl *ebl, GElf_Ehdr *ehdr);
static void print_phdr (Ebl *ebl, GElf_Ehdr *ehdr);
static void print_scngrp (Ebl *ebl);
-static void print_dynamic (Ebl *ebl, GElf_Ehdr *ehdr);
+static void print_dynamic (Ebl *ebl);
static void print_relocs (Ebl *ebl, GElf_Ehdr *ehdr);
static void handle_relocs_rel (Ebl *ebl, GElf_Ehdr *ehdr, Elf_Scn *scn,
GElf_Shdr *shdr);
gettext ("cannot determine number of sections: %s"),
elf_errmsg (-1));
+ /* Determine the number of phdrs. */
+ if (unlikely (elf_getphdrnum (ebl->elf, &phnum) < 0))
+ error (EXIT_FAILURE, 0,
+ gettext ("cannot determine number of program headers: %s"),
+ elf_errmsg (-1));
+
/* For an ET_REL file, libdwfl has adjusted the in-core shdrs
and may have applied relocation to some sections.
So we need to get a fresh Elf handle on the file to display those. */
if (print_section_groups)
print_scngrp (ebl);
if (print_dynamic_table)
- print_dynamic (ebl, ehdr);
+ print_dynamic (ebl);
if (print_relocations)
print_relocs (pure_ebl, ehdr);
if (print_histogram)
printf (gettext (" Size of program header entries: %" PRId16 " %s\n"),
ehdr->e_phentsize, gettext ("(bytes)"));
- printf (gettext (" Number of program headers entries: %" PRId16 "\n"),
+ printf (gettext (" Number of program headers entries: %" PRId16),
ehdr->e_phnum);
+ if (ehdr->e_phnum == PN_XNUM)
+ {
+ GElf_Shdr shdr_mem;
+ GElf_Shdr *shdr = gelf_getshdr (elf_getscn (ebl->elf, 0), &shdr_mem);
+ if (shdr != NULL)
+ printf (gettext (" (%" PRIu32 " in [0].sh_info)"),
+ (uint32_t) shdr->sh_info);
+ else
+ fputs_unlocked (gettext (" ([0] not available)"), stdout);
+ }
+ fputc_unlocked ('\n', stdout);
printf (gettext (" Size of section header entries: %" PRId16 " %s\n"),
ehdr->e_shentsize, gettext ("(bytes)"));
bool has_relro = false;
GElf_Addr relro_from = 0;
GElf_Addr relro_to = 0;
- for (size_t cnt = 0; cnt < ehdr->e_phnum; ++cnt)
+ for (size_t cnt = 0; cnt < phnum; ++cnt)
{
char buf[128];
GElf_Phdr mem;
puts (gettext ("\n Section to Segment mapping:\n Segment Sections..."));
- for (size_t cnt = 0; cnt < ehdr->e_phnum; ++cnt)
+ for (size_t cnt = 0; cnt < phnum; ++cnt)
{
/* Print the segment number. */
printf (" %2.2zu ", cnt);
/* Determine the segment this section is part of. */
size_t cnt2;
GElf_Phdr *phdr2 = NULL;
- for (cnt2 = 0; cnt2 < ehdr->e_phnum; ++cnt2)
+ for (cnt2 = 0; cnt2 < phnum; ++cnt2)
{
GElf_Phdr phdr2_mem;
phdr2 = gelf_getphdr (ebl->elf, cnt2, &phdr2_mem);
break;
}
- if (cnt2 < ehdr->e_phnum)
+ if (cnt2 < phnum)
{
if ((phdr2->p_flags & PF_W) == 0 && !in_ro)
{
/* Print the dynamic segment. */
static void
-print_dynamic (Ebl *ebl, GElf_Ehdr *ehdr)
+print_dynamic (Ebl *ebl)
{
- for (int i = 0; i < ehdr->e_phnum; ++i)
+ for (size_t i = 0; i < phnum; ++i)
{
GElf_Phdr phdr_mem;
GElf_Phdr *phdr = gelf_getphdr (ebl->elf, i, &phdr_mem);
{
is_statically_linked = 1;
- for (size_t inner = 0; inner < ehdr->e_phnum; ++inner)
+ for (size_t inner = 0; inner < phnum; ++inner)
{
GElf_Phdr phdr_mem;
GElf_Phdr *phdr = gelf_getphdr (ebl->elf, inner,
{
is_statically_linked = 1;
- for (size_t inner = 0; inner < ehdr->e_phnum; ++inner)
+ for (size_t inner = 0; inner < phnum; ++inner)
{
GElf_Phdr phdr_mem;
GElf_Phdr *phdr = gelf_getphdr (ebl->elf, inner,
/* We have to look through the program header to find the note
sections. There can be more than one. */
- for (size_t cnt = 0; cnt < ehdr->e_phnum; ++cnt)
+ for (size_t cnt = 0; cnt < phnum; ++cnt)
{
GElf_Phdr mem;
GElf_Phdr *phdr = gelf_getphdr (ebl->elf, cnt, &mem);