[llvm] [JITLink][AArch32] Unittest for error paths of readAddend and applyFixup functionality (PR #69636)
Eymen Ünay via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 7 10:39:49 PST 2023
https://github.com/eymay updated https://github.com/llvm/llvm-project/pull/69636
>From 4d3d045894e07fb94dcf283a6a824eeb68f0f21e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Eymen=20=C3=9Cnay?= <eymenunay at outlook.com>
Date: Thu, 19 Oct 2023 22:38:05 +0300
Subject: [PATCH 1/8] [JITLink][AArch32] Unittest for error paths of readAddend
functionality
This commit is part of an effort to increase coverage of AArch32 backend.
---
.../ExecutionEngine/JITLink/AArch32Tests.cpp | 94 +++++++++++++++++++
1 file changed, 94 insertions(+)
diff --git a/llvm/unittests/ExecutionEngine/JITLink/AArch32Tests.cpp b/llvm/unittests/ExecutionEngine/JITLink/AArch32Tests.cpp
index dcc8d3b237ff318..1df59edcd769407 100644
--- a/llvm/unittests/ExecutionEngine/JITLink/AArch32Tests.cpp
+++ b/llvm/unittests/ExecutionEngine/JITLink/AArch32Tests.cpp
@@ -9,6 +9,7 @@
#include <llvm/BinaryFormat/ELF.h>
#include <llvm/ExecutionEngine/JITLink/aarch32.h>
+#include "llvm/Testing/Support/Error.h"
#include "gtest/gtest.h"
using namespace llvm;
@@ -67,6 +68,99 @@ TEST(AArch32_ELF, EdgeKinds) {
}
}
+struct ThumbRelocation {
+ /// Create a read-only reference to a Thumb32 fixup.
+ ThumbRelocation(const char *FixupPtr)
+ : Hi{*reinterpret_cast<const support::ulittle16_t *>(FixupPtr)},
+ Lo{*reinterpret_cast<const support::ulittle16_t *>(FixupPtr + 2)} {}
+
+ const support::ulittle16_t &Hi; // First halfword
+ const support::ulittle16_t &Lo; // Second halfword
+};
+
+struct ArmRelocation {
+
+ ArmRelocation(const char *FixupPtr)
+ : Wd{*reinterpret_cast<const support::ulittle32_t *>(FixupPtr)} {}
+
+ const support::ulittle32_t &Wd;
+};
+
+std::string makeUnexpectedOpcodeError(const LinkGraph &G,
+ const ThumbRelocation &R,
+ Edge::Kind Kind) {
+ return formatv("Invalid opcode [ {0:x4}, {1:x4} ] for relocation: {2}",
+ static_cast<uint16_t>(R.Hi), static_cast<uint16_t>(R.Lo),
+ G.getEdgeKindName(Kind));
+}
+
+std::string makeUnexpectedOpcodeError(const LinkGraph &G,
+ const ArmRelocation &R, Edge::Kind Kind) {
+ return formatv("Invalid opcode {0:x8} for relocation: {1}",
+ static_cast<uint32_t>(R.Wd), G.getEdgeKindName(Kind));
+}
+
+TEST(AArch32_ELF, readAddends) {
+ auto G = std::make_unique<LinkGraph>("foo", Triple("armv7-linux-gnueabi"), 4,
+ llvm::endianness::little,
+ getGenericEdgeKindName);
+
+ ArrayRef<char> Content = "hello, world!";
+ auto &Sec =
+ G->createSection("__data", orc::MemProt::Read | orc::MemProt::Write);
+ orc::ExecutorAddr B1Addr(0x1000);
+ auto &B = G->createContentBlock(Sec, Content, B1Addr, 4, 0);
+
+ Symbol &TargetSymbol = G->addAnonymousSymbol(B, 0, 4, false, false);
+ Edge InvalidEdge(FirstDataRelocation - 1, 0, TargetSymbol, 0);
+
+ auto ArmCfg = getArmConfigForCPUArch(ARMBuildAttrs::v7);
+
+ auto makeReadAddendError = [](LinkGraph &G, Block &B, Edge &E) {
+ return ("In graph " + G.getName() + ", section " +
+ B.getSection().getName() +
+ " can not read implicit addend for aarch32 edge kind " +
+ G.getEdgeKindName(E.getKind()))
+ .str();
+ };
+
+ EXPECT_THAT_EXPECTED(
+ readAddend(*G, B, InvalidEdge, ArmCfg),
+ FailedWithMessage(makeReadAddendError(*G, B, InvalidEdge)));
+
+ ArmRelocation R_Arm(B.getContent().data());
+ ThumbRelocation R_Thumb(B.getContent().data());
+
+ for (Edge::Kind K = FirstDataRelocation; K < LastDataRelocation; K += 1) {
+ Edge E(K, 0, TargetSymbol, 0);
+ EXPECT_THAT_EXPECTED(readAddendData(*G, B, E), Succeeded());
+ EXPECT_THAT_EXPECTED(readAddendArm(*G, B, E),
+ FailedWithMessage(makeReadAddendError(*G, B, E)));
+ EXPECT_THAT_EXPECTED(readAddendThumb(*G, B, E, ArmCfg),
+ FailedWithMessage(makeReadAddendError(*G, B, E)));
+ }
+ for (Edge::Kind K = FirstArmRelocation; K < LastArmRelocation; K += 1) {
+ Edge E(K, 0, TargetSymbol, 0);
+ EXPECT_THAT_EXPECTED(readAddendData(*G, B, E),
+ FailedWithMessage(makeReadAddendError(*G, B, E)));
+ EXPECT_THAT_EXPECTED(
+ readAddendArm(*G, B, E),
+ FailedWithMessage(makeUnexpectedOpcodeError(*G, R_Arm, K)));
+ EXPECT_THAT_EXPECTED(readAddendThumb(*G, B, E, ArmCfg),
+ FailedWithMessage(makeReadAddendError(*G, B, E)));
+ }
+ for (Edge::Kind K = FirstThumbRelocation; K < LastThumbRelocation; K += 1) {
+ Edge E(K, 0, TargetSymbol, 0);
+ EXPECT_THAT_EXPECTED(readAddendData(*G, B, E),
+ FailedWithMessage(makeReadAddendError(*G, B, E)));
+ EXPECT_THAT_EXPECTED(readAddendArm(*G, B, E),
+ FailedWithMessage(makeReadAddendError(*G, B, E)));
+ EXPECT_THAT_EXPECTED(
+ readAddendThumb(*G, B, E, ArmCfg),
+ FailedWithMessage(makeUnexpectedOpcodeError(*G, R_Thumb, K)));
+ }
+}
+
namespace llvm {
namespace jitlink {
namespace aarch32 {
>From 200bdfd492a0602f88a93735ca60115c0d2af39c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Eymen=20=C3=9Cnay?= <eymenunay at outlook.com>
Date: Wed, 25 Oct 2023 13:03:53 +0300
Subject: [PATCH 2/8] Move test to another file
---
.../JITLink/AArch32ErrorTests.cpp | 112 ++++++++++++++++++
.../ExecutionEngine/JITLink/AArch32Tests.cpp | 92 --------------
.../ExecutionEngine/JITLink/CMakeLists.txt | 1 +
3 files changed, 113 insertions(+), 92 deletions(-)
create mode 100644 llvm/unittests/ExecutionEngine/JITLink/AArch32ErrorTests.cpp
diff --git a/llvm/unittests/ExecutionEngine/JITLink/AArch32ErrorTests.cpp b/llvm/unittests/ExecutionEngine/JITLink/AArch32ErrorTests.cpp
new file mode 100644
index 000000000000000..0a1155443345c3e
--- /dev/null
+++ b/llvm/unittests/ExecutionEngine/JITLink/AArch32ErrorTests.cpp
@@ -0,0 +1,112 @@
+//===------- AArch32ErrorTests.cpp - Unit tests for AArch32 error handling -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include <llvm/ExecutionEngine/JITLink/aarch32.h>
+
+
+#include "llvm/Testing/Support/Error.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+using namespace llvm::jitlink;
+using namespace llvm::jitlink::aarch32;
+using namespace llvm::support;
+using namespace llvm::support::endian;
+
+struct ThumbRelocation {
+ /// Create a read-only reference to a Thumb32 fixup.
+ ThumbRelocation(const char *FixupPtr)
+ : Hi{*reinterpret_cast<const support::ulittle16_t *>(FixupPtr)},
+ Lo{*reinterpret_cast<const support::ulittle16_t *>(FixupPtr + 2)} {}
+
+ const support::ulittle16_t &Hi; // First halfword
+ const support::ulittle16_t &Lo; // Second halfword
+};
+
+struct ArmRelocation {
+
+ ArmRelocation(const char *FixupPtr)
+ : Wd{*reinterpret_cast<const support::ulittle32_t *>(FixupPtr)} {}
+
+ const support::ulittle32_t &Wd;
+};
+
+std::string makeUnexpectedOpcodeError(const LinkGraph &G,
+ const ThumbRelocation &R,
+ Edge::Kind Kind) {
+ return formatv("Invalid opcode [ {0:x4}, {1:x4} ] for relocation: {2}",
+ static_cast<uint16_t>(R.Hi), static_cast<uint16_t>(R.Lo),
+ G.getEdgeKindName(Kind));
+}
+
+std::string makeUnexpectedOpcodeError(const LinkGraph &G,
+ const ArmRelocation &R, Edge::Kind Kind) {
+ return formatv("Invalid opcode {0:x8} for relocation: {1}",
+ static_cast<uint32_t>(R.Wd), G.getEdgeKindName(Kind));
+}
+
+TEST(AArch32_ELF, readAddends) {
+ auto G = std::make_unique<LinkGraph>("foo", Triple("armv7-linux-gnueabi"), 4,
+ llvm::endianness::little,
+ getGenericEdgeKindName);
+
+ ArrayRef<char> Content = "hello, world!";
+ auto &Sec =
+ G->createSection("__data", orc::MemProt::Read | orc::MemProt::Write);
+ orc::ExecutorAddr B1Addr(0x1000);
+ auto &B = G->createContentBlock(Sec, Content, B1Addr, 4, 0);
+
+ Symbol &TargetSymbol = G->addAnonymousSymbol(B, 0, 4, false, false);
+ Edge InvalidEdge(FirstDataRelocation - 1, 0, TargetSymbol, 0);
+
+ auto ArmCfg = getArmConfigForCPUArch(ARMBuildAttrs::v7);
+
+ auto makeReadAddendError = [](LinkGraph &G, Block &B, Edge &E) {
+ return ("In graph " + G.getName() + ", section " +
+ B.getSection().getName() +
+ " can not read implicit addend for aarch32 edge kind " +
+ G.getEdgeKindName(E.getKind()))
+ .str();
+ };
+
+ EXPECT_THAT_EXPECTED(
+ readAddend(*G, B, InvalidEdge, ArmCfg),
+ FailedWithMessage(makeReadAddendError(*G, B, InvalidEdge)));
+
+ ArmRelocation R_Arm(B.getContent().data());
+ ThumbRelocation R_Thumb(B.getContent().data());
+
+ for (Edge::Kind K = FirstDataRelocation; K < LastDataRelocation; K += 1) {
+ Edge E(K, 0, TargetSymbol, 0);
+ EXPECT_THAT_EXPECTED(readAddendData(*G, B, E), Succeeded());
+ EXPECT_THAT_EXPECTED(readAddendArm(*G, B, E),
+ FailedWithMessage(makeReadAddendError(*G, B, E)));
+ EXPECT_THAT_EXPECTED(readAddendThumb(*G, B, E, ArmCfg),
+ FailedWithMessage(makeReadAddendError(*G, B, E)));
+ }
+ for (Edge::Kind K = FirstArmRelocation; K < LastArmRelocation; K += 1) {
+ Edge E(K, 0, TargetSymbol, 0);
+ EXPECT_THAT_EXPECTED(readAddendData(*G, B, E),
+ FailedWithMessage(makeReadAddendError(*G, B, E)));
+ EXPECT_THAT_EXPECTED(
+ readAddendArm(*G, B, E),
+ FailedWithMessage(makeUnexpectedOpcodeError(*G, R_Arm, K)));
+ EXPECT_THAT_EXPECTED(readAddendThumb(*G, B, E, ArmCfg),
+ FailedWithMessage(makeReadAddendError(*G, B, E)));
+ }
+ for (Edge::Kind K = FirstThumbRelocation; K < LastThumbRelocation; K += 1) {
+ Edge E(K, 0, TargetSymbol, 0);
+ EXPECT_THAT_EXPECTED(readAddendData(*G, B, E),
+ FailedWithMessage(makeReadAddendError(*G, B, E)));
+ EXPECT_THAT_EXPECTED(readAddendArm(*G, B, E),
+ FailedWithMessage(makeReadAddendError(*G, B, E)));
+ EXPECT_THAT_EXPECTED(
+ readAddendThumb(*G, B, E, ArmCfg),
+ FailedWithMessage(makeUnexpectedOpcodeError(*G, R_Thumb, K)));
+ }
+}
diff --git a/llvm/unittests/ExecutionEngine/JITLink/AArch32Tests.cpp b/llvm/unittests/ExecutionEngine/JITLink/AArch32Tests.cpp
index 1df59edcd769407..5bcfb85ac44bfb5 100644
--- a/llvm/unittests/ExecutionEngine/JITLink/AArch32Tests.cpp
+++ b/llvm/unittests/ExecutionEngine/JITLink/AArch32Tests.cpp
@@ -68,98 +68,6 @@ TEST(AArch32_ELF, EdgeKinds) {
}
}
-struct ThumbRelocation {
- /// Create a read-only reference to a Thumb32 fixup.
- ThumbRelocation(const char *FixupPtr)
- : Hi{*reinterpret_cast<const support::ulittle16_t *>(FixupPtr)},
- Lo{*reinterpret_cast<const support::ulittle16_t *>(FixupPtr + 2)} {}
-
- const support::ulittle16_t &Hi; // First halfword
- const support::ulittle16_t &Lo; // Second halfword
-};
-
-struct ArmRelocation {
-
- ArmRelocation(const char *FixupPtr)
- : Wd{*reinterpret_cast<const support::ulittle32_t *>(FixupPtr)} {}
-
- const support::ulittle32_t &Wd;
-};
-
-std::string makeUnexpectedOpcodeError(const LinkGraph &G,
- const ThumbRelocation &R,
- Edge::Kind Kind) {
- return formatv("Invalid opcode [ {0:x4}, {1:x4} ] for relocation: {2}",
- static_cast<uint16_t>(R.Hi), static_cast<uint16_t>(R.Lo),
- G.getEdgeKindName(Kind));
-}
-
-std::string makeUnexpectedOpcodeError(const LinkGraph &G,
- const ArmRelocation &R, Edge::Kind Kind) {
- return formatv("Invalid opcode {0:x8} for relocation: {1}",
- static_cast<uint32_t>(R.Wd), G.getEdgeKindName(Kind));
-}
-
-TEST(AArch32_ELF, readAddends) {
- auto G = std::make_unique<LinkGraph>("foo", Triple("armv7-linux-gnueabi"), 4,
- llvm::endianness::little,
- getGenericEdgeKindName);
-
- ArrayRef<char> Content = "hello, world!";
- auto &Sec =
- G->createSection("__data", orc::MemProt::Read | orc::MemProt::Write);
- orc::ExecutorAddr B1Addr(0x1000);
- auto &B = G->createContentBlock(Sec, Content, B1Addr, 4, 0);
-
- Symbol &TargetSymbol = G->addAnonymousSymbol(B, 0, 4, false, false);
- Edge InvalidEdge(FirstDataRelocation - 1, 0, TargetSymbol, 0);
-
- auto ArmCfg = getArmConfigForCPUArch(ARMBuildAttrs::v7);
-
- auto makeReadAddendError = [](LinkGraph &G, Block &B, Edge &E) {
- return ("In graph " + G.getName() + ", section " +
- B.getSection().getName() +
- " can not read implicit addend for aarch32 edge kind " +
- G.getEdgeKindName(E.getKind()))
- .str();
- };
-
- EXPECT_THAT_EXPECTED(
- readAddend(*G, B, InvalidEdge, ArmCfg),
- FailedWithMessage(makeReadAddendError(*G, B, InvalidEdge)));
-
- ArmRelocation R_Arm(B.getContent().data());
- ThumbRelocation R_Thumb(B.getContent().data());
-
- for (Edge::Kind K = FirstDataRelocation; K < LastDataRelocation; K += 1) {
- Edge E(K, 0, TargetSymbol, 0);
- EXPECT_THAT_EXPECTED(readAddendData(*G, B, E), Succeeded());
- EXPECT_THAT_EXPECTED(readAddendArm(*G, B, E),
- FailedWithMessage(makeReadAddendError(*G, B, E)));
- EXPECT_THAT_EXPECTED(readAddendThumb(*G, B, E, ArmCfg),
- FailedWithMessage(makeReadAddendError(*G, B, E)));
- }
- for (Edge::Kind K = FirstArmRelocation; K < LastArmRelocation; K += 1) {
- Edge E(K, 0, TargetSymbol, 0);
- EXPECT_THAT_EXPECTED(readAddendData(*G, B, E),
- FailedWithMessage(makeReadAddendError(*G, B, E)));
- EXPECT_THAT_EXPECTED(
- readAddendArm(*G, B, E),
- FailedWithMessage(makeUnexpectedOpcodeError(*G, R_Arm, K)));
- EXPECT_THAT_EXPECTED(readAddendThumb(*G, B, E, ArmCfg),
- FailedWithMessage(makeReadAddendError(*G, B, E)));
- }
- for (Edge::Kind K = FirstThumbRelocation; K < LastThumbRelocation; K += 1) {
- Edge E(K, 0, TargetSymbol, 0);
- EXPECT_THAT_EXPECTED(readAddendData(*G, B, E),
- FailedWithMessage(makeReadAddendError(*G, B, E)));
- EXPECT_THAT_EXPECTED(readAddendArm(*G, B, E),
- FailedWithMessage(makeReadAddendError(*G, B, E)));
- EXPECT_THAT_EXPECTED(
- readAddendThumb(*G, B, E, ArmCfg),
- FailedWithMessage(makeUnexpectedOpcodeError(*G, R_Thumb, K)));
- }
-}
namespace llvm {
namespace jitlink {
diff --git a/llvm/unittests/ExecutionEngine/JITLink/CMakeLists.txt b/llvm/unittests/ExecutionEngine/JITLink/CMakeLists.txt
index e535bcf47fc801e..d4886754f0a9ca4 100644
--- a/llvm/unittests/ExecutionEngine/JITLink/CMakeLists.txt
+++ b/llvm/unittests/ExecutionEngine/JITLink/CMakeLists.txt
@@ -9,6 +9,7 @@ set(LLVM_LINK_COMPONENTS
add_llvm_unittest(JITLinkTests
AArch32Tests.cpp
+ AArch32ErrorTests.cpp
EHFrameSupportTests.cpp
JITLinkMocks.cpp
LinkGraphTests.cpp
>From 0386ab7531398c9b20c9eb8a5b95cd7ec2013a9d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Eymen=20=C3=9Cnay?= <eymenunay at outlook.com>
Date: Wed, 25 Oct 2023 16:39:43 +0300
Subject: [PATCH 3/8] replace Error functions with string matchers
---
.../JITLink/AArch32ErrorTests.cpp | 59 ++++---------------
1 file changed, 10 insertions(+), 49 deletions(-)
diff --git a/llvm/unittests/ExecutionEngine/JITLink/AArch32ErrorTests.cpp b/llvm/unittests/ExecutionEngine/JITLink/AArch32ErrorTests.cpp
index 0a1155443345c3e..47b6b1c9d469746 100644
--- a/llvm/unittests/ExecutionEngine/JITLink/AArch32ErrorTests.cpp
+++ b/llvm/unittests/ExecutionEngine/JITLink/AArch32ErrorTests.cpp
@@ -18,37 +18,6 @@ using namespace llvm::jitlink::aarch32;
using namespace llvm::support;
using namespace llvm::support::endian;
-struct ThumbRelocation {
- /// Create a read-only reference to a Thumb32 fixup.
- ThumbRelocation(const char *FixupPtr)
- : Hi{*reinterpret_cast<const support::ulittle16_t *>(FixupPtr)},
- Lo{*reinterpret_cast<const support::ulittle16_t *>(FixupPtr + 2)} {}
-
- const support::ulittle16_t &Hi; // First halfword
- const support::ulittle16_t &Lo; // Second halfword
-};
-
-struct ArmRelocation {
-
- ArmRelocation(const char *FixupPtr)
- : Wd{*reinterpret_cast<const support::ulittle32_t *>(FixupPtr)} {}
-
- const support::ulittle32_t &Wd;
-};
-
-std::string makeUnexpectedOpcodeError(const LinkGraph &G,
- const ThumbRelocation &R,
- Edge::Kind Kind) {
- return formatv("Invalid opcode [ {0:x4}, {1:x4} ] for relocation: {2}",
- static_cast<uint16_t>(R.Hi), static_cast<uint16_t>(R.Lo),
- G.getEdgeKindName(Kind));
-}
-
-std::string makeUnexpectedOpcodeError(const LinkGraph &G,
- const ArmRelocation &R, Edge::Kind Kind) {
- return formatv("Invalid opcode {0:x8} for relocation: {1}",
- static_cast<uint32_t>(R.Wd), G.getEdgeKindName(Kind));
-}
TEST(AArch32_ELF, readAddends) {
auto G = std::make_unique<LinkGraph>("foo", Triple("armv7-linux-gnueabi"), 4,
@@ -66,47 +35,39 @@ TEST(AArch32_ELF, readAddends) {
auto ArmCfg = getArmConfigForCPUArch(ARMBuildAttrs::v7);
- auto makeReadAddendError = [](LinkGraph &G, Block &B, Edge &E) {
- return ("In graph " + G.getName() + ", section " +
- B.getSection().getName() +
- " can not read implicit addend for aarch32 edge kind " +
- G.getEdgeKindName(E.getKind()))
- .str();
- };
EXPECT_THAT_EXPECTED(
readAddend(*G, B, InvalidEdge, ArmCfg),
- FailedWithMessage(makeReadAddendError(*G, B, InvalidEdge)));
+ FailedWithMessage(testing::HasSubstr("can not read implicit addend for aarch32 edge kind Keep-Alive")));
- ArmRelocation R_Arm(B.getContent().data());
- ThumbRelocation R_Thumb(B.getContent().data());
+ std::string ReadAddendError = "can not read implicit addend for aarch32 edge kind <Unrecognized edge kind>";
for (Edge::Kind K = FirstDataRelocation; K < LastDataRelocation; K += 1) {
Edge E(K, 0, TargetSymbol, 0);
EXPECT_THAT_EXPECTED(readAddendData(*G, B, E), Succeeded());
EXPECT_THAT_EXPECTED(readAddendArm(*G, B, E),
- FailedWithMessage(makeReadAddendError(*G, B, E)));
+ FailedWithMessage(testing::HasSubstr(ReadAddendError)));
EXPECT_THAT_EXPECTED(readAddendThumb(*G, B, E, ArmCfg),
- FailedWithMessage(makeReadAddendError(*G, B, E)));
+ FailedWithMessage(testing::HasSubstr(ReadAddendError)));
}
for (Edge::Kind K = FirstArmRelocation; K < LastArmRelocation; K += 1) {
Edge E(K, 0, TargetSymbol, 0);
EXPECT_THAT_EXPECTED(readAddendData(*G, B, E),
- FailedWithMessage(makeReadAddendError(*G, B, E)));
+ FailedWithMessage(testing::HasSubstr(ReadAddendError)));
EXPECT_THAT_EXPECTED(
readAddendArm(*G, B, E),
- FailedWithMessage(makeUnexpectedOpcodeError(*G, R_Arm, K)));
+ FailedWithMessage(testing::StartsWith("Invalid opcode")));
EXPECT_THAT_EXPECTED(readAddendThumb(*G, B, E, ArmCfg),
- FailedWithMessage(makeReadAddendError(*G, B, E)));
+ FailedWithMessage(testing::HasSubstr(ReadAddendError)));
}
for (Edge::Kind K = FirstThumbRelocation; K < LastThumbRelocation; K += 1) {
Edge E(K, 0, TargetSymbol, 0);
EXPECT_THAT_EXPECTED(readAddendData(*G, B, E),
- FailedWithMessage(makeReadAddendError(*G, B, E)));
+ FailedWithMessage(testing::HasSubstr(ReadAddendError)));
EXPECT_THAT_EXPECTED(readAddendArm(*G, B, E),
- FailedWithMessage(makeReadAddendError(*G, B, E)));
+ FailedWithMessage(testing::HasSubstr(ReadAddendError)));
EXPECT_THAT_EXPECTED(
readAddendThumb(*G, B, E, ArmCfg),
- FailedWithMessage(makeUnexpectedOpcodeError(*G, R_Thumb, K)));
+ FailedWithMessage(testing::StartsWith("Invalid opcode")));
}
}
>From 0bc00cffba0cff99e0eb39022eb600744ecd37f2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Eymen=20=C3=9Cnay?= <eymenunay at outlook.com>
Date: Wed, 25 Oct 2023 18:29:00 +0300
Subject: [PATCH 4/8] Add applyFixup Error checking
---
.../JITLink/AArch32ErrorTests.cpp | 70 ++++++++++++++++---
.../ExecutionEngine/JITLink/AArch32Tests.cpp | 1 -
2 files changed, 59 insertions(+), 12 deletions(-)
diff --git a/llvm/unittests/ExecutionEngine/JITLink/AArch32ErrorTests.cpp b/llvm/unittests/ExecutionEngine/JITLink/AArch32ErrorTests.cpp
index 47b6b1c9d469746..1b784fd9297aeaf 100644
--- a/llvm/unittests/ExecutionEngine/JITLink/AArch32ErrorTests.cpp
+++ b/llvm/unittests/ExecutionEngine/JITLink/AArch32ErrorTests.cpp
@@ -1,4 +1,4 @@
-//===------- AArch32ErrorTests.cpp - Unit tests for AArch32 error handling -===//
+//===------- AArch32ErrorTests.cpp - Test AArch32 error handling ----------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -18,24 +18,23 @@ using namespace llvm::jitlink::aarch32;
using namespace llvm::support;
using namespace llvm::support::endian;
+auto G = std::make_unique<LinkGraph>("foo", Triple("armv7-linux-gnueabi"), 4,
+ llvm::endianness::little,
+ getGenericEdgeKindName);
+auto &Sec =
+ G->createSection("__data", orc::MemProt::Read | orc::MemProt::Write);
+orc::ExecutorAddr B1Addr(0x1000);
-TEST(AArch32_ELF, readAddends) {
- auto G = std::make_unique<LinkGraph>("foo", Triple("armv7-linux-gnueabi"), 4,
- llvm::endianness::little,
- getGenericEdgeKindName);
+auto ArmCfg = getArmConfigForCPUArch(ARMBuildAttrs::v7);
+
+TEST(AArch32_ELF, readAddendErrors) {
ArrayRef<char> Content = "hello, world!";
- auto &Sec =
- G->createSection("__data", orc::MemProt::Read | orc::MemProt::Write);
- orc::ExecutorAddr B1Addr(0x1000);
auto &B = G->createContentBlock(Sec, Content, B1Addr, 4, 0);
Symbol &TargetSymbol = G->addAnonymousSymbol(B, 0, 4, false, false);
Edge InvalidEdge(FirstDataRelocation - 1, 0, TargetSymbol, 0);
- auto ArmCfg = getArmConfigForCPUArch(ARMBuildAttrs::v7);
-
-
EXPECT_THAT_EXPECTED(
readAddend(*G, B, InvalidEdge, ArmCfg),
FailedWithMessage(testing::HasSubstr("can not read implicit addend for aarch32 edge kind Keep-Alive")));
@@ -71,3 +70,52 @@ TEST(AArch32_ELF, readAddends) {
FailedWithMessage(testing::StartsWith("Invalid opcode")));
}
}
+
+TEST(AArch32_ELF, applyFixupErrors) {
+ char ContentArray[] = "hello, world!";
+ MutableArrayRef<char> MutableContent(ContentArray);
+ auto &B = G->createMutableContentBlock(Sec, MutableContent, B1Addr, 4, 0);
+
+ Symbol &TargetSymbol = G->addAnonymousSymbol(B, 0, 4, false, false);
+ Edge InvalidEdge(FirstDataRelocation - 1, 0, TargetSymbol, 0);
+
+ EXPECT_THAT_ERROR(applyFixup(*G, B, InvalidEdge, ArmCfg),
+ FailedWithMessage(testing::HasSubstr(
+ "encountered unfixable aarch32 edge kind Keep-Alive")));
+
+ std::string UnfixableEdgeError =
+ "encountered unfixable aarch32 edge kind <Unrecognized edge kind>";
+
+ for (Edge::Kind K = FirstDataRelocation; K < LastDataRelocation; K += 1) {
+ Edge E(K, 0, TargetSymbol, 0);
+ EXPECT_THAT_ERROR(applyFixupData(*G, B, E), Succeeded());
+ EXPECT_THAT_ERROR(
+ applyFixupArm(*G, B, E),
+ FailedWithMessage(testing::HasSubstr(UnfixableEdgeError)));
+ EXPECT_THAT_ERROR(
+ applyFixupThumb(*G, B, E, ArmCfg),
+ FailedWithMessage(testing::HasSubstr(UnfixableEdgeError)));
+ }
+ for (Edge::Kind K = FirstArmRelocation; K < LastArmRelocation; K += 1) {
+ Edge E(K, 0, TargetSymbol, 0);
+ EXPECT_THAT_ERROR(
+ applyFixupData(*G, B, E),
+ FailedWithMessage(testing::HasSubstr(UnfixableEdgeError)));
+ EXPECT_THAT_ERROR(applyFixupArm(*G, B, E),
+ FailedWithMessage(testing::StartsWith("Invalid opcode")));
+ EXPECT_THAT_ERROR(
+ applyFixupThumb(*G, B, E, ArmCfg),
+ FailedWithMessage(testing::HasSubstr(UnfixableEdgeError)));
+ }
+ for (Edge::Kind K = FirstThumbRelocation; K < LastThumbRelocation; K += 1) {
+ Edge E(K, 0, TargetSymbol, 0);
+ EXPECT_THAT_ERROR(
+ applyFixupData(*G, B, E),
+ FailedWithMessage(testing::HasSubstr(UnfixableEdgeError)));
+ EXPECT_THAT_ERROR(
+ applyFixupArm(*G, B, E),
+ FailedWithMessage(testing::HasSubstr(UnfixableEdgeError)));
+ EXPECT_THAT_ERROR(applyFixupThumb(*G, B, E, ArmCfg),
+ FailedWithMessage(testing::StartsWith("Invalid opcode")));
+ }
+}
diff --git a/llvm/unittests/ExecutionEngine/JITLink/AArch32Tests.cpp b/llvm/unittests/ExecutionEngine/JITLink/AArch32Tests.cpp
index 5bcfb85ac44bfb5..0ff1798fc73bb4e 100644
--- a/llvm/unittests/ExecutionEngine/JITLink/AArch32Tests.cpp
+++ b/llvm/unittests/ExecutionEngine/JITLink/AArch32Tests.cpp
@@ -68,7 +68,6 @@ TEST(AArch32_ELF, EdgeKinds) {
}
}
-
namespace llvm {
namespace jitlink {
namespace aarch32 {
>From bd780f1f87ff02293676430a26df4c4c71478676 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Eymen=20=C3=9Cnay?= <eymenunay at outlook.com>
Date: Wed, 25 Oct 2023 18:38:42 +0300
Subject: [PATCH 5/8] remove Error.h
---
llvm/unittests/ExecutionEngine/JITLink/AArch32Tests.cpp | 1 -
1 file changed, 1 deletion(-)
diff --git a/llvm/unittests/ExecutionEngine/JITLink/AArch32Tests.cpp b/llvm/unittests/ExecutionEngine/JITLink/AArch32Tests.cpp
index 0ff1798fc73bb4e..dcc8d3b237ff318 100644
--- a/llvm/unittests/ExecutionEngine/JITLink/AArch32Tests.cpp
+++ b/llvm/unittests/ExecutionEngine/JITLink/AArch32Tests.cpp
@@ -9,7 +9,6 @@
#include <llvm/BinaryFormat/ELF.h>
#include <llvm/ExecutionEngine/JITLink/aarch32.h>
-#include "llvm/Testing/Support/Error.h"
#include "gtest/gtest.h"
using namespace llvm;
>From e119a2d7efbd681dab2a12a7e6ac1f338ebfd6c0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Eymen=20=C3=9Cnay?= <eymenunay at outlook.com>
Date: Thu, 26 Oct 2023 10:44:08 +0300
Subject: [PATCH 6/8] clang-format whole file
---
.../JITLink/AArch32ErrorTests.cpp | 37 +++++++++++--------
1 file changed, 22 insertions(+), 15 deletions(-)
diff --git a/llvm/unittests/ExecutionEngine/JITLink/AArch32ErrorTests.cpp b/llvm/unittests/ExecutionEngine/JITLink/AArch32ErrorTests.cpp
index 1b784fd9297aeaf..e06c223c37398d8 100644
--- a/llvm/unittests/ExecutionEngine/JITLink/AArch32ErrorTests.cpp
+++ b/llvm/unittests/ExecutionEngine/JITLink/AArch32ErrorTests.cpp
@@ -8,7 +8,6 @@
#include <llvm/ExecutionEngine/JITLink/aarch32.h>
-
#include "llvm/Testing/Support/Error.h"
#include "gtest/gtest.h"
@@ -37,34 +36,42 @@ TEST(AArch32_ELF, readAddendErrors) {
EXPECT_THAT_EXPECTED(
readAddend(*G, B, InvalidEdge, ArmCfg),
- FailedWithMessage(testing::HasSubstr("can not read implicit addend for aarch32 edge kind Keep-Alive")));
+ FailedWithMessage(testing::HasSubstr(
+ "can not read implicit addend for aarch32 edge kind Keep-Alive")));
- std::string ReadAddendError = "can not read implicit addend for aarch32 edge kind <Unrecognized edge kind>";
+ std::string ReadAddendError = "can not read implicit addend for aarch32 edge "
+ "kind <Unrecognized edge kind>";
for (Edge::Kind K = FirstDataRelocation; K < LastDataRelocation; K += 1) {
Edge E(K, 0, TargetSymbol, 0);
EXPECT_THAT_EXPECTED(readAddendData(*G, B, E), Succeeded());
- EXPECT_THAT_EXPECTED(readAddendArm(*G, B, E),
- FailedWithMessage(testing::HasSubstr(ReadAddendError)));
- EXPECT_THAT_EXPECTED(readAddendThumb(*G, B, E, ArmCfg),
- FailedWithMessage(testing::HasSubstr(ReadAddendError)));
+ EXPECT_THAT_EXPECTED(
+ readAddendArm(*G, B, E),
+ FailedWithMessage(testing::HasSubstr(ReadAddendError)));
+ EXPECT_THAT_EXPECTED(
+ readAddendThumb(*G, B, E, ArmCfg),
+ FailedWithMessage(testing::HasSubstr(ReadAddendError)));
}
for (Edge::Kind K = FirstArmRelocation; K < LastArmRelocation; K += 1) {
Edge E(K, 0, TargetSymbol, 0);
- EXPECT_THAT_EXPECTED(readAddendData(*G, B, E),
- FailedWithMessage(testing::HasSubstr(ReadAddendError)));
+ EXPECT_THAT_EXPECTED(
+ readAddendData(*G, B, E),
+ FailedWithMessage(testing::HasSubstr(ReadAddendError)));
EXPECT_THAT_EXPECTED(
readAddendArm(*G, B, E),
FailedWithMessage(testing::StartsWith("Invalid opcode")));
- EXPECT_THAT_EXPECTED(readAddendThumb(*G, B, E, ArmCfg),
- FailedWithMessage(testing::HasSubstr(ReadAddendError)));
+ EXPECT_THAT_EXPECTED(
+ readAddendThumb(*G, B, E, ArmCfg),
+ FailedWithMessage(testing::HasSubstr(ReadAddendError)));
}
for (Edge::Kind K = FirstThumbRelocation; K < LastThumbRelocation; K += 1) {
Edge E(K, 0, TargetSymbol, 0);
- EXPECT_THAT_EXPECTED(readAddendData(*G, B, E),
- FailedWithMessage(testing::HasSubstr(ReadAddendError)));
- EXPECT_THAT_EXPECTED(readAddendArm(*G, B, E),
- FailedWithMessage(testing::HasSubstr(ReadAddendError)));
+ EXPECT_THAT_EXPECTED(
+ readAddendData(*G, B, E),
+ FailedWithMessage(testing::HasSubstr(ReadAddendError)));
+ EXPECT_THAT_EXPECTED(
+ readAddendArm(*G, B, E),
+ FailedWithMessage(testing::HasSubstr(ReadAddendError)));
EXPECT_THAT_EXPECTED(
readAddendThumb(*G, B, E, ArmCfg),
FailedWithMessage(testing::StartsWith("Invalid opcode")));
>From c2d539cf071549d1b120945d592421308e0ff2fe Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Eymen=20=C3=9Cnay?= <eymenunay at outlook.com>
Date: Tue, 7 Nov 2023 09:41:29 +0300
Subject: [PATCH 7/8] Removed redundant checking and replaced magic numbers
with readable names
---
.../JITLink/AArch32ErrorTests.cpp | 131 ++++++++----------
1 file changed, 58 insertions(+), 73 deletions(-)
diff --git a/llvm/unittests/ExecutionEngine/JITLink/AArch32ErrorTests.cpp b/llvm/unittests/ExecutionEngine/JITLink/AArch32ErrorTests.cpp
index e06c223c37398d8..de5e0a3f2947e14 100644
--- a/llvm/unittests/ExecutionEngine/JITLink/AArch32ErrorTests.cpp
+++ b/llvm/unittests/ExecutionEngine/JITLink/AArch32ErrorTests.cpp
@@ -17,61 +17,55 @@ using namespace llvm::jitlink::aarch32;
using namespace llvm::support;
using namespace llvm::support::endian;
-auto G = std::make_unique<LinkGraph>("foo", Triple("armv7-linux-gnueabi"), 4,
- llvm::endianness::little,
+constexpr unsigned PointerSize = 4;
+auto G = std::make_unique<LinkGraph>("foo", Triple("armv7-linux-gnueabi"),
+ PointerSize, llvm::endianness::little,
getGenericEdgeKindName);
auto &Sec =
G->createSection("__data", orc::MemProt::Read | orc::MemProt::Write);
-orc::ExecutorAddr B1Addr(0x1000);
+orc::ExecutorAddr B1DummyAddr(0x1000);
auto ArmCfg = getArmConfigForCPUArch(ARMBuildAttrs::v7);
TEST(AArch32_ELF, readAddendErrors) {
+ // Permanently undefined instruction
+ // 11110:op:imm4:1:op1:imm12
+ // op = 1111111 Permanent undefined
+ // op1 = 010
+ ArrayRef<char> Content = "0xf7f0a000";
+ constexpr uint64_t Alignment = 4;
+ constexpr uint64_t AlignmentOffset = 0;
+ auto &B = G->createContentBlock(Sec, Content, B1DummyAddr, Alignment,
+ AlignmentOffset);
+ constexpr orc::ExecutorAddrDiff Offset = 0;
+ constexpr orc::ExecutorAddrDiff Size = 4;
+ Symbol &TargetSymbol = G->addAnonymousSymbol(B, Offset, Size, false, false);
+ Edge InvalidEdge(Edge::GenericEdgeKind::Invalid, 0 /*Offset*/, TargetSymbol,
+ 0 /*Addend*/);
+
+ EXPECT_THAT_EXPECTED(readAddendData(*G, B, InvalidEdge),
+ FailedWithMessage(testing::HasSubstr(
+ "can not read implicit addend for aarch32 edge kind "
+ "INVALID RELOCATION")));
+
+ EXPECT_THAT_EXPECTED(readAddendArm(*G, B, InvalidEdge),
+ FailedWithMessage(testing::HasSubstr(
+ "can not read implicit addend for aarch32 edge kind "
+ "INVALID RELOCATION")));
+
+ EXPECT_THAT_EXPECTED(readAddendThumb(*G, B, InvalidEdge, ArmCfg),
+ FailedWithMessage(testing::HasSubstr(
+ "can not read implicit addend for aarch32 edge kind "
+ "INVALID RELOCATION")));
- ArrayRef<char> Content = "hello, world!";
- auto &B = G->createContentBlock(Sec, Content, B1Addr, 4, 0);
-
- Symbol &TargetSymbol = G->addAnonymousSymbol(B, 0, 4, false, false);
- Edge InvalidEdge(FirstDataRelocation - 1, 0, TargetSymbol, 0);
-
- EXPECT_THAT_EXPECTED(
- readAddend(*G, B, InvalidEdge, ArmCfg),
- FailedWithMessage(testing::HasSubstr(
- "can not read implicit addend for aarch32 edge kind Keep-Alive")));
-
- std::string ReadAddendError = "can not read implicit addend for aarch32 edge "
- "kind <Unrecognized edge kind>";
-
- for (Edge::Kind K = FirstDataRelocation; K < LastDataRelocation; K += 1) {
- Edge E(K, 0, TargetSymbol, 0);
- EXPECT_THAT_EXPECTED(readAddendData(*G, B, E), Succeeded());
- EXPECT_THAT_EXPECTED(
- readAddendArm(*G, B, E),
- FailedWithMessage(testing::HasSubstr(ReadAddendError)));
- EXPECT_THAT_EXPECTED(
- readAddendThumb(*G, B, E, ArmCfg),
- FailedWithMessage(testing::HasSubstr(ReadAddendError)));
- }
for (Edge::Kind K = FirstArmRelocation; K < LastArmRelocation; K += 1) {
Edge E(K, 0, TargetSymbol, 0);
- EXPECT_THAT_EXPECTED(
- readAddendData(*G, B, E),
- FailedWithMessage(testing::HasSubstr(ReadAddendError)));
EXPECT_THAT_EXPECTED(
readAddendArm(*G, B, E),
FailedWithMessage(testing::StartsWith("Invalid opcode")));
- EXPECT_THAT_EXPECTED(
- readAddendThumb(*G, B, E, ArmCfg),
- FailedWithMessage(testing::HasSubstr(ReadAddendError)));
}
for (Edge::Kind K = FirstThumbRelocation; K < LastThumbRelocation; K += 1) {
Edge E(K, 0, TargetSymbol, 0);
- EXPECT_THAT_EXPECTED(
- readAddendData(*G, B, E),
- FailedWithMessage(testing::HasSubstr(ReadAddendError)));
- EXPECT_THAT_EXPECTED(
- readAddendArm(*G, B, E),
- FailedWithMessage(testing::HasSubstr(ReadAddendError)));
EXPECT_THAT_EXPECTED(
readAddendThumb(*G, B, E, ArmCfg),
FailedWithMessage(testing::StartsWith("Invalid opcode")));
@@ -79,49 +73,40 @@ TEST(AArch32_ELF, readAddendErrors) {
}
TEST(AArch32_ELF, applyFixupErrors) {
- char ContentArray[] = "hello, world!";
+ // Permanently undefined instruction
+ char ContentArray[] = "0xf7f0a000";
MutableArrayRef<char> MutableContent(ContentArray);
- auto &B = G->createMutableContentBlock(Sec, MutableContent, B1Addr, 4, 0);
-
- Symbol &TargetSymbol = G->addAnonymousSymbol(B, 0, 4, false, false);
- Edge InvalidEdge(FirstDataRelocation - 1, 0, TargetSymbol, 0);
-
- EXPECT_THAT_ERROR(applyFixup(*G, B, InvalidEdge, ArmCfg),
- FailedWithMessage(testing::HasSubstr(
- "encountered unfixable aarch32 edge kind Keep-Alive")));
-
- std::string UnfixableEdgeError =
- "encountered unfixable aarch32 edge kind <Unrecognized edge kind>";
+ constexpr uint64_t Alignment = 4;
+ constexpr uint64_t AlignmentOffset = 0;
+ auto &B = G->createMutableContentBlock(Sec, MutableContent, B1DummyAddr,
+ Alignment, AlignmentOffset);
+
+ constexpr orc::ExecutorAddrDiff Offset = 0;
+ constexpr orc::ExecutorAddrDiff Size = 4;
+ Symbol &TargetSymbol = G->addAnonymousSymbol(B, Offset, Size, false, false);
+ Edge InvalidEdge(Edge::GenericEdgeKind::Invalid, 0 /*Offset*/, TargetSymbol,
+ 0 /*Addend*/);
+
+ EXPECT_THAT_ERROR(
+ applyFixupData(*G, B, InvalidEdge),
+ FailedWithMessage(testing::HasSubstr(
+ "encountered unfixable aarch32 edge kind INVALID RELOCATION")));
+ EXPECT_THAT_ERROR(
+ applyFixupArm(*G, B, InvalidEdge),
+ FailedWithMessage(testing::HasSubstr(
+ "encountered unfixable aarch32 edge kind INVALID RELOCATION")));
+ EXPECT_THAT_ERROR(
+ applyFixupThumb(*G, B, InvalidEdge, ArmCfg),
+ FailedWithMessage(testing::HasSubstr(
+ "encountered unfixable aarch32 edge kind INVALID RELOCATION")));
- for (Edge::Kind K = FirstDataRelocation; K < LastDataRelocation; K += 1) {
- Edge E(K, 0, TargetSymbol, 0);
- EXPECT_THAT_ERROR(applyFixupData(*G, B, E), Succeeded());
- EXPECT_THAT_ERROR(
- applyFixupArm(*G, B, E),
- FailedWithMessage(testing::HasSubstr(UnfixableEdgeError)));
- EXPECT_THAT_ERROR(
- applyFixupThumb(*G, B, E, ArmCfg),
- FailedWithMessage(testing::HasSubstr(UnfixableEdgeError)));
- }
for (Edge::Kind K = FirstArmRelocation; K < LastArmRelocation; K += 1) {
Edge E(K, 0, TargetSymbol, 0);
- EXPECT_THAT_ERROR(
- applyFixupData(*G, B, E),
- FailedWithMessage(testing::HasSubstr(UnfixableEdgeError)));
EXPECT_THAT_ERROR(applyFixupArm(*G, B, E),
FailedWithMessage(testing::StartsWith("Invalid opcode")));
- EXPECT_THAT_ERROR(
- applyFixupThumb(*G, B, E, ArmCfg),
- FailedWithMessage(testing::HasSubstr(UnfixableEdgeError)));
}
for (Edge::Kind K = FirstThumbRelocation; K < LastThumbRelocation; K += 1) {
Edge E(K, 0, TargetSymbol, 0);
- EXPECT_THAT_ERROR(
- applyFixupData(*G, B, E),
- FailedWithMessage(testing::HasSubstr(UnfixableEdgeError)));
- EXPECT_THAT_ERROR(
- applyFixupArm(*G, B, E),
- FailedWithMessage(testing::HasSubstr(UnfixableEdgeError)));
EXPECT_THAT_ERROR(applyFixupThumb(*G, B, E, ArmCfg),
FailedWithMessage(testing::StartsWith("Invalid opcode")));
}
>From c9eb0ce453b35477e8392646239cfbdb195acd14 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Eymen=20=C3=9Cnay?= <eymenunay at outlook.com>
Date: Tue, 7 Nov 2023 21:09:35 +0300
Subject: [PATCH 8/8] Add udf instruction to both Arm and Thumb
---
.../llvm/ExecutionEngine/JITLink/aarch32.h | 8 +-
.../JITLink/AArch32ErrorTests.cpp | 105 +++++++++++++-----
2 files changed, 84 insertions(+), 29 deletions(-)
diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/aarch32.h b/llvm/include/llvm/ExecutionEngine/JITLink/aarch32.h
index 3f36b53d6684a79..0f766ee63eeeaea 100644
--- a/llvm/include/llvm/ExecutionEngine/JITLink/aarch32.h
+++ b/llvm/include/llvm/ExecutionEngine/JITLink/aarch32.h
@@ -192,14 +192,14 @@ template <> struct FixupInfo<Arm_MovwAbsNC> : public FixupInfo<Arm_MovtAbs> {
};
template <> struct FixupInfo<Thumb_Jump24> {
- static constexpr HalfWords Opcode{0xf000, 0x8000};
- static constexpr HalfWords OpcodeMask{0xf800, 0x8000};
+ static constexpr HalfWords Opcode{0xf000, 0x9000};
+ static constexpr HalfWords OpcodeMask{0xf800, 0xd000};
static constexpr HalfWords ImmMask{0x07ff, 0x2fff};
};
template <> struct FixupInfo<Thumb_Call> {
- static constexpr HalfWords Opcode{0xf000, 0xc000};
- static constexpr HalfWords OpcodeMask{0xf800, 0xc000};
+ static constexpr HalfWords Opcode{0xf000, 0xd000};
+ static constexpr HalfWords OpcodeMask{0xf800, 0xd000};
static constexpr HalfWords ImmMask{0x07ff, 0x2fff};
static constexpr uint16_t LoBitH = 0x0001;
static constexpr uint16_t LoBitNoBlx = 0x1000;
diff --git a/llvm/unittests/ExecutionEngine/JITLink/AArch32ErrorTests.cpp b/llvm/unittests/ExecutionEngine/JITLink/AArch32ErrorTests.cpp
index de5e0a3f2947e14..d155a3799036aeb 100644
--- a/llvm/unittests/ExecutionEngine/JITLink/AArch32ErrorTests.cpp
+++ b/llvm/unittests/ExecutionEngine/JITLink/AArch32ErrorTests.cpp
@@ -23,37 +23,57 @@ auto G = std::make_unique<LinkGraph>("foo", Triple("armv7-linux-gnueabi"),
getGenericEdgeKindName);
auto &Sec =
G->createSection("__data", orc::MemProt::Read | orc::MemProt::Write);
-orc::ExecutorAddr B1DummyAddr(0x1000);
auto ArmCfg = getArmConfigForCPUArch(ARMBuildAttrs::v7);
TEST(AArch32_ELF, readAddendErrors) {
+
+ constexpr orc::ExecutorAddr B1DummyAddr(0x1000);
+ constexpr orc::ExecutorAddr B2DummyAddr(0x2000);
+
// Permanently undefined instruction
// 11110:op:imm4:1:op1:imm12
// op = 1111111 Permanent undefined
// op1 = 010
- ArrayRef<char> Content = "0xf7f0a000";
- constexpr uint64_t Alignment = 4;
+ uint8_t ArmWord[] = {0xf0, 0x00, 0xf0, 0xe7};
+ ArrayRef<char> ArmContent(reinterpret_cast<const char *>(&ArmWord),
+ sizeof(ArmWord));
+ // Permanently undefined instruction in Thumb
+ // udf #0
+ //
+ // 11110:op:imm4:1:op1:imm12
+ // op = 1111111 Permanent undefined
+ // op1 = 010
+ //
+ constexpr HalfWords ThumbHalfWords{0xf7f0, 0xa000};
+ ArrayRef<char> ThumbContent(reinterpret_cast<const char *>(&ThumbHalfWords),
+ sizeof(ThumbHalfWords));
+ constexpr uint64_t ArmAlignment = 4;
+ constexpr uint64_t ThumbAlignment = 2;
constexpr uint64_t AlignmentOffset = 0;
- auto &B = G->createContentBlock(Sec, Content, B1DummyAddr, Alignment,
- AlignmentOffset);
+ auto &BArm = G->createContentBlock(Sec, ArmContent, B1DummyAddr, ArmAlignment,
+ AlignmentOffset);
+ auto &BThumb = G->createContentBlock(Sec, ThumbContent, B2DummyAddr,
+ ThumbAlignment, AlignmentOffset);
constexpr orc::ExecutorAddrDiff Offset = 0;
constexpr orc::ExecutorAddrDiff Size = 4;
- Symbol &TargetSymbol = G->addAnonymousSymbol(B, Offset, Size, false, false);
+ Symbol &TargetSymbol =
+ G->addAnonymousSymbol(BArm, Offset, Size, false, false);
Edge InvalidEdge(Edge::GenericEdgeKind::Invalid, 0 /*Offset*/, TargetSymbol,
0 /*Addend*/);
- EXPECT_THAT_EXPECTED(readAddendData(*G, B, InvalidEdge),
+ // Since invalid edge kind case is tested content of block is not significant
+ EXPECT_THAT_EXPECTED(readAddendData(*G, BArm, InvalidEdge),
FailedWithMessage(testing::HasSubstr(
"can not read implicit addend for aarch32 edge kind "
"INVALID RELOCATION")));
- EXPECT_THAT_EXPECTED(readAddendArm(*G, B, InvalidEdge),
+ EXPECT_THAT_EXPECTED(readAddendArm(*G, BArm, InvalidEdge),
FailedWithMessage(testing::HasSubstr(
"can not read implicit addend for aarch32 edge kind "
"INVALID RELOCATION")));
- EXPECT_THAT_EXPECTED(readAddendThumb(*G, B, InvalidEdge, ArmCfg),
+ EXPECT_THAT_EXPECTED(readAddendThumb(*G, BArm, InvalidEdge, ArmCfg),
FailedWithMessage(testing::HasSubstr(
"can not read implicit addend for aarch32 edge kind "
"INVALID RELOCATION")));
@@ -61,53 +81,88 @@ TEST(AArch32_ELF, readAddendErrors) {
for (Edge::Kind K = FirstArmRelocation; K < LastArmRelocation; K += 1) {
Edge E(K, 0, TargetSymbol, 0);
EXPECT_THAT_EXPECTED(
- readAddendArm(*G, B, E),
+ readAddendArm(*G, BArm, E),
FailedWithMessage(testing::StartsWith("Invalid opcode")));
}
for (Edge::Kind K = FirstThumbRelocation; K < LastThumbRelocation; K += 1) {
Edge E(K, 0, TargetSymbol, 0);
EXPECT_THAT_EXPECTED(
- readAddendThumb(*G, B, E, ArmCfg),
+ readAddendThumb(*G, BThumb, E, ArmCfg),
FailedWithMessage(testing::StartsWith("Invalid opcode")));
}
}
TEST(AArch32_ELF, applyFixupErrors) {
- // Permanently undefined instruction
- char ContentArray[] = "0xf7f0a000";
- MutableArrayRef<char> MutableContent(ContentArray);
- constexpr uint64_t Alignment = 4;
+
+ struct MutableHalfWords {
+ constexpr MutableHalfWords(HalfWords Preset)
+ : Hi(Preset.Hi), Lo(Preset.Lo) {}
+
+ uint16_t Hi; // First halfword
+ uint16_t Lo; // Second halfword
+ };
+
+ constexpr orc::ExecutorAddr B3DummyAddr(0x5000);
+ constexpr orc::ExecutorAddr B4DummyAddr(0x6000);
+
+ // Permanently undefined instruction in ARM
+ // udf #0
+ uint8_t ArmWord[] = {0xf0, 0x00, 0xf0, 0xe7};
+ MutableArrayRef<char> MutableArmContent(reinterpret_cast<char *>(ArmWord),
+ sizeof(ArmWord));
+ // Permanently undefined instruction in Thumb
+ // udf #0
+ //
+ // 11110:op:imm4:1:op1:imm12
+ // op = 1111111 Permanent undefined
+ // op1 = 010
+ //
+ constexpr HalfWords ThumbHalfWords{0xf7f0, 0xa000};
+ MutableHalfWords MutableThumbHalfWords{ThumbHalfWords};
+ MutableArrayRef<char> MutableThumbContent(
+ reinterpret_cast<char *>(&MutableThumbHalfWords),
+ sizeof(MutableThumbHalfWords));
+ constexpr uint64_t ArmAlignment = 4;
+ constexpr uint64_t ThumbAlignment = 2;
constexpr uint64_t AlignmentOffset = 0;
- auto &B = G->createMutableContentBlock(Sec, MutableContent, B1DummyAddr,
- Alignment, AlignmentOffset);
+ auto &BArm = G->createMutableContentBlock(Sec, MutableArmContent, B3DummyAddr,
+ ArmAlignment, AlignmentOffset);
+ auto &BThumb = G->createMutableContentBlock(
+ Sec, MutableThumbContent, B4DummyAddr, ThumbAlignment, AlignmentOffset);
constexpr orc::ExecutorAddrDiff Offset = 0;
constexpr orc::ExecutorAddrDiff Size = 4;
- Symbol &TargetSymbol = G->addAnonymousSymbol(B, Offset, Size, false, false);
+ Symbol &TargetSymbol =
+ G->addAnonymousSymbol(BArm, Offset, Size, false, false);
Edge InvalidEdge(Edge::GenericEdgeKind::Invalid, 0 /*Offset*/, TargetSymbol,
0 /*Addend*/);
+ // Since invalid edge kind case is tested content of block is not significant
EXPECT_THAT_ERROR(
- applyFixupData(*G, B, InvalidEdge),
+ applyFixupData(*G, BArm, InvalidEdge),
FailedWithMessage(testing::HasSubstr(
"encountered unfixable aarch32 edge kind INVALID RELOCATION")));
EXPECT_THAT_ERROR(
- applyFixupArm(*G, B, InvalidEdge),
+ applyFixupArm(*G, BArm, InvalidEdge),
FailedWithMessage(testing::HasSubstr(
"encountered unfixable aarch32 edge kind INVALID RELOCATION")));
EXPECT_THAT_ERROR(
- applyFixupThumb(*G, B, InvalidEdge, ArmCfg),
+ applyFixupThumb(*G, BArm, InvalidEdge, ArmCfg),
FailedWithMessage(testing::HasSubstr(
"encountered unfixable aarch32 edge kind INVALID RELOCATION")));
for (Edge::Kind K = FirstArmRelocation; K < LastArmRelocation; K += 1) {
Edge E(K, 0, TargetSymbol, 0);
- EXPECT_THAT_ERROR(applyFixupArm(*G, B, E),
- FailedWithMessage(testing::StartsWith("Invalid opcode")));
+ EXPECT_THAT_ERROR(applyFixupArm(*G, BArm, E),
+ FailedWithMessage(testing::AllOf(
+ testing::StartsWith("Invalid opcode"),
+ testing::EndsWith(G->getEdgeKindName(K)))));
}
for (Edge::Kind K = FirstThumbRelocation; K < LastThumbRelocation; K += 1) {
Edge E(K, 0, TargetSymbol, 0);
- EXPECT_THAT_ERROR(applyFixupThumb(*G, B, E, ArmCfg),
- FailedWithMessage(testing::StartsWith("Invalid opcode")));
+ EXPECT_THAT_ERROR(applyFixupThumb(*G, BThumb, E, ArmCfg),
+ FailedWithMessage(testing::AllOf(
+ testing::StartsWith("Invalid opcode"),
+ testing::EndsWith(G->getEdgeKindName(K)))));
}
}
More information about the llvm-commits
mailing list