From: Kostya Serebryany Date: Tue, 21 Aug 2012 06:53:28 +0000 (+0000) Subject: [asan] If we are compiling with ASan, add metadata indicating dynamically initialized... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=05c5ebc9bafe5613204eefb59a47ab878e4fbd0b;p=clang [asan] If we are compiling with ASan, add metadata indicating dynamically initialized globals. Patch by Reid Watson, reviewed by Richard Smith git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162259 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 3ae3c52130..840a18ead4 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -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)