summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Carlier <devnexen@gmail.com>2018-10-04 20:58:18 +0000
committerDavid Carlier <devnexen@gmail.com>2018-10-04 20:58:18 +0000
commit51b40fa2eafc676c26a0cc134a584de529745624 (patch)
tree930f8502a0b604eeef714bd5c3a419bbdc6b8d93
parentfea7ddb36e42bbb07faae66b771b52eaf88bfd0d (diff)
[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
-rw-r--r--compiler-rt/cmake/config-ix.cmake2
-rw-r--r--compiler-rt/lib/esan/CMakeLists.txt1
-rw-r--r--compiler-rt/lib/esan/esan_interceptors.cpp10
-rw-r--r--compiler-rt/lib/esan/esan_shadow.h2
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_linux.cc14
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_linux.h2
-rw-r--r--compiler-rt/test/esan/TestCases/large-stack-linux.c2
-rw-r--r--compiler-rt/test/esan/TestCases/workingset-early-fault.c2
-rw-r--r--compiler-rt/test/esan/TestCases/workingset-memset.cpp2
-rw-r--r--compiler-rt/test/esan/TestCases/workingset-midreport.cpp2
-rw-r--r--compiler-rt/test/esan/TestCases/workingset-samples.cpp2
-rw-r--r--compiler-rt/test/esan/TestCases/workingset-signal-posix.cpp2
-rw-r--r--compiler-rt/test/esan/TestCases/workingset-simple.cpp2
-rw-r--r--compiler-rt/test/esan/lit.cfg3
14 files changed, 39 insertions, 9 deletions
diff --git a/compiler-rt/cmake/config-ix.cmake b/compiler-rt/cmake/config-ix.cmake
index 6ab79dc762b..27097b7e9b3 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 4de5c0205c1..c880971e3dd 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 0c596f1cf37..833faa2cd5b 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 72a919a190d..b76a9ccbd9e 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 98c2c682bc0..2e01149ae07 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<sigset_t *>(set);
+ sigdelset(rset, signum);
+}
+
+bool internal_sigismember(__sanitizer_sigset_t *set, int signum) {
+ sigset_t *rset = reinterpret_cast<sigset_t *>(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 975d6541d88..8322f4e083b 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/<pid>/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 1af32f8ba25..17d88674ba1 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 <assert.h>
#include <stdio.h>
diff --git a/compiler-rt/test/esan/TestCases/workingset-early-fault.c b/compiler-rt/test/esan/TestCases/workingset-early-fault.c
index 1c420c368ca..971285b3f81 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 <stdio.h>
#include <stdlib.h>
diff --git a/compiler-rt/test/esan/TestCases/workingset-memset.cpp b/compiler-rt/test/esan/TestCases/workingset-memset.cpp
index 9c972ec7a73..56ed2f5b7c4 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 <stdlib.h>
#include <string.h>
diff --git a/compiler-rt/test/esan/TestCases/workingset-midreport.cpp b/compiler-rt/test/esan/TestCases/workingset-midreport.cpp
index 38c37655438..acd1eed1761 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 <sanitizer/esan_interface.h>
#include <sched.h>
diff --git a/compiler-rt/test/esan/TestCases/workingset-samples.cpp b/compiler-rt/test/esan/TestCases/workingset-samples.cpp
index d97b62ba4e8..1f8e97dadcc 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 <sanitizer/esan_interface.h>
#include <sched.h>
diff --git a/compiler-rt/test/esan/TestCases/workingset-signal-posix.cpp b/compiler-rt/test/esan/TestCases/workingset-signal-posix.cpp
index ba776fc02ed..6f9787bd73e 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 <assert.h>
#include <setjmp.h>
diff --git a/compiler-rt/test/esan/TestCases/workingset-simple.cpp b/compiler-rt/test/esan/TestCases/workingset-simple.cpp
index f1ac2ecfe13..dc17bcfd540 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 <stdlib.h>
#include <string.h>
diff --git a/compiler-rt/test/esan/lit.cfg b/compiler-rt/test/esan/lit.cfg
index 8b8457d66e0..1bb34ee0865 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