After setting the LTO mode from the -flto option, look at the input files as well. If any of them is an object file containing LLVM bitcode,
set the LTO mode to either thin or full, depending on the input file.
This makes the following sample work:
clang test.c -c -flto clang test.o
Which also works when using GCC. Currently this makes non-lld linkers print an error, for example when using ld.bfd:
$ clang test.o test.o: file not recognized: file format not recognized clang-10: error: linker command failed with exit code 1 (use -v to see invocation)