Skip to content

Commit 57bee1e

Browse files
authored
[JITLink] Add support for R_X86_64_PC16 relocation type. (#109630)
This patch adds support for R_X86_64_PC16 relocation type and x86_64::Delta16 edge kind. This patch also adds missing test cases for R_X86_64_PC32, R_X86_64_PC64 relocation types.
1 parent ebbf664 commit 57bee1e

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,19 @@ enum EdgeKind_x86_64 : Edge::Kind {
9595
///
9696
Delta32,
9797

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

502+
case Delta16: {
503+
int64_t Value = E.getTarget().getAddress() - FixupAddress + E.getAddend();
504+
if (LLVM_LIKELY(isInt<16>(Value)))
505+
*(little16_t *)FixupPtr = Value;
506+
else
507+
return makeTargetOutOfRangeError(G, B, E);
508+
break;
509+
}
510+
489511
case Delta8: {
490512
int64_t Value = E.getTarget().getAddress() - FixupAddress + E.getAddend();
491513
if (LLVM_LIKELY(isInt<8>(Value)))

llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ class ELFLinkGraphBuilder_x86_64 : public ELFLinkGraphBuilder<object::ELF64LE> {
156156
case ELF::R_X86_64_PC8:
157157
Kind = x86_64::Delta8;
158158
break;
159+
case ELF::R_X86_64_PC16:
160+
Kind = x86_64::Delta16;
161+
break;
159162
case ELF::R_X86_64_PC32:
160163
case ELF::R_X86_64_GOTPC32:
161164
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 Delta16:
38+
return "Delta16";
3739
case Delta8:
3840
return "Delta8";
3941
case NegDelta64:

llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_PC8.s renamed to llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_PC.s

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# RUN: -filetype=obj -o %t.o %s
33
# RUN: llvm-jitlink -noexec %t.o
44
#
5-
# Check R_X86_64_PC8 handling.
5+
# Check R_X86_64_PC* handling.
66

77
.text
88
.globl main
@@ -14,3 +14,6 @@ main:
1414

1515
.rodata
1616
.byte main-. # Generate R_X86_64_PC8 relocation.
17+
.short main-. # Generate R_X86_64_PC16 relocation.
18+
.long main-. # Generate R_X86_64_PC32 relocation.
19+
.quad main-. # Generate R_X86_64_PC64 relocation.

0 commit comments

Comments
 (0)