LLD removes empty output sections otherwise specified in the linker script. Prior to this change however, if section descriptions included ANY kind of symbol assignment, then the consequent output section would not be removed, even if the assignment was marked with PROVIDE and not actually triggered (i.e. the symbol was never referenced). This change modifies the isDiscarable function to ignore such directives when determining whether a section should be discarded, in keeping with bfd's behaviour. Symbol assignments that do result in a symbol definition will continue to result in a kept section (this is not actually the same as bfd's behaviour, but it is simpler, and probably makes more sense).
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
LGTM with few nits.
test/ELF/linkerscript/provide-empty-section.s | ||
---|---|---|
5 | I would avoid using additional input file and -defsym and be more explicit # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %tundefined.o # RUN: echo "foo=42" | llvm-mc -filetype=obj -triple=x86_64-unknown-linux - -o %tdefined.o # RUN: echo "call foo" | llvm-mc -filetype=obj -triple=x86_64-unknown-linux - -o %treference.o | |
11 | Let's do it a single line. That is what we usually try to do if possible and also it avoids multiple echo calls. # RUN: echo "SECTIONS { .bar : { PROVIDE(foo = .); } }" > %t.script |
ELF/LinkerScript.cpp | ||
---|---|---|
841 | I also was wondered if we might want to abstract from Provide here and use something like if (Cmd->Name != "." && !Cmd->Sym) ... But I am not sure it worth doing. |
Rather than rush this in before I go home today, I'll wait until Monday before putting it in, assuming there are no objections by then.
ELF/LinkerScript.cpp | ||
---|---|---|
841 | My one concern with this change is that it relies on us setting Provide to false when we define a symbol because of it. I'll try with your suggested change on Monday before putting this in, as I think it feels a little safer. Are you happy with it going straight in if I make that change? | |
test/ELF/linkerscript/provide-empty-section.s | ||
5 | Ah, I didn't know about that technique. I'll make that change, no problem. | |
11 | Will do. |
ELF/LinkerScript.cpp | ||
---|---|---|
841 | Yep. |
I also was wondered if we might want to abstract from Provide here and use something like
But I am not sure it worth doing.