Index: ELF/LinkerScript.cpp =================================================================== --- ELF/LinkerScript.cpp +++ ELF/LinkerScript.cpp @@ -812,8 +812,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(B)) return {D->Section, D->Value, Loc}; Index: test/ELF/linkerscript/memory-err.s =================================================================== --- test/ELF/linkerscript/memory-err.s +++ test/ELF/linkerscript/memory-err.s @@ -0,0 +1,5 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t +# RUN: echo "MEMORY { name : ORIGIN = .; }" > %t.script +# RUN: not ld.lld -shared -o %t2 --script %t.script %t 2>&1 | FileCheck %s +# CHECK: error: {{.*}}.script:1: unable to get location counter value