diff --git a/llvm/include/llvm/LTO/legacy/ThinLTOCodeGenerator.h b/llvm/include/llvm/LTO/legacy/ThinLTOCodeGenerator.h --- a/llvm/include/llvm/LTO/legacy/ThinLTOCodeGenerator.h +++ b/llvm/include/llvm/LTO/legacy/ThinLTOCodeGenerator.h @@ -299,7 +299,8 @@ * SavedObjectsDirectoryPath. */ std::string writeGeneratedObject(int count, StringRef CacheEntryPath, - const MemoryBuffer &OutputBuffer); + const MemoryBuffer &OutputBuffer, + StringRef objectFileName = ""); /**@}*/ private: diff --git a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp --- a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp +++ b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp @@ -964,11 +964,16 @@ /// Returns the path to the generated file in SavedObjectsDirectoryPath. std::string ThinLTOCodeGenerator::writeGeneratedObject(int count, StringRef CacheEntryPath, - const MemoryBuffer &OutputBuffer) { + const MemoryBuffer &OutputBuffer, + StringRef objectFileName) { auto ArchName = TMBuilder.TheTriple.getArchName(); SmallString<128> OutputPath(SavedObjectsDirectoryPath); - llvm::sys::path::append(OutputPath, - Twine(count) + "." + ArchName + ".thinlto.o"); + if (objectFileName.empty()) + llvm::sys::path::append(OutputPath, + Twine(count) + "." + ArchName + ".thinlto.o"); + else + llvm::sys::path::append(OutputPath, Twine(count) + "." + ArchName + "." + + objectFileName + ".thinlto.o"); OutputPath.c_str(); // Ensure the string is null terminated. if (sys::fs::exists(OutputPath)) sys::fs::remove(OutputPath); @@ -1164,6 +1169,10 @@ auto &Mod = Modules[IndexCount]; Pool.async([&](int count) { auto ModuleIdentifier = Mod->getName(); + + StringRef moduleIdentifierFileName = + llvm::sys::path::filename(ModuleIdentifier); + auto &ExportList = ExportLists[ModuleIdentifier]; auto &DefinedGVSummaries = ModuleToDefinedGVSummaries[ModuleIdentifier]; @@ -1188,7 +1197,8 @@ ProducedBinaries[count] = std::move(ErrOrBuffer.get()); else ProducedBinaryFiles[count] = writeGeneratedObject( - count, CacheEntryPath, *ErrOrBuffer.get()); + count, CacheEntryPath, *ErrOrBuffer.get(), + moduleIdentifierFileName); return; } } @@ -1246,7 +1256,7 @@ return; } ProducedBinaryFiles[count] = writeGeneratedObject( - count, CacheEntryPath, *OutputBuffer); + count, CacheEntryPath, *OutputBuffer, moduleIdentifierFileName); }, IndexCount); } }