[llvm] 57bee1e - [JITLink] Add support for R_X86_64_PC16 relocation type. (#109630)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 24 06:21:45 PDT 2024
Author: Xing Guo
Date: 2024-09-24T21:21:42+08:00
New Revision: 57bee1e4322d34f9760563081f9c10b6850bc2bf
URL: https://github.com/llvm/llvm-project/commit/57bee1e4322d34f9760563081f9c10b6850bc2bf
DIFF: https://github.com/llvm/llvm-project/commit/57bee1e4322d34f9760563081f9c10b6850bc2bf.diff
LOG: [JITLink] Add support for R_X86_64_PC16 relocation type. (#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.
Added:
llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_PC.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:
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 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