% cat a.s .section cident,"a",@progbits .byte 0 % as a.s -o a.o % ld.bfd -r --gc-sections --print-gc-sections -u __start_cident a.o -o a ld.bfd: removing unused section 'cident' in file 'a.o' % ld.bfd --gc-sections --print-gc-sections -u __start_cident a.o -o a ld.bfd: warning: cannot find entry symbol _start; not setting start address Non-relocatable links retain 'cident' while relocatable links discard it. I don't know whether the rule should be consistent here. I am also thinking how 'cident' should behave when it is in a section group.
A relocatable link doesn't create __start and __end symbols, thus the undefined reference to __start_cident is not related to any section. Use -Ur if you want them.
(In reply to Andreas Schwab from comment #1) > A relocatable link doesn't create __start and __end symbols, thus the > undefined reference to __start_cident is not related to any section. Use > -Ur if you want them. The documentation says -Ur is equivalent to -r for non-C++ programs @kindex -Ur @cindex constructors @item -Ur For anything other than C++ programs, this option is equivalent to @samp{-r}: it generates relocatable output---i.e., an output file that can in turn serve as input to @command{ld}. When linking C++ programs, @samp{-Ur} @emph{does} resolve references to constructors, unlike @samp{-r}. It does not work to use @samp{-Ur} on files that were themselves linked with @samp{-Ur}; once the constructor table has been built, it cannot be added to. Use @samp{-Ur} only for the last partial link, and @samp{-r} for the others. ld -r is allowed to not defined __start_cindent, but it should not discard the sections. Not only -u __start_cindent does not retain 'cindent', a relocation '.quad __start_cindent' does not retain 'cindent' as well. I don't think this is invalid.
__start_cident isn't meaningful for -r since the output cident section isn't the final one. Try "-T keep.t" with --keep.t-- SECTIONS { cident : { KEEP(*(cident)) } } --