[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
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index aacb5d8..efb3c4a 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -350,7 +350,9 @@
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