From 64cfffd333b261ebb68a6ee04b09cc42d32c1992 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Thu, 28 Jan 2016 18:40:06 +0000 Subject: ELF: Rename error -> fatal and redefine error as a non-noreturn function. In many situations, we don't want to exit at the first error even in the process model. For example, it is better to report all undefined symbols rather than reporting the first one that the linker picked up randomly. In order to handle such errors, we don't need to wrap everything with ErrorOr (thanks for David Blaikie for pointing this out!) Instead, we can set a flag to record the fact that we found an error and keep it going until it reaches a reasonable checkpoint. This idea should be applicable to other places. For example, we can ignore broken relocations and check for errors after visiting all relocs. In this patch, I rename error to fatal, and introduce another version of error which doesn't call exit. That function instead sets HasError to true. Once HasError becomes true, it stays true, so that we know that there was an error if it is true. I think introducing a non-noreturn error reporting function is by itself a good idea, and it looks to me that this also provides a gradual path towards lld-as-a-library (or at least embed-lld-to-your-program) without sacrificing code readability with lots of ErrorOr's. http://reviews.llvm.org/D16641 llvm-svn: 259069 --- lld/ELF/LinkerScript.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'lld/ELF/LinkerScript.cpp') diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index 1345bd4f973..d9f98e9bbff 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -86,7 +86,7 @@ void LinkerScript::run() { } else if (Tok == "SECTIONS") { readSections(); } else { - error("unknown directive: " + Tok); + fatal("unknown directive: " + Tok); } } } @@ -103,7 +103,7 @@ std::vector LinkerScript::tokenize(StringRef S) { if (S.startswith("\"")) { size_t E = S.find("\"", 1); if (E == StringRef::npos) - error("unclosed quote"); + fatal("unclosed quote"); Ret.push_back(S.substr(1, E - 1)); S = S.substr(E + 1); continue; @@ -128,7 +128,7 @@ StringRef LinkerScript::skipSpace(StringRef S) { if (S.startswith("/*")) { size_t E = S.find("*/", 2); if (E == StringRef::npos) - error("unclosed comment in a linker script"); + fatal("unclosed comment in a linker script"); S = S.substr(E + 2); continue; } @@ -141,13 +141,13 @@ StringRef LinkerScript::skipSpace(StringRef S) { StringRef LinkerScript::next() { if (atEOF()) - error("unexpected EOF"); + fatal("unexpected EOF"); return Tokens[Pos++]; } bool LinkerScript::skip(StringRef Tok) { if (atEOF()) - error("unexpected EOF"); + fatal("unexpected EOF"); if (Tok != Tokens[Pos]) return false; ++Pos; @@ -157,7 +157,7 @@ bool LinkerScript::skip(StringRef Tok) { void LinkerScript::expect(StringRef Expect) { StringRef Tok = next(); if (Tok != Expect) - error(Expect + " expected, but got " + Tok); + fatal(Expect + " expected, but got " + Tok); } void LinkerScript::addFile(StringRef S) { @@ -184,7 +184,7 @@ void LinkerScript::addFile(StringRef S) { } else { std::string Path = findFromSearchPaths(S); if (Path.empty()) - error("Unable to find " + S); + fatal("Unable to find " + S); Driver->addFile(Saver.save(Path)); } } @@ -238,7 +238,7 @@ void LinkerScript::readGroup() { void LinkerScript::readInclude() { StringRef Tok = next(); auto MBOrErr = MemoryBuffer::getFile(Tok); - error(MBOrErr, "cannot open " + Tok); + fatal(MBOrErr, "cannot open " + Tok); std::unique_ptr &MB = *MBOrErr; StringRef S = Saver.save(MB->getMemBufferRef().getBuffer()); std::vector V = tokenize(S); @@ -269,7 +269,7 @@ void LinkerScript::readOutputFormat() { if (Tok == ")") return; if (Tok != ",") - error("unexpected token: " + Tok); + fatal("unexpected token: " + Tok); next(); expect(","); next(); -- cgit v1.2.3