Alexey Samsonov | b7dd329 | 2014-07-09 19:40:08 +0000 | [diff] [blame] | 1 | //===--- SanitizerBlacklist.cpp - Blacklist for sanitizers ----------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // User-provided blacklist used to disable/alter instrumentation done in |
| 11 | // sanitizers. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
Alexey Samsonov | 8d043e8 | 2014-10-15 19:57:45 +0000 | [diff] [blame] | 14 | #include "clang/Basic/SanitizerBlacklist.h" |
Alexey Samsonov | b7dd329 | 2014-07-09 19:40:08 +0000 | [diff] [blame] | 15 | #include "llvm/IR/Function.h" |
| 16 | #include "llvm/IR/GlobalValue.h" |
| 17 | #include "llvm/IR/Module.h" |
| 18 | |
| 19 | using namespace clang; |
Alexey Samsonov | b7dd329 | 2014-07-09 19:40:08 +0000 | [diff] [blame] | 20 | |
| 21 | static StringRef GetGlobalTypeString(const llvm::GlobalValue &G) { |
| 22 | // Types of GlobalVariables are always pointer types. |
| 23 | llvm::Type *GType = G.getType()->getElementType(); |
| 24 | // For now we support blacklisting struct types only. |
| 25 | if (llvm::StructType *SGType = dyn_cast<llvm::StructType>(GType)) { |
| 26 | if (!SGType->isLiteral()) |
| 27 | return SGType->getName(); |
| 28 | } |
| 29 | return "<unknown type>"; |
| 30 | } |
| 31 | |
Alexey Samsonov | 0b15e34 | 2014-10-15 22:17:27 +0000 | [diff] [blame] | 32 | SanitizerBlacklist::SanitizerBlacklist(const std::string &BlacklistPath) |
| 33 | : SCL(llvm::SpecialCaseList::createOrDie(BlacklistPath)) {} |
| 34 | |
Alexey Samsonov | b7dd329 | 2014-07-09 19:40:08 +0000 | [diff] [blame] | 35 | bool SanitizerBlacklist::isIn(const llvm::Function &F) const { |
Alexey Samsonov | 74246aa | 2014-10-16 17:10:38 +0000 | [diff] [blame] | 36 | return isBlacklistedFile(F.getParent()->getModuleIdentifier()) || |
| 37 | isBlacklistedFunction(F.getName()); |
Alexey Samsonov | b7dd329 | 2014-07-09 19:40:08 +0000 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | bool SanitizerBlacklist::isIn(const llvm::GlobalVariable &G, |
Craig Topper | bf3e327 | 2014-08-30 16:55:52 +0000 | [diff] [blame] | 41 | StringRef Category) const { |
Alexey Samsonov | 74246aa | 2014-10-16 17:10:38 +0000 | [diff] [blame] | 42 | return isBlacklistedFile(G.getParent()->getModuleIdentifier(), Category) || |
Alexey Samsonov | b7dd329 | 2014-07-09 19:40:08 +0000 | [diff] [blame] | 43 | SCL->inSection("global", G.getName(), Category) || |
| 44 | SCL->inSection("type", GetGlobalTypeString(G), Category); |
| 45 | } |
Alexey Samsonov | 8485601 | 2014-07-10 22:34:19 +0000 | [diff] [blame] | 46 | |
Kostya Serebryany | 293dc9b | 2014-10-16 20:54:52 +0000 | [diff] [blame^] | 47 | bool SanitizerBlacklist::isBlacklistedType(StringRef MangledTypeName, |
| 48 | StringRef Category) const { |
| 49 | return SCL->inSection("type", MangledTypeName, Category); |
Alexey Samsonov | 8485601 | 2014-07-10 22:34:19 +0000 | [diff] [blame] | 50 | } |
Alexey Samsonov | 74246aa | 2014-10-16 17:10:38 +0000 | [diff] [blame] | 51 | |
| 52 | bool SanitizerBlacklist::isBlacklistedFunction(StringRef FunctionName) const { |
| 53 | return SCL->inSection("fun", FunctionName); |
| 54 | } |
| 55 | |
| 56 | bool SanitizerBlacklist::isBlacklistedFile(StringRef FileName, |
| 57 | StringRef Category) const { |
| 58 | return SCL->inSection("src", FileName, Category); |
| 59 | } |