Skip to content

Commit d29fdfb

Browse files
authored
[LTO] Avoid assert fail on failed pass plugin load (#96691)
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.
1 parent 3f78d89 commit d29fdfb

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

llvm/lib/LTO/LTOBackend.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,8 @@ static void RegisterPassPlugins(ArrayRef<std::string> PassPlugins,
191191
// Load requested pass plugins and let them register pass builder callbacks
192192
for (auto &PluginFN : PassPlugins) {
193193
auto PassPlugin = PassPlugin::Load(PluginFN);
194-
if (!PassPlugin) {
195-
errs() << "Failed to load passes from '" << PluginFN
196-
<< "'. Request ignored.\n";
197-
continue;
198-
}
199-
194+
if (!PassPlugin)
195+
report_fatal_error(PassPlugin.takeError(), /*gen_crash_diag=*/false);
200196
PassPlugin->registerPassBuilderCallbacks(PB);
201197
}
202198
}
Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
1-
; REQUIRES: plugins, examples
1+
; REQUIRES: plugins
22
; UNSUPPORTED: target={{.*windows.*}}
33

4-
; RUN: not opt < %s -load-pass-plugin=%t/nonexistant.so -disable-output 2>&1 | FileCheck %s
5-
; CHECK: Could not load library {{.*}}nonexistant.so
4+
; RUN: not opt < %s -load-pass-plugin=%t/nonexistent.so -disable-output 2>&1 | FileCheck %s
5+
6+
; RUN: opt %s -o %t.o
7+
; RUN: not llvm-lto2 run -load-pass-plugin=%t/nonexistent.so %t.o -o %t \
8+
; RUN: -r %t.o,test 2>&1 | \
9+
; RUN: FileCheck %s
10+
11+
; CHECK: Could not load library {{.*}}nonexistent.so
12+
13+
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
14+
target triple = "x86_64-unknown-linux-gnu"
15+
16+
define void @test() {
17+
ret void
18+
}

0 commit comments

Comments
 (0)