tl;dr With --gc-sections, I think the rule "__start_foo/__stop_foo references from live sections retains all non-SHF_LINK_ORDER input sections foo" does not cary its weight, so I'd like to drop it entirely in ⚙ D96914 [ELF] Add -z start-stop-gc to let __start_/__stop_ not retain C identifier name sections
I have done a large-scale internal test with huge amount of OSS usage and spotted two issues:
(1) Linking systemd. systemd/bus-error.h at main · systemd/systemd · GitHub there will be an `undefined symbol: __start_SYSTEMD_BUS_ERROR_MAP` error. Supposedly it can be trivially fixed by using undefined weak symbols on __start_/__stop_.
(2) Linking Swift. There will be errors like `undefined hidden symbol: __start_swift5_protocols`.
swift/SwiftRT-ELF.cpp at main · apple/swift · GitHub
It seems that trivially making `extern const char __start_##name` does not work.
The code relies on some `swift5_*` input sections being GC root.
(If someone can file an issue to Swift, I'd appreciate that.)
(If Swift folks can fix it, I'll give my big thanks:)
This can still potentially break some propritary code so I am sending this heads-up.
I'll place rationale below (it is complicated).
The current rule is:
__start_/__stop_ references retains all non-SHF_LINK_ORDER C identifier name sections.
After ⚙ D96753 [lld][ELF] __start_/__stop_ refs don't retain C-ident named group sections , it will become
__start_/__stop_ references retains all non-SHF_LINK_ORDER non-SHF_GROUP C identifier name sections.
(The section group special case is to allow garbage collecting __llvm_prf_* sections for -fprofile-generate/-fprofile-instr-generate. The saving is huge.)
Personally I'd drop the rule entirely (D96914) (get support from jhenderson and phosek), i.e.
__start_/__stop_ references do not retain C identifier name sections.
and hope folks can fix Swift/systemd to not rely on the original rule.