public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* Re: [PATCH] readelf: Add optional --symbols[=SECTION] argument to select section name.
@ 2016-11-18 13:16 Mark Wielaard
  0 siblings, 0 replies; 3+ messages in thread
From: Mark Wielaard @ 2016-11-18 13:16 UTC (permalink / raw)
  To: elfutils-devel

[-- Attachment #1: Type: text/plain, Size: 495 bytes --]

On Thu, 2016-11-17 at 15:45 +0100, Florian Weimer wrote:
> On 11/17/2016 03:23 PM, Mark Wielaard wrote:
> > +2016-11-17  Mark Wielaard  <mjw@redhat.com>
> > +
> > +	* readelf.c (options): Add optional arg SECTION for symbols.
> > +	(symbol_table_section): New static variable.
> > +	(parse_opt): Set symbol_table_section on 's'.
> > +	(print_symtab): Filter on symbol_table_section name is set.
> 
> I tested it and it does what I want.  Thanks!

Thanks for testing. Pushed to master.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] readelf: Add optional --symbols[=SECTION] argument to select section name.
@ 2016-11-17 14:45 Florian Weimer
  0 siblings, 0 replies; 3+ messages in thread
From: Florian Weimer @ 2016-11-17 14:45 UTC (permalink / raw)
  To: elfutils-devel

[-- Attachment #1: Type: text/plain, Size: 391 bytes --]

On 11/17/2016 03:23 PM, Mark Wielaard wrote:
> +2016-11-17  Mark Wielaard  <mjw@redhat.com>
> +
> +	* readelf.c (options): Add optional arg SECTION for symbols.
> +	(symbol_table_section): New static variable.
> +	(parse_opt): Set symbol_table_section on 's'.
> +	(print_symtab): Filter on symbol_table_section name is set.

I tested it and it does what I want.  Thanks!

Florian

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] readelf: Add optional --symbols[=SECTION] argument to select section name.
@ 2016-11-17 14:23 Mark Wielaard
  0 siblings, 0 replies; 3+ messages in thread
From: Mark Wielaard @ 2016-11-17 14:23 UTC (permalink / raw)
  To: elfutils-devel

[-- Attachment #1: Type: text/plain, Size: 4305 bytes --]

Make it possible to display just the symbols from a named symbol section
instead of always displaying all symbol sections.

https://bugzilla.redhat.com/show_bug.cgi?id=1396092

Signed-off-by: Mark Wielaard <mjw@redhat.com>
---
 src/ChangeLog          |  7 +++++++
 src/readelf.c          | 20 +++++++++++++++++++-
 tests/ChangeLog        |  4 ++++
 tests/run-readelf-s.sh | 11 +++++++++++
 4 files changed, 41 insertions(+), 1 deletion(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index 3314706..fe95ecb 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,10 @@
+2016-11-17  Mark Wielaard  <mjw@redhat.com>
+
+	* readelf.c (options): Add optional arg SECTION for symbols.
+	(symbol_table_section): New static variable.
+	(parse_opt): Set symbol_table_section on 's'.
+	(print_symtab): Filter on symbol_table_section name is set.
+
 2016-11-10  Mark Wielaard  <mjw@redhat.com>
 
 	* ar.c (write_member): Make sure tmpbuf is large enough to contain
diff --git a/src/readelf.c b/src/readelf.c
index 204aeec..a47b056 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -85,7 +85,8 @@ static const struct argp_option options[] =
   { "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,
@@ -157,6 +158,9 @@ static bool print_section_header;
 /* 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;
 
@@ -389,6 +393,7 @@ parse_opt (int key, char *arg,
     case 's':
       print_symbol_table = true;
       any_control_option = true;
+      symbol_table_section = arg;
       break;
     case 'V':
       print_version_info = true;
@@ -2236,6 +2241,19 @@ print_symtab (Ebl *ebl, int type)
 
       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)
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 5a9d537..7031cf5 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,7 @@
+2016-11-17  Mark Wielaard  <mjw@redhat.com>
+
+	* run-readelf-s.sh: Add --symbols=.dynsym and --symbols=.symtab tests.
+
 2016-11-02  Mark Wielaard  <mjw@redhat.com>
 
 	* backtrace-data.c (thread_callback): Add explicit break after error.
diff --git a/tests/run-readelf-s.sh b/tests/run-readelf-s.sh
index 59407d1..82c3417 100755
--- a/tests/run-readelf-s.sh
+++ b/tests/run-readelf-s.sh
@@ -273,9 +273,20 @@ Symbol table [28] '.symtab' contains 40 entries:
    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
 
-- 
1.8.3.1

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-11-18 13:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-18 13:16 [PATCH] readelf: Add optional --symbols[=SECTION] argument to select section name Mark Wielaard
  -- strict thread matches above, loose matches on Subject: below --
2016-11-17 14:45 Florian Weimer
2016-11-17 14:23 Mark Wielaard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).