diff options
author | Andrew Paverd <andrew.paverd@microsoft.com> | 2020-01-10 11:08:18 +0000 |
---|---|---|
committer | David Chisnall <David.Chisnall@microsoft.com> | 2020-01-10 16:04:12 +0000 |
commit | bdd88b7ed3956534a0a71b1ea2bc88c69d48f9b7 (patch) | |
tree | 4f0a7aeaf0f6eb0a34d373c6c74c93763669d6c4 /llvm/lib/Transforms/CFGuard | |
parent | d864d93496c5fd0cc473953ab825f07e3d4c4e86 (diff) | |
download | bcm5719-llvm-bdd88b7ed3956534a0a71b1ea2bc88c69d48f9b7.tar.gz bcm5719-llvm-bdd88b7ed3956534a0a71b1ea2bc88c69d48f9b7.zip |
Add support for __declspec(guard(nocf))
Summary:
Avoid using the `nocf_check` attribute with Control Flow Guard. Instead, use a
new `"guard_nocf"` function attribute to indicate that checks should not be
added on indirect calls within that function. Add support for
`__declspec(guard(nocf))` following the same syntax as MSVC.
Reviewers: rnk, dmajor, pcc, hans, aaron.ballman
Reviewed By: aaron.ballman
Subscribers: aaron.ballman, tomrittervg, hiraditya, cfe-commits, llvm-commits
Tags: #clang, #llvm
Differential Revision: https://reviews.llvm.org/D72167
Diffstat (limited to 'llvm/lib/Transforms/CFGuard')
-rw-r--r-- | llvm/lib/Transforms/CFGuard/CFGuard.cpp | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/llvm/lib/Transforms/CFGuard/CFGuard.cpp b/llvm/lib/Transforms/CFGuard/CFGuard.cpp index 3eca00691e0..7c5e90cb53c 100644 --- a/llvm/lib/Transforms/CFGuard/CFGuard.cpp +++ b/llvm/lib/Transforms/CFGuard/CFGuard.cpp @@ -254,8 +254,8 @@ bool CFGuard::doInitialization(Module &M) { bool CFGuard::runOnFunction(Function &F) { - // Skip modules and functions for which CFGuard checks have been disabled. - if (cfguard_module_flag != 2 || F.hasFnAttribute(Attribute::NoCfCheck)) + // Skip modules for which CFGuard checks have been disabled. + if (cfguard_module_flag != 2) return false; SmallVector<CallBase *, 8> IndirectCalls; @@ -267,17 +267,15 @@ bool CFGuard::runOnFunction(Function &F) { for (BasicBlock &BB : F.getBasicBlockList()) { for (Instruction &I : BB.getInstList()) { auto *CB = dyn_cast<CallBase>(&I); - if (CB && CB->isIndirectCall()) { + if (CB && CB->isIndirectCall() && !CB->hasFnAttr("guard_nocf")) { IndirectCalls.push_back(CB); CFGuardCounter++; } } } - // If no checks are needed, return early and add this attribute to indicate - // that subsequent CFGuard passes can skip this function. + // If no checks are needed, return early. if (IndirectCalls.empty()) { - F.addFnAttr(Attribute::NoCfCheck); return false; } |