[ASan] Make the remaining coverage tests pass on Darwin, move them to Posix/

This CL:
 - moves PrepareForSandboxing() to sanitizer_posix_libcdep.cc
 - fixes the coverage tests to use flag substitutions defined in r233802 and not rely on hardcoded shared library names
 - moves those tests to TestCases/Posix so that they can be executed on Darwin

llvm-svn: 233828
This commit is contained in:
Alexander Potapenko 2015-04-01 17:56:29 +00:00
parent f1b82e3ad1
commit 0ae78444e7
10 changed files with 69 additions and 74 deletions

View File

@ -15,6 +15,7 @@
#include "sanitizer_platform.h"
#if SANITIZER_FREEBSD || SANITIZER_LINUX
#include "sanitizer_atomic.h"
#include "sanitizer_common.h"
#include "sanitizer_flags.h"
#include "sanitizer_freebsd.h"
@ -22,8 +23,6 @@
#include "sanitizer_placement_new.h"
#include "sanitizer_procmaps.h"
#include "sanitizer_stacktrace.h"
#include "sanitizer_atomic.h"
#include "sanitizer_symbolizer.h"
#if SANITIZER_ANDROID || SANITIZER_FREEBSD
#include <dlfcn.h> // for dlsym()
@ -462,19 +461,6 @@ uptr GetListOfModules(LoadedModule *modules, uptr max_modules,
}
#endif // SANITIZER_ANDROID
void PrepareForSandboxing(__sanitizer_sandbox_arguments *args) {
// Some kinds of sandboxes may forbid filesystem access, so we won't be able
// to read the file mappings from /proc/self/maps. Luckily, neither the
// process will be able to load additional libraries, so it's fine to use the
// cached mappings.
MemoryMappingLayout::CacheMemoryMappings();
// Same for /proc/self/exe in the symbolizer.
#if !SANITIZER_GO
Symbolizer::GetOrInit()->PrepareForSandboxing();
CovPrepareForSandboxing(args);
#endif
}
// getrusage does not give us the current RSS, only the max RSS.
// Still, this is better than nothing if /proc/self/statm is not available
// for some reason, e.g. due to a sandbox.

View File

@ -220,11 +220,6 @@ void ReExec() {
UNIMPLEMENTED();
}
void PrepareForSandboxing(__sanitizer_sandbox_arguments *args) {
(void)args;
// Nothing here for now.
}
uptr GetPageSize() {
return sysconf(_SC_PAGESIZE);
}

View File

@ -18,7 +18,9 @@
#include "sanitizer_common.h"
#include "sanitizer_flags.h"
#include "sanitizer_platform_limits_posix.h"
#include "sanitizer_procmaps.h"
#include "sanitizer_stacktrace.h"
#include "sanitizer_symbolizer.h"
#include <errno.h>
#include <pthread.h>
@ -200,6 +202,19 @@ bool IsAccessibleMemoryRange(uptr beg, uptr size) {
return result;
}
void PrepareForSandboxing(__sanitizer_sandbox_arguments *args) {
// Some kinds of sandboxes may forbid filesystem access, so we won't be able
// to read the file mappings from /proc/self/maps. Luckily, neither the
// process will be able to load additional libraries, so it's fine to use the
// cached mappings.
MemoryMappingLayout::CacheMemoryMappings();
// Same for /proc/self/exe in the symbolizer.
#if !SANITIZER_GO
Symbolizer::GetOrInit()->PrepareForSandboxing();
CovPrepareForSandboxing(args);
#endif
}
} // namespace __sanitizer
#endif // SANITIZER_POSIX

View File

@ -1,18 +1,18 @@
// Test for direct coverage writing enabled at activation time.
// RUN: %clangxx_asan -fsanitize-coverage=1 -DSHARED %s -shared -o %T/libcoverage_direct_activation_test_1.so -fPIC
// RUN: %clangxx_asan -fsanitize-coverage=1 -DSHARED %s -shared -o %dynamiclib -fPIC
// RUN: %clangxx -c -DSO_DIR=\"%T\" %s -o %t.o
// RUN: %clangxx_asan -fsanitize-coverage=1 %t.o %libdl -o %t
// RUN: rm -rf %T/coverage-direct-activation
// RUN: mkdir -p %T/coverage-direct-activation/normal
// RUN: ASAN_OPTIONS=coverage=1,coverage_direct=0,coverage_dir=%T/coverage-direct-activation/normal:verbosity=1 %run %t
// RUN: ASAN_OPTIONS=coverage=1,coverage_direct=0,coverage_dir=%T/coverage-direct-activation/normal:verbosity=1 %run %t %dynamiclib
// RUN: %sancov print %T/coverage-direct-activation/normal/*.sancov >%T/coverage-direct-activation/normal/out.txt
// RUN: mkdir -p %T/coverage-direct-activation/direct
// RUN: ASAN_OPTIONS=start_deactivated=1,coverage_direct=1,verbosity=1 \
// RUN: ASAN_ACTIVATION_OPTIONS=coverage=1,coverage_dir=%T/coverage-direct-activation/direct %run %t
// RUN: ASAN_ACTIVATION_OPTIONS=coverage=1,coverage_dir=%T/coverage-direct-activation/direct %run %t %dynamiclib
// RUN: cd %T/coverage-direct-activation/direct
// RUN: %sancov rawunpack *.sancov.raw
// RUN: %sancov print *.sancov >out.txt
@ -24,7 +24,7 @@
// RUN: mkdir -p %T/coverage-direct-activation/direct2
// RUN: ASAN_OPTIONS=start_deactivated=1,coverage=1,coverage_direct=1,verbosity=1 \
// RUN: ASAN_ACTIVATION_OPTIONS=coverage_dir=%T/coverage-direct-activation/direct2 %run %t
// RUN: ASAN_ACTIVATION_OPTIONS=coverage_dir=%T/coverage-direct-activation/direct2 %run %t %dynamiclib
// RUN: cd %T/coverage-direct-activation/direct2
// RUN: %sancov rawunpack *.sancov.raw
// RUN: %sancov print *.sancov >out.txt
@ -47,8 +47,8 @@ void bar() { printf("bar\n"); }
int main(int argc, char **argv) {
fprintf(stderr, "PID: %d\n", getpid());
void *handle1 =
dlopen(SO_DIR "/libcoverage_direct_activation_test_1.so", RTLD_LAZY);
assert(argc > 1);
void *handle1 = dlopen(argv[1], RTLD_LAZY); // %dynamiclib
assert(handle1);
void (*bar1)() = (void (*)())dlsym(handle1, "bar");
assert(bar1);

View File

@ -2,18 +2,18 @@
// Current implementation maps output file in chunks of 64K. This test overflows
// 1 chunk.
// RUN: %clangxx_asan -fsanitize-coverage=1 -O0 -DSHARED %s -shared -o %T/libcoverage_direct_large_test_1.so -fPIC
// RUN: %clangxx_asan -fsanitize-coverage=1 -O0 -DSO_DIR=\"%T\" %s %libdl -o %t
// RUN: %clangxx_asan -fsanitize-coverage=1 -O0 -DSHARED %s -shared -o %dynamiclib -fPIC
// RUN: %clangxx_asan -fsanitize-coverage=1 -O0 %s %libdl -o %t
// RUN: rm -rf %T/coverage-direct-large
// RUN: mkdir -p %T/coverage-direct-large/normal && cd %T/coverage-direct-large/normal
// RUN: ASAN_OPTIONS=coverage=1:coverage_direct=0:verbosity=1 %run %t
// RUN: ASAN_OPTIONS=coverage=1:coverage_direct=0:verbosity=1 %run %t %dynamiclib
// RUN: %sancov print *.sancov >out.txt
// RUN: cd ../..
// RUN: mkdir -p %T/coverage-direct-large/direct && cd %T/coverage-direct-large/direct
// RUN: ASAN_OPTIONS=coverage=1:coverage_direct=1:verbosity=1 %run %t
// RUN: ASAN_OPTIONS=coverage=1:coverage_direct=1:verbosity=1 %run %t %dynamiclib
// RUN: %sancov rawunpack *.sancov.raw
// RUN: %sancov print *.sancov >out.txt
// RUN: cd ../..
@ -49,11 +49,11 @@ extern "C" void so_entry() {
#include <assert.h>
#include <dlfcn.h>
int main(void) {
#include <stdio.h>
int main(int argc, char **argv) {
F4(CALL, f)
void *handle1 =
dlopen(SO_DIR "/libcoverage_direct_large_test_1.so", RTLD_LAZY);
assert(argc > 1);
void *handle1 = dlopen(argv[1], RTLD_LAZY); // %dynamiclib
assert(handle1);
void (*so_entry)() = (void (*)())dlsym(handle1, "so_entry");
assert(so_entry);

View File

@ -1,16 +1,16 @@
// Test for direct coverage writing with dlopen at coverage level 1 to 3.
// RUN: %clangxx_asan -fsanitize-coverage=1 -DSHARED %s -shared -o %T/libcoverage_direct_test_1.so -fPIC
// RUN: %clangxx_asan -fsanitize-coverage=1 -DSO_DIR=\"%T\" %s %libdl -o %t
// RUN: %clangxx_asan -fsanitize-coverage=1 -DSHARED %s -shared -o %dynamiclib -fPIC
// RUN: %clangxx_asan -fsanitize-coverage=1 %s %libdl -o %t
// RUN: rm -rf %T/coverage-direct
// RUN: mkdir -p %T/coverage-direct/normal
// RUN: ASAN_OPTIONS=coverage=1:coverage_direct=0:coverage_dir=%T/coverage-direct/normal:verbosity=1 %run %t
// RUN: ASAN_OPTIONS=coverage=1:coverage_direct=0:coverage_dir=%T/coverage-direct/normal:verbosity=1 %run %t %dynamiclib
// RUN: %sancov print %T/coverage-direct/normal/*.sancov >%T/coverage-direct/normal/out.txt
// RUN: mkdir -p %T/coverage-direct/direct
// RUN: ASAN_OPTIONS=coverage=1:coverage_direct=1:coverage_dir=%T/coverage-direct/direct:verbosity=1 %run %t
// RUN: ASAN_OPTIONS=coverage=1:coverage_direct=1:coverage_dir=%T/coverage-direct/direct:verbosity=1 %run %t %dynamiclib
// RUN: cd %T/coverage-direct/direct
// RUN: %sancov rawunpack *.sancov.raw
// RUN: %sancov print *.sancov >out.txt
@ -19,17 +19,17 @@
// RUN: diff -u coverage-direct/normal/out.txt coverage-direct/direct/out.txt
// RUN: %clangxx_asan -fsanitize-coverage=2 -DSHARED %s -shared -o %T/libcoverage_direct_test_1.so -fPIC
// RUN: %clangxx_asan -fsanitize-coverage=2 -DSHARED %s -shared -o %dynamiclib -fPIC
// RUN: %clangxx_asan -fsanitize-coverage=2 -DSO_DIR=\"%T\" %s %libdl -o %t
// RUN: rm -rf %T/coverage-direct
// RUN: mkdir -p %T/coverage-direct/normal
// RUN: ASAN_OPTIONS=coverage=1:coverage_direct=0:coverage_dir=%T/coverage-direct/normal:verbosity=1 %run %t
// RUN: ASAN_OPTIONS=coverage=1:coverage_direct=0:coverage_dir=%T/coverage-direct/normal:verbosity=1 %run %t %dynamiclib
// RUN: %sancov print %T/coverage-direct/normal/*.sancov >%T/coverage-direct/normal/out.txt
// RUN: mkdir -p %T/coverage-direct/direct
// RUN: ASAN_OPTIONS=coverage=1:coverage_direct=1:coverage_dir=%T/coverage-direct/direct:verbosity=1 %run %t
// RUN: ASAN_OPTIONS=coverage=1:coverage_direct=1:coverage_dir=%T/coverage-direct/direct:verbosity=1 %run %t %dynamiclib
// RUN: cd %T/coverage-direct/direct
// RUN: %sancov rawunpack *.sancov.raw
// RUN: %sancov print *.sancov >out.txt
@ -38,17 +38,17 @@
// RUN: diff -u coverage-direct/normal/out.txt coverage-direct/direct/out.txt
// RUN: %clangxx_asan -fsanitize-coverage=3 -DSHARED %s -shared -o %T/libcoverage_direct_test_1.so -fPIC
// RUN: %clangxx_asan -fsanitize-coverage=3 -DSHARED %s -shared -o %dynamiclib -fPIC
// RUN: %clangxx_asan -fsanitize-coverage=3 -DSO_DIR=\"%T\" %s %libdl -o %t
// RUN: rm -rf %T/coverage-direct
// RUN: mkdir -p %T/coverage-direct/normal
// RUN: ASAN_OPTIONS=coverage=1:coverage_direct=0:coverage_dir=%T/coverage-direct/normal:verbosity=1 %run %t
// RUN: ASAN_OPTIONS=coverage=1:coverage_direct=0:coverage_dir=%T/coverage-direct/normal:verbosity=1 %run %t %dynamiclib
// RUN: %sancov print %T/coverage-direct/normal/*.sancov >%T/coverage-direct/normal/out.txt
// RUN: mkdir -p %T/coverage-direct/direct
// RUN: ASAN_OPTIONS=coverage=1:coverage_direct=1:coverage_dir=%T/coverage-direct/direct:verbosity=1 %run %t
// RUN: ASAN_OPTIONS=coverage=1:coverage_direct=1:coverage_dir=%T/coverage-direct/direct:verbosity=1 %run %t %dynamiclib
// RUN: cd %T/coverage-direct/direct
// RUN: %sancov rawunpack *.sancov.raw
// RUN: %sancov print *.sancov >out.txt
@ -71,8 +71,8 @@ void bar() { printf("bar\n"); }
int main(int argc, char **argv) {
fprintf(stderr, "PID: %d\n", getpid());
void *handle1 =
dlopen(SO_DIR "/libcoverage_direct_test_1.so", RTLD_LAZY);
assert(argc > 1);
void *handle1 = dlopen(argv[1], RTLD_LAZY);
assert(handle1);
void (*bar1)() = (void (*)())dlsym(handle1, "bar");
assert(bar1);

View File

@ -1,13 +1,13 @@
// Check that unloading a module doesn't break coverage dumping for remaining
// modules.
// RUN: %clangxx_asan -fsanitize-coverage=1 -DSHARED %s -shared -o %T/libcoverage_module_unloaded_test_1.so -fPIC
// RUN: %clangxx_asan -fsanitize-coverage=1 -DSHARED %s -shared -o %T/libcoverage_module_unloaded_test_2.so -fPIC
// RUN: %clangxx_asan -fsanitize-coverage=1 -DSO_DIR=\"%T\" %s %libdl -o %t
// RUN: %clangxx_asan -fsanitize-coverage=1 -DSHARED %s -shared -o %dynamiclib1 -fPIC
// RUN: %clangxx_asan -fsanitize-coverage=1 -DSHARED %s -shared -o %dynamiclib2 -fPIC
// RUN: %clangxx_asan -fsanitize-coverage=1 %s %libdl -o %t
// RUN: export ASAN_OPTIONS=coverage=1:verbosity=1
// RUN: mkdir -p %T/coverage-module-unloaded && cd %T/coverage-module-unloaded
// RUN: %run %t 2>&1 | FileCheck %s
// RUN: %run %t foo 2>&1 | FileCheck %s
// RUN: cd .. && rm coverage-module-unloaded -r
// RUN: %run %t %dynamiclib1 %dynamiclib2 2>&1 | FileCheck %s
// RUN: %run %t %dynamiclib1 %dynamiclib2 foo 2>&1 | FileCheck %s
// RUN: rm -r %T/coverage-module-unloaded
//
// https://code.google.com/p/address-sanitizer/issues/detail?id=263
// XFAIL: android
@ -25,14 +25,13 @@ void bar() { printf("bar\n"); }
int main(int argc, char **argv) {
fprintf(stderr, "PID: %d\n", getpid());
void *handle1 =
dlopen(SO_DIR "/libcoverage_module_unloaded_test_1.so", RTLD_LAZY);
assert(argc > 2);
void *handle1 = dlopen(argv[1], RTLD_LAZY); // %dynamiclib1
assert(handle1);
void (*bar1)() = (void (*)())dlsym(handle1, "bar");
assert(bar1);
bar1();
void *handle2 =
dlopen(SO_DIR "/libcoverage_module_unloaded_test_2.so", RTLD_LAZY);
void *handle2 = dlopen(argv[2], RTLD_LAZY); // %dynamiclib2
assert(handle2);
void (*bar2)() = (void (*)())dlsym(handle2, "bar");
assert(bar2);
@ -50,7 +49,7 @@ int main(int argc, char **argv) {
// CHECK: PID: [[PID:[0-9]+]]
// CHECK: [[PID]].sancov: 1 PCs written
// CHECK: test_1.so.[[PID]]
// CHECK: test_2.so.[[PID]]
// CHECK: coverage-module-unloaded{{.*}}1.[[PID]]
// CHECK: coverage-module-unloaded{{.*}}2.[[PID]]
// Even though we've unloaded one of the libs we still dump the coverage file
// for that lib (although the data will be inaccurate, it at all useful)
// for that lib (although the data will be inaccurate, if at all useful)

View File

@ -1,5 +1,5 @@
// RUN: %clangxx_asan -fsanitize-coverage=2 -DSHARED %s -shared -o %T/libcoverage_sandboxing_test.so -fPIC
// RUN: %clangxx_asan -fsanitize-coverage=1 %s -o %t -Wl,-R,\$ORIGIN -L%T -lcoverage_sandboxing_test
// RUN: %clangxx_asan -fsanitize-coverage=2 -DSHARED %s -shared -o %dynamiclib -fPIC %ld_flags_rpath_so
// RUN: %clangxx_asan -fsanitize-coverage=1 %s -o %t %ld_flags_rpath_exe
// RUN: export ASAN_OPTIONS=coverage=1:verbosity=1
// RUN: rm -rf %T/coverage_sandboxing_test
// RUN: mkdir %T/coverage_sandboxing_test && cd %T/coverage_sandboxing_test
@ -12,12 +12,12 @@
// RUN: %run %t a b 2>&1 | FileCheck %s --check-prefix=CHECK-sandbox
// RUN: %sancov unpack coverage_sandboxing_test.sancov.packed
// RUN: cd ..
// RUN: %sancov print vanilla/libcoverage_sandboxing_test.so.*.sancov > vanilla.txt
// RUN: %sancov print sandbox1/libcoverage_sandboxing_test.so.*.sancov > sandbox1.txt
// RUN: %sancov print sandbox2/libcoverage_sandboxing_test.so.*.sancov > sandbox2.txt
// RUN: %sancov print vanilla/`basename %dynamiclib`*.sancov > vanilla.txt
// RUN: %sancov print sandbox1/`basename %dynamiclib`*.sancov > sandbox1.txt
// RUN: %sancov print sandbox2/`basename %dynamiclib`*.sancov > sandbox2.txt
// RUN: diff vanilla.txt sandbox1.txt
// RUN: diff vanilla.txt sandbox2.txt
// RUN: cd ../ && rm coverage_sandboxing_test -r
// RUN: rm -r %T/coverage_sandboxing_test
// https://code.google.com/p/address-sanitizer/issues/detail?id=263
// XFAIL: android

View File

@ -1,21 +1,21 @@
// RUN: %clangxx_asan -fsanitize-coverage=1 -DSHARED %s -shared -o %T/libcoverage_test.so -fPIC
// RUN: %clangxx_asan -fsanitize-coverage=1 %s -o %t -Wl,-R,\$ORIGIN -L%T -lcoverage_test
// RUN: %clangxx_asan -fsanitize-coverage=1 -DSHARED %s -shared -o %dynamiclib -fPIC %ld_flags_rpath_so
// RUN: %clangxx_asan -fsanitize-coverage=1 %s %ld_flags_rpath_exe -o %t
// RUN: export ASAN_OPTIONS=coverage=1:verbosity=1
// RUN: rm -rf %T/coverage && mkdir -p %T/coverage && cd %T/coverage
// RUN: %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-main
// RUN: %sancov print coverage.*sancov 2>&1 | FileCheck %s --check-prefix=CHECK-SANCOV1
// RUN: %sancov print `ls coverage.*sancov | grep -v '.so'` 2>&1 | FileCheck %s --check-prefix=CHECK-SANCOV1
// RUN: %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: %sancov print `ls coverage.*sancov | grep -v '.so'` 2>&1 | FileCheck %s --check-prefix=CHECK-SANCOV2
// RUN: %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: %sancov print `ls *coverage.*sancov | grep -v '.so'` 2>&1 | FileCheck %s --check-prefix=CHECK-SANCOV2
// RUN: %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_test.*sancov 2>&1 | FileCheck %s --check-prefix=CHECK-SANCOV1
// RUN: %sancov merge coverage.*sancov > merged-cov
// RUN: %sancov print `ls *coverage.*sancov | grep -v '.so'` 2>&1 | FileCheck %s --check-prefix=CHECK-SANCOV2
// RUN: %sancov print `ls *coverage.*sancov | grep '.so'` 2>&1 | FileCheck %s --check-prefix=CHECK-SANCOV1
// RUN: %sancov merge `ls *coverage.*sancov | grep -v '.so'` > merged-cov
// RUN: %sancov print merged-cov 2>&1 | FileCheck %s --check-prefix=CHECK-SANCOV2
// RUN: not %run %t foo bar 4 2>&1 | FileCheck %s --check-prefix=CHECK-report
// RUN: not %run %t foo bar 4 5 2>&1 | FileCheck %s --check-prefix=CHECK-segv
// RUN: cd .. && rm coverage -r
// RUN: rm -r %T/coverage
//
// https://code.google.com/p/address-sanitizer/issues/detail?id=263
// XFAIL: android