diff --git a/src/lto-unix.cc b/src/lto-unix.cc index 09f4c2edf7..8af3b9fd68 100644 --- a/src/lto-unix.cc +++ b/src/lto-unix.cc @@ -598,6 +598,12 @@ create_plugin_input_file(Context &ctx, MappedFile *mf) { template ObjectFile *read_lto_object(Context &ctx, MappedFile *mf) { + if (ctx.arg.plugin.empty()) + Fatal(ctx) << mf->name << ": don't know how to handle this LTO object file " + << "because no -plugin option was given. Please make sure you " + << "added -flto not only for creating object files but also for " + << "creating the final executable."; + load_lto_plugin(ctx); // V0 API's claim_file is not thread-safe. @@ -606,12 +612,6 @@ ObjectFile *read_lto_object(Context &ctx, MappedFile *mf) { if (!is_gcc_linker_api_v1) lock.lock(); - if (ctx.arg.plugin.empty()) - Fatal(ctx) << mf->name << ": don't know how to handle this LTO object file " - << "because no -plugin option was given. Please make sure you " - << "added -flto not only for creating object files but also for " - << "creating the final executable."; - // Create mold's object instance ObjectFile *obj = new ObjectFile; ctx.obj_pool.emplace_back(obj); diff --git a/test/lto-no-plugin.sh b/test/lto-no-plugin.sh new file mode 100755 index 0000000000..9e9a297ecc --- /dev/null +++ b/test/lto-no-plugin.sh @@ -0,0 +1,12 @@ +#!/bin/bash +. $(dirname $0)/common.inc + +[ $MACHINE = $(uname -m) ] || skip + +echo 'int main() {}' | clang -B. -flto -o /dev/null -xc - >& /dev/null || skip + +echo 'int main() {}' | clang -c -o $t/a.o -xc - +echo 'void foo() {}' | clang -c -o $t/b.o -xc - -flto + +! ./mold -o /dev/null $t/a.o $t/b.o >& $t/log +grep -q "b.o: don't know how to handle this LTO object file" $t/log