r209789 - [ASan] Hoist blacklisting globals from init-order checking to Clang.
Alexey Samsonov
vonosmas at gmail.com
Wed May 28 18:43:54 PDT 2014
Author: samsonov
Date: Wed May 28 20:43:53 2014
New Revision: 209789
URL: http://llvm.org/viewvc/llvm-project?rev=209789&view=rev
Log:
[ASan] Hoist blacklisting globals from init-order checking to Clang.
Clang knows about the sanitizer blacklist and it makes no sense to
add global to the list of llvm.asan.dynamically_initialized_globals if it
will be blacklisted in the instrumentation pass anyway. Instead, we should
do as much blacklisting as possible (if not all) in the frontend.
Modified:
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/test/CodeGen/sanitize-init-order.cpp
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=209789&r1=209788&r2=209789&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Wed May 28 20:43:53 2014
@@ -1878,12 +1878,11 @@ void CodeGenModule::EmitGlobalVarDefinit
EmitCXXGlobalVarDeclInitFunc(D, GV, NeedsGlobalCtor);
// If we are compiling with ASan, add metadata indicating dynamically
- // initialized globals.
- if (SanOpts.Address && NeedsGlobalCtor) {
- llvm::Module &M = getModule();
-
- llvm::NamedMDNode *DynamicInitializers =
- M.getOrInsertNamedMetadata("llvm.asan.dynamically_initialized_globals");
+ // initialized (and not blacklisted) globals.
+ if (SanOpts.Address && NeedsGlobalCtor &&
+ !SanitizerBlacklist->isIn(*GV, "init")) {
+ llvm::NamedMDNode *DynamicInitializers = TheModule.getOrInsertNamedMetadata(
+ "llvm.asan.dynamically_initialized_globals");
llvm::Value *GlobalToAdd[] = { GV };
llvm::MDNode *ThisGlobal = llvm::MDNode::get(VMContext, GlobalToAdd);
DynamicInitializers->addOperand(ThisGlobal);
Modified: cfe/trunk/test/CodeGen/sanitize-init-order.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/sanitize-init-order.cpp?rev=209789&r1=209788&r2=209789&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/sanitize-init-order.cpp (original)
+++ cfe/trunk/test/CodeGen/sanitize-init-order.cpp Wed May 28 20:43:53 2014
@@ -1,5 +1,12 @@
// RUN: %clang_cc1 -fsanitize=address,init-order -emit-llvm -o - %s | FileCheck %s
+// Test blacklist functionality.
+// RUN: echo "global-init-src:%s" > %t-file.blacklist
+// RUN: echo "global-init-type:struct.PODWithCtorAndDtor" > %t-type.blacklist
+// RUN: %clang_cc1 -fsanitize=address,init-order -fsanitize-blacklist=%t-file.blacklist -emit-llvm -o - %s | FileCheck %s --check-prefix=BLACKLIST
+// RUN: %clang_cc1 -fsanitize=address,init-order -fsanitize-blacklist=%t-type.blacklist -emit-llvm -o - %s | FileCheck %s --check-prefix=BLACKLIST
+// REQUIRES: shell
+
struct PODStruct {
int x;
};
@@ -22,3 +29,5 @@ PODWithCtorAndDtor s3;
// constructor.
// CHECK: !llvm.asan.dynamically_initialized_globals = !{[[GLOB:![0-9]+]]}
// CHECK: [[GLOB]] = metadata !{%struct.PODWithCtorAndDtor
+
+// BLACKLIST-NOT: llvm.asan.dynamically_initialized_globals
More information about the cfe-commits
mailing list