[llvm] [RISCV] Emit .note.gnu.property section when Zicfiss-based shadow stack is enabled (PR #127036)

Kito Cheng via llvm-commits llvm-commits at lists.llvm.org
Mon May 12 01:33:26 PDT 2025


================
@@ -0,0 +1,13 @@
+; RUN: llc --mtriple=riscv32-unknown-linux-gnu --filetype=obj -o - %s | llvm-readelf -n - | FileCheck %s
+; RUN: llc --mtriple=riscv64-unknown-linux-gnu --filetype=obj -o - %s | llvm-readelf -n - | FileCheck %s
+
+; CHECK: Properties: RISC-V feature: ZICFISS
+
+define i32 @f() "hw-shadow-stack" {
+entry:
+  ret i32 0
+}
+
+!llvm.module.flags = !{!0}
+
+!0 = !{i32 8, !"cf-protection-return", i32 1}
----------------
kito-cheng wrote:

Could you also add check to make sure the output is right?

Here is the testcase from our downstream, it might have slight different, but should be a good reference :)
```
; RUN: llc -mtriple riscv32 -mattr=+experimental-zicfiss < %s | FileCheck %s --check-prefixes=CHECK,RV32
; RUN: llc -mtriple riscv64 -mattr=+experimental-zicfiss < %s | FileCheck %s --check-prefixes=CHECK,RV64

define dso_local void @foo() {
  ret void
}

!llvm.module.flags = !{!0}

; CHECK:        .size   foo, .Lfunc_end0-foo
; CHECK:        .cfi_endproc
; CHECK:                                        # -- End function
; CHECK:        .section        ".note.GNU-stack","", at progbits
; CHECK:        .section        .note.gnu.property,"a", at note
; RV32:         .p2align        2, 0x0
; RV64:         .p2align        3, 0x0
; CHECK:        .word   4
; RV32:         .word   12
; RV64:         .word   16
; CHECK:        .word   5
; CHECK:        .asciz  "GNU"
; CHECK:        .word   3221225472
; CHECK:        .word   4
; CHECK:        .word   2
; RV64:         .word   0
; CHECK:.Lsec_end0:
; CHECK:        .section        ".note.GNU-stack","", at progbits


!0 = !{i32 8, !"cf-protection-return", i32 1}
```

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


More information about the llvm-commits mailing list