Bug 29566 - objdump -p considers an empty .gnu.version_r invalid
Summary: objdump -p considers an empty .gnu.version_r invalid
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: 2.40
Assignee: Alan Modra
Depends on:
Reported: 2022-09-13 07:18 UTC by Fangrui Song
Modified: 2022-09-21 12:41 UTC (History)
1 user (show)

See Also:
Last reconfirmed:


Note You need to log in before you can comment on or make changes to this bug.
Description Fangrui Song 2022-09-13 07:18:19 UTC
% cat a.yaml
--- !ELF
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_EXEC
  Machine: EM_X86_64
  - Name:            .gnu.version_r
    Type:            SHT_GNU_verneed
    Flags:           [ SHF_ALLOC ]
  - Name:    f1
    Binding: STB_GLOBAL
% yaml2obj a.yaml -o a.o    # a utility from llvm-project . On Debian, the package "llvm" contains it.
% objdump -p a.o

a.o:     file format elf64-x86-64
objdump: a.o: .gnu.version_r invalid entry
objdump: warning: private headers incomplete: bad value

% readelf -V a.o

Version needs section '.gnu.version_r' contains 0 entries:
 Addr: 0x0000000000000000  Offset: 0x000040  Link: 3 (.dynstr)


objdump -p gives a warning while readelf -V doesn't.
Comment 1 Alan Modra 2022-09-21 07:33:13 UTC
Is there any point in allowing an empty .gnu.version_r section?
Comment 2 Fangrui Song 2022-09-21 08:32:44 UTC
The spec (https://sourceware.org/gnu-gabi/program-loading-and-dynamic-linking.txt) doesn't reject it. For a section whose content is a concatenated N items, the ELF spirits typically allows N==0, as otherwise it needs an additional sentence to disallow the case, which is unnecessary.

It seems that the reference implementation of Go may generate .gnu.version_r at least in some cases: https://github.com/llvm/llvm-project/issues/57707
Comment 3 Alan Modra 2022-09-21 10:09:26 UTC
OK, so if we have linkers that produce them, I suppose they ought to be allowed.  Easily done.
Comment 4 Sourceware Commits 2022-09-21 12:40:28 UTC
The master branch has been updated by Alan Modra <amodra@sourceware.org>:


commit f9a59eea78428159a9522bd64ec354a872f1dc31
Author: Alan Modra <amodra@gmail.com>
Date:   Wed Sep 21 19:34:08 2022 +0930

    PR29566, objdump -p considers an empty .gnu.version_r invalid
    Allow and ignore an empty section.
            PR 29566
            * elf.c (bfd_section_from_shdr): Don't set elf_dynverdef or
            elf_dynverref for empty sections.
            (_bfd_elf_slurp_version_tables): Remove now redundant tests.
Comment 5 Alan Modra 2022-09-21 12:41:04 UTC
Fixed for 2.40