[llvm] 9ee16eb - [JITLink][x86-64] Add x86_64::Pointer8 edge kind, ELF::R_X86_64_8 reloc support.
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Sat Apr 15 19:37:43 PDT 2023
Author: Lang Hames
Date: 2023-04-16T02:35:36Z
New Revision: 9ee16eb526f7ef2e407d8fd67fed46403350ec99
URL: https://github.com/llvm/llvm-project/commit/9ee16eb526f7ef2e407d8fd67fed46403350ec99
DIFF: https://github.com/llvm/llvm-project/commit/9ee16eb526f7ef2e407d8fd67fed46403350ec99.diff
LOG: [JITLink][x86-64] Add x86_64::Pointer8 edge kind, ELF::R_X86_64_8 reloc support.
This commit adds an x86-64 Pointer8 edge kind (8-bit pointer), and uses it to
implement support for the ELF::R_X86_64_8 relocation kind.
Added:
llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_8.s
Modified:
llvm/include/llvm/ExecutionEngine/JITLink/x86_64.h
llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp
llvm/lib/ExecutionEngine/JITLink/x86_64.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/x86_64.h b/llvm/include/llvm/ExecutionEngine/JITLink/x86_64.h
index d168ce9947ff8..519aa192c6417 100644
--- a/llvm/include/llvm/ExecutionEngine/JITLink/x86_64.h
+++ b/llvm/include/llvm/ExecutionEngine/JITLink/x86_64.h
@@ -64,6 +64,17 @@ enum EdgeKind_x86_64 : Edge::Kind {
///
Pointer16,
+ /// A plain 8-bit pointer value relocation.
+ ///
+ /// Fixup expression:
+ /// Fixup <- Target + Addend : uint8
+ ///
+ /// Errors:
+ /// - The target must reside in the low 8-bits of the address space,
+ /// otherwise an out-of-range error will be returned.
+ ///
+ Pointer8,
+
/// A 64-bit delta.
///
/// Delta from the fixup to the target.
@@ -435,6 +446,15 @@ inline Error applyFixup(LinkGraph &G, Block &B, const Edge &E,
break;
}
+ case Pointer8: {
+ uint64_t Value = E.getTarget().getAddress().getValue() + E.getAddend();
+ if (LLVM_LIKELY(isUInt<8>(Value)))
+ *(uint8_t *)FixupPtr = Value;
+ else
+ return makeTargetOutOfRangeError(G, B, E);
+ break;
+ }
+
case PCRel32:
case BranchPCRel32:
case BranchPCRel32ToPtrJumpStub:
diff --git a/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp b/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp
index 692b1619db002..7ac088f1a9422 100644
--- a/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp
@@ -162,6 +162,9 @@ class ELFLinkGraphBuilder_x86_64 : public ELFLinkGraphBuilder<object::ELF64LE> {
case ELF::R_X86_64_16:
Kind = x86_64::Pointer16;
break;
+ case ELF::R_X86_64_8:
+ Kind = x86_64::Pointer8;
+ break;
case ELF::R_X86_64_32S:
Kind = x86_64::Pointer32Signed;
break;
diff --git a/llvm/lib/ExecutionEngine/JITLink/x86_64.cpp b/llvm/lib/ExecutionEngine/JITLink/x86_64.cpp
index 097e19e02530e..9c7642da3bf09 100644
--- a/llvm/lib/ExecutionEngine/JITLink/x86_64.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/x86_64.cpp
@@ -28,6 +28,8 @@ const char *getEdgeKindName(Edge::Kind K) {
return "Pointer32Signed";
case Pointer16:
return "Pointer16";
+ case Pointer8:
+ return "Pointer8";
case Delta64:
return "Delta64";
case Delta32:
diff --git a/llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_8.s b/llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_8.s
new file mode 100644
index 0000000000000..d5337682f809b
--- /dev/null
+++ b/llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_8.s
@@ -0,0 +1,36 @@
+# RUN: llvm-mc -triple=x86_64-unknown-linux -position-independent \
+# RUN: -filetype=obj -o %t.o %s
+# RUN: llvm-jitlink -noexec -abs X=0x12 -check=%s %t.o
+# RUN: not llvm-jitlink -noexec -abs X=0x123 %t.o 2>&1 | \
+# RUN: FileCheck -check-prefix=CHECK-ERROR %s
+#
+# Check success and failure cases of R_X86_64_16 handling.
+
+# jitlink-check: *{8}P = X
+
+# CHECK-ERROR: relocation target "X" {{.*}} is out of range of Pointer8 fixup
+
+ .text
+ .section .text.main,"ax", at progbits
+ .globl main
+ .p2align 4, 0x90
+ .type main, at function
+main:
+ xorl %eax, %eax
+ retq
+.Lfunc_end0:
+ .size main, .Lfunc_end0-main
+
+ .type P, at object
+ .data
+ .globl P
+P:
+ .byte X # Using byte here generates R_X86_64_8.
+ .byte 0
+ .byte 0
+ .byte 0
+ .byte 0
+ .byte 0
+ .byte 0
+ .byte 0
+ .size P, 8
More information about the llvm-commits
mailing list