Skip to content

Commit

Permalink
Show "LTO plugin missing" error correctly
Browse files Browse the repository at this point in the history
Fixes #1403
  • Loading branch information
rui314 committed Jan 19, 2025
1 parent 1fbc6f3 commit f25e450
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/lto-unix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,12 @@ create_plugin_input_file(Context<E> &ctx, MappedFile *mf) {

template <typename E>
ObjectFile<E> *read_lto_object(Context<E> &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.
Expand All @@ -606,12 +612,6 @@ ObjectFile<E> *read_lto_object(Context<E> &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<E> *obj = new ObjectFile<E>;
ctx.obj_pool.emplace_back(obj);
Expand Down
12 changes: 12 additions & 0 deletions test/lto-no-plugin.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f25e450

Please sign in to comment.