[ELF] Allow references to reserved symbols in linker scripts
This requires collectign all symbols referenced in the linker script
and adding them to symbol table as undefined symbol.
Differential Revision: https://reviews.llvm.org/D31147
llvm-svn: 298577
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index f98e689..adb7ce8 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -999,8 +999,8 @@
if (SymbolBody *B = findSymbol(S)) {
if (auto *D = dyn_cast<DefinedRegular>(B))
return {D->Section, D->Value};
- auto *C = cast<DefinedCommon>(B);
- return {InX::Common, C->Offset};
+ if (auto *C = dyn_cast<DefinedCommon>(B))
+ return {InX::Common, C->Offset};
}
error(Loc + ": symbol not found: " + S);
return 0;
@@ -1867,8 +1867,11 @@
return [=] { return V; };
// Tok is a symbol name.
- if (Tok != "." && !isValidCIdentifier(Tok))
- setError("malformed number: " + Tok);
+ if (Tok != ".") {
+ if (!isValidCIdentifier(Tok))
+ setError("malformed number: " + Tok);
+ Script->Opt.UndefinedSymbols.push_back(Tok);
+ }
return [=] { return Script->getSymbolValue(Location, Tok); };
}