diff options
Diffstat (limited to 'src/readelf.c')
-rw-r--r-- | src/readelf.c | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/src/readelf.c b/src/readelf.c index 2084fb1f..cbb519d1 100644 --- a/src/readelf.c +++ b/src/readelf.c @@ -84,6 +84,9 @@ ARGP_PROGRAM_BUG_ADDRESS_DEF = PACKAGE_BUGREPORT; /* argp key value for --dwarf-skeleton, non-ascii. */ #define DWARF_SKELETON 257 +/* argp key value for --dyn-syms, non-ascii. */ +#define PRINT_DYNSYM_TABLE 258 + /* Terrible hack for hooking unrelated skeleton/split compile units, see __libdw_link_skel_split in print_debug. */ static bool do_not_close_dwfl = false; @@ -113,8 +116,10 @@ static const struct argp_option options[] = { "sections", 'S', NULL, OPTION_ALIAS | OPTION_HIDDEN, NULL, 0 }, { "symbols", 's', "SECTION", OPTION_ARG_OPTIONAL, N_("Display the symbol table sections"), 0 }, + { "dyn-syms", PRINT_DYNSYM_TABLE, NULL, 0, + N_("Display (only) the dynamic symbol table"), 0 }, { "version-info", 'V', NULL, 0, N_("Display versioning information"), 0 }, - { "notes", 'n', NULL, 0, N_("Display the ELF notes"), 0 }, + { "notes", 'n', "SECTION", OPTION_ARG_OPTIONAL, N_("Display the ELF notes"), 0 }, { "arch-specific", 'A', NULL, 0, N_("Display architecture specific information, if any"), 0 }, { "exception", 'e', NULL, 0, @@ -187,9 +192,15 @@ static bool print_section_header; /* True if the symbol table should be printed. */ static bool print_symbol_table; +/* True if (only) the dynsym table should be printed. */ +static bool print_dynsym_table; + /* A specific section name, or NULL to print all symbol tables. */ static char *symbol_table_section; +/* A specific section name, or NULL to print all ELF notes. */ +static char *notes_section; + /* True if the version information should be printed. */ static bool print_version_info; @@ -354,7 +365,7 @@ main (int argc, char *argv[]) int fd = open (argv[remaining], O_RDONLY); if (fd == -1) { - error (0, errno, gettext ("cannot open input file")); + error (0, errno, _("cannot open input file '%s'"), argv[remaining]); continue; } @@ -439,6 +450,7 @@ parse_opt (int key, char *arg, case 'n': print_notes = true; any_control_option = true; + notes_section = arg; break; case 'r': print_relocations = true; @@ -453,6 +465,10 @@ parse_opt (int key, char *arg, any_control_option = true; symbol_table_section = arg; break; + case PRINT_DYNSYM_TABLE: + print_dynsym_table = true; + any_control_option = true; + break; case 'V': print_version_info = true; any_control_option = true; @@ -994,7 +1010,7 @@ process_elf_file (Dwfl_Module *dwflmod, int fd) print_relocs (pure_ebl, ehdr); if (print_histogram) handle_hash (ebl); - if (print_symbol_table) + if (print_symbol_table || print_dynsym_table) print_symtab (ebl, SHT_DYNSYM); if (print_version_info) print_verinfo (ebl); @@ -12408,6 +12424,13 @@ handle_notes (Ebl *ebl, GElf_Ehdr *ehdr) /* Not what we are looking for. */ continue; + if (notes_section != NULL) + { + char *sname = elf_strptr (ebl->elf, shstrndx, shdr->sh_name); + if (sname == NULL || strcmp (sname, notes_section) != 0) + continue; + } + printf (gettext ("\ \nNote section [%2zu] '%s' of %" PRIu64 " bytes at offset %#0" PRIx64 ":\n"), elf_ndxscn (scn), @@ -12623,6 +12646,7 @@ for_each_section_argument (Elf *elf, const struct section_argument *list, error (EXIT_FAILURE, 0, gettext ("cannot get section header: %s"), elf_errmsg (-1)); name = elf_strptr (elf, shstrndx, shdr_mem.sh_name); + (*dump) (scn, &shdr_mem, name); } else { |