Skip to content

Commit 9ee16eb

Browse files
committed
[JITLink][x86-64] Add x86_64::Pointer8 edge kind, ELF::R_X86_64_8 reloc support.
This commit adds an x86-64 Pointer8 edge kind (8-bit pointer), and uses it to implement support for the ELF::R_X86_64_8 relocation kind.
1 parent 258e04f commit 9ee16eb

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-0
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,17 @@ enum EdgeKind_x86_64 : Edge::Kind {
6464
///
6565
Pointer16,
6666

67+
/// A plain 8-bit pointer value relocation.
68+
///
69+
/// Fixup expression:
70+
/// Fixup <- Target + Addend : uint8
71+
///
72+
/// Errors:
73+
/// - The target must reside in the low 8-bits of the address space,
74+
/// otherwise an out-of-range error will be returned.
75+
///
76+
Pointer8,
77+
6778
/// A 64-bit delta.
6879
///
6980
/// Delta from the fixup to the target.
@@ -435,6 +446,15 @@ inline Error applyFixup(LinkGraph &G, Block &B, const Edge &E,
435446
break;
436447
}
437448

449+
case Pointer8: {
450+
uint64_t Value = E.getTarget().getAddress().getValue() + E.getAddend();
451+
if (LLVM_LIKELY(isUInt<8>(Value)))
452+
*(uint8_t *)FixupPtr = Value;
453+
else
454+
return makeTargetOutOfRangeError(G, B, E);
455+
break;
456+
}
457+
438458
case PCRel32:
439459
case BranchPCRel32:
440460
case BranchPCRel32ToPtrJumpStub:

llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ class ELFLinkGraphBuilder_x86_64 : public ELFLinkGraphBuilder<object::ELF64LE> {
162162
case ELF::R_X86_64_16:
163163
Kind = x86_64::Pointer16;
164164
break;
165+
case ELF::R_X86_64_8:
166+
Kind = x86_64::Pointer8;
167+
break;
165168
case ELF::R_X86_64_32S:
166169
Kind = x86_64::Pointer32Signed;
167170
break;

llvm/lib/ExecutionEngine/JITLink/x86_64.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ const char *getEdgeKindName(Edge::Kind K) {
2828
return "Pointer32Signed";
2929
case Pointer16:
3030
return "Pointer16";
31+
case Pointer8:
32+
return "Pointer8";
3133
case Delta64:
3234
return "Delta64";
3335
case Delta32:
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# RUN: llvm-mc -triple=x86_64-unknown-linux -position-independent \
2+
# RUN: -filetype=obj -o %t.o %s
3+
# RUN: llvm-jitlink -noexec -abs X=0x12 -check=%s %t.o
4+
# RUN: not llvm-jitlink -noexec -abs X=0x123 %t.o 2>&1 | \
5+
# RUN: FileCheck -check-prefix=CHECK-ERROR %s
6+
#
7+
# Check success and failure cases of R_X86_64_16 handling.
8+
9+
# jitlink-check: *{8}P = X
10+
11+
# CHECK-ERROR: relocation target "X" {{.*}} is out of range of Pointer8 fixup
12+
13+
.text
14+
.section .text.main,"ax",@progbits
15+
.globl main
16+
.p2align 4, 0x90
17+
.type main,@function
18+
main:
19+
xorl %eax, %eax
20+
retq
21+
.Lfunc_end0:
22+
.size main, .Lfunc_end0-main
23+
24+
.type P,@object
25+
.data
26+
.globl P
27+
P:
28+
.byte X # Using byte here generates R_X86_64_8.
29+
.byte 0
30+
.byte 0
31+
.byte 0
32+
.byte 0
33+
.byte 0
34+
.byte 0
35+
.byte 0
36+
.size P, 8

0 commit comments

Comments
 (0)