From 2fdb26da619cd09e3ccc8d154e48eb0034474823 Mon Sep 17 00:00:00 2001 From: Ming-Yi Lai Date: Tue, 18 Feb 2025 17:27:20 +0800 Subject: [clang][RISCV] Introduce preprocessor macro when Zicfiss-based shadow stack is enabled (#127592) The `-fcf-protection=[full|return]` flag enables shadow stack implementation based on RISC-V Zicfiss extension. This patch adds the `__riscv_shadow_stack` predefined macro to preprocessing when such a shadow stack implementation is enabled. --- clang/lib/Frontend/CompilerInvocation.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'clang/lib/Frontend/CompilerInvocation.cpp') diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 014e629..b9a5c05 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -4048,8 +4048,13 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args, if (const Arg *A = Args.getLastArg(OPT_fcf_protection_EQ)) { StringRef Name = A->getValue(); - if (Name == "full" || Name == "branch") { + if (Name == "full") { + Opts.CFProtectionBranch = 1; + Opts.CFProtectionReturn = 1; + } else if (Name == "branch") { Opts.CFProtectionBranch = 1; + } else if (Name == "return") { + Opts.CFProtectionReturn = 1; } } -- cgit v1.1