From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gnu.wildebeest.org (gnu.wildebeest.org [45.83.234.184]) by sourceware.org (Postfix) with ESMTPS id 365E53858D33 for ; Thu, 16 Feb 2023 16:02:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 365E53858D33 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=klomp.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=klomp.org Received: from r6.localdomain (82-217-174-174.cable.dynamic.v4.ziggo.nl [82.217.174.174]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id AF5C630067D7; Thu, 16 Feb 2023 17:02:46 +0100 (CET) Received: by r6.localdomain (Postfix, from userid 1000) id 823633401E3; Thu, 16 Feb 2023 17:02:45 +0100 (CET) Message-ID: <634598e6cf48b8d5a864f43ede8ec8731fc5cf51.camel@klomp.org> Subject: Re: [PATCH] PR28873 - Implement eu-readelf -D From: Mark Wielaard To: Di Chen , elfutils-devel@sourceware.org Date: Thu, 16 Feb 2023 17:02:45 +0100 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.46.3 (3.46.3-1.fc37) MIME-Version: 1.0 X-Spam-Status: No, score=-3031.6 required=5.0 tests=BAYES_00,JMQ_SPF_NEUTRAL,KAM_DMARC_STATUS,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hi, On Sat, 2023-02-11 at 00:17 +0800, Di Chen via Elfutils-devel wrote: > From bdc19de94bff8f8812611b9ba8c0116a650d0fb5 Mon Sep 17 00:00:00 2001 > From: Di Chen > Date: Fri, 13 Jan 2023 20:12:43 +0800 > Subject: [PATCH] readelf: display dynamic symtab without section headers >=20 > This commit adds a new option "-D/--use-dynamic" to support printing the > dynamic symbol table from the PT_DYNAMIC segment. By using the > PT_DYNAMIC segment, eu-readelf can go through the contents of dynamic > section entries and the values of each tag. From that, we can get the > address and size of the dynamic symbol table, the address of the string > table, etc. >=20 > By using the new option "-D/--use-dynamic", eu-readelf can list the > symbols without section headers. >=20 > Example: > $ ./src/readelf -Ds a.out > 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UNDEF > 1: 0000000000000000 0 FUNC GLOBAL DEFAULT UNDEF > __libc_start_main@GLIBC_2.34 (2) > 2: 0000000000000000 0 NOTYPE WEAK DEFAULT UNDEF > __gmon_start__ >=20 > https://sourceware.org/bugzilla/show_bug.cgi?id=3D28873 >=20 > Signed-off-by: Di Chen Very nice. Note that my local build (gcc 12.2.1) says: In function =E2=80=98handle_dynamic_symtab=E2=80=99, inlined from =E2=80=98print_symtab=E2=80=99 at /home/mark/src/elfutils/src/readelf.c:2451:9: /home/mark/src/elfutils/src/readelf.c:2535:29: error: =E2=80=98syments=E2= =80=99 may be used uninitialized [-Werror=3Dmaybe-uninitialized] 2535 | if (offs[i_gnu_hash] !=3D 0 && syments =3D=3D 0) { | ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~ /home/mark/src/elfutils/src/readelf.c: In function =E2=80=98print_symtab=E2= =80=99: /home/mark/src/elfutils/src/readelf.c:2519:10: note: =E2=80=98syments=E2=80= =99 was declared here 2519 | size_t syments; | ^~~~~~~ And I think it is correct. We have 3 different ways of trying to set syments. We should initialize syments to zero so each check knows whether a previous one succeeded or not. I have not been very picky about missing ChangeLog entries, but in this case it would really help understanding what was changed. Specifically it would be nice to note that the code in handle_dynamic_symtab to calculate the syments was lifted from libdwfl/dwfl_module_getdwarf.c. Lets keep the indentation GNU style, like in dwfl_module_getdwarf.c, I don't think the new indentation is helpful. Finally the actual printing of the symbols and processing the version information in handle_dynamic_symtab look like they were mostly copied from handle_symtab. Can that code be shared? Thanks, Mark