diff options
Diffstat (limited to 'test/asan/TestCases/Linux')
| -rw-r--r-- | test/asan/TestCases/Linux/asan_rt_confict_test-2.cc | 4 | ||||
| -rw-r--r-- | test/asan/TestCases/Linux/coverage-missing.cc | 10 | ||||
| -rw-r--r-- | test/asan/TestCases/Linux/local_alias.cc | 11 | ||||
| -rw-r--r-- | test/asan/TestCases/Linux/new_delete_mismatch.cc | 1 | ||||
| -rw-r--r-- | test/asan/TestCases/Linux/new_delete_mismatch_global.cc | 16 | ||||
| -rw-r--r-- | test/asan/TestCases/Linux/new_delete_mismatch_stack.cc | 17 | ||||
| -rw-r--r-- | test/asan/TestCases/Linux/odr-violation.cc | 26 | ||||
| -rw-r--r-- | test/asan/TestCases/Linux/odr-vtable.cc | 26 | ||||
| -rw-r--r-- | test/asan/TestCases/Linux/odr_c_test.c | 8 | ||||
| -rw-r--r-- | test/asan/TestCases/Linux/odr_indicators.cc | 26 | ||||
| -rw-r--r-- | test/asan/TestCases/Linux/preinit_test.cc | 7 | ||||
| -rw-r--r-- | test/asan/TestCases/Linux/preinstalled_signal.cc | 2 |
12 files changed, 123 insertions, 31 deletions
diff --git a/test/asan/TestCases/Linux/asan_rt_confict_test-2.cc b/test/asan/TestCases/Linux/asan_rt_confict_test-2.cc index 4c935e2b0f3ba..6328cbb2ce812 100644 --- a/test/asan/TestCases/Linux/asan_rt_confict_test-2.cc +++ b/test/asan/TestCases/Linux/asan_rt_confict_test-2.cc @@ -1,8 +1,8 @@ // Test that mixed static/dynamic sanitization of program objects // is prohibited. // -// RUN: %clangxx_asan -DBUILD_SO=1 -fPIC -shared %s -o %t.so -// RUN: %clangxx_asan_static %s %t.so -o %t +// RUN: %clangxx_asan -DBUILD_SO=1 -fPIC -shared %s -o %dynamiclib +// RUN: %clangxx_asan_static %s %ld_flags_rpath_exe -o %t // RUN: not %run %t 2>&1 | FileCheck %s // REQUIRES: asan-dynamic-runtime diff --git a/test/asan/TestCases/Linux/coverage-missing.cc b/test/asan/TestCases/Linux/coverage-missing.cc index 32aada645deb2..10acef9af4b03 100644 --- a/test/asan/TestCases/Linux/coverage-missing.cc +++ b/test/asan/TestCases/Linux/coverage-missing.cc @@ -45,7 +45,15 @@ // RUN: diff bar.txt foo-missing.txt > %t.log || true // RUN: not grep "^<" %t.log -// REQUIRES: x86-target-arch +// FIXME %sancov GetInstrumentedPCs relies on objdump -d to +// obtain the number of instrumented PCs. The i386 +// %dynamiclib has .plt entries that are not recognized by +// objdump, +// "sancov.py: found 0 instrumented PCs in *.so", +// causing AddressSanitizer-i386-linux to fail. +// Change it back to x86-target-arch after %sancov switches to a more robust approach. + +// REQUIRES: x86_64-target-arch // XFAIL: android #include <stdio.h> diff --git a/test/asan/TestCases/Linux/local_alias.cc b/test/asan/TestCases/Linux/local_alias.cc index 266d3fe6bc8ff..a8b3d75e375bf 100644 --- a/test/asan/TestCases/Linux/local_alias.cc +++ b/test/asan/TestCases/Linux/local_alias.cc @@ -4,14 +4,11 @@ // false positive global-buffer-overflow due to sanitized library poisons // globals from non-sanitized one. // -// FIXME: https://github.com/google/sanitizers/issues/316 -// XFAIL: android -// -// RUN: %clangxx_asan -DBUILD_INSTRUMENTED_DSO=1 -fPIC -shared -mllvm -asan-use-private-alias %s -o %t-INSTRUMENTED-SO.so -// RUN: %clangxx -DBUILD_UNINSTRUMENTED_DSO=1 -fPIC -shared %s -o %t-UNINSTRUMENTED-SO.so +// RUN: %clangxx_asan -DBUILD_INSTRUMENTED_DSO=1 -fPIC -shared -mllvm -asan-use-private-alias %s -o %dynamiclib1 +// RUN: %clangxx -DBUILD_UNINSTRUMENTED_DSO=1 -fPIC -shared %s -o %dynamiclib2 // RUN: %clangxx %s -c -mllvm -asan-use-private-alias -o %t.o -// RUN: %clangxx_asan %t.o %t-UNINSTRUMENTED-SO.so %t-INSTRUMENTED-SO.so -o %t-EXE -// RUN: %env_asan_opts=use_odr_indicator=true %run %t-EXE +// RUN: %clangxx_asan %t.o %ld_flags_rpath_exe2 %ld_flags_rpath_exe1 -o %t-EXE +// RUN: %run %t-EXE #if defined (BUILD_INSTRUMENTED_DSO) long h = 15; diff --git a/test/asan/TestCases/Linux/new_delete_mismatch.cc b/test/asan/TestCases/Linux/new_delete_mismatch.cc index 3a71862fb732e..05f74bda7549e 100644 --- a/test/asan/TestCases/Linux/new_delete_mismatch.cc +++ b/test/asan/TestCases/Linux/new_delete_mismatch.cc @@ -14,3 +14,4 @@ int main() { } // CHECK: AddressSanitizer: alloc-dealloc-mismatch (operator new [] vs operator delete) on 0x +// CHECK: is located 0 bytes inside of 10-byte region diff --git a/test/asan/TestCases/Linux/new_delete_mismatch_global.cc b/test/asan/TestCases/Linux/new_delete_mismatch_global.cc new file mode 100644 index 0000000000000..3f1a78715cafe --- /dev/null +++ b/test/asan/TestCases/Linux/new_delete_mismatch_global.cc @@ -0,0 +1,16 @@ +// Check that we report delete on a memory that belongs to a global variable. + +// RUN: %clangxx_asan -g %s -o %t && %env_asan_opts=alloc_dealloc_mismatch=1 not %run %t 2>&1 | FileCheck %s + +#include <stdlib.h> + +static volatile char *x; +char a[10]; + +int main() { + x = &a[0]; + delete x; +} + +// CHECK: AddressSanitizer: attempting free on address which was not malloc()-ed +// CHECK: is located 0 bytes inside of global variable 'a' defined in diff --git a/test/asan/TestCases/Linux/new_delete_mismatch_stack.cc b/test/asan/TestCases/Linux/new_delete_mismatch_stack.cc new file mode 100644 index 0000000000000..bbf07cc21380f --- /dev/null +++ b/test/asan/TestCases/Linux/new_delete_mismatch_stack.cc @@ -0,0 +1,17 @@ +// Check that we report delete on a memory that belongs to a stack variable. + +// RUN: %clangxx_asan -g %s -o %t && %env_asan_opts=alloc_dealloc_mismatch=1 not %run %t 2>&1 | FileCheck %s + +#include <stdlib.h> + +static volatile char *x; + +int main() { + char a[10]; + x = &a[0]; + delete x; +} + +// CHECK: AddressSanitizer: attempting free on address which was not malloc()-ed +// CHECK: is located in stack of thread T0 at offset +// CHECK: 'a'{{.*}} <== Memory access at offset {{16|32}} is inside this variable diff --git a/test/asan/TestCases/Linux/odr-violation.cc b/test/asan/TestCases/Linux/odr-violation.cc index 70437a8321b91..a1941fcc8d7a3 100644 --- a/test/asan/TestCases/Linux/odr-violation.cc +++ b/test/asan/TestCases/Linux/odr-violation.cc @@ -5,15 +5,15 @@ // pointers. This setting is not on by default because it's too expensive. // // Different size: detect a bug if detect_odr_violation>=1 -// RUN: %clangxx_asan -DBUILD_SO=1 -fPIC -shared %s -o %t-ODR-SO.so -// RUN: %clangxx_asan %s %t-ODR-SO.so -Wl,-R. -o %t-ODR-EXE +// RUN: %clangxx_asan -DBUILD_SO=1 -fPIC -shared %s -o %dynamiclib +// RUN: %clangxx_asan %s %ld_flags_rpath_exe -o %t-ODR-EXE // RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=1 not %run %t-ODR-EXE 2>&1 | FileCheck %s // RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=2 not %run %t-ODR-EXE 2>&1 | FileCheck %s // RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=0 %run %t-ODR-EXE 2>&1 | FileCheck %s --check-prefix=DISABLED // RUN: %env_asan_opts=fast_unwind_on_malloc=0 not %run %t-ODR-EXE 2>&1 | FileCheck %s // // Same size: report a bug only if detect_odr_violation>=2. -// RUN: %clangxx_asan -DBUILD_SO=1 -fPIC -shared %s -o %t-ODR-SO.so -DSZ=100 +// RUN: %clangxx_asan -DBUILD_SO=1 -fPIC -shared %s -o %dynamiclib -DSZ=100 // RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=1 %run %t-ODR-EXE 2>&1 | FileCheck %s --check-prefix=DISABLED // RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=2 not %run %t-ODR-EXE 2>&1 | FileCheck %s // RUN: %env_asan_opts=fast_unwind_on_malloc=0 not %run %t-ODR-EXE 2>&1 | FileCheck %s @@ -23,12 +23,20 @@ // 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 // RUN: rm -f %t.supp // +// Use private aliases for global variables without indicator symbol. +// RUN: %clangxx_asan -DBUILD_SO=1 -fPIC -shared -mllvm -asan-use-private-alias %s -o %dynamiclib -DSZ=100 +// RUN: %clangxx_asan -mllvm -asan-use-private-alias %s %ld_flags_rpath_exe -o %t-ODR-EXE +// RUN: %env_asan_opts=fast_unwind_on_malloc=0 %run %t-ODR-EXE 2>&1 | FileCheck %s --check-prefix=DISABLED + // Use private aliases for global variables: use indicator symbol to detect ODR violation. -// RUN: %clangxx_asan -DBUILD_SO=1 -fPIC -shared -mllvm -asan-use-private-alias %s -o %t-ODR-SO.so -DSZ=100 -// RUN: %clangxx_asan -mllvm -asan-use-private-alias %s %t-ODR-SO.so -Wl,-R. -o %t-ODR-EXE -// RUN: %env_asan_opts=fast_unwind_on_malloc=0 %run %t-ODR-EXE 2>&1 | FileCheck %s --check-prefix=DISABLED -// RUN: %env_asan_opts=fast_unwind_on_malloc=0:use_odr_indicator=false %run %t-ODR-EXE 2>&1 | FileCheck %s --check-prefix=DISABLED -// RUN: %env_asan_opts=fast_unwind_on_malloc=0:use_odr_indicator=true not %run %t-ODR-EXE 2>&1 | FileCheck %s +// RUN: %clangxx_asan -DBUILD_SO=1 -fPIC -shared -mllvm -asan-use-private-alias -mllvm -asan-use-odr-indicator %s -o %dynamiclib -DSZ=100 +// RUN: %clangxx_asan -mllvm -asan-use-private-alias -mllvm -asan-use-odr-indicator %s %ld_flags_rpath_exe -o %t-ODR-EXE +// RUN: %env_asan_opts=fast_unwind_on_malloc=0 not %run %t-ODR-EXE 2>&1 | FileCheck %s + +// Same as above but with clang switches. +// RUN: %clangxx_asan -DBUILD_SO=1 -fPIC -shared -fsanitize-address-use-odr-indicator %s -o %dynamiclib -DSZ=100 +// RUN: %clangxx_asan -fsanitize-address-use-odr-indicator %s %ld_flags_rpath_exe -o %t-ODR-EXE +// RUN: %env_asan_opts=fast_unwind_on_malloc=0 not %run %t-ODR-EXE 2>&1 | FileCheck %s // GNU driver doesn't handle .so files properly. // REQUIRES: Clang @@ -52,6 +60,6 @@ int main(int argc, char **argv) { // CHECK: These globals were registered at these points: // CHECK: ODR-EXE -// CHECK: ODR-SO +// CHECK: odr-violation.cc.dynamic // CHECK: SUMMARY: AddressSanitizer: odr-violation: global 'foo::G' at {{.*}}odr-violation.cc // DISABLED: PASS diff --git a/test/asan/TestCases/Linux/odr-vtable.cc b/test/asan/TestCases/Linux/odr-vtable.cc new file mode 100644 index 0000000000000..fdbab4bb1fd82 --- /dev/null +++ b/test/asan/TestCases/Linux/odr-vtable.cc @@ -0,0 +1,26 @@ +// RUN: %clangxx_asan -fno-rtti -DBUILD_SO1 -fPIC -shared %s -o %dynamiclib1 +// RUN: %clangxx_asan -fno-rtti -DBUILD_SO2 -fPIC -shared %s -o %dynamiclib2 +// RUN: %clangxx_asan -fno-rtti %s %ld_flags_rpath_exe1 %ld_flags_rpath_exe2 -o %t +// RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=2 not %run %t 2>&1 | FileCheck %s + +struct XYZ { + virtual void foo(); +}; + +#if defined(BUILD_SO1) + +void XYZ::foo() {} + +#elif defined(BUILD_SO2) + +void XYZ::foo() {} + +#else + +int main() {} + +#endif + +// CHECK: AddressSanitizer: odr-violation +// CHECK-NEXT: 'vtable for XYZ' +// CHECK-NEXT: 'vtable for XYZ' diff --git a/test/asan/TestCases/Linux/odr_c_test.c b/test/asan/TestCases/Linux/odr_c_test.c index b1d23493b5704..c1423ed30b1b3 100644 --- a/test/asan/TestCases/Linux/odr_c_test.c +++ b/test/asan/TestCases/Linux/odr_c_test.c @@ -1,13 +1,11 @@ // Test that we can properly report an ODR violation // between an instrumented global and a non-instrumented global. -// RUN: %clang_asan %s -fPIC -shared -o %t-1.so -DFILE1 -// RUN: %clang_asan %s -fPIC -shared -o %t-2.so -DFILE2 -// RUN: %clang_asan %s -fPIE %t-1.so %t-2.so -Wl,-R`pwd` -o %t +// RUN: %clang_asan %s -fPIC -shared -o %dynamiclib1 -DFILE1 +// RUN: %clang_asan %s -fPIC -shared -o %dynamiclib2 -DFILE2 +// RUN: %clang_asan %s -fPIE %ld_flags_rpath_exe1 %ld_flags_rpath_exe2 -o %t // RUN: not %run %t 2>&1 | FileCheck %s // -// REQUIRES: x86_64-target-arch -// // CHECK: The following global variable is not properly aligned. // CHECK: ERROR: AddressSanitizer: odr-violation #if defined(FILE1) diff --git a/test/asan/TestCases/Linux/odr_indicators.cc b/test/asan/TestCases/Linux/odr_indicators.cc new file mode 100644 index 0000000000000..36176b552906d --- /dev/null +++ b/test/asan/TestCases/Linux/odr_indicators.cc @@ -0,0 +1,26 @@ +// RUN: %clangxx_asan -fPIC %s -o %t +// RUN: %env_asan_opts=report_globals=2 %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK,INDICATOR0 + +// RUN: %clangxx_asan -fsanitize-address-use-odr-indicator -fPIC %s -o %t +// RUN: %env_asan_opts=report_globals=2 %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK,INDICATOR1 + +#include <stdio.h> + +int test_global_1; +// INDICATOR0-DAG: Added Global{{.*}} name=test_global_1{{.*}} odr_indicator={{0x0+$}} +// INDICATOR1-DAG: Added Global{{.*}} name=test_global_1{{.*}} odr_indicator={{0x0*[^0]+.*$}} + +static int test_global_2; +// CHECK-DAG: Added Global{{.*}} name=test_global_2{{.*}} odr_indicator={{0xf+$}} + +namespace { +static int test_global_3; +// CHECK-DAG: Added Global{{.*}} name={{.*}}::test_global_3{{.*}} odr_indicator={{0xf+$}} +} // namespace + +int main() { + const char f[] = "%d %d %d\n"; + // CHECK-DAG: Added Global{{.*}} name=__const.main.f{{.*}} odr_indicator={{0xf+$}} + printf(f, test_global_1, test_global_2, test_global_3); + return 0; +} diff --git a/test/asan/TestCases/Linux/preinit_test.cc b/test/asan/TestCases/Linux/preinit_test.cc index 10dde67d6a9b9..f8c2b6bf52f1d 100644 --- a/test/asan/TestCases/Linux/preinit_test.cc +++ b/test/asan/TestCases/Linux/preinit_test.cc @@ -1,8 +1,5 @@ -// FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316 -// XFAIL: android -// -// RUN: %clangxx -DFUNC=zzzz %s -shared -o %t.so -fPIC -// RUN: %clangxx_asan -DFUNC=main %s -o %t -Wl,-R. %t.so +// RUN: %clangxx -DFUNC=zzzz %s -shared -o %dynamiclib -fPIC +// RUN: %clangxx_asan -DFUNC=main %s -o %t %ld_flags_rpath_exe // RUN: %run %t // GNU driver doesn't handle .so files properly. diff --git a/test/asan/TestCases/Linux/preinstalled_signal.cc b/test/asan/TestCases/Linux/preinstalled_signal.cc index ac4ea93a5418d..2b50944c6f2f6 100644 --- a/test/asan/TestCases/Linux/preinstalled_signal.cc +++ b/test/asan/TestCases/Linux/preinstalled_signal.cc @@ -1,4 +1,3 @@ -// clang-format off // RUN: %clangxx -std=c++11 %s -o %t // RUN: env LD_PRELOAD=%shared_libasan %env_asan_opts=handle_segv=1 not %run %t 2>&1 | FileCheck %s // RUN: env LD_PRELOAD=%shared_libasan %env_asan_opts=handle_segv=2 not %run %t 2>&1 | FileCheck %s @@ -17,7 +16,6 @@ // This way of setting LD_PRELOAD does not work with Android test runner. // REQUIRES: !android -// clang-format on #include <assert.h> #include <signal.h> |
