Skip to content

Commit a4472c7

Browse files
authored
[AArch64] Fix the size passed to __trampoline_setup (llvm#118234)
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.
1 parent 76fac9c commit a4472c7

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7281,9 +7281,16 @@ SDValue AArch64TargetLowering::LowerINIT_TRAMPOLINE(SDValue Op,
72817281
Entry.Ty = IntPtrTy;
72827282
Entry.Node = Trmp;
72837283
Args.push_back(Entry);
7284-
Entry.Node = DAG.getConstant(20, dl, MVT::i64);
7285-
Args.push_back(Entry);
72867284

7285+
if (auto *FI = dyn_cast<FrameIndexSDNode>(Trmp.getNode())) {
7286+
MachineFunction &MF = DAG.getMachineFunction();
7287+
MachineFrameInfo &MFI = MF.getFrameInfo();
7288+
Entry.Node =
7289+
DAG.getConstant(MFI.getObjectSize(FI->getIndex()), dl, MVT::i64);
7290+
} else
7291+
Entry.Node = DAG.getConstant(36, dl, MVT::i64);
7292+
7293+
Args.push_back(Entry);
72877294
Entry.Node = FPtr;
72887295
Args.push_back(Entry);
72897296
Entry.Node = Nest;
Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
; RUN: llc -mtriple=aarch64-- < %s | FileCheck %s
22

3+
@trampg = internal global [36 x i8] zeroinitializer, align 8
4+
35
declare void @llvm.init.trampoline(ptr, ptr, ptr);
46
declare ptr @llvm.adjust.trampoline(ptr);
57

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

11-
define i64 @main() {
13+
define i64 @func1() {
1214
%val = alloca i64
1315
%nval = bitcast ptr %val to ptr
1416
%tramp = alloca [36 x i8], align 8
17+
; CHECK: mov w1, #36
1518
; CHECK: bl __trampoline_setup
1619
call void @llvm.init.trampoline(ptr %tramp, ptr @f, ptr %nval)
1720
%fp = call ptr @llvm.adjust.trampoline(ptr %tramp)
1821
ret i64 0
1922
}
23+
24+
define i64 @func2() {
25+
%val = alloca i64
26+
%nval = bitcast ptr %val to ptr
27+
; CHECK: mov w1, #36
28+
; CHECK: bl __trampoline_setup
29+
call void @llvm.init.trampoline(ptr @trampg, ptr @f, ptr %nval)
30+
%fp = call ptr @llvm.adjust.trampoline(ptr @trampg)
31+
ret i64 0
32+
}

0 commit comments

Comments
 (0)