Skip to content

Commit

Permalink
arm64_32: extend @llvm.stackguard call to in-DAG 64-bits before handi…
Browse files Browse the repository at this point in the history
…ng off

Pointers are 64-bits in the DAG, so we need to extend the result of loading the
cookie when building the DAG.
  • Loading branch information
TNorthover committed Feb 19, 2024
1 parent da04f30 commit 0215d2c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6956,11 +6956,12 @@ void SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I,
case Intrinsic::stackguard: {
MachineFunction &MF = DAG.getMachineFunction();
const Module &M = *MF.getFunction().getParent();
EVT PtrTy = TLI.getValueType(DAG.getDataLayout(), I.getType());
SDValue Chain = getRoot();
if (TLI.useLoadStackGuardNode()) {
Res = getLoadStackGuard(DAG, sdl, Chain);
Res = DAG.getPtrExtOrTrunc(Res, sdl, PtrTy);
} else {
EVT PtrTy = TLI.getValueType(DAG.getDataLayout(), I.getType());
const Value *Global = TLI.getSDagStackGuard(M);
Align Align = DAG.getDataLayout().getPrefTypeAlign(Global->getType());
Res = DAG.getLoad(PtrTy, sdl, Chain, getValue(Global),
Expand Down
14 changes: 14 additions & 0 deletions llvm/test/CodeGen/AArch64/arm64_32.ll
Original file line number Diff line number Diff line change
Expand Up @@ -759,5 +759,19 @@ define void @test_bzero(i64 %in) {

declare void @llvm.memset.p0.i32(ptr nocapture writeonly, i8, i32, i1)

define i1 @test_stackguard(ptr %p1) {
; CHECK-LABEL: test_stackguard:
; CHECK: adrp x[[TMP:[0-9]+]], ___stack_chk_guard@GOTPAGE
; CHECK: ldr [[GUARD:w[0-9]+]], [x[[TMP]], ___stack_chk_guard@GOTPAGEOFF]
; CHECK: cmp [[GUARD]], w

%p2 = call ptr @llvm.stackguard()
%res = icmp ne ptr %p2, %p1
ret i1 %res
}
declare ptr @llvm.stackguard()
@__stack_chk_guard = external global i32


!llvm.module.flags = !{!0}
!0 = !{i32 7, !"PIC Level", i32 2}

0 comments on commit 0215d2c

Please sign in to comment.