Index: lld/ELF/LTO.cpp =================================================================== --- lld/ELF/LTO.cpp +++ lld/ELF/LTO.cpp @@ -227,7 +227,6 @@ // Merge all the bitcode files we have seen, codegen the result // and return the resulting ObjectFile(s). std::vector BitcodeCompiler::compile() { - std::vector Ret; unsigned MaxTasks = LTOObj->getMaxTasks(); Buff.resize(MaxTasks); Files.resize(MaxTasks); @@ -253,19 +252,6 @@ if (!Config->ThinLTOCacheDir.empty()) pruneCache(Config->ThinLTOCacheDir, Config->ThinLTOCachePolicy); - for (unsigned I = 0; I != MaxTasks; ++I) { - if (Buff[I].empty()) - continue; - if (Config->SaveTemps) { - if (I == 0) - saveBuffer(Buff[I], Config->OutputFile + ".lto.o"); - else - saveBuffer(Buff[I], Config->OutputFile + Twine(I) + ".lto.o"); - } - InputFile *Obj = createObjectFile(MemoryBufferRef(Buff[I], "lto.tmp")); - Ret.push_back(Obj); - } - // If LazyObjFile has not been added to link, emit empty index files. // This is needed because this is what GNU gold plugin does and we have a // distributed build system that depends on that behavior. @@ -286,7 +272,6 @@ if (Config->ThinLTOEmitImportsFiles) openFile(Path + ".imports"); } - // 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. @@ -295,6 +280,21 @@ return {}; } + std::vector Ret; + + for (unsigned I = 0; I != MaxTasks; ++I) { + if (Buff[I].empty()) + continue; + if (Config->SaveTemps) { + if (I == 0) + saveBuffer(Buff[I], Config->OutputFile + ".lto.o"); + else + saveBuffer(Buff[I], Config->OutputFile + Twine(I) + ".lto.o"); + } + InputFile *Obj = createObjectFile(MemoryBufferRef(Buff[I], "lto.tmp")); + Ret.push_back(Obj); + } + for (std::unique_ptr &File : Files) if (File) Ret.push_back(createObjectFile(*File));