Bug 246015 - readelf -S truncates section names
Summary: readelf -S truncates section names
Status: In Progress
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: Ed Maste
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-04-29 02:48 UTC by Conrad Meyer
Modified: 2021-02-23 01:49 UTC (History)
4 users (show)

See Also:
koobs: mfc-stable13+
koobs: mfc-stable12?


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Conrad Meyer freebsd_committer 2020-04-29 02:48:40 UTC
-W and -WW do not improve the situation.

The documented -N flag is not implemented and would at least hypothetically provide a non-truncating mode, although archaic GNU objdump-2.17 from 2007 doesn't have this problem without any additional flag required.
Comment 1 Ed Maste freebsd_committer 2021-02-02 14:26:44 UTC
Indeed, creating a test file via
$ objcopy -I binary -O elf64-x86-64 -B x86-64 --rename-section .data=.this-is-a-really-long-name empty output.elf

ELF Tool Chain readelf by default shows:
$ readelf -S output.elf
There are 5 section headers, starting at offset 0x78:

Section Headers:
  [Nr] Name              Type             Address           Offset
       Size              EntSize          Flags  Link  Info  Align
  [ 0]                   NULL             0000000000000000  00000000
       0000000000000000  0000000000000000           0     0     0
  [ 1] .this-is-a-really PROGBITS         0000000000000000  00000040
       0000000000000000  0000000000000000  WA       0     0     1
  [ 2] .shstrtab         STRTAB           0000000000000000  00000040
       0000000000000038  0000000000000000           0     0     1
  [ 3] .symtab           SYMTAB           0000000000000000  000001b8
       0000000000000078  0000000000000018           4     2     8
  [ 4] .strtab           STRTAB           0000000000000000  00000230
       000000000000003a  0000000000000000           0     0     1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings)
  I (info), L (link order), G (group), x (unknown)
  O (extra OS processing required) o (OS specific), p (processor specific)

GNU readelf 2.33.1 shows:
$ /usr/local/bin/readelf -S output.elf
There are 5 section headers, starting at offset 0x78:

Section Headers:
  [Nr] Name              Type             Address           Offset
       Size              EntSize          Flags  Link  Info  Align
  [ 0]                   NULL             0000000000000000  00000000
       0000000000000000  0000000000000000           0     0     0
  [ 1] .this-is-a-really PROGBITS         0000000000000000  00000040
       0000000000000000  0000000000000000  WA       0     0     1
  [ 2] .shstrtab         STRTAB           0000000000000000  00000040
       0000000000000038  0000000000000000           0     0     1
  [ 3] .symtab           SYMTAB           0000000000000000  000001b8
       0000000000000078  0000000000000018           4     2     8
  [ 4] .strtab           STRTAB           0000000000000000  00000230
       000000000000003a  0000000000000000           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),
  l (large), p (processor specific)

(These differ only in the key.)

With -W GNU readelf shows:
$ /usr/local/bin/readelf -S -W output.elf 
There are 5 section headers, starting at offset 0x78:

Section Headers:
  [Nr] Name              Type            Address          Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            0000000000000000 000000 000000 00      0   0  0
  [ 1] .this-is-a-really-long-name PROGBITS        0000000000000000 000040 000000 00  WA  0   0  1
  [ 2] .shstrtab         STRTAB          0000000000000000 000040 000038 00      0   0  1
  [ 3] .symtab           SYMTAB          0000000000000000 0001b8 000078 18      4   2  8
  [ 4] .strtab           STRTAB          0000000000000000 000230 00003a 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),
  l (large), p (processor specific)

While ELF Tool Chain prints on one line but does not widen the name:

$ readelf -S -W output.elf
There are 5 section headers, starting at offset 0x78:

Section Headers:
  [Nr] Name              Type            Addr             Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            0000000000000000 000000 000000 00      0   0  0
  [ 1] .this-is-a-really PROGBITS        0000000000000000 000040 000000 00  WA  0   0  1
  [ 2] .shstrtab         STRTAB          0000000000000000 000040 000038 00      0   0  1
  [ 3] .symtab           SYMTAB          0000000000000000 0001b8 000078 18      4   2  8
  [ 4] .strtab           STRTAB          0000000000000000 000230 00003a 00      0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings)
  I (info), L (link order), G (group), x (unknown)
  O (extra OS processing required) o (OS specific), p (processor specific)
Comment 2 Ed Maste freebsd_committer 2021-02-02 14:33:08 UTC
Aside, readelf -t does display the full name
Comment 3 commit-hook freebsd_committer 2021-02-03 21:26:03 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=847dfd2803f6c8b077e3ebc68e35adff2c79a65f

commit 847dfd2803f6c8b077e3ebc68e35adff2c79a65f
Author:     Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2021-02-02 14:35:04 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2021-02-03 21:24:22 +0000

    readelf: do not trucate section name with -W

    PR:             246015
    Reviewed by:    cem
    Sponsored by:   The FreeBSD Foundation
    Differential Revision: https://reviews.freebsd.org/D28461

 contrib/elftoolchain/readelf/readelf.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
Comment 4 commit-hook freebsd_committer 2021-02-18 19:43:13 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=207f4289711423b4ffb2f92520b8f2a4a03350de

commit 207f4289711423b4ffb2f92520b8f2a4a03350de
Author:     Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2021-02-02 14:35:04 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2021-02-18 19:31:28 +0000

    readelf: do not trucate section name with -W

    PR:             246015
    Reviewed by:    cem
    Sponsored by:   The FreeBSD Foundation
    Differential Revision: https://reviews.freebsd.org/D28461

    (cherry picked from commit 847dfd2803f6c8b077e3ebc68e35adff2c79a65f)

 contrib/elftoolchain/readelf/readelf.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
Comment 5 Kubilay Kocak freebsd_committer freebsd_triage 2021-02-23 01:49:06 UTC
^Triage: Assign to committer resolving, track merges to stable/*