Skip to content

Commit 2bdf623

Browse files
[JITLink][AArch32] Split out error test for invalid edge in applyFixup()
Also rename the fixture class since these tests are not ELF-specific.
1 parent 7f3ee3c commit 2bdf623

File tree

1 file changed

+31
-13
lines changed

1 file changed

+31
-13
lines changed

llvm/unittests/ExecutionEngine/JITLink/AArch32ErrorTests.cpp

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,14 @@ constexpr uint64_t AlignmentOffset = 0;
3333
constexpr orc::ExecutorAddrDiff SymbolOffset = 0;
3434
constexpr orc::ExecutorAddrDiff SymbolSize = 4;
3535

36-
class AArch32Errors_ELF : public testing::Test {
36+
class AArch32Errors : public testing::Test {
3737
protected:
38-
ArmConfig ArmCfg = getArmConfigForCPUArch(ARMBuildAttrs::v7);
38+
const ArmConfig Cfg = getArmConfigForCPUArch(ARMBuildAttrs::v7);
3939
std::unique_ptr<LinkGraph> G;
4040
Section *S = nullptr;
4141

4242
const uint8_t Zeros[4]{0x00, 0x00, 0x00, 0x00};
43+
uint8_t MutableZeros[4]{0x00, 0x00, 0x00, 0x00};
4344

4445
public:
4546
static void SetUpTestCase() {}
@@ -62,15 +63,24 @@ class AArch32Errors_ELF : public testing::Test {
6263
return G->createContentBlock(*S, CharContent, orc::ExecutorAddr(Addr),
6364
Alignment, AlignmentOffset);
6465
}
66+
67+
template <size_t Size>
68+
Block &createMutableBlock(uint8_t (&Content)[Size], uint64_t Addr,
69+
uint64_t Alignment = 4) {
70+
MutableArrayRef<char> CharContent{reinterpret_cast<char *>(&Content),
71+
sizeof(Content)};
72+
return G->createMutableContentBlock(
73+
*S, CharContent, orc::ExecutorAddr(Addr), Alignment, AlignmentOffset);
74+
}
6575
};
6676

67-
TEST_F(AArch32Errors_ELF, readAddendDataErrors) {
77+
TEST_F(AArch32Errors, readAddendDataGeneric) {
6878
Block &ZerosBlock = createBlock(Zeros, 0x1000);
6979
constexpr uint64_t ZerosOffset = 0;
7080

7181
// Invalid edge kind is the only error we can raise here right now.
7282
Edge::Kind Invalid = Edge::GenericEdgeKind::Invalid;
73-
EXPECT_THAT_EXPECTED(readAddend(*G, ZerosBlock, ZerosOffset, Invalid, ArmCfg),
83+
EXPECT_THAT_EXPECTED(readAddend(*G, ZerosBlock, ZerosOffset, Invalid, Cfg),
7484
FailedWithMessage(testing::HasSubstr(
7585
"can not read implicit addend for aarch32 edge kind "
7686
"INVALID RELOCATION")));
@@ -121,6 +131,23 @@ TEST(AArch32_ELF, readAddendThumbErrors) {
121131
}
122132
}
123133

134+
TEST_F(AArch32Errors, applyFixupDataGeneric) {
135+
Block &OriginBlock = createMutableBlock(MutableZeros, 0x1000);
136+
Block &TargetBlock = createBlock(Zeros, 0x2000);
137+
138+
constexpr uint64_t OffsetInTarget = 0;
139+
Symbol &TargetSymbol = G->addAnonymousSymbol(TargetBlock, OffsetInTarget,
140+
PointerSize, false, false);
141+
142+
constexpr uint64_t OffsetInOrigin = 0;
143+
Edge::Kind Invalid = Edge::GenericEdgeKind::Invalid;
144+
Edge InvalidEdge(Invalid, OffsetInOrigin, TargetSymbol, 0 /*Addend*/);
145+
EXPECT_THAT_ERROR(
146+
applyFixup(*G, OriginBlock, InvalidEdge, Cfg),
147+
FailedWithMessage(testing::HasSubstr(
148+
"encountered unfixable aarch32 edge kind INVALID RELOCATION")));
149+
}
150+
124151
TEST(AArch32_ELF, applyFixupArmErrors) {
125152

126153
constexpr orc::ExecutorAddr B3DummyAddr(0x5000);
@@ -134,13 +161,6 @@ TEST(AArch32_ELF, applyFixupArmErrors) {
134161

135162
Symbol &TargetSymbol =
136163
G->addAnonymousSymbol(BArm, SymbolOffset, SymbolSize, false, false);
137-
Edge InvalidEdge(Edge::GenericEdgeKind::Invalid, 0 /*Offset*/, TargetSymbol,
138-
0 /*Addend*/);
139-
140-
EXPECT_THAT_ERROR(
141-
applyFixup(*G, BArm, InvalidEdge, ArmCfg),
142-
FailedWithMessage(testing::HasSubstr(
143-
"encountered unfixable aarch32 edge kind INVALID RELOCATION")));
144164

145165
for (Edge::Kind K = FirstArmRelocation; K < LastArmRelocation; K += 1) {
146166
Edge E(K, 0, TargetSymbol, 0);
@@ -180,8 +200,6 @@ TEST(AArch32_ELF, applyFixupThumbErrors) {
180200
Sec, MutableThumbContent, B4DummyAddr, ThumbAlignment, AlignmentOffset);
181201
Symbol &TargetSymbol =
182202
G->addAnonymousSymbol(BThumb, SymbolOffset, SymbolSize, false, false);
183-
Edge InvalidEdge(Edge::GenericEdgeKind::Invalid, 0 /*Offset*/, TargetSymbol,
184-
0 /*Addend*/);
185203

186204
for (Edge::Kind K = FirstThumbRelocation; K < LastThumbRelocation; K += 1) {
187205
Edge E(K, 0, TargetSymbol, 0);

0 commit comments

Comments
 (0)