aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CodeGenModule.cpp
diff options
context:
space:
mode:
authorMing-Yi Lai <ming-yi.lai@mediatek.com>2024-09-26 18:30:43 +0800
committerGitHub <noreply@github.com>2024-09-26 18:30:43 +0800
commit9f33eb861a3d17fd92163ee894f7cd9f256d03fb (patch)
treee81f0cec7a13842d45bc8de1413f3e51398dc55d /clang/lib/CodeGen/CodeGenModule.cpp
parent497523b695d06c8bf9f3aaf5a5cb4414a5b0625b (diff)
downloadllvm-9f33eb861a3d17fd92163ee894f7cd9f256d03fb.zip
llvm-9f33eb861a3d17fd92163ee894f7cd9f256d03fb.tar.gz
llvm-9f33eb861a3d17fd92163ee894f7cd9f256d03fb.tar.bz2
[clang][RISCV] Introduce command line options for RISC-V Zicfilp CFI
This patch enables the following command line flags for RISC-V targets: + `-fcf-protection=branch` turns on forward-edge control-flow integrity conditioning + `-mcf-branch-label-scheme=unlabeled|func-sig` selects the label scheme used in the forward-edge CFI conditioning
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r--clang/lib/CodeGen/CodeGenModule.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index d53d479..2381fa9 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1164,6 +1164,16 @@ void CodeGenModule::Release() {
// Indicate that we want to instrument branch control flow protection.
getModule().addModuleFlag(llvm::Module::Min, "cf-protection-branch",
1);
+
+ auto Scheme = CodeGenOpts.getCFBranchLabelScheme();
+ if (Target.checkCFBranchLabelSchemeSupported(Scheme, getDiags())) {
+ if (Scheme == CFBranchLabelSchemeKind::Default)
+ Scheme = Target.getDefaultCFBranchLabelScheme();
+ getModule().addModuleFlag(
+ llvm::Module::Error, "cf-branch-label-scheme",
+ llvm::MDString::get(getLLVMContext(),
+ getCFBranchLabelSchemeFlagVal(Scheme)));
+ }
}
if (CodeGenOpts.FunctionReturnThunks)