public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] readelf: Add optional "SECTION" argument for --notes.
@ 2019-08-21 10:32 Mark Wielaard
  2019-08-26  9:30 ` Mark Wielaard
  0 siblings, 1 reply; 2+ messages in thread
From: Mark Wielaard @ 2019-08-21 10:32 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Ben Coyote Woodard, Mark Wielaard

There are multiple sections that can contain ELF Notes. It is sometimes
nice to just list the notes from a specific section.

  -n, --notes[=SECTION]      Display the ELF notes

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 src/ChangeLog |  7 +++++++
 src/readelf.c | 13 ++++++++++++-
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index c2102fcd..ad673c11 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,10 @@
+2019-08-26  Mark Wielaard  <mark@klomp.org>
+
+	* readelf (options): Add OPTION_ARG_OPTIONAL "SECTION" for notes.
+	(notes_section): New global variable.
+	(parse_opt): Set notes_section.
+	(handle_notes): Check if notes_section is set.
+
 2019-07-26  Florian Weimer  <fweimer@redhat.com>
 	    Mark Wielaard  <mark@klomp.org>
 
diff --git a/src/readelf.c b/src/readelf.c
index 2084fb1f..24be7a9a 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -114,7 +114,7 @@ static const struct argp_option options[] =
   { "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 },
+  { "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,
@@ -190,6 +190,9 @@ static bool print_symbol_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;
 
@@ -439,6 +442,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;
@@ -12408,6 +12412,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),
-- 
2.18.1

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

* Re: [PATCH] readelf: Add optional "SECTION" argument for --notes.
  2019-08-21 10:32 [PATCH] readelf: Add optional "SECTION" argument for --notes Mark Wielaard
@ 2019-08-26  9:30 ` Mark Wielaard
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Wielaard @ 2019-08-26  9:30 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Ben Coyote Woodard

Hi,

On Wed, 2019-08-21 at 12:32 +0200, Mark Wielaard wrote:
> There are multiple sections that can contain ELF Notes. It is sometimes
> nice to just list the notes from a specific section.
> 
>   -n, --notes[=SECTION]      Display the ELF notes

Pushed to master.

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

end of thread, other threads:[~2019-08-26  9:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-21 10:32 [PATCH] readelf: Add optional "SECTION" argument for --notes Mark Wielaard
2019-08-26  9:30 ` 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).