[llvm] 2b9cec6 - [ARM64EC 5/?] Fix names of __chkstk and __security_check_cookie.
Eli Friedman via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 5 13:20:08 PDT 2022
Author: Eli Friedman
Date: 2022-09-05T13:19:54-07:00
New Revision: 2b9cec6244fda2f3191e8398aeae363aa67bebc8
URL: https://github.com/llvm/llvm-project/commit/2b9cec6244fda2f3191e8398aeae363aa67bebc8
DIFF: https://github.com/llvm/llvm-project/commit/2b9cec6244fda2f3191e8398aeae363aa67bebc8.diff
LOG: [ARM64EC 5/?] Fix names of __chkstk and __security_check_cookie.
Part of initial Arm64EC patchset.
Arm64EC code needs to use functions with a different name, to avoid
using the x64 versions.
Differential Revision: https://reviews.llvm.org/D125417
Added:
Modified:
llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
llvm/lib/Target/AArch64/AArch64Subtarget.h
llvm/test/CodeGen/AArch64/stack-protector-target.ll
llvm/test/CodeGen/AArch64/win-alloca.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp b/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
index 611748ad3b70..09c243ada305 100644
--- a/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
@@ -1660,13 +1660,14 @@ void AArch64FrameLowering::emitPrologue(MachineFunction &MF,
.setMIFlags(MachineInstr::FrameSetup);
}
+ const char* ChkStk = Subtarget.getChkStkName();
switch (MF.getTarget().getCodeModel()) {
case CodeModel::Tiny:
case CodeModel::Small:
case CodeModel::Medium:
case CodeModel::Kernel:
BuildMI(MBB, MBBI, DL, TII->get(AArch64::BL))
- .addExternalSymbol("__chkstk")
+ .addExternalSymbol(ChkStk)
.addReg(AArch64::X15, RegState::Implicit)
.addReg(AArch64::X16, RegState::Implicit | RegState::Define | RegState::Dead)
.addReg(AArch64::X17, RegState::Implicit | RegState::Define | RegState::Dead)
@@ -1681,8 +1682,8 @@ void AArch64FrameLowering::emitPrologue(MachineFunction &MF,
case CodeModel::Large:
BuildMI(MBB, MBBI, DL, TII->get(AArch64::MOVaddrEXT))
.addReg(AArch64::X16, RegState::Define)
- .addExternalSymbol("__chkstk")
- .addExternalSymbol("__chkstk")
+ .addExternalSymbol(ChkStk)
+ .addExternalSymbol(ChkStk)
.setMIFlags(MachineInstr::FrameSetup);
if (NeedsWinCFI) {
HasWinCFI = true;
diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
index b5d8d3d6b4ef..67a5f88e1408 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -12492,7 +12492,8 @@ SDValue AArch64TargetLowering::LowerWindowsDYNAMIC_STACKALLOC(
SDValue Op, SDValue Chain, SDValue &Size, SelectionDAG &DAG) const {
SDLoc dl(Op);
EVT PtrVT = getPointerTy(DAG.getDataLayout());
- SDValue Callee = DAG.getTargetExternalSymbol("__chkstk", PtrVT, 0);
+ SDValue Callee = DAG.getTargetExternalSymbol(Subtarget->getChkStkName(),
+ PtrVT, 0);
const AArch64RegisterInfo *TRI = Subtarget->getRegisterInfo();
const uint32_t *Mask = TRI->getWindowsStackProbePreservedMask();
@@ -20965,8 +20966,8 @@ void AArch64TargetLowering::insertSSPDeclarations(Module &M) const {
// MSVC CRT has a function to validate security cookie.
FunctionCallee SecurityCheckCookie = M.getOrInsertFunction(
- "__security_check_cookie", Type::getVoidTy(M.getContext()),
- Type::getInt8PtrTy(M.getContext()));
+ Subtarget->getSecurityCheckCookieName(),
+ Type::getVoidTy(M.getContext()), Type::getInt8PtrTy(M.getContext()));
if (Function *F = dyn_cast<Function>(SecurityCheckCookie.getCallee())) {
F->setCallingConv(CallingConv::Win64);
F->addParamAttr(0, Attribute::AttrKind::InReg);
@@ -20986,7 +20987,7 @@ Value *AArch64TargetLowering::getSDagStackGuard(const Module &M) const {
Function *AArch64TargetLowering::getSSPStackGuardCheck(const Module &M) const {
// MSVC CRT has a function to validate security cookie.
if (Subtarget->getTargetTriple().isWindowsMSVCEnvironment())
- return M.getFunction("__security_check_cookie");
+ return M.getFunction(Subtarget->getSecurityCheckCookieName());
return TargetLowering::getSSPStackGuardCheck(M);
}
diff --git a/llvm/lib/Target/AArch64/AArch64Subtarget.h b/llvm/lib/Target/AArch64/AArch64Subtarget.h
index 31315953be3b..7296e144ced1 100644
--- a/llvm/lib/Target/AArch64/AArch64Subtarget.h
+++ b/llvm/lib/Target/AArch64/AArch64Subtarget.h
@@ -353,6 +353,19 @@ class AArch64Subtarget final : public AArch64GenSubtargetInfo {
}
unsigned getVScaleForTuning() const { return VScaleForTuning; }
+
+ const char* getChkStkName() const {
+ if (isWindowsArm64EC())
+ return "__chkstk_arm64ec";
+ return "__chkstk";
+ }
+
+ const char* getSecurityCheckCookieName() const {
+ if (isWindowsArm64EC())
+ return "__security_check_cookie_arm64ec";
+ return "__security_check_cookie";
+ }
+
};
} // End llvm namespace
diff --git a/llvm/test/CodeGen/AArch64/stack-protector-target.ll b/llvm/test/CodeGen/AArch64/stack-protector-target.ll
index 9d420e8db3e9..dc0a288d8918 100644
--- a/llvm/test/CodeGen/AArch64/stack-protector-target.ll
+++ b/llvm/test/CodeGen/AArch64/stack-protector-target.ll
@@ -3,6 +3,7 @@
; RUN: llc -mtriple=aarch64-fuchsia < %s -o - | FileCheck --check-prefixes=FUCHSIA-AARCH64-COMMON,FUCHSIA-AARCH64-USER %s
; RUN: llc -mtriple=aarch64-fuchsia -mattr=+tpidr-el1 < %s -o - | FileCheck --check-prefixes=FUCHSIA-AARCH64-COMMON,FUCHSIA-AARCH64-KERNEL %s
; RUN: llc -mtriple=aarch64-windows < %s -o - | FileCheck --check-prefix=WINDOWS-AARCH64 %s
+; RUN: llc -mtriple=arm64ec-windows-msvc < %s -o - | FileCheck --check-prefix=WINDOWS-ARM64EC %s
define void @_Z1fv() sspreq {
entry:
@@ -35,3 +36,10 @@ declare void @_Z7CapturePi(i32*)
; WINDOWS-AARCH64: bl _Z7CapturePi
; WINDOWS-AARCH64: ldr x0, [sp, #8]
; WINDOWS-AARCH64: bl __security_check_cookie
+
+; WINDOWS-ARM64EC: adrp x8, __security_cookie
+; WINDOWS-ARM64EC: ldr x8, [x8, :lo12:__security_cookie]
+; WINDOWS-ARM64EC: str x8, [sp, #8]
+; WINDOWS-ARM64EC: bl _Z7CapturePi
+; WINDOWS-ARM64EC: ldr x0, [sp, #8]
+; WINDOWS-ARM64EC: bl __security_check_cookie_arm64ec
diff --git a/llvm/test/CodeGen/AArch64/win-alloca.ll b/llvm/test/CodeGen/AArch64/win-alloca.ll
index 9c34cabbb547..e4d52ca99001 100644
--- a/llvm/test/CodeGen/AArch64/win-alloca.ll
+++ b/llvm/test/CodeGen/AArch64/win-alloca.ll
@@ -1,5 +1,6 @@
; RUN: llc -mtriple aarch64-windows -verify-machineinstrs -filetype asm -o - %s | FileCheck %s -check-prefixes=CHECK,CHECK-OPT
; RUN: llc -mtriple aarch64-windows -verify-machineinstrs -filetype asm -o - %s -O0 | FileCheck %s
+; RUN: llc -mtriple arm64ec-windows-msvc -verify-machineinstrs -filetype asm -o - %s | FileCheck -check-prefix=CHECK-ARM64EC %s
define void @func(i64 %a) {
entry:
@@ -20,3 +21,4 @@ declare void @func2(i8*)
; CHECK-OPT: sub [[REG3:x[0-9]+]], sp, x15, lsl #4
; CHECK-OPT: mov sp, [[REG3]]
; CHECK: bl func2
+; CHECK-ARM64EC: bl __chkstk_arm64ec
More information about the llvm-commits
mailing list