From 316d58822dada9440bd06ecfc758dcc2364d617c Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Mon, 2 Jan 2017 19:18:27 +0000 Subject: Vendor import of compiler-rt trunk r290819: https://llvm.org/svn/llvm-project/compiler-rt/trunk@290819 --- test/asan/TestCases/Darwin/cstring_section.c | 17 +++++++++ test/asan/TestCases/Darwin/dead-strip.c | 22 +++++++++++ test/asan/TestCases/Darwin/dump_registers.cc | 26 +++++++++++++ test/asan/TestCases/Darwin/malloc_destroy_zone.cc | 21 +++++++++++ test/asan/TestCases/Darwin/odr-lto.cc | 45 +++++++++++++++++++++++ 5 files changed, 131 insertions(+) create mode 100644 test/asan/TestCases/Darwin/cstring_section.c create mode 100644 test/asan/TestCases/Darwin/dead-strip.c create mode 100644 test/asan/TestCases/Darwin/dump_registers.cc create mode 100644 test/asan/TestCases/Darwin/malloc_destroy_zone.cc create mode 100644 test/asan/TestCases/Darwin/odr-lto.cc (limited to 'test/asan/TestCases/Darwin') diff --git a/test/asan/TestCases/Darwin/cstring_section.c b/test/asan/TestCases/Darwin/cstring_section.c new file mode 100644 index 000000000000..952d6fcdd465 --- /dev/null +++ b/test/asan/TestCases/Darwin/cstring_section.c @@ -0,0 +1,17 @@ +// Test that AddressSanitizer moves constant strings into a separate section. + +// RUN: %clang_asan -c -o %t %s +// RUN: llvm-objdump -s %t | FileCheck %s + +// Check that "Hello.\n" is in __asan_cstring and not in __cstring. +// CHECK: Contents of section __asan_cstring: +// CHECK: 48656c6c {{.*}} Hello. +// CHECK: Contents of section __const: +// CHECK-NOT: 48656c6c {{.*}} Hello. +// CHECK: Contents of section __cstring: +// CHECK-NOT: 48656c6c {{.*}} Hello. + +int main(int argc, char *argv[]) { + argv[0] = "Hello.\n"; + return 0; +} diff --git a/test/asan/TestCases/Darwin/dead-strip.c b/test/asan/TestCases/Darwin/dead-strip.c new file mode 100644 index 000000000000..f87a5e52b1cf --- /dev/null +++ b/test/asan/TestCases/Darwin/dead-strip.c @@ -0,0 +1,22 @@ +// Test that AddressSanitizer does not re-animate dead globals when dead +// stripping is turned on. +// +// This test verifies that an out-of-bounds access on a global variable is +// detected after dead stripping has been performed. This proves that the +// runtime is able to register globals in the __DATA,__asan_globals section. + +// REQUIRES: osx-ld64-live_support +// RUN: %clang_asan -mmacosx-version-min=10.11 -Xlinker -dead_strip -o %t %s +// RUN: llvm-nm -format=posix %t | FileCheck --check-prefix NM-CHECK %s +// RUN: not %run %t 2>&1 | FileCheck --check-prefix ASAN-CHECK %s + +int alive[1] = {}; +int dead[1] = {}; +// NM-CHECK: {{^_alive }} +// NM-CHECK-NOT: {{^_dead }} + +int main(int argc, char *argv[]) { + alive[argc] = 0; + // ASAN-CHECK: {{0x.* is located 0 bytes to the right of global variable}} + return 0; +} diff --git a/test/asan/TestCases/Darwin/dump_registers.cc b/test/asan/TestCases/Darwin/dump_registers.cc new file mode 100644 index 000000000000..884ad2ed44c0 --- /dev/null +++ b/test/asan/TestCases/Darwin/dump_registers.cc @@ -0,0 +1,26 @@ +// Check that ASan dumps the CPU registers on a SIGSEGV. + +// RUN: %clangxx_asan %s -o %t +// RUN: not %run %t 2>&1 | FileCheck %s + +#include +#include + +int main() { + fprintf(stderr, "Hello\n"); + char *ptr; + + if (sizeof(void *) == 8) + ptr = (char *)0x6666666666666666; + else if (sizeof(void *) == 4) + ptr = (char *)0x55555555; + else + assert(0 && "Your computer is weird."); + + char c = *ptr; // BOOM + // CHECK: ERROR: AddressSanitizer: SEGV + // CHECK: Register values: + // CHECK: {{0x55555555|0x6666666666666666}} + fprintf(stderr, "World\n"); + return c; +} diff --git a/test/asan/TestCases/Darwin/malloc_destroy_zone.cc b/test/asan/TestCases/Darwin/malloc_destroy_zone.cc new file mode 100644 index 000000000000..9144bd689f74 --- /dev/null +++ b/test/asan/TestCases/Darwin/malloc_destroy_zone.cc @@ -0,0 +1,21 @@ +// RUN: %clangxx_asan %s -o %t && %run %t 2>&1 | FileCheck %s + +#include +#include +#include + +int main() { + fprintf(stderr, "start\n"); + malloc_zone_t *zone = malloc_create_zone(0, 0); + fprintf(stderr, "zone = %p\n", zone); + malloc_set_zone_name(zone, "myzone"); + fprintf(stderr, "name changed\n"); + malloc_destroy_zone(zone); + fprintf(stderr, "done\n"); + return 0; +} + +// CHECK: start +// CHECK-NEXT: zone = 0x{{.*}} +// CHECK-NEXT: name changed +// CHECK-NEXT: done diff --git a/test/asan/TestCases/Darwin/odr-lto.cc b/test/asan/TestCases/Darwin/odr-lto.cc new file mode 100644 index 000000000000..40abec5827d5 --- /dev/null +++ b/test/asan/TestCases/Darwin/odr-lto.cc @@ -0,0 +1,45 @@ +// Check that -asan-use-private-alias and use_odr_indicator=1 silence the false +// positive ODR violation on Darwin with LTO. + +// REQUIRES: lto + +// RUN: %clangxx_asan -DPART=0 -c %s -o %t-1.o -flto +// RUN: %clangxx_asan -DPART=1 -c %s -o %t-2.o -flto +// RUN: %clangxx_asan %t-1.o %t-2.o -o %t -flto +// RUN: not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-ODR + +// RUN: %clangxx_asan -DPART=0 -c %s -o %t-1.o -flto -mllvm -asan-use-private-alias +// RUN: %clangxx_asan -DPART=1 -c %s -o %t-2.o -flto -mllvm -asan-use-private-alias +// RUN: %clangxx_asan %t-1.o %t-2.o -o %t -flto +// RUN: %env_asan_opts=use_odr_indicator=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ODR + +#include +#include +void putstest(); + +#if PART == 1 + +static const char *my_global = "test\n\00abc"; + +int main() +{ + fputs(my_global, stderr); + putstest(); + fprintf(stderr, "Done.\n"); + return 0; +} + +#else // PART == 1 + +static const char *my_other_global = "test\n\00abc"; + +void putstest() +{ + fputs(my_other_global, stderr); +} + +#endif // PART == 1 + +// CHECK-ODR: ERROR: AddressSanitizer: odr-violation +// CHECK-NO-ODR-NOT: ERROR: AddressSanitizer: odr-violation +// CHECK-NO-ODR: Done. -- cgit v1.2.3