Index: llvm/include/llvm/Object/IRObjectFile.h =================================================================== --- llvm/include/llvm/Object/IRObjectFile.h +++ llvm/include/llvm/Object/IRObjectFile.h @@ -28,9 +28,9 @@ class ObjectFile; class IRObjectFile : public SymbolicFile { - std::unique_ptr M; + std::vector> Ms; ModuleSymbolTable SymTab; - IRObjectFile(MemoryBufferRef Object, std::unique_ptr M); + IRObjectFile(MemoryBufferRef Object, std::vector> Ms); public: ~IRObjectFile() override; Index: llvm/lib/Object/IRObjectFile.cpp =================================================================== --- llvm/lib/Object/IRObjectFile.cpp +++ llvm/lib/Object/IRObjectFile.cpp @@ -35,9 +35,11 @@ using namespace llvm; using namespace object; -IRObjectFile::IRObjectFile(MemoryBufferRef Object, std::unique_ptr Mod) - : SymbolicFile(Binary::ID_IR, Object), M(std::move(Mod)) { - SymTab.addModule(M.get()); +IRObjectFile::IRObjectFile(MemoryBufferRef Object, + std::vector> Ms) + : SymbolicFile(Binary::ID_IR, Object), Ms(std::move(Ms)) { + for (auto &M : this->Ms) + SymTab.addModule(M.get()); } IRObjectFile::~IRObjectFile() {} @@ -73,7 +75,11 @@ return basic_symbol_iterator(BasicSymbolRef(Ret, this)); } -StringRef IRObjectFile::getTargetTriple() const { return M->getTargetTriple(); } +StringRef IRObjectFile::getTargetTriple() const { + // Each module must have the same target triple, so we arbitrarily access the + // first one. + return Ms[0]->getTargetTriple(); +} ErrorOr IRObjectFile::findBitcodeInObject(const ObjectFile &Obj) { for (const SectionRef &Sec : Obj.sections()) { @@ -108,19 +114,26 @@ } 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 std::unique_ptr( - new IRObjectFile(*BCOrErr, std::move(M))); + new IRObjectFile(*BCOrErr, 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 +}