Bug 24627

Summary: readelf -V output is inconsistent
Product: binutils Reporter: Fangrui Song <i>
Component: binutilsAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: normal CC: nickc
Priority: P2    
Version: unspecified   
Target Milestone: ---   
Host: Target:
Build: Last reconfirmed:

Description Fangrui Song 2019-05-29 13:14:47 UTC
% readelf -V /lib/x86_64-linux-gnu/libc.so.6
Version symbols section '.gnu.version' contains 2247 entries:
 Addr: 0000000000016a3a  Offset: 0x016a3a  Link: 4 (.dynsym)
  000:   0 (*local*)      1b (GLIBC_PRIVATE)  1b (GLIBC_PRIVATE)  1c (GLIBC_2.3)  
  004:  1b (GLIBC_PRIVATE)  1b (GLIBC_PRIVATE)   0 (*local*)      1b (GLIBC_PRIVATE)
  ...

Version definition section '.gnu.version_d' contains 26 entries:
  Addr: 0x0000000000017bc8  Offset: 0x017bc8  Link: 5 (.dynstr)
  000000: Rev: 1  Flags: BASE  Index: 1  Cnt: 1  Name: libc.so.6
  0x001c: Rev: 1  Flags: none  Index: 2  Cnt: 1  Name: GLIBC_2.2.5
  ...

Version needs section '.gnu.version_r' contains 1 entry:
 Addr: 0x0000000000017f60  Offset: 0x017f60  Link: 5 (.dynstr)
  000000: Version: 1  File: ld-linux-x86-64.so.2  Cnt: 2
  0x0010:   Name: GLIBC_2.3  Flags: none  Version: 28
  ...

* In the output .gnu.version and .gnu.version_d, `Addr:` is indented by 2.
* `000000` probably should be printed as `0x0000`
Comment 1 Fangrui Song 2019-05-29 13:15:46 UTC
Sorry, in .gnu.version_d, `Addr:` is indented by 2.
Comment 2 Sourceware Commits 2019-05-30 09:19:19 UTC
The master branch has been updated by Nick Clifton <nickc@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=ae9ac79e5e291a2bc5c6620a10c37a3558d55d36

commit ae9ac79e5e291a2bc5c6620a10c37a3558d55d36
Author: Nick Clifton <nickc@redhat.com>
Date:   Thu May 30 10:17:29 2019 +0100

    Harmonize readelf's output for version sections.
    
    	PR 24627
    binutils * readelf.c (process_version_sections): Add 0x prefix to address
    	display.  Correct indentation.
    
    ld	* testsuite/ld-elf/ver_def.vd: Update expected output.
Comment 3 Nick Clifton 2019-05-30 09:28:22 UTC
Hi Fanguri,

  I would not call the output "ugly", rather I think that "inconsistent"
  would be a better word.

  Nevertheless I have applied a patch so that "Addr" is only intended by
  one space for three types of output, and that the address always
  receives a 0x prefix.

  The fact that a zero value does not receive a 0x prefix when displaying
  offsets into the section is an artefact of the printf function's '#' 
  formatting character and not something that we can control directly.
  (Well other than abandoning the use of the # formatter).  So I have not
  changed this.

Cheers
  Nick
Comment 4 Fangrui Song 2019-05-30 10:05:51 UTC
Thank you for your prompt fix!
Comment 5 Fangrui Song 2019-05-30 10:11:25 UTC
One remaining issue (after ae9ac79e5e291a2bc5c6620a10c37a3558d55d36). Does `000000: Rev: 1` below need a similar %# fix?

Version definition section '.gnu.version_d' contains 26 entries:
 Addr: 0x0000000000017bc8  Offset: 0x017bc8  Link: 5 (.dynstr)
  000000: Rev: 1  Flags: BASE  Index: 1  Cnt: 1  Name: libc.so.6
  0x001c: Rev: 1  Flags: none  Index: 2  Cnt: 1  Name: GLIBC_2.2.5
  0x0038: Rev: 1  Flags: none  Index: 3  Cnt: 2  Name: GLIBC_2.2.6