* [Bug tools/28873] New: Implement eu-readelf -D
@ 2022-02-08 14:41 dichen at redhat dot com
2022-02-08 14:43 ` [Bug tools/28873] " dichen at redhat dot com
` (12 more replies)
0 siblings, 13 replies; 14+ messages in thread
From: dichen at redhat dot com @ 2022-02-08 14:41 UTC (permalink / raw)
To: elfutils-devel
https://sourceware.org/bugzilla/show_bug.cgi?id=28873
Bug ID: 28873
Summary: Implement eu-readelf -D
Product: elfutils
Version: unspecified
Status: NEW
Severity: normal
Priority: P2
Component: tools
Assignee: unassigned at sourceware dot org
Reporter: dichen at redhat dot com
CC: elfutils-devel at sourceware dot org
Target Milestone: ---
Currently, eu-readelf is using section headers (in readelf.c:handle_symtab(),
it calls gelf_getshdr() for fetching section headers and get related info like
section size, type, etc) to find the symbol information and print them.
This task will add new options to eu-readelf (-D and --use-dynamic).
And this task aims for printing the symbols by lookup through the program
headers
and the dynamic table. PT_DYNAMIC->DT_* for DT_{GNU_,}HASH, DT_SYMTAB,
DT_STRSZ,
DT_VERNEED, DT_VERSYM(for version information), etc.
previous discussion: https://bugzilla.redhat.com/show_bug.cgi?id=444621
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug tools/28873] Implement eu-readelf -D
2022-02-08 14:41 [Bug tools/28873] New: Implement eu-readelf -D dichen at redhat dot com
@ 2022-02-08 14:43 ` dichen at redhat dot com
2022-02-08 14:43 ` dichen at redhat dot com
` (11 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: dichen at redhat dot com @ 2022-02-08 14:43 UTC (permalink / raw)
To: elfutils-devel
https://sourceware.org/bugzilla/show_bug.cgi?id=28873
Di Chen <dichen at redhat dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug tools/28873] Implement eu-readelf -D
2022-02-08 14:41 [Bug tools/28873] New: Implement eu-readelf -D dichen at redhat dot com
2022-02-08 14:43 ` [Bug tools/28873] " dichen at redhat dot com
@ 2022-02-08 14:43 ` dichen at redhat dot com
2022-03-30 11:48 ` dichen at redhat dot com
` (10 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: dichen at redhat dot com @ 2022-02-08 14:43 UTC (permalink / raw)
To: elfutils-devel
https://sourceware.org/bugzilla/show_bug.cgi?id=28873
Di Chen <dichen at redhat dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at sourceware dot org |dichen at redhat dot com
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug tools/28873] Implement eu-readelf -D
2022-02-08 14:41 [Bug tools/28873] New: Implement eu-readelf -D dichen at redhat dot com
2022-02-08 14:43 ` [Bug tools/28873] " dichen at redhat dot com
2022-02-08 14:43 ` dichen at redhat dot com
@ 2022-03-30 11:48 ` dichen at redhat dot com
2022-03-31 13:07 ` dichen at redhat dot com
` (9 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: dichen at redhat dot com @ 2022-03-30 11:48 UTC (permalink / raw)
To: elfutils-devel
https://sourceware.org/bugzilla/show_bug.cgi?id=28873
Di Chen <dichen at redhat dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Depends on| |28928
Referenced Bugs:
https://sourceware.org/bugzilla/show_bug.cgi?id=28928
[Bug 28928] Wrong dynamic section entry number
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug tools/28873] Implement eu-readelf -D
2022-02-08 14:41 [Bug tools/28873] New: Implement eu-readelf -D dichen at redhat dot com
` (2 preceding siblings ...)
2022-03-30 11:48 ` dichen at redhat dot com
@ 2022-03-31 13:07 ` dichen at redhat dot com
2022-04-19 8:18 ` mark at klomp dot org
` (8 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: dichen at redhat dot com @ 2022-03-31 13:07 UTC (permalink / raw)
To: elfutils-devel
https://sourceware.org/bugzilla/show_bug.cgi?id=28873
--- Comment #1 from Di Chen <dichen at redhat dot com> ---
This Bug depends on Bug 28928 because when calling
`$ eu-readelf -d --use-dynamic {FILE}`
eu-readelf will need the number of dynamic section entris which involves with
Bug 28928
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug tools/28873] Implement eu-readelf -D
2022-02-08 14:41 [Bug tools/28873] New: Implement eu-readelf -D dichen at redhat dot com
` (3 preceding siblings ...)
2022-03-31 13:07 ` dichen at redhat dot com
@ 2022-04-19 8:18 ` mark at klomp dot org
2022-08-08 9:33 ` dichen at redhat dot com
` (7 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: mark at klomp dot org @ 2022-04-19 8:18 UTC (permalink / raw)
To: elfutils-devel
https://sourceware.org/bugzilla/show_bug.cgi?id=28873
Bug 28873 depends on bug 28928, which changed state.
Bug 28928 Summary: Wrong dynamic section entry number
https://sourceware.org/bugzilla/show_bug.cgi?id=28928
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug tools/28873] Implement eu-readelf -D
2022-02-08 14:41 [Bug tools/28873] New: Implement eu-readelf -D dichen at redhat dot com
` (4 preceding siblings ...)
2022-04-19 8:18 ` mark at klomp dot org
@ 2022-08-08 9:33 ` dichen at redhat dot com
2022-08-08 9:38 ` dichen at redhat dot com
` (6 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: dichen at redhat dot com @ 2022-08-08 9:33 UTC (permalink / raw)
To: elfutils-devel
https://sourceware.org/bugzilla/show_bug.cgi?id=28873
--- Comment #2 from Di Chen <dichen at redhat dot com> ---
commit 369c021c6eedae3665c1dbbaa4fc43afbbb698f4
Author: Di Chen <dichen@redhat.com>
Date: Thu Apr 28 19:55:33 2022 +0800
readelf: Support --dynamic with --use-dynamic
Currently, eu-readelf is using section headers to dump the dynamic
segment information (print_dynamic -> handle_dynamic).
This patch adds new options to eu-readelf (-D, --use-dynamic)
for (-d, --dynamic).
https://sourceware.org/bugzilla/show_bug.cgi?id=28873
Signed-off-by: Di Chen <dichen@redhat.com>
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug tools/28873] Implement eu-readelf -D
2022-02-08 14:41 [Bug tools/28873] New: Implement eu-readelf -D dichen at redhat dot com
` (5 preceding siblings ...)
2022-08-08 9:33 ` dichen at redhat dot com
@ 2022-08-08 9:38 ` dichen at redhat dot com
2022-08-08 9:42 ` dichen at redhat dot com
` (5 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: dichen at redhat dot com @ 2022-08-08 9:38 UTC (permalink / raw)
To: elfutils-devel
https://sourceware.org/bugzilla/show_bug.cgi?id=28873
--- Comment #3 from Di Chen <dichen at redhat dot com> ---
Finished the first part of the whole task, now eu-readelf can dump the dynamic
segment information from dynamic program header, i.e.
```
$ ./src/readelf -Dd ~/test/eu-readelf-no-shdr
Dynamic segment contains 26 entries:
Addr: 0x0000000000474e00 Offset: 0x073e00
Type Value
NEEDED Shared library: [libdw.so.1]
NEEDED Shared library: [libelf.so.1]
NEEDED Shared library: [libc.so.6]
INIT 0x0000000000404000
FINI 0x000000000043d4a8
INIT_ARRAY 0x0000000000474df0
INIT_ARRAYSZ 8 (bytes)
FINI_ARRAY 0x0000000000474df8
FINI_ARRAYSZ 8 (bytes)
GNU_HASH 0x00000000004003a0
STRTAB 0x00000000004016b0
SYMTAB 0x00000000004003f0
STRSZ 3086 (bytes)
SYMENT 24 (bytes)
DEBUG
PLTGOT 0x0000000000475000
PLTRELSZ 4560 (bytes)
PLTREL RELA
JMPREL 0x00000000004026a0
RELA 0x0000000000402610
RELASZ 144 (bytes)
RELAENT 24 (bytes)
VERNEED 0x0000000000402450
VERNEEDNUM 3
VERSYM 0x00000000004022be
NULL
```
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug tools/28873] Implement eu-readelf -D
2022-02-08 14:41 [Bug tools/28873] New: Implement eu-readelf -D dichen at redhat dot com
` (6 preceding siblings ...)
2022-08-08 9:38 ` dichen at redhat dot com
@ 2022-08-08 9:42 ` dichen at redhat dot com
2023-01-16 13:30 ` dichen at redhat dot com
` (4 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: dichen at redhat dot com @ 2022-08-08 9:42 UTC (permalink / raw)
To: elfutils-devel
https://sourceware.org/bugzilla/show_bug.cgi?id=28873
--- Comment #4 from Di Chen <dichen at redhat dot com> ---
Update:
I am working on the second part of the task, make eu-readelf can dump symbol
information from dynamic program header, like $ eu-readelf -Ds {FILE}
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug tools/28873] Implement eu-readelf -D
2022-02-08 14:41 [Bug tools/28873] New: Implement eu-readelf -D dichen at redhat dot com
` (7 preceding siblings ...)
2022-08-08 9:42 ` dichen at redhat dot com
@ 2023-01-16 13:30 ` dichen at redhat dot com
2023-01-16 13:39 ` dichen at redhat dot com
` (3 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: dichen at redhat dot com @ 2023-01-16 13:30 UTC (permalink / raw)
To: elfutils-devel
https://sourceware.org/bugzilla/show_bug.cgi?id=28873
--- Comment #5 from Di Chen <dichen at redhat dot com> ---
Created attachment 14600
--> https://sourceware.org/bugzilla/attachment.cgi?id=14600&action=edit
readelf: display dynamic symtab without section headers
```
# failed to print symtab of a binary which has section headers removed.
$ ./src/readelf -s ~/test/a.out
# it works with "-D" for a binary which has section headers removed.
$ ./src/readelf -Ds ~/test/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__
```
It works well for binaries which has SYMTAB section right after STRTAB section.
```
$ readelf -Dd ~/test/a.out
Dynamic section at offset 0x2e60 contains 20 entries:
Tag Type Name/Value
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
0x000000000000000c (INIT) 0x401000
0x000000000000000d (FINI) 0x401124
0x0000000000000019 (INIT_ARRAY) 0x403e50
0x000000000000001b (INIT_ARRAYSZ) 8 (bytes)
0x000000000000001a (FINI_ARRAY) 0x403e58
0x000000000000001c (FINI_ARRAYSZ) 8 (bytes)
0x000000006ffffef5 (GNU_HASH) 0x4003c0
0x0000000000000005 (STRTAB) 0x400428
0x0000000000000006 (SYMTAB) 0x4003e0
0x000000000000000a (STRSZ) 55 (bytes)
0x000000000000000b (SYMENT) 24 (bytes)
0x0000000000000015 (DEBUG) 0x0
0x0000000000000007 (RELA) 0x400488
0x0000000000000008 (RELASZ) 48 (bytes)
0x0000000000000009 (RELAENT) 24 (bytes)
0x000000006ffffffe (VERNEED) 0x400468
0x000000006fffffff (VERNEEDNUM) 1
0x000000006ffffff0 (VERSYM) 0x400460
0x0000000000000000 (NULL) 0x0
```
Because I use offset difference between SYMTAB and STRTAB to get the symbol
table entry number.
```
size_t syments = ((offs[i_strtab] - offs[i_symtab]) /
gelf_fsize(ebl->elf, ELF_T_SYM, 1, EV_CURRENT));
```
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug tools/28873] Implement eu-readelf -D
2022-02-08 14:41 [Bug tools/28873] New: Implement eu-readelf -D dichen at redhat dot com
` (8 preceding siblings ...)
2023-01-16 13:30 ` dichen at redhat dot com
@ 2023-01-16 13:39 ` dichen at redhat dot com
2023-02-03 18:24 ` amerey at redhat dot com
` (2 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: dichen at redhat dot com @ 2023-01-16 13:39 UTC (permalink / raw)
To: elfutils-devel
https://sourceware.org/bugzilla/show_bug.cgi?id=28873
--- Comment #6 from Di Chen <dichen at redhat dot com> ---
[Follow the last comment]
For a binary with SYMTAB STRTAB having different order, like upside down, or
having other section in between. eg.
```
$ readelf -Dd /usr/local/go/bin/go
Dynamic section at offset 0x9e5220 contains 19 entries:
Tag Type Name/Value
0x0000000000000004 (HASH) 0xb3c3c0
0x0000000000000006 (SYMTAB) 0xb3c880
0x000000000000000b (SYMENT) 24 (bytes)
0x0000000000000005 (STRTAB) 0xb3c660
0x000000000000000a (STRSZ) 531 (bytes)
0x0000000000000007 (RELA) 0xb3bfd8
0x0000000000000008 (RELASZ) 24 (bytes)
0x0000000000000009 (RELAENT) 24 (bytes)
0x0000000000000003 (PLTGOT) 0xde5100
0x0000000000000015 (DEBUG) 0x0
0x0000000000000001 (NEEDED) Shared library: [libpthread.so.0]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
0x000000006ffffffe (VERNEED) 0xb3c360
0x000000006fffffff (VERNEEDNUM) 2
0x000000006ffffff0 (VERSYM) 0xb3c300
0x0000000000000014 (PLTREL) RELA
0x0000000000000002 (PLTRELSZ) 768 (bytes)
0x0000000000000017 (JMPREL) 0xb3bff0
0x0000000000000000 (NULL) 0x0
```
It will mess up the syments (symbol table entry number) calculation.
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug tools/28873] Implement eu-readelf -D
2022-02-08 14:41 [Bug tools/28873] New: Implement eu-readelf -D dichen at redhat dot com
` (9 preceding siblings ...)
2023-01-16 13:39 ` dichen at redhat dot com
@ 2023-02-03 18:24 ` amerey at redhat dot com
2023-02-04 17:02 ` mark at klomp dot org
2023-04-18 19:51 ` mark at klomp dot org
12 siblings, 0 replies; 14+ messages in thread
From: amerey at redhat dot com @ 2023-02-03 18:24 UTC (permalink / raw)
To: elfutils-devel
https://sourceware.org/bugzilla/show_bug.cgi?id=28873
Aaron Merey <amerey at redhat dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |amerey at redhat dot com
--- Comment #7 from Aaron Merey <amerey at redhat dot com> ---
(In reply to Di Chen from comment #5)
> Because I use offset difference between SYMTAB and STRTAB to get the symbol
> table entry number.
> ```
> size_t syments = ((offs[i_strtab] - offs[i_symtab]) /
> gelf_fsize(ebl->elf, ELF_T_SYM, 1, EV_CURRENT));
> ```
>
> For a binary with SYMTAB STRTAB having different order, like upside down, or
> having other section in between. eg.
> [...]
> It will mess up the syments (symbol table entry number) calculation.
This raises an interesting question: how do you calculate the number of symbols
in .dynsym without using section headers?
I figured there'd some kind of "DT_SYMTABNUM" value somewhere but unfortunately
the answer doesn't appear to be so straightforward.
Judging from the binutils readelf source code you need to use information in
the .hash and .gnu.hash sections to calculate the number of entries.
To complicate things even more, a binary can contain either .hash or .gnu.hash
or both and computing the number of .dynsym entries is different in each case.
See binutils/readelf.c:get_num_dynamic_syms, you may need to implement some of
this in your patch.
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug tools/28873] Implement eu-readelf -D
2022-02-08 14:41 [Bug tools/28873] New: Implement eu-readelf -D dichen at redhat dot com
` (10 preceding siblings ...)
2023-02-03 18:24 ` amerey at redhat dot com
@ 2023-02-04 17:02 ` mark at klomp dot org
2023-04-18 19:51 ` mark at klomp dot org
12 siblings, 0 replies; 14+ messages in thread
From: mark at klomp dot org @ 2023-02-04 17:02 UTC (permalink / raw)
To: elfutils-devel
https://sourceware.org/bugzilla/show_bug.cgi?id=28873
--- Comment #8 from Mark Wielaard <mark at klomp dot org> ---
(In reply to Aaron Merey from comment #7)
> This raises an interesting question: how do you calculate the number of
> symbols in .dynsym without using section headers?
>
> I figured there'd some kind of "DT_SYMTABNUM" value somewhere but
> unfortunately the answer doesn't appear to be so straightforward.
It has been proposed, but not (yet) adopted:
https://groups.google.com/g/generic-abi/c/9L03yrxXPBc
(sorry, a google groups link, there should be a normal archive, but I cannot
find it right now). If that was adopted and linkers would generate it, then
this question would indeed have a simple answer. Sadly, it isn't :{
> Judging from the binutils readelf source code you need to use information in
> the .hash and .gnu.hash sections to calculate the number of entries.
>
> To complicate things even more, a binary can contain either .hash or
> .gnu.hash or both and computing the number of .dynsym entries is different
> in each case. See binutils/readelf.c:get_num_dynamic_syms, you may need to
> implement some of this in your patch.
If there is a .hash section then it is fairly easy, the first word is the
number of symbols the hash/symbol table describes.
If it is a .gnu.hash section then sadly you have to parse and go through the
whole hashtable and count.
There is an implementation already in elfutils, but it is a bit hiden and
obscure if you don't know what you are looking for. Search for "Figure out the
size of the symbol table" in libdwfl/dwfl_module_getdwarf.c.
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug tools/28873] Implement eu-readelf -D
2022-02-08 14:41 [Bug tools/28873] New: Implement eu-readelf -D dichen at redhat dot com
` (11 preceding siblings ...)
2023-02-04 17:02 ` mark at klomp dot org
@ 2023-04-18 19:51 ` mark at klomp dot org
12 siblings, 0 replies; 14+ messages in thread
From: mark at klomp dot org @ 2023-04-18 19:51 UTC (permalink / raw)
To: elfutils-devel
https://sourceware.org/bugzilla/show_bug.cgi?id=28873
Mark Wielaard <mark at klomp dot org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
--- Comment #9 from Mark Wielaard <mark at klomp dot org> ---
commit 4d8de4b2fa05495d69d09e1a3d335f24d6bf33ee
Author: Di Chen <dichen@redhat.com>
Date: Mon Mar 27 10:01:05 2023 +0800
readelf: display dynamic symtab without section headers
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.
By using the new option "-D/--use-dynamic", eu-readelf can list the
symbols without section headers.
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__
https://sourceware.org/bugzilla/show_bug.cgi?id=28873
Signed-off-by: Di Chen <dichen@redhat.com>
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2023-04-18 19:51 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-08 14:41 [Bug tools/28873] New: Implement eu-readelf -D dichen at redhat dot com
2022-02-08 14:43 ` [Bug tools/28873] " dichen at redhat dot com
2022-02-08 14:43 ` dichen at redhat dot com
2022-03-30 11:48 ` dichen at redhat dot com
2022-03-31 13:07 ` dichen at redhat dot com
2022-04-19 8:18 ` mark at klomp dot org
2022-08-08 9:33 ` dichen at redhat dot com
2022-08-08 9:38 ` dichen at redhat dot com
2022-08-08 9:42 ` dichen at redhat dot com
2023-01-16 13:30 ` dichen at redhat dot com
2023-01-16 13:39 ` dichen at redhat dot com
2023-02-03 18:24 ` amerey at redhat dot com
2023-02-04 17:02 ` mark at klomp dot org
2023-04-18 19:51 ` mark at klomp dot org
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).