1 //===-------- ObjectLinkingLayerTest.cpp - ObjectLinkingLayer tests -------===//
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
7 //===----------------------------------------------------------------------===//
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"
17 using namespace llvm::jitlink
;
18 using namespace llvm::orc
;
23 sys::Memory::ProtectionFlags(sys::Memory::MF_READ
| sys::Memory::MF_WRITE
);
25 const char BlockContentBytes
[] = {0x01, 0x02, 0x03, 0x04,
26 0x05, 0x06, 0x07, 0x08};
28 ArrayRef
<char> BlockContent(BlockContentBytes
);
30 class ObjectLinkingLayerTest
: public testing::Test
{
32 ~ObjectLinkingLayerTest() {
33 if (auto Err
= ES
.endSession())
34 ES
.reportError(std::move(Err
));
38 ExecutionSession ES
{std::make_unique
<UnsupportedExecutorProcessControl
>()};
39 JITDylib
&JD
= ES
.createBareJITDylib("main");
40 ObjectLinkingLayer ObjLinkingLayer
{
41 ES
, std::make_unique
<InProcessMemoryManager
>()};
44 TEST_F(ObjectLinkingLayerTest
, AddLinkGraph
) {
46 std::make_unique
<LinkGraph
>("foo", Triple("x86_64-apple-darwin"), 8,
47 support::little
, x86_64::getEdgeKindName
);
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,
54 EXPECT_THAT_ERROR(ObjLinkingLayer
.add(JD
, std::move(G
)), Succeeded());
56 EXPECT_THAT_EXPECTED(ES
.lookup(&JD
, "_X"), Succeeded());
59 } // end anonymous namespace