[hjl@gnu-cfl-2 retain-2]$ cat x.s .type _start,"function" .section .text,"axR",%progbits .global _start _start: .nop [hjl@gnu-cfl-2 retain-2]$ make ./as -o x.o x.s ./ld -e _start -o x x.o readelf -h x ELF Header: Magic: 7f 45 4c 46 02 01 01 03 00 00 00 00 00 00 00 00 Class: ELF64 Data: 2's complement, little endian Version: 1 (current) OS/ABI: UNIX - GNU ABI Version: 0 Type: EXEC (Executable file) Machine: Advanced Micro Devices X86-64 Version: 0x1 Entry point address: 0x401000 Start of program headers: 64 (bytes into file) Start of section headers: 4352 (bytes into file) Flags: 0x0 Size of this header: 64 (bytes) Size of program headers: 56 (bytes) Number of program headers: 4 Size of section headers: 64 (bytes) Number of section headers: 6 Section header string table index: 5 [hjl@gnu-cfl-2 retain-2]$ Since SHF_GNU_RETAIN has no impact on shared object and executable, they shouldn't be marked with ELFOSABI_GNU.
SHF_GNU_RETAIN is in the OS-specific range, the marking is required to properly recognize it.
(In reply to Andreas Schwab from comment #1) > SHF_GNU_RETAIN is in the OS-specific range, the marking is required to > properly recognize it. SHF_GNU_RETAIN does nothing on shared object and executable. Linker doesn't even mark it on shared object and executable.
That is irrelevant. Without the marking the bit has no defined meaning.
The master branch has been updated by H.J. Lu <hjl@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=04f8967487515179cc6dfc7c828f77eeb75c08d3 commit 04f8967487515179cc6dfc7c828f77eeb75c08d3 Author: H.J. Lu <hjl.tools@gmail.com> Date: Fri Dec 18 04:24:26 2020 -0800 elf: Copy elf_gnu_osabi_retain only for relocatable link Copy elf_gnu_osabi_retain from input only for relocatable link since SHF_GNU_RETAIN has no impact on non-relocatable outputs. bfd/ PR ld/27091 * elflink.c (elf_link_input_bfd): Copy elf_gnu_osabi_retain from input only for relocatable link. ld/ PR ld/27091 * testsuite/ld-elf/retain7.s: New file. * testsuite/ld-elf/retain7a.d: Likewise. * testsuite/ld-elf/retain7b.d: Likewise.
Fixed.