blob: 84ec2100b6279ffd35472abb44943ac05a34138f [file] [log] [blame]
Alexey Samsonovb7dd3292014-07-09 19:40:08 +00001//===--- 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 Samsonov8d043e82014-10-15 19:57:45 +000014#include "clang/Basic/SanitizerBlacklist.h"
Alexey Samsonovb7dd3292014-07-09 19:40:08 +000015#include "llvm/IR/Function.h"
16#include "llvm/IR/GlobalValue.h"
17#include "llvm/IR/Module.h"
18
19using namespace clang;
Alexey Samsonovb7dd3292014-07-09 19:40:08 +000020
21static 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 Samsonov0b15e342014-10-15 22:17:27 +000032SanitizerBlacklist::SanitizerBlacklist(const std::string &BlacklistPath)
33 : SCL(llvm::SpecialCaseList::createOrDie(BlacklistPath)) {}
34
Alexey Samsonovb7dd3292014-07-09 19:40:08 +000035bool SanitizerBlacklist::isIn(const llvm::Function &F) const {
Alexey Samsonov74246aa2014-10-16 17:10:38 +000036 return isBlacklistedFile(F.getParent()->getModuleIdentifier()) ||
37 isBlacklistedFunction(F.getName());
Alexey Samsonovb7dd3292014-07-09 19:40:08 +000038}
39
40bool SanitizerBlacklist::isIn(const llvm::GlobalVariable &G,
Craig Topperbf3e3272014-08-30 16:55:52 +000041 StringRef Category) const {
Alexey Samsonov74246aa2014-10-16 17:10:38 +000042 return isBlacklistedFile(G.getParent()->getModuleIdentifier(), Category) ||
Alexey Samsonovb7dd3292014-07-09 19:40:08 +000043 SCL->inSection("global", G.getName(), Category) ||
44 SCL->inSection("type", GetGlobalTypeString(G), Category);
45}
Alexey Samsonov84856012014-07-10 22:34:19 +000046
Kostya Serebryany293dc9b2014-10-16 20:54:52 +000047bool SanitizerBlacklist::isBlacklistedType(StringRef MangledTypeName,
48 StringRef Category) const {
49 return SCL->inSection("type", MangledTypeName, Category);
Alexey Samsonov84856012014-07-10 22:34:19 +000050}
Alexey Samsonov74246aa2014-10-16 17:10:38 +000051
52bool SanitizerBlacklist::isBlacklistedFunction(StringRef FunctionName) const {
53 return SCL->inSection("fun", FunctionName);
54}
55
56bool SanitizerBlacklist::isBlacklistedFile(StringRef FileName,
57 StringRef Category) const {
58 return SCL->inSection("src", FileName, Category);
59}