llvm.org GIT mirror llvm / c36c93b
[COFF, ARM64] Add support for MSVC buffer security check Reviewers: rnk, mstorsjo, compnerd, efriedma, TomTan Reviewed By: rnk Subscribers: javed.absar, kristof.beyls, chrib, llvm-commits Differential Revision: https://reviews.llvm.org/D54248 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@346469 91177308-0d34-0410-b5e6-96231b3b80d8 Mandeep Singh Grang 1 year, 5 days ago
3 changed file(s) with 45 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
1166711667 return TargetLowering::getIRStackGuard(IRB);
1166811668 }
1166911669
11670 void AArch64TargetLowering::insertSSPDeclarations(Module &M) const {
11671 // MSVC CRT provides functionalities for stack protection.
11672 if (Subtarget->getTargetTriple().isWindowsMSVCEnvironment()) {
11673 // MSVC CRT has a global variable holding security cookie.
11674 M.getOrInsertGlobal("__security_cookie",
11675 Type::getInt8PtrTy(M.getContext()));
11676
11677 // MSVC CRT has a function to validate security cookie.
11678 auto *SecurityCheckCookie = cast(
11679 M.getOrInsertFunction("__security_check_cookie",
11680 Type::getVoidTy(M.getContext()),
11681 Type::getInt8PtrTy(M.getContext())));
11682 SecurityCheckCookie->setCallingConv(CallingConv::Win64);
11683 SecurityCheckCookie->addAttribute(1, Attribute::AttrKind::InReg);
11684 return;
11685 }
11686 TargetLowering::insertSSPDeclarations(M);
11687 }
11688
11689 Value *AArch64TargetLowering::getSDagStackGuard(const Module &M) const {
11690 // MSVC CRT has a global variable holding security cookie.
11691 if (Subtarget->getTargetTriple().isWindowsMSVCEnvironment())
11692 return M.getGlobalVariable("__security_cookie");
11693 return TargetLowering::getSDagStackGuard(M);
11694 }
11695
11696 Value *AArch64TargetLowering::getSSPStackGuardCheck(const Module &M) const {
11697 // MSVC CRT has a function to validate security cookie.
11698 if (Subtarget->getTargetTriple().isWindowsMSVCEnvironment())
11699 return M.getFunction("__security_check_cookie");
11700 return TargetLowering::getSSPStackGuardCheck(M);
11701 }
11702
1167011703 Value *AArch64TargetLowering::getSafeStackPointerLocation(IRBuilder<> &IRB) const {
1167111704 // Android provides a fixed TLS slot for the SafeStack pointer. See the
1167211705 // definition of TLS_SLOT_SAFESTACK in
399399 /// If the target has a standard location for the stack protector cookie,
400400 /// returns the address of that location. Otherwise, returns nullptr.
401401 Value *getIRStackGuard(IRBuilder<> &IRB) const override;
402
403 void insertSSPDeclarations(Module &M) const override;
404 Value *getSDagStackGuard(const Module &M) const override;
405 Value *getSSPStackGuardCheck(const Module &M) const override;
402406
403407 /// If the target has a standard location for the unsafe stack pointer,
404408 /// returns the address of that location. Otherwise, returns nullptr.
11 ; RUN: llc -mtriple=aarch64-linux-android < %s -o - | FileCheck --check-prefix=ANDROID-AARCH64 %s
22 ; RUN: llc -mtriple=aarch64-fuchsia < %s -o - | FileCheck --check-prefixes=FUCHSIA-AARCH64-COMMON,FUCHSIA-AARCH64-USER %s
33 ; RUN: llc -mtriple=aarch64-fuchsia -code-model=kernel < %s -o - | FileCheck --check-prefixes=FUCHSIA-AARCH64-COMMON,FUCHSIA-AARCH64-KERNEL %s
4 ; RUN: llc -mtriple=aarch64-windows < %s -o - | FileCheck --check-prefix=WINDOWS-AARCH64 %s
45
56 define void @_Z1fv() sspreq {
67 entry:
2627 ; FUCHSIA-AARCH64-COMMON: ldur [[C:.*]], {{\[}}[[A]], #-16]
2728 ; FUCHSIA-AARCH64-COMMON: ldr [[D:.*]], [sp,
2829 ; FUCHSIA-AARCH64-COMMON: cmp [[C]], [[D]]
30
31 ; WINDOWS-AARCH64: adrp x8, __security_cookie
32 ; WINDOWS-AARCH64: ldr x8, [x8, __security_cookie]
33 ; WINDOWS-AARCH64: str x8, [sp, #8]
34 ; WINDOWS-AARCH64: bl _Z7CapturePi
35 ; WINDOWS-AARCH64: ldr x0, [sp, #8]
36 ; WINDOWS-AARCH64: bl __security_check_cookie