summaryrefslogtreecommitdiffstats
path: root/lld/ELF/Error.cpp
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2016-01-28 18:40:06 +0000
committerRui Ueyama <ruiu@google.com>2016-01-28 18:40:06 +0000
commit64cfffd333b261ebb68a6ee04b09cc42d32c1992 (patch)
tree3320a40b26ea9552b91802bbf4b83767398f1f1e /lld/ELF/Error.cpp
parentec8d086c64f4012714405fb0d7b0729a33c18179 (diff)
downloadbcm5719-llvm-64cfffd333b261ebb68a6ee04b09cc42d32c1992.tar.gz
bcm5719-llvm-64cfffd333b261ebb68a6ee04b09cc42d32c1992.zip
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
Diffstat (limited to 'lld/ELF/Error.cpp')
-rw-r--r--lld/ELF/Error.cpp29
1 files changed, 22 insertions, 7 deletions
diff --git a/lld/ELF/Error.cpp b/lld/ELF/Error.cpp
index e0701f7f4cc..327bb26a4f1 100644
--- a/lld/ELF/Error.cpp
+++ b/lld/ELF/Error.cpp
@@ -15,23 +15,38 @@
namespace lld {
namespace elf2 {
+bool HasError;
+
void warning(const Twine &Msg) { llvm::errs() << Msg << "\n"; }
void error(const Twine &Msg) {
llvm::errs() << Msg << "\n";
- exit(1);
+ HasError = true;
}
void error(std::error_code EC, const Twine &Prefix) {
- if (!EC)
- return;
- error(Prefix + ": " + EC.message());
+ if (EC)
+ error(Prefix + ": " + EC.message());
}
void error(std::error_code EC) {
- if (!EC)
- return;
- error(EC.message());
+ if (EC)
+ error(EC.message());
+}
+
+void fatal(const Twine &Msg) {
+ llvm::errs() << Msg << "\n";
+ exit(1);
+}
+
+void fatal(std::error_code EC, const Twine &Prefix) {
+ if (EC)
+ fatal(Prefix + ": " + EC.message());
+}
+
+void fatal(std::error_code EC) {
+ if (EC)
+ fatal(EC.message());
}
} // namespace elf2
OpenPOWER on IntegriCloud