diff options
author | George Rimar <grimar@accesssoftek.com> | 2016-04-06 08:08:40 +0000 |
---|---|---|
committer | George Rimar <grimar@accesssoftek.com> | 2016-04-06 08:08:40 +0000 |
commit | 2348320d4efb4a3cea84fcb6e542038fc1b07008 (patch) | |
tree | 3b2ff5f67aec8032ed77cfeeb99b5ee8b0350f10 /lld/ELF/LinkerScript.cpp | |
parent | 7ca0627c51b31650281654dbadf080f1ec6d46ec (diff) | |
download | bcm5719-llvm-2348320d4efb4a3cea84fcb6e542038fc1b07008.tar.gz bcm5719-llvm-2348320d4efb4a3cea84fcb6e542038fc1b07008.zip |
[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
llvm-svn: 265523
Diffstat (limited to 'lld/ELF/LinkerScript.cpp')
-rw-r--r-- | lld/ELF/LinkerScript.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index abd8d0a8344..36c92524166 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -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; } |