From patchwork Fri Nov 25 13:29:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Martin_Li=C5=A1ka?= X-Patchwork-Id: 61105 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9605D38532D0 for ; Fri, 25 Nov 2022 13:29:32 +0000 (GMT) X-Original-To: elfutils-devel@sourceware.org Delivered-To: elfutils-devel@sourceware.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id ABF363854570 for ; Fri, 25 Nov 2022 13:29:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org ABF363854570 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.cz Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id E248821AD2; Fri, 25 Nov 2022 13:29:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1669382964; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Wq2krvZ/twnhdHQI+ztzyC4uGK919pgvo10775hDJbc=; b=D5Cthv7RMs0zHeIAeY8zrilpw6pVWLe3w78ZNmpQodA4XPMngcXQAslL0XEXxqbtWa9U9/ ZAL8M8Xlv1E5/XLLEDsTjuDJnR/22xM+SvuaDVcKQmsuPqno7gScp1vJz49H2gk+/CQVsr WBVc7reMdmOQ/q/OpseY6q1ByuBuPVU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1669382964; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Wq2krvZ/twnhdHQI+ztzyC4uGK919pgvo10775hDJbc=; b=3JXa+ht95J1mFdDnJSuxaamwTjF5Dl5rsXPrJevEjPrIpuhkvxXfxEfrw58WohO8s0WHjI Og3GZeVbmFEXgiAQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id CD16E1361C; Fri, 25 Nov 2022 13:29:24 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 0rvMMDTDgGPeTQAAMHmgww (envelope-from ); Fri, 25 Nov 2022 13:29:24 +0000 Message-ID: Date: Fri, 25 Nov 2022 14:29:24 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.0 From: =?utf-8?q?Martin_Li=C5=A1ka?= Subject: [PATCH] readelf: print warning for -sW To: elfutils-devel@sourceware.org Content-Language: en-US Cc: Mark Wielaard X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: elfutils-devel@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Elfutils-devel mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , Errors-To: elfutils-devel-bounces+patchwork=sourceware.org@sourceware.org Sender: "Elfutils-devel" 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