[llvm] [RISCV] Implement shadow stack on shadow stack mode with Zicfiss. (PR #68075)

Sami Tolvanen via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 13 16:19:51 PDT 2023


================
@@ -106,9 +111,14 @@ static void emitSCSEpilogue(MachineFunction &MF, MachineBasicBlock &MBB,
           CSI, [&](CalleeSavedInfo &CSR) { return CSR.getReg() == RAReg; }))
     return;
 
+  const RISCVInstrInfo *TII = STI.getInstrInfo();
+  if (STI.hasFeature(RISCV::FeatureStdExtZicfiss)) {
----------------
samitolvanen wrote:

> > Do we need an enable other than just the feature being in -march? The shadow stack pointer has to be set up when the application starts. Is this done by the kernel?
> > My concern is that if your -mcpu supports Zicfiss, but the kernel doesn't, this will generate code that doesn't work.
> 
> oh, that's good point...let me check how other target do

If the kernel doesn't support Zicfiss, it presumably also hasn't enabled the extension for U-mode. Therefore, my understanding is that the application loader can simply skip shadow stack setup for the program, including the `prctl` (which would fail with `-EINVAL`), and since the Zicfiss (Zimop) instructions are no-ops when the extension is disabled, the program would run normally, just without shadow stacks. Does this sound correct?

https://github.com/llvm/llvm-project/pull/68075


More information about the llvm-commits mailing list