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
- Repository
- rL LLVM
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 ↗ | (On Diff #47908) | 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 ↗ | (On Diff #47908) | Why did you change this? |
389–396 ↗ | (On Diff #47908) | This should be a regular member function rather than a closure. |
413 ↗ | (On Diff #47908) | 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 ↗ | (On Diff #47908) | 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. |
ELF/LinkerScript.cpp | ||
---|---|---|
55 ↗ | (On Diff #48164) | return R && R->Keep; |
395 ↗ | (On Diff #48164) | Did you test this code with an incomplete input? I think this will fall into an infinite loop if you give SECTIONS { .foo : { KEEP( |
396 ↗ | (On Diff #48164) | Why don't you add Keep as a parameter to the constructor? |
ELF/LinkerScript.h | ||
58 ↗ | (On Diff #48164) | Remove LinkerScript::. |
- Addressed Rui's comments.
ELF/LinkerScript.cpp | ||
---|---|---|
395 ↗ | (On Diff #48164) | Hmm you're right, my mistake. |
- 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 | ||
---|---|---|
52 ↗ | (On Diff #48490) | Yes, that is the test I had in mind, thanks. |