* Readelf section header printing alignment
@ 2023-12-26 23:01 Pete Dietl
2023-12-26 23:59 ` Mike Frysinger
2024-01-05 15:12 ` Nick Clifton
0 siblings, 2 replies; 4+ messages in thread
From: Pete Dietl @ 2023-12-26 23:01 UTC (permalink / raw)
To: binutils
The section headers output from readelf with the '-W' option become ugly and
unaligned when a section name is too long.
Example:
Section Headers:
[Nr] Name Type Address Off Size
ES Flg Lk Inf Al
[ 0] NULL 0000000000000000 000000
000000 00 0 0 0
[ 1] .text PROGBITS 0000000000000000 000040
00000f 00 AX 0 0 1
[ 2] .data PROGBITS 0000000000000000 00004f
000000 00 WA 0 0 1
[ 3] .bss NOBITS 0000000000000000 00004f
000000 00 WA 0 0 1
[ 4] .comment PROGBITS 0000000000000000 00004f
00002c 01 MS 0 0 1
[ 5] .note.GNU-stack PROGBITS 0000000000000000 00007b
000000 00 0 0 1
[ 6] .note.gnu.property NOTE 0000000000000000 000080
000020 00 A 0 0 8
[ 7] .eh_frame PROGBITS 0000000000000000 0000a0
000038 00 A 0 0 8
[ 8] .rela.eh_frame RELA 0000000000000000 000148
000018 18 I 9 7 8
[ 9] .symtab SYMTAB 0000000000000000 0000d8
000060 18 10 3 8
[10] .strtab STRTAB 0000000000000000 000138
00000d 00 0 0 1
[11] .shstrtab STRTAB 0000000000000000 000160
000067 00 0 0 1
May I submit a patch to compute the amount of space between 'Name' and 'Type'
from the longest of the section header names, or is this just a silly
formatting detail that no one cares about? :)
Thanks,
Pete
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Readelf section header printing alignment
2023-12-26 23:01 Readelf section header printing alignment Pete Dietl
@ 2023-12-26 23:59 ` Mike Frysinger
2024-01-05 15:12 ` Nick Clifton
1 sibling, 0 replies; 4+ messages in thread
From: Mike Frysinger @ 2023-12-26 23:59 UTC (permalink / raw)
To: Pete Dietl; +Cc: binutils
[-- Attachment #1: Type: text/plain, Size: 1824 bytes --]
On 26 Dec 2023 15:01, Pete Dietl wrote:
> The section headers output from readelf with the '-W' option become ugly and
> unaligned when a section name is too long.
> Example:
>
> Section Headers:
> [Nr] Name Type Address Off Size
> ES Flg Lk Inf Al
> [ 0] NULL 0000000000000000 000000
> 000000 00 0 0 0
> [ 1] .text PROGBITS 0000000000000000 000040
> 00000f 00 AX 0 0 1
> [ 2] .data PROGBITS 0000000000000000 00004f
> 000000 00 WA 0 0 1
> [ 3] .bss NOBITS 0000000000000000 00004f
> 000000 00 WA 0 0 1
> [ 4] .comment PROGBITS 0000000000000000 00004f
> 00002c 01 MS 0 0 1
> [ 5] .note.GNU-stack PROGBITS 0000000000000000 00007b
> 000000 00 0 0 1
> [ 6] .note.gnu.property NOTE 0000000000000000 000080
> 000020 00 A 0 0 8
> [ 7] .eh_frame PROGBITS 0000000000000000 0000a0
> 000038 00 A 0 0 8
> [ 8] .rela.eh_frame RELA 0000000000000000 000148
> 000018 18 I 9 7 8
> [ 9] .symtab SYMTAB 0000000000000000 0000d8
> 000060 18 10 3 8
> [10] .strtab STRTAB 0000000000000000 000138
> 00000d 00 0 0 1
> [11] .shstrtab STRTAB 0000000000000000 000160
> 000067 00 0 0 1
>
> May I submit a patch to compute the amount of space between 'Name' and 'Type'
> from the longest of the section header names, or is this just a silly
> formatting detail that no one cares about? :)
i think all of the cols can get unaligned if the content is bigger than the
allocated space. i wish it would autoalign/fix itself, at least when using
the -W option.
-mike
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Readelf section header printing alignment
2023-12-26 23:01 Readelf section header printing alignment Pete Dietl
2023-12-26 23:59 ` Mike Frysinger
@ 2024-01-05 15:12 ` Nick Clifton
2024-01-06 6:55 ` Fangrui Song
1 sibling, 1 reply; 4+ messages in thread
From: Nick Clifton @ 2024-01-05 15:12 UTC (permalink / raw)
To: Pete Dietl, binutils
Hi Pete,
> The section headers output from readelf with the '-W' option become ugly and
> unaligned when a section name is too long.
Agreed. In hindsight it would have been better to emit the section name
as the last entry on the output line, rather than the second.
If it helps you could try using the readelf program the elfutils project
(eu-readelf) as this appear to adjust the column positions to allow for
extra long section names. I think that this is a bad idea however as
it could end up looking very strange if just one section has an extremely
long section name.
Changing the default output layout now would be a bad idea as there
are scripts and tools out there that depend upon the current behaviour.
It would be possible however to add a new command line option which
would change the layout. Perhaps simply --section-name-at-end ?
Although this seems a bit, hmm, hackish. Or maybe:
--section-listing-layout=[number,name,type,addr,off,size,flags,info,align]
Then this option could be used to just display the fields of interest
to the user, in the order that they want. So:
--section-listing-layout=type,size,name
would produce output like this:
Section Headers:
Type Size Name
NULL 0
PROGBITS 00000f .text
PROGBITS 000000 .data
NOBITS 000000 .bss
PROGBITS 00002c .comment
PROGBITS 000000 .note.GNU-stack
NOTE 000020 .note.gnu.property
whereas:
--section-listing-layout=name,size
would produce output like this:
Section Headers:
Name Size
0
.text 00000f
.data 000000
.bss 000000
.comment 00002c
.note.GNU-stack 000000
.note.gnu.property 000020
I am just theorizing however. I am not actually volunteering to write
the code. But, as they say, "patches welcome"...
Cheers
Nick
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Readelf section header printing alignment
2024-01-05 15:12 ` Nick Clifton
@ 2024-01-06 6:55 ` Fangrui Song
0 siblings, 0 replies; 4+ messages in thread
From: Fangrui Song @ 2024-01-06 6:55 UTC (permalink / raw)
To: Pete Dietl; +Cc: binutils, Nick Clifton
On Fri, Jan 5, 2024 at 7:12 AM Nick Clifton <nickc@redhat.com> wrote:
>
> Hi Pete,
>
> > The section headers output from readelf with the '-W' option become ugly and
> > unaligned when a section name is too long.
>
> Agreed. In hindsight it would have been better to emit the section name
> as the last entry on the output line, rather than the second.
>
> If it helps you could try using the readelf program the elfutils project
> (eu-readelf) as this appear to adjust the column positions to allow for
> extra long section names. I think that this is a bad idea however as
> it could end up looking very strange if just one section has an extremely
> long section name.
>
> Changing the default output layout now would be a bad idea as there
> are scripts and tools out there that depend upon the current behaviour.
>
> It would be possible however to add a new command line option which
> would change the layout. Perhaps simply --section-name-at-end ?
> Although this seems a bit, hmm, hackish. Or maybe:
>
> --section-listing-layout=[number,name,type,addr,off,size,flags,info,align]
>
> Then this option could be used to just display the fields of interest
> to the user, in the order that they want. So:
>
> --section-listing-layout=type,size,name
>
> would produce output like this:
>
> Section Headers:
> Type Size Name
> NULL 0
> PROGBITS 00000f .text
> PROGBITS 000000 .data
> NOBITS 000000 .bss
> PROGBITS 00002c .comment
> PROGBITS 000000 .note.GNU-stack
> NOTE 000020 .note.gnu.property
>
> whereas:
>
> --section-listing-layout=name,size
>
> would produce output like this:
>
> Section Headers:
> Name Size
> 0
> .text 00000f
> .data 000000
> .bss 000000
> .comment 00002c
> .note.GNU-stack 000000
> .note.gnu.property 000020
>
> I am just theorizing however. I am not actually volunteering to write
> the code. But, as they say, "patches welcome"...
>
> Cheers
> Nick
>
> i think all of the cols can get unaligned if the content is bigger than the
> allocated space. i wish it would autoalign/fix itself, at least when using
> the -W option.
Both eu-readelf and llvm-readelf simply ignore -W/--wide and do not
implement the narrow output at all.
Many folks like me always prefer -W since the narrow output for
certain features has truncated output (e.g. -s output truncates the
symbol name).
If a tool reads readelf -W output and will be broken due to readelf -W
changing the number of spaces, the tool is very likely broken dealing
with the object file in the first place.
To elaborate on what Mike mentioned, columns like (Flg,Lk,Inf,Al) have
the length problem as well... Fixing it will make the code more
complex, so perhaps we can recognize the problem and leave things
as-is...
Note: section warnings immediately follow the section row and
precomputing the column size can easily change the output, though it
probably doesn't matter.
% readelf -S a32
There are 4 section headers, starting at offset 0x54:
Section Headers:
[Nr] Name Type Addr Off Size ES Flg Lk Inf Al
[ 0] NULL 00000000 000000 000000 00 0 0 0
readelf: Warning: [ 1]: Unexpected value (1) in info field.
[ 1] .foo PROGBITS 00000002 000037 000003 06 WA 4 1 5
readelf: Warning: section 1: sh_link value of 4 is larger than the
number of sections
[ 2] .strtab STRTAB 00000000 00003a 000001 00 0 0 1
[ 3] .shstrtab STRTAB 00000000 00003b 000018 00 0 0 1
Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
L (link order), O (extra OS processing required), G (group), T (TLS),
C (compressed), x (unknown), o (OS specific), E (exclude),
D (mbind), p (processor specific)
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-01-06 6:55 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-26 23:01 Readelf section header printing alignment Pete Dietl
2023-12-26 23:59 ` Mike Frysinger
2024-01-05 15:12 ` Nick Clifton
2024-01-06 6:55 ` Fangrui Song
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).