[clang] [llvm] [Clang][RISCV] Support -fcf-protection=return for RISC-V (PR #112477)
Ming-Yi Lai via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 24 19:27:10 PDT 2024
================
@@ -607,6 +607,9 @@ class RISCVTargetCodeGenInfo : public TargetCodeGenInfo {
auto *Fn = cast<llvm::Function>(GV);
Fn->addFnAttr("interrupt", Kind);
+
+ if (CGM.getCodeGenOpts().CFProtectionReturn)
----------------
mylai-mtk wrote:
After tracing the code, I believe the above lines are for attaching interrupt attributes to LLVM functions based on the C `__attribute__((interrupt))` parsed by Clang. They're placed here since the interrupt attribute implementation is target-specific (ref. https://gcc.gnu.org/onlinedocs/gcc-4.9.2/gcc/Function-Attributes.html#index-interrupt-handler-functions-2886).
The above lines
```c++
const auto *Attr = FD->getAttr<RISCVInterruptAttr>();
if (!Attr)
return;
```
mean that for C function declarations without the interrupt attribute, which is the common case for normal functions, the `setTargetAttributes` function would exit early, and this renders your attachment of the `hw-shadow-stack` attribute undone.
https://github.com/llvm/llvm-project/pull/112477
More information about the llvm-commits
mailing list