[llvm-commits] [PATCH] Refactor ASan passes options and add blacklist file to them
Alexey Samsonov
samsonov at google.com
Fri Nov 30 22:58:03 PST 2012
Hi kcc,
This patch allows ASan pass to take blacklist file
from frontend (see also review D152).
http://llvm-reviews.chandlerc.com/D153
Files:
include/llvm/Transforms/Instrumentation.h
lib/Transforms/Instrumentation/AddressSanitizer.cpp
Index: include/llvm/Transforms/Instrumentation.h
===================================================================
--- include/llvm/Transforms/Instrumentation.h
+++ include/llvm/Transforms/Instrumentation.h
@@ -14,6 +14,8 @@
#ifndef LLVM_TRANSFORMS_INSTRUMENTATION_H
#define LLVM_TRANSFORMS_INSTRUMENTATION_H
+#include "llvm/ADT/StringRef.h"
+
namespace llvm {
class ModulePass;
@@ -33,11 +35,26 @@
bool Use402Format = false,
bool UseExtraChecksum = false);
+struct AddressSanitizerOptions {
+ const bool CheckInitOrder;
+ const bool CheckUseAfterReturn;
+ const bool CheckLifetime;
+ const StringRef BlacklistFile;
+ AddressSanitizerOptions(bool CheckInitOrder = false,
+ bool CheckUseAfterReturn = false,
+ bool CheckLifetime = false,
+ StringRef BlacklistFile = StringRef())
+ : CheckInitOrder(CheckInitOrder),
+ CheckUseAfterReturn(CheckUseAfterReturn),
+ CheckLifetime(CheckLifetime),
+ BlacklistFile(BlacklistFile) {}
+};
+
// Insert AddressSanitizer (address sanity checking) instrumentation
FunctionPass *createAddressSanitizerFunctionPass(
- bool CheckInitOrder = false, bool CheckUseAfterReturn = false,
- bool CheckLifetime = false);
-ModulePass *createAddressSanitizerModulePass(bool CheckInitOrder = false);
+ const AddressSanitizerOptions &Options = AddressSanitizerOptions());
+ModulePass *createAddressSanitizerModulePass(
+ const AddressSanitizerOptions &Options = AddressSanitizerOptions());
// Insert MemorySanitizer instrumentation (detection of uninitialized reads)
FunctionPass *createMemorySanitizerPass();
// Insert ThreadSanitizer (race detection) instrumentation
Index: lib/Transforms/Instrumentation/AddressSanitizer.cpp
===================================================================
--- lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -113,9 +113,8 @@
cl::desc("Handle C++ initializer order"), cl::Hidden, cl::init(false));
static cl::opt<bool> ClMemIntrin("asan-memintrin",
cl::desc("Handle memset/memcpy/memmove"), cl::Hidden, cl::init(true));
-// This flag may need to be replaced with -fasan-blacklist.
-static cl::opt<std::string> ClBlackListFile("asan-blacklist",
- cl::desc("File containing the list of functions to ignore "
+static cl::opt<std::string> ClBlackListFile("asan-blacklist",
+ cl::desc("File containing the list of objects to ignore "
"during instrumentation"), cl::Hidden);
// These flags allow to change the shadow mapping.
@@ -178,6 +177,14 @@
SmallSet<GlobalValue*, 32> DynInitGlobals;
};
+static StringRef chooseBlacklist(StringRef BL1, StringRef BL2) {
+ if (BL1.empty()) return BL2;
+ if (BL2.empty()) return BL1;
+ report_fatal_error("ASan expects at most one blacklist file, while two "
+ "were provided: \'" + BL1 + "\' and \'" + BL2 + "\'");
+ return StringRef();
+}
+
static int MappingScale() {
return ClMappingScale ? ClMappingScale : kDefaultShadowScale;
}
@@ -190,13 +197,13 @@
/// AddressSanitizer: instrument the code in module to find memory bugs.
struct AddressSanitizer : public FunctionPass {
- AddressSanitizer(bool CheckInitOrder = false,
- bool CheckUseAfterReturn = false,
- bool CheckLifetime = false)
+ AddressSanitizer(const AddressSanitizerOptions &Options =
+ AddressSanitizerOptions())
: FunctionPass(ID),
- CheckInitOrder(CheckInitOrder || ClInitializers),
- CheckUseAfterReturn(CheckUseAfterReturn || ClUseAfterReturn),
- CheckLifetime(CheckLifetime || ClCheckLifetime) {}
+ CheckInitOrder(Options.CheckInitOrder || ClInitializers),
+ CheckUseAfterReturn(Options.CheckUseAfterReturn || ClUseAfterReturn),
+ CheckLifetime(Options.CheckLifetime || ClCheckLifetime),
+ BlacklistFile(chooseBlacklist(Options.BlacklistFile, ClBlackListFile)) {}
virtual const char *getPassName() const {
return "AddressSanitizerFunctionPass";
}
@@ -255,6 +262,7 @@
Function *AsanInitFunction;
Function *AsanStackMallocFunc, *AsanStackFreeFunc;
Function *AsanHandleNoReturnFunc;
+ SmallString<64> BlacklistFile;
OwningPtr<BlackList> BL;
// This array is indexed by AccessIsWrite and log2(AccessSize).
Function *AsanErrorCallback[2][kNumberOfAccessSizes];
@@ -264,9 +272,11 @@
class AddressSanitizerModule : public ModulePass {
public:
- AddressSanitizerModule(bool CheckInitOrder = false)
+ AddressSanitizerModule(const AddressSanitizerOptions &Options =
+ AddressSanitizerOptions())
: ModulePass(ID),
- CheckInitOrder(CheckInitOrder || ClInitializers) {}
+ CheckInitOrder(Options.CheckInitOrder || ClInitializers),
+ BlacklistFile(chooseBlacklist(Options.BlacklistFile, ClBlackListFile)) {}
bool runOnModule(Module &M);
static char ID; // Pass identification, replacement for typeid
virtual const char *getPassName() const {
@@ -278,6 +288,7 @@
Value *LastAddr);
bool CheckInitOrder;
+ SmallString<64> BlacklistFile;
OwningPtr<BlackList> BL;
SetOfDynamicallyInitializedGlobals DynamicallyInitializedGlobals;
Type *IntptrTy;
@@ -292,17 +303,17 @@
"AddressSanitizer: detects use-after-free and out-of-bounds bugs.",
false, false)
FunctionPass *llvm::createAddressSanitizerFunctionPass(
- bool CheckInitOrder, bool CheckUseAfterReturn, bool CheckLifetime) {
- return new AddressSanitizer(CheckInitOrder, CheckUseAfterReturn,
- CheckLifetime);
+ const AddressSanitizerOptions &Options) {
+ return new AddressSanitizer(Options);
}
char AddressSanitizerModule::ID = 0;
INITIALIZE_PASS(AddressSanitizerModule, "asan-module",
"AddressSanitizer: detects use-after-free and out-of-bounds bugs."
"ModulePass", false, false)
-ModulePass *llvm::createAddressSanitizerModulePass(bool CheckInitOrder) {
- return new AddressSanitizerModule(CheckInitOrder);
+ModulePass *llvm::createAddressSanitizerModulePass(
+ const AddressSanitizerOptions &Options) {
+ return new AddressSanitizerModule(Options);
}
static size_t TypeSizeToSizeIndex(uint32_t TypeSize) {
@@ -619,7 +630,7 @@
TD = getAnalysisIfAvailable<DataLayout>();
if (!TD)
return false;
- BL.reset(new BlackList(ClBlackListFile));
+ BL.reset(new BlackList(BlacklistFile));
if (BL->isIn(M)) return false;
DynamicallyInitializedGlobals.Init(M);
C = &(M.getContext());
@@ -794,7 +805,7 @@
if (!TD)
return false;
- BL.reset(new BlackList(ClBlackListFile));
+ BL.reset(new BlackList(BlacklistFile));
DynamicallyInitializedGlobals.Init(M);
C = &(M.getContext());
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153.1.patch
Type: text/x-patch
Size: 6898 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20121130/6bb49ab6/attachment.bin>
More information about the llvm-commits
mailing list