diff options
author | Maksim Panchenko <maks@fb.com> | 2024-06-18 09:31:52 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-18 09:31:52 -0700 |
commit | ae6f730b2f6f2055b3a658235ddef91624d532f2 (patch) | |
tree | 562d0df7a9ccaacaa8c71acfe985de9e47e328af | |
parent | b99d0b34400176cb9183113b96b245400caaf8d8 (diff) | |
download | llvm-ae6f730b2f6f2055b3a658235ddef91624d532f2.zip llvm-ae6f730b2f6f2055b3a658235ddef91624d532f2.tar.gz llvm-ae6f730b2f6f2055b3a658235ddef91624d532f2.tar.bz2 |
[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.
4 files changed, 47 insertions, 1 deletions
diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/x86_64.h b/llvm/include/llvm/ExecutionEngine/JITLink/x86_64.h index e072ee15..2f475ed 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 52dd83d..b27a1a1 100644 --- a/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp @@ -153,6 +153,9 @@ private: 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 273ac7b..9f7ece8 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 0000000..cac6dd9 --- /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,@function +main: + xorl %eax, %eax + retq + .size main, .-main + + .type P,@object + .globl P +P: + .byte main-. # Generate R_X86_64_PC8 relocation. + .size P, .-P |