[ELF] - Don't segfault when accessing location counter inside MEMORY command.
We would previously crash on next script:
MEMORY { name : ORIGIN = .; }
Patch fixes that.
Differential revision: https://reviews.llvm.org/D36138
llvm-svn: 311073
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 805d50b..c146c46 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -842,8 +842,13 @@
}
ExprValue LinkerScript::getSymbolValue(const Twine &Loc, StringRef S) {
- if (S == ".")
- return {CurAddressState->OutSec, Dot - CurAddressState->OutSec->Addr, Loc};
+ if (S == ".") {
+ if (CurAddressState)
+ return {CurAddressState->OutSec, Dot - CurAddressState->OutSec->Addr,
+ Loc};
+ error(Loc + ": unable to get location counter value");
+ return 0;
+ }
if (SymbolBody *B = Symtab->find(S)) {
if (auto *D = dyn_cast<DefinedRegular>(B))
return {D->Section, D->Value, Loc};