[llvm] [JITLink] Add support for R_X86_64_PC16 relocation type. (PR #109630)
Xing Guo via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 23 01:08:51 PDT 2024
https://github.com/higuoxing created https://github.com/llvm/llvm-project/pull/109630
This patch adds support for R_X86_64_PC16 relocation type and x86_64::Delta16 edge kind. This patch also adds missing test cases for R_X86_64_PC32, R_X86_64_PC64 relocation types.
>From 9edc73061765a9a580204aae7e322beb804a058c Mon Sep 17 00:00:00 2001
From: Xing Guo <higuoxing at gmail.com>
Date: Mon, 23 Sep 2024 15:57:42 +0800
Subject: [PATCH] [JITLink] Add support for R_X86_64_PC16 relocation type.
This patch adds support for R_X86_64_PC16 relocation type and
x86_64::Delta16 edge kind. This patch also adds missing test cases for
R_X86_64_PC32, R_X86_64_PC64 relocation types.
---
.../llvm/ExecutionEngine/JITLink/x86_64.h | 22 +++++++++++++++++++
.../ExecutionEngine/JITLink/ELF_x86_64.cpp | 3 +++
llvm/lib/ExecutionEngine/JITLink/x86_64.cpp | 2 ++
.../{ELF_R_X86_64_PC8.s => ELF_R_X86_64_PC.s} | 5 ++++-
4 files changed, 31 insertions(+), 1 deletion(-)
rename llvm/test/ExecutionEngine/JITLink/x86-64/{ELF_R_X86_64_PC8.s => ELF_R_X86_64_PC.s} (61%)
diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/x86_64.h b/llvm/include/llvm/ExecutionEngine/JITLink/x86_64.h
index 2f475ed884a7e2..24cf982fc3ab0f 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,
+ /// A 16-bit delta.
+ ///
+ /// Delta from the fixup to the target.
+ ///
+ /// Fixup expression:
+ /// Fixup <- Target - Fixup + Addend : int16
+ ///
+ /// Errors:
+ /// - The result of the fixup expression must fit into an int16, otherwise
+ /// an out-of-range error will be returned.
+ ///
+ Delta16,
+
/// An 8-bit delta.
///
/// Delta from the fixup to the target.
@@ -486,6 +499,15 @@ inline Error applyFixup(LinkGraph &G, Block &B, const Edge &E,
break;
}
+ case Delta16: {
+ int64_t Value = E.getTarget().getAddress() - FixupAddress + E.getAddend();
+ if (LLVM_LIKELY(isInt<16>(Value)))
+ *(little16_t *)FixupPtr = Value;
+ else
+ return makeTargetOutOfRangeError(G, B, E);
+ break;
+ }
+
case Delta8: {
int64_t Value = E.getTarget().getAddress() - FixupAddress + E.getAddend();
if (LLVM_LIKELY(isInt<8>(Value)))
diff --git a/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp b/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp
index b27a1a19acae0a..6a32ccc3776510 100644
--- a/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp
@@ -156,6 +156,9 @@ class ELFLinkGraphBuilder_x86_64 : public ELFLinkGraphBuilder<object::ELF64LE> {
case ELF::R_X86_64_PC8:
Kind = x86_64::Delta8;
break;
+ case ELF::R_X86_64_PC16:
+ Kind = x86_64::Delta16;
+ 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 9f7ece8ffbbb3f..cca4358a377660 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 Delta16:
+ return "Delta16";
case Delta8:
return "Delta8";
case NegDelta64:
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_PC.s
similarity index 61%
rename from llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_PC8.s
rename to llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_PC.s
index 46b851a836abb8..d88875e3855114 100644
--- a/llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_PC8.s
+++ b/llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_PC.s
@@ -2,7 +2,7 @@
# RUN: -filetype=obj -o %t.o %s
# RUN: llvm-jitlink -noexec %t.o
#
-# Check R_X86_64_PC8 handling.
+# Check R_X86_64_PC* handling.
.text
.globl main
@@ -14,3 +14,6 @@ main:
.rodata
.byte main-. # Generate R_X86_64_PC8 relocation.
+ .short main-. # Generate R_X86_64_PC16 relocation.
+ .long main-. # Generate R_X86_64_PC32 relocation.
+ .quad main-. # Generate R_X86_64_PC64 relocation.
More information about the llvm-commits
mailing list