]> granicus.if.org Git - clang/commitdiff
[asan] If we are compiling with ASan, add metadata indicating dynamically initialized...
authorKostya Serebryany <kcc@google.com>
Tue, 21 Aug 2012 06:53:28 +0000 (06:53 +0000)
committerKostya Serebryany <kcc@google.com>
Tue, 21 Aug 2012 06:53:28 +0000 (06:53 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162259 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CodeGenModule.cpp

index 3ae3c521300bc38b663344306b8485d1eb46e556..840a18ead42b8b93aca49f18fce6a84b53c64d7c 100644 (file)
@@ -1682,6 +1682,18 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D) {
   if (NeedsGlobalCtor || NeedsGlobalDtor)
     EmitCXXGlobalVarDeclInitFunc(D, GV, NeedsGlobalCtor);
 
+  // If we are compiling with ASan, add metadata indicating dynamically
+  // initialized globals.
+  if (LangOpts.AddressSanitizer && NeedsGlobalCtor) {
+    llvm::Module &M = getModule();
+
+    llvm::NamedMDNode *DynamicInitializers =
+        M.getOrInsertNamedMetadata("llvm.asan.dynamically_initialized_globals");
+    llvm::Value *GlobalToAdd[] = { GV };
+    llvm::MDNode *ThisGlobal = llvm::MDNode::get(VMContext, GlobalToAdd);
+    DynamicInitializers->addOperand(ThisGlobal);
+  }
+
   // Emit global variable debug information.
   if (CGDebugInfo *DI = getModuleDebugInfo())
     if (getCodeGenOpts().DebugInfo >= CodeGenOptions::LimitedDebugInfo)