You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A C identifier name section consists of isalnum characters and _. . is disallowed.
GNU ld's rule is
__start_/__stop_ references from a live input section retains all C identifier name sections.
(--gc-sections is based on input sections. A live input section indicates that the section is retained, due to a relocation chain from a GC root).
In LLD<=12, the rule is:
__start_/__stop_ references from a live input section retains all non-SHF_LINK_ORDER C identifier name sections.
(Example SHF_LINK_ORDER C identifier name sections: __patchable_function_entries (-fpatchable-function-entry), __sancov_guards (clang -fsanitize-coverage=trace-pc-guard, before clang 13))
In LLD>=13, the default rule is:
__start_/__stop_ references from a live input section retains all non-SHF_LINK_ORDER non-SHF_GROUP C identifier name sections.
(SHF_GROUP is to allow more __llvm_prf_cnts/__llvm_prf_data sections to be GCable.)
With ld.lld -z start-stop-gc (requires https://reviews.llvm.org/D96914), the (unhelpful in many cases) rule will be dropped entirely:
__start_/__stop_ references do not retain C identifier name sections.
i.e. All C identifier name sections will be GCable.
(Note, a KEEP(...) command in linker scripts makes all the matched input sections GC roots.)
HAVE_LD_DEAD_CODE_DATA_ELIMINATION (--gc-sections) is currently not very common, but the adoption is rising. The kernel has a large number of __start_/__stop_ sections, so understanding whether ld.lld -z start-stop-gc can cause breakage will be useful. We probably need a thorough test.
If a link has different sizes with ld.lld -z start-stop-gc, this means some C identifier name sections (and other sections reachable via relocation chain) can now be GCed.
If nothing breaks => cool, we are now able to GC some unnecessarily retained sections.
If something breaks => we should think whether we should use
KEEP(...) command in a linker script => no-brainer but it can unnecessarily retain sections which are otherwise unneeded.
Add a relocation from the user section to the metadata section (preferably R_*_NONE).
The text was updated successfully, but these errors were encountered:
MaskRay
changed the title
ld.lld "Don't let __start_/__stop_ retain non-SHF_LINK_ORDER C identifier name sections"
ld.lld -z start-stop-gc (GC of C identifier name sections)
Feb 26, 2021
@MaskRay is there anything more you'd like to do here? I'm going to close this out pre-emptively, but please do reopen with more info if you have more thoughts here.
https://lists.llvm.org/pipermail/llvm-dev/2021-February/148682.html I am thinking whether we can change the existing
ld.lld --gc-sections
rule about C identifier name sections.https://maskray.me/blog/2021-01-31-metadata-sections-comdat-and-shf-link-order has more information. You may skip the paragraphs before "C identifier name sections".
A C identifier name section consists of
isalnum
characters and_
..
is disallowed.GNU ld's rule is
(
--gc-sections
is based on input sections. A live input section indicates that the section is retained, due to a relocation chain from a GC root).In LLD<=12, the rule is:
(Example SHF_LINK_ORDER C identifier name sections:
__patchable_function_entries
(-fpatchable-function-entry
),__sancov_guards
(clang -fsanitize-coverage=trace-pc-guard
, before clang 13))In LLD>=13, the default rule is:
(SHF_GROUP is to allow more
__llvm_prf_cnts
/__llvm_prf_data
sections to be GCable.)With
ld.lld -z start-stop-gc
(requires https://reviews.llvm.org/D96914), the (unhelpful in many cases) rule will be dropped entirely:i.e. All C identifier name sections will be GCable.
(Note, a
KEEP(...)
command in linker scripts makes all the matched input sections GC roots.)HAVE_LD_DEAD_CODE_DATA_ELIMINATION
(--gc-sections
) is currently not very common, but the adoption is rising. The kernel has a large number of__start_
/__stop_
sections, so understanding whetherld.lld -z start-stop-gc
can cause breakage will be useful. We probably need a thorough test.If a link has different sizes with
ld.lld -z start-stop-gc
, this means some C identifier name sections (and other sections reachable via relocation chain) can now be GCed.KEEP(...)
command in a linker script => no-brainer but it can unnecessarily retain sections which are otherwise unneeded.R_*_NONE
).The text was updated successfully, but these errors were encountered: