[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
Sat Apr 2 13:40:54 PDT 2016
grimar updated this revision to Diff 52474.
grimar marked 2 inline comments as done.
grimar added a comment.
- Addressed review comments.
- Fixed test (implemented workaround check for counting whitespaces as found no way to do the same with regexp in testsuite, it seems broken here).
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,29 @@
# 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: hexdump -C %t.log | FileCheck -check-prefix=ERR6DUMP %s
+## Check that last line is "^"
+# ERR6DUMP: 00000030 54 41 47 20 7b 0d 0a 5e
+
+## 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: hexdump -C %t.log | FileCheck -check-prefix=ERR7DUMP %s
+## Check that last line is " ^"
+# ERR7DUMP: 00000040 20 20 20 20 20 5e
Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -138,6 +138,7 @@
void readSectionPatterns(StringRef OutSec, bool Keep);
size_t getPos();
+ void printLineColumn();
std::vector<uint8_t> parseHex(StringRef S);
StringSaver Saver;
@@ -172,11 +173,29 @@
}
}
+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();
+ return S.substr(Begin, End - Begin);
+}
+
+void ScriptParser::printLineColumn() {
+ StringRef Tok = Tokens[Pos == 0 ? 0 : Pos - 1];
+ StringRef Line = getLine(Input, Tok.data() - Input.data()).rtrim();
+ size_t Col = Tok.data() - Line.data() + 1;
+ error(Line);
+ error(std::string(Col > 0 ? (Col - 1) : 0, ' ') + "^");
+}
+
// 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);
+ printLineColumn();
Error = true;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18699.52474.patch
Type: text/x-patch
Size: 2754 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160402/82a283bc/attachment.bin>
More information about the llvm-commits
mailing list