Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion llvm/include/llvm/ExecutionEngine/JITLink/x86_64.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,27 @@ 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
/// an out-of-range error will be returned.
///
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.
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/ExecutionEngine/JITLink/x86_64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
19 changes: 19 additions & 0 deletions llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_PC8.s
Original file line number Diff line number Diff line change
@@ -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
Loading