diff options
Diffstat (limited to 'unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp')
-rw-r--r-- | unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp | 127 |
1 files changed, 71 insertions, 56 deletions
diff --git a/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp b/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp index ed7b327124d7..420631c36ad2 100644 --- a/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp +++ b/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp @@ -12,6 +12,7 @@ #include "llvm/ExecutionEngine/ExecutionEngine.h" #include "llvm/ExecutionEngine/Orc/CompileUtils.h" #include "llvm/ExecutionEngine/Orc/LambdaResolver.h" +#include "llvm/ExecutionEngine/Orc/Legacy.h" #include "llvm/ExecutionEngine/Orc/NullResolver.h" #include "llvm/ExecutionEngine/SectionMemoryManager.h" #include "llvm/IR/Constants.h" @@ -66,7 +67,12 @@ TEST(RTDyldObjectLinkingLayerTest, TestSetProcessAllSections) { bool DebugSectionSeen = false; auto MM = std::make_shared<MemoryManagerWrapper>(DebugSectionSeen); - RTDyldObjectLinkingLayer ObjLayer([&MM]() { return MM; }); + ExecutionSession ES(std::make_shared<SymbolStringPool>()); + + RTDyldObjectLinkingLayer ObjLayer(ES, [&MM](VModuleKey) { + return RTDyldObjectLinkingLayer::Resources{ + MM, std::make_shared<NullResolver>()}; + }); LLVMContext Context; auto M = llvm::make_unique<Module>("", Context); @@ -88,46 +94,48 @@ TEST(RTDyldObjectLinkingLayerTest, TestSetProcessAllSections) { if (!TM) return; - auto Obj = - std::make_shared<object::OwningBinary<object::ObjectFile>>( - SimpleCompiler(*TM)(*M)); - - auto Resolver = - createLambdaResolver( - [](const std::string &Name) { - return JITSymbol(nullptr); - }, - [](const std::string &Name) { - return JITSymbol(nullptr); - }); + auto Obj = SimpleCompiler(*TM)(*M); { // Test with ProcessAllSections = false (the default). - auto H = cantFail(ObjLayer.addObject(Obj, Resolver)); - cantFail(ObjLayer.emitAndFinalize(H)); + auto K = ES.allocateVModule(); + cantFail(ObjLayer.addObject( + K, MemoryBuffer::getMemBufferCopy(Obj->getBuffer()))); + cantFail(ObjLayer.emitAndFinalize(K)); EXPECT_EQ(DebugSectionSeen, false) << "Unexpected debug info section"; - cantFail(ObjLayer.removeObject(H)); + cantFail(ObjLayer.removeObject(K)); } { // Test with ProcessAllSections = true. ObjLayer.setProcessAllSections(true); - auto H = cantFail(ObjLayer.addObject(Obj, Resolver)); - cantFail(ObjLayer.emitAndFinalize(H)); + auto K = ES.allocateVModule(); + cantFail(ObjLayer.addObject(K, std::move(Obj))); + cantFail(ObjLayer.emitAndFinalize(K)); EXPECT_EQ(DebugSectionSeen, true) << "Expected debug info section not seen"; - cantFail(ObjLayer.removeObject(H)); + cantFail(ObjLayer.removeObject(K)); } } TEST_F(RTDyldObjectLinkingLayerExecutionTest, NoDuplicateFinalization) { - if (!TM) + if (!SupportsJIT) return; + ExecutionSession ES(std::make_shared<SymbolStringPool>()); + auto MM = std::make_shared<SectionMemoryManagerWrapper>(); - RTDyldObjectLinkingLayer ObjLayer([&MM]() { return MM; }); + std::map<orc::VModuleKey, std::shared_ptr<orc::SymbolResolver>> Resolvers; + + RTDyldObjectLinkingLayer ObjLayer(ES, [&](VModuleKey K) { + auto I = Resolvers.find(K); + assert(I != Resolvers.end() && "Missing resolver"); + auto R = std::move(I->second); + Resolvers.erase(I); + return RTDyldObjectLinkingLayer::Resources{MM, std::move(R)}; + }); SimpleCompiler Compile(*TM); // Create a pair of modules that will trigger recursive finalization: @@ -153,9 +161,7 @@ TEST_F(RTDyldObjectLinkingLayerExecutionTest, NoDuplicateFinalization) { Builder.CreateRet(FourtyTwo); } - auto Obj1 = - std::make_shared<object::OwningBinary<object::ObjectFile>>( - Compile(*MB1.getModule())); + auto Obj1 = Compile(*MB1.getModule()); ModuleBuilder MB2(Context, "", "dummy"); { @@ -166,25 +172,29 @@ TEST_F(RTDyldObjectLinkingLayerExecutionTest, NoDuplicateFinalization) { IRBuilder<> Builder(FooEntry); Builder.CreateRet(Builder.CreateCall(BarDecl)); } - auto Obj2 = - std::make_shared<object::OwningBinary<object::ObjectFile>>( - Compile(*MB2.getModule())); - - auto Resolver = - createLambdaResolver( - [&](const std::string &Name) { - if (auto Sym = ObjLayer.findSymbol(Name, true)) - return Sym; - return JITSymbol(nullptr); + auto Obj2 = Compile(*MB2.getModule()); + + auto K1 = ES.allocateVModule(); + Resolvers[K1] = std::make_shared<NullResolver>(); + cantFail(ObjLayer.addObject(K1, std::move(Obj1))); + + auto K2 = ES.allocateVModule(); + auto LegacyLookup = [&](const std::string &Name) { + return ObjLayer.findSymbol(Name, true); + }; + + Resolvers[K2] = createSymbolResolver( + [&](const SymbolNameSet &Symbols) { + return cantFail(lookupFlagsWithLegacyFn(Symbols, LegacyLookup)); }, - [](const std::string &Name) { - return JITSymbol(nullptr); + [&](std::shared_ptr<AsynchronousSymbolQuery> Query, + const SymbolNameSet &Symbols) { + return lookupWithLegacyFn(ES, *Query, Symbols, LegacyLookup); }); - cantFail(ObjLayer.addObject(std::move(Obj1), Resolver)); - auto H = cantFail(ObjLayer.addObject(std::move(Obj2), Resolver)); - cantFail(ObjLayer.emitAndFinalize(H)); - cantFail(ObjLayer.removeObject(H)); + cantFail(ObjLayer.addObject(K2, std::move(Obj2))); + cantFail(ObjLayer.emitAndFinalize(K2)); + cantFail(ObjLayer.removeObject(K2)); // Finalization of module 2 should trigger finalization of module 1. // Verify that finalize on SMMW is only called once. @@ -193,12 +203,17 @@ TEST_F(RTDyldObjectLinkingLayerExecutionTest, NoDuplicateFinalization) { } TEST_F(RTDyldObjectLinkingLayerExecutionTest, NoPrematureAllocation) { - if (!TM) + if (!SupportsJIT) return; + ExecutionSession ES(std::make_shared<SymbolStringPool>()); + auto MM = std::make_shared<SectionMemoryManagerWrapper>(); - RTDyldObjectLinkingLayer ObjLayer([&MM]() { return MM; }); + RTDyldObjectLinkingLayer ObjLayer(ES, [&MM](VModuleKey K) { + return RTDyldObjectLinkingLayer::Resources{ + MM, std::make_shared<NullResolver>()}; + }); SimpleCompiler Compile(*TM); // Create a pair of unrelated modules: @@ -225,9 +240,7 @@ TEST_F(RTDyldObjectLinkingLayerExecutionTest, NoPrematureAllocation) { Builder.CreateRet(FourtyTwo); } - auto Obj1 = - std::make_shared<object::OwningBinary<object::ObjectFile>>( - Compile(*MB1.getModule())); + auto Obj1 = Compile(*MB1.getModule()); ModuleBuilder MB2(Context, "", "dummy"); { @@ -239,15 +252,13 @@ TEST_F(RTDyldObjectLinkingLayerExecutionTest, NoPrematureAllocation) { Value *Seven = ConstantInt::getSigned(Int32Ty, 7); Builder.CreateRet(Seven); } - auto Obj2 = - std::make_shared<object::OwningBinary<object::ObjectFile>>( - Compile(*MB2.getModule())); + auto Obj2 = Compile(*MB2.getModule()); - auto NR = std::make_shared<NullResolver>(); - auto H = cantFail(ObjLayer.addObject(std::move(Obj1), NR)); - cantFail(ObjLayer.addObject(std::move(Obj2), NR)); - cantFail(ObjLayer.emitAndFinalize(H)); - cantFail(ObjLayer.removeObject(H)); + auto K = ES.allocateVModule(); + cantFail(ObjLayer.addObject(K, std::move(Obj1))); + cantFail(ObjLayer.addObject(ES.allocateVModule(), std::move(Obj2))); + cantFail(ObjLayer.emitAndFinalize(K)); + cantFail(ObjLayer.removeObject(K)); // Only one call to needsToReserveAllocationSpace should have been made. EXPECT_EQ(MM->NeedsToReserveAllocationSpaceCount, 1) @@ -256,10 +267,14 @@ TEST_F(RTDyldObjectLinkingLayerExecutionTest, NoPrematureAllocation) { } TEST_F(RTDyldObjectLinkingLayerExecutionTest, TestNotifyLoadedSignature) { + ExecutionSession ES(std::make_shared<SymbolStringPool>()); RTDyldObjectLinkingLayer ObjLayer( - []() { return nullptr; }, - [](RTDyldObjectLinkingLayer::ObjHandleT, - const RTDyldObjectLinkingLayer::ObjectPtr &obj, + ES, + [](VModuleKey) { + return RTDyldObjectLinkingLayer::Resources{ + nullptr, std::make_shared<NullResolver>()}; + }, + [](VModuleKey, const object::ObjectFile &obj, const RuntimeDyld::LoadedObjectInfo &info) {}); } |