Index: ELF/LinkerScript.h =================================================================== --- ELF/LinkerScript.h +++ ELF/LinkerScript.h @@ -190,7 +190,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; @@ -242,7 +242,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: ELF/LinkerScript.cpp =================================================================== --- ELF/LinkerScript.cpp +++ ELF/LinkerScript.cpp @@ -914,10 +914,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 = currentLocation(); + E = [=](uint64_t Dot) { + return getSymbolValue(Loc, Name, Dot) + E(Dot); + }; + } return new SymbolAssignment(Name, E); } @@ -1799,7 +1804,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: test/ELF/linkerscript/segment-start.s =================================================================== --- test/ELF/linkerscript/segment-start.s +++ 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: test/ELF/linkerscript/symbol-assignexpr.s =================================================================== --- test/ELF/linkerscript/symbol-assignexpr.s +++ 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: