[asan] make sure that linker-initialized globals (non-extern) are not instrumented...
[oota-llvm.git] / lib / Transforms / Instrumentation / BlackList.cpp
index ef34b8a56d88e0e7485f466328bd93241ffc6d85..e02c631f7f7a1bcf6dd6f524d5fded900fa1ad32 100644 (file)
@@ -20,6 +20,7 @@
 #include "llvm/ADT/OwningPtr.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/DerivedTypes.h"
 #include "llvm/Function.h"
 #include "llvm/GlobalVariable.h"
 #include "llvm/Module.h"
@@ -92,12 +93,25 @@ bool BlackList::isIn(const Module &M) {
   return inSection("src", M.getModuleIdentifier());
 }
 
+static StringRef GetGVTypeString(const GlobalVariable &G) {
+  // Types of GlobalVariables are always pointer types.
+  Type *GType = G.getType()->getElementType();
+  // For now we support blacklisting struct types only.
+  if (StructType *SGType = dyn_cast<StructType>(GType)) {
+    if (!SGType->isLiteral())
+      return SGType->getName();
+  }
+  return "<unknown type>";
+}
+
 bool BlackList::isInInit(const GlobalVariable &G) {
-  return isIn(*G.getParent()) || inSection("global-init", G.getName());
+  return (isIn(*G.getParent()) ||
+          inSection("global-init", G.getName()) ||
+          inSection("global-init-type", GetGVTypeString(G)));
 }
 
 bool BlackList::inSection(const StringRef Section,
-                                  const StringRef Query) {
+                          const StringRef Query) {
   Regex *FunctionRegex = Entries[Section];
   return FunctionRegex ? FunctionRegex->match(Query) : false;
 }