Skip to content

Commit fe4a28f

Browse files
committed
[Clang][RISCV] Support -fcf-protection=return for RISC-V
1 parent 4db57ab commit fe4a28f

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

clang/lib/Basic/Targets/RISCV.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,13 @@ class RISCVTargetInfo : public TargetInfo {
141141
return true;
142142
}
143143

144+
bool
145+
checkCFProtectionReturnSupported(DiagnosticsEngine &Diags) const override {
146+
if (ISAInfo->hasExtension("zimop"))
147+
return true;
148+
return TargetInfo::checkCFProtectionReturnSupported(Diags);
149+
}
150+
144151
CFBranchLabelSchemeKind getDefaultCFBranchLabelScheme() const override {
145152
return CFBranchLabelSchemeKind::FuncSig;
146153
}

clang/lib/CodeGen/CodeGenFunction.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,10 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy,
899899
if (CodeGenOpts.PointerAuth.IndirectGotos)
900900
Fn->addFnAttr("ptrauth-indirect-gotos");
901901

902+
// Add return control flow integrity attributes.
903+
if (CodeGenOpts.CFProtectionReturn)
904+
Fn->addFnAttr("hw-shadow-stack");
905+
902906
// Apply xray attributes to the function (as a string, for now)
903907
bool AlwaysXRayAttr = false;
904908
if (const auto *XRayAttr = D ? D->getAttr<XRayInstrumentAttr>() : nullptr) {

0 commit comments

Comments
 (0)