[PATCH] D18699: [ELF] - Teach linkerscript error handler to show full script line + column marker on error.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 1 09:58:59 PDT 2016
grimar created this revision.
grimar added reviewers: ruiu, rafael.
grimar added subscribers: llvm-commits, grimar.
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 {
^
```
http://reviews.llvm.org/D18699
Files:
ELF/LinkerScript.cpp
test/ELF/linkerscript-diagnostic.s
Index: test/ELF/linkerscript-diagnostic.s
===================================================================
--- test/ELF/linkerscript-diagnostic.s
+++ test/ELF/linkerscript-diagnostic.s
@@ -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
+# FileCheck -check-prefix=ERR6 %s < %t.log
+# ERR6: line 1:
+# ERR6: UNKNOWN_TAG {
+# ERR6: {{[ ]{5}\^}}
+
+## 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
+# FileCheck -check-prefix=ERR7 %s < %t.log
+# ERR7: line 4:
+# ERR7: boom .temp : { *(.temp) }
+# ERR7: {{[ ]{7}\^}}
Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -138,6 +138,7 @@
void readSectionPatterns(StringRef OutSec, bool Keep);
size_t getPos();
+ std::pair<StringRef, size_t> getLineColumn();
std::vector<uint8_t> parseHex(StringRef S);
StringSaver Saver;
@@ -172,11 +173,36 @@
}
}
+std::pair<StringRef, size_t> ScriptParser::getLineColumn() {
+ const char *Begin = Input.data();
+ const char *End = Begin + Input.size();
+
+ if (Pos == 0) {
+ const char *Eol = strchr(Begin, '\n');
+ return {StringRef(Begin, Eol ? (Eol - Begin) : (End - Begin)),
+ Tokens[0].size() / 2};
+ }
+
+ const char *Tok = Tokens[Pos - 1].data();
+ const char *S = Tok;
+ while (S > Begin && *(S - 1) != '\n')
+ --S;
+
+ const char *Eol = strchr(Tok, '\n');
+ return {StringRef(S, Eol ? (Eol - S) : (End - S)),
+ Tok - S + Tokens[Pos - 1].size() / 2};
+}
+
// 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);
+ StringRef Line;
+ size_t Col;
+ std::tie(Line, Col) = getLineColumn();
+ error(Line);
+ error(std::string(Col, ' ') + "^");
Error = true;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18699.52388.patch
Type: text/x-patch
Size: 2610 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160401/2cf9f9b2/attachment.bin>
More information about the llvm-commits
mailing list