summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen/CodeGenModule.cpp
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2012-08-21 06:53:28 +0000
committerKostya Serebryany <kcc@google.com>2012-08-21 06:53:28 +0000
commit28a26c8d996aa82a80e8586720af789d3afa8739 (patch)
treea29c3b45b0b2e3e6d9fde40fe5b65b59d7688dd1 /clang/lib/CodeGen/CodeGenModule.cpp
parent6b745b5281f56f9ab01aad26fd6e883606d618d7 (diff)
downloadbcm5719-llvm-28a26c8d996aa82a80e8586720af789d3afa8739.tar.gz
bcm5719-llvm-28a26c8d996aa82a80e8586720af789d3afa8739.zip
[asan] If we are compiling with ASan, add metadata indicating dynamically initialized globals. Patch by Reid Watson, reviewed by Richard Smith
llvm-svn: 162259
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r--clang/lib/CodeGen/CodeGenModule.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 3ae3c521300..840a18ead42 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/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)
OpenPOWER on IntegriCloud