diff options
author | Alexey Samsonov <vonosmas@gmail.com> | 2014-10-17 22:37:33 +0000 |
---|---|---|
committer | Alexey Samsonov <vonosmas@gmail.com> | 2014-10-17 22:37:33 +0000 |
commit | 87d48052c99c5988278f275ba94d2eb50f6f0a2a (patch) | |
tree | de203f18637fab479b28d40db4153d123ea5b228 /lib/Basic/SanitizerBlacklist.cpp | |
parent | a4de584195b308145f7ad189b5dd0303de5fb4f7 (diff) |
[ASan] Improve blacklisting of global variables.
This commit changes the way we blacklist global variables in ASan.
Now the global is excluded from instrumentation (either regular
bounds checking, or initialization-order checking) if:
1) Global is explicitly blacklisted by its mangled name.
This part is left unchanged.
2) SourceLocation of a global is in blacklisted source file.
This changes the old behavior, where instead of looking at the
SourceLocation of a variable we simply considered llvm::Module
identifier. This was wrong, as identifier may not correspond to
the file name, and we incorrectly disabled instrumentation
for globals coming from #include'd files.
3) Global is blacklisted by type.
Now we build the type of a global variable using Clang machinery
(QualType::getAsString()), instead of llvm::StructType::getName().
After this commit, the active users of ASan blacklist files
may have to revisit them (this is a backwards-incompatible change).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@220097 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Basic/SanitizerBlacklist.cpp')
-rw-r--r-- | lib/Basic/SanitizerBlacklist.cpp | 21 |
1 files changed, 3 insertions, 18 deletions
diff --git a/lib/Basic/SanitizerBlacklist.cpp b/lib/Basic/SanitizerBlacklist.cpp index 2f4bdb5113..9b2cdfd4f5 100644 --- a/lib/Basic/SanitizerBlacklist.cpp +++ b/lib/Basic/SanitizerBlacklist.cpp @@ -12,31 +12,16 @@ // //===----------------------------------------------------------------------===// #include "clang/Basic/SanitizerBlacklist.h" -#include "llvm/IR/GlobalValue.h" -#include "llvm/IR/Module.h" using namespace clang; -static StringRef GetGlobalTypeString(const llvm::GlobalValue &G) { - // Types of GlobalVariables are always pointer types. - llvm::Type *GType = G.getType()->getElementType(); - // For now we support blacklisting struct types only. - if (llvm::StructType *SGType = dyn_cast<llvm::StructType>(GType)) { - if (!SGType->isLiteral()) - return SGType->getName(); - } - return "<unknown type>"; -} - SanitizerBlacklist::SanitizerBlacklist(StringRef BlacklistPath, SourceManager &SM) : SCL(llvm::SpecialCaseList::createOrDie(BlacklistPath)), SM(SM) {} -bool SanitizerBlacklist::isIn(const llvm::GlobalVariable &G, - StringRef Category) const { - return isBlacklistedFile(G.getParent()->getModuleIdentifier(), Category) || - SCL->inSection("global", G.getName(), Category) || - SCL->inSection("type", GetGlobalTypeString(G), Category); +bool SanitizerBlacklist::isBlacklistedGlobal(StringRef GlobalName, + StringRef Category) const { + return SCL->inSection("global", GlobalName, Category); } bool SanitizerBlacklist::isBlacklistedType(StringRef MangledTypeName, |