Skip to content

Commit

Permalink
[Clang][RISCV] Support -fcf-protection=return for RISC-V
Browse files Browse the repository at this point in the history
  • Loading branch information
jaidTw committed Oct 16, 2024
1 parent 4db57ab commit 2a7a6ef
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions clang/lib/Basic/Targets/RISCV.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ 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;
}
Expand Down
4 changes: 4 additions & 0 deletions clang/lib/CodeGen/CodeGenFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 2a7a6ef

Please sign in to comment.