| 1 |
//===-------- X86_64Tests.cpp - Unit tests for the AArch64 backend --------===// |
| 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/BinaryFormat/ELF.h> |
| 10 |
#include <llvm/ExecutionEngine/JITLink/x86_64.h> |
| 11 |
|
| 12 |
#include "gtest/gtest.h" |
| 13 |
|
| 14 |
using namespace llvm; |
| 15 |
using namespace llvm::jitlink; |
| 16 |
using namespace llvm::jitlink::x86_64; |
| 17 |
|
| 18 |
TEST(X86_64, EmptyLinkGraph) { |
| 19 |
LinkGraph G("foo", std::make_shared<orc::SymbolStringPool>(), |
| 20 |
Triple("x86_64-apple-darwin"), SubtargetFeatures(), |
| 21 |
getEdgeKindName); |
| 22 |
EXPECT_EQ(G.getName(), "foo"); |
| 23 |
EXPECT_EQ(G.getTargetTriple().str(), "x86_64-apple-darwin"); |
| 24 |
EXPECT_EQ(G.getPointerSize(), 8U); |
| 25 |
EXPECT_EQ(G.getEndianness(), llvm::endianness::little); |
| 26 |
EXPECT_TRUE(G.external_symbols().empty()); |
| 27 |
EXPECT_TRUE(G.absolute_symbols().empty()); |
| 28 |
EXPECT_TRUE(G.defined_symbols().empty()); |
| 29 |
EXPECT_TRUE(G.blocks().empty()); |
| 30 |
} |
| 31 |
|
| 32 |
TEST(X86_64, GOTAndStubs) { |
| 33 |
LinkGraph G("foo", std::make_shared<orc::SymbolStringPool>(), |
| 34 |
Triple("x86_64-apple-darwin"), SubtargetFeatures(), |
| 35 |
getEdgeKindName); |
| 36 |
|
| 37 |
auto &External = G.addExternalSymbol("external", 0, false); |
| 38 |
|
| 39 |
// First table accesses. We expect the graph to be empty: |
| 40 |
EXPECT_EQ(G.findSectionByName(GOTTableManager::getSectionName()), nullptr); |
| 41 |
EXPECT_EQ(G.findSectionByName(PLTTableManager::getSectionName()), nullptr); |
| 42 |
|
| 43 |
{ |
| 44 |
// Create first GOT and PLT table managers and request a PLT stub. This |
| 45 |
// should force creation of both a PLT stub and GOT entry. |
| 46 |
GOTTableManager GOT(G); |
| 47 |
PLTTableManager PLT(G, GOT); |
| 48 |
|
| 49 |
PLT.getEntryForTarget(G, External); |
| 50 |
} |
| 51 |
|
| 52 |
auto *GOTSec = G.findSectionByName(GOTTableManager::getSectionName()); |
| 53 |
EXPECT_NE(GOTSec, nullptr); |
| 54 |
if (GOTSec) { |
| 55 |
// Expect one entry in the GOT now. |
| 56 |
EXPECT_EQ(GOTSec->symbols_size(), 1U); |
| 57 |
EXPECT_EQ(GOTSec->blocks_size(), 1U); |
| 58 |
} |
| 59 |
|
| 60 |
auto *PLTSec = G.findSectionByName(PLTTableManager::getSectionName()); |
| 61 |
EXPECT_NE(PLTSec, nullptr); |
| 62 |
if (PLTSec) { |
| 63 |
// Expect one entry in the PLT. |
| 64 |
EXPECT_EQ(PLTSec->symbols_size(), 1U); |
| 65 |
EXPECT_EQ(PLTSec->blocks_size(), 1U); |
| 66 |
} |
| 67 |
|
| 68 |
{ |
| 69 |
// Create second GOT and PLT table managers and request a PLT stub. This |
| 70 |
// should force creation of both a PLT stub and GOT entry. |
| 71 |
GOTTableManager GOT(G); |
| 72 |
PLTTableManager PLT(G, GOT); |
| 73 |
|
| 74 |
PLT.getEntryForTarget(G, External); |
| 75 |
} |
| 76 |
|
| 77 |
EXPECT_EQ(G.findSectionByName(GOTTableManager::getSectionName()), GOTSec); |
| 78 |
if (GOTSec) { |
| 79 |
// Expect the same one entry in the GOT. |
| 80 |
EXPECT_EQ(GOTSec->symbols_size(), 1U); |
| 81 |
EXPECT_EQ(GOTSec->blocks_size(), 1U); |
| 82 |
} |
| 83 |
|
| 84 |
EXPECT_EQ(G.findSectionByName(PLTTableManager::getSectionName()), PLTSec); |
| 85 |
if (PLTSec) { |
| 86 |
// Expect the same one entry in the GOT. |
| 87 |
EXPECT_EQ(PLTSec->symbols_size(), 1U); |
| 88 |
EXPECT_EQ(PLTSec->blocks_size(), 1U); |
| 89 |
} |
| 90 |
} |