[llvm] ae6f730 - [JITLink] Add x86_64::Delta8 edge kind, ELF::R_X86_64_PC8 support (#95869)

via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 18 09:31:57 PDT 2024


Author: Maksim Panchenko
Date: 2024-06-18T09:31:52-07:00
New Revision: ae6f730b2f6f2055b3a658235ddef91624d532f2

URL: https://github.com/llvm/llvm-project/commit/ae6f730b2f6f2055b3a658235ddef91624d532f2
DIFF: https://github.com/llvm/llvm-project/commit/ae6f730b2f6f2055b3a658235ddef91624d532f2.diff

LOG: [JITLink] Add x86_64::Delta8 edge kind, ELF::R_X86_64_PC8 support (#95869)

Add support for ELF::R_X86_64_PC8 relocation via new x86_64::Delta8 edge
kind.

Added: 
    llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_PC8.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 e072ee1575de8..2f475ed884a7e 100644
--- a/llvm/include/llvm/ExecutionEngine/JITLink/x86_64.h
+++ b/llvm/include/llvm/ExecutionEngine/JITLink/x86_64.h
@@ -87,7 +87,7 @@ enum EdgeKind_x86_64 : Edge::Kind {
   /// Delta from the fixup to the target.
   ///
   /// Fixup expression:
-  ///   Fixup <- Target - Fixup + Addend : int64
+  ///   Fixup <- Target - Fixup + Addend : int32
   ///
   /// Errors:
   ///   - The result of the fixup expression must fit into an int32, otherwise
@@ -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 : int8
+  ///
+  /// 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)))
+      *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