summaryrefslogtreecommitdiffstats
path: root/lld/ELF
diff options
context:
space:
mode:
authorPetr Hosek <phosek@chromium.org>2017-03-23 03:52:34 +0000
committerPetr Hosek <phosek@chromium.org>2017-03-23 03:52:34 +0000
commit30f16b23398f44926656d221131f1b015f424b8f (patch)
tree200bf80bdd3ce5aec9a93450292d5689c6721607 /lld/ELF
parent968381ef22f9d782a8097b05a3eb5781e58eebb7 (diff)
downloadbcm5719-llvm-30f16b23398f44926656d221131f1b015f424b8f.tar.gz
bcm5719-llvm-30f16b23398f44926656d221131f1b015f424b8f.zip
[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
Diffstat (limited to 'lld/ELF')
-rw-r--r--lld/ELF/Driver.cpp5
-rw-r--r--lld/ELF/LinkerScript.cpp11
-rw-r--r--lld/ELF/LinkerScript.h3
3 files changed, 15 insertions, 4 deletions
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 87a54304669..09c232a846c 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -921,6 +921,11 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &Args) {
if (ErrorCount)
return;
+ // Some symbols (such as __ehdr_start) are defined lazily only when there
+ // are undefined symbols for them, so we add these to trigger that logic.
+ for (StringRef Sym : Script->Opt.UndefinedSymbols)
+ Symtab.addUndefined(Sym);
+
for (auto *Arg : Args.filtered(OPT_wrap))
Symtab.wrap(Arg->getValue());
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index f98e689f0b9..adb7ce862bb 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -999,8 +999,8 @@ ExprValue LinkerScript::getSymbolValue(const Twine &Loc, StringRef S) {
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 @@ Expr ScriptParser::readPrimary() {
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); };
}
diff --git a/lld/ELF/LinkerScript.h b/lld/ELF/LinkerScript.h
index 00e4f9ec96e..6dc70518656 100644
--- a/lld/ELF/LinkerScript.h
+++ b/lld/ELF/LinkerScript.h
@@ -217,6 +217,9 @@ struct ScriptConfiguration {
// A map from memory region name to a memory region descriptor.
llvm::DenseMap<llvm::StringRef, MemoryRegion> MemoryRegions;
+
+ // A list of undefined symbols referenced by the script.
+ std::vector<llvm::StringRef> UndefinedSymbols;
};
class LinkerScript {
OpenPOWER on IntegriCloud