% cat a.yaml --- !ELF FileHeader: Class: ELFCLASS64 Data: ELFDATA2LSB Type: ET_EXEC Machine: EM_X86_64 Sections: - Name: .gnu.version_r Type: SHT_GNU_verneed Flags: [ SHF_ALLOC ] DynamicSymbols: - 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.
Is there any point in allowing an empty .gnu.version_r section?
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
OK, so if we have linkers that produce them, I suppose they ought to be allowed. Easily done.
The master branch has been updated by Alan Modra <amodra@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=f9a59eea78428159a9522bd64ec354a872f1dc31 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.
Fixed for 2.40