summaryrefslogtreecommitdiffstats
path: root/llvm/test/Instrumentation
diff options
context:
space:
mode:
authorRyan Govostes <rzg@apple.com>2016-03-28 20:28:57 +0000
committerRyan Govostes <rzg@apple.com>2016-03-28 20:28:57 +0000
commit653f9d0273cf44e54d4c110b1cf19ef6cfab47ba (patch)
treefe646a488c1e04d428eea1c449701cc72506c487 /llvm/test/Instrumentation
parentdc91fe5d8b7777942d46d5d8152a586932f13291 (diff)
downloadbcm5719-llvm-653f9d0273cf44e54d4c110b1cf19ef6cfab47ba.tar.gz
bcm5719-llvm-653f9d0273cf44e54d4c110b1cf19ef6cfab47ba.zip
[asan] Support dead code stripping on Mach-O platforms
On OS X El Capitan and iOS 9, the linker supports a new section attribute, live_support, which allows dead stripping to remove dead globals along with the ASAN metadata about them. With this change __asan_global structures are emitted in a new __DATA,__asan_globals section on Darwin. Additionally, there is a __DATA,__asan_liveness section with the live_support attribute. Each entry in this section is simply a tuple that binds together the liveness of a global variable and its ASAN metadata structure. Thus the metadata structure will be alive if and only if the global it references is also alive. Review: http://reviews.llvm.org/D16737 llvm-svn: 264645
Diffstat (limited to 'llvm/test/Instrumentation')
-rw-r--r--llvm/test/Instrumentation/AddressSanitizer/global_metadata.ll2
-rw-r--r--llvm/test/Instrumentation/AddressSanitizer/global_metadata_darwin.ll37
2 files changed, 38 insertions, 1 deletions
diff --git a/llvm/test/Instrumentation/AddressSanitizer/global_metadata.ll b/llvm/test/Instrumentation/AddressSanitizer/global_metadata.ll
index 6cf1ee8e8d4..c189603381a 100644
--- a/llvm/test/Instrumentation/AddressSanitizer/global_metadata.ll
+++ b/llvm/test/Instrumentation/AddressSanitizer/global_metadata.ll
@@ -20,7 +20,7 @@ target triple = "x86_64-unknown-linux-gnu"
; CHECK: [[FILENAME:@__asan_gen_.[0-9]+]] = private unnamed_addr constant [22 x i8] c"/tmp/asan-globals.cpp\00", align 1
; CHECK: [[LOCDESCR:@__asan_gen_.[0-9]+]] = private unnamed_addr constant { [22 x i8]*, i32, i32 } { [22 x i8]* [[FILENAME]], i32 5, i32 5 }
-; Check that location decriptors and global names were passed into __asan_register_globals:
+; Check that location descriptors and global names were passed into __asan_register_globals:
; CHECK: i64 ptrtoint ([7 x i8]* [[VARNAME]] to i64)
; CHECK: i64 ptrtoint ({ [22 x i8]*, i32, i32 }* [[LOCDESCR]] to i64)
diff --git a/llvm/test/Instrumentation/AddressSanitizer/global_metadata_darwin.ll b/llvm/test/Instrumentation/AddressSanitizer/global_metadata_darwin.ll
new file mode 100644
index 00000000000..2fcbe7851bf
--- /dev/null
+++ b/llvm/test/Instrumentation/AddressSanitizer/global_metadata_darwin.ll
@@ -0,0 +1,37 @@
+; Test that global metadata is placed in a separate section on Mach-O platforms,
+; allowing dead stripping to be performed, and that the appropriate runtime
+; routines are invoked.
+
+; RUN: opt < %s -asan -asan-module -S | FileCheck %s
+
+target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-apple-macosx10.11.0"
+
+@global = global [1 x i32] zeroinitializer, align 4
+
+!llvm.asan.globals = !{!0}
+
+!0 = !{[1 x i32]* @global, !1, !"global", i1 false, i1 false}
+!1 = !{!"test-globals.c", i32 1, i32 5}
+
+
+; Test that there is a Needle global variable:
+; CHECK: @__asan_needle = internal global i64 0
+
+; Find the metadata for @global:
+; CHECK: [[METADATA:@[0-9]+]] = internal global {{.*}} @global {{.*}} section "__DATA,__asan_globals,regular", align 1
+
+; Find the liveness binder for @global and its metadata:
+; CHECK: @{{[0-9]+}} = internal global {{.*}} @global {{.*}} [[METADATA]] {{.*}} section "__DATA,__asan_liveness,regular,live_support"
+
+; Test that __asan_apply_to_globals is invoked from the constructor:
+; CHECK-LABEL: define internal void @asan.module_ctor
+; CHECK-NOT: ret
+; CHECK: call void @__asan_apply_to_globals(i64 ptrtoint (void (i64, i64)* @__asan_register_globals to i64), i64 ptrtoint (i64* @__asan_needle to i64))
+; CHECK: ret
+
+; Test that __asan_apply_to_globals is invoked from the destructor:
+; CHECK-LABEL: define internal void @asan.module_dtor
+; CHECK-NOT: ret
+; CHECK: call void @__asan_apply_to_globals(i64 ptrtoint (void (i64, i64)* @__asan_unregister_globals to i64), i64 ptrtoint (i64* @__asan_needle to i64))
+; CHECK: ret
OpenPOWER on IntegriCloud