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 const char BlockContentBytes[] = {0x01, 0x02, 0x03, 0x04,
23 0x05, 0x06, 0x07, 0x08};
24
25 ArrayRef<char> BlockContent(BlockContentBytes);
26
27 class ObjectLinkingLayerTest : public testing::Test {
28 public:
~ObjectLinkingLayerTest()29 ~ObjectLinkingLayerTest() {
30 if (auto Err = ES.endSession())
31 ES.reportError(std::move(Err));
32 }
33
34 protected:
35 ExecutionSession ES{std::make_unique<UnsupportedExecutorProcessControl>()};
36 JITDylib &JD = ES.createBareJITDylib("main");
37 ObjectLinkingLayer ObjLinkingLayer{
38 ES, std::make_unique<InProcessMemoryManager>(4096)};
39 };
40
TEST_F(ObjectLinkingLayerTest,AddLinkGraph)41 TEST_F(ObjectLinkingLayerTest, AddLinkGraph) {
42 auto G =
43 std::make_unique<LinkGraph>("foo", Triple("x86_64-apple-darwin"), 8,
44 support::little, x86_64::getEdgeKindName);
45
46 auto &Sec1 = G->createSection("__data", MemProt::Read | MemProt::Write);
47 auto &B1 = G->createContentBlock(Sec1, BlockContent,
48 orc::ExecutorAddr(0x1000), 8, 0);
49 G->addDefinedSymbol(B1, 4, "_X", 4, Linkage::Strong, Scope::Default, false,
50 false);
51
52 EXPECT_THAT_ERROR(ObjLinkingLayer.add(JD, std::move(G)), Succeeded());
53
54 EXPECT_THAT_EXPECTED(ES.lookup(&JD, "_X"), Succeeded());
55 }
56
57 } // end anonymous namespace
58