https://github.com/jaidTw updated https://github.com/llvm/llvm-project/pull/112477
>From fe4a28fb691b69d9af384f1dc2f0667761adef44 Mon Sep 17 00:00:00 2001 From: Jesse Huang <jesse.hu...@sifive.com> Date: Sun, 13 Oct 2024 15:11:06 +0800 Subject: [PATCH 1/2] [Clang][RISCV] Support -fcf-protection=return for RISC-V --- clang/lib/Basic/Targets/RISCV.h | 7 +++++++ clang/lib/CodeGen/CodeGenFunction.cpp | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/clang/lib/Basic/Targets/RISCV.h b/clang/lib/Basic/Targets/RISCV.h index bf40edb8683b3e..3f2cee72fc3731 100644 --- a/clang/lib/Basic/Targets/RISCV.h +++ b/clang/lib/Basic/Targets/RISCV.h @@ -141,6 +141,13 @@ class RISCVTargetInfo : public TargetInfo { return true; } + bool + checkCFProtectionReturnSupported(DiagnosticsEngine &Diags) const override { + if (ISAInfo->hasExtension("zimop")) + return true; + return TargetInfo::checkCFProtectionReturnSupported(Diags); + } + CFBranchLabelSchemeKind getDefaultCFBranchLabelScheme() const override { return CFBranchLabelSchemeKind::FuncSig; } diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index 2306043c90f406..d8f0f7c14f6b40 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -899,6 +899,10 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, if (CodeGenOpts.PointerAuth.IndirectGotos) Fn->addFnAttr("ptrauth-indirect-gotos"); + // Add return control flow integrity attributes. + if (CodeGenOpts.CFProtectionReturn) + Fn->addFnAttr("hw-shadow-stack"); + // Apply xray attributes to the function (as a string, for now) bool AlwaysXRayAttr = false; if (const auto *XRayAttr = D ? D->getAttr<XRayInstrumentAttr>() : nullptr) { >From 449c0d9500243b76eeba32a4771a77f8c849542f Mon Sep 17 00:00:00 2001 From: Jesse Huang <jesse.hu...@sifive.com> Date: Wed, 23 Oct 2024 14:42:35 +0800 Subject: [PATCH 2/2] [Clang][RISCV] Add RISCV check for hw-shadow-stack --- clang/lib/CodeGen/CodeGenFunction.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index d8f0f7c14f6b40..f25b9dc4752b4c 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -900,7 +900,8 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, Fn->addFnAttr("ptrauth-indirect-gotos"); // Add return control flow integrity attributes. - if (CodeGenOpts.CFProtectionReturn) + if (CodeGenOpts.CFProtectionReturn && + getContext().getTargetInfo().getTriple().isRISCV()) Fn->addFnAttr("hw-shadow-stack"); // Apply xray attributes to the function (as a string, for now) _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits