blob: bc76116632ecac94c4df7bc2fd59607e7e545707 [file] [log] [blame]
Stephen Hines6a211c52014-07-21 00:49:56 -07001// FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316
2// XFAIL: android
3//
Stephen Hines86277eb2015-03-23 12:06:32 -07004// We use fast_unwind_on_malloc=0 to have full unwinding even w/o frame
5// pointers. This setting is not on by default because it's too expensive.
6//
Stephen Hines2d1fdb22014-05-28 23:58:16 -07007// Different size: detect a bug if detect_odr_violation>=1
Stephen Hines6a211c52014-07-21 00:49:56 -07008// RUN: %clangxx_asan -DBUILD_SO=1 -fPIC -shared %s -o %t-ODR-SO.so
9// RUN: %clangxx_asan %s %t-ODR-SO.so -Wl,-R. -o %t-ODR-EXE
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080010// RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=1 not %run %t-ODR-EXE 2>&1 | FileCheck %s
11// RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=2 not %run %t-ODR-EXE 2>&1 | FileCheck %s
12// RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=0 %run %t-ODR-EXE 2>&1 | FileCheck %s --check-prefix=DISABLED
13// RUN: %env_asan_opts=fast_unwind_on_malloc=0 not %run %t-ODR-EXE 2>&1 | FileCheck %s
Stephen Hines2d1fdb22014-05-28 23:58:16 -070014//
15// Same size: report a bug only if detect_odr_violation>=2.
Stephen Hines6a211c52014-07-21 00:49:56 -070016// RUN: %clangxx_asan -DBUILD_SO=1 -fPIC -shared %s -o %t-ODR-SO.so -DSZ=100
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080017// RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=1 %run %t-ODR-EXE 2>&1 | FileCheck %s --check-prefix=DISABLED
18// RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=2 not %run %t-ODR-EXE 2>&1 | FileCheck %s
19// RUN: %env_asan_opts=fast_unwind_on_malloc=0 not %run %t-ODR-EXE 2>&1 | FileCheck %s
Stephen Hines86277eb2015-03-23 12:06:32 -070020// RUN: echo "odr_violation:foo::ZZZ" > %t.supp
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080021// RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=2:suppressions=%t.supp not %run %t-ODR-EXE 2>&1 | FileCheck %s
Stephen Hines86277eb2015-03-23 12:06:32 -070022// RUN: echo "odr_violation:foo::G" > %t.supp
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080023// RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=2:suppressions=%t.supp %run %t-ODR-EXE 2>&1 | FileCheck %s --check-prefix=DISABLED
Stephen Hines86277eb2015-03-23 12:06:32 -070024// RUN: rm -f %t.supp
Stephen Hines2d1fdb22014-05-28 23:58:16 -070025
26// GNU driver doesn't handle .so files properly.
27// REQUIRES: Clang
28
29#ifndef SZ
30# define SZ 4
31#endif
32
33#if BUILD_SO
Stephen Hines6d186232014-11-26 17:56:19 -080034namespace foo { char G[SZ]; }
Stephen Hines2d1fdb22014-05-28 23:58:16 -070035#else
36#include <stdio.h>
Stephen Hines6d186232014-11-26 17:56:19 -080037namespace foo { char G[100]; }
38// CHECK: ERROR: AddressSanitizer: odr-violation
39// CHECK: size=100 'foo::G' {{.*}}odr-violation.cc:[[@LINE-2]]:22
40// CHECK: size={{4|100}} 'foo::G'
Stephen Hines2d1fdb22014-05-28 23:58:16 -070041int main(int argc, char **argv) {
Stephen Hines6d186232014-11-26 17:56:19 -080042 printf("PASS: %p\n", &foo::G);
Stephen Hines2d1fdb22014-05-28 23:58:16 -070043}
44#endif
45
Stephen Hines6a211c52014-07-21 00:49:56 -070046// CHECK: These globals were registered at these points:
47// CHECK: ODR-EXE
48// CHECK: ODR-SO
Stephen Hines6d186232014-11-26 17:56:19 -080049// CHECK: SUMMARY: AddressSanitizer: odr-violation: global 'foo::G' at {{.*}}odr-violation.cc
Stephen Hines2d1fdb22014-05-28 23:58:16 -070050// DISABLED: PASS