Index: llvm/include/llvm/Object/IRObjectFile.h =================================================================== --- llvm/include/llvm/Object/IRObjectFile.h +++ llvm/include/llvm/Object/IRObjectFile.h @@ -27,7 +27,7 @@ class ObjectFile; class IRObjectFile : public SymbolicFile { - std::unique_ptr M; + std::vector> Ms; std::unique_ptr Mang; typedef std::pair AsmSymbol; SpecificBumpPtrAllocator AsmSymbols; @@ -38,8 +38,10 @@ return *reinterpret_cast(Symb.p); } + void addModule(Module &M); + public: - IRObjectFile(MemoryBufferRef Object, std::unique_ptr M); + IRObjectFile(MemoryBufferRef Object, std::vector> Ms); ~IRObjectFile() override; void moveSymbolNext(DataRefImpl &Symb) const override; std::error_code printSymbolName(raw_ostream &OS, @@ -56,7 +58,7 @@ return const_cast(this)->getModule(); } Module &getModule() { - return *M; + return *Ms[0]; } std::unique_ptr takeModule(); Index: llvm/lib/LTO/LTOModule.cpp =================================================================== --- llvm/lib/LTO/LTOModule.cpp +++ llvm/lib/LTO/LTOModule.cpp @@ -233,8 +233,10 @@ march->createTargetMachine(TripleStr, CPU, FeatureStr, options, None); M->setDataLayout(target->createDataLayout()); - std::unique_ptr IRObj( - new object::IRObjectFile(Buffer, std::move(M))); + std::vector> Ms; + Ms.push_back(std::move(M)); + std::unique_ptr IRObj(new object::IRObjectFile( + Buffer, std::move(Ms))); std::unique_ptr Ret(new LTOModule(std::move(IRObj), target)); Ret->parseSymbols(); Index: llvm/lib/Object/IRObjectFile.cpp =================================================================== --- llvm/lib/Object/IRObjectFile.cpp +++ llvm/lib/Object/IRObjectFile.cpp @@ -35,20 +35,25 @@ using namespace llvm; using namespace object; -IRObjectFile::IRObjectFile(MemoryBufferRef Object, std::unique_ptr Mod) - : SymbolicFile(Binary::ID_IR, Object), M(std::move(Mod)) { +IRObjectFile::IRObjectFile(MemoryBufferRef Object, + std::vector> Ms) + : SymbolicFile(Binary::ID_IR, Object), Ms(std::move(Ms)) { Mang.reset(new Mangler()); + for (auto &M : this->Ms) + addModule(*M); +} - for (Function &F : *M) +void IRObjectFile::addModule(Module &M) { + for (Function &F : M) SymTab.push_back(&F); - for (GlobalVariable &GV : M->globals()) + for (GlobalVariable &GV : M.globals()) SymTab.push_back(&GV); - for (GlobalAlias &GA : M->aliases()) + for (GlobalAlias &GA : M.aliases()) SymTab.push_back(&GA); - for (GlobalIFunc &GIF : M->ifuncs()) + for (GlobalIFunc &GIF : M.ifuncs()) SymTab.push_back(&GIF); - CollectAsmUndefinedRefs(Triple(M->getTargetTriple()), M->getModuleInlineAsm(), + CollectAsmUndefinedRefs(Triple(M.getTargetTriple()), M.getModuleInlineAsm(), [this](StringRef Name, BasicSymbolRef::Flags Flags) { SymTab.push_back(new (AsmSymbols.Allocate()) AsmSymbol(Name, Flags)); @@ -201,7 +206,7 @@ return getSym(Symb).dyn_cast(); } -std::unique_ptr IRObjectFile::takeModule() { return std::move(M); } +std::unique_ptr IRObjectFile::takeModule() { return std::move(Ms[0]); } basic_symbol_iterator IRObjectFile::symbol_begin_impl() const { DataRefImpl Ret; @@ -248,18 +253,25 @@ } Expected> -llvm::object::IRObjectFile::create(MemoryBufferRef Object, - LLVMContext &Context) { +IRObjectFile::create(MemoryBufferRef Object, LLVMContext &Context) { ErrorOr BCOrErr = findBitcodeInMemBuffer(Object); if (!BCOrErr) return errorCodeToError(BCOrErr.getError()); - Expected> MOrErr = - getLazyBitcodeModule(*BCOrErr, Context, - /*ShouldLazyLoadMetadata*/ true); - if (!MOrErr) - return MOrErr.takeError(); + Expected> BMsOrErr = + getBitcodeModuleList(*BCOrErr); + if (!BMsOrErr) + return BMsOrErr.takeError(); + + std::vector> Ms; + for (auto BM : *BMsOrErr) { + Expected> MOrErr = + BM.getLazyModule(Context, /*ShouldLazyLoadMetadata*/ true); + if (!MOrErr) + return MOrErr.takeError(); + + Ms.push_back(std::move(*MOrErr)); + } - std::unique_ptr &M = MOrErr.get(); - return llvm::make_unique(BCOrErr.get(), std::move(M)); + return llvm::make_unique(BCOrErr.get(), std::move(Ms)); } Index: llvm/test/Object/Inputs/multi-module.ll =================================================================== --- /dev/null +++ llvm/test/Object/Inputs/multi-module.ll @@ -0,0 +1,3 @@ +define void @f2() { + ret void +} Index: llvm/test/Object/multi-module.ll =================================================================== --- /dev/null +++ llvm/test/Object/multi-module.ll @@ -0,0 +1,8 @@ +; RUN: llvm-join -o - %s %S/Inputs/multi-module.ll | llvm-nm - | FileCheck %s + +; CHECK: T f1 +; CHECK: T f2 + +define void @f1() { + ret void +}