Skip to content

Commit

Permalink
[X86] Use Min behavior for cf-protection-{return,branch}/ibt-seal mod…
Browse files Browse the repository at this point in the history
…ule flags

These features require that all object files are compiled with the support. When
the feature is disabled for an object file, the merge behavior should treat the
file having a value of 0 (see D129911).

Reviewed By: xiangzhangllvm

Differential Revision: https://reviews.llvm.org/D130065
  • Loading branch information
MaskRay committed Jul 20, 2022
1 parent e882ac5 commit 23ba688
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions clang/lib/CodeGen/CodeGenModule.cpp
Expand Up @@ -743,19 +743,19 @@ void CodeGenModule::Release() {
if (CodeGenOpts.CFProtectionReturn &&
Target.checkCFProtectionReturnSupported(getDiags())) {
// Indicate that we want to instrument return control flow protection.
getModule().addModuleFlag(llvm::Module::Override, "cf-protection-return",
getModule().addModuleFlag(llvm::Module::Min, "cf-protection-return",
1);
}

if (CodeGenOpts.CFProtectionBranch &&
Target.checkCFProtectionBranchSupported(getDiags())) {
// Indicate that we want to instrument branch control flow protection.
getModule().addModuleFlag(llvm::Module::Override, "cf-protection-branch",
getModule().addModuleFlag(llvm::Module::Min, "cf-protection-branch",
1);
}

if (CodeGenOpts.IBTSeal)
getModule().addModuleFlag(llvm::Module::Override, "ibt-seal", 1);
getModule().addModuleFlag(llvm::Module::Min, "ibt-seal", 1);

if (CodeGenOpts.FunctionReturnThunks)
getModule().addModuleFlag(llvm::Module::Override, "function_return_thunk_extern", 1);
Expand Down
4 changes: 2 additions & 2 deletions clang/test/CodeGen/X86/x86-cf-protection.c
Expand Up @@ -8,7 +8,7 @@
// RETURN: #define __CET__ 2
// BRANCH: #define __CET__ 1
// FULL: #define __CET__ 3
// CFPROT: "cf-protection-branch", i32 1
// IBTSEAL: "ibt-seal", i32 1
// CFPROT: !{i32 8, !"cf-protection-branch", i32 1}
// IBTSEAL: !{i32 8, !"ibt-seal", i32 1}
// NOIBTSEAL-NOT: "ibt-seal", i32 1
void foo() {}

0 comments on commit 23ba688

Please sign in to comment.