summaryrefslogtreecommitdiffstats
path: root/lld/ELF/LinkerScript.cpp
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2016-03-30 16:51:57 +0000
committerRui Ueyama <ruiu@google.com>2016-03-30 16:51:57 +0000
commit38dc83417b860e510bc376dbad4c4194df2e883c (patch)
treee171ae28adcff9a1d9d05f99d3da5da0a9883979 /lld/ELF/LinkerScript.cpp
parent1d5e6d4bdcc316137e6e8fe75b709f5464190f59 (diff)
downloadbcm5719-llvm-38dc83417b860e510bc376dbad4c4194df2e883c.tar.gz
bcm5719-llvm-38dc83417b860e510bc376dbad4c4194df2e883c.zip
Include line number in error message for linker scripts.
This patch is based on http://reviews.llvm.org/D18545 written by George Rimar. llvm-svn: 264878
Diffstat (limited to 'lld/ELF/LinkerScript.cpp')
-rw-r--r--lld/ELF/LinkerScript.cpp15
1 files changed, 13 insertions, 2 deletions
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index d75ebb0ed4d..abd8d0a8344 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -106,7 +106,7 @@ class elf::ScriptParser {
public:
ScriptParser(BumpPtrAllocator *A, StringRef S, bool B)
- : Saver(*A), Tokens(tokenize(S)), IsUnderSysroot(B) {}
+ : Saver(*A), Input(S), Tokens(tokenize(S)), IsUnderSysroot(B) {}
void run();
@@ -137,9 +137,11 @@ private:
void readOutputSectionDescription();
void readSectionPatterns(StringRef OutSec, bool Keep);
+ size_t getPos();
std::vector<uint8_t> parseHex(StringRef S);
StringSaver Saver;
+ StringRef Input;
std::vector<StringRef> Tokens;
const static StringMap<Handler> Cmd;
size_t Pos = 0;
@@ -174,7 +176,7 @@ void ScriptParser::run() {
void ScriptParser::setError(const Twine &Msg) {
if (Error)
return;
- error(Msg);
+ error("line " + Twine(getPos()) + ": " + Msg);
Error = true;
}
@@ -412,6 +414,15 @@ void ScriptParser::readSectionPatterns(StringRef OutSec, bool Keep) {
Script->Sections.emplace_back(OutSec, next(), Keep);
}
+// Returns the current line number.
+size_t ScriptParser::getPos() {
+ if (Pos == 0)
+ return 1;
+ const char *Begin = Input.data();
+ const char *Tok = Tokens[Pos - 1].data();
+ return StringRef(Begin, Tok - Begin).count('\n') + 1;
+}
+
std::vector<uint8_t> ScriptParser::parseHex(StringRef S) {
std::vector<uint8_t> Hex;
while (!S.empty()) {
OpenPOWER on IntegriCloud