[lld][ELF] __start_/__stop_ refs don't retain C-ident named group sections
authorPetr Hosek <phosek@google.com>
Tue, 16 Feb 2021 07:41:16 +0000 (23:41 -0800)
committerPetr Hosek <phosek@google.com>
Sun, 21 Feb 2021 06:22:05 +0000 (22:22 -0800)
commit1a3f3a3fa17909aa22958a4f06b1a357a75b1bb4
tree0cb8829632342ea42935c5e46e5b8332e7ae2b5b
parent0b417ba20f21c7057cf9c0fed8cbc761331f4022
[lld][ELF] __start_/__stop_ refs don't retain C-ident named group sections

The special root semantics for identifier-named sections is meant
specifically for the metadata sections. In the context of group
semantics, where group members are always retained or discarded as a
unit, it's natural not to have this semantics apply to a section in a
group, otherwise we would never discard the group defeating the purpose
of using the group in the first place.

This change modifies the GC behavior so that __start_/__stop_ references
don't retain C identifier named sections in section groups which allows
for these groups to be collected. This matches the behavior of BFD ld.

The only kind of existing case that might break is interdependent
metadata sections that are all in a group together, but that group
doesn't contain any other sections referenced by anything except
implicit inclusion in a `__start_` and/or `__stop_`-referenced
identifier-named section, but such cases should be unlikely.

Differential Revision: https://reviews.llvm.org/D96753
lld/ELF/MarkLive.cpp
lld/test/ELF/gc-sections-startstop.s [new file with mode: 0644]
lld/test/ELF/startstop-gccollect.s [deleted file]