summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdrian Prantl <aprantl@apple.com>2016-09-20 18:28:42 +0000
committerAdrian Prantl <aprantl@apple.com>2016-09-20 18:28:42 +0000
commit12fa3b391100edc02ca49444a8d7cd13805c8815 (patch)
tree0100c538312c6444d0fc06a2eba186dee9998661
parent9800539f19a05d7f2093d8fe40605151a87d0d15 (diff)
downloadbcm5719-llvm-12fa3b391100edc02ca49444a8d7cd13805c8815.tar.gz
bcm5719-llvm-12fa3b391100edc02ca49444a8d7cd13805c8815.zip
ASAN: Don't drop debug info attachements for global variables.
This is a follow-up to r281284. Global Variables now can have !dbg attachements, so ASAN should clone these when generating a sanitized copy of a global variable. <rdar://problem/24899262> llvm-svn: 281994
-rw-r--r--llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp7
-rw-r--r--llvm/test/Instrumentation/AddressSanitizer/debug-info-global-var.ll28
2 files changed, 35 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
index b601d391f24..c5bcb39992f 100644
--- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -1534,6 +1534,13 @@ bool AddressSanitizerModule::InstrumentGlobals(IRBuilder<> &IRB, Module &M) {
NewGlobal->copyAttributesFrom(G);
NewGlobal->setAlignment(MinRZ);
+ // Transfer the debug info. The payload starts at offset zero so we can
+ // copy the debug info over as is.
+ SmallVector<DIGlobalVariable *, 1> GVs;
+ G->getDebugInfo(GVs);
+ for (auto *GV : GVs)
+ NewGlobal->addDebugInfo(GV);
+
Value *Indices2[2];
Indices2[0] = IRB.getInt32(0);
Indices2[1] = IRB.getInt32(0);
diff --git a/llvm/test/Instrumentation/AddressSanitizer/debug-info-global-var.ll b/llvm/test/Instrumentation/AddressSanitizer/debug-info-global-var.ll
new file mode 100644
index 00000000000..2848538f328
--- /dev/null
+++ b/llvm/test/Instrumentation/AddressSanitizer/debug-info-global-var.ll
@@ -0,0 +1,28 @@
+; RUN: opt < %s -asan -asan-module -S | FileCheck %s
+source_filename = "version.c"
+target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-apple-macosx10.12.0"
+
+; CHECK: @version = constant { [5 x i8], [59 x i8] } {{.*}}, !dbg ![[GV:.*]]
+@version = constant [5 x i8] c"4.00\00", align 1, !dbg !0
+
+!llvm.dbg.cu = !{!1}
+!llvm.module.flags = !{!10, !11, !12}
+!llvm.ident = !{!13}
+
+; CHECK: ![[GV]] = distinct !DIGlobalVariable(name: "version"
+; CHECK-NOT: expr:
+!0 = distinct !DIGlobalVariable(name: "version", scope: !1, file: !2, line: 2, type: !5, isLocal: false, isDefinition: true)
+!1 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2, producer: "clang version 4.0.0 (trunk 281923) (llvm/trunk 281916)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !3, globals: !4)
+!2 = !DIFile(filename: "version.c", directory: "/Volumes/Fusion/Data/radar/24899262")
+!3 = !{}
+!4 = !{!0}
+!5 = !DICompositeType(tag: DW_TAG_array_type, baseType: !6, size: 40, align: 8, elements: !8)
+!6 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !7)
+!7 = !DIBasicType(name: "char", size: 8, align: 8, encoding: DW_ATE_signed_char)
+!8 = !{!9}
+!9 = !DISubrange(count: 5)
+!10 = !{i32 2, !"Dwarf Version", i32 4}
+!11 = !{i32 2, !"Debug Info Version", i32 3}
+!12 = !{i32 1, !"PIC Level", i32 2}
+!13 = !{!"clang version 4.0.0 (trunk 281923) (llvm/trunk 281916)"}
OpenPOWER on IntegriCloud