2013-07-09 22:03:17 +00:00
|
|
|
//===-- SpecialCaseList.h - special case list for sanitizers ----*- C++ -*-===//
|
2012-03-14 23:22:10 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This is a utility class for instrumentation passes (like AddressSanitizer
|
2012-08-24 16:40:11 +00:00
|
|
|
// or ThreadSanitizer) to avoid instrumenting some functions or global
|
2013-07-09 22:03:17 +00:00
|
|
|
// variables based on a user-supplied list.
|
2012-08-24 16:40:11 +00:00
|
|
|
//
|
2013-07-09 22:03:17 +00:00
|
|
|
// The list can also specify categories for specific globals, which can be used
|
|
|
|
// to instruct an instrumentation pass to treat certain functions or global
|
|
|
|
// variables in a specific way, such as by omitting certain aspects of
|
|
|
|
// instrumentation while keeping others, or informing the instrumentation pass
|
|
|
|
// that a specific uninstrumentable function has certain semantics, thus
|
|
|
|
// allowing the pass to instrument callers according to those semantics.
|
|
|
|
//
|
|
|
|
// For example, AddressSanitizer uses the "init" category for globals whose
|
|
|
|
// initializers should not be instrumented, but which in all other respects
|
|
|
|
// should be instrumented.
|
|
|
|
//
|
|
|
|
// Each line contains a prefix, followed by a colon and a wild card expression,
|
|
|
|
// followed optionally by an equals sign and an instrumentation-specific
|
|
|
|
// category. Empty lines and lines starting with "#" are ignored.
|
2012-08-24 16:40:11 +00:00
|
|
|
// ---
|
2012-10-19 15:24:46 +00:00
|
|
|
// # Blacklisted items:
|
2012-08-24 16:40:11 +00:00
|
|
|
// fun:*_ZN4base6subtle*
|
2012-09-05 07:29:56 +00:00
|
|
|
// global:*global_with_bad_access_or_initialization*
|
2013-07-09 22:03:17 +00:00
|
|
|
// global:*global_with_initialization_issues*=init
|
|
|
|
// type:*Namespace::ClassName*=init
|
2012-08-24 16:40:11 +00:00
|
|
|
// src:file_with_tricky_code.cc
|
2013-07-09 22:03:17 +00:00
|
|
|
// src:ignore-global-initializers-issues.cc=init
|
|
|
|
//
|
|
|
|
// # Functions with pure functional semantics:
|
|
|
|
// fun:cos=functional
|
|
|
|
// fun:sin=functional
|
2012-08-24 16:40:11 +00:00
|
|
|
// ---
|
|
|
|
// Note that the wild card is in fact an llvm::Regex, but * is automatically
|
|
|
|
// replaced with .*
|
|
|
|
// This is similar to the "ignore" feature of ThreadSanitizer.
|
|
|
|
// http://code.google.com/p/data-race-test/wiki/ThreadSanitizerIgnores
|
2012-03-14 23:22:10 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
|
2012-08-24 16:40:11 +00:00
|
|
|
#include "llvm/ADT/StringMap.h"
|
2012-03-14 23:22:10 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
class Function;
|
2012-08-24 16:40:11 +00:00
|
|
|
class GlobalVariable;
|
2013-07-09 22:03:09 +00:00
|
|
|
class MemoryBuffer;
|
2012-08-24 16:40:11 +00:00
|
|
|
class Module;
|
2012-03-14 23:22:10 +00:00
|
|
|
class Regex;
|
2012-08-24 16:40:11 +00:00
|
|
|
class StringRef;
|
2012-03-14 23:22:10 +00:00
|
|
|
|
2013-07-09 22:02:49 +00:00
|
|
|
class SpecialCaseList {
|
2012-03-14 23:22:10 +00:00
|
|
|
public:
|
2013-07-09 22:02:49 +00:00
|
|
|
SpecialCaseList(const StringRef Path);
|
2013-07-09 22:03:09 +00:00
|
|
|
SpecialCaseList(const MemoryBuffer *MB);
|
2013-07-09 22:03:17 +00:00
|
|
|
~SpecialCaseList();
|
|
|
|
|
|
|
|
/// Returns whether either this function or its source file are listed in the
|
|
|
|
/// given category, which may be omitted to search the empty category.
|
|
|
|
bool isIn(const Function &F, const StringRef Category = StringRef()) const;
|
|
|
|
|
|
|
|
/// Returns whether this global, its type or its source file are listed in the
|
|
|
|
/// given category, which may be omitted to search the empty category.
|
|
|
|
bool isIn(const GlobalVariable &G,
|
|
|
|
const StringRef Category = StringRef()) const;
|
|
|
|
|
|
|
|
/// Returns whether this module is listed in the given category, which may be
|
|
|
|
/// omitted to search the empty category.
|
|
|
|
bool isIn(const Module &M, const StringRef Category = StringRef()) const;
|
|
|
|
|
|
|
|
/// Returns whether either this function or its source file are listed in any
|
|
|
|
/// category. Category will contain the name of an arbitrary category in
|
|
|
|
/// which this function is listed.
|
|
|
|
bool findCategory(const Function &F, StringRef &Category) const;
|
|
|
|
|
|
|
|
/// Returns whether this global, its type or its source file are listed in any
|
|
|
|
/// category. Category will contain the name of an arbitrary category in
|
|
|
|
/// which this global is listed.
|
|
|
|
bool findCategory(const GlobalVariable &G, StringRef &Category) const;
|
|
|
|
|
|
|
|
/// Returns whether this module is listed in any category. Category will
|
|
|
|
/// contain the name of an arbitrary category in which this module is listed.
|
|
|
|
bool findCategory(const Module &M, StringRef &Category) const;
|
2013-07-09 22:03:09 +00:00
|
|
|
|
2012-03-14 23:22:10 +00:00
|
|
|
private:
|
2013-08-05 17:48:04 +00:00
|
|
|
struct Entry;
|
|
|
|
StringMap<StringMap<Entry> > Entries;
|
2012-08-24 16:40:11 +00:00
|
|
|
|
2013-07-09 22:03:09 +00:00
|
|
|
void init(const MemoryBuffer *MB);
|
2013-07-09 22:03:17 +00:00
|
|
|
bool findCategory(const StringRef Section, const StringRef Query,
|
|
|
|
StringRef &Category) const;
|
|
|
|
bool inSectionCategory(const StringRef Section, const StringRef Query,
|
|
|
|
const StringRef Category) const;
|
2012-03-14 23:22:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace llvm
|