pkgsrc-WIP-changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

compiler-rt-git: Backport patches from upstream review



Module Name:	pkgsrc-wip
Committed By:	Kamil Rytarowski <n54%gmx.com@localhost>
Pushed By:	kamil
Date:		Mon Oct 23 16:30:56 2017 +0200
Changeset:	57ae381f47bf88817a44b588c4b4b310cee864ae

Modified Files:
	compiler-rt-git/PLIST
	compiler-rt-git/distinfo
Added Files:
	compiler-rt-git/patches/patch-lib_asan_asan__interceptors.cc
	compiler-rt-git/patches/patch-lib_msan_msan__interceptors.cc
	compiler-rt-git/patches/patch-lib_msan_msan__linux.cc
	compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__common__interceptors.inc
	compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__internal__defs.h
	compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__linux.cc
	compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__platform__limits__netbsd.cc
	compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__platform__limits__netbsd.h
	compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__syscall__generic.inc
	compiler-rt-git/patches/patch-lib_tsan_go_buildgo.sh
	compiler-rt-git/patches/patch-lib_tsan_rtl_tsan__interceptors.cc
	compiler-rt-git/patches/patch-lib_tsan_rtl_tsan__platform.h
	compiler-rt-git/patches/patch-lib_tsan_rtl_tsan__platform__linux.cc
	compiler-rt-git/patches/patch-lib_tsan_rtl_tsan__platform__posix.cc
	compiler-rt-git/patches/patch-lib_tsan_tests_rtl_tsan__test__util__posix.cc
	compiler-rt-git/patches/patch-test_msan_lit.cfg
	compiler-rt-git/patches/patch-test_tsan_lit.cfg
	compiler-rt-git/patches/patch-test_tsan_map32bit.cc
	compiler-rt-git/patches/patch-test_tsan_strerror__r.cc

Log Message:
compiler-rt-git: Backport patches from upstream review

https://reviews.llvm.org/D39124

Testing them with local patches.

Sync PLIST with upstream.

Sponsored by <The NetBSD Foundation>

To see a diff of this commit:
https://wip.pkgsrc.org/cgi-bin/gitweb.cgi?p=pkgsrc-wip.git;a=commitdiff;h=57ae381f47bf88817a44b588c4b4b310cee864ae

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

diffstat:
 compiler-rt-git/PLIST                              |  12 +-
 compiler-rt-git/distinfo                           |  19 ++
 .../patches/patch-lib_asan_asan__interceptors.cc   |  20 ++
 .../patches/patch-lib_msan_msan__interceptors.cc   | 175 +++++++++++++
 .../patches/patch-lib_msan_msan__linux.cc          |  24 ++
 ...zer__common_sanitizer__common__interceptors.inc |  29 +++
 ...b_sanitizer__common_sanitizer__internal__defs.h |  13 +
 ...patch-lib_sanitizer__common_sanitizer__linux.cc | 276 +++++++++++++++++++++
 ...__common_sanitizer__platform__limits__netbsd.cc |  13 +
 ...r__common_sanitizer__platform__limits__netbsd.h |  13 +
 ...nitizer__common_sanitizer__syscall__generic.inc |  17 ++
 .../patches/patch-lib_tsan_go_buildgo.sh           |  26 ++
 .../patch-lib_tsan_rtl_tsan__interceptors.cc       |  50 ++++
 .../patches/patch-lib_tsan_rtl_tsan__platform.h    |  24 ++
 .../patch-lib_tsan_rtl_tsan__platform__linux.cc    |  24 ++
 .../patch-lib_tsan_rtl_tsan__platform__posix.cc    |  15 ++
 ...h-lib_tsan_tests_rtl_tsan__test__util__posix.cc |  22 ++
 compiler-rt-git/patches/patch-test_msan_lit.cfg    |  14 ++
 compiler-rt-git/patches/patch-test_tsan_lit.cfg    |  14 ++
 .../patches/patch-test_tsan_map32bit.cc            |  20 ++
 .../patches/patch-test_tsan_strerror__r.cc         |  14 ++
 21 files changed, 830 insertions(+), 4 deletions(-)

diffs:
diff --git a/compiler-rt-git/PLIST b/compiler-rt-git/PLIST
index d6b206167f..ee38c6a8de 100644
--- a/compiler-rt-git/PLIST
+++ b/compiler-rt-git/PLIST
@@ -1,5 +1,6 @@
 @comment $NetBSD$
 lib/clang/${PKGVERSION}/asan_blacklist.txt
+lib/clang/${PKGVERSION}/cfi_blacklist.txt
 lib/clang/${PKGVERSION}/include/sanitizer/allocator_interface.h
 lib/clang/${PKGVERSION}/include/sanitizer/asan_interface.h
 lib/clang/${PKGVERSION}/include/sanitizer/common_interface_defs.h
@@ -25,21 +26,24 @@ lib/clang/${PKGVERSION}/lib/${COMPILER_RT_OS_DIR}/libclang_rt.asan_cxx-x86_64.a
 lib/clang/${PKGVERSION}/lib/${COMPILER_RT_OS_DIR}/libclang_rt.asan_cxx-x86_64.a.syms
 lib/clang/${PKGVERSION}/lib/${COMPILER_RT_OS_DIR}/libclang_rt.builtins-i386.a
 lib/clang/${PKGVERSION}/lib/${COMPILER_RT_OS_DIR}/libclang_rt.builtins-x86_64.a
-lib/clang/${PKGVERSION}/lib/${COMPILER_RT_OS_DIR}/libclang_rt.profile-i386.a
-lib/clang/${PKGVERSION}/lib/${COMPILER_RT_OS_DIR}/libclang_rt.profile-x86_64.a
+lib/clang/${PKGVERSION}/lib/${COMPILER_RT_OS_DIR}/libclang_rt.fuzzer-x86_64.a
+lib/clang/${PKGVERSION}/lib/${COMPILER_RT_OS_DIR}/libclang_rt.fuzzer_no_main-x86_64.a
 lib/clang/${PKGVERSION}/lib/${COMPILER_RT_OS_DIR}/libclang_rt.safestack-i386.a
 lib/clang/${PKGVERSION}/lib/${COMPILER_RT_OS_DIR}/libclang_rt.safestack-x86_64.a
 lib/clang/${PKGVERSION}/lib/${COMPILER_RT_OS_DIR}/libclang_rt.stats-i386.a
 lib/clang/${PKGVERSION}/lib/${COMPILER_RT_OS_DIR}/libclang_rt.stats-x86_64.a
 lib/clang/${PKGVERSION}/lib/${COMPILER_RT_OS_DIR}/libclang_rt.stats_client-i386.a
 lib/clang/${PKGVERSION}/lib/${COMPILER_RT_OS_DIR}/libclang_rt.stats_client-x86_64.a
+lib/clang/${PKGVERSION}/lib/${COMPILER_RT_OS_DIR}/libclang_rt.ubsan_minimal-i386.a
+lib/clang/${PKGVERSION}/lib/${COMPILER_RT_OS_DIR}/libclang_rt.ubsan_minimal-i386.so
+lib/clang/${PKGVERSION}/lib/${COMPILER_RT_OS_DIR}/libclang_rt.ubsan_minimal-x86_64.a
+lib/clang/${PKGVERSION}/lib/${COMPILER_RT_OS_DIR}/libclang_rt.ubsan_minimal-x86_64.a.syms
+lib/clang/${PKGVERSION}/lib/${COMPILER_RT_OS_DIR}/libclang_rt.ubsan_minimal-x86_64.so
 lib/clang/${PKGVERSION}/lib/${COMPILER_RT_OS_DIR}/libclang_rt.ubsan_standalone-i386.a
 lib/clang/${PKGVERSION}/lib/${COMPILER_RT_OS_DIR}/libclang_rt.ubsan_standalone-i386.so
 lib/clang/${PKGVERSION}/lib/${COMPILER_RT_OS_DIR}/libclang_rt.ubsan_standalone-x86_64.a
 lib/clang/${PKGVERSION}/lib/${COMPILER_RT_OS_DIR}/libclang_rt.ubsan_standalone-x86_64.a.syms
 lib/clang/${PKGVERSION}/lib/${COMPILER_RT_OS_DIR}/libclang_rt.ubsan_standalone-x86_64.so
 lib/clang/${PKGVERSION}/lib/${COMPILER_RT_OS_DIR}/libclang_rt.ubsan_standalone_cxx-i386.a
-lib/clang/${PKGVERSION}/lib/${COMPILER_RT_OS_DIR}/libclang_rt.ubsan_standalone_cxx-i386.so
 lib/clang/${PKGVERSION}/lib/${COMPILER_RT_OS_DIR}/libclang_rt.ubsan_standalone_cxx-x86_64.a
 lib/clang/${PKGVERSION}/lib/${COMPILER_RT_OS_DIR}/libclang_rt.ubsan_standalone_cxx-x86_64.a.syms
-lib/clang/${PKGVERSION}/lib/${COMPILER_RT_OS_DIR}/libclang_rt.ubsan_standalone_cxx-x86_64.so
diff --git a/compiler-rt-git/distinfo b/compiler-rt-git/distinfo
index 7931384fd5..20080e1051 100644
--- a/compiler-rt-git/distinfo
+++ b/compiler-rt-git/distinfo
@@ -12,3 +12,22 @@ Size (libcxx-3.6.2.src.tar.xz) = 944020 bytes
 SHA1 (llvm-3.6.2.src.tar.xz) = 7a00257eb2bc9431e4c77c3a36b033072c54bc7e
 RMD160 (llvm-3.6.2.src.tar.xz) = 521cbc5fe2925ea3c6e90c7a31f752a04045c972
 Size (llvm-3.6.2.src.tar.xz) = 12802380 bytes
+SHA1 (patch-lib_asan_asan__interceptors.cc) = 74abe6eb1c37b13699f50f9fce646e8090ec8835
+SHA1 (patch-lib_msan_msan__interceptors.cc) = 4d653c4cfd3ac4a2e9b2e24c7cdbd5e1e4d40297
+SHA1 (patch-lib_msan_msan__linux.cc) = 74929d9901d33384d6cb71454e2dbeb4f1832509
+SHA1 (patch-lib_sanitizer__common_sanitizer__common__interceptors.inc) = 11be5158b04de14ea62b4d81f74631258cf13589
+SHA1 (patch-lib_sanitizer__common_sanitizer__internal__defs.h) = ac1a5c5e3f4114d9b7a6825381f0e224a662a40f
+SHA1 (patch-lib_sanitizer__common_sanitizer__linux.cc) = 220c4d42c8094ff9f1ddf54086010686a669832f
+SHA1 (patch-lib_sanitizer__common_sanitizer__platform__limits__netbsd.cc) = ee9e13a10ec519528e34730da7661c6fbc990465
+SHA1 (patch-lib_sanitizer__common_sanitizer__platform__limits__netbsd.h) = 3c707fada208894a66b4f3f40ad69ec5c4b55ded
+SHA1 (patch-lib_sanitizer__common_sanitizer__syscall__generic.inc) = eec3a26027ca2baca69cb2b6f5507951ba1fee2a
+SHA1 (patch-lib_tsan_go_buildgo.sh) = 9bb9aefcae996401348eaafe7dd7979a52f18bc3
+SHA1 (patch-lib_tsan_rtl_tsan__interceptors.cc) = be7dc3faa774a318bf89aef6b8ad77ac282ff474
+SHA1 (patch-lib_tsan_rtl_tsan__platform.h) = efb840bec628ea0653f52eeefdf00750e5e3109d
+SHA1 (patch-lib_tsan_rtl_tsan__platform__linux.cc) = 1c043283951b20c5d6abdbd940b4cb8e527177f2
+SHA1 (patch-lib_tsan_rtl_tsan__platform__posix.cc) = e99a94bd7a925a38cac04b09376d5d0de6648f1b
+SHA1 (patch-lib_tsan_tests_rtl_tsan__test__util__posix.cc) = ec3993dfa325106c8e39b706527f8230253851dc
+SHA1 (patch-test_msan_lit.cfg) = e92693d7e713b657f46c855125411550fca5af6a
+SHA1 (patch-test_tsan_lit.cfg) = c7507f246b35d3179a2476fde5bb941c256894fa
+SHA1 (patch-test_tsan_map32bit.cc) = b30b423661c20420dc718315fe370df6425d84df
+SHA1 (patch-test_tsan_strerror__r.cc) = c67b7d617c5ebe747434be7b600164a0e742bca6
diff --git a/compiler-rt-git/patches/patch-lib_asan_asan__interceptors.cc b/compiler-rt-git/patches/patch-lib_asan_asan__interceptors.cc
new file mode 100644
index 0000000000..0a6e112331
--- /dev/null
+++ b/compiler-rt-git/patches/patch-lib_asan_asan__interceptors.cc
@@ -0,0 +1,20 @@
+$NetBSD$
+
+--- lib/asan/asan_interceptors.cc.orig	2017-10-23 14:29:58.177998728 +0000
++++ lib/asan/asan_interceptors.cc
+@@ -118,9 +118,15 @@ DECLARE_REAL_AND_INTERCEPTOR(void, free,
+ // But asan does not remember UserId's for threads (pthread_t);
+ // and remembers all ever existed threads, so the linear search by UserId
+ // can be slow.
++#if !SANITIZER_NETBSD
+ #define COMMON_INTERCEPTOR_SET_PTHREAD_NAME(ctx, thread, name) \
+   do {                                                         \
+   } while (false)
++#else
++#define COMMON_INTERCEPTOR_SET_PTHREAD_NAME(ctx, thread, name, arg) \
++  do {                                                              \
++  } while (false)
++#endif
+ #define COMMON_INTERCEPTOR_BLOCK_REAL(name) REAL(name)
+ // Strict init-order checking is dlopen-hostile:
+ // https://github.com/google/sanitizers/issues/178
diff --git a/compiler-rt-git/patches/patch-lib_msan_msan__interceptors.cc b/compiler-rt-git/patches/patch-lib_msan_msan__interceptors.cc
new file mode 100644
index 0000000000..f1453cd61a
--- /dev/null
+++ b/compiler-rt-git/patches/patch-lib_msan_msan__interceptors.cc
@@ -0,0 +1,175 @@
+$NetBSD$
+
+--- lib/msan/msan_interceptors.cc.orig	2017-10-20 11:21:05.000000000 +0000
++++ lib/msan/msan_interceptors.cc
+@@ -118,7 +118,7 @@ static void *AllocateFromLocalPool(uptr 
+ #define CHECK_UNPOISONED_STRING(x, n)                           \
+     CHECK_UNPOISONED_STRING_OF_LEN((x), internal_strlen(x), (n))
+ 
+-#if !SANITIZER_FREEBSD
++#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
+ INTERCEPTOR(SIZE_T, fread_unlocked, void *ptr, SIZE_T size, SIZE_T nmemb,
+             void *file) {
+   ENSURE_MSAN_INITED();
+@@ -168,7 +168,7 @@ INTERCEPTOR(int, posix_memalign, void **
+   return res;
+ }
+ 
+-#if !SANITIZER_FREEBSD
++#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
+ INTERCEPTOR(void *, memalign, SIZE_T alignment, SIZE_T size) {
+   GET_MALLOC_STACK_TRACE;
+   return msan_memalign(alignment, size, &stack);
+@@ -196,7 +196,7 @@ INTERCEPTOR(void *, valloc, SIZE_T size)
+   return msan_valloc(size, &stack);
+ }
+ 
+-#if !SANITIZER_FREEBSD
++#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
+ INTERCEPTOR(void *, pvalloc, SIZE_T size) {
+   GET_MALLOC_STACK_TRACE;
+   return msan_pvalloc(size, &stack);
+@@ -212,7 +212,7 @@ INTERCEPTOR(void, free, void *ptr) {
+   MsanDeallocate(&stack, ptr);
+ }
+ 
+-#if !SANITIZER_FREEBSD
++#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
+ INTERCEPTOR(void, cfree, void *ptr) {
+   GET_MALLOC_STACK_TRACE;
+   if (!ptr || UNLIKELY(IsInDlsymAllocPool(ptr))) return;
+@@ -227,7 +227,7 @@ INTERCEPTOR(uptr, malloc_usable_size, vo
+   return __sanitizer_get_allocated_size(ptr);
+ }
+ 
+-#if !SANITIZER_FREEBSD
++#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
+ // This function actually returns a struct by value, but we can't unpoison a
+ // temporary! The following is equivalent on all supported platforms but
+ // aarch64 (which uses a different register for sret value).  We have a test
+@@ -246,7 +246,7 @@ INTERCEPTOR(void, mallinfo, __sanitizer_
+ #define MSAN_MAYBE_INTERCEPT_MALLINFO
+ #endif
+ 
+-#if !SANITIZER_FREEBSD
++#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
+ INTERCEPTOR(int, mallopt, int cmd, int value) {
+   return -1;
+ }
+@@ -255,7 +255,7 @@ INTERCEPTOR(int, mallopt, int cmd, int v
+ #define MSAN_MAYBE_INTERCEPT_MALLOPT
+ #endif
+ 
+-#if !SANITIZER_FREEBSD
++#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
+ INTERCEPTOR(void, malloc_stats, void) {
+   // FIXME: implement, but don't call REAL(malloc_stats)!
+ }
+@@ -308,7 +308,7 @@ INTERCEPTOR(char *, strdup, char *src) {
+   return res;
+ }
+ 
+-#if !SANITIZER_FREEBSD
++#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
+ INTERCEPTOR(char *, __strdup, char *src) {
+   ENSURE_MSAN_INITED();
+   GET_STORE_STACK_TRACE;
+@@ -473,7 +473,7 @@ INTERCEPTOR(SIZE_T, strftime_l, char *s,
+   INTERCEPTOR_STRFTIME_BODY(char, SIZE_T, strftime_l, s, max, format, tm, loc);
+ }
+ 
+-#if !SANITIZER_FREEBSD
++#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
+ INTERCEPTOR(SIZE_T, __strftime_l, char *s, SIZE_T max, const char *format,
+             __sanitizer_tm *tm, void *loc) {
+   INTERCEPTOR_STRFTIME_BODY(char, SIZE_T, __strftime_l, s, max, format, tm,
+@@ -495,7 +495,7 @@ INTERCEPTOR(SIZE_T, wcsftime_l, wchar_t 
+                             loc);
+ }
+ 
+-#if !SANITIZER_FREEBSD
++#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
+ INTERCEPTOR(SIZE_T, __wcsftime_l, wchar_t *s, SIZE_T max, const wchar_t *format,
+             __sanitizer_tm *tm, void *loc) {
+   INTERCEPTOR_STRFTIME_BODY(wchar_t, SIZE_T, __wcsftime_l, s, max, format, tm,
+@@ -614,7 +614,7 @@ INTERCEPTOR(int, putenv, char *string) {
+   return res;
+ }
+ 
+-#if !SANITIZER_FREEBSD
++#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
+ INTERCEPTOR(int, __fxstat, int magic, int fd, void *buf) {
+   ENSURE_MSAN_INITED();
+   int res = REAL(__fxstat)(magic, fd, buf);
+@@ -627,7 +627,7 @@ INTERCEPTOR(int, __fxstat, int magic, in
+ #define MSAN_MAYBE_INTERCEPT___FXSTAT
+ #endif
+ 
+-#if !SANITIZER_FREEBSD
++#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
+ INTERCEPTOR(int, __fxstat64, int magic, int fd, void *buf) {
+   ENSURE_MSAN_INITED();
+   int res = REAL(__fxstat64)(magic, fd, buf);
+@@ -640,7 +640,7 @@ INTERCEPTOR(int, __fxstat64, int magic, 
+ #define MSAN_MAYBE_INTERCEPT___FXSTAT64
+ #endif
+ 
+-#if SANITIZER_FREEBSD
++#if SANITIZER_FREEBSD && !SANITIZER_NETBSD
+ INTERCEPTOR(int, fstatat, int fd, char *pathname, void *buf, int flags) {
+   ENSURE_MSAN_INITED();
+   int res = REAL(fstatat)(fd, pathname, buf, flags);
+@@ -659,7 +659,7 @@ INTERCEPTOR(int, __fxstatat, int magic, 
+ # define MSAN_INTERCEPT_FSTATAT INTERCEPT_FUNCTION(__fxstatat)
+ #endif
+ 
+-#if !SANITIZER_FREEBSD
++#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
+ INTERCEPTOR(int, __fxstatat64, int magic, int fd, char *pathname, void *buf,
+             int flags) {
+   ENSURE_MSAN_INITED();
+@@ -706,7 +706,7 @@ INTERCEPTOR(char *, fgets, char *s, int 
+   return res;
+ }
+ 
+-#if !SANITIZER_FREEBSD
++#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
+ INTERCEPTOR(char *, fgets_unlocked, char *s, int size, void *stream) {
+   ENSURE_MSAN_INITED();
+   char *res = REAL(fgets_unlocked)(s, size, stream);
+@@ -729,7 +729,7 @@ INTERCEPTOR(int, getrlimit, int resource
+   return res;
+ }
+ 
+-#if !SANITIZER_FREEBSD
++#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
+ INTERCEPTOR(int, getrlimit64, int resource, void *rlim) {
+   if (msan_init_is_running) return REAL(getrlimit64)(resource, rlim);
+   ENSURE_MSAN_INITED();
+@@ -805,7 +805,7 @@ INTERCEPTOR(int, gethostname, char *name
+   return res;
+ }
+ 
+-#if !SANITIZER_FREEBSD
++#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
+ INTERCEPTOR(int, epoll_wait, int epfd, void *events, int maxevents,
+     int timeout) {
+   ENSURE_MSAN_INITED();
+@@ -820,7 +820,7 @@ INTERCEPTOR(int, epoll_wait, int epfd, v
+ #define MSAN_MAYBE_INTERCEPT_EPOLL_WAIT
+ #endif
+ 
+-#if !SANITIZER_FREEBSD
++#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
+ INTERCEPTOR(int, epoll_pwait, int epfd, void *events, int maxevents,
+     int timeout, void *sigmask) {
+   ENSURE_MSAN_INITED();
+@@ -909,7 +909,7 @@ INTERCEPTOR(void *, mmap, void *addr, SI
+   return res;
+ }
+ 
+-#if !SANITIZER_FREEBSD
++#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
+ INTERCEPTOR(void *, mmap64, void *addr, SIZE_T length, int prot, int flags,
+             int fd, OFF64_T offset) {
+   ENSURE_MSAN_INITED();
diff --git a/compiler-rt-git/patches/patch-lib_msan_msan__linux.cc b/compiler-rt-git/patches/patch-lib_msan_msan__linux.cc
new file mode 100644
index 0000000000..57d9393647
--- /dev/null
+++ b/compiler-rt-git/patches/patch-lib_msan_msan__linux.cc
@@ -0,0 +1,24 @@
+$NetBSD$
+
+--- lib/msan/msan_linux.cc.orig	2017-07-03 15:33:06.000000000 +0000
++++ lib/msan/msan_linux.cc
+@@ -9,11 +9,11 @@
+ //
+ // This file is a part of MemorySanitizer.
+ //
+-// Linux- and FreeBSD-specific code.
++// Linux-, NetBSD- and FreeBSD-specific code.
+ //===----------------------------------------------------------------------===//
+ 
+ #include "sanitizer_common/sanitizer_platform.h"
+-#if SANITIZER_FREEBSD || SANITIZER_LINUX
++#if SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD
+ 
+ #include "msan.h"
+ #include "msan_thread.h"
+@@ -213,4 +213,4 @@ void MsanTSDDtor(void *tsd) {
+ 
+ } // namespace __msan
+ 
+-#endif // SANITIZER_FREEBSD || SANITIZER_LINUX
++#endif // SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD
diff --git a/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__common__interceptors.inc b/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__common__interceptors.inc
new file mode 100644
index 0000000000..2d3867a290
--- /dev/null
+++ b/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__common__interceptors.inc
@@ -0,0 +1,29 @@
+$NetBSD$
+
+--- lib/sanitizer_common/sanitizer_common_interceptors.inc.orig	2017-10-20 11:21:05.000000000 +0000
++++ lib/sanitizer_common/sanitizer_common_interceptors.inc
+@@ -4405,7 +4405,7 @@ INTERCEPTOR(char *, tempnam, char *dir, 
+ #define INIT_TEMPNAM
+ #endif
+ 
+-#if SANITIZER_INTERCEPT_PTHREAD_SETNAME_NP
++#if SANITIZER_INTERCEPT_PTHREAD_SETNAME_NP && !SANITIZER_NETBSD
+ INTERCEPTOR(int, pthread_setname_np, uptr thread, const char *name) {
+   void *ctx;
+   COMMON_INTERCEPTOR_ENTER(ctx, pthread_setname_np, thread, name);
+@@ -4414,6 +4414,15 @@ INTERCEPTOR(int, pthread_setname_np, upt
+   return REAL(pthread_setname_np)(thread, name);
+ }
+ #define INIT_PTHREAD_SETNAME_NP COMMON_INTERCEPT_FUNCTION(pthread_setname_np);
++#elif SANITIZER_INTERCEPT_PTHREAD_SETNAME_NP && SANITIZER_NETBSD
++INTERCEPTOR(int, pthread_setname_np, uptr thread, const char *name, void *arg) {
++  void *ctx;
++  COMMON_INTERCEPTOR_ENTER(ctx, pthread_setname_np, thread, name, arg);
++  COMMON_INTERCEPTOR_READ_STRING(ctx, name, 0);
++  COMMON_INTERCEPTOR_SET_PTHREAD_NAME(ctx, thread, name, arg);
++  return REAL(pthread_setname_np)(thread, name, arg);
++}
++#define INIT_PTHREAD_SETNAME_NP COMMON_INTERCEPT_FUNCTION(pthread_setname_np);
+ #else
+ #define INIT_PTHREAD_SETNAME_NP
+ #endif
diff --git a/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__internal__defs.h b/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__internal__defs.h
new file mode 100644
index 0000000000..2eaa4a9ea6
--- /dev/null
+++ b/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__internal__defs.h
@@ -0,0 +1,13 @@
+$NetBSD$
+
+--- lib/sanitizer_common/sanitizer_internal_defs.h.orig	2017-10-20 11:21:05.000000000 +0000
++++ lib/sanitizer_common/sanitizer_internal_defs.h
+@@ -36,7 +36,7 @@
+ #endif
+ 
+ // TLS is handled differently on different platforms
+-#if SANITIZER_LINUX
++#if SANITIZER_LINUX || SANITIZER_NETBSD
+ # define SANITIZER_TLS_INITIAL_EXEC_ATTRIBUTE \
+     __attribute__((tls_model("initial-exec"))) thread_local
+ #else
diff --git a/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__linux.cc b/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__linux.cc
new file mode 100644
index 0000000000..d7e26b9258
--- /dev/null
+++ b/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__linux.cc
@@ -0,0 +1,276 @@
+$NetBSD$
+
+--- lib/sanitizer_common/sanitizer_linux.cc.orig	2017-10-20 11:21:05.000000000 +0000
++++ lib/sanitizer_common/sanitizer_linux.cc
+@@ -87,7 +87,9 @@ extern char **environ;  // provided by c
+ #include <limits.h>  // For NAME_MAX
+ #include <sys/sysctl.h>
+ extern char **environ;  // provided by crt1
+-#endif                  // SANITIZER_NETBSD
++#include <sys/exec.h>
++extern struct ps_strings *__ps_strings;
++#endif  // SANITIZER_NETBSD
+ 
+ #if !SANITIZER_ANDROID
+ #include <sys/signal.h>
+@@ -174,11 +176,11 @@ uptr internal_mmap(void *addr, uptr leng
+ #endif // !SANITIZER_S390
+ 
+ uptr internal_munmap(void *addr, uptr length) {
+-  return internal_syscall(SYSCALL(munmap), (uptr)addr, length);
++  return internal_syscall_ptr(SYSCALL(munmap), (uptr)addr, length);
+ }
+ 
+ int internal_mprotect(void *addr, uptr length, int prot) {
+-  return internal_syscall(SYSCALL(mprotect), (uptr)addr, length, prot);
++  return internal_syscall_ptr(SYSCALL(mprotect), (uptr)addr, length, prot);
+ }
+ 
+ uptr internal_close(fd_t fd) {
+@@ -189,7 +191,7 @@ uptr internal_open(const char *filename,
+ #if SANITIZER_USES_CANONICAL_LINUX_SYSCALLS
+   return internal_syscall(SYSCALL(openat), AT_FDCWD, (uptr)filename, flags);
+ #else
+-  return internal_syscall(SYSCALL(open), (uptr)filename, flags);
++  return internal_syscall_ptr(SYSCALL(open), (uptr)filename, flags);
+ #endif
+ }
+ 
+@@ -198,36 +200,28 @@ uptr internal_open(const char *filename,
+   return internal_syscall(SYSCALL(openat), AT_FDCWD, (uptr)filename, flags,
+                           mode);
+ #else
+-  return internal_syscall(SYSCALL(open), (uptr)filename, flags, mode);
++  return internal_syscall_ptr(SYSCALL(open), (uptr)filename, flags, mode);
+ #endif
+ }
+ 
+ uptr internal_read(fd_t fd, void *buf, uptr count) {
+   sptr res;
+-#if SANITIZER_NETBSD
+-  HANDLE_EINTR(res, internal_syscall_ptr(SYSCALL(read), fd, buf, count));
+-#else
+-  HANDLE_EINTR(res, (sptr)internal_syscall(SYSCALL(read), fd, (uptr)buf,
++  HANDLE_EINTR(res, (sptr)internal_syscall_ptr(SYSCALL(read), fd, (uptr)buf,
+                count));
+-#endif
+   return res;
+ }
+ 
+ uptr internal_write(fd_t fd, const void *buf, uptr count) {
+   sptr res;
+-#if SANITIZER_NETBSD
+-  HANDLE_EINTR(res, internal_syscall_ptr(SYSCALL(write), fd, buf, count));
+-#else
+-  HANDLE_EINTR(res, (sptr)internal_syscall(SYSCALL(write), fd, (uptr)buf,
++  HANDLE_EINTR(res, (sptr)internal_syscall_ptr(SYSCALL(write), fd, (uptr)buf,
+                count));
+-#endif
+   return res;
+ }
+ 
+ uptr internal_ftruncate(fd_t fd, uptr size) {
+   sptr res;
+ #if SANITIZER_NETBSD
+-  HANDLE_EINTR(res, internal_syscall(SYSCALL(ftruncate), fd, 0, (s64)size));
++  HANDLE_EINTR(res, internal_syscall64(SYSCALL(ftruncate), fd, 0, (s64)size));
+ #else
+   HANDLE_EINTR(res, (sptr)internal_syscall(SYSCALL(ftruncate), fd,
+                (OFF_T)size));
+@@ -304,7 +298,7 @@ static void kernel_stat_to_stat(struct k
+ 
+ uptr internal_stat(const char *path, void *buf) {
+ #if SANITIZER_FREEBSD || SANITIZER_NETBSD
+-  return internal_syscall(SYSCALL(fstatat), AT_FDCWD, (uptr)path,
++  return internal_syscall_ptr(SYSCALL(fstatat), AT_FDCWD, (uptr)path,
+                           (uptr)buf, 0);
+ #elif SANITIZER_USES_CANONICAL_LINUX_SYSCALLS
+   return internal_syscall(SYSCALL(newfstatat), AT_FDCWD, (uptr)path,
+@@ -329,7 +323,7 @@ uptr internal_stat(const char *path, voi
+ 
+ uptr internal_lstat(const char *path, void *buf) {
+ #if SANITIZER_NETBSD
+-  return internal_syscall(SYSCALL(lstat), path, buf);
++  return internal_syscall_ptr(SYSCALL(lstat), path, buf);
+ #elif SANITIZER_FREEBSD
+   return internal_syscall(SYSCALL(fstatat), AT_FDCWD, (uptr)path,
+                           (uptr)buf, AT_SYMLINK_NOFOLLOW);
+@@ -355,15 +349,15 @@ uptr internal_lstat(const char *path, vo
+ }
+ 
+ uptr internal_fstat(fd_t fd, void *buf) {
+-#if SANITIZER_FREEBSD || SANITIZER_LINUX_USES_64BIT_SYSCALLS || SANITIZER_NETBSD
+-# if SANITIZER_MIPS64
++#if SANITIZER_FREEBSD || SANITIZER_NETBSD || SANITIZER_LINUX_USES_64BIT_SYSCALLS
++# if SANITIZER_MIPS64 && !SANITIZER_NETBSD
+   // For mips64, fstat syscall fills buffer in the format of kernel_stat
+   struct kernel_stat kbuf;
+   int res = internal_syscall(SYSCALL(fstat), fd, &kbuf);
+   kernel_stat_to_stat(&kbuf, (struct stat *)buf);
+   return res;
+ # else
+-  return internal_syscall(SYSCALL(fstat), fd, (uptr)buf);
++  return internal_syscall_ptr(SYSCALL(fstat), fd, (uptr)buf);
+ # endif
+ #else
+   struct stat64 buf64;
+@@ -403,7 +397,7 @@ uptr internal_unlink(const char *path) {
+ #if SANITIZER_USES_CANONICAL_LINUX_SYSCALLS
+   return internal_syscall(SYSCALL(unlinkat), AT_FDCWD, (uptr)path, 0);
+ #else
+-  return internal_syscall(SYSCALL(unlink), (uptr)path);
++  return internal_syscall_ptr(SYSCALL(unlink), (uptr)path);
+ #endif
+ }
+ 
+@@ -412,7 +406,7 @@ uptr internal_rename(const char *oldpath
+   return internal_syscall(SYSCALL(renameat), AT_FDCWD, (uptr)oldpath, AT_FDCWD,
+                           (uptr)newpath);
+ #else
+-  return internal_syscall(SYSCALL(rename), (uptr)oldpath, (uptr)newpath);
++  return internal_syscall_ptr(SYSCALL(rename), (uptr)oldpath, (uptr)newpath);
+ #endif
+ }
+ 
+@@ -433,14 +427,14 @@ unsigned int internal_sleep(unsigned int
+   struct timespec ts;
+   ts.tv_sec = 1;
+   ts.tv_nsec = 0;
+-  int res = internal_syscall(SYSCALL(nanosleep), &ts, &ts);
++  int res = internal_syscall_ptr(SYSCALL(nanosleep), &ts, &ts);
+   if (res) return ts.tv_sec;
+   return 0;
+ }
+ 
+ uptr internal_execve(const char *filename, char *const argv[],
+                      char *const envp[]) {
+-  return internal_syscall(SYSCALL(execve), (uptr)filename, (uptr)argv,
++  return internal_syscall_ptr(SYSCALL(execve), (uptr)filename, (uptr)argv,
+                           (uptr)envp);
+ }
+ 
+@@ -524,13 +518,13 @@ const char *GetEnv(const char *name) {
+ #endif
+ }
+ 
+-#if !SANITIZER_FREEBSD
++#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
+ extern "C" {
+   SANITIZER_WEAK_ATTRIBUTE extern void *__libc_stack_end;
+ }
+ #endif
+ 
+-#if !SANITIZER_GO && !SANITIZER_FREEBSD
++#if !SANITIZER_GO && !SANITIZER_FREEBSD && !SANITIZER_NETBSD
+ static void ReadNullSepFileToArray(const char *path, char ***arr,
+                                    int arr_size) {
+   char *buff;
+@@ -556,7 +550,22 @@ static void ReadNullSepFileToArray(const
+ #endif
+ 
+ static void GetArgsAndEnv(char ***argv, char ***envp) {
+-#if !SANITIZER_FREEBSD
++#if SANITIZER_FREEBSD
++  // On FreeBSD, retrieving the argument and environment arrays is done via the
++  // kern.ps_strings sysctl, which returns a pointer to a structure containing
++  // this information. See also <sys/exec.h>.
++  ps_strings *pss;
++  size_t sz = sizeof(pss);
++  if (sysctlbyname("kern.ps_strings", &pss, &sz, NULL, 0) == -1) {
++    Printf("sysctl kern.ps_strings failed\n");
++    Die();
++  }
++  *argv = pss->ps_argvstr;
++  *envp = pss->ps_envstr;
++#elif SANITIZER_NETBSD
++  *argv = __ps_strings->ps_argvstr;
++  *argv = __ps_strings->ps_envstr;
++#else
+ #if !SANITIZER_GO
+   if (&__libc_stack_end) {
+ #endif
+@@ -571,18 +580,6 @@ static void GetArgsAndEnv(char ***argv, 
+     ReadNullSepFileToArray("/proc/self/environ", envp, kMaxEnvp);
+   }
+ #endif
+-#else
+-  // On FreeBSD, retrieving the argument and environment arrays is done via the
+-  // kern.ps_strings sysctl, which returns a pointer to a structure containing
+-  // this information. See also <sys/exec.h>.
+-  ps_strings *pss;
+-  size_t sz = sizeof(pss);
+-  if (sysctlbyname("kern.ps_strings", &pss, &sz, NULL, 0) == -1) {
+-    Printf("sysctl kern.ps_strings failed\n");
+-    Die();
+-  }
+-  *argv = pss->ps_argvstr;
+-  *envp = pss->ps_envstr;
+ #endif
+ }
+ 
+@@ -594,8 +591,22 @@ char **GetArgv() {
+ 
+ void ReExec() {
+   char **argv, **envp;
++  const char *pathname = "/proc/self/exe";
++
++#if SANITIZER_NETBSD
++  static const int name[] = {
++    CTL_KERN, KERN_PROC_ARGS, -1, KERN_PROC_PATHNAME,
++  };
++  char path[400];
++  size_t len;
++
++  len = sizeof(path);
++  if (sysctl(name, ARRAY_SIZE(name), path, &len, NULL, 0) != -1)
++    pathname = path;
++#endif
++
+   GetArgsAndEnv(&argv, &envp);
+-  uptr rv = internal_execve("/proc/self/exe", argv, envp);
++  uptr rv = internal_execve(pathname, argv, envp);
+   int rverrno;
+   CHECK_EQ(internal_iserror(rv, &rverrno), true);
+   Printf("execve failed, errno %d\n", rverrno);
+@@ -699,7 +710,7 @@ uptr internal_ptrace(int request, int pi
+ 
+ uptr internal_waitpid(int pid, int *status, int options) {
+ #if SANITIZER_NETBSD
+-  return internal_syscall(SYSCALL(wait4), pid, status, options,
++  return internal_syscall_ptr(SYSCALL(wait4), pid, status, options,
+                           NULL /* rusage */);
+ #else
+   return internal_syscall(SYSCALL(wait4), pid, (uptr)status, options,
+@@ -717,7 +728,7 @@ uptr internal_getppid() {
+ 
+ uptr internal_getdents(fd_t fd, struct linux_dirent *dirp, unsigned int count) {
+ #if SANITIZER_NETBSD
+-  return internal_syscall(SYSCALL(getdents), fd, dirp, (uptr)count);
++  return internal_syscall64(SYSCALL(getdents), fd, dirp, (uptr)count);
+ #elif SANITIZER_FREEBSD
+   return internal_syscall(SYSCALL(getdirentries), fd, (uptr)dirp, count, NULL);
+ #elif SANITIZER_USES_CANONICAL_LINUX_SYSCALLS
+@@ -742,7 +753,11 @@ uptr internal_prctl(int option, uptr arg
+ #endif
+ 
+ uptr internal_sigaltstack(const void *ss, void *oss) {
++#if SANITIZER_NETBSD
++  return internal_syscall_ptr(SYSCALL(sigaltstack), (uptr)ss, (uptr)oss);
++#else
+   return internal_syscall(SYSCALL(sigaltstack), (uptr)ss, (uptr)oss);
++#endif
+ }
+ 
+ int internal_fork() {
+@@ -823,8 +838,10 @@ int internal_sigaction_syscall(int signu
+ 
+ uptr internal_sigprocmask(int how, __sanitizer_sigset_t *set,
+     __sanitizer_sigset_t *oldset) {
+-#if SANITIZER_FREEBSD || SANITIZER_NETBSD
++#if SANITIZER_FREEBSD
+   return internal_syscall(SYSCALL(sigprocmask), how, set, oldset);
++#elif SANITIZER_NETBSD
++  return internal_syscall_ptr(SYSCALL(sigprocmask), how, set, oldset);
+ #else
+   __sanitizer_kernel_sigset_t *k_set = (__sanitizer_kernel_sigset_t *)set;
+   __sanitizer_kernel_sigset_t *k_oldset = (__sanitizer_kernel_sigset_t *)oldset;
diff --git a/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__platform__limits__netbsd.cc b/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__platform__limits__netbsd.cc
new file mode 100644
index 0000000000..16f7c9dec8
--- /dev/null
+++ b/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__platform__limits__netbsd.cc
@@ -0,0 +1,13 @@
+$NetBSD$
+
+--- lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc.orig	2017-10-20 11:21:05.000000000 +0000
++++ lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc
+@@ -128,6 +128,8 @@ uptr __sanitizer_in_addr_sz(int af) {
+     return 0;
+ }
+ 
++unsigned struct_ElfW_Phdr_sz = sizeof(Elf_Phdr);
++
+ int glob_nomatch = GLOB_NOMATCH;
+ int glob_altdirfunc = GLOB_ALTDIRFUNC;
+ 
diff --git a/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__platform__limits__netbsd.h b/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__platform__limits__netbsd.h
new file mode 100644
index 0000000000..8c0a2bda2f
--- /dev/null
+++ b/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__platform__limits__netbsd.h
@@ -0,0 +1,13 @@
+$NetBSD$
+
+--- lib/sanitizer_common/sanitizer_platform_limits_netbsd.h.orig	2017-10-20 11:21:05.000000000 +0000
++++ lib/sanitizer_common/sanitizer_platform_limits_netbsd.h
+@@ -313,7 +313,7 @@ struct __sanitizer_wordexp_t {
+   uptr we_nbytes;
+ };
+ 
+-typedef void __sanitizer_FILE;
++typedef char __sanitizer_FILE;
+ #define SANITIZER_HAS_STRUCT_FILE 0
+ 
+ extern int shmctl_ipc_stat;
diff --git a/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__syscall__generic.inc b/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__syscall__generic.inc
new file mode 100644
index 0000000000..3467876683
--- /dev/null
+++ b/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__syscall__generic.inc
@@ -0,0 +1,17 @@
+$NetBSD$
+
+--- lib/sanitizer_common/sanitizer_syscall_generic.inc.orig	2017-08-05 14:29:08.000000000 +0000
++++ lib/sanitizer_common/sanitizer_syscall_generic.inc
+@@ -43,8 +43,12 @@
+ # endif
+ #elif defined(__x86_64__) && (SANITIZER_FREEBSD || SANITIZER_MAC)
+ # define internal_syscall __syscall
++# define internal_syscall64 __syscall
++# define internal_syscall_ptr __syscall
+ # else
+ # define internal_syscall syscall
++# define internal_syscall64 syscall
++# define internal_syscall_ptr syscall
+ #endif
+ 
+ bool internal_iserror(uptr retval, int *rverrno) {
diff --git a/compiler-rt-git/patches/patch-lib_tsan_go_buildgo.sh b/compiler-rt-git/patches/patch-lib_tsan_go_buildgo.sh
new file mode 100644
index 0000000000..91d68d3015
--- /dev/null
+++ b/compiler-rt-git/patches/patch-lib_tsan_go_buildgo.sh
@@ -0,0 +1,26 @@
+$NetBSD$
+
+--- lib/tsan/go/buildgo.sh.orig	2017-10-20 11:21:05.000000000 +0000
++++ lib/tsan/go/buildgo.sh
+@@ -68,6 +68,21 @@ elif [ "`uname -a | grep FreeBSD`" != ""
+ 		../../sanitizer_common/sanitizer_linux_libcdep.cc
+ 		../../sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc
+ 	"
++elif [ "`uname -a | grep NetBSD`" != "" ]; then
++	SUFFIX="netbsd_amd64"
++	OSCFLAGS="-fno-strict-aliasing -fPIC -Werror"
++	OSLDFLAGS="-lpthread -fPIC -fpie"
++	SRCS="
++		$SRCS
++		../rtl/tsan_platform_linux.cc
++		../../sanitizer_common/sanitizer_posix.cc
++		../../sanitizer_common/sanitizer_posix_libcdep.cc
++		../../sanitizer_common/sanitizer_procmaps_common.cc
++		../../sanitizer_common/sanitizer_procmaps_freebsd.cc
++		../../sanitizer_common/sanitizer_linux.cc
++		../../sanitizer_common/sanitizer_linux_libcdep.cc
++		../../sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc
++	"
+ elif [ "`uname -a | grep Darwin`" != "" ]; then
+ 	SUFFIX="darwin_amd64"
+ 	OSCFLAGS="-fPIC -Wno-unused-const-variable -Wno-unknown-warning-option -isysroot $(xcodebuild -version -sdk macosx Path) -mmacosx-version-min=10.7"
diff --git a/compiler-rt-git/patches/patch-lib_tsan_rtl_tsan__interceptors.cc b/compiler-rt-git/patches/patch-lib_tsan_rtl_tsan__interceptors.cc
new file mode 100644
index 0000000000..f586e88174
--- /dev/null
+++ b/compiler-rt-git/patches/patch-lib_tsan_rtl_tsan__interceptors.cc
@@ -0,0 +1,50 @@
+$NetBSD$
+
+--- lib/tsan/rtl/tsan_interceptors.cc.orig	2017-10-20 11:21:05.000000000 +0000
++++ lib/tsan/rtl/tsan_interceptors.cc
+@@ -43,8 +43,16 @@ using namespace __tsan;  // NOLINT
+ #if SANITIZER_NETBSD
+ #define dirfd(dirp) (*(int *)(dirp))
+ #define fileno_unlocked fileno
+-#define stdout __sF[1]
+-#define stderr __sF[2]
++
++#if _LP64
++#define __sF_size 152
++#else
++#define __sF_size 88
++#endif
++
++#define stdout ((char*)&__sF + (__sF_size * 1))
++#define stderr ((char*)&__sF + (__sF_size * 2))
++
+ #endif
+ 
+ #if SANITIZER_ANDROID
+@@ -99,7 +107,7 @@ extern "C" int dirfd(void *dirp);
+ extern "C" int mallopt(int param, int value);
+ #endif
+ #if SANITIZER_NETBSD
+-extern __sanitizer_FILE **__sF;
++extern __sanitizer_FILE __sF[];
+ #else
+ extern __sanitizer_FILE *stdout, *stderr;
+ #endif
+@@ -2248,8 +2256,17 @@ static void HandleRecvmsg(ThreadState *t
+ #define COMMON_INTERCEPTOR_SET_THREAD_NAME(ctx, name) \
+   ThreadSetName(((TsanInterceptorContext *) ctx)->thr, name)
+ 
++#if !SANITIZER_NETBSD
+ #define COMMON_INTERCEPTOR_SET_PTHREAD_NAME(ctx, thread, name) \
+   __tsan::ctx->thread_registry->SetThreadNameByUserId(thread, name)
++#else
++#define COMMON_INTERCEPTOR_SET_PTHREAD_NAME(ctx, thread, name, arg) \
++  do { \
++    char newname[32]; \
++    internal_snprintf(newname, sizeof(newname), name, arg); \
++    __tsan::ctx->thread_registry->SetThreadNameByUserId(thread, newname); \
++  } while(0)
++#endif
+ 
+ #define COMMON_INTERCEPTOR_BLOCK_REAL(name) BLOCK_REAL(name)
+ 
diff --git a/compiler-rt-git/patches/patch-lib_tsan_rtl_tsan__platform.h b/compiler-rt-git/patches/patch-lib_tsan_rtl_tsan__platform.h
new file mode 100644
index 0000000000..d9bb55fe31
--- /dev/null
+++ b/compiler-rt-git/patches/patch-lib_tsan_rtl_tsan__platform.h
@@ -0,0 +1,24 @@
+$NetBSD$
+
+--- lib/tsan/rtl/tsan_platform.h.orig	2017-08-05 14:29:08.000000000 +0000
++++ lib/tsan/rtl/tsan_platform.h
+@@ -42,6 +42,19 @@ C/C++ on linux/x86_64 and freebsd/x86_64
+ 7b00 0000 0000 - 7c00 0000 0000: heap
+ 7c00 0000 0000 - 7e80 0000 0000: -
+ 7e80 0000 0000 - 8000 0000 0000: modules and main thread stack
++
++C/C++ on netbsd/amd64 can reuse the same mapping:
++ * The address space starts from 0x1000 (option with 0x0) and ends with
++   0x7f7ffffff000.
++ * LoAppMem-kHeapMemEnd can be reused as it is.
++ * No VDSO support.
++ * No MidAppMem region.
++ * No additional HeapMem region.
++ * HiAppMem contains the stack, loader, shared libraries and heap.
++ * Stack on NetBSD/amd64 has prereserved 128MB.
++ * Heap grows downwards (top-down).
++ * ASLR must be disabled per-process or globally.
++
+ */
+ struct Mapping {
+   static const uptr kMetaShadowBeg = 0x300000000000ull;
diff --git a/compiler-rt-git/patches/patch-lib_tsan_rtl_tsan__platform__linux.cc b/compiler-rt-git/patches/patch-lib_tsan_rtl_tsan__platform__linux.cc
new file mode 100644
index 0000000000..53cbd28304
--- /dev/null
+++ b/compiler-rt-git/patches/patch-lib_tsan_rtl_tsan__platform__linux.cc
@@ -0,0 +1,24 @@
+$NetBSD$
+
+--- lib/tsan/rtl/tsan_platform_linux.cc.orig	2017-08-05 14:29:08.000000000 +0000
++++ lib/tsan/rtl/tsan_platform_linux.cc
+@@ -14,11 +14,12 @@
+ 
+ 
+ #include "sanitizer_common/sanitizer_platform.h"
+-#if SANITIZER_LINUX || SANITIZER_FREEBSD
++#if SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD
+ 
+ #include "sanitizer_common/sanitizer_common.h"
+ #include "sanitizer_common/sanitizer_libc.h"
+ #include "sanitizer_common/sanitizer_linux.h"
++#include "sanitizer_common/sanitizer_platform_limits_netbsd.h"
+ #include "sanitizer_common/sanitizer_platform_limits_posix.h"
+ #include "sanitizer_common/sanitizer_posix.h"
+ #include "sanitizer_common/sanitizer_procmaps.h"
+@@ -401,4 +402,4 @@ void cur_thread_finalize() {
+ 
+ }  // namespace __tsan
+ 
+-#endif  // SANITIZER_LINUX || SANITIZER_FREEBSD
++#endif  // SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD
diff --git a/compiler-rt-git/patches/patch-lib_tsan_rtl_tsan__platform__posix.cc b/compiler-rt-git/patches/patch-lib_tsan_rtl_tsan__platform__posix.cc
new file mode 100644
index 0000000000..189e50c2dc
--- /dev/null
+++ b/compiler-rt-git/patches/patch-lib_tsan_rtl_tsan__platform__posix.cc
@@ -0,0 +1,15 @@
+$NetBSD$
+
+--- lib/tsan/rtl/tsan_platform_posix.cc.orig	2017-08-05 14:29:08.000000000 +0000
++++ lib/tsan/rtl/tsan_platform_posix.cc
+@@ -124,8 +124,10 @@ void CheckAndProtect() {
+     if (segment.start >= HeapMemEnd() && segment.start < HeapEnd()) continue;
+     if (segment.protection == 0)  // Zero page or mprotected.
+       continue;
++#if !SANITIZER_NETBSD
+     if (segment.start >= VdsoBeg())  // vdso
+       break;
++#endif
+     Printf("FATAL: ThreadSanitizer: unexpected memory mapping %p-%p\n",
+            segment.start, segment.end);
+     Die();
diff --git a/compiler-rt-git/patches/patch-lib_tsan_tests_rtl_tsan__test__util__posix.cc b/compiler-rt-git/patches/patch-lib_tsan_tests_rtl_tsan__test__util__posix.cc
new file mode 100644
index 0000000000..69127891b2
--- /dev/null
+++ b/compiler-rt-git/patches/patch-lib_tsan_tests_rtl_tsan__test__util__posix.cc
@@ -0,0 +1,22 @@
+$NetBSD$
+
+--- lib/tsan/tests/rtl/tsan_test_util_posix.cc.orig	2017-07-03 15:33:06.000000000 +0000
++++ lib/tsan/tests/rtl/tsan_test_util_posix.cc
+@@ -9,7 +9,7 @@
+ //
+ // This file is a part of ThreadSanitizer (TSan), a race detector.
+ //
+-// Test utils, Linux, FreeBSD and Darwin implementation.
++// Test utils, Linux, FreeBSD, NetBSD and Darwin implementation.
+ //===----------------------------------------------------------------------===//
+ 
+ #include "sanitizer_common/sanitizer_atomic.h"
+@@ -270,7 +270,7 @@ void ScopedThread::Impl::HandleEvent(Eve
+       }
+     }
+     CHECK_NE(tsan_mop, 0);
+-#if defined(__FreeBSD__) || defined(__APPLE__)
++#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__NetBSD__)
+     const int ErrCode = ESOCKTNOSUPPORT;
+ #else
+     const int ErrCode = ECHRNG;
diff --git a/compiler-rt-git/patches/patch-test_msan_lit.cfg b/compiler-rt-git/patches/patch-test_msan_lit.cfg
new file mode 100644
index 0000000000..6b6e67762a
--- /dev/null
+++ b/compiler-rt-git/patches/patch-test_msan_lit.cfg
@@ -0,0 +1,14 @@
+$NetBSD$
+
+--- test/msan/lit.cfg.orig	2017-10-20 11:21:05.000000000 +0000
++++ test/msan/lit.cfg
+@@ -29,8 +29,7 @@ config.substitutions.append( ("%clangxx_
+ # Default test suffixes.
+ config.suffixes = ['.c', '.cc', '.cpp']
+ 
+-# MemorySanitizer tests are currently supported on Linux only.
+-if config.host_os not in ['Linux']:
++if config.host_os not in ['Linux', 'NetBSD']:
+   config.unsupported = True
+ 
+ # For mips64, mips64el we have forced store_context_size to 1 because these
diff --git a/compiler-rt-git/patches/patch-test_tsan_lit.cfg b/compiler-rt-git/patches/patch-test_tsan_lit.cfg
new file mode 100644
index 0000000000..1428200137
--- /dev/null
+++ b/compiler-rt-git/patches/patch-test_tsan_lit.cfg
@@ -0,0 +1,14 @@
+$NetBSD$
+
+--- test/tsan/lit.cfg.orig	2017-10-20 11:21:05.000000000 +0000
++++ test/tsan/lit.cfg
+@@ -79,8 +79,7 @@ config.substitutions.append( ("%deflake 
+ # Default test suffixes.
+ config.suffixes = ['.c', '.cc', '.cpp', '.m', '.mm']
+ 
+-# ThreadSanitizer tests are currently supported on FreeBSD, Linux and Darwin.
+-if config.host_os not in ['FreeBSD', 'Linux', 'Darwin']:
++if config.host_os not in ['FreeBSD', 'Linux', 'Darwin', 'NetBSD']:
+   config.unsupported = True
+ 
+ if config.android:
diff --git a/compiler-rt-git/patches/patch-test_tsan_map32bit.cc b/compiler-rt-git/patches/patch-test_tsan_map32bit.cc
new file mode 100644
index 0000000000..fffc498f29
--- /dev/null
+++ b/compiler-rt-git/patches/patch-test_tsan_map32bit.cc
@@ -0,0 +1,20 @@
+$NetBSD$
+
+--- test/tsan/map32bit.cc.orig	2017-07-03 15:33:06.000000000 +0000
++++ test/tsan/map32bit.cc
+@@ -12,8 +12,8 @@
+ // XFAIL: aarch64
+ // XFAIL: powerpc64
+ 
+-// MAP_32BIT doesn't exist on OS X.
+-// UNSUPPORTED: darwin
++// MAP_32BIT doesn't exist on OS X and NetBSD.
++// UNSUPPORTED: darwin,netbsd
+ 
+ void *Thread(void *ptr) {
+   *(int*)ptr = 42;
+@@ -45,4 +45,3 @@ int main() {
+ 
+ // CHECK: WARNING: ThreadSanitizer: data race
+ // CHECK: DONE
+-
diff --git a/compiler-rt-git/patches/patch-test_tsan_strerror__r.cc b/compiler-rt-git/patches/patch-test_tsan_strerror__r.cc
new file mode 100644
index 0000000000..3b0b08b789
--- /dev/null
+++ b/compiler-rt-git/patches/patch-test_tsan_strerror__r.cc
@@ -0,0 +1,14 @@
+$NetBSD$
+
+--- test/tsan/strerror_r.cc.orig	2017-07-03 15:33:06.000000000 +0000
++++ test/tsan/strerror_r.cc
+@@ -11,7 +11,8 @@
+ char buffer[1000];
+ 
+ void *Thread(void *p) {
+-  return strerror_r(TEST_ERROR, buffer, sizeof(buffer));
++  strerror_r(TEST_ERROR, buffer, sizeof(buffer));
++  return buffer;
+ }
+ 
+ int main() {



Home | Main Index | Thread Index | Old Index