The attached patch adds support for the new SHF_GNU_RETAIN ELF section flag, which was discussed on the GNU gABI mailing list here: https://sourceware.org/pipermail/gnu-gabi/2020q3/000429.html The flag is GNU-specific so uses a bit in the SHF_MASKOS mask. Its precise definition is as follows: ======================================================================= Section Attribute Flags +-------------------------------------+ | Name | Value | +-------------------------------------+ | SHF_GNU_RETAIN | 0x200000 (1 << 21) | +-------------------------------------+ SHF_GNU_RETAIN The link editor should not garbage collect the section if it is unused. ======================================================================= The overall intention for this new flag is to enable a new "retain" attribute to be applied to declarations of functions and data in the source code. This attribute can be used to ensure the definition associated with the declaration is present in the linked output file, even if linker garbage collection would normally remove the containing section because it is unused. The new ".retain" assembler directive can be used to apply SHF_GNU_RETAIN to a section. GCC will emit this directive when assembling definitions of functions and data that have had the "retain" attribute applied. Note that there is *not* a direct mapping of SHF_GNU_RETAIN to the BFD section flag SEC_KEEP. SEC_KEEP would prevent the user being able to explicitly remove an SHF_GNU_RETAIN section by placing it in /DISCARD/, which could be necessary in some situations. I successfully regtested the patch for the Binutils, GAS and LD testsuites for the following CPUs, applying the "-elf" suffix when configuring: aarch64 alpha arc arm avr bfin bpf cr16 cris crx csky d10v d30v dlx epiphany fr30 frv ft32 h8300 hppa i386 ia64 ia64-vms ip2k iq2000 lm32 m32c m32r m68hc11 m68hc12 m68k mcore mep metag microblaze mips mmix moxie msp430 mt nds32 nfp nios2 or1k pj ppc pru riscv rl78 rx s12z s390 score sh sparc spu tic6x tilegx tilepro v850 vax visium wasm32 x86-64 x86 xc16x xgate xstormy16 xtensa z80 The new tests are passing for all targets except mmix-elf. This target has a lot of LD failures, particularly --gc-sections doesn't appear to have any effect. I don't know anything about the target, but I wonder if it should be added to the hard-coded list of targets that doesn't support --gc-sections. I have therefore XFAIL'd the new LD tests for this target. I also regtested for i386-pe, to ensure there was no spill-over of the new functionality into any non-ELF areas. Ok to apply? Thanks, Jozef