Skip to content

Commit f99f73f

Browse files
author
Yeting Kuo
committed
[RISCV] Add feature forced-sw-shadow-stack to decide use hw/sw implemenet for shadow stack.
1 parent 7ee57c4 commit f99f73f

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

llvm/lib/Target/RISCV/RISCVFeatures.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,3 +1044,8 @@ def FeatureTaggedGlobals : SubtargetFeature<"tagged-globals",
10441044
"AllowTaggedGlobals",
10451045
"true", "Use an instruction sequence for taking the address of a global "
10461046
"that allows a memory tag in the upper address bits">;
1047+
1048+
def FeatureForcedSWShadowStack : SubtargetFeature<
1049+
"forced-sw-shadow-stack", "HasForcedSWShadowStack", "true",
1050+
"Implement shadow stack with software.">;
1051+
def HasForcedSWShadowStack : Predicate<"Subtarget->hasForcedSWShadowStack()">;

llvm/lib/Target/RISCV/RISCVFrameLowering.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@
2727

2828
using namespace llvm;
2929

30-
static cl::opt<bool>
31-
HardwareShadowStack("riscv-hardware-shadow-stack", cl::init(false),
32-
cl::Hidden,
33-
cl::desc("Enable hardware shadow stack with Zicfiss."));
34-
3530
static const Register AllPopRegs[] = {
3631
RISCV::X1, RISCV::X8, RISCV::X9, RISCV::X18, RISCV::X19,
3732
RISCV::X20, RISCV::X21, RISCV::X22, RISCV::X23, RISCV::X24,
@@ -57,9 +52,8 @@ static void emitSCSPrologue(MachineFunction &MF, MachineBasicBlock &MBB,
5752
return;
5853

5954
const RISCVInstrInfo *TII = STI.getInstrInfo();
60-
if (HardwareShadowStack) {
61-
if (!STI.hasFeature(RISCV::FeatureStdExtZicfiss))
62-
report_fatal_error("Hardware shadow stack needs Zicfiss to be enabled");
55+
if (!STI.hasForcedSWShadowStack() &&
56+
STI.hasFeature(RISCV::FeatureStdExtZicfiss)) {
6357
BuildMI(MBB, MI, DL, TII->get(RISCV::SSPUSH)).addReg(RAReg);
6458
return;
6559
}
@@ -119,9 +113,8 @@ static void emitSCSEpilogue(MachineFunction &MF, MachineBasicBlock &MBB,
119113
return;
120114

121115
const RISCVInstrInfo *TII = STI.getInstrInfo();
122-
if (HardwareShadowStack) {
123-
if (!STI.hasFeature(RISCV::FeatureStdExtZicfiss))
124-
report_fatal_error("Hardware shadow stack needs Zicfiss to be enabled");
116+
if (!STI.hasForcedSWShadowStack() &&
117+
STI.hasFeature(RISCV::FeatureStdExtZicfiss)) {
125118
BuildMI(MBB, MI, DL, TII->get(RISCV::SSPOPCHK)).addReg(RAReg);
126119
return;
127120
}

llvm/test/CodeGen/RISCV/shadowcallstack.ll

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33
; RUN: | FileCheck %s --check-prefix=RV32
44
; RUN: llc -mtriple=riscv64 -verify-machineinstrs < %s \
55
; RUN: | FileCheck %s --check-prefix=RV64
6-
; RUN: llc -mtriple=riscv32 -mattr=+experimental-zicfiss -riscv-hardware-shadow-stack -verify-machineinstrs < %s \
7-
; RUN: | FileCheck %s --check-prefix=RV32-ZICFISS
8-
; RUN: llc -mtriple=riscv64 -mattr=+experimental-zicfiss -riscv-hardware-shadow-stack -verify-machineinstrs < %s \
9-
; RUN: | FileCheck %s --check-prefix=RV64-ZICFISS
6+
; RUN: llc -mtriple=riscv32 -mattr=+experimental-zicfiss < %s \
7+
; RUN: -verify-machineinstrs | FileCheck %s --check-prefix=RV32-ZICFISS
8+
; RUN: llc -mtriple=riscv64 -mattr=+experimental-zicfiss < %s \
9+
; RUN: -verify-machineinstrs | FileCheck %s --check-prefix=RV64-ZICFISS
10+
; RUN: llc -mtriple=riscv32 -mattr=+experimental-zicfiss,forced-sw-shadow-stack \
11+
; RUN: -verify-machineinstrs < %s | FileCheck %s --check-prefix=RV32
12+
; RUN: llc -mtriple=riscv64 -mattr=+experimental-zicfiss,forced-sw-shadow-stack \
13+
; RUN: -verify-machineinstrs < %s | FileCheck %s --check-prefix=RV64
1014

1115
define void @f1() shadowcallstack {
1216
; RV32-LABEL: f1:

0 commit comments

Comments
 (0)