Skip to content

[JITLink] Add support for R_X86_64_PC16 relocation type. #109630

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 1 commit into from
Sep 24, 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
22 changes: 22 additions & 0 deletions llvm/include/llvm/ExecutionEngine/JITLink/x86_64.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)))
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 @@ -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;
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 Delta16:
return "Delta16";
case Delta8:
return "Delta8";
case NegDelta64:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Loading