[PATCH] D27194: [ELF] Print file:line for 'symbol not found' error
Rafael Avila de Espindola via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 30 02:58:42 PST 2016
LGTM
Eugene Leviant via Phabricator <reviews at reviews.llvm.org> writes:
> evgeny777 created this revision.
> evgeny777 added reviewers: ruiu, rafael.
> evgeny777 added subscribers: grimar, ikudrin, llvm-commits.
> evgeny777 set the repository for this revision to rL LLVM.
> evgeny777 added a project: lld.
>
> Repository:
> rL LLVM
>
> https://reviews.llvm.org/D27194
>
> Files:
> ELF/LinkerScript.cpp
> ELF/LinkerScript.h
> test/ELF/linkerscript/segment-start.s
> test/ELF/linkerscript/symbol-assignexpr.s
>
>
> 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:
> 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: 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<PhdrEntry<ELFT>> &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<ELFT>();
> }
>
> -template <class ELFT> uint64_t LinkerScript<ELFT>::getSymbolValue(StringRef S) {
> +template <class ELFT>
> +uint64_t LinkerScript<ELFT>::getSymbolValue(const Twine &Loc, StringRef S) {
> if (SymbolBody *B = Symtab<ELFT>::X->find(S))
> return B->getVA<ELFT>();
> - 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/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:
> 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: 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<PhdrEntry<ELFT>> &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<ELFT>();
> }
>
> -template <class ELFT> uint64_t LinkerScript<ELFT>::getSymbolValue(StringRef S) {
> +template <class ELFT>
> +uint64_t LinkerScript<ELFT>::getSymbolValue(const Twine &Loc, StringRef S) {
> if (SymbolBody *B = Symtab<ELFT>::X->find(S))
> return B->getVA<ELFT>();
> - 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); }};
> }
More information about the llvm-commits
mailing list