Index: lld/trunk/ELF/LinkerScript.h =================================================================== --- lld/trunk/ELF/LinkerScript.h +++ lld/trunk/ELF/LinkerScript.h @@ -193,7 +193,7 @@ public: virtual uint64_t getHeaderSize() = 0; - virtual uint64_t getSymbolValue(StringRef S) = 0; + virtual uint64_t getSymbolValue(const Twine &Loc, StringRef S) = 0; virtual bool isDefined(StringRef S) = 0; virtual bool isAbsolute(StringRef S) = 0; virtual const OutputSectionBase *getSymbolSection(StringRef S) = 0; @@ -245,7 +245,7 @@ void assignAddresses(std::vector &Phdrs); bool hasPhdrsCommands(); uint64_t getHeaderSize() override; - uint64_t getSymbolValue(StringRef S) override; + uint64_t getSymbolValue(const Twine &Loc, StringRef S) override; bool isDefined(StringRef S) override; bool isAbsolute(StringRef S) override; const OutputSectionBase *getSymbolSection(StringRef S) override; Index: lld/trunk/ELF/LinkerScript.cpp =================================================================== --- lld/trunk/ELF/LinkerScript.cpp +++ lld/trunk/ELF/LinkerScript.cpp @@ -901,10 +901,11 @@ return elf::getHeaderSize(); } -template uint64_t LinkerScript::getSymbolValue(StringRef S) { +template +uint64_t LinkerScript::getSymbolValue(const Twine &Loc, StringRef S) { if (SymbolBody *B = Symtab::X->find(S)) return B->getVA(); - error("symbol not found: " + S); + error(Loc + ": symbol not found: " + S); return 0; } @@ -1523,10 +1524,10 @@ return Cmd; } -static uint64_t getSymbolValue(StringRef S, uint64_t Dot) { +static uint64_t getSymbolValue(const Twine &Loc, StringRef S, uint64_t Dot) { if (S == ".") return Dot; - return ScriptBase->getSymbolValue(S); + return ScriptBase->getSymbolValue(Loc, S); } static bool isAbsolute(StringRef S) { @@ -1547,8 +1548,12 @@ } else { E = readExpr(); } - if (Op == "+=") - E = [=](uint64_t Dot) { return getSymbolValue(Name, Dot) + E(Dot); }; + if (Op == "+=") { + std::string Loc = getCurrentLocation(); + E = [=](uint64_t Dot) { + return getSymbolValue(Loc, Name, Dot) + E(Dot); + }; + } return new SymbolAssignment(Name, E); } @@ -1800,7 +1805,7 @@ // Tok is a symbol name. if (Tok != "." && !isValidCIdentifier(Tok)) setError("malformed number: " + Tok); - return {[=](uint64_t Dot) { return getSymbolValue(Tok, Dot); }, + return {[=](uint64_t Dot) { return getSymbolValue(Location, Tok, Dot); }, [=] { return isAbsolute(Tok); }, [=] { return ScriptBase->getSymbolSection(Tok); }}; } Index: lld/trunk/test/ELF/linkerscript/segment-start.s =================================================================== --- lld/trunk/test/ELF/linkerscript/segment-start.s +++ lld/trunk/test/ELF/linkerscript/segment-start.s @@ -24,4 +24,4 @@ // RUN: echo "SECTIONS { . = SEGMENT_START(\"foobar\", foo); }" > %t.script // RUN: not ld.lld %t.o %t.script -shared -o %t2.so 2>&1 \ // RUN: | FileCheck --check-prefix=ERR %s -// ERR: symbol not found: foo +// ERR: {{.*}}.script:1: symbol not found: foo Index: lld/trunk/test/ELF/linkerscript/symbol-assignexpr.s =================================================================== --- lld/trunk/test/ELF/linkerscript/symbol-assignexpr.s +++ lld/trunk/test/ELF/linkerscript/symbol-assignexpr.s @@ -38,7 +38,7 @@ # RUN: }" > %t2.script # RUN: not ld.lld -o %t2 --script %t2.script %t 2>&1 \ # RUN: | FileCheck -check-prefix=ERR %s -# ERR: symbol not found: symbol +# ERR: {{.*}}.script:1: symbol not found: symbol .global _start _start: