Skip to content

Commit cb4e2fa

Browse files
maksfbAlexisPerry
authored andcommitted
[JITLink] Add x86_64::Delta8 edge kind, ELF::R_X86_64_PC8 support (llvm#95869)
Add support for ELF::R_X86_64_PC8 relocation via new x86_64::Delta8 edge kind.
1 parent eb580db commit cb4e2fa

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

llvm/include/llvm/ExecutionEngine/JITLink/x86_64.h

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,27 @@ enum EdgeKind_x86_64 : Edge::Kind {
8787
/// Delta from the fixup to the target.
8888
///
8989
/// Fixup expression:
90-
/// Fixup <- Target - Fixup + Addend : int64
90+
/// Fixup <- Target - Fixup + Addend : int32
9191
///
9292
/// Errors:
9393
/// - The result of the fixup expression must fit into an int32, otherwise
9494
/// an out-of-range error will be returned.
9595
///
9696
Delta32,
9797

98+
/// An 8-bit delta.
99+
///
100+
/// Delta from the fixup to the target.
101+
///
102+
/// Fixup expression:
103+
/// Fixup <- Target - Fixup + Addend : int8
104+
///
105+
/// Errors:
106+
/// - The result of the fixup expression must fit into an int8, otherwise
107+
/// an out-of-range error will be returned.
108+
///
109+
Delta8,
110+
98111
/// A 64-bit negative delta.
99112
///
100113
/// Delta from target back to the fixup.
@@ -473,6 +486,15 @@ inline Error applyFixup(LinkGraph &G, Block &B, const Edge &E,
473486
break;
474487
}
475488

489+
case Delta8: {
490+
int64_t Value = E.getTarget().getAddress() - FixupAddress + E.getAddend();
491+
if (LLVM_LIKELY(isInt<8>(Value)))
492+
*FixupPtr = Value;
493+
else
494+
return makeTargetOutOfRangeError(G, B, E);
495+
break;
496+
}
497+
476498
case NegDelta64: {
477499
int64_t Value = FixupAddress - E.getTarget().getAddress() + E.getAddend();
478500
*(little64_t *)FixupPtr = Value;

llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ class ELFLinkGraphBuilder_x86_64 : public ELFLinkGraphBuilder<object::ELF64LE> {
153153
Edge::Kind Kind = Edge::Invalid;
154154

155155
switch (ELFReloc) {
156+
case ELF::R_X86_64_PC8:
157+
Kind = x86_64::Delta8;
158+
break;
156159
case ELF::R_X86_64_PC32:
157160
case ELF::R_X86_64_GOTPC32:
158161
Kind = x86_64::Delta32;

llvm/lib/ExecutionEngine/JITLink/x86_64.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ const char *getEdgeKindName(Edge::Kind K) {
3434
return "Delta64";
3535
case Delta32:
3636
return "Delta32";
37+
case Delta8:
38+
return "Delta8";
3739
case NegDelta64:
3840
return "NegDelta64";
3941
case NegDelta32:
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# RUN: llvm-mc -triple=x86_64-unknown-linux -position-independent \
2+
# RUN: -filetype=obj -o %t.o %s
3+
# RUN: llvm-jitlink -noexec %t.o
4+
#
5+
# Check R_X86_64_PC8 handling.
6+
7+
.text
8+
.globl main
9+
.type main,@function
10+
main:
11+
xorl %eax, %eax
12+
retq
13+
.size main, .-main
14+
15+
.type P,@object
16+
.globl P
17+
P:
18+
.byte main-. # Generate R_X86_64_PC8 relocation.
19+
.size P, .-P

0 commit comments

Comments
 (0)