[lld] r265523 - [ELF] - Teach linkerscript error handler to show full script line and column marker on error.
Rafael EspĂndola via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 6 07:58:58 PDT 2016
Nice! :-)
On 6 April 2016 at 04:08, George Rimar via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
> Author: grimar
> Date: Wed Apr 6 03:08:40 2016
> New Revision: 265523
>
> URL: http://llvm.org/viewvc/llvm-project?rev=265523&view=rev
> Log:
> [ELF] - Teach linkerscript error handler to show full script line and column marker on error.
>
> When error, this adds the text line of script to the output
> and a marks exact incorrect token under it:
>
> line 1: <error text here>
> UNKNOWN_TAG {
> ^
>
> Differential revision: http://reviews.llvm.org/D18699
>
> Modified:
> lld/trunk/ELF/LinkerScript.cpp
> lld/trunk/test/ELF/linkerscript-diagnostic.s
>
> Modified: lld/trunk/ELF/LinkerScript.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=265523&r1=265522&r2=265523&view=diff
> ==============================================================================
> --- lld/trunk/ELF/LinkerScript.cpp (original)
> +++ lld/trunk/ELF/LinkerScript.cpp Wed Apr 6 03:08:40 2016
> @@ -138,6 +138,7 @@ private:
> void readSectionPatterns(StringRef OutSec, bool Keep);
>
> size_t getPos();
> + void printErrorPos();
> std::vector<uint8_t> parseHex(StringRef S);
>
> StringSaver Saver;
> @@ -172,11 +173,31 @@ void ScriptParser::run() {
> }
> }
>
> +// Returns the line that the character S[Pos] is in.
> +static StringRef getLine(StringRef S, size_t Pos) {
> + size_t Begin = S.rfind('\n', Pos);
> + size_t End = S.find('\n', Pos);
> + Begin = (Begin == StringRef::npos) ? 0 : Begin + 1;
> + if (End == StringRef::npos)
> + End = S.size();
> + // rtrim for DOS-style newlines.
> + return S.substr(Begin, End - Begin).rtrim();
> +}
> +
> +void ScriptParser::printErrorPos() {
> + StringRef Tok = Tokens[Pos == 0 ? 0 : Pos - 1];
> + StringRef Line = getLine(Input, Tok.data() - Input.data());
> + size_t Col = Tok.data() - Line.data();
> + error(Line);
> + error(std::string(Col, ' ') + "^");
> +}
> +
> // We don't want to record cascading errors. Keep only the first one.
> void ScriptParser::setError(const Twine &Msg) {
> if (Error)
> return;
> error("line " + Twine(getPos()) + ": " + Msg);
> + printErrorPos();
> Error = true;
> }
>
>
> Modified: lld/trunk/test/ELF/linkerscript-diagnostic.s
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript-diagnostic.s?rev=265523&r1=265522&r2=265523&view=diff
> ==============================================================================
> --- lld/trunk/test/ELF/linkerscript-diagnostic.s (original)
> +++ lld/trunk/test/ELF/linkerscript-diagnostic.s Wed Apr 6 03:08:40 2016
> @@ -42,3 +42,25 @@
> # RUN: echo ".temp + { *(.temp) } }" >> %t.script
> # RUN: not ld.lld -shared %t -o %t1 --script %t.script 2>&1 | FileCheck -check-prefix=ERR5 %s
> # ERR5: line 6:
> +
> +## Check that text of lines and pointer to 'bad' token are working ok.
> +# RUN: echo "UNKNOWN_TAG {" > %t.script
> +# RUN: echo ".text : { *(.text) }" >> %t.script
> +# RUN: echo ".keep : { *(.keep) }" >> %t.script
> +# RUN: echo ".temp : { *(.temp) } }" >> %t.script
> +# RUN: not ld.lld -shared %t -o %t1 --script %t.script > %t.log 2>&1
> +# RUN: FileCheck -check-prefix=ERR6 %s < %t.log
> +# ERR6: line 1:
> +# ERR6-NEXT: UNKNOWN_TAG {
> +# RUN: grep '^^' %t.log
> +
> +## One more check that text of lines and pointer to 'bad' token are working ok.
> +# RUN: echo "SECTIONS {" > %t.script
> +# RUN: echo ".text : { *(.text) }" >> %t.script
> +# RUN: echo ".keep : { *(.keep) }" >> %t.script
> +# RUN: echo "boom .temp : { *(.temp) } }" >> %t.script
> +# RUN: not ld.lld -shared %t -o %t1 --script %t.script > %t.log 2>&1
> +# RUN: FileCheck -check-prefix=ERR7 %s < %t.log
> +# ERR7: line 4: : expected, but got .temp
> +# ERR7-NEXT: boom .temp : { *(.temp) } }
> +# RUN: grep '^ ^' %t.log
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list