Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions clang/lib/Basic/Targets/RISCV.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
5 changes: 5 additions & 0 deletions clang/lib/CodeGen/CodeGenFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,11 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy,
if (CodeGenOpts.PointerAuth.IndirectGotos)
Fn->addFnAttr("ptrauth-indirect-gotos");

// Add return control flow integrity attributes for RISCV.
if (CodeGenOpts.CFProtectionReturn &&
getContext().getTargetInfo().getTriple().isRISCV())
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
Loading