Index: ELF/LTO.h =================================================================== --- ELF/LTO.h +++ ELF/LTO.h @@ -39,12 +39,15 @@ void add(BitcodeFile &F); std::unique_ptr compile(); + BitcodeCompiler() + : Combined(new llvm::Module("blah", Context)), Mover(*Combined.get()){}; + private: llvm::TargetMachine *getTargetMachine(); llvm::LLVMContext Context; - llvm::Module Combined{"ld-temp.o", Context}; - llvm::IRMover Mover{Combined}; + std::unique_ptr Combined; + llvm::IRMover Mover; SmallString<0> OwningData; std::unique_ptr MB; llvm::StringSet<> InternalizedSyms; Index: ELF/LTO.cpp =================================================================== --- ELF/LTO.cpp +++ ELF/LTO.cpp @@ -138,23 +138,23 @@ // and return the resulting ObjectFile. std::unique_ptr BitcodeCompiler::compile() { for (const auto &Name : InternalizedSyms) { - GlobalValue *GV = Combined.getNamedValue(Name.first()); + GlobalValue *GV = Combined->getNamedValue(Name.first()); assert(GV); internalize(*GV); } if (Config->SaveTemps) - saveBCFile(Combined, ".lto.bc"); + saveBCFile(*Combined, ".lto.bc"); std::unique_ptr TM(getTargetMachine()); - runLTOPasses(Combined, *TM); + runLTOPasses(*Combined, *TM); raw_svector_ostream OS(OwningData); legacy::PassManager CodeGenPasses; if (TM->addPassesToEmitFile(CodeGenPasses, OS, TargetMachine::CGFT_ObjectFile)) fatal("failed to setup codegen"); - CodeGenPasses.run(Combined); + CodeGenPasses.run(*Combined); MB = MemoryBuffer::getMemBuffer(OwningData, "LLD-INTERNAL-combined-lto-object", false); if (Config->SaveTemps) @@ -163,7 +163,7 @@ } TargetMachine *BitcodeCompiler::getTargetMachine() { - StringRef TripleStr = Combined.getTargetTriple(); + StringRef TripleStr = Combined->getTargetTriple(); std::string Msg; const Target *T = TargetRegistry::lookupTarget(TripleStr, Msg); if (!T)