Index: cfe/trunk/lib/CodeGen/BackendUtil.cpp =================================================================== --- cfe/trunk/lib/CodeGen/BackendUtil.cpp +++ cfe/trunk/lib/CodeGen/BackendUtil.cpp @@ -1161,6 +1161,7 @@ Conf.DebugPassManager = CGOpts.DebugPassManager; Conf.RemarksWithHotness = CGOpts.DiagnosticsWithHotness; Conf.RemarksFilename = CGOpts.OptRecordFile; + Conf.DwoPath = CGOpts.SplitDwarfFile; switch (Action) { case Backend_EmitNothing: Conf.PreCodeGenModuleHook = [](size_t Task, const Module &Mod) { Index: cfe/trunk/test/CodeGen/thinlto-split-dwarf.c =================================================================== --- cfe/trunk/test/CodeGen/thinlto-split-dwarf.c +++ cfe/trunk/test/CodeGen/thinlto-split-dwarf.c @@ -0,0 +1,21 @@ +// REQUIRES: x86-registered-target + +// RUN: %clang_cc1 -debug-info-kind=limited -triple x86_64-unknown-linux-gnu \ +// RUN: -flto=thin -emit-llvm-bc \ +// RUN: -o %t.o %s + +// RUN: llvm-lto2 run -thinlto-distributed-indexes %t.o \ +// RUN: -o %t2.index \ +// RUN: -r=%t.o,main,px + +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu \ +// RUN: -emit-obj -fthinlto-index=%t.o.thinlto.bc \ +// RUN: -o %t.native.o -split-dwarf-file %t.native.dwo -x ir %t.o + +// RUN: llvm-readobj -sections %t.native.o | FileCheck --check-prefix=O %s +// RUN: llvm-readobj -sections %t.native.dwo | FileCheck --check-prefix=DWO %s + +// O-NOT: .dwo +// DWO: .dwo + +int main() {} Index: llvm/trunk/include/llvm/LTO/Config.h =================================================================== --- llvm/trunk/include/llvm/LTO/Config.h +++ llvm/trunk/include/llvm/LTO/Config.h @@ -76,6 +76,11 @@ /// The directory to store .dwo files. std::string DwoDir; + /// The path to write a .dwo file to. This should generally only be used when + /// running an individual backend directly via thinBackend(), as otherwise + /// all .dwo files will be written to the same path. + std::string DwoPath; + /// Optimization remarks file path. std::string RemarksFilename = ""; Index: llvm/trunk/lib/LTO/LTOBackend.cpp =================================================================== --- llvm/trunk/lib/LTO/LTOBackend.cpp +++ llvm/trunk/lib/LTO/LTOBackend.cpp @@ -291,14 +291,19 @@ return; std::unique_ptr DwoOut; + SmallString<1024> DwoFile(Conf.DwoPath); if (!Conf.DwoDir.empty()) { std::error_code EC; if (auto EC = llvm::sys::fs::create_directories(Conf.DwoDir)) report_fatal_error("Failed to create directory " + Conf.DwoDir + ": " + EC.message()); - SmallString<1024> DwoFile(Conf.DwoDir); + DwoFile = Conf.DwoDir; sys::path::append(DwoFile, std::to_string(Task) + ".dwo"); + } + + if (!DwoFile.empty()) { + std::error_code EC; TM->Options.MCOptions.SplitDwarfFile = DwoFile.str().str(); DwoOut = llvm::make_unique(DwoFile, EC, sys::fs::F_None); if (EC)