Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion llvm/include/llvm/CodeGen/TargetLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -5770,7 +5770,7 @@ class LLVM_ABI TargetLowering : public TargetLoweringBase {
virtual bool useLoadStackGuardNode(const Module &M) const { return false; }

virtual SDValue emitStackGuardXorFP(SelectionDAG &DAG, SDValue Val,
const SDLoc &DL) const {
const SDLoc &DL, bool FailureBB) const {
llvm_unreachable("not implemented for this target");
}

Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3087,7 +3087,7 @@ void SelectionDAGBuilder::visitSPDescriptorParent(StackProtectorDescriptor &SPD,
MachineMemOperand::MOVolatile);

if (TLI.useStackGuardXorFP())
GuardVal = TLI.emitStackGuardXorFP(DAG, GuardVal, dl);
GuardVal = TLI.emitStackGuardXorFP(DAG, GuardVal, dl, false);

// If we're using function-based instrumentation, call the guard check
// function
Expand Down Expand Up @@ -3192,7 +3192,7 @@ void SelectionDAGBuilder::visitSPDescriptorFailure(
MachineMemOperand::MOVolatile);

if (TLI.useStackGuardXorFP())
GuardVal = TLI.emitStackGuardXorFP(DAG, GuardVal, dl);
GuardVal = TLI.emitStackGuardXorFP(DAG, GuardVal, dl, true);

// The target provides a guard check function to validate the guard value.
// Generate a call to that function with the content of the guard slot as
Expand Down Expand Up @@ -7354,7 +7354,7 @@ void SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I,
MachineMemOperand::MOVolatile);
}
if (TLI.useStackGuardXorFP())
Res = TLI.emitStackGuardXorFP(DAG, Res, sdl);
Res = TLI.emitStackGuardXorFP(DAG, Res, sdl, false);
DAG.setRoot(Chain);
setValue(&I, Res);
return;
Expand Down
18 changes: 18 additions & 0 deletions llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28968,6 +28968,24 @@ bool AArch64TargetLowering::useLoadStackGuardNode(const Module &M) const {
return true;
}

bool AArch64TargetLowering::useStackGuardXorFP() const {
// Currently only MSVC CRTs XOR the frame pointer into the stack guard value.
return Subtarget->getTargetTriple().isOSMSVCRT() &&
!getTargetMachine().Options.EnableGlobalISel;
}

SDValue AArch64TargetLowering::emitStackGuardXorFP(SelectionDAG &DAG,
SDValue Val, const SDLoc &DL,
bool FailureBB) const {
if (FailureBB) {
return DAG.getNode(
ISD::XOR, DL, Val.getValueType(), Val,
DAG.getCopyFromReg(DAG.getEntryNode(), DL,
getStackPointerRegisterToSaveRestore(), MVT::i64));
}
return Val;
}

unsigned AArch64TargetLowering::combineRepeatedFPDivisors() const {
// Combine multiple FDIVs with the same divisor into multiple FMULs by the
// reciprocal if there are three or more FDIVs.
Expand Down
3 changes: 3 additions & 0 deletions llvm/lib/Target/AArch64/AArch64ISelLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,9 @@ class AArch64TargetLowering : public TargetLowering {
shouldExpandAtomicCmpXchgInIR(AtomicCmpXchgInst *AI) const override;

bool useLoadStackGuardNode(const Module &M) const override;
bool useStackGuardXorFP() const override;
SDValue emitStackGuardXorFP(SelectionDAG &DAG, SDValue Val, const SDLoc &DL,
bool FailureBB) const override;
TargetLoweringBase::LegalizeTypeAction
getPreferredVectorAction(MVT VT) const override;

Expand Down
9 changes: 9 additions & 0 deletions llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2276,6 +2276,15 @@ bool AArch64InstrInfo::expandPostRAPseudo(MachineInstr &MI) const {
.addMemOperand(*MI.memoperands_begin());
}
}
// To match MSVC
if (Subtarget.getTargetTriple().isOSMSVCRT() &&
!Subtarget.getTargetLowering()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there some reason the isTargetMachO() check is in AArch64TargetLowering::useStackGuardXorFP, but not here?

->getTargetMachine()
.Options.EnableGlobalISel) {
BuildMI(MBB, MI, DL, get(AArch64::EORXrr), Reg)
.addReg(Reg, RegState::Kill)
.addReg(AArch64::SP);
}

MBB.erase(MI);

Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/Target/X86/X86ISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2739,7 +2739,8 @@ bool X86TargetLowering::useStackGuardXorFP() const {
}

SDValue X86TargetLowering::emitStackGuardXorFP(SelectionDAG &DAG, SDValue Val,
const SDLoc &DL) const {
const SDLoc &DL,
bool FailureBB) const {
EVT PtrTy = getPointerTy(DAG.getDataLayout());
unsigned XorOp = Subtarget.is64Bit() ? X86::XOR64_FP : X86::XOR32_FP;
MachineSDNode *Node = DAG.getMachineNode(XorOp, DL, PtrTy, Val);
Expand Down
5 changes: 2 additions & 3 deletions llvm/lib/Target/X86/X86ISelLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -1594,9 +1594,8 @@ namespace llvm {
bool useStackGuardXorFP() const override;
void insertSSPDeclarations(Module &M) const override;
Function *getSSPStackGuardCheck(const Module &M) const override;
SDValue emitStackGuardXorFP(SelectionDAG &DAG, SDValue Val,
const SDLoc &DL) const override;

SDValue emitStackGuardXorFP(SelectionDAG &DAG, SDValue Val, const SDLoc &DL,
bool FailureBB) const override;

/// Return true if the target stores SafeStack pointer at a fixed offset in
/// some non-standard address space, and populates the address space and
Expand Down
4 changes: 3 additions & 1 deletion llvm/test/CodeGen/AArch64/mingw-refptr.ll
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
; RUN: llc < %s -mtriple=aarch64-w64-mingw32 | FileCheck %s --check-prefixes=CHECK,CHECK-SD
; RUN: llc < %s -mtriple=aarch64-w64-mingw32 -global-isel | FileCheck %s --check-prefixes=CHECK,CHECK-GI
; RUN: llc < %s -mtriple=aarch64-w64-mingw32 -global-isel | FileCheck %s --check-prefixes=CHECK-GI

@var = external local_unnamed_addr global i32, align 4
@dsolocalvar = external dso_local local_unnamed_addr global i32, align 4
Expand Down Expand Up @@ -89,12 +89,14 @@ define dso_local void @sspFunc() #0 {
; CHECK-NEXT: add x0, sp, #7
; CHECK-NEXT: ldr x8, [x8, :lo12:.refptr.__stack_chk_guard]
; CHECK-NEXT: ldr x8, [x8]
; CHECK-NEXT: eor x8, x8, sp
; CHECK-NEXT: str x8, [sp, #8]
; CHECK-NEXT: bl ptrUser
; CHECK-NEXT: adrp x8, .refptr.__stack_chk_guard
; CHECK-NEXT: ldr x8, [x8, :lo12:.refptr.__stack_chk_guard]
; CHECK-NEXT: ldr x9, [sp, #8]
; CHECK-NEXT: ldr x8, [x8]
; CHECK-NEXT: eor x8, x8, sp
; CHECK-NEXT: cmp x8, x9
; CHECK-NEXT: b.ne .LBB6_2
; CHECK-NEXT: // %bb.1: // %entry
Expand Down
10 changes: 8 additions & 2 deletions llvm/test/CodeGen/AArch64/stack-protector-target.ll
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,20 @@ declare void @_Z7CapturePi(ptr)

; WINDOWS-AARCH64: adrp x8, __security_cookie
; WINDOWS-AARCH64: ldr x8, [x8, :lo12:__security_cookie]
; WINDOWS-AARCH64: eor x8, x8, sp
; WINDOWS-AARCH64: str x8, [sp, #8]
; WINDOWS-AARCH64: bl _Z7CapturePi
; WINDOWS-AARCH64: ldr x0, [sp, #8]
; WINDOWS-AARCH64: ldr x8, [sp, #8]
; WINDOWS-AARCH64: mov x9, sp
; WINDOWS-AARCH64: eor x0, x8, x9
; WINDOWS-AARCH64: bl __security_check_cookie

; WINDOWS-ARM64EC: adrp x8, __security_cookie
; WINDOWS-ARM64EC: ldr x8, [x8, :lo12:__security_cookie]
; WINDOWS-ARM64EC: eor x8, x8, sp
; WINDOWS-ARM64EC: str x8, [sp, #8]
; WINDOWS-ARM64EC: bl "#_Z7CapturePi"
; WINDOWS-ARM64EC: ldr x0, [sp, #8]
; WINDOWS-ARM64EC: ldr x8, [sp, #8]
; WINDOWS-ARM64EC: mov x9, sp
; WINDOWS-ARM64EC: eor x0, x8, x9
; WINDOWS-ARM64EC: bl "#__security_check_cookie_arm64ec"