2018-09-13 Mark Wielaard <mark@klomp.org>
+ * readelf.c (print_shdr): Get number of section with elf_getshdrnum.
+ (print_phdr): Likewise.
+
+2018-09-13 Mark Wielaard <mark@klomp.org>
+
* strip.c (handle_elf): Check against shstrndx, not e_shstrndx.
Explicitly set shdrstrndx for debug file.
* unstrip.c (copy_elf): Explicitly copy shstrndx.
size_t shstrndx;
if (! print_file_header)
- printf (gettext ("\
-There are %d section headers, starting at offset %#" PRIx64 ":\n\
+ {
+ size_t sections;
+ if (unlikely (elf_getshdrnum (ebl->elf, §ions) < 0))
+ error (EXIT_FAILURE, 0,
+ gettext ("cannot get number of sections: %s"),
+ elf_errmsg (-1));
+
+ printf (gettext ("\
+There are %zd section headers, starting at offset %#" PRIx64 ":\n\
\n"),
- ehdr->e_shnum, ehdr->e_shoff);
+ sections, ehdr->e_shoff);
+ }
/* Get the section header string table index. */
if (unlikely (elf_getshdrstrndx (ebl->elf, &shstrndx) < 0))
error (EXIT_FAILURE, 0,
- gettext ("cannot get section header string table index"));
+ gettext ("cannot get section header string table index: %s"),
+ elf_errmsg (-1));
puts (gettext ("Section Headers:"));
}
}
- if (ehdr->e_shnum == 0)
+ size_t sections;
+ if (unlikely (elf_getshdrnum (ebl->elf, §ions) < 0))
+ error (EXIT_FAILURE, 0,
+ gettext ("cannot get number of sections: %s"),
+ elf_errmsg (-1));
+
+ if (sections == 0)
/* No sections in the file. Punt. */
return;