Index: ELF/Driver.cpp =================================================================== --- ELF/Driver.cpp +++ ELF/Driver.cpp @@ -1265,10 +1265,18 @@ for (auto *Arg : Args.filtered(OPT_wrap)) Symtab->addSymbolWrap(Arg->getValue()); + // Do link-time optimization if given files are LLVM bitcode files. + // This compiles bitcode files into real object files. Symtab->addCombinedLTOObject(); if (errorCount()) return; + // If -thinlto-index-only is given, we should create only "index + // files" and not object files. Index file creation is already done + // in addCombinedLTOObject, so we are done if that's the case. + if (Config->ThinLTOIndexOnly) + return; + // Apply symbol renames for -wrap. Symtab->applySymbolWrap(); Index: ELF/LTO.cpp =================================================================== --- ELF/LTO.cpp +++ ELF/LTO.cpp @@ -282,7 +282,9 @@ // ThinLTO with index only option is required to generate only the index // files. After that, we exit from linker and ThinLTO backend runs in a // distributed environment. - exit(0); + if (IndexFile) + IndexFile->close(); + return {}; } for (std::unique_ptr &File : Files) Index: test/ELF/lto/thinlto.ll =================================================================== --- test/ELF/lto/thinlto.ll +++ test/ELF/lto/thinlto.ll @@ -37,7 +37,7 @@ ; RUN: rm -f %t4.o.thinlto.bc ; RUN: touch %t4.o.thinlto.bc ; RUN: chmod 400 %t4.o.thinlto.bc -; RUN: ld.lld -m elf_x86_64 --plugin-opt=thinlto-index-only -shared %t.o %t4.o -o %t5 2>&1 | FileCheck %s --check-prefix=ERR +; RUN: not ld.lld -m elf_x86_64 --plugin-opt=thinlto-index-only -shared %t.o %t4.o -o %t5 2>&1 | FileCheck %s --check-prefix=ERR ; ERR: cannot open {{.*}}4.o.thinlto.bc: {{P|p}}ermission denied ; Ensure lld doesn't generates index files when thinlto-index-only is not enabled