public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: "Martin Liška" <mliska@suse.cz>
To: elfutils-devel@sourceware.org
Cc: Mark Wielaard <mark@klomp.org>
Subject: [PATCH] readelf: print warning for -sW
Date: Fri, 25 Nov 2022 14:29:24 +0100	[thread overview]
Message-ID: <fad31cad-b00b-42b3-7256-305ab44df7b3@suse.cz> (raw)

The option -s accepts in elfutils (compared to binutils) a positional
argument that is name of a symbol table section which should be printed.

Thus, print a reasonable warning if -sW is used:
./src/readelf -sW a.out
WARNING: cannot find section: 'W'

Ready for master?
Thanks,
Martin

src/ChangeLog:

	* readelf.c (print_symtab): Change signature and return true if
	something is printed.
	(process_elf_file): Use it and print warning.

tests/ChangeLog:

	* run-readelf-s.sh: Test -sW.
---
 src/readelf.c          | 23 ++++++++++++++++++-----
 tests/run-readelf-s.sh |  3 +++
 2 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/src/readelf.c b/src/readelf.c
index 3dafb041..cc3e0229 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -306,7 +306,7 @@ static void handle_relocs_rel (Ebl *ebl, GElf_Ehdr *ehdr, Elf_Scn *scn,
 			       GElf_Shdr *shdr);
 static void handle_relocs_rela (Ebl *ebl, GElf_Ehdr *ehdr, Elf_Scn *scn,
 				GElf_Shdr *shdr);
-static void print_symtab (Ebl *ebl, int type);
+static bool print_symtab (Ebl *ebl, int type);
 static void handle_symtab (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr);
 static void print_verinfo (Ebl *ebl);
 static void handle_verneed (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr);
@@ -1022,6 +1022,8 @@ process_elf_file (Dwfl_Module *dwflmod, int fd)
 	goto ebl_error;
     }
 
+  bool symtab_printed = false;
+
   if (print_file_header)
     print_ehdr (ebl, ehdr);
   if (print_section_header)
@@ -1037,11 +1039,17 @@ process_elf_file (Dwfl_Module *dwflmod, int fd)
   if (print_histogram)
     handle_hash (ebl);
   if (print_symbol_table || print_dynsym_table)
-    print_symtab (ebl, SHT_DYNSYM);
+    symtab_printed |= print_symtab (ebl, SHT_DYNSYM);
   if (print_version_info)
     print_verinfo (ebl);
   if (print_symbol_table)
-    print_symtab (ebl, SHT_SYMTAB);
+    symtab_printed |= print_symtab (ebl, SHT_SYMTAB);
+
+  if ((print_symbol_table || print_dynsym_table)
+      && !symtab_printed && symbol_table_section != NULL)
+    printf ("WARNING: %s: '%s'\n", _("cannot find section"),
+        symbol_table_section);
+
   if (print_arch)
     print_liblist (ebl);
   if (print_arch)
@@ -2425,13 +2433,15 @@ handle_relocs_rela (Ebl *ebl, GElf_Ehdr *ehdr, Elf_Scn *scn, GElf_Shdr *shdr)
 }
 
 
-/* Print the program header.  */
-static void
+/* Print the program header.  Return true if a symtab is printed,
+   false otherwise.  */
+static bool
 print_symtab (Ebl *ebl, int type)
 {
   /* Find the symbol table(s).  For this we have to search through the
      section table.  */
   Elf_Scn *scn = NULL;
+  bool symtab_printed = false;
 
   while ((scn = elf_nextscn (ebl->elf, scn)) != NULL)
     {
@@ -2467,8 +2477,11 @@ print_symtab (Ebl *ebl, int type)
 			    elf_ndxscn (scn), elf_errmsg (-1));
 	    }
 	  handle_symtab (ebl, scn, shdr);
+	  symtab_printed = true;
 	}
     }
+
+  return symtab_printed;
 }
 
 
diff --git a/tests/run-readelf-s.sh b/tests/run-readelf-s.sh
index ee1c0e82..c150c165 100755
--- a/tests/run-readelf-s.sh
+++ b/tests/run-readelf-s.sh
@@ -395,4 +395,7 @@ Symbol table [27] '.symtab' contains 42 entries:
    41: 00000000004003a8      0 FUNC    GLOBAL DEFAULT       11 _init
 EOF
 
+${abs_top_builddir}/src/readelf --elf-section -sW testfilebaxmin 2>&1 \
+  | grep "WARNING: cannot find section: 'W'" >/dev/null || exit 2
+
 exit 0
-- 
2.38.1


             reply	other threads:[~2022-11-25 13:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-25 13:29 Martin Liška [this message]
2022-11-25 17:27 ` Mark Wielaard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fad31cad-b00b-42b3-7256-305ab44df7b3@suse.cz \
    --to=mliska@suse.cz \
    --cc=elfutils-devel@sourceware.org \
    --cc=mark@klomp.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).