aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen
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
commit05c5ebc9bafe5613204eefb59a47ab878e4fbd0b (patch)
treeedcc230abd438d50800532845cfbf0ebb260d191 /lib/CodeGen
parent88d2f678e70ab9360f09f3534d9223e6ec20f129 (diff)
[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
Diffstat (limited to 'lib/CodeGen')
-rw-r--r--lib/CodeGen/CodeGenModule.cpp12
1 files changed, 12 insertions, 0 deletions
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)