[lld] 4a67b93 - [ELF] Make checkError context-aware

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sat Nov 16 15:43:10 PST 2024


Author: Fangrui Song
Date: 2024-11-16T15:43:05-08:00
New Revision: 4a67b93fe8ffa330f3e9018232589e75c58f5806

URL: https://github.com/llvm/llvm-project/commit/4a67b93fe8ffa330f3e9018232589e75c58f5806
DIFF: https://github.com/llvm/llvm-project/commit/4a67b93fe8ffa330f3e9018232589e75c58f5806.diff

LOG: [ELF] Make checkError context-aware

Added: 
    

Modified: 
    lld/Common/ErrorHandler.cpp
    lld/ELF/Driver.cpp
    lld/ELF/LTO.cpp
    lld/include/lld/Common/ErrorHandler.h

Removed: 
    


################################################################################
diff  --git a/lld/Common/ErrorHandler.cpp b/lld/Common/ErrorHandler.cpp
index 9526db7fefc9aa..daca2e36ac4a5e 100644
--- a/lld/Common/ErrorHandler.cpp
+++ b/lld/Common/ErrorHandler.cpp
@@ -146,6 +146,11 @@ void lld::checkError(Error e) {
                   [&](ErrorInfoBase &eib) { error(eib.message()); });
 }
 
+void lld::checkError(ErrorHandler &eh, Error e) {
+  handleAllErrors(std::move(e),
+                  [&](ErrorInfoBase &eib) { eh.error(eib.message()); });
+}
+
 // This is for --vs-diagnostics.
 //
 // Normally, lld's error message starts with argv[0]. Therefore, it usually

diff  --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 41816025f38b16..78850e23220027 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -724,8 +724,10 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
   }
 
   if (ctx.arg.timeTraceEnabled) {
-    checkError(timeTraceProfilerWrite(
-        args.getLastArgValue(OPT_time_trace_eq).str(), ctx.arg.outputFile));
+    checkError(
+        *ctx.errHandler,
+        timeTraceProfilerWrite(args.getLastArgValue(OPT_time_trace_eq).str(),
+                               ctx.arg.outputFile));
     timeTraceProfilerCleanup();
   }
 }

diff  --git a/lld/ELF/LTO.cpp b/lld/ELF/LTO.cpp
index dc327ce7f78151..36161c3d648708 100644
--- a/lld/ELF/LTO.cpp
+++ b/lld/ELF/LTO.cpp
@@ -165,9 +165,9 @@ static lto::Config createConfig(Ctx &ctx) {
   }
 
   if (!ctx.arg.saveTempsArgs.empty())
-    checkError(c.addSaveTemps(ctx.arg.outputFile.str() + ".",
-                              /*UseInputModulePath*/ true,
-                              ctx.arg.saveTempsArgs));
+    checkError(*ctx.errHandler, c.addSaveTemps(ctx.arg.outputFile.str() + ".",
+                                               /*UseInputModulePath*/ true,
+                                               ctx.arg.saveTempsArgs));
   return c;
 }
 
@@ -278,7 +278,7 @@ void BitcodeCompiler::add(BitcodeFile &f) {
     // their values are still not final.
     r.LinkerRedefined = sym->scriptDefined;
   }
-  checkError(ltoObj->add(std::move(f.obj), resols));
+  checkError(*ctx.errHandler, ltoObj->add(std::move(f.obj), resols));
 }
 
 // If LazyObjFile has not been added to link, emit empty index files.
@@ -329,13 +329,14 @@ std::vector<InputFile *> BitcodeCompiler::compile() {
                              }));
 
   if (!ctx.bitcodeFiles.empty())
-    checkError(ltoObj->run(
-        [&](size_t task, const Twine &moduleName) {
-          buf[task].first = moduleName.str();
-          return std::make_unique<CachedFileStream>(
-              std::make_unique<raw_svector_ostream>(buf[task].second));
-        },
-        cache));
+    checkError(*ctx.errHandler, ltoObj->run(
+                                    [&](size_t task, const Twine &moduleName) {
+                                      buf[task].first = moduleName.str();
+                                      return std::make_unique<CachedFileStream>(
+                                          std::make_unique<raw_svector_ostream>(
+                                              buf[task].second));
+                                    },
+                                    cache));
 
   // Emit empty index files for non-indexed files but not in single-module mode.
   if (ctx.arg.thinLTOModulesToCompile.empty()) {

diff  --git a/lld/include/lld/Common/ErrorHandler.h b/lld/include/lld/Common/ErrorHandler.h
index 6be862e5115da9..607092477ec766 100644
--- a/lld/include/lld/Common/ErrorHandler.h
+++ b/lld/include/lld/Common/ErrorHandler.h
@@ -172,6 +172,7 @@ class SyncStream {
 
 void diagnosticHandler(const llvm::DiagnosticInfo &di);
 void checkError(Error e);
+void checkError(ErrorHandler &eh, Error e);
 
 // check functions are convenient functions to strip errors
 // from error-or-value objects.


        


More information about the llvm-commits mailing list