The Linux kernel uses this for having a per-thread stack canary. Implementing this for both arm64 and riscv is desired. For example, gcc's arm64 support is used like this in the kernel: -mstack-protector-guard=sysreg -mstack-protector-guard-reg=sp_el0 -mstack-protector-guard-offset=0 https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=0a1213fa7432778b71a1c0166bf56660a3aab030 Here are discussions on the start of riscv support: https://lore.kernel.org/lkml/CAJF2gTTr_ENhGRmjqNbGBhEc8y4D3YSqAResvwHuB1ykemKTUw@mail.gmail.com/
SelectionDAGBuilder::visitSPDescriptorParent is probably the most relevant method for this. I'm not sure yet how best to modify getLoadStackGuard in order to change this from a load of a global Value to an aarch64 specific `mrs` instruction. Here's a basic test case demonstrating the differences between these 3 new flags, vs without them (but still with -fstack-protector-strong). https://godbolt.org/z/oEc1fvMPo
Ah looks like I can just add custom expansion for AArch64::LOAD_STACK_GUARD in AArch64InstrInfo::expandPostRAPseudo() and that seems to work.
aarch64: https://reviews.llvm.org/D100919
https://reviews.llvm.org/rG0f417789192e74f9d2fad0f6aee4efc394257176 has landed for aarch64 with the caveats that we only support sp_el0 for valid sysreg, and we don't try too hard to support arbitrary int32_t's for offsets.
For the Linux kernel, it looks like risc-v uses -mstack-protector-guard=tls -mstack-protector-guard-reg=tp -mstack-protector-guard-offset= It looks like ppc uses: -mstack-protector-guard=tls -mstack-protector-guard-reg={r13|r2} -mstack-protector-guard-offset= x86 uses: -mstack-protector-guard-reg=fs -mstack-protector-guard-symbol=__stack_chk_guard -mstack-protector-guard=global See https://bugs.llvm.org/show_bug.cgi?id=49209 for -mstack-protector-guard-symbol=.