[llvm] [JITLink][AArch32] Unittest for error paths of readAddend and applyFixup functionality (PR #69636)
Stefan Gränitz via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 8 10:29:35 PST 2023
================
@@ -0,0 +1,210 @@
+//===------- 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.
+// 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;
+
+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);
+
+auto ArmCfg = getArmConfigForCPUArch(ARMBuildAttrs::v7);
+
+constexpr uint64_t ArmAlignment = 4;
+constexpr uint64_t ThumbAlignment = 2;
+constexpr uint64_t AlignmentOffset = 0;
+
+constexpr orc::ExecutorAddrDiff SymbolOffset = 0;
+constexpr orc::ExecutorAddrDiff SymbolSize = 4;
+
+TEST(AArch32_ELF, readAddendArmErrors) {
+
+ constexpr orc::ExecutorAddr B1DummyAddr(0x1000);
+
+ // Permanently undefined instruction in ARM
+ // udf #0
+ uint8_t ArmWord[] = {0xf0, 0x00, 0xf0, 0xe7};
+ ArrayRef<char> ArmContent(reinterpret_cast<const char *>(&ArmWord),
+ sizeof(ArmWord));
+ auto &BArm = G->createContentBlock(Sec, ArmContent, B1DummyAddr, ArmAlignment,
+ AlignmentOffset);
+ Symbol &TargetSymbol =
+ G->addAnonymousSymbol(BArm, SymbolOffset, SymbolSize, false, false);
+ Edge InvalidEdge(Edge::GenericEdgeKind::Invalid, 0 /*Offset*/, TargetSymbol,
+ 0 /*Addend*/);
+
+ 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, BArm, InvalidEdge),
+ FailedWithMessage(testing::HasSubstr(
+ "can not read implicit addend for aarch32 edge kind "
+ "INVALID RELOCATION")));
+
+ EXPECT_THAT_EXPECTED(readAddendThumb(*G, BArm, InvalidEdge, ArmCfg),
+ FailedWithMessage(testing::HasSubstr(
+ "can not read implicit addend for aarch32 edge kind "
+ "INVALID RELOCATION")));
----------------
weliveindetail wrote:
Can we deduplicate these across all test cases please?
https://github.com/llvm/llvm-project/pull/69636
More information about the llvm-commits
mailing list