[ELF] Don't create empty output section for unreferenced PROVIDEs
authorJames Henderson <jh7370@my.bristol.ac.uk>
Tue, 3 Jul 2018 09:23:25 +0000 (09:23 +0000)
committerJames Henderson <jh7370@my.bristol.ac.uk>
Tue, 3 Jul 2018 09:23:25 +0000 (09:23 +0000)
commitb427d4eced315ffa2b6f5bd0f7ee24c9c869126a
tree22b5411a2ccc68f84a137f2332a296cb58a7752e
parent3897ded69101a87b6451d51bbb2e5b2e81387a53
[ELF] Don't create empty output section for unreferenced PROVIDEs

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).

Reviewed By: grimar

Differential Revision: https://reviews.llvm.org/D48771

llvm-svn: 336184
lld/ELF/LinkerScript.cpp
lld/test/ELF/linkerscript/provide-empty-section.s [new file with mode: 0644]