[ELF] Fix the semantic of PROVIDE in linker scripts.

PROVIDE request us to define a symbol only if it is referenced and is
not defined by any object included in the link. We created the
symbol in the symbol table no matter what.

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

llvm-svn: 276592
This commit is contained in:
Davide Italiano
2016-07-25 00:25:18 +00:00
parent 249b03effb
commit 373a533a0a
3 changed files with 29 additions and 5 deletions

View File

@@ -350,7 +350,9 @@ template <class ELFT> void LinkerScript<ELFT>::addScriptedSymbols() {
continue;
SymbolBody *B = Symtab<ELFT>::X->find(Cmd->Name);
if (!B || B->isUndefined())
// The semantic of PROVIDE is that of introducing a symbol only if
// it's not defined and there's at least a reference to it.
if ((!B && !Cmd->Provide) || (B && B->isUndefined()))
Symtab<ELFT>::X->addAbsolute(Cmd->Name,
Cmd->Hidden ? STV_HIDDEN : STV_DEFAULT);
else