Skip to content

Commit

Permalink
[LTO] Avoid assert fail on failed pass plugin load (llvm#96691)
Browse files Browse the repository at this point in the history
Without this patch, passing -load-pass-plugin=nonexistent.so to
llvm-lto2 produces a backtrace because LTOBackend.cpp does not handle
the error correctly:

```
Failed to load passes from 'nonexistant.so'. Request ignored.
Expected<T> must be checked before access or destruction.
Unchecked Expected<T> contained error:
Could not load library 'nonexistant.so': nonexistant.so: cannot open shared object file: No such file or directoryPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
```

Any tool using `lto::Config::PassPlugins` should suffer similarly.

Based on the message "Request ignored" and the continue statement, the
intention was apparently to continue on failure to load a plugin.
However, no one appears to rely on that behavior now given that it
crashes instead, and terminating is consistent with opt.
  • Loading branch information
jdenny-ornl authored and AlexisPerry committed Jun 27, 2024
1 parent c3a55dd commit 8a617a5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
8 changes: 2 additions & 6 deletions llvm/lib/LTO/LTOBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,8 @@ static void RegisterPassPlugins(ArrayRef<std::string> PassPlugins,
// Load requested pass plugins and let them register pass builder callbacks
for (auto &PluginFN : PassPlugins) {
auto PassPlugin = PassPlugin::Load(PluginFN);
if (!PassPlugin) {
errs() << "Failed to load passes from '" << PluginFN
<< "'. Request ignored.\n";
continue;
}

if (!PassPlugin)
report_fatal_error(PassPlugin.takeError(), /*gen_crash_diag=*/false);
PassPlugin->registerPassBuilderCallbacks(PB);
}
}
Expand Down
19 changes: 16 additions & 3 deletions llvm/test/Feature/load_plugin_error.ll
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
; REQUIRES: plugins, examples
; REQUIRES: plugins
; UNSUPPORTED: target={{.*windows.*}}

; RUN: not opt < %s -load-pass-plugin=%t/nonexistant.so -disable-output 2>&1 | FileCheck %s
; CHECK: Could not load library {{.*}}nonexistant.so
; RUN: not opt < %s -load-pass-plugin=%t/nonexistent.so -disable-output 2>&1 | FileCheck %s

; RUN: opt %s -o %t.o
; RUN: not llvm-lto2 run -load-pass-plugin=%t/nonexistent.so %t.o -o %t \
; RUN: -r %t.o,test 2>&1 | \
; RUN: FileCheck %s

; CHECK: Could not load library {{.*}}nonexistent.so

target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

define void @test() {
ret void
}

0 comments on commit 8a617a5

Please sign in to comment.