When link-time garbage collection is in use (-gc-sections), it is often useful to mark sections that should not be eliminated. This is accomplished by surrounding an input section's wildcard entry with KEEP().
Patch implements that command.
Details
Diff Detail
Event Timeline
What's the performance impact of this change? This change made the linker compare all discarded section names against all rules in linker scripts, which can be expensive. Of course that depends on input, but O(n*m) where n is the number of discarded sections and m is the number of section rules is a bit scary.
ELF/LinkerScript.cpp | ||
---|---|---|
46–52 | You want to define template <class ELFT> SectionRule *LinkerScript::find(InputSectionBase<ELFT> *S) { for (SectionRule &R : Sections) if (R.match(S)) return &R; return nullptr; } and use it both from shouldKeep and from getOutputSection. | |
384 | Why did you change this? | |
389–396 | This should be a regular member function rather than a closure. | |
413 | Please use setError() in the linker script as other code does. |
That really depends I guess. Should be tested on real app that uses the features of LS. Currently I think it is not in the state when valid tests can be performed.
There are lot of possible ways to optimize I believe, but for now I suggest to leave this one implementation.
ELF/LinkerScript.cpp | ||
---|---|---|
384 | I changed that when modified readOutputSectionDescription() as well. So this change is to match the style of readOutputSectionDescription() which is called from readSections(). Not sure it is fine for this patch, probably separate patch for both is better. I returned that back as mentioned above refactor patch has it. |
- Addressed review comments.
- Updated testcase: added case when section name matches two entries in the SECTIONS directive, the first one doesn't have KEEP, the second one does.
test/ELF/linkerscript-sections-keep.s | ||
---|---|---|
53 | Yes, that is the test I had in mind, thanks. |
Please do not over use friend. No one but LinkerScript should use SectionRule, so you want to make the member public.