{ "relocs", 'r', NULL, 0, N_("Display relocations"), 0 },
{ "section-headers", 'S', NULL, 0, N_("Display the sections' headers"), 0 },
{ "sections", 'S', NULL, OPTION_ALIAS | OPTION_HIDDEN, NULL, 0 },
- { "symbols", 's', NULL, 0, N_("Display the symbol table"), 0 },
+ { "symbols", 's', "SECTION", OPTION_ARG_OPTIONAL,
+ N_("Display the symbol table sections"), 0 },
{ "version-info", 'V', NULL, 0, N_("Display versioning information"), 0 },
{ "notes", 'n', NULL, 0, N_("Display the ELF notes"), 0 },
{ "arch-specific", 'A', NULL, 0,
/* True if the symbol table should be printed. */
static bool print_symbol_table;
+/* A specific section name, or NULL to print all symbol tables. */
+static char *symbol_table_section;
+
/* True if the version information should be printed. */
static bool print_version_info;
case 's':
print_symbol_table = true;
any_control_option = true;
+ symbol_table_section = arg;
break;
case 'V':
print_version_info = true;
if (shdr != NULL && shdr->sh_type == (GElf_Word) type)
{
+ if (symbol_table_section != NULL)
+ {
+ /* Get the section header string table index. */
+ size_t shstrndx;
+ const char *sname;
+ if (unlikely (elf_getshdrstrndx (ebl->elf, &shstrndx) < 0))
+ error (EXIT_FAILURE, 0,
+ gettext ("cannot get section header string table index"));
+ sname = elf_strptr (ebl->elf, shstrndx, shdr->sh_name);
+ if (sname == NULL || strcmp (sname, symbol_table_section) != 0)
+ continue;
+ }
+
if ((shdr->sh_flags & SHF_COMPRESSED) != 0)
{
if (elf_compress (scn, 0, 0) < 0)
39: 0000000000000680 0 FUNC GLOBAL DEFAULT 11 _init
EOF
+# Display all symbol tables.
cat testfile.dynsym.in testfile.symtab.in \
| testrun_compare ${abs_top_builddir}/src/readelf -s testfilebaztab
+# Display just .dynsym
+cat testfile.dynsym.in \
+ | testrun_compare ${abs_top_builddir}/src/readelf \
+ --symbols=.dynsym testfilebaztab
+
+# Display just .symtab
+cat testfile.symtab.in \
+ | testrun_compare ${abs_top_builddir}/src/readelf \
+ --symbols=.symtab testfilebaztab
+
cat testfile.dynsym.in \
| testrun_compare ${abs_top_builddir}/src/readelf -s testfilebazdbg