[llvm] [JITLink] Add x86_64::Delta8 edge kind, ELF::R_X86_64_PC8 support (PR #95869)
Maksim Panchenko via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 17 16:52:35 PDT 2024
https://github.com/maksfb created https://github.com/llvm/llvm-project/pull/95869
Add support for ELF::R_X86_64_PC8 relocation via new x86_64::Delta8 edge kind.
>From 2903899c2e6bd726b032d9e0d5b2a5ae744ba6aa Mon Sep 17 00:00:00 2001
From: Maksim Panchenko <maks at fb.com>
Date: Mon, 17 Jun 2024 14:24:29 -0700
Subject: [PATCH] [JITLink] Add x86_64::Delta8 edge kind, ELF::R_X86_64_PC8
support
Add support for ELF::R_X86_64_PC8 relocation via new x86_64::Delta8 edge
kind.
---
.../llvm/ExecutionEngine/JITLink/x86_64.h | 22 +++++++++++++++++++
.../ExecutionEngine/JITLink/ELF_x86_64.cpp | 3 +++
llvm/lib/ExecutionEngine/JITLink/x86_64.cpp | 2 ++
.../JITLink/x86-64/ELF_R_X86_64_PC8.s | 19 ++++++++++++++++
4 files changed, 46 insertions(+)
create mode 100644 llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_PC8.s
diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/x86_64.h b/llvm/include/llvm/ExecutionEngine/JITLink/x86_64.h
index e072ee1575de8..e6f72bcae91a6 100644
--- a/llvm/include/llvm/ExecutionEngine/JITLink/x86_64.h
+++ b/llvm/include/llvm/ExecutionEngine/JITLink/x86_64.h
@@ -95,6 +95,19 @@ enum EdgeKind_x86_64 : Edge::Kind {
///
Delta32,
+ /// An 8-bit delta.
+ ///
+ /// Delta from the fixup to the target.
+ ///
+ /// Fixup expression:
+ /// Fixup <- Target - Fixup + Addend : int64
+ ///
+ /// Errors:
+ /// - The result of the fixup expression must fit into an int8, otherwise
+ /// an out-of-range error will be returned.
+ ///
+ Delta8,
+
/// A 64-bit negative delta.
///
/// Delta from target back to the fixup.
@@ -473,6 +486,15 @@ inline Error applyFixup(LinkGraph &G, Block &B, const Edge &E,
break;
}
+ case Delta8: {
+ int64_t Value = E.getTarget().getAddress() - FixupAddress + E.getAddend();
+ if (LLVM_LIKELY(isInt<8>(Value)))
+ *(little32_t *)FixupPtr = Value;
+ else
+ return makeTargetOutOfRangeError(G, B, E);
+ break;
+ }
+
case NegDelta64: {
int64_t Value = FixupAddress - E.getTarget().getAddress() + E.getAddend();
*(little64_t *)FixupPtr = Value;
diff --git a/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp b/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp
index 52dd83d9040fe..b27a1a19acae0 100644
--- a/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp
@@ -153,6 +153,9 @@ class ELFLinkGraphBuilder_x86_64 : public ELFLinkGraphBuilder<object::ELF64LE> {
Edge::Kind Kind = Edge::Invalid;
switch (ELFReloc) {
+ case ELF::R_X86_64_PC8:
+ Kind = x86_64::Delta8;
+ break;
case ELF::R_X86_64_PC32:
case ELF::R_X86_64_GOTPC32:
Kind = x86_64::Delta32;
diff --git a/llvm/lib/ExecutionEngine/JITLink/x86_64.cpp b/llvm/lib/ExecutionEngine/JITLink/x86_64.cpp
index 273ac7b372a7f..9f7ece8ffbbb3 100644
--- a/llvm/lib/ExecutionEngine/JITLink/x86_64.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/x86_64.cpp
@@ -34,6 +34,8 @@ const char *getEdgeKindName(Edge::Kind K) {
return "Delta64";
case Delta32:
return "Delta32";
+ case Delta8:
+ return "Delta8";
case NegDelta64:
return "NegDelta64";
case NegDelta32:
diff --git a/llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_PC8.s b/llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_PC8.s
new file mode 100644
index 0000000000000..cac6dd9c612b6
--- /dev/null
+++ b/llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_PC8.s
@@ -0,0 +1,19 @@
+# RUN: llvm-mc -triple=x86_64-unknown-linux -position-independent \
+# RUN: -filetype=obj -o %t.o %s
+# RUN: llvm-jitlink -noexec %t.o
+#
+# Check R_X86_64_PC8 handling.
+
+ .text
+ .globl main
+ .type main, at function
+main:
+ xorl %eax, %eax
+ retq
+ .size main, .-main
+
+ .type P, at object
+ .globl P
+P:
+ .byte main-. # Generate R_X86_64_PC8 relocation.
+ .size P, .-P
More information about the llvm-commits
mailing list