[llvm] ef61592 - [llvm-jitlink] Don't show FailedToMaterialize errors by default.

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 17 12:01:12 PDT 2022


Author: Lang Hames
Date: 2022-04-17T12:01:06-07:00
New Revision: ef61592bb4792e89c22f49ee1d32a612b1b921f5

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

LOG: [llvm-jitlink] Don't show FailedToMaterialize errors by default.

This patch makes printing of FailedToMaterialize errors in llvm-jitlink
conditional on the -show-err-failed-to-materialize option, which defaults to
false.

FailedToMaterialize errors are not root-cause errors: they're generated when a
symbol is requested but cannot be provided because of a failure that was
reported on some other error path. They typically don't convey actionable
information, and tend to flood error logs making root cause errors harder to
spot. Hiding FailedToMaterialize errors by default addresses these issues.

Added: 
    

Modified: 
    llvm/tools/llvm-jitlink/llvm-jitlink.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
index 480bc5078471e..dcb79d9d3997f 100644
--- a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
+++ b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
@@ -224,9 +224,14 @@ static cl::opt<bool> AddSelfRelocations(
     cl::desc("Add relocations to function pointers to the current function"),
     cl::init(false), cl::cat(JITLinkCategory));
 
-ExitOnError ExitOnErr;
+static cl::opt<bool>
+    ShowErrFailedToMaterialize("show-err-failed-to-materialize",
+                               cl::desc("Show FailedToMaterialize errors"),
+                               cl::init(false), cl::cat(JITLinkCategory));
+
+static ExitOnError ExitOnErr;
 
-LLVM_ATTRIBUTE_USED void linkComponents() {
+static LLVM_ATTRIBUTE_USED void linkComponents() {
   errs() << (void *)&llvm_orc_registerEHFrameSectionWrapper
          << (void *)&llvm_orc_deregisterEHFrameSectionWrapper
          << (void *)&llvm_orc_registerJITLoaderGDBWrapper;
@@ -243,6 +248,34 @@ llvm_jitlink_setTestResultOverride(int64_t Value) {
 
 static Error addSelfRelocations(LinkGraph &G);
 
+namespace {
+
+template <typename ErrT>
+
+class ConditionalPrintErr {
+public:
+  ConditionalPrintErr(bool C) : C(C) {}
+  void operator()(ErrT &EI) {
+    if (C) {
+      errs() << "llvm-jitlink error: ";
+      EI.log(errs());
+      errs() << "\n";
+    }
+  }
+
+private:
+  bool C;
+};
+
+void reportLLVMJITLinkError(Error Err) {
+  handleAllErrors(
+      std::move(Err),
+      ConditionalPrintErr<orc::FailedToMaterialize>(ShowErrFailedToMaterialize),
+      ConditionalPrintErr<ErrorInfoBase>(true));
+}
+
+} // end anonymous namespace
+
 namespace llvm {
 
 static raw_ostream &
@@ -1010,6 +1043,8 @@ Session::Session(std::unique_ptr<ExecutorProcessControl> EPC, Error &Err)
 
   ErrorAsOutParameter _(&Err);
 
+  ES.setErrorReporter(reportLLVMJITLinkError);
+
   if (auto MainJDOrErr = ES.createJITDylib("main"))
     MainJD = &*MainJDOrErr;
   else {
@@ -1968,7 +2003,12 @@ int main(int argc, char *argv[]) {
     TimeRegion TR(Timers ? &Timers->LinkTimer : nullptr);
     // Find the entry-point function unconditionally, since we want to force
     // it to be materialized to collect stats.
-    EntryPoint = ExitOnErr(getMainEntryPoint(*S));
+    if (auto EP = getMainEntryPoint(*S))
+      EntryPoint = *EP;
+    else {
+      reportLLVMJITLinkError(EP.takeError());
+      exit(1);
+    }
     LLVM_DEBUG({
       dbgs() << "Using entry point \"" << EntryPointName
              << "\": " << formatv("{0:x16}", EntryPoint.getAddress()) << "\n";
@@ -1977,7 +2017,12 @@ int main(int argc, char *argv[]) {
     // If we're running with the ORC runtime then replace the entry-point
     // with the __orc_rt_run_program symbol.
     if (!OrcRuntime.empty()) {
-      EntryPoint = ExitOnErr(getOrcRuntimeEntryPoint(*S));
+      if (auto EP = getOrcRuntimeEntryPoint(*S))
+        EntryPoint = *EP;
+      else {
+        reportLLVMJITLinkError(EP.takeError());
+        exit(1);
+      }
       LLVM_DEBUG({
         dbgs() << "(called via __orc_rt_run_program_wrapper at "
                << formatv("{0:x16}", EntryPoint.getAddress()) << ")\n";


        


More information about the llvm-commits mailing list