1 //===-------- ObjectLinkingLayerTest.cpp - ObjectLinkingLayer tests -------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h" 10 #include "llvm/ExecutionEngine/JITLink/JITLink.h" 11 #include "llvm/ExecutionEngine/JITLink/JITLinkMemoryManager.h" 12 #include "llvm/ExecutionEngine/JITLink/x86_64.h" 13 #include "llvm/Testing/Support/Error.h" 14 #include "gtest/gtest.h" 15 16 using namespace llvm; 17 using namespace llvm::jitlink; 18 using namespace llvm::orc; 19 20 namespace { 21 22 auto RWFlags = 23 sys::Memory::ProtectionFlags(sys::Memory::MF_READ | sys::Memory::MF_WRITE); 24 25 const char BlockContentBytes[] = {0x01, 0x02, 0x03, 0x04, 26 0x05, 0x06, 0x07, 0x08}; 27 28 ArrayRef<char> BlockContent(BlockContentBytes); 29 30 class ObjectLinkingLayerTest : public testing::Test { 31 public: 32 ~ObjectLinkingLayerTest() { 33 if (auto Err = ES.endSession()) 34 ES.reportError(std::move(Err)); 35 } 36 37 protected: 38 ExecutionSession ES{std::make_unique<UnsupportedExecutorProcessControl>()}; 39 JITDylib &JD = ES.createBareJITDylib("main"); 40 ObjectLinkingLayer ObjLinkingLayer{ 41 ES, std::make_unique<InProcessMemoryManager>()}; 42 }; 43 44 TEST_F(ObjectLinkingLayerTest, AddLinkGraph) { 45 auto G = 46 std::make_unique<LinkGraph>("foo", Triple("x86_64-apple-darwin"), 8, 47 support::little, x86_64::getEdgeKindName); 48 49 auto &Sec1 = G->createSection("__data", RWFlags); 50 auto &B1 = G->createContentBlock(Sec1, BlockContent, 0x1000, 8, 0); 51 G->addDefinedSymbol(B1, 4, "_X", 4, Linkage::Strong, Scope::Default, false, 52 false); 53 54 EXPECT_THAT_ERROR(ObjLinkingLayer.add(JD, std::move(G)), Succeeded()); 55 56 EXPECT_THAT_EXPECTED(ES.lookup(&JD, "_X"), Succeeded()); 57 } 58 59 } // end anonymous namespace 60