diff options
author | Mark Wielaard <mark@klomp.org> | 2019-09-03 00:03:22 +0200 |
---|---|---|
committer | Mark Wielaard <mark@klomp.org> | 2019-09-10 15:45:53 +0200 |
commit | 08986c35d7bee335f447f542918bbbc2bdd638a9 (patch) | |
tree | 3caab495fb05ad5bd1a33b091a608c45e0bea8ac | |
parent | b833c731359af12af9f16bcb621b3cdc170eafbc (diff) |
readelf: Add --dyn-sym option.
It is already possible to select the symbol table to print by name,
using --symbols=SECTION. This allows printing the dynamic symbol table
with --symbols=.dynsym. binutils readelf allows printing just the
dynamic symbol table by type using --dyn-sym. Add the same option
and document it. Also add a testcase to show --symbols=.dynsym and
--dyn-sym produce the same output.
Signed-off-by: Mark Wielaard <mark@klomp.org>
-rw-r--r-- | doc/ChangeLog | 5 | ||||
-rw-r--r-- | doc/readelf.1 | 9 | ||||
-rw-r--r-- | src/ChangeLog | 8 | ||||
-rw-r--r-- | src/readelf.c | 14 | ||||
-rw-r--r-- | tests/ChangeLog | 4 | ||||
-rwxr-xr-x | tests/run-readelf-s.sh | 3 |
6 files changed, 40 insertions, 3 deletions
diff --git a/doc/ChangeLog b/doc/ChangeLog index 722752da..00a61ac3 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,8 @@ +2019-09-02 Mark Wielaard <mark@klomp.org> + + * readelf.1 (symbols): Add optional section name. + (dyn-sym): Document new option. + 2019-08-28 Mark Wielaard <mark@klomp.org> * COPYING: Rename to... diff --git a/doc/readelf.1 b/doc/readelf.1 index 4f0dd00a..33263819 100644 --- a/doc/readelf.1 +++ b/doc/readelf.1 @@ -146,7 +146,8 @@ eu-readelf [\fB\-a\fR|\fB\-\-all\fR] [\fB\-S\fR|\fB\-\-section\-headers\fR|\fB\-\-sections\fR] [\fB\-g\fR|\fB\-\-section\-groups\fR] [\fB\-e\fR|\fB\-\-exception\fR] - [\fB\-s\fR|\fB\-\-symbols\fR] + [\fB\-s\fR|\fB\-\-symbols\fR] [section name] ] + [\fB\-\-dyn-syms\fR] [\fB\-n\fR|\fB\-\-notes\fR [section name] ] [\fB\-r\fR|\fB\-\-relocs\fR] [\fB\-d\fR|\fB\-\-dynamic\fR] @@ -254,7 +255,7 @@ of the symbol tables. .IP "\fB\-s\fR" 4 .IX Item "-s" .PD 0 -.IP "\fB\-\-symbols\fR" 4 +.IP "\fB\-\-symbols\fR [section name]" 4 .IX Item "--symbols" .PD Displays the entries in symbol table section of the file, if it has one. @@ -265,6 +266,10 @@ symbol name, preceeded by an @ character. For example when resolving unversioned references to the symbol then it is displayed as a suffix preceeded by two @ characters. For example \&\fBfoo@@VER_2\fR. +.IP "\fB\-\-dyn-syms\fR" 4 +.IX Item "--dyn-syms" +.PD +Display (only) the dynamic symbol table. .IP "\fB\-e\fR" 4 .IX Item "-e" .PD 0 diff --git a/src/ChangeLog b/src/ChangeLog index a945c429..3007c30d 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2019-09-02 Mark Wielaard <mark@klomp.org> + + * readelf.c (PRINT_DYNSYM_TABLE): New argp key value. + (argp_opt): Add syn-sym. + (print_dynsym_table): New static bool. + (parse_opt): Handle PRINT_DYNSYM_TABLE. + (process_elf_file): Check print_dynsym_table. + 2019-08-27 Mark Wielaard <mark@klomp.org> * readelf.c (for_each_section_argument): Call (*dump) also for diff --git a/src/readelf.c b/src/readelf.c index 77f9c3a3..5d2b5f43 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,6 +116,8 @@ 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', "SECTION", OPTION_ARG_OPTIONAL, N_("Display the ELF notes"), 0 }, { "arch-specific", 'A', NULL, 0, @@ -187,6 +192,9 @@ 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; @@ -457,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; @@ -998,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); diff --git a/tests/ChangeLog b/tests/ChangeLog index b01ff965..97b8dedb 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,7 @@ +2019-09-02 Mark Wielaard <mark@klomp.org> + + * run-readelf-s.sh: Add --dyn-syms case. + 2019-09-07 Mark Wielaard <mark@klomp.org> * Makefile.am (EXTRA_DIST): Add run-disasm-riscv64.sh, diff --git a/tests/run-readelf-s.sh b/tests/run-readelf-s.sh index 82c3417e..527c436c 100755 --- a/tests/run-readelf-s.sh +++ b/tests/run-readelf-s.sh @@ -281,6 +281,9 @@ cat testfile.dynsym.in testfile.symtab.in \ cat testfile.dynsym.in \ | testrun_compare ${abs_top_builddir}/src/readelf \ --symbols=.dynsym testfilebaztab +cat testfile.dynsym.in \ + | testrun_compare ${abs_top_builddir}/src/readelf \ + --dyn-syms testfilebaztab # Display just .symtab cat testfile.symtab.in \ |