Skip to content

Commit 79685b5

Browse files
committed
[JITLink][aarch64] Fix dependence tracking for Pointer64Authenticated edges.
Transform Pointer64Authenticated edges into KeepAlive edges, rather than removing them, in order to preserve symbol dependence information. The lowerPointer64AuthEdgesToSigningFunction pass is responsible for transforming Pointer64Authenticated edges to a signing function that can be run in the executing process to initialize global PAC pointers. Removing the edges entirely in this pass results in loss of dependence tracking, which can in turn cause ORC to report PAC pointers as ready before the pointers targets have completed materialization (resulting in a use-before-finalize error, often manifesting as access to uninitialized / unprotected memory). This commit addresses the issue by leaving the edges in the graph and simply changing their kind to KeepAlive, a no-op for fixup purposes but followed for dependence tracking purposes.
1 parent 8b29c5c commit 79685b5

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

llvm/lib/ExecutionEngine/JITLink/aarch64.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,7 @@ Error lowerPointer64AuthEdgesToSigningFunction(LinkGraph &G) {
317317
};
318318

319319
for (auto *B : G.blocks()) {
320-
for (auto EI = B->edges().begin(); EI != B->edges().end();) {
321-
auto &E = *EI;
320+
for (auto &E : B->edges()) {
322321
if (E.getKind() == aarch64::Pointer64Authenticated) {
323322
uint64_t EncodedInfo = E.getAddend();
324323
int32_t RealAddend = (uint32_t)(EncodedInfo & 0xffffffff);
@@ -358,10 +357,9 @@ Error lowerPointer64AuthEdgesToSigningFunction(LinkGraph &G) {
358357
// Store signed pointer.
359358
cantFail(writeStoreRegSeq(AppendInstr, Reg2, Reg1));
360359

361-
// Remove this edge.
362-
EI = B->removeEdge(EI);
363-
} else
364-
++EI;
360+
// Replace edge with a keep-alive to preserve dependence info.
361+
E.setKind(Edge::KeepAlive);
362+
}
365363
}
366364
}
367365

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# RUN: llvm-mc -triple=arm64e-apple-macosx -filetype=obj -o %t.o %s
2+
# RUN: llvm-jitlink -num-threads=0 -debug-only=orc -noexec \
3+
# RUN: -abs _foo=0x1 %t.o 2>&1 \
4+
# RUN: | FileCheck %s
5+
#
6+
# Ensure that we don't lose dependence tracking information when ptrauth edges
7+
# are lowered: _main should still depend on _foo.
8+
9+
# CHECK: Symbols: { _main }, Dependencies: { (main, { _foo }) }
10+
11+
.section __TEXT,__text,regular,pure_instructions
12+
13+
.section __DATA,__data
14+
.globl _main
15+
.p2align 3, 0x0
16+
_main:
17+
.quad _foo@AUTH(ia,0)
18+
19+
.subsections_via_symbols

0 commit comments

Comments
 (0)