[PATCH] D79653: [sanitizer] Enable whitelist/blacklist in new PM
Jinsong Ji via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri May 8 15:36:29 PDT 2020
jsji created this revision.
jsji added reviewers: tuktuk, vitalybuka, morehouse, kcc.
Herald added subscribers: llvm-commits, Sanitizers, cfe-commits, hiraditya.
Herald added projects: clang, Sanitizers, LLVM.
https://reviews.llvm.org/D63616 added `-fsanitize-coverage-whitelist`
and `-fsanitize-coverage-blacklist` for clang.
However, it was done only for legacy pass manager.
This patch enable it for new pass manager as well.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D79653
Files:
clang/lib/CodeGen/BackendUtil.cpp
compiler-rt/test/sanitizer_common/TestCases/sanitizer_coverage_whitelist_blacklist.cpp
llvm/include/llvm/Transforms/Instrumentation/SanitizerCoverage.h
llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
Index: llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
===================================================================
--- llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
+++ llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
@@ -322,7 +322,8 @@
PreservedAnalyses ModuleSanitizerCoveragePass::run(Module &M,
ModuleAnalysisManager &MAM) {
- ModuleSanitizerCoverage ModuleSancov(Options);
+ ModuleSanitizerCoverage ModuleSancov(Options, Whitelist.get(),
+ Blacklist.get());
auto &FAM = MAM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
auto DTCallback = [&FAM](Function &F) -> const DominatorTree * {
return &FAM.getResult<DominatorTreeAnalysis>(F);
Index: llvm/include/llvm/Transforms/Instrumentation/SanitizerCoverage.h
===================================================================
--- llvm/include/llvm/Transforms/Instrumentation/SanitizerCoverage.h
+++ llvm/include/llvm/Transforms/Instrumentation/SanitizerCoverage.h
@@ -18,6 +18,7 @@
#include "llvm/IR/Module.h"
#include "llvm/IR/PassManager.h"
+#include "llvm/Support/SpecialCaseList.h"
#include "llvm/Transforms/Instrumentation.h"
namespace llvm {
@@ -30,12 +31,26 @@
: public PassInfoMixin<ModuleSanitizerCoveragePass> {
public:
explicit ModuleSanitizerCoveragePass(
- SanitizerCoverageOptions Options = SanitizerCoverageOptions())
- : Options(Options) {}
+ SanitizerCoverageOptions Options = SanitizerCoverageOptions(),
+ const std::vector<std::string> &WhitelistFiles =
+ std::vector<std::string>(),
+ const std::vector<std::string> &BlacklistFiles =
+ std::vector<std::string>())
+ : Options(Options) {
+ if (WhitelistFiles.size() > 0)
+ Whitelist = SpecialCaseList::createOrDie(WhitelistFiles,
+ *vfs::getRealFileSystem());
+ if (BlacklistFiles.size() > 0)
+ Blacklist = SpecialCaseList::createOrDie(BlacklistFiles,
+ *vfs::getRealFileSystem());
+ }
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
private:
SanitizerCoverageOptions Options;
+
+ std::unique_ptr<SpecialCaseList> Whitelist;
+ std::unique_ptr<SpecialCaseList> Blacklist;
};
// Insert SanitizerCoverage instrumentation.
Index: compiler-rt/test/sanitizer_common/TestCases/sanitizer_coverage_whitelist_blacklist.cpp
===================================================================
--- compiler-rt/test/sanitizer_common/TestCases/sanitizer_coverage_whitelist_blacklist.cpp
+++ compiler-rt/test/sanitizer_common/TestCases/sanitizer_coverage_whitelist_blacklist.cpp
@@ -51,6 +51,13 @@
// RUN: %clangxx -O0 %s -S -o - -emit-llvm -fsanitize-coverage=inline-8bit-counters,indirect-calls,trace-cmp,pc-table -fsanitize-coverage-whitelist=wl_foo.txt -fsanitize-coverage-blacklist=bl_all.txt 2>&1 | not grep -f patterns.txt
// RUN: %clangxx -O0 %s -S -o - -emit-llvm -fsanitize-coverage=inline-8bit-counters,indirect-calls,trace-cmp,pc-table -fsanitize-coverage-whitelist=wl_bar.txt -fsanitize-coverage-blacklist=bl_all.txt 2>&1 | not grep -f patterns.txt
+// RUN: %clangxx -O0 %s -S -o - -emit-llvm -fsanitize-coverage=inline-8bit-counters,indirect-calls,trace-cmp,pc-table -fexperimental-new-pass-manager -fsanitize-coverage-blacklist=bl_all.txt 2>&1 | not grep -f patterns.txt
+// RUN: %clangxx -O0 %s -S -o - -emit-llvm -fsanitize-coverage=inline-8bit-counters,indirect-calls,trace-cmp,pc-table -fexperimental-new-pass-manager -fsanitize-coverage-whitelist=wl_all.txt -fsanitize-coverage-blacklist=bl_all.txt 2>&1 | not grep -f patterns.txt
+// RUN: %clangxx -O0 %s -S -o - -emit-llvm -fsanitize-coverage=inline-8bit-counters,indirect-calls,trace-cmp,pc-table -fexperimental-new-pass-manager -fsanitize-coverage-whitelist=wl_none.txt -fsanitize-coverage-blacklist=bl_all.txt 2>&1 | not grep -f patterns.txt
+// RUN: %clangxx -O0 %s -S -o - -emit-llvm -fsanitize-coverage=inline-8bit-counters,indirect-calls,trace-cmp,pc-table -fexperimental-new-pass-manager -fsanitize-coverage-whitelist=wl_file.txt -fsanitize-coverage-blacklist=bl_all.txt 2>&1 | not grep -f patterns.txt
+// RUN: %clangxx -O0 %s -S -o - -emit-llvm -fsanitize-coverage=inline-8bit-counters,indirect-calls,trace-cmp,pc-table -fexperimental-new-pass-manager -fsanitize-coverage-whitelist=wl_foo.txt -fsanitize-coverage-blacklist=bl_all.txt 2>&1 | not grep -f patterns.txt
+// RUN: %clangxx -O0 %s -S -o - -emit-llvm -fsanitize-coverage=inline-8bit-counters,indirect-calls,trace-cmp,pc-table -fexperimental-new-pass-manager -fsanitize-coverage-whitelist=wl_bar.txt -fsanitize-coverage-blacklist=bl_all.txt 2>&1 | not grep -f patterns.txt
+
// RUN: %clangxx -O0 %s -S -o - -emit-llvm -fsanitize-coverage=inline-8bit-counters,indirect-calls,trace-cmp,pc-table -fsanitize-coverage-blacklist=bl_none.txt 2>&1 | grep -f patterns.txt | count 14
// RUN: %clangxx -O0 %s -S -o - -emit-llvm -fsanitize-coverage=inline-8bit-counters,indirect-calls,trace-cmp,pc-table -fsanitize-coverage-whitelist=wl_all.txt -fsanitize-coverage-blacklist=bl_none.txt 2>&1 | grep -f patterns.txt | count 14
// RUN: %clangxx -O0 %s -S -o - -emit-llvm -fsanitize-coverage=inline-8bit-counters,indirect-calls,trace-cmp,pc-table -fsanitize-coverage-whitelist=wl_none.txt -fsanitize-coverage-blacklist=bl_none.txt 2>&1 | not grep -f patterns.txt
Index: clang/lib/CodeGen/BackendUtil.cpp
===================================================================
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -1331,7 +1331,9 @@
CodeGenOpts.SanitizeCoverageIndirectCalls ||
CodeGenOpts.SanitizeCoverageTraceCmp) {
auto SancovOpts = getSancovOptsFromCGOpts(CodeGenOpts);
- MPM.addPass(ModuleSanitizerCoveragePass(SancovOpts));
+ MPM.addPass(ModuleSanitizerCoveragePass(
+ SancovOpts, CodeGenOpts.SanitizeCoverageWhitelistFiles,
+ CodeGenOpts.SanitizeCoverageBlacklistFiles));
}
if (LangOpts.Sanitize.has(SanitizerKind::HWAddress)) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79653.262967.patch
Type: text/x-patch
Size: 6258 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200508/8a194983/attachment.bin>
More information about the llvm-commits
mailing list