Skip to content

Commit

Permalink
[AArch64] Fix the size passed to __trampoline_setup (#118234)
Browse files Browse the repository at this point in the history
The trampoline size is 36 bytes on AArch64. The runtime function
__trampoline_setup aborts as it expects the trampoline size of at least 36 
bytes, and the size passed is 20 bytes. Fix the inconsistency in
AArch64TargetLowering::LowerINIT_TRAMPOLINE.
  • Loading branch information
ssijaric-nv authored Jan 10, 2025
1 parent 76fac9c commit a4472c7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
11 changes: 9 additions & 2 deletions llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7281,9 +7281,16 @@ SDValue AArch64TargetLowering::LowerINIT_TRAMPOLINE(SDValue Op,
Entry.Ty = IntPtrTy;
Entry.Node = Trmp;
Args.push_back(Entry);
Entry.Node = DAG.getConstant(20, dl, MVT::i64);
Args.push_back(Entry);

if (auto *FI = dyn_cast<FrameIndexSDNode>(Trmp.getNode())) {
MachineFunction &MF = DAG.getMachineFunction();
MachineFrameInfo &MFI = MF.getFrameInfo();
Entry.Node =
DAG.getConstant(MFI.getObjectSize(FI->getIndex()), dl, MVT::i64);
} else
Entry.Node = DAG.getConstant(36, dl, MVT::i64);

Args.push_back(Entry);
Entry.Node = FPtr;
Args.push_back(Entry);
Entry.Node = Nest;
Expand Down
15 changes: 14 additions & 1 deletion llvm/test/CodeGen/AArch64/trampoline.ll
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
; RUN: llc -mtriple=aarch64-- < %s | FileCheck %s

@trampg = internal global [36 x i8] zeroinitializer, align 8

declare void @llvm.init.trampoline(ptr, ptr, ptr);
declare ptr @llvm.adjust.trampoline(ptr);

Expand All @@ -8,12 +10,23 @@ define i64 @f(ptr nest %c, i64 %x, i64 %y) {
ret i64 %sum
}

define i64 @main() {
define i64 @func1() {
%val = alloca i64
%nval = bitcast ptr %val to ptr
%tramp = alloca [36 x i8], align 8
; CHECK: mov w1, #36
; CHECK: bl __trampoline_setup
call void @llvm.init.trampoline(ptr %tramp, ptr @f, ptr %nval)
%fp = call ptr @llvm.adjust.trampoline(ptr %tramp)
ret i64 0
}

define i64 @func2() {
%val = alloca i64
%nval = bitcast ptr %val to ptr
; CHECK: mov w1, #36
; CHECK: bl __trampoline_setup
call void @llvm.init.trampoline(ptr @trampg, ptr @f, ptr %nval)
%fp = call ptr @llvm.adjust.trampoline(ptr @trampg)
ret i64 0
}

0 comments on commit a4472c7

Please sign in to comment.