Skip to content

Commit 9c52102

Browse files
committed
[ORC][AArch64] Guard against negative offsets in writeIndirectStubsBlock.
In OrcAArch64::writeIndirectStubsBlock, masks the high bits of the immediate operand to the stub's ldr instruction so that negative offsets to the stub pointer do not overflow. No testcase -- this fixes most of the OrcLazy testcases for AArch64 (at least on Darwin), but we still need to fix the exception-handling test before we can turn them on.
1 parent 34001b5 commit 9c52102

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

llvm/lib/ExecutionEngine/Orc/OrcABISupport.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,11 @@ void OrcAArch64::writeIndirectStubsBlock(
165165
//
166166
// .section __orc_stubs
167167
// stub1:
168-
// ldr x0, ptr1 ; PC-rel load of ptr1
169-
// br x0 ; Jump to resolver
168+
// ldr x16, ptr1 ; PC-rel load of ptr1
169+
// br x16 ; Jump to resolver
170170
// stub2:
171-
// ldr x0, ptr2 ; PC-rel load of ptr2
172-
// br x0 ; Jump to resolver
171+
// ldr x16, ptr2 ; PC-rel load of ptr2
172+
// br x16 ; Jump to resolver
173173
//
174174
// ...
175175
//
@@ -188,8 +188,10 @@ void OrcAArch64::writeIndirectStubsBlock(
188188
"PointersBlock is out of range");
189189
uint64_t PtrDisplacement =
190190
PointersBlockTargetAddress - StubsBlockTargetAddress;
191+
assert((PtrDisplacement % 8 == 0) &&
192+
"Displacement to pointer is not a multiple of 8");
191193
uint64_t *Stub = reinterpret_cast<uint64_t *>(StubsBlockWorkingMem);
192-
uint64_t PtrOffsetField = PtrDisplacement << 3;
194+
uint64_t PtrOffsetField = ((PtrDisplacement >> 2) & 0x7ffff) << 5;
193195

194196
for (unsigned I = 0; I < NumStubs; ++I)
195197
Stub[I] = 0xd61f020058000010 | PtrOffsetField;

0 commit comments

Comments
 (0)