From bbe5d55fea9d25fc2e4a0deeb5531e6010a81646 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Thu, 4 Oct 2018 20:58:18 +0000 Subject: [PATCH] [Esan] Port cache frag to FreeBSD Data involving struct accesses accounting work (plan to support only efficiency-cache-frag flag in the frontend side). Reviewers: krytarowski, vitalybuka, jfb Reviewed By : vitalybuka Differential Revision: https://reviews.llvm.org/D52608 llvm-svn: 343812 --- compiler-rt/cmake/config-ix.cmake | 2 +- compiler-rt/lib/esan/CMakeLists.txt | 1 + compiler-rt/lib/esan/esan_interceptors.cpp | 10 +++++++--- compiler-rt/lib/esan/esan_shadow.h | 2 +- compiler-rt/lib/sanitizer_common/sanitizer_linux.cc | 14 ++++++++++++-- compiler-rt/lib/sanitizer_common/sanitizer_linux.h | 2 ++ compiler-rt/test/esan/TestCases/large-stack-linux.c | 2 ++ compiler-rt/test/esan/TestCases/workingset-early-fault.c | 2 ++ compiler-rt/test/esan/TestCases/workingset-memset.cpp | 2 ++ compiler-rt/test/esan/TestCases/workingset-midreport.cpp | 2 ++ compiler-rt/test/esan/TestCases/workingset-samples.cpp | 2 ++ .../test/esan/TestCases/workingset-signal-posix.cpp | 2 ++ compiler-rt/test/esan/TestCases/workingset-simple.cpp | 2 ++ compiler-rt/test/esan/lit.cfg | 3 +-- 14 files changed, 39 insertions(+), 9 deletions(-) diff --git a/compiler-rt/cmake/config-ix.cmake b/compiler-rt/cmake/config-ix.cmake index 6ab79dc..27097b7 100644 --- a/compiler-rt/cmake/config-ix.cmake +++ b/compiler-rt/cmake/config-ix.cmake @@ -625,7 +625,7 @@ else() endif() if (COMPILER_RT_HAS_SANITIZER_COMMON AND ESAN_SUPPORTED_ARCH AND - OS_NAME MATCHES "Linux") + OS_NAME MATCHES "Linux|FreeBSD") set(COMPILER_RT_HAS_ESAN TRUE) else() set(COMPILER_RT_HAS_ESAN FALSE) diff --git a/compiler-rt/lib/esan/CMakeLists.txt b/compiler-rt/lib/esan/CMakeLists.txt index 4de5c02..c880971 100644 --- a/compiler-rt/lib/esan/CMakeLists.txt +++ b/compiler-rt/lib/esan/CMakeLists.txt @@ -14,6 +14,7 @@ set(ESAN_SOURCES esan_interceptors.cpp esan_linux.cpp esan_sideline_linux.cpp + esan_sideline_bsd.cpp cache_frag.cpp working_set.cpp working_set_posix.cpp) diff --git a/compiler-rt/lib/esan/esan_interceptors.cpp b/compiler-rt/lib/esan/esan_interceptors.cpp index 0c596f1..833faa2 100644 --- a/compiler-rt/lib/esan/esan_interceptors.cpp +++ b/compiler-rt/lib/esan/esan_interceptors.cpp @@ -327,7 +327,7 @@ INTERCEPTOR(int, rmdir, char *path) { // Signal-related interceptors //===----------------------------------------------------------------------===// -#if SANITIZER_LINUX +#if SANITIZER_LINUX || SANITIZER_FREEBSD typedef void (*signal_handler_t)(int); INTERCEPTOR(signal_handler_t, signal, int signum, signal_handler_t handler) { void *ctx; @@ -344,7 +344,7 @@ INTERCEPTOR(signal_handler_t, signal, int signum, signal_handler_t handler) { #define ESAN_MAYBE_INTERCEPT_SIGNAL #endif -#if SANITIZER_LINUX +#if SANITIZER_LINUX || SANITIZER_FREEBSD DECLARE_REAL(int, sigaction, int signum, const struct sigaction *act, struct sigaction *oldact) INTERCEPTOR(int, sigaction, int signum, const struct sigaction *act, @@ -363,7 +363,11 @@ int real_sigaction(int signum, const void *act, void *oldact) { if (REAL(sigaction) == nullptr) { // With an instrumented allocator, this is called during interceptor init // and we need a raw syscall solution. +#if SANITIZER_LINUX return internal_sigaction_syscall(signum, act, oldact); +#else + return internal_sigaction(signum, act, oldact); +#endif } return REAL(sigaction)(signum, (const struct sigaction *)act, (struct sigaction *)oldact); @@ -376,7 +380,7 @@ int real_sigaction(int signum, const void *act, void *oldact) { #define ESAN_MAYBE_INTERCEPT_SIGACTION #endif -#if SANITIZER_LINUX +#if SANITIZER_LINUX || SANITIZER_FREEBSD INTERCEPTOR(int, sigprocmask, int how, __sanitizer_sigset_t *set, __sanitizer_sigset_t *oldset) { void *ctx; diff --git a/compiler-rt/lib/esan/esan_shadow.h b/compiler-rt/lib/esan/esan_shadow.h index 72a919a..b76a9cc 100644 --- a/compiler-rt/lib/esan/esan_shadow.h +++ b/compiler-rt/lib/esan/esan_shadow.h @@ -30,7 +30,7 @@ struct ApplicationRegion { bool ShadowMergedWithPrev; }; -#if SANITIZER_LINUX && defined(__x86_64__) +#if (SANITIZER_LINUX || SANITIZER_FREEBSD) && defined(__x86_64__) // Linux x86_64 // // Application memory falls into these 5 regions (ignoring the corner case diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc index 98c2c68..2e01149 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc @@ -906,8 +906,18 @@ bool internal_sigismember(__sanitizer_sigset_t *set, int signum) { const uptr bit = signum % (sizeof(k_set->sig[0]) * 8); return k_set->sig[idx] & (1 << bit); } -#endif // SANITIZER_LINUX -#endif // !SANITIZER_SOLARIS && !SANITIZER_NETBSD +#elif SANITIZER_FREEBSD +void internal_sigdelset(__sanitizer_sigset_t *set, int signum) { + sigset_t *rset = reinterpret_cast(set); + sigdelset(rset, signum); +} + +bool internal_sigismember(__sanitizer_sigset_t *set, int signum) { + sigset_t *rset = reinterpret_cast(set); + return sigismember(rset, signum); +} +#endif +#endif // !SANITIZER_SOLARIS #if !SANITIZER_NETBSD // ThreadLister implementation. diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.h b/compiler-rt/lib/sanitizer_common/sanitizer_linux.h index 975d654..8322f4e 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.h @@ -69,6 +69,8 @@ void internal_sigdelset(__sanitizer_sigset_t *set, int signum); uptr internal_clone(int (*fn)(void *), void *child_stack, int flags, void *arg, int *parent_tidptr, void *newtls, int *child_tidptr); #endif +#elif SANITIZER_FREEBSD +void internal_sigdelset(__sanitizer_sigset_t *set, int signum); #endif // SANITIZER_LINUX // This class reads thread IDs from /proc//task using only syscalls. diff --git a/compiler-rt/test/esan/TestCases/large-stack-linux.c b/compiler-rt/test/esan/TestCases/large-stack-linux.c index 1af32f8..17d8867 100644 --- a/compiler-rt/test/esan/TestCases/large-stack-linux.c +++ b/compiler-rt/test/esan/TestCases/large-stack-linux.c @@ -1,5 +1,7 @@ // RUN: %clang_esan_wset -O0 %s -o %t 2>&1 // RUN: %env_esan_opts="verbosity=1 record_snapshots=0" %run %t %t 2>&1 | FileCheck %s +// Stucks at init and no clone feature equivalent. +// UNSUPPORTED: freebsd #include #include diff --git a/compiler-rt/test/esan/TestCases/workingset-early-fault.c b/compiler-rt/test/esan/TestCases/workingset-early-fault.c index 1c420c3..971285b 100644 --- a/compiler-rt/test/esan/TestCases/workingset-early-fault.c +++ b/compiler-rt/test/esan/TestCases/workingset-early-fault.c @@ -3,6 +3,8 @@ // // RUN: %clang_esan_wset %s -o %t // RUN: %run %t 2>&1 | FileCheck %s +// Stucks at init and no clone feature equivalent. +// UNSUPPORTED: freebsd #include #include diff --git a/compiler-rt/test/esan/TestCases/workingset-memset.cpp b/compiler-rt/test/esan/TestCases/workingset-memset.cpp index 9c972ec..56ed2f5 100644 --- a/compiler-rt/test/esan/TestCases/workingset-memset.cpp +++ b/compiler-rt/test/esan/TestCases/workingset-memset.cpp @@ -1,5 +1,7 @@ // RUN: %clang_esan_wset -O0 %s -o %t 2>&1 // RUN: %run %t 2>&1 | FileCheck %s +// Stucks at init and no clone feature equivalent. +// UNSUPPORTED: freebsd #include #include diff --git a/compiler-rt/test/esan/TestCases/workingset-midreport.cpp b/compiler-rt/test/esan/TestCases/workingset-midreport.cpp index 38c3765..acd1eed 100644 --- a/compiler-rt/test/esan/TestCases/workingset-midreport.cpp +++ b/compiler-rt/test/esan/TestCases/workingset-midreport.cpp @@ -6,6 +6,8 @@ // FIXME: Re-enable once PR33590 is fixed. // UNSUPPORTED: x86_64 +// Stucks at init and no clone feature equivalent. +// UNSUPPORTED: freebsd #include #include diff --git a/compiler-rt/test/esan/TestCases/workingset-samples.cpp b/compiler-rt/test/esan/TestCases/workingset-samples.cpp index d97b62b..1f8e97d 100644 --- a/compiler-rt/test/esan/TestCases/workingset-samples.cpp +++ b/compiler-rt/test/esan/TestCases/workingset-samples.cpp @@ -3,6 +3,8 @@ // FIXME: Re-enable once PR33590 is fixed. // UNSUPPORTED: x86_64 +// Stucks at init and no clone feature equivalent. +// UNSUPPORTED: freebsd #include #include diff --git a/compiler-rt/test/esan/TestCases/workingset-signal-posix.cpp b/compiler-rt/test/esan/TestCases/workingset-signal-posix.cpp index ba776fc..6f9787b 100644 --- a/compiler-rt/test/esan/TestCases/workingset-signal-posix.cpp +++ b/compiler-rt/test/esan/TestCases/workingset-signal-posix.cpp @@ -1,5 +1,7 @@ // RUN: %clang_esan_wset -O0 %s -o %t 2>&1 // RUN: %run %t 2>&1 | FileCheck %s +// Stucks at init and no clone feature equivalent. +// UNSUPPORTED: freebsd #include #include diff --git a/compiler-rt/test/esan/TestCases/workingset-simple.cpp b/compiler-rt/test/esan/TestCases/workingset-simple.cpp index f1ac2ec..dc17bcf 100644 --- a/compiler-rt/test/esan/TestCases/workingset-simple.cpp +++ b/compiler-rt/test/esan/TestCases/workingset-simple.cpp @@ -3,6 +3,8 @@ // FIXME: Re-enable once PR33590 is fixed. // UNSUPPORTED: x86_64 +// Stucks at init and no clone feature equivalent. +// UNSUPPORTED: freebsd #include #include diff --git a/compiler-rt/test/esan/lit.cfg b/compiler-rt/test/esan/lit.cfg index 8b8457d..1bb34ee 100644 --- a/compiler-rt/test/esan/lit.cfg +++ b/compiler-rt/test/esan/lit.cfg @@ -39,6 +39,5 @@ config.substitutions.append(('%env_esan_opts=', # Default test suffixes. config.suffixes = ['.c', '.cpp'] -# EfficiencySanitizer tests are currently supported on Linux x86-64 only. -if config.host_os not in ['Linux'] or config.target_arch not in ['x86_64', 'mips64'] : +if config.host_os not in ['Linux', 'FreeBSD'] or config.target_arch not in ['x86_64', 'mips64'] : config.unsupported = True -- 2.7.4