Summary: This patch (on top of the previous two (https://reviews.llvm.org/D40898 and https://reviews.llvm.org/D40899) complete the compiler-rt side of the the Solaris sanitizer port. It contains the following sets of changes: * For the time being, the port is for 32-bit x86 only, so reject the various tests on x86_64. * When compiling as C++, <setjmp.h> resp. <iso/setjmp_iso.h> only declares _setjmp and _longjmp inside namespace std. * MAP_FILE is a Windows feature. While e.g. Linux <sys/mman.h> provides a no-op compat define, Solaris does not. * test/asan/TestCases/Posix/coverage.cc was initially failing like this: /vol/gcc/src/llvm/llvm/local/projects/compiler-rt/lib/sanitizer_common/scripts/sancov.py: 4 files merged; 2 PCs total rm: cannot remove '/var/gcc/llvm/local/projects/compiler-rt/test/asan/I386SunOSConfig/TestCases/Posix/Output/coverage': Invalid argument Further digging revealed that the rm was trying to remove the running test's working directory which failed as observed. cd'ing out of the dir before let the test pass. * Two tests needed a declaration of alloca. I've now copied the existing code from test/asan/TestCases/alloca_constant_size.cc, but it may be more profitable and maintainable to have a common testsuite header where such code is collected. * Similarly, Solaris' printf %p format doesn't include the leading 0x. * In test/asan/TestCases/malloc-no-intercept.c, I had to undef __EXTENSIONS__ (predefined by clang for no apparent reason) to avoid conflicting declarations for memalign. * test/ubsan/TestCases/Float/cast-overflow.cpp has different platform dependent ways to define BYTE_ORDER and friends. Why not just use __BYTE_ORDER__ and friends as predefined by clang and gcc? Patch by Rainer Orth. Reviewers: kcc, alekseyshl Reviewed By: alekseyshl Subscribers: srhines, kubamracek, mgorny, krytarowski, fedor.sergeev, JDevlieghere, llvm-commits, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D40900 llvm-svn: 322635
77 lines
2.9 KiB
C++
77 lines
2.9 KiB
C++
// RUN: %clangxx_asan -fsanitize-coverage=func,trace-pc-guard -DSHARED %s -shared -o %dynamiclib -fPIC %ld_flags_rpath_so
|
|
// RUN: %clangxx_asan -fsanitize-coverage=func,trace-pc-guard %s %ld_flags_rpath_exe -o %t
|
|
// RUN: rm -rf %T/coverage && mkdir -p %T/coverage && cd %T/coverage
|
|
// RUN: %env_asan_opts=coverage=1:verbosity=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-main
|
|
// RUN: %sancov print coverage.*sancov 2>&1 | FileCheck %s --check-prefix=CHECK-SANCOV1
|
|
// RUN: %env_asan_opts=coverage=1:verbosity=1 %run %t foo 2>&1 | FileCheck %s --check-prefix=CHECK-foo
|
|
// RUN: %sancov print coverage.*sancov 2>&1 | FileCheck %s --check-prefix=CHECK-SANCOV2
|
|
// RUN: %env_asan_opts=coverage=1:verbosity=1 %run %t bar 2>&1 | FileCheck %s --check-prefix=CHECK-bar
|
|
// RUN: %sancov print coverage.*sancov 2>&1 | FileCheck %s --check-prefix=CHECK-SANCOV2
|
|
// RUN: %env_asan_opts=coverage=1:verbosity=1 %run %t foo bar 2>&1 | FileCheck %s --check-prefix=CHECK-foo-bar
|
|
// RUN: %sancov print coverage.*sancov 2>&1 | FileCheck %s --check-prefix=CHECK-SANCOV2
|
|
// RUN: %sancov print libcoverage.*sancov 2>&1 | FileCheck %s --check-prefix=CHECK-SANCOV1
|
|
// RUN: %sancov merge coverage.*sancov > merged-cov
|
|
// RUN: %sancov print merged-cov 2>&1 | FileCheck %s --check-prefix=CHECK-SANCOV2
|
|
// RUN: %env_asan_opts=coverage=1:verbosity=1 not %run %t foo bar 4 2>&1 | FileCheck %s --check-prefix=CHECK-report
|
|
// RUN: %env_asan_opts=coverage=1:verbosity=1 not %run %t foo bar 4 5 2>&1 | FileCheck %s --check-prefix=CHECK-segv
|
|
// RUN: cd .. && rm -r %T/coverage
|
|
//
|
|
// https://code.google.com/p/address-sanitizer/issues/detail?id=263
|
|
// XFAIL: android
|
|
// UNSUPPORTED: ios
|
|
|
|
#include <assert.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
|
|
#ifdef SHARED
|
|
void bar() { printf("bar\n"); }
|
|
#else
|
|
__attribute__((noinline))
|
|
void foo() { printf("foo\n"); }
|
|
extern void bar();
|
|
|
|
int G[4];
|
|
|
|
int main(int argc, char **argv) {
|
|
fprintf(stderr, "PID: %d\n", getpid());
|
|
for (int i = 1; i < argc; i++) {
|
|
if (!strcmp(argv[i], "foo"))
|
|
foo();
|
|
if (!strcmp(argv[i], "bar"))
|
|
bar();
|
|
}
|
|
if (argc == 5) {
|
|
static volatile char *zero = 0;
|
|
*zero = 0; // SEGV if argc == 5.
|
|
}
|
|
return G[argc]; // Buffer overflow if argc >= 4.
|
|
}
|
|
#endif
|
|
|
|
// CHECK-main: PID: [[PID:[0-9]+]]
|
|
// CHECK-main: [[PID]].sancov: 1 PCs written
|
|
// CHECK-main-NOT: .so.[[PID]]
|
|
//
|
|
// CHECK-foo: PID: [[PID:[0-9]+]]
|
|
// CHECK-foo: [[PID]].sancov: 2 PCs written
|
|
// CHECK-foo-NOT: .so.[[PID]]
|
|
//
|
|
// CHECK-bar: PID: [[PID:[0-9]+]]
|
|
// CHECK-bar-DAG: .so.[[PID]].sancov: 1 PCs written
|
|
// CHECK-bar-DAG: [[PID]].sancov: 1 PCs written
|
|
//
|
|
// CHECK-foo-bar: PID: [[PID:[0-9]+]]
|
|
// CHECK-foo-bar-DAG: so.[[PID]].sancov: 1 PCs written
|
|
// CHECK-foo-bar-DAG: [[PID]].sancov: 2 PCs written
|
|
//
|
|
// CHECK-report: AddressSanitizer: global-buffer-overflow
|
|
// CHECK-report: PCs written
|
|
//
|
|
// CHECK-segv: AddressSanitizer: SEGV
|
|
// CHECK-segv: PCs written
|
|
//
|
|
// CHECK-SANCOV1: 1 PCs total
|
|
// CHECK-SANCOV2: 2 PCs total
|