pkgsrc-WIP-changes archive

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

compiler-rt-git: Add asan for NetBSD



Module Name:	pkgsrc-wip
Committed By:	Kamil Rytarowski <n54%gmx.com@localhost>
Pushed By:	kamil
Date:		Mon Jul 3 17:49:57 2017 +0200
Changeset:	c09ffd0c5e04a16aadf613a36f6d0c64b12ac6a8

Modified Files:
	compiler-rt-git/Makefile
	compiler-rt-git/PLIST
	compiler-rt-git/distinfo
Added Files:
	compiler-rt-git/patches/patch-cmake_config-ix.cmake
	compiler-rt-git/patches/patch-lib_asan_asan__interceptors.cc
	compiler-rt-git/patches/patch-lib_asan_asan__interceptors.h
	compiler-rt-git/patches/patch-lib_asan_asan__linux.cc
	compiler-rt-git/patches/patch-lib_asan_asan__malloc__linux.cc
	compiler-rt-git/patches/patch-lib_asan_asan__stack.h
	compiler-rt-git/patches/patch-lib_asan_scripts_asan__symbolize.py
	compiler-rt-git/patches/patch-lib_interception_interception.h
	compiler-rt-git/patches/patch-lib_interception_interception__linux.cc
	compiler-rt-git/patches/patch-lib_interception_interception__linux.h
	compiler-rt-git/patches/patch-lib_sanitizer__common_CMakeLists.txt
	compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__internal__defs.h
	compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__libignore.cc
	compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__linux.cc
	compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__linux.h
	compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__linux__libcdep.cc
	compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__netbsd.h
	compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__platform.h
	compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__platform__interceptors.h
	compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__platform__limits__posix.cc
	compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__platform__limits__posix.h
	compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__procmaps.h
	compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__procmaps__common.cc
	compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__procmaps__netbsd.cc
	compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__syscall__generic.inc
	compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__unwind__linux__libcdep.cc

Log Message:
compiler-rt-git: Add asan for NetBSD

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=c09ffd0c5e04a16aadf613a36f6d0c64b12ac6a8

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

diffstat:
 compiler-rt-git/Makefile                           |   7 +-
 compiler-rt-git/PLIST                              |  45 +-
 compiler-rt-git/distinfo                           |  26 +
 .../patches/patch-cmake_config-ix.cmake            |  22 +
 .../patches/patch-lib_asan_asan__interceptors.cc   |  16 +
 .../patches/patch-lib_asan_asan__interceptors.h    |  13 +
 .../patches/patch-lib_asan_asan__linux.cc          |  53 ++
 .../patches/patch-lib_asan_asan__malloc__linux.cc  |  19 +
 .../patches/patch-lib_asan_asan__stack.h           |  13 +
 .../patch-lib_asan_scripts_asan__symbolize.py      |  22 +
 .../patches/patch-lib_interception_interception.h  |  31 +
 .../patch-lib_interception_interception__linux.cc  |  40 ++
 .../patch-lib_interception_interception__linux.h   |  19 +
 .../patch-lib_sanitizer__common_CMakeLists.txt     |  12 +
 ...b_sanitizer__common_sanitizer__internal__defs.h |  13 +
 ...h-lib_sanitizer__common_sanitizer__libignore.cc |  19 +
 ...patch-lib_sanitizer__common_sanitizer__linux.cc | 336 +++++++++++
 .../patch-lib_sanitizer__common_sanitizer__linux.h |  20 +
 ..._sanitizer__common_sanitizer__linux__libcdep.cc |  69 +++
 ...patch-lib_sanitizer__common_sanitizer__netbsd.h |  25 +
 ...tch-lib_sanitizer__common_sanitizer__platform.h |  35 ++
 ...zer__common_sanitizer__platform__interceptors.h | 241 ++++++++
 ...r__common_sanitizer__platform__limits__posix.cc | 239 ++++++++
 ...er__common_sanitizer__platform__limits__posix.h | 638 +++++++++++++++++++++
 ...tch-lib_sanitizer__common_sanitizer__procmaps.h |  31 +
 ...anitizer__common_sanitizer__procmaps__common.cc |  19 +
 ...anitizer__common_sanitizer__procmaps__netbsd.cc |  84 +++
 ...nitizer__common_sanitizer__syscall__generic.inc |  44 ++
 ...er__common_sanitizer__unwind__linux__libcdep.cc |  43 ++
 29 files changed, 2177 insertions(+), 17 deletions(-)

diffs:
diff --git a/compiler-rt-git/Makefile b/compiler-rt-git/Makefile
index 655fe9440d..6444748c68 100644
--- a/compiler-rt-git/Makefile
+++ b/compiler-rt-git/Makefile
@@ -1,6 +1,6 @@
 # $NetBSD: Makefile.common,v 1.7 2015/07/20 05:49:53 adam Exp $
 
-PKGNAME=	compiler-rt-4.0.0
+PKGNAME=	compiler-rt-5.0.0
 CATEGORIES=	lang devel
 
 GIT_REPOSITORIES=	compiler-rt
@@ -25,12 +25,15 @@ CMAKE_ARG_PATH=		${WRKSRC}
 CMAKE_ARGS+=	-DCMAKE_BUILD_TYPE=Release
 CMAKE_ARGS+=	-DCMAKE_C_COMPILER=${CC:Q}
 CMAKE_ARGS+=	-DCMAKE_CXX_COMPILER=${CXX:Q}
+CMAKE_ARGS+=	-DCOMPILER_RT_OS_DIR:STRING=${LOWER_OPSYS}${OS_VERSION:R}
+CMAKE_ARGS+=	-DCOMPILER_RT_INSTALL_PATH:STRING=lib/clang/${PKGVERSION_NOREV}
 
-CMAKE_ARG_PATH=	${WRKDIR}/compiler-rt
+PLIST_SUBST+=	COMPILER_RT_OS_DIR=${LOWER_OPSYS}${OS_VERSION:R}
 
 post-extract:
 	${RUN} mkdir -p ${WRKDIR}/build
 
 .include "../../wip/mk/git-package.mk"
+DEPENDS+=	llvm-${PKGVERSION_NOREV}{,nb*}:../../wip/llvm-git
 .include "../../wip/llvm-git/buildlink3.mk"
 .include "../../mk/bsd.pkg.mk"
diff --git a/compiler-rt-git/PLIST b/compiler-rt-git/PLIST
index f209c1dc16..b00e2dd733 100644
--- a/compiler-rt-git/PLIST
+++ b/compiler-rt-git/PLIST
@@ -1,16 +1,31 @@
 @comment $NetBSD$
-include/sanitizer/allocator_interface.h
-include/sanitizer/asan_interface.h
-include/sanitizer/common_interface_defs.h
-include/sanitizer/coverage_interface.h
-include/sanitizer/dfsan_interface.h
-include/sanitizer/esan_interface.h
-include/sanitizer/linux_syscall_hooks.h
-include/sanitizer/lsan_interface.h
-include/sanitizer/msan_interface.h
-include/sanitizer/tsan_interface.h
-include/sanitizer/tsan_interface_atomic.h
-include/xray/xray_interface.h
-include/xray/xray_log_interface.h
-lib/netbsd/libclang_rt.builtins-i386.a
-lib/netbsd/libclang_rt.builtins-x86_64.a
+lib/clang/${PKGVERSION}/asan_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
+lib/clang/${PKGVERSION}/include/sanitizer/coverage_interface.h
+lib/clang/${PKGVERSION}/include/sanitizer/dfsan_interface.h
+lib/clang/${PKGVERSION}/include/sanitizer/esan_interface.h
+lib/clang/${PKGVERSION}/include/sanitizer/linux_syscall_hooks.h
+lib/clang/${PKGVERSION}/include/sanitizer/lsan_interface.h
+lib/clang/${PKGVERSION}/include/sanitizer/msan_interface.h
+lib/clang/${PKGVERSION}/include/sanitizer/tsan_interface.h
+lib/clang/${PKGVERSION}/include/sanitizer/tsan_interface_atomic.h
+lib/clang/${PKGVERSION}/include/xray/xray_interface.h
+lib/clang/${PKGVERSION}/include/xray/xray_log_interface.h
+lib/clang/${PKGVERSION}/lib/${COMPILER_RT_OS_DIR}/libclang_rt.asan-i386.a
+lib/clang/${PKGVERSION}/lib/${COMPILER_RT_OS_DIR}/libclang_rt.asan-i386.so
+lib/clang/${PKGVERSION}/lib/${COMPILER_RT_OS_DIR}/libclang_rt.asan-preinit-i386.a
+lib/clang/${PKGVERSION}/lib/${COMPILER_RT_OS_DIR}/libclang_rt.asan-preinit-x86_64.a
+lib/clang/${PKGVERSION}/lib/${COMPILER_RT_OS_DIR}/libclang_rt.asan-x86_64.a
+lib/clang/${PKGVERSION}/lib/${COMPILER_RT_OS_DIR}/libclang_rt.asan-x86_64.a.syms
+lib/clang/${PKGVERSION}/lib/${COMPILER_RT_OS_DIR}/libclang_rt.asan-x86_64.so
+lib/clang/${PKGVERSION}/lib/${COMPILER_RT_OS_DIR}/libclang_rt.asan_cxx-i386.a
+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.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
diff --git a/compiler-rt-git/distinfo b/compiler-rt-git/distinfo
index 7931384fd5..d37adf0207 100644
--- a/compiler-rt-git/distinfo
+++ b/compiler-rt-git/distinfo
@@ -12,3 +12,29 @@ 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-cmake_config-ix.cmake) = a8f965c384da0da76054e26e3d8670e972ab1deb
+SHA1 (patch-lib_asan_asan__interceptors.cc) = 9a61c5625f1c7a4e5338623bd528fa5d92869abc
+SHA1 (patch-lib_asan_asan__interceptors.h) = 75b6bb46fe25c8ed4d82aeab30d8eb4c925436e2
+SHA1 (patch-lib_asan_asan__linux.cc) = a7ba455bdc33669052f95a2253132a4028859869
+SHA1 (patch-lib_asan_asan__malloc__linux.cc) = 243e11352b9f5e83aa5c4d5d7e2a8f5808d0eb78
+SHA1 (patch-lib_asan_asan__stack.h) = 287566e2bc220d8fe5045df47058ac54ad907e1a
+SHA1 (patch-lib_asan_scripts_asan__symbolize.py) = fbae70f476433262306ae5fb5904bbf8e0b0d8e0
+SHA1 (patch-lib_interception_interception.h) = 4854b9cd428eb2a9c3508e687408b52a3a3183ca
+SHA1 (patch-lib_interception_interception__linux.cc) = fca6d1801ffa7abfedd9a40d8330a03453b551b4
+SHA1 (patch-lib_interception_interception__linux.h) = 23b5b738f5b3535da7beaa5d08952e076b65014a
+SHA1 (patch-lib_sanitizer__common_CMakeLists.txt) = 510c6b5b5c3824b2aea3c8e34427f3a27f8d10db
+SHA1 (patch-lib_sanitizer__common_sanitizer__internal__defs.h) = 19cd534bcb183b9f1da6b36efb00785c3af0eed4
+SHA1 (patch-lib_sanitizer__common_sanitizer__libignore.cc) = 2721e3264296f9ea0debc3d6efddedba67600d47
+SHA1 (patch-lib_sanitizer__common_sanitizer__linux.cc) = 6a219c12f896ad54c8990df2f54239cc6e86f971
+SHA1 (patch-lib_sanitizer__common_sanitizer__linux.h) = 0d02a7c4cc61bcf6a3156ffa2fd8d940cca3ab74
+SHA1 (patch-lib_sanitizer__common_sanitizer__linux__libcdep.cc) = 08e701e72e5afcdff009580b23e16e91dfc6eac1
+SHA1 (patch-lib_sanitizer__common_sanitizer__netbsd.h) = c70b84e9ab3e6874912e8675834c2cb42e83aab6
+SHA1 (patch-lib_sanitizer__common_sanitizer__platform.h) = 629173ae6deaa0f61d52f78ee0db619ce6acb10f
+SHA1 (patch-lib_sanitizer__common_sanitizer__platform__interceptors.h) = 4ca8ee9d1ab04f51e55a8df86c1b88efebe2da3c
+SHA1 (patch-lib_sanitizer__common_sanitizer__platform__limits__posix.cc) = 10179f35182196dc6f23796ce72f6fb2d5f97ccd
+SHA1 (patch-lib_sanitizer__common_sanitizer__platform__limits__posix.h) = 74cbca2057071357ec2ef35477c73fd1a55cbbad
+SHA1 (patch-lib_sanitizer__common_sanitizer__procmaps.h) = e304954272f2624d823b29b9eb7aa6bb001f7c47
+SHA1 (patch-lib_sanitizer__common_sanitizer__procmaps__common.cc) = 2f270afc2c316b99ad3c25c09896ac98c988f557
+SHA1 (patch-lib_sanitizer__common_sanitizer__procmaps__netbsd.cc) = fb4518f4f9dd589d7d35a8bc9e5e76d6dceb8476
+SHA1 (patch-lib_sanitizer__common_sanitizer__syscall__generic.inc) = 42ad08df9a330a8755220e995230b8f16467c425
+SHA1 (patch-lib_sanitizer__common_sanitizer__unwind__linux__libcdep.cc) = dac542d9c711d132c972de407233f25880f3163a
diff --git a/compiler-rt-git/patches/patch-cmake_config-ix.cmake b/compiler-rt-git/patches/patch-cmake_config-ix.cmake
new file mode 100644
index 0000000000..753ab06ec8
--- /dev/null
+++ b/compiler-rt-git/patches/patch-cmake_config-ix.cmake
@@ -0,0 +1,22 @@
+$NetBSD$
+
+--- cmake/config-ix.cmake.orig	2017-07-03 15:33:06.516370306 +0000
++++ cmake/config-ix.cmake
+@@ -441,7 +441,7 @@ set(COMPILER_RT_SANITIZERS_TO_BUILD ${AL
+ list_replace(COMPILER_RT_SANITIZERS_TO_BUILD all "${ALL_SANITIZERS}")
+ 
+ if (SANITIZER_COMMON_SUPPORTED_ARCH AND NOT LLVM_USE_SANITIZER AND
+-    (OS_NAME MATCHES "Android|Darwin|Linux|FreeBSD" OR
++    (OS_NAME MATCHES "Android|Darwin|Linux|FreeBSD|NetBSD" OR
+     (OS_NAME MATCHES "Windows" AND (NOT MINGW AND NOT CYGWIN))))
+   set(COMPILER_RT_HAS_SANITIZER_COMMON TRUE)
+ else()
+@@ -460,7 +460,7 @@ else()
+   set(COMPILER_RT_HAS_ASAN FALSE)
+ endif()
+ 
+-if (OS_NAME MATCHES "Linux|FreeBSD|Windows")
++if (OS_NAME MATCHES "Linux|FreeBSD|NetBSD|Windows")
+   set(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME TRUE)
+ else()
+   set(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME FALSE)
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..f7b77aa3ef
--- /dev/null
+++ b/compiler-rt-git/patches/patch-lib_asan_asan__interceptors.cc
@@ -0,0 +1,16 @@
+$NetBSD$
+
+--- lib/asan/asan_interceptors.cc.orig	2017-07-03 15:33:06.520942325 +0000
++++ lib/asan/asan_interceptors.cc
+@@ -424,6 +424,11 @@ INTERCEPTOR(int, swapcontext, struct uco
+ }
+ #endif  // ASAN_INTERCEPT_SWAPCONTEXT
+ 
++#if SANITIZER_NETBSD
++#define longjmp __longjmp14
++#define siglongjmp __siglongjmp14
++#endif
++
+ INTERCEPTOR(void, longjmp, void *env, int val) {
+   __asan_handle_no_return();
+   REAL(longjmp)(env, val);
diff --git a/compiler-rt-git/patches/patch-lib_asan_asan__interceptors.h b/compiler-rt-git/patches/patch-lib_asan_asan__interceptors.h
new file mode 100644
index 0000000000..7457f7f9e8
--- /dev/null
+++ b/compiler-rt-git/patches/patch-lib_asan_asan__interceptors.h
@@ -0,0 +1,13 @@
+$NetBSD$
+
+--- lib/asan/asan_interceptors.h.orig	2017-07-03 15:33:06.521004205 +0000
++++ lib/asan/asan_interceptors.h
+@@ -34,7 +34,7 @@
+ # define ASAN_INTERCEPT_FORK 0
+ #endif
+ 
+-#if SANITIZER_FREEBSD || SANITIZER_LINUX
++#if SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD
+ # define ASAN_USE_ALIAS_ATTRIBUTE_FOR_INDEX 1
+ #else
+ # define ASAN_USE_ALIAS_ATTRIBUTE_FOR_INDEX 0
diff --git a/compiler-rt-git/patches/patch-lib_asan_asan__linux.cc b/compiler-rt-git/patches/patch-lib_asan_asan__linux.cc
new file mode 100644
index 0000000000..69eec063ba
--- /dev/null
+++ b/compiler-rt-git/patches/patch-lib_asan_asan__linux.cc
@@ -0,0 +1,53 @@
+$NetBSD$
+
+--- lib/asan/asan_linux.cc.orig	2017-07-03 15:33:06.521305430 +0000
++++ lib/asan/asan_linux.cc
+@@ -13,13 +13,14 @@
+ //===----------------------------------------------------------------------===//
+ 
+ #include "sanitizer_common/sanitizer_platform.h"
+-#if SANITIZER_FREEBSD || SANITIZER_LINUX
++#if SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD
+ 
+ #include "asan_interceptors.h"
+ #include "asan_internal.h"
+ #include "asan_thread.h"
+ #include "sanitizer_common/sanitizer_flags.h"
+ #include "sanitizer_common/sanitizer_freebsd.h"
++#include "sanitizer_common/sanitizer_netbsd.h"
+ #include "sanitizer_common/sanitizer_libc.h"
+ #include "sanitizer_common/sanitizer_procmaps.h"
+ 
+@@ -42,6 +43,10 @@
+ #if SANITIZER_ANDROID || SANITIZER_FREEBSD
+ #include <ucontext.h>
+ extern "C" void* _DYNAMIC;
++#elif SANITIZER_NETBSD
++#include <ucontext.h>
++#include <link_elf.h>   
++extern Elf_Dyn  _DYNAMIC;
+ #else
+ #include <sys/ucontext.h>
+ #include <link.h>
+@@ -96,6 +101,15 @@ static int FindFirstDSOCallback(struct d
+   if (internal_strncmp(info->dlpi_name, "linux-", sizeof("linux-") - 1) == 0)
+     return 0;
+ 
++#if SANITIZER_NETBSD
++  // Ignore first entry (the main program)
++  char **p = (char **)data;
++  if (*p == NULL) {
++    *p = (char *)-1;
++    return 0;
++  }
++#endif
++
+   *(const char **)data = info->dlpi_name;
+   return 1;
+ }
+@@ -174,4 +188,4 @@ void *AsanDlSymNext(const char *sym) {
+ 
+ } // namespace __asan
+ 
+-#endif // SANITIZER_FREEBSD || SANITIZER_LINUX
++#endif // SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD
diff --git a/compiler-rt-git/patches/patch-lib_asan_asan__malloc__linux.cc b/compiler-rt-git/patches/patch-lib_asan_asan__malloc__linux.cc
new file mode 100644
index 0000000000..2c1140135f
--- /dev/null
+++ b/compiler-rt-git/patches/patch-lib_asan_asan__malloc__linux.cc
@@ -0,0 +1,19 @@
+$NetBSD$
+
+--- lib/asan/asan_malloc_linux.cc.orig	2017-07-03 15:33:06.521563494 +0000
++++ lib/asan/asan_malloc_linux.cc
+@@ -15,7 +15,7 @@
+ //===----------------------------------------------------------------------===//
+ 
+ #include "sanitizer_common/sanitizer_platform.h"
+-#if SANITIZER_FREEBSD || SANITIZER_LINUX
++#if SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD
+ 
+ #include "sanitizer_common/sanitizer_tls_get_addr.h"
+ #include "asan_allocator.h"
+@@ -226,4 +226,4 @@ void ReplaceSystemMalloc() {
+ }  // namespace __asan
+ #endif  // SANITIZER_ANDROID
+ 
+-#endif  // SANITIZER_FREEBSD || SANITIZER_LINUX
++#endif  // SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD
diff --git a/compiler-rt-git/patches/patch-lib_asan_asan__stack.h b/compiler-rt-git/patches/patch-lib_asan_asan__stack.h
new file mode 100644
index 0000000000..726d7e7baa
--- /dev/null
+++ b/compiler-rt-git/patches/patch-lib_asan_asan__stack.h
@@ -0,0 +1,13 @@
+$NetBSD$
+
+--- lib/asan/asan_stack.h.orig	2017-07-03 15:33:06.523226694 +0000
++++ lib/asan/asan_stack.h
+@@ -44,7 +44,7 @@ void GetStackTraceWithPcBpAndContext(Buf
+       // On FreeBSD the slow unwinding that leverages _Unwind_Backtrace()
+       // yields the call stack of the signal's handler and not of the code
+       // that raised the signal (as it does on Linux).
+-      if (SANITIZER_FREEBSD && t->isInDeadlySignal()) fast = true;
++      if ((SANITIZER_FREEBSD || SANITIZER_NETBSD) && t->isInDeadlySignal()) fast = true;
+       uptr stack_top = t->stack_top();
+       uptr stack_bottom = t->stack_bottom();
+       ScopedUnwinding unwind_scope(t);
diff --git a/compiler-rt-git/patches/patch-lib_asan_scripts_asan__symbolize.py b/compiler-rt-git/patches/patch-lib_asan_scripts_asan__symbolize.py
new file mode 100644
index 0000000000..cb5e3c82b5
--- /dev/null
+++ b/compiler-rt-git/patches/patch-lib_asan_scripts_asan__symbolize.py
@@ -0,0 +1,22 @@
+$NetBSD$
+
+--- lib/asan/scripts/asan_symbolize.py.orig	2017-07-03 15:33:06.524556193 +0000
++++ lib/asan/scripts/asan_symbolize.py
+@@ -280,7 +280,7 @@ def BreakpadSymbolizerFactory(binary):
+ def SystemSymbolizerFactory(system, addr, binary, arch):
+   if system == 'Darwin':
+     return DarwinSymbolizer(addr, binary, arch)
+-  elif system == 'Linux' or system == 'FreeBSD':
++  elif system == 'Linux' or system == 'FreeBSD' or system == 'NetBSD':
+     return Addr2LineSymbolizer(binary)
+ 
+ 
+@@ -370,7 +370,7 @@ class SymbolizationLoop(object):
+       self.binary_name_filter = binary_name_filter
+       self.dsym_hint_producer = dsym_hint_producer
+       self.system = os.uname()[0]
+-      if self.system not in ['Linux', 'Darwin', 'FreeBSD']:
++      if self.system not in ['Linux', 'Darwin', 'FreeBSD', 'NetBSD']:
+         raise Exception('Unknown system')
+       self.llvm_symbolizers = {}
+       self.last_llvm_symbolizer = None
diff --git a/compiler-rt-git/patches/patch-lib_interception_interception.h b/compiler-rt-git/patches/patch-lib_interception_interception.h
new file mode 100644
index 0000000000..071d4cde13
--- /dev/null
+++ b/compiler-rt-git/patches/patch-lib_interception_interception.h
@@ -0,0 +1,31 @@
+$NetBSD$
+
+--- lib/interception/interception.h.orig	2017-07-03 15:33:06.543884557 +0000
++++ lib/interception/interception.h
+@@ -15,7 +15,7 @@
+ #ifndef INTERCEPTION_H
+ #define INTERCEPTION_H
+ 
+-#if !defined(__linux__) && !defined(__FreeBSD__) && \
++#if !defined(__linux__) && !defined(__FreeBSD__) && !defined(__NetBSD__) && \
+   !defined(__APPLE__) && !defined(_WIN32)
+ # error "Interception doesn't work on this operating system."
+ #endif
+@@ -129,7 +129,7 @@ const interpose_substitution substitutio
+     extern "C" ret_type func(__VA_ARGS__);
+ # define DECLARE_WRAPPER_WINAPI(ret_type, func, ...) \
+     extern "C" __declspec(dllimport) ret_type __stdcall func(__VA_ARGS__);
+-#elif defined(__FreeBSD__)
++#elif defined(__FreeBSD__) || defined(__NetBSD__)
+ # define WRAP(x) __interceptor_ ## x
+ # define WRAPPER_NAME(x) "__interceptor_" #x
+ # define INTERCEPTOR_ATTRIBUTE __attribute__((visibility("default")))
+@@ -241,7 +241,7 @@ typedef unsigned long uptr;  // NOLINT
+ 
+ #define INCLUDED_FROM_INTERCEPTION_LIB
+ 
+-#if defined(__linux__) || defined(__FreeBSD__)
++#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__)
+ # include "interception_linux.h"
+ # define INTERCEPT_FUNCTION(func) INTERCEPT_FUNCTION_LINUX_OR_FREEBSD(func)
+ # define INTERCEPT_FUNCTION_VER(func, symver) \
diff --git a/compiler-rt-git/patches/patch-lib_interception_interception__linux.cc b/compiler-rt-git/patches/patch-lib_interception_interception__linux.cc
new file mode 100644
index 0000000000..e6ae2dfb54
--- /dev/null
+++ b/compiler-rt-git/patches/patch-lib_interception_interception__linux.cc
@@ -0,0 +1,40 @@
+$NetBSD$
+
+--- lib/interception/interception_linux.cc.orig	2017-07-03 15:33:06.543936170 +0000
++++ lib/interception/interception_linux.cc
+@@ -12,14 +12,28 @@
+ // Linux-specific interception methods.
+ //===----------------------------------------------------------------------===//
+ 
+-#if defined(__linux__) || defined(__FreeBSD__)
++#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__)
+ #include "interception.h"
+ 
+ #include <dlfcn.h>   // for dlsym() and dlvsym()
+ 
++#ifdef __NetBSD__
++static int mystrcmp(const char *s1, const char *s2) {
++  while (*s1 == *s2++)
++    if (*s1++ == 0)
++      return (0);
++  return (*(const unsigned char *)s1 - *(const unsigned char *)--s2);
++}
++#endif
++
+ namespace __interception {
+ bool GetRealFunctionAddress(const char *func_name, uptr *func_addr,
+     uptr real, uptr wrapper) {
++#ifdef __NetBSD__
++  // XXX: Until I come up with something better to deal with renames.
++  if (mystrcmp(func_name, "sigaction") == 0)
++    func_name = "__sigaction14";
++#endif
+   *func_addr = (uptr)dlsym(RTLD_NEXT, func_name);
+   return real == wrapper;
+ }
+@@ -33,4 +47,4 @@ void *GetFuncAddrVer(const char *func_na
+ }  // namespace __interception
+ 
+ 
+-#endif  // __linux__ || __FreeBSD__
++#endif  // __linux__ || __FreeBSD__ || __NetBSD__
diff --git a/compiler-rt-git/patches/patch-lib_interception_interception__linux.h b/compiler-rt-git/patches/patch-lib_interception_interception__linux.h
new file mode 100644
index 0000000000..8ff9a790f3
--- /dev/null
+++ b/compiler-rt-git/patches/patch-lib_interception_interception__linux.h
@@ -0,0 +1,19 @@
+$NetBSD$
+
+--- lib/interception/interception_linux.h.orig	2017-07-03 15:33:06.543980100 +0000
++++ lib/interception/interception_linux.h
+@@ -12,7 +12,7 @@
+ // Linux-specific interception methods.
+ //===----------------------------------------------------------------------===//
+ 
+-#if defined(__linux__) || defined(__FreeBSD__)
++#if defined(__linux__) || defined(__FreeBSD__) | defined(__NetBSD__)
+ 
+ #if !defined(INCLUDED_FROM_INTERCEPTION_LIB)
+ # error "interception_linux.h should be included from interception library only"
+@@ -44,4 +44,4 @@ void *GetFuncAddrVer(const char *func_na
+ #endif  // !defined(__ANDROID__)
+ 
+ #endif  // INTERCEPTION_LINUX_H
+-#endif  // __linux__ || __FreeBSD__
++#endif  // __linux__ || __FreeBSD__ || __NetBSD__
diff --git a/compiler-rt-git/patches/patch-lib_sanitizer__common_CMakeLists.txt b/compiler-rt-git/patches/patch-lib_sanitizer__common_CMakeLists.txt
new file mode 100644
index 0000000000..c900c1d508
--- /dev/null
+++ b/compiler-rt-git/patches/patch-lib_sanitizer__common_CMakeLists.txt
@@ -0,0 +1,12 @@
+$NetBSD$
+
+--- lib/sanitizer_common/CMakeLists.txt.orig	2017-07-03 15:33:06.550862958 +0000
++++ lib/sanitizer_common/CMakeLists.txt
+@@ -22,6 +22,7 @@ set(SANITIZER_SOURCES_NOTERMINATION
+   sanitizer_procmaps_freebsd.cc
+   sanitizer_procmaps_linux.cc
+   sanitizer_procmaps_mac.cc
++  sanitizer_procmaps_netbsd.cc
+   sanitizer_stackdepot.cc
+   sanitizer_stacktrace.cc
+   sanitizer_stacktrace_printer.cc
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..9766d715bc
--- /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-07-03 15:33:06.556591130 +0000
++++ lib/sanitizer_common/sanitizer_internal_defs.h
+@@ -133,7 +133,7 @@ typedef int pid_t;
+ // _FILE_OFFSET_BITS. This definition of OFF_T matches the ABI of system calls
+ // like pread and mmap, as opposed to pread64 and mmap64.
+ // FreeBSD, Mac and Linux/x86-64 are special.
+-#if SANITIZER_FREEBSD || SANITIZER_MAC || \
++#if SANITIZER_FREEBSD || SANITIZER_NETBSD || SANITIZER_MAC || \
+   (SANITIZER_LINUX && defined(__x86_64__))
+ typedef u64 OFF_T;
+ #else
diff --git a/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__libignore.cc b/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__libignore.cc
new file mode 100644
index 0000000000..c8c239299c
--- /dev/null
+++ b/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__libignore.cc
@@ -0,0 +1,19 @@
+$NetBSD$
+
+--- lib/sanitizer_common/sanitizer_libignore.cc.orig	2017-07-03 15:33:06.556851079 +0000
++++ lib/sanitizer_common/sanitizer_libignore.cc
+@@ -9,7 +9,7 @@
+ 
+ #include "sanitizer_platform.h"
+ 
+-#if SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_MAC
++#if SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_MAC || SANITIZER_NETBSD
+ 
+ #include "sanitizer_libignore.h"
+ #include "sanitizer_flags.h"
+@@ -125,4 +125,4 @@ void LibIgnore::OnLibraryUnloaded() {
+ 
+ } // namespace __sanitizer
+ 
+-#endif // #if SANITIZER_FREEBSD || SANITIZER_LINUX
++#endif // #if SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD
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..a2e2245ec3
--- /dev/null
+++ b/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__linux.cc
@@ -0,0 +1,336 @@
+$NetBSD$
+
+--- lib/sanitizer_common/sanitizer_linux.cc.orig	2017-07-03 15:33:06.557337873 +0000
++++ lib/sanitizer_common/sanitizer_linux.cc
+@@ -14,7 +14,7 @@
+ 
+ #include "sanitizer_platform.h"
+ 
+-#if SANITIZER_FREEBSD || SANITIZER_LINUX
++#if SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD
+ 
+ #include "sanitizer_common.h"
+ #include "sanitizer_flags.h"
+@@ -27,10 +27,14 @@
+ #include "sanitizer_stacktrace.h"
+ #include "sanitizer_symbolizer.h"
+ 
+-#if !SANITIZER_FREEBSD
++#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
+ #include <asm/param.h>
+ #endif
+ 
++#if SANITIZER_NETBSD
++#include <lwp.h>
++#endif
++
+ // For mips64, syscall(__NR_stat) fills the buffer in the 'struct kernel_stat'
+ // format. Struct kernel_stat is defined as 'struct stat' in asm/stat.h. To
+ // access stat from asm/stat.h, without conflicting with definition in
+@@ -71,6 +75,12 @@ extern "C" {
+ extern char **environ;  // provided by crt1
+ #endif  // SANITIZER_FREEBSD
+ 
++#if SANITIZER_NETBSD
++#include <limits.h>     // For NAME_MAX
++#include <sys/sysctl.h>
++extern char **environ;  // provided by crt1
++#endif  // SANITIZER_NETBSD 
++
+ #if !SANITIZER_ANDROID
+ #include <sys/signal.h>
+ #endif
+@@ -131,7 +141,10 @@ namespace __sanitizer {
+ #if !SANITIZER_S390
+ uptr internal_mmap(void *addr, uptr length, int prot, int flags, int fd,
+                    OFF_T offset) {
+-#if SANITIZER_FREEBSD || SANITIZER_LINUX_USES_64BIT_SYSCALLS
++#if SANITIZER_NETBSD     
++  return internal_syscall_ptr(SYSCALL(mmap), addr, length, prot, flags, fd,
++                              (long)0, offset);
++#elif SANITIZER_FREEBSD || SANITIZER_LINUX_USES_64BIT_SYSCALLS
+   return internal_syscall(SYSCALL(mmap), (uptr)addr, length, prot, flags, fd,
+                           offset);
+ #else
+@@ -174,26 +187,38 @@ uptr internal_open(const char *filename,
+ 
+ uptr internal_read(fd_t fd, void *buf, uptr count) {
+   sptr res;
++#ifdef 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,
+                count));
++#endif
+   return res;
+ }
+ 
+ uptr internal_write(fd_t fd, const void *buf, uptr count) {
+   sptr res;
++#ifdef 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,
+                count));
++#endif
+   return res;
+ }
+ 
+ uptr internal_ftruncate(fd_t fd, uptr size) {
+   sptr res;
++#ifdef SANITIZER_NETBSD
++  HANDLE_EINTR(res, internal_syscall(SYSCALL(ftruncate), fd, 0, (s64)size));
++#else
+   HANDLE_EINTR(res, (sptr)internal_syscall(SYSCALL(ftruncate), fd,
+                (OFF_T)size));
++#endif
+   return res;
+ }
+ 
+-#if !SANITIZER_LINUX_USES_64BIT_SYSCALLS && !SANITIZER_FREEBSD
++#if !SANITIZER_LINUX_USES_64BIT_SYSCALLS && !SANITIZER_FREEBSD && !SANITIZER_NETBSD
+ static void stat64_to_stat(struct stat64 *in, struct stat *out) {
+   internal_memset(out, 0, sizeof(*out));
+   out->st_dev = in->st_dev;
+@@ -234,7 +259,7 @@ static void kernel_stat_to_stat(struct k
+ #endif
+ 
+ uptr internal_stat(const char *path, void *buf) {
+-#if SANITIZER_FREEBSD
++#if SANITIZER_FREEBSD || SANITIZER_NETBSD
+   return internal_syscall(SYSCALL(fstatat), AT_FDCWD, (uptr)path,
+                           (uptr)buf, 0);
+ #elif SANITIZER_USES_CANONICAL_LINUX_SYSCALLS
+@@ -259,7 +284,9 @@ uptr internal_stat(const char *path, voi
+ }
+ 
+ uptr internal_lstat(const char *path, void *buf) {
+-#if SANITIZER_FREEBSD
++#if SANITIZER_NETBSD
++  return internal_syscall(SYSCALL(lstat), path, buf);
++#elif SANITIZER_FREEBSD
+   return internal_syscall(SYSCALL(fstatat), AT_FDCWD, (uptr)path,
+                           (uptr)buf, AT_SYMLINK_NOFOLLOW);
+ #elif SANITIZER_USES_CANONICAL_LINUX_SYSCALLS
+@@ -284,7 +311,7 @@ uptr internal_lstat(const char *path, vo
+ }
+ 
+ uptr internal_fstat(fd_t fd, void *buf) {
+-#if SANITIZER_FREEBSD || SANITIZER_LINUX_USES_64BIT_SYSCALLS
++#if SANITIZER_FREEBSD || SANITIZER_LINUX_USES_64BIT_SYSCALLS || SANITIZER_NETBSD
+ # if SANITIZER_MIPS64
+   // For mips64, fstat syscall fills buffer in the format of kernel_stat
+   struct kernel_stat kbuf;
+@@ -318,7 +345,9 @@ uptr internal_dup2(int oldfd, int newfd)
+ }
+ 
+ uptr internal_readlink(const char *path, char *buf, uptr bufsize) {
+-#if SANITIZER_USES_CANONICAL_LINUX_SYSCALLS
++#if SANITIZER_NETBSD
++  return internal_syscall_ptr(SYSCALL(readlink), path, buf, bufsize);
++#elif SANITIZER_USES_CANONICAL_LINUX_SYSCALLS
+   return internal_syscall(SYSCALL(readlinkat), AT_FDCWD,
+                           (uptr)path, (uptr)buf, bufsize);
+ #else
+@@ -348,7 +377,7 @@ uptr internal_sched_yield() {
+ }
+ 
+ void internal__exit(int exitcode) {
+-#if SANITIZER_FREEBSD
++#if SANITIZER_FREEBSD || SANITIZER_NETBSD
+   internal_syscall(SYSCALL(exit), exitcode);
+ #else
+   internal_syscall(SYSCALL(exit_group), exitcode);
+@@ -387,19 +416,25 @@ bool FileExists(const char *filename) {
+ tid_t GetTid() {
+ #if SANITIZER_FREEBSD
+   return (uptr)pthread_self();
++#elif SANITIZER_NETBSD
++  return _lwp_self();
+ #else
+   return internal_syscall(SYSCALL(gettid));
+ #endif
+ }
+ 
+ u64 NanoTime() {
+-#if SANITIZER_FREEBSD
++#if SANITIZER_FREEBSD || SANITIZER_NETBSD
+   timeval tv;
+ #else
+   kernel_timeval tv;
+ #endif
+   internal_memset(&tv, 0, sizeof(tv));
++#if SANITIZER_NETBSD
++  internal_syscall(SYSCALL(gettimeofday), &tv, NULL);
++#else
+   internal_syscall(SYSCALL(gettimeofday), (uptr)&tv, 0);
++#endif
+   return (u64)tv.tv_sec * 1000*1000*1000 + tv.tv_usec * 1000;
+ }
+ 
+@@ -407,7 +442,7 @@ u64 NanoTime() {
+ // 'environ' array (on FreeBSD) and does not use libc. This function should be
+ // called first inside __asan_init.
+ const char *GetEnv(const char *name) {
+-#if SANITIZER_FREEBSD
++#if SANITIZER_FREEBSD || SANITIZER_NETBSD
+   if (::environ != 0) {
+     uptr NameLen = internal_strlen(name);
+     for (char **Env = ::environ; *Env != 0; Env++) {
+@@ -541,6 +576,8 @@ void BlockingMutex::Lock() {
+   while (atomic_exchange(m, MtxSleeping, memory_order_acquire) != MtxUnlocked) {
+ #if SANITIZER_FREEBSD
+     _umtx_op(m, UMTX_OP_WAIT_UINT, MtxSleeping, 0, 0);
++#elif SANITIZER_NETBSD
++    sched_yield(); /* No userspace futex-like synchromization */
+ #else
+     internal_syscall(SYSCALL(futex), (uptr)m, FUTEX_WAIT, MtxSleeping, 0, 0, 0);
+ #endif
+@@ -554,6 +591,8 @@ void BlockingMutex::Unlock() {
+   if (v == MtxSleeping) {
+ #if SANITIZER_FREEBSD
+     _umtx_op(m, UMTX_OP_WAKE, 1, 0, 0);
++#elif SANITIZER_NETBSD
++    /* No userspace futex-like synchromization */
+ #else
+     internal_syscall(SYSCALL(futex), (uptr)m, FUTEX_WAKE, 1, 0, 0, 0);
+ #endif
+@@ -569,6 +608,17 @@ void BlockingMutex::CheckLocked() {
+ // The actual size of this structure is specified by d_reclen.
+ // Note that getdents64 uses a different structure format. We only provide the
+ // 32-bit syscall here.
++#if SANITIZER_NETBSD
++// struct dirent is different for Linux and us. At this moment, we use only
++// d_fileno (Linux call this d_ino), d_reclen, and d_name.
++struct linux_dirent {
++  u64  d_ino;     // d_fileno
++  u16  d_reclen;
++  u16  d_namlen;  // not used
++  u8   d_type;    // not used
++  char d_name[NAME_MAX + 1];
++};
++#else
+ struct linux_dirent {
+ #if SANITIZER_X32 || defined(__aarch64__)
+   u64 d_ino;
+@@ -583,16 +633,34 @@ struct linux_dirent {
+ #endif
+   char               d_name[256];
+ };
++#endif
+ 
+ // Syscall wrappers.
+ uptr internal_ptrace(int request, int pid, void *addr, void *data) {
++#if SANITIZER_NETBSD
++// XXX We need additional work for ptrace:
++//   - for request, we use PT_FOO whereas Linux uses PTRACE_FOO
++//   - data is int for us, but void * for Linux
++//   - Linux sometimes uses data in the case where we use addr instead
++// At this moment, this function is used only within
++// "#if SANITIZER_LINUX && defined(__x86_64__)" block in
++// sanitizer_stoptheworld_linux_libcdep.cc.
++  return internal_syscall_ptr(SYSCALL(ptrace), request, pid, (uptr)addr,
++                          (uptr)data);
++#else
+   return internal_syscall(SYSCALL(ptrace), request, pid, (uptr)addr,
+                           (uptr)data);
++#endif
+ }
+ 
+ uptr internal_waitpid(int pid, int *status, int options) {
++#if SANITIZER_NETBSD
++  return internal_syscall(SYSCALL(wait4), pid, status, options,
++                          NULL /* rusage */);
++#else
+   return internal_syscall(SYSCALL(wait4), pid, (uptr)status, options,
+                           0 /* rusage */);
++#endif
+ }
+ 
+ uptr internal_getpid() {
+@@ -604,7 +672,9 @@ uptr internal_getppid() {
+ }
+ 
+ uptr internal_getdents(fd_t fd, struct linux_dirent *dirp, unsigned int count) {
+-#if SANITIZER_FREEBSD
++#if SANITIZER_NETBSD
++  return internal_syscall(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
+   return internal_syscall(SYSCALL(getdents64), fd, (uptr)dirp, count);
+@@ -614,7 +684,11 @@ uptr internal_getdents(fd_t fd, struct l
+ }
+ 
+ uptr internal_lseek(fd_t fd, OFF_T offset, int whence) {
++#if SANITIZER_NETBSD
++  return internal_syscall64(SYSCALL(lseek), fd, 0, offset, whence);
++#else
+   return internal_syscall(SYSCALL(lseek), fd, offset, whence);
++#endif
+ }
+ 
+ #if SANITIZER_LINUX
+@@ -706,7 +780,7 @@ int internal_sigaction_syscall(int signu
+ 
+ uptr internal_sigprocmask(int how, __sanitizer_sigset_t *set,
+     __sanitizer_sigset_t *oldset) {
+-#if SANITIZER_FREEBSD
++#if SANITIZER_FREEBSD || SANITIZER_NETBSD
+   return internal_syscall(SYSCALL(sigprocmask), how, set, oldset);
+ #else
+   __sanitizer_kernel_sigset_t *k_set = (__sanitizer_kernel_sigset_t *)set;
+@@ -829,8 +903,12 @@ uptr GetPageSize() {
+ }
+ 
+ uptr ReadBinaryName(/*out*/char *buf, uptr buf_len) {
+-#if SANITIZER_FREEBSD
+-  const int Mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
++#if SANITIZER_FREEBSD || SANITIZER_NETBSD
++# if SANITIZER_FREEBSD
++  const int Mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
++# else
++  const int Mib[4] = { CTL_KERN, KERN_PROC_ARGS, -1, KERN_PROC_PATHNAME };
++# endif
+   const char *default_module_name = "kern.proc.pathname";
+   size_t Size = buf_len;
+   bool IsErr = (sysctl(Mib, ARRAY_SIZE(Mib), buf, &Size, NULL, 0) != 0);
+@@ -1474,6 +1552,8 @@ SignalContext::WriteFlag SignalContext::
+   static const uptr PF_WRITE = 1U << 1;
+ #if SANITIZER_FREEBSD
+   uptr err = ucontext->uc_mcontext.mc_err;
++#elif SANITIZER_NETBSD
++  uptr err = ucontext->uc_mcontext.__gregs[_REG_ERR];
+ #else
+   uptr err = ucontext->uc_mcontext.gregs[REG_ERR];
+ #endif
+@@ -1520,6 +1600,11 @@ void GetPcSpBp(void *context, uptr *pc, 
+   *pc = ucontext->uc_mcontext.mc_rip;
+   *bp = ucontext->uc_mcontext.mc_rbp;
+   *sp = ucontext->uc_mcontext.mc_rsp;
++# elif SANITIZER_NETBSD
++  ucontext_t *ucontext = (ucontext_t*)context;
++  *pc = ucontext->uc_mcontext.__gregs[_REG_RIP];
++  *bp = ucontext->uc_mcontext.__gregs[_REG_RBP];
++  *sp = ucontext->uc_mcontext.__gregs[_REG_RSP];
+ # else
+   ucontext_t *ucontext = (ucontext_t*)context;
+   *pc = ucontext->uc_mcontext.gregs[REG_RIP];
+@@ -1532,6 +1617,11 @@ void GetPcSpBp(void *context, uptr *pc, 
+   *pc = ucontext->uc_mcontext.mc_eip;
+   *bp = ucontext->uc_mcontext.mc_ebp;
+   *sp = ucontext->uc_mcontext.mc_esp;
++# elif SANITIZER_NETBSD
++  ucontext_t *ucontext = (ucontext_t*)context;
++  *pc = ucontext->uc_mcontext.__gregs[_REG_EIP];
++  *bp = ucontext->uc_mcontext.__gregs[_REG_EBP];
++  *sp = ucontext->uc_mcontext.__gregs[_REG_ESP];
+ # else
+   ucontext_t *ucontext = (ucontext_t*)context;
+   *pc = ucontext->uc_mcontext.gregs[REG_EIP];
+@@ -1632,4 +1722,4 @@ bool GetRandom(void *buffer, uptr length
+ 
+ } // namespace __sanitizer
+ 
+-#endif // SANITIZER_FREEBSD || SANITIZER_LINUX
++#endif // SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD
diff --git a/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__linux.h b/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__linux.h
new file mode 100644
index 0000000000..565bc65cd7
--- /dev/null
+++ b/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__linux.h
@@ -0,0 +1,20 @@
+$NetBSD$
+
+--- lib/sanitizer_common/sanitizer_linux.h.orig	2017-07-03 15:33:06.557405759 +0000
++++ lib/sanitizer_common/sanitizer_linux.h
+@@ -14,7 +14,7 @@
+ #define SANITIZER_LINUX_H
+ 
+ #include "sanitizer_platform.h"
+-#if SANITIZER_FREEBSD || SANITIZER_LINUX
++#if SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD
+ #include "sanitizer_common.h"
+ #include "sanitizer_internal_defs.h"
+ #include "sanitizer_posix.h"
+@@ -130,5 +130,5 @@ ALWAYS_INLINE uptr *get_android_tls_ptr(
+ 
+ }  // namespace __sanitizer
+ 
+-#endif  // SANITIZER_FREEBSD || SANITIZER_LINUX
++#endif  // SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD
+ #endif  // SANITIZER_LINUX_H
diff --git a/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__linux__libcdep.cc b/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__linux__libcdep.cc
new file mode 100644
index 0000000000..e4ec2fb347
--- /dev/null
+++ b/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__linux__libcdep.cc
@@ -0,0 +1,69 @@
+$NetBSD$
+
+--- lib/sanitizer_common/sanitizer_linux_libcdep.cc.orig	2017-07-03 15:33:06.557567721 +0000
++++ lib/sanitizer_common/sanitizer_linux_libcdep.cc
+@@ -14,13 +14,14 @@
+ 
+ #include "sanitizer_platform.h"
+ 
+-#if SANITIZER_FREEBSD || SANITIZER_LINUX
++#if SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD
+ 
+ #include "sanitizer_allocator_internal.h"
+ #include "sanitizer_atomic.h"
+ #include "sanitizer_common.h"
+ #include "sanitizer_flags.h"
+ #include "sanitizer_freebsd.h"
++#include "sanitizer_netbsd.h"
+ #include "sanitizer_linux.h"
+ #include "sanitizer_placement_new.h"
+ #include "sanitizer_procmaps.h"
+@@ -151,7 +152,7 @@ bool SanitizerGetThreadName(char *name, 
+ #endif
+ }
+ 
+-#if !SANITIZER_FREEBSD && !SANITIZER_ANDROID && !SANITIZER_GO
++#if !SANITIZER_FREEBSD && !SANITIZER_ANDROID && !SANITIZER_GO && !SANITIZER_NETBSD
+ static uptr g_tls_size;
+ 
+ #ifdef __i386__
+@@ -179,7 +180,7 @@ void InitTlsSize() {
+ }
+ #else
+ void InitTlsSize() { }
+-#endif  // !SANITIZER_FREEBSD && !SANITIZER_ANDROID && !SANITIZER_GO
++#endif  // !SANITIZER_FREEBSD && !SANITIZER_ANDROID && !SANITIZER_GO && !SANITIZER_NETBSD
+ 
+ #if (defined(__x86_64__) || defined(__i386__) || defined(__mips__) \
+     || defined(__aarch64__) || defined(__powerpc64__) || defined(__s390__) \
+@@ -336,6 +337,12 @@ uptr ThreadSelf() {
+ }
+ #endif  // SANITIZER_FREEBSD
+ 
++#if SANITIZER_NETBSD                                                                                                                                                                          
++uptr ThreadSelf() {
++  return (uptr)pthread_self();
++}
++#endif // SANITIZER_NETBSD
++
+ #if !SANITIZER_GO
+ static void GetTls(uptr *addr, uptr *size) {
+ #if SANITIZER_LINUX && !SANITIZER_ANDROID
+@@ -365,7 +372,7 @@ static void GetTls(uptr *addr, uptr *siz
+     *addr = (uptr) dtv[2];
+     *size = (*addr == 0) ? 0 : ((uptr) segbase[0] - (uptr) dtv[2]);
+   }
+-#elif SANITIZER_ANDROID
++#elif SANITIZER_ANDROID || SANITIZER_NETBSD
+   *addr = 0;
+   *size = 0;
+ #else
+@@ -376,7 +383,7 @@ static void GetTls(uptr *addr, uptr *siz
+ 
+ #if !SANITIZER_GO
+ uptr GetTlsSize() {
+-#if SANITIZER_FREEBSD || SANITIZER_ANDROID
++#if SANITIZER_FREEBSD || SANITIZER_ANDROID || SANITIZER_NETBSD
+   uptr addr, size;
+   GetTls(&addr, &size);
+   return size;
diff --git a/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__netbsd.h b/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__netbsd.h
new file mode 100644
index 0000000000..114c5d6967
--- /dev/null
+++ b/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__netbsd.h
@@ -0,0 +1,25 @@
+$NetBSD$
+
+--- lib/sanitizer_common/sanitizer_netbsd.h.orig	2017-07-03 15:44:10.252636298 +0000
++++ lib/sanitizer_common/sanitizer_netbsd.h
+@@ -0,0 +1,20 @@
++//===-- sanitizer_freebsd.h -------------------------------------*- C++ -*-===//
++//
++//                     The LLVM Compiler Infrastructure
++//
++// This file is distributed under the University of Illinois Open Source
++// License. See LICENSE.TXT for details.
++//
++//===----------------------------------------------------------------------===//
++//
++// This file is a part of Sanitizer runtime. It contains NetBSD-specific
++// definitions.
++//
++//===----------------------------------------------------------------------===//
++
++#ifndef SANITIZER_NETBSD_H
++#define SANITIZER_NETBSD_H
++
++#include "sanitizer_internal_defs.h"
++
++#endif  // SANITIZER_NETBSD_H
diff --git a/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__platform.h b/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__platform.h
new file mode 100644
index 0000000000..bd7a78f6ef
--- /dev/null
+++ b/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__platform.h
@@ -0,0 +1,35 @@
+$NetBSD$
+
+--- lib/sanitizer_common/sanitizer_platform.h.orig	2017-07-03 15:33:06.558504013 +0000
++++ lib/sanitizer_common/sanitizer_platform.h
+@@ -13,7 +13,7 @@
+ #ifndef SANITIZER_PLATFORM_H
+ #define SANITIZER_PLATFORM_H
+ 
+-#if !defined(__linux__) && !defined(__FreeBSD__) && \
++#if !defined(__linux__) && !defined(__FreeBSD__) && !defined(__NetBSD__) && \
+   !defined(__APPLE__) && !defined(_WIN32)
+ # error "This operating system is not supported"
+ #endif
+@@ -30,6 +30,12 @@
+ # define SANITIZER_FREEBSD 0
+ #endif
+ 
++#if defined(__NetBSD__)
++# define SANITIZER_NETBSD 1
++#else
++# define SANITIZER_NETBSD 0
++#endif
++
+ #if defined(__APPLE__)
+ # define SANITIZER_MAC     1
+ # include <TargetConditionals.h>
+@@ -79,7 +85,7 @@
+ # define SANITIZER_ANDROID 0
+ #endif
+ 
+-#define SANITIZER_POSIX (SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_MAC)
++#define SANITIZER_POSIX (SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD || SANITIZER_MAC)
+ 
+ #if __LP64__ || defined(_WIN64)
+ #  define SANITIZER_WORDSIZE 64
diff --git a/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__platform__interceptors.h b/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__platform__interceptors.h
new file mode 100644
index 0000000000..f3744febfe
--- /dev/null
+++ b/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__platform__interceptors.h
@@ -0,0 +1,241 @@
+$NetBSD$
+
+--- lib/sanitizer_common/sanitizer_platform_interceptors.h.orig	2017-07-03 15:33:06.558600953 +0000
++++ lib/sanitizer_common/sanitizer_platform_interceptors.h
+@@ -49,6 +49,12 @@
+ # define SI_FREEBSD 0
+ #endif
+ 
++#if SANITIZER_NETBSD
++# define SI_NETBSD 1
++#else
++# define SI_NETBSD 0
++#endif
++
+ #if SANITIZER_LINUX
+ # define SI_LINUX 1
+ #else
+@@ -111,7 +117,7 @@
+ #define SANITIZER_INTERCEPT_MEMMEM \
+   SI_NOT_WINDOWS && !SI_MAC_DEPLOYMENT_BELOW_10_7
+ #define SANITIZER_INTERCEPT_MEMCHR 1
+-#define SANITIZER_INTERCEPT_MEMRCHR SI_FREEBSD || SI_LINUX
++#define SANITIZER_INTERCEPT_MEMRCHR SI_FREEBSD || SI_LINUX || SI_NETBSD
+ 
+ #define SANITIZER_INTERCEPT_READ   SI_NOT_WINDOWS
+ #define SANITIZER_INTERCEPT_PREAD  SI_NOT_WINDOWS
+@@ -127,7 +133,7 @@
+ #define SANITIZER_INTERCEPT_READV SI_NOT_WINDOWS
+ #define SANITIZER_INTERCEPT_WRITEV SI_NOT_WINDOWS
+ 
+-#define SANITIZER_INTERCEPT_PREADV SI_FREEBSD || SI_LINUX_NOT_ANDROID
++#define SANITIZER_INTERCEPT_PREADV SI_FREEBSD || SI_NETBSD || SI_LINUX_NOT_ANDROID
+ #define SANITIZER_INTERCEPT_PWRITEV SI_LINUX_NOT_ANDROID
+ #define SANITIZER_INTERCEPT_PREADV64 SI_LINUX_NOT_ANDROID
+ #define SANITIZER_INTERCEPT_PWRITEV64 SI_LINUX_NOT_ANDROID
+@@ -142,7 +148,7 @@
+ 
+ #ifndef SANITIZER_INTERCEPT_PRINTF
+ # define SANITIZER_INTERCEPT_PRINTF SI_NOT_WINDOWS
+-# define SANITIZER_INTERCEPT_PRINTF_L SI_FREEBSD
++# define SANITIZER_INTERCEPT_PRINTF_L SI_FREEBSD || SI_NETBSD
+ # define SANITIZER_INTERCEPT_ISOC99_PRINTF SI_LINUX_NOT_ANDROID
+ #endif
+ 
+@@ -151,13 +157,13 @@
+ 
+ #define SANITIZER_INTERCEPT_GETPWNAM_AND_FRIENDS SI_NOT_WINDOWS
+ #define SANITIZER_INTERCEPT_GETPWNAM_R_AND_FRIENDS \
+-  SI_FREEBSD || SI_MAC || SI_LINUX_NOT_ANDROID
++  SI_FREEBSD || SI_NETBSD || SI_MAC || SI_LINUX_NOT_ANDROID
+ #define SANITIZER_INTERCEPT_GETPWENT \
+-  SI_FREEBSD || SI_MAC || SI_LINUX_NOT_ANDROID
++  SI_FREEBSD || SI_NETBSD || SI_MAC || SI_LINUX_NOT_ANDROID
+ #define SANITIZER_INTERCEPT_FGETPWENT SI_LINUX_NOT_ANDROID
+-#define SANITIZER_INTERCEPT_GETPWENT_R SI_FREEBSD || SI_LINUX_NOT_ANDROID
++#define SANITIZER_INTERCEPT_GETPWENT_R SI_FREEBSD || SI_NETBSD || SI_LINUX_NOT_ANDROID
+ #define SANITIZER_INTERCEPT_SETPWENT SI_MAC || SI_LINUX_NOT_ANDROID
+-#define SANITIZER_INTERCEPT_CLOCK_GETTIME SI_FREEBSD || SI_LINUX
++#define SANITIZER_INTERCEPT_CLOCK_GETTIME SI_FREEBSD || SI_NETBSD || SI_LINUX
+ #define SANITIZER_INTERCEPT_GETITIMER SI_NOT_WINDOWS
+ #define SANITIZER_INTERCEPT_TIME SI_NOT_WINDOWS
+ #define SANITIZER_INTERCEPT_GLOB SI_LINUX_NOT_ANDROID
+@@ -200,41 +206,41 @@
+ #define SANITIZER_INTERCEPT_MBSNRTOWCS SI_MAC || SI_LINUX_NOT_ANDROID
+ #define SANITIZER_INTERCEPT_WCSTOMBS SI_NOT_WINDOWS
+ #define SANITIZER_INTERCEPT_WCSNRTOMBS \
+-  SI_FREEBSD || SI_MAC || SI_LINUX_NOT_ANDROID
++  SI_FREEBSD || SI_NETBSD || SI_MAC || SI_LINUX_NOT_ANDROID
+ #define SANITIZER_INTERCEPT_WCRTOMB \
+-  SI_FREEBSD || SI_MAC || SI_LINUX_NOT_ANDROID
++  SI_FREEBSD || SI_NETBSD || SI_MAC || SI_LINUX_NOT_ANDROID
+ #define SANITIZER_INTERCEPT_TCGETATTR SI_LINUX_NOT_ANDROID
+ #define SANITIZER_INTERCEPT_REALPATH SI_NOT_WINDOWS
+ #define SANITIZER_INTERCEPT_CANONICALIZE_FILE_NAME SI_LINUX_NOT_ANDROID
+ #define SANITIZER_INTERCEPT_CONFSTR \
+-  SI_FREEBSD || SI_MAC || SI_LINUX_NOT_ANDROID
++  SI_FREEBSD || SI_NETBSD || SI_MAC || SI_LINUX_NOT_ANDROID
+ #define SANITIZER_INTERCEPT_SCHED_GETAFFINITY SI_LINUX_NOT_ANDROID
+ #define SANITIZER_INTERCEPT_SCHED_GETPARAM SI_LINUX_NOT_ANDROID
+ #define SANITIZER_INTERCEPT_STRERROR SI_NOT_WINDOWS
+ #define SANITIZER_INTERCEPT_STRERROR_R SI_NOT_WINDOWS
+ #define SANITIZER_INTERCEPT_XPG_STRERROR_R SI_LINUX_NOT_ANDROID
+ #define SANITIZER_INTERCEPT_SCANDIR \
+-  SI_FREEBSD || SI_LINUX_NOT_ANDROID
++  SI_FREEBSD || SI_NETBSD || SI_LINUX_NOT_ANDROID
+ #define SANITIZER_INTERCEPT_SCANDIR64 SI_LINUX_NOT_ANDROID
+ #define SANITIZER_INTERCEPT_GETGROUPS SI_NOT_WINDOWS
+ #define SANITIZER_INTERCEPT_POLL SI_NOT_WINDOWS
+ #define SANITIZER_INTERCEPT_PPOLL SI_LINUX_NOT_ANDROID
+ #define SANITIZER_INTERCEPT_WORDEXP \
+-  SI_FREEBSD || (SI_MAC && !SI_IOS) || SI_LINUX_NOT_ANDROID
++  SI_FREEBSD || SI_NETBSD || (SI_MAC && !SI_IOS) || SI_LINUX_NOT_ANDROID
+ #define SANITIZER_INTERCEPT_SIGWAIT SI_NOT_WINDOWS
+ #define SANITIZER_INTERCEPT_SIGWAITINFO SI_LINUX_NOT_ANDROID
+ #define SANITIZER_INTERCEPT_SIGTIMEDWAIT SI_LINUX_NOT_ANDROID
+ #define SANITIZER_INTERCEPT_SIGSETOPS \
+-  SI_FREEBSD || SI_MAC || SI_LINUX_NOT_ANDROID
++  SI_FREEBSD || SI_NETBSD || SI_MAC || SI_LINUX_NOT_ANDROID
+ #define SANITIZER_INTERCEPT_SIGPENDING SI_NOT_WINDOWS
+ #define SANITIZER_INTERCEPT_SIGPROCMASK SI_NOT_WINDOWS
+-#define SANITIZER_INTERCEPT_BACKTRACE SI_FREEBSD || SI_LINUX_NOT_ANDROID
++#define SANITIZER_INTERCEPT_BACKTRACE SI_FREEBSD || SI_NETBSD || SI_LINUX_NOT_ANDROID
+ #define SANITIZER_INTERCEPT_GETMNTENT SI_LINUX
+ #define SANITIZER_INTERCEPT_GETMNTENT_R SI_LINUX_NOT_ANDROID
+ #define SANITIZER_INTERCEPT_STATFS SI_FREEBSD || SI_MAC || SI_LINUX_NOT_ANDROID
+ #define SANITIZER_INTERCEPT_STATFS64 \
+   (SI_MAC && !SI_IOS) || SI_LINUX_NOT_ANDROID
+-#define SANITIZER_INTERCEPT_STATVFS SI_FREEBSD || SI_LINUX_NOT_ANDROID
++#define SANITIZER_INTERCEPT_STATVFS SI_FREEBSD || SI_NETBSD || SI_LINUX_NOT_ANDROID
+ #define SANITIZER_INTERCEPT_STATVFS64 SI_LINUX_NOT_ANDROID
+ #define SANITIZER_INTERCEPT_INITGROUPS SI_NOT_WINDOWS
+ #define SANITIZER_INTERCEPT_ETHER_NTOA_ATON SI_NOT_WINDOWS
+@@ -242,18 +248,18 @@
+   SI_FREEBSD || SI_MAC || SI_LINUX_NOT_ANDROID
+ #define SANITIZER_INTERCEPT_ETHER_R SI_FREEBSD || SI_LINUX_NOT_ANDROID
+ #define SANITIZER_INTERCEPT_SHMCTL \
+-  ((SI_FREEBSD || SI_LINUX_NOT_ANDROID) && SANITIZER_WORDSIZE == 64)
++  SI_NETBSD || ((SI_FREEBSD || SI_LINUX_NOT_ANDROID) && SANITIZER_WORDSIZE == 64)
+ #define SANITIZER_INTERCEPT_RANDOM_R SI_LINUX_NOT_ANDROID
+ #define SANITIZER_INTERCEPT_PTHREAD_ATTR_GET SI_NOT_WINDOWS
+ #define SANITIZER_INTERCEPT_PTHREAD_ATTR_GETINHERITSCHED \
+-  SI_FREEBSD || SI_MAC || SI_LINUX_NOT_ANDROID
++  SI_FREEBSD || SI_NETBSD || SI_MAC || SI_LINUX_NOT_ANDROID
+ #define SANITIZER_INTERCEPT_PTHREAD_ATTR_GETAFFINITY_NP SI_LINUX_NOT_ANDROID
+ #define SANITIZER_INTERCEPT_PTHREAD_MUTEXATTR_GETPSHARED SI_NOT_WINDOWS
+ #define SANITIZER_INTERCEPT_PTHREAD_MUTEXATTR_GETTYPE SI_NOT_WINDOWS
+ #define SANITIZER_INTERCEPT_PTHREAD_MUTEXATTR_GETPROTOCOL \
+-  SI_MAC || SI_LINUX_NOT_ANDROID
++  SI_MAC || SI_NETBSD || SI_LINUX_NOT_ANDROID
+ #define SANITIZER_INTERCEPT_PTHREAD_MUTEXATTR_GETPRIOCEILING \
+-  SI_MAC || SI_LINUX_NOT_ANDROID
++  SI_MAC || SI_NETBSD || SI_LINUX_NOT_ANDROID
+ #define SANITIZER_INTERCEPT_PTHREAD_MUTEXATTR_GETROBUST SI_LINUX_NOT_ANDROID
+ #define SANITIZER_INTERCEPT_PTHREAD_MUTEXATTR_GETROBUST_NP SI_LINUX_NOT_ANDROID
+ #define SANITIZER_INTERCEPT_PTHREAD_RWLOCKATTR_GETPSHARED SI_NOT_WINDOWS
+@@ -272,29 +278,29 @@
+ #define SANITIZER_INTERCEPT_LGAMMAL_R SI_LINUX_NOT_ANDROID
+ #define SANITIZER_INTERCEPT_DRAND48_R SI_LINUX_NOT_ANDROID
+ #define SANITIZER_INTERCEPT_RAND_R \
+-  SI_FREEBSD || SI_MAC || SI_LINUX_NOT_ANDROID
+-#define SANITIZER_INTERCEPT_ICONV SI_FREEBSD || SI_LINUX_NOT_ANDROID
++  SI_FREEBSD || SI_NETBSD || SI_MAC || SI_LINUX_NOT_ANDROID
++#define SANITIZER_INTERCEPT_ICONV SI_FREEBSD || SI_NETBSD || SI_LINUX_NOT_ANDROID
+ #define SANITIZER_INTERCEPT_TIMES SI_NOT_WINDOWS
+ 
+ // FIXME: getline seems to be available on OSX 10.7
+-#define SANITIZER_INTERCEPT_GETLINE SI_FREEBSD || SI_LINUX_NOT_ANDROID
++#define SANITIZER_INTERCEPT_GETLINE SI_FREEBSD || SI_NETBSD || SI_LINUX_NOT_ANDROID
+ 
+-#define SANITIZER_INTERCEPT__EXIT SI_LINUX || SI_FREEBSD || SI_MAC
++#define SANITIZER_INTERCEPT__EXIT SI_LINUX || SI_FREEBSD || SI_NETBSD || SI_MAC
+ 
+ #define SANITIZER_INTERCEPT_PHTREAD_MUTEX SI_NOT_WINDOWS
+ #define SANITIZER_INTERCEPT_PTHREAD_SETNAME_NP \
+-  SI_FREEBSD || SI_LINUX_NOT_ANDROID
++  SI_FREEBSD || SI_NETBSD || SI_LINUX_NOT_ANDROID
+ 
+ #define SANITIZER_INTERCEPT_TLS_GET_ADDR \
+-  SI_FREEBSD || SI_LINUX_NOT_ANDROID
++  SI_FREEBSD || SI_NETBSD || SI_LINUX_NOT_ANDROID
+ 
+ #define SANITIZER_INTERCEPT_LISTXATTR SI_LINUX
+ #define SANITIZER_INTERCEPT_GETXATTR SI_LINUX
+ #define SANITIZER_INTERCEPT_GETRESID SI_LINUX
+ #define SANITIZER_INTERCEPT_GETIFADDRS \
+-  SI_FREEBSD || SI_LINUX_NOT_ANDROID || SI_MAC
++  SI_FREEBSD || SI_NETBSD || SI_LINUX_NOT_ANDROID || SI_MAC
+ #define SANITIZER_INTERCEPT_IF_INDEXTONAME \
+-  SI_FREEBSD || SI_LINUX_NOT_ANDROID || SI_MAC
++  SI_FREEBSD || SI_NETBSD || SI_LINUX_NOT_ANDROID || SI_MAC
+ #define SANITIZER_INTERCEPT_CAPGET SI_LINUX_NOT_ANDROID
+ #if SI_LINUX && defined(__arm__)
+ #define SANITIZER_INTERCEPT_AEABI_MEM 1
+@@ -302,32 +308,32 @@
+ #define SANITIZER_INTERCEPT_AEABI_MEM 0
+ #endif
+ #define SANITIZER_INTERCEPT___BZERO SI_MAC
+-#define SANITIZER_INTERCEPT_FTIME !SI_FREEBSD && SI_NOT_WINDOWS
++#define SANITIZER_INTERCEPT_FTIME !SI_FREEBSD && !SI_NETBSD && SI_NOT_WINDOWS
+ #define SANITIZER_INTERCEPT_XDR SI_LINUX_NOT_ANDROID
+-#define SANITIZER_INTERCEPT_TSEARCH SI_LINUX_NOT_ANDROID || SI_MAC
++#define SANITIZER_INTERCEPT_TSEARCH SI_LINUX_NOT_ANDROID || SI_MAC || SI_NETBSD
+ #define SANITIZER_INTERCEPT_LIBIO_INTERNALS SI_LINUX_NOT_ANDROID
+ #define SANITIZER_INTERCEPT_FOPEN SI_NOT_WINDOWS
+ #define SANITIZER_INTERCEPT_FOPEN64 SI_LINUX_NOT_ANDROID
+-#define SANITIZER_INTERCEPT_OPEN_MEMSTREAM SI_LINUX_NOT_ANDROID
++#define SANITIZER_INTERCEPT_OPEN_MEMSTREAM SI_LINUX_NOT_ANDROID || SI_NETBSD
+ #define SANITIZER_INTERCEPT_OBSTACK SI_LINUX_NOT_ANDROID
+ #define SANITIZER_INTERCEPT_FFLUSH SI_NOT_WINDOWS
+ #define SANITIZER_INTERCEPT_FCLOSE SI_NOT_WINDOWS
+ 
+ #ifndef SANITIZER_INTERCEPT_DLOPEN_DLCLOSE
+ #define SANITIZER_INTERCEPT_DLOPEN_DLCLOSE \
+-    SI_FREEBSD || SI_LINUX_NOT_ANDROID || SI_MAC
++    SI_FREEBSD || SI_NETBSD || SI_LINUX_NOT_ANDROID || SI_MAC
+ #endif
+ 
+-#define SANITIZER_INTERCEPT_GETPASS SI_LINUX_NOT_ANDROID || SI_MAC
++#define SANITIZER_INTERCEPT_GETPASS SI_LINUX_NOT_ANDROID || SI_MAC || SI_NETBSD
+ #define SANITIZER_INTERCEPT_TIMERFD SI_LINUX_NOT_ANDROID
+ 
+ #define SANITIZER_INTERCEPT_MLOCKX SI_NOT_WINDOWS
+ #define SANITIZER_INTERCEPT_FOPENCOOKIE SI_LINUX_NOT_ANDROID
+-#define SANITIZER_INTERCEPT_SEM SI_LINUX || SI_FREEBSD
++#define SANITIZER_INTERCEPT_SEM SI_LINUX || SI_FREEBSD || SI_NETBSD
+ #define SANITIZER_INTERCEPT_PTHREAD_SETCANCEL SI_NOT_WINDOWS
+-#define SANITIZER_INTERCEPT_MINCORE SI_LINUX
++#define SANITIZER_INTERCEPT_MINCORE SI_LINUX || SI_NETBSD
+ #define SANITIZER_INTERCEPT_PROCESS_VM_READV SI_LINUX
+-#define SANITIZER_INTERCEPT_CTERMID SI_LINUX || SI_MAC || SI_FREEBSD
++#define SANITIZER_INTERCEPT_CTERMID SI_LINUX || SI_MAC || SI_FREEBSD || SI_NETBSD
+ #define SANITIZER_INTERCEPT_CTERMID_R SI_MAC || SI_FREEBSD
+ 
+ #define SANITIZER_INTERCEPTOR_HOOKS SI_LINUX || SI_MAC || SI_WINDOWS
+@@ -335,7 +341,7 @@
+ #define SANITIZER_INTERCEPT_SEND_SENDTO SI_NOT_WINDOWS
+ #define SANITIZER_INTERCEPT_EVENTFD_READ_WRITE SI_LINUX
+ 
+-#define SANITIZER_INTERCEPT_STAT (SI_FREEBSD || SI_MAC || SI_ANDROID)
++#define SANITIZER_INTERCEPT_STAT (SI_FREEBSD || SI_MAC || SI_ANDROID || SI_NETBSD)
+ #define SANITIZER_INTERCEPT___XSTAT !SANITIZER_INTERCEPT_STAT && SI_NOT_WINDOWS
+ #define SANITIZER_INTERCEPT___XSTAT64 SI_LINUX_NOT_ANDROID
+ #define SANITIZER_INTERCEPT___LXSTAT SANITIZER_INTERCEPT___XSTAT
+@@ -345,12 +351,12 @@
+ #define SANITIZER_INTERCEPT_UTMPX SI_LINUX_NOT_ANDROID || SI_MAC || SI_FREEBSD
+ 
+ #define SANITIZER_INTERCEPT_GETLOADAVG \
+-  SI_LINUX_NOT_ANDROID || SI_MAC || SI_FREEBSD
++  SI_LINUX_NOT_ANDROID || SI_MAC || SI_FREEBSD || SI_NETBSD
+ 
+-#define SANITIZER_INTERCEPT_MALLOPT_AND_MALLINFO (!SI_FREEBSD && !SI_MAC)
+-#define SANITIZER_INTERCEPT_MEMALIGN (!SI_FREEBSD && !SI_MAC)
+-#define SANITIZER_INTERCEPT_PVALLOC (!SI_FREEBSD && !SI_MAC)
+-#define SANITIZER_INTERCEPT_CFREE (!SI_FREEBSD && !SI_MAC)
++#define SANITIZER_INTERCEPT_MALLOPT_AND_MALLINFO (!SI_FREEBSD && !SI_MAC && !SI_NETBSD)
++#define SANITIZER_INTERCEPT_MEMALIGN (!SI_FREEBSD && !SI_MAC && !SI_NETBSD)
++#define SANITIZER_INTERCEPT_PVALLOC (!SI_FREEBSD && !SI_MAC && !SI_NETBSD)
++#define SANITIZER_INTERCEPT_CFREE (!SI_FREEBSD && !SI_MAC && !SI_NETBSD)
+ #define SANITIZER_INTERCEPT_ALIGNED_ALLOC (!SI_MAC)
+ #define SANITIZER_INTERCEPT_MALLOC_USABLE_SIZE (!SI_MAC)
+ #define SANITIZER_INTERCEPT_MCHECK_MPROBE SI_LINUX_NOT_ANDROID
diff --git a/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__platform__limits__posix.cc b/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__platform__limits__posix.cc
new file mode 100644
index 0000000000..9f08406d45
--- /dev/null
+++ b/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__platform__limits__posix.cc
@@ -0,0 +1,239 @@
+$NetBSD$
+
+--- lib/sanitizer_common/sanitizer_platform_limits_posix.cc.orig	2017-07-03 15:33:06.558965384 +0000
++++ lib/sanitizer_common/sanitizer_platform_limits_posix.cc
+@@ -14,7 +14,7 @@
+ 
+ #include "sanitizer_platform.h"
+ 
+-#if SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_MAC
++#if SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_MAC || SANITIZER_NETBSD
+ // Tests in this file assume that off_t-dependent data structures match the
+ // libc ABI. For example, struct dirent here is what readdir() function (as
+ // exported from libc) returns, and not the user-facing "dirent", which
+@@ -79,7 +79,7 @@
+ #include <net/if_arp.h>
+ #endif
+ 
+-#if SANITIZER_FREEBSD
++#if SANITIZER_FREEBSD || SANITIZER_NETBSD
+ # include <sys/mount.h>
+ # include <sys/sockio.h>
+ # include <sys/socket.h>
+@@ -94,16 +94,18 @@
+ # include <sys/statvfs.h>
+ # include <sys/soundcard.h>
+ # include <sys/mtio.h>
+-# include <sys/consio.h>
+-# include <sys/kbio.h>
+-# include <sys/link_elf.h>
+ # include <netinet/ip_mroute.h>
+ # include <netinet/in.h>
+-# include <net/ethernet.h>
+ # include <net/ppp_defs.h>
+ # include <glob.h>
+ # include <term.h>
++#endif
+ 
++#if SANITIZER_FREEBSD
++# include <sys/consio.h>
++# include <sys/kbio.h>
++# include <sys/link_elf.h>
++# include <net/ethernet.h>
+ #define _KERNEL  // to declare 'shminfo' structure
+ # include <sys/shm.h>
+ #undef _KERNEL
+@@ -111,11 +113,19 @@
+ #undef INLINE  // to avoid clashes with sanitizers' definitions
+ #endif
+ 
+-#if SANITIZER_FREEBSD || SANITIZER_IOS
++#if SANITIZER_NETBSD
++# include <net/if_ether.h>
++# include <sys/shm.h>
++# include <link_elf.h>
++# define statfs statvfs
++# define d_ino d_fileno 
++#endif
++
++#if SANITIZER_FREEBSD || SANITIZER_IOS || SANITIZER_NETBSD
+ #undef IOC_DIRMASK
+ #endif
+ 
+-#if SANITIZER_LINUX || SANITIZER_FREEBSD
++#if SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD
+ # include <utime.h>
+ # include <sys/ptrace.h>
+ # if defined(__mips64) || defined(__aarch64__) || defined(__arm__)
+@@ -200,9 +210,9 @@ typedef struct user_fpregs elf_fpregset_
+ namespace __sanitizer {
+   unsigned struct_utsname_sz = sizeof(struct utsname);
+   unsigned struct_stat_sz = sizeof(struct stat);
+-#if !SANITIZER_IOS && !SANITIZER_FREEBSD
++#if !SANITIZER_IOS && !SANITIZER_FREEBSD  && !SANITIZER_NETBSD
+   unsigned struct_stat64_sz = sizeof(struct stat64);
+-#endif // !SANITIZER_IOS && !SANITIZER_FREEBSD
++#endif // !SANITIZER_IOS && !SANITIZER_FREEBSD && !SANITIZER_NETBSD
+   unsigned struct_rusage_sz = sizeof(struct rusage);
+   unsigned struct_tm_sz = sizeof(struct tm);
+   unsigned struct_passwd_sz = sizeof(struct passwd);
+@@ -245,12 +255,12 @@ namespace __sanitizer {
+   unsigned struct_oldold_utsname_sz = sizeof(struct oldold_utsname);
+ #endif // SANITIZER_LINUX
+ 
+-#if SANITIZER_LINUX || SANITIZER_FREEBSD
++#if SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD
+   unsigned struct_rlimit_sz = sizeof(struct rlimit);
+   unsigned struct_timespec_sz = sizeof(struct timespec);
+   unsigned struct_utimbuf_sz = sizeof(struct utimbuf);
+   unsigned struct_itimerspec_sz = sizeof(struct itimerspec);
+-#endif // SANITIZER_LINUX || SANITIZER_FREEBSD
++#endif // SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD
+ 
+ #if SANITIZER_LINUX && !SANITIZER_ANDROID
+   unsigned struct_ustat_sz = sizeof(struct ustat);
+@@ -258,12 +268,12 @@ namespace __sanitizer {
+   unsigned struct_statvfs64_sz = sizeof(struct statvfs64);
+ #endif // SANITIZER_LINUX && !SANITIZER_ANDROID
+ 
+-#if (SANITIZER_LINUX || SANITIZER_FREEBSD) && !SANITIZER_ANDROID
++#if (SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD) && !SANITIZER_ANDROID
+   unsigned struct_timex_sz = sizeof(struct timex);
+   unsigned struct_msqid_ds_sz = sizeof(struct msqid_ds);
+   unsigned struct_mq_attr_sz = sizeof(struct mq_attr);
+   unsigned struct_statvfs_sz = sizeof(struct statvfs);
+-#endif // (SANITIZER_LINUX || SANITIZER_FREEBSD) && !SANITIZER_ANDROID
++#endif // (SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD) && !SANITIZER_ANDROID
+ 
+   uptr sig_ign = (uptr)SIG_IGN;
+   uptr sig_dfl = (uptr)SIG_DFL;
+@@ -274,9 +284,16 @@ namespace __sanitizer {
+ #endif
+ 
+ 
+-#if (SANITIZER_LINUX || SANITIZER_FREEBSD) && !SANITIZER_ANDROID
++#if (SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD) && !SANITIZER_ANDROID
+   unsigned struct_shminfo_sz = sizeof(struct shminfo);
++#if !SANITIZER_NETBSD
+   unsigned struct_shm_info_sz = sizeof(struct shm_info);
++#else
++#define IPC_INFO -1
++#define SHM_INFO -1
++#define SHM_STAT -1
++  unsigned struct_shm_info_sz = -1;
++#endif
+   int shmctl_ipc_stat = (int)IPC_STAT;
+   int shmctl_ipc_info = (int)IPC_INFO;
+   int shmctl_shm_info = (int)SHM_INFO;
+@@ -310,7 +327,7 @@ unsigned struct_ElfW_Phdr_sz = sizeof(El
+ unsigned struct_ElfW_Phdr_sz = sizeof(Elf_Phdr);
+ #endif
+ 
+-#if (SANITIZER_LINUX || SANITIZER_FREEBSD) && !SANITIZER_ANDROID
++#if (SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD) && !SANITIZER_ANDROID
+   int glob_nomatch = GLOB_NOMATCH;
+   int glob_altdirfunc = GLOB_ALTDIRFUNC;
+ #endif
+@@ -452,7 +469,7 @@ unsigned struct_ElfW_Phdr_sz = sizeof(El
+   unsigned struct_seq_event_rec_sz = sizeof(struct seq_event_rec);
+   unsigned struct_synth_info_sz = sizeof(struct synth_info);
+   unsigned struct_vt_mode_sz = sizeof(struct vt_mode);
+-#endif // SANITIZER_LINUX || SANITIZER_FREEBSD
++#endif // SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD
+ 
+ #if SANITIZER_LINUX && !SANITIZER_ANDROID
+   unsigned struct_ax25_parms_struct_sz = sizeof(struct ax25_parms_struct);
+@@ -479,7 +496,7 @@ unsigned struct_ElfW_Phdr_sz = sizeof(El
+   unsigned struct_unimapinit_sz = sizeof(struct unimapinit);
+ #endif // SANITIZER_LINUX && !SANITIZER_ANDROID
+ 
+-#if (SANITIZER_LINUX || SANITIZER_FREEBSD) && !SANITIZER_ANDROID
++#if (SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD) && !SANITIZER_ANDROID
+   unsigned struct_audio_buf_info_sz = sizeof(struct audio_buf_info);
+   unsigned struct_ppp_stats_sz = sizeof(struct ppp_stats);
+ #endif // (SANITIZER_LINUX || SANITIZER_FREEBSD) && !SANITIZER_ANDROID
+@@ -535,7 +552,7 @@ unsigned struct_ElfW_Phdr_sz = sizeof(El
+   unsigned IOCTL_TIOCSPGRP = TIOCSPGRP;
+   unsigned IOCTL_TIOCSTI = TIOCSTI;
+   unsigned IOCTL_TIOCSWINSZ = TIOCSWINSZ;
+-#if ((SANITIZER_LINUX || SANITIZER_FREEBSD) && !SANITIZER_ANDROID)
++#if ((SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD) && !SANITIZER_ANDROID)
+   unsigned IOCTL_SIOCGETSGCNT = SIOCGETSGCNT;
+   unsigned IOCTL_SIOCGETVIFCNT = SIOCGETVIFCNT;
+ #endif
+@@ -975,7 +992,7 @@ COMPILER_CHECK(IOC_NR(0x12345678) == _IO
+ COMPILER_CHECK(IOC_TYPE(0x12345678) == _IOC_TYPE(0x12345678));
+ #endif // SANITIZER_LINUX
+ 
+-#if SANITIZER_LINUX || SANITIZER_FREEBSD
++#if SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD
+ // There are more undocumented fields in dl_phdr_info that we are not interested
+ // in.
+ COMPILER_CHECK(sizeof(__sanitizer_dl_phdr_info) <= sizeof(dl_phdr_info));
+@@ -983,9 +1000,9 @@ CHECK_SIZE_AND_OFFSET(dl_phdr_info, dlpi
+ CHECK_SIZE_AND_OFFSET(dl_phdr_info, dlpi_name);
+ CHECK_SIZE_AND_OFFSET(dl_phdr_info, dlpi_phdr);
+ CHECK_SIZE_AND_OFFSET(dl_phdr_info, dlpi_phnum);
+-#endif // SANITIZER_LINUX || SANITIZER_FREEBSD
++#endif // SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD
+ 
+-#if (SANITIZER_LINUX || SANITIZER_FREEBSD) && !SANITIZER_ANDROID
++#if (SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD) && !SANITIZER_ANDROID
+ CHECK_TYPE_SIZE(glob_t);
+ CHECK_SIZE_AND_OFFSET(glob_t, gl_pathc);
+ CHECK_SIZE_AND_OFFSET(glob_t, gl_pathv);
+@@ -1037,7 +1054,7 @@ COMPILER_CHECK(sizeof(__sanitizer_dirent
+ CHECK_SIZE_AND_OFFSET(dirent, d_ino);
+ #if SANITIZER_MAC
+ CHECK_SIZE_AND_OFFSET(dirent, d_seekoff);
+-#elif SANITIZER_FREEBSD
++#elif SANITIZER_FREEBSD || SANITIZER_NETBSD
+ // There is no 'd_off' field on FreeBSD.
+ #else
+ CHECK_SIZE_AND_OFFSET(dirent, d_off);
+@@ -1134,11 +1151,14 @@ CHECK_SIZE_AND_OFFSET(mntent, mnt_passno
+ 
+ CHECK_TYPE_SIZE(ether_addr);
+ 
+-#if (SANITIZER_LINUX || SANITIZER_FREEBSD) && !SANITIZER_ANDROID
++#if (SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD) && !SANITIZER_ANDROID
+ CHECK_TYPE_SIZE(ipc_perm);
+ # if SANITIZER_FREEBSD
+ CHECK_SIZE_AND_OFFSET(ipc_perm, key);
+ CHECK_SIZE_AND_OFFSET(ipc_perm, seq);
++# elif SANITIZER_NETBSD
++CHECK_SIZE_AND_OFFSET(ipc_perm, _key);
++CHECK_SIZE_AND_OFFSET(ipc_perm, _seq);
+ # else
+ CHECK_SIZE_AND_OFFSET(ipc_perm, __key);
+ CHECK_SIZE_AND_OFFSET(ipc_perm, __seq);
+@@ -1175,20 +1195,20 @@ CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_next)
+ CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_name);
+ CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_addr);
+ CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_netmask);
+-#if SANITIZER_LINUX || SANITIZER_FREEBSD
++#if SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD
+ // Compare against the union, because we can't reach into the union in a
+ // compliant way.
+ #ifdef ifa_dstaddr
+ #undef ifa_dstaddr
+ #endif
+-# if SANITIZER_FREEBSD
++# if SANITIZER_FREEBSD || SANITIZER_NETBSD
+ CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_dstaddr);
+ # else
+ COMPILER_CHECK(sizeof(((__sanitizer_ifaddrs *)nullptr)->ifa_dstaddr) ==
+                sizeof(((ifaddrs *)nullptr)->ifa_ifu));
+ COMPILER_CHECK(offsetof(__sanitizer_ifaddrs, ifa_dstaddr) ==
+                offsetof(ifaddrs, ifa_ifu));
+-# endif // SANITIZER_FREEBSD
++# endif // SANITIZER_FREEBSD || SANITIZER_NETBSD
+ #else
+ CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_dstaddr);
+ #endif // SANITIZER_LINUX
+@@ -1289,4 +1309,4 @@ CHECK_TYPE_SIZE(sem_t);
+ COMPILER_CHECK(ARM_VFPREGS_SIZE == ARM_VFPREGS_SIZE_ASAN);
+ #endif
+ 
+-#endif // SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_MAC
++#endif // SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_MAC || SANITIZER_NETBSD
diff --git a/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__platform__limits__posix.h b/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__platform__limits__posix.h
new file mode 100644
index 0000000000..aa83e85128
--- /dev/null
+++ b/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__platform__limits__posix.h
@@ -0,0 +1,638 @@
+$NetBSD$
+
+--- lib/sanitizer_common/sanitizer_platform_limits_posix.h.orig	2017-07-03 15:33:06.559211156 +0000
++++ lib/sanitizer_common/sanitizer_platform_limits_posix.h
+@@ -18,18 +18,31 @@
+ #include "sanitizer_internal_defs.h"
+ #include "sanitizer_platform.h"
+ 
++// FreeBSD's and NetBSD's dlopen() returns a pointer to an Obj_Entry structure
++// that incorporates the map structure.
+ #if SANITIZER_FREEBSD
+-// FreeBSD's dlopen() returns a pointer to an Obj_Entry structure that
+-// incorporates the map structure.
+ # define GET_LINK_MAP_BY_DLOPEN_HANDLE(handle) \
+     ((link_map*)((handle) == nullptr ? nullptr : ((char*)(handle) + 544)))
+-// Get sys/_types.h, because that tells us whether 64-bit inodes are
+-// used in struct dirent below.
+-#include <sys/_types.h>
++#elif SANITIZER_NETBSD
++#if defined(__x86_64__)
++# define GET_LINK_MAP_BY_DLOPEN_HANDLE(handle) \
++    ((link_map*)((handle) == nullptr ? nullptr : ((char*)(handle) + 608)))
++#elif defined(__i386__)
++# define GET_LINK_MAP_BY_DLOPEN_HANDLE(handle) \
++    ((link_map*)((handle) == nullptr ? nullptr : ((char*)(handle) + 324)))
++#else
++#error Port sanitizer_platform_limits_posix.h.
++#endif
+ #else
+ # define GET_LINK_MAP_BY_DLOPEN_HANDLE(handle) ((link_map*)(handle))
+ #endif  // !SANITIZER_FREEBSD
+ 
++#if SANITIZER_FREEBSD
++// Get sys/_types.h, because that tells us whether 64-bit inodes are
++// used in struct dirent below.
++#include <sys/_types.h>
++#endif
++
+ #ifndef __GLIBC_PREREQ
+ #define __GLIBC_PREREQ(x, y) 0
+ #endif
+@@ -37,7 +50,7 @@
+ namespace __sanitizer {
+   extern unsigned struct_utsname_sz;
+   extern unsigned struct_stat_sz;
+-#if !SANITIZER_FREEBSD && !SANITIZER_IOS
++#if !SANITIZER_FREEBSD && !SANITIZER_IOS && !SANITIZER_NETBSD
+   extern unsigned struct_stat64_sz;
+ #endif
+   extern unsigned struct_rusage_sz;
+@@ -55,10 +68,14 @@ namespace __sanitizer {
+   extern unsigned struct_itimerspec_sz;
+   extern unsigned struct_sigevent_sz;
+   extern unsigned struct_sched_param_sz;
++#if !SANITIZER_NETBSD
+   extern unsigned struct_statfs64_sz;
++#endif
+ 
+ #if !SANITIZER_ANDROID
++#if !SANITIZER_NETBSD
+   extern unsigned struct_statfs_sz;
++#endif
+   extern unsigned struct_sockaddr_sz;
+   extern unsigned ucontext_t_sz;
+ #endif // !SANITIZER_ANDROID
+@@ -121,18 +138,21 @@ namespace __sanitizer {
+ #endif  // SANITIZER_LINUX
+ 
+ #if SANITIZER_LINUX || SANITIZER_FREEBSD
+-
+ #if defined(__powerpc64__) || defined(__s390__)
+   const unsigned struct___old_kernel_stat_sz = 0;
+ #elif !defined(__sparc__)
+   const unsigned struct___old_kernel_stat_sz = 32;
+ #endif
++#endif // SANITIZER_LINUX || SANITIZER_FREEBSD
++
++#if SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD
+ 
+   extern unsigned struct_rlimit_sz;
+   extern unsigned struct_utimbuf_sz;
+   extern unsigned struct_timespec_sz;
+ 
+   struct __sanitizer_iocb {
++#if SANITIZER_LINUX || SANITIZER_FREEBSD
+     u64   aio_data;
+     u32   aio_key_or_aio_reserved1; // Simply crazy.
+     u32   aio_reserved1_or_aio_key; // Luckily, we don't need these.
+@@ -144,21 +164,54 @@ namespace __sanitizer {
+     s64   aio_offset;
+     u64   aio_reserved2;
+     u64   aio_reserved3;
++#elif SANITIZER_NETBSD
++#if defined(__x86_64__)
++    u64   aio_offset;
++    u64   aio_buf;
++    u64   aio_nbytes;
++    u32   aio_fildes;
++    u32   aio_lio_opcode;
++    u64   aio_reqprio;
++    u8    aio_sigevent[32];
++    u32   _state;
++    u32   _errno;
++    u64   _retval;
++#elif defined(__i386__)
++    u64   aio_offset;
++    u32   aio_buf;
++    u32   aio_nbytes;
++    u32   aio_fildes;
++    u32   aio_lio_opcode;
++    u32   aio_reqprio;
++    u8    aio_sigevent[20];
++    u32   _state;
++    u32   _errno;
++    u32   _retval;
++#else
++#error port this to your platform
++#endif
++#endif
+   };
++#endif
+ 
++#if SANITIZER_LINUX || SANITIZER_FREEBSD
+   struct __sanitizer_io_event {
+     u64 data;
+     u64 obj;
+     u64 res;
+     u64 res2;
+   };
++#endif
+ 
++#if SANITIZER_LINUX || SANITIZER_FREEBSD
+   const unsigned iocb_cmd_pread = 0;
+   const unsigned iocb_cmd_pwrite = 1;
+   const unsigned iocb_cmd_preadv = 7;
+   const unsigned iocb_cmd_pwritev = 8;
++#endif
+ 
+   struct __sanitizer___sysctl_args {
++#if SANITIZER_LINUX || SANITIZER_FREEBSD
+     int *name;
+     int nlen;
+     void *oldval;
+@@ -166,10 +219,32 @@ namespace __sanitizer {
+     void *newval;
+     uptr newlen;
+     unsigned long ___unused[4];
++#else
++#if defined(__x86_64__)
++    u64   name;
++    u32   namelen;
++    u64   oldp;
++    u64   oldlenp;
++    u64   newp;
++    u64   newlen;
++#elif defined(__i386__)
++    u32   name;
++    u32   namelen;
++    u32   oldp;
++    u32   oldlenp;
++    u32   newp;
++    u32   newlen;
++#else
++#error port this
++#endif
++#endif
+   };
+ 
++#if SANITIZER_LINUX || SANITIZER_FREEBSD
+   const unsigned old_sigset_t_sz = sizeof(unsigned long);
++#endif
+ 
++#if SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD
+   struct __sanitizer_sem_t {
+ #if SANITIZER_ANDROID && defined(_LP64)
+     int data[4];
+@@ -179,9 +254,17 @@ namespace __sanitizer {
+     uptr data[4];
+ #elif SANITIZER_FREEBSD
+     u32 data[4];
++#elif SANITIZER_NETBSD
++#if defined(__x86_64__)
++    u8 data[40];
++#elif defined(__i386__)
++    u8 data[20];
++#else
++#error port this to your platform
++#endif
+ #endif
+   };
+-#endif // SANITIZER_LINUX || SANITIZER_FREEBSD
++#endif // SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD
+ 
+ #if SANITIZER_ANDROID
+   struct __sanitizer_mallinfo {
+@@ -324,14 +407,37 @@ namespace __sanitizer {
+     unsigned long shm_dtime;
+     unsigned long shm_ctime;
+   };
++
++#elif SANITIZER_NETBSD
++  struct __sanitizer_ipc_perm {
++    u32 uid;
++    u32 gid;
++    u32 cuid;
++    u32 cgid;
++    u32 mode;
++    unsigned short _seq;
++    long _key;
++  };
++
++  struct __sanitizer_shmid_ds {
++    __sanitizer_ipc_perm shm_perm;
++    unsigned long shm_segsz;
++    u32 shm_lpid;
++    u32 shm_cpid;
++    unsigned int shm_nattch;
++    u64 shm_atime;
++    u64 shm_dtime;
++    u64 shm_ctime;
++    void *_shm_internal;
++  };
+ #endif
+ 
+-#if (SANITIZER_LINUX || SANITIZER_FREEBSD) && !SANITIZER_ANDROID
++#if (SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD) && !SANITIZER_ANDROID
+   extern unsigned struct_msqid_ds_sz;
+   extern unsigned struct_mq_attr_sz;
+   extern unsigned struct_timex_sz;
+   extern unsigned struct_statvfs_sz;
+-#endif  // (SANITIZER_LINUX || SANITIZER_FREEBSD) && !SANITIZER_ANDROID
++#endif  // (SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD) && !SANITIZER_ANDROID
+ 
+   struct __sanitizer_iovec {
+     void *iov_base;
+@@ -351,6 +457,9 @@ namespace __sanitizer {
+ # endif
+     void *ifa_dstaddr; // (struct sockaddr *)
+     void *ifa_data;
++#if SANITIZER_NETBSD
++    unsigned int ifa_addrflags;
++#endif
+   };
+ #endif  // !SANITIZER_ANDROID
+ 
+@@ -376,13 +485,24 @@ namespace __sanitizer {
+   const int __sanitizer_XDR_FREE = 2;
+ #endif
+ 
++#if SANITIZER_NETBSD || (defined(__x86_64__) && !defined(_LP64))
++  typedef long long __sanitizer_time_t;
++#else
++  typedef long __sanitizer_time_t;
++#endif
++
+   struct __sanitizer_passwd {
+     char *pw_name;
+     char *pw_passwd;
++#if SANITIZER_NETBSD
+     int pw_uid;
+     int pw_gid;
+-#if SANITIZER_MAC || SANITIZER_FREEBSD
+-    long pw_change;
++#else
++    u32 pw_uid;
++    u32 pw_gid;
++#endif
++#if SANITIZER_MAC || SANITIZER_FREEBSD || SANITIZER_NETBSD
++    __sanitizer_time_t pw_change;
+     char *pw_class;
+ #endif
+ #if !(SANITIZER_ANDROID && (SANITIZER_WORDSIZE == 32))
+@@ -390,8 +510,8 @@ namespace __sanitizer {
+ #endif
+     char *pw_dir;
+     char *pw_shell;
+-#if SANITIZER_MAC || SANITIZER_FREEBSD
+-    long pw_expire;
++#if SANITIZER_MAC || SANITIZER_FREEBSD || SANITIZER_NETBSD
++    __sanitizer_time_t pw_expire;
+ #endif
+ #if SANITIZER_FREEBSD
+     int pw_fields;
+@@ -405,12 +525,6 @@ namespace __sanitizer {
+     char **gr_mem;
+   };
+ 
+-#if defined(__x86_64__) && !defined(_LP64)
+-  typedef long long __sanitizer_time_t;
+-#else
+-  typedef long __sanitizer_time_t;
+-#endif
+-
+   struct __sanitizer_timeb {
+     __sanitizer_time_t time;
+     unsigned short millitm;
+@@ -447,7 +561,7 @@ namespace __sanitizer {
+   };
+ #endif
+ 
+-#if SANITIZER_MAC || SANITIZER_FREEBSD
++#if SANITIZER_MAC || SANITIZER_FREEBSD || SANITIZER_NETBSD
+   struct __sanitizer_msghdr {
+     void *msg_name;
+     unsigned msg_namelen;
+@@ -497,6 +611,16 @@ namespace __sanitizer {
+     unsigned short d_reclen;
+     // more fields that we don't care about
+   };
++#elif SANITIZER_NETBSD
++  struct __sanitizer_dirent {
++    u64 d_fileno;
++    u16 d_reclen;
++#if 0 // not needed here?
++    u16 d_namlen;
++    u8  d_type;
++    u8  d_name[512];
++#endif
++  };
+ #elif SANITIZER_ANDROID || defined(__x86_64__)
+   struct __sanitizer_dirent {
+     unsigned long long d_ino;
+@@ -523,7 +647,7 @@ namespace __sanitizer {
+ #endif
+ 
+ // 'clock_t' is 32 bits wide on x64 FreeBSD
+-#if SANITIZER_FREEBSD
++#if SANITIZER_FREEBSD || SANITIZER_NETBSD
+   typedef int __sanitizer_clock_t;
+ #elif defined(__x86_64__) && !defined(_LP64)
+   typedef long long __sanitizer_clock_t;
+@@ -531,7 +655,7 @@ namespace __sanitizer {
+   typedef long __sanitizer_clock_t;
+ #endif
+ 
+-#if SANITIZER_LINUX
++#if SANITIZER_LINUX || SANITIZER_NETBSD
+   typedef int __sanitizer_clockid_t;
+ #endif
+ 
+@@ -562,8 +686,22 @@ namespace __sanitizer {
+   typedef struct {
+     unsigned long fds_bits[1024 / (8 * sizeof(long))];
+   } __sanitizer___kernel_fd_set;
++#elif SANITIZER_NETBSD
++  typedef u32 __sanitizer___kernel_uid_t;
++  typedef u32 __sanitizer___kernel_gid_t;
++  typedef u64 __sanitizer___kernel_off_t;
++  typedef struct {
++    u32 fds_bits[8];
++  } __sanitizer___kernel_fd_set;
+ #endif
+ 
++#if SANITIZER_NETBSD
++  typedef struct {
++    unsigned int pta_magic;
++    int pta_flags;
++    void *pta_private;
++  } __sanitizer_pthread_attr_t;
++#else
+   // This thing depends on the platform. We are only interested in the upper
+   // limit. Verified with a compiler assert in .cc.
+   const int pthread_attr_t_max_sz = 128;
+@@ -571,6 +709,7 @@ namespace __sanitizer {
+     char size[pthread_attr_t_max_sz]; // NOLINT
+     void *align;
+   };
++#endif
+ 
+ #if SANITIZER_ANDROID
+ # if SANITIZER_MIPS
+@@ -590,6 +729,10 @@ namespace __sanitizer {
+      // uint32_t * 4
+      unsigned int __bits[4];
+   };
++#elif SANITIZER_NETBSD
++  struct __sanitizer_sigset_t {
++     u32 __bits[4];
++  };
+ #endif
+ 
+   // Linux system headers define the 'sa_handler' and 'sa_sigaction' macros.
+@@ -622,6 +765,15 @@ namespace __sanitizer {
+     uptr sa_flags;
+     void (*sa_restorer)();
+   };
++#elif SANITIZER_NETBSD
++  struct __sanitizer_sigaction {
++    union {
++      void (*handler)(int sig);
++      void (*sigaction)(int sig, void *siginfo, void *uctx);
++    };
++    __sanitizer_sigset_t sa_mask;
++    int sa_flags;
++  };
+ #else // !SANITIZER_ANDROID
+   struct __sanitizer_sigaction {
+ #if defined(__mips__) && !SANITIZER_FREEBSD
+@@ -640,6 +792,7 @@ namespace __sanitizer {
+ #else
+     __sanitizer_sigset_t sa_mask;
+ #endif
++
+ #ifndef __mips__
+ #if defined(__sparc__)
+ #if __GLIBC_PREREQ (2, 20)
+@@ -670,7 +823,7 @@ namespace __sanitizer {
+   };
+ #endif // !SANITIZER_ANDROID
+ 
+-#if SANITIZER_FREEBSD
++#if SANITIZER_FREEBSD || SANITIZER_NETBSD
+   typedef __sanitizer_sigset_t __sanitizer_kernel_sigset_t;
+ #elif defined(__mips__)
+   struct __sanitizer_kernel_sigset_t {
+@@ -717,7 +870,7 @@ namespace __sanitizer {
+   extern int af_inet6;
+   uptr __sanitizer_in_addr_sz(int af);
+ 
+-#if SANITIZER_LINUX || SANITIZER_FREEBSD
++#if SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD
+   struct __sanitizer_dl_phdr_info {
+     uptr dlpi_addr;
+     const char *dlpi_name;
+@@ -733,7 +886,7 @@ namespace __sanitizer {
+     int ai_family;
+     int ai_socktype;
+     int ai_protocol;
+-#if SANITIZER_ANDROID || SANITIZER_MAC || SANITIZER_FREEBSD
++#if SANITIZER_ANDROID || SANITIZER_MAC || SANITIZER_FREEBSD || SANITIZER_NETBSD
+     unsigned ai_addrlen;
+     char *ai_canonname;
+     void *ai_addr;
+@@ -759,7 +912,7 @@ namespace __sanitizer {
+     short revents;
+   };
+ 
+-#if SANITIZER_ANDROID || SANITIZER_MAC || SANITIZER_FREEBSD
++#if SANITIZER_ANDROID || SANITIZER_MAC || SANITIZER_FREEBSD || SANITIZER_NETBSD
+   typedef unsigned __sanitizer_nfds_t;
+ #else
+   typedef unsigned long __sanitizer_nfds_t;
+@@ -779,7 +932,7 @@ namespace __sanitizer {
+     int (*gl_lstat)(const char *, void *);
+     int (*gl_stat)(const char *, void *);
+   };
+-# elif SANITIZER_FREEBSD
++# elif SANITIZER_FREEBSD || SANITIZER_NETBSD
+   struct __sanitizer_glob_t {
+     uptr gl_pathc;
+     uptr gl_matchc;
+@@ -793,9 +946,9 @@ namespace __sanitizer {
+     int (*gl_lstat)(const char*, void* /* struct stat* */);
+     int (*gl_stat)(const char*, void* /* struct stat* */);
+   };
+-# endif  // SANITIZER_FREEBSD
++# endif  // SANITIZER_FREEBSD || SANITIZER_NETBSD
+ 
+-# if SANITIZER_LINUX || SANITIZER_FREEBSD
++# if SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD
+   extern int glob_nomatch;
+   extern int glob_altdirfunc;
+ # endif
+@@ -807,7 +960,7 @@ namespace __sanitizer {
+     uptr we_wordc;
+     char **we_wordv;
+     uptr we_offs;
+-#if SANITIZER_FREEBSD
++#if SANITIZER_FREEBSD || SANITIZER_NETBSD
+     char *we_strings;
+     uptr we_nbytes;
+ #endif
+@@ -832,6 +985,37 @@ namespace __sanitizer {
+     int _fileno;
+   };
+ # define SANITIZER_HAS_STRUCT_FILE 1
++#elif SANITIZER_NETBSD
++  struct __sanitizer_FILE {
++    unsigned char *_p;
++    int     _r;
++    int     _w;
++    unsigned short _flags;
++    short   _file;
++    struct  {
++        unsigned char *_base;
++        int     _size;
++    } _bf;
++    int     _lbfsize;
++    void    *_cookie;
++    int     (*_close)(void *);
++    u64 (*_read) (void *, void *, uptr);
++    u64 (*_seek) (void *, u64, int);
++    uptr (*_write)(void *, const void *, uptr);
++    struct {
++        unsigned char *_base;
++        int     _size;
++    } _ext;
++    unsigned char *_up;
++    int     _ur;
++    unsigned char _ubuf[3];
++    unsigned char _nbuf[1];
++    int     (*_flush)(void *);
++    char    _lb_unused[sizeof(uptr)];
++    int     _blksize;
++    u64 _offset;
++  };
++# define SANITIZER_HAS_STRUCT_FILE 0 // not ported
+ #else
+   typedef void __sanitizer_FILE;
+ # define SANITIZER_HAS_STRUCT_FILE 0
+@@ -864,7 +1048,7 @@ namespace __sanitizer {
+   extern int ptrace_geteventmsg;
+ #endif
+ 
+-#if (SANITIZER_LINUX || SANITIZER_FREEBSD) && !SANITIZER_ANDROID
++#if (SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD) && !SANITIZER_ANDROID
+   extern unsigned struct_shminfo_sz;
+   extern unsigned struct_shm_info_sz;
+   extern int shmctl_ipc_stat;
+@@ -923,6 +1107,7 @@ struct __sanitizer_cookie_io_functions_t
+ };
+ #endif
+ 
++#if 1 // !SANITIZER_NETBSD
+ #define IOC_NRBITS 8
+ #define IOC_TYPEBITS 8
+ #if defined(__powerpc__) || defined(__powerpc64__) || defined(__mips__) || \
+@@ -966,13 +1151,17 @@ struct __sanitizer_cookie_io_functions_t
+ #else
+ #define IOC_SIZE(nr) (((nr) >> IOC_SIZESHIFT) & IOC_SIZEMASK)
+ #endif
++#endif
+ 
+   extern unsigned struct_ifreq_sz;
+   extern unsigned struct_termios_sz;
+   extern unsigned struct_winsize_sz;
+ 
+-#if SANITIZER_LINUX
++#if SANITIZER_LINUX || SANITIZER_NETBSD
+   extern unsigned struct_arpreq_sz;
++#endif
++
++#if SANITIZER_LINUX
+   extern unsigned struct_cdrom_msf_sz;
+   extern unsigned struct_cdrom_multisession_sz;
+   extern unsigned struct_cdrom_read_audio_sz;
+@@ -1006,6 +1195,9 @@ struct __sanitizer_cookie_io_functions_t
+   extern unsigned struct_copr_debug_buf_sz;
+   extern unsigned struct_copr_msg_sz;
+   extern unsigned struct_midi_info_sz;
++#endif
++
++#if SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD
+   extern unsigned struct_mtget_sz;
+   extern unsigned struct_mtop_sz;
+   extern unsigned struct_rtentry_sz;
+@@ -1013,7 +1205,7 @@ struct __sanitizer_cookie_io_functions_t
+   extern unsigned struct_seq_event_rec_sz;
+   extern unsigned struct_synth_info_sz;
+   extern unsigned struct_vt_mode_sz;
+-#endif // SANITIZER_LINUX || SANITIZER_FREEBSD
++#endif // SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD
+ 
+ #if SANITIZER_LINUX && !SANITIZER_ANDROID
+   extern unsigned struct_ax25_parms_struct_sz;
+@@ -1035,10 +1227,10 @@ struct __sanitizer_cookie_io_functions_t
+   extern unsigned struct_unimapinit_sz;
+ #endif  // SANITIZER_LINUX && !SANITIZER_ANDROID
+ 
+-#if (SANITIZER_LINUX || SANITIZER_FREEBSD) && !SANITIZER_ANDROID
++#if (SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD) && !SANITIZER_ANDROID
+   extern unsigned struct_audio_buf_info_sz;
+   extern unsigned struct_ppp_stats_sz;
+-#endif  // (SANITIZER_LINUX || SANITIZER_FREEBSD) && !SANITIZER_ANDROID
++#endif  // (SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD) && !SANITIZER_ANDROID
+ 
+ #if !SANITIZER_ANDROID && !SANITIZER_MAC
+   extern unsigned struct_sioc_sg_req_sz;
+@@ -1095,7 +1287,7 @@ struct __sanitizer_cookie_io_functions_t
+   extern unsigned IOCTL_TIOCSPGRP;
+   extern unsigned IOCTL_TIOCSTI;
+   extern unsigned IOCTL_TIOCSWINSZ;
+-#if (SANITIZER_LINUX || SANITIZER_FREEBSD) && !SANITIZER_ANDROID
++#if (SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD) && !SANITIZER_ANDROID
+   extern unsigned IOCTL_SIOCGETSGCNT;
+   extern unsigned IOCTL_SIOCGETVIFCNT;
+ #endif
+@@ -1258,10 +1450,10 @@ struct __sanitizer_cookie_io_functions_t
+   extern unsigned IOCTL_VT_RESIZEX;
+   extern unsigned IOCTL_VT_SENDSIG;
+ #endif  // SANITIZER_LINUX
+-#if SANITIZER_LINUX || SANITIZER_FREEBSD
++#if SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD
+   extern unsigned IOCTL_MTIOCGET;
+   extern unsigned IOCTL_MTIOCTOP;
+-  extern unsigned IOCTL_SIOCADDRT;
++  extern unsigned IOCTL_SIOCADDRT;//
+   extern unsigned IOCTL_SIOCDELRT;
+   extern unsigned IOCTL_SNDCTL_DSP_GETBLKSIZE;
+   extern unsigned IOCTL_SNDCTL_DSP_GETFMTS;
+@@ -1359,7 +1551,7 @@ struct __sanitizer_cookie_io_functions_t
+   extern unsigned IOCTL_VT_RELDISP;
+   extern unsigned IOCTL_VT_SETMODE;
+   extern unsigned IOCTL_VT_WAITACTIVE;
+-#endif  // SANITIZER_LINUX || SANITIZER_FREEBSD
++#endif  // SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD
+ 
+ #if SANITIZER_LINUX && !SANITIZER_ANDROID
+   extern unsigned IOCTL_CYGETDEFTHRESH;
+@@ -1448,21 +1640,27 @@ struct __sanitizer_cookie_io_functions_t
+   extern unsigned IOCTL_TIOCSSERIAL;
+ #endif  // SANITIZER_LINUX && !SANITIZER_ANDROID
+ 
+-#if (SANITIZER_LINUX || SANITIZER_FREEBSD) && !SANITIZER_ANDROID
++#if (SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD) && !SANITIZER_ANDROID
++#if !SANITIZER_NETBSD
+   extern unsigned IOCTL_GIO_SCRNMAP;
++#endif
+   extern unsigned IOCTL_KDDISABIO;
+   extern unsigned IOCTL_KDENABIO;
+   extern unsigned IOCTL_KDGETLED;
++#if !SANITIZER_NETBSD
+   extern unsigned IOCTL_KDGETMODE;
++#endif
+   extern unsigned IOCTL_KDGKBMODE;
+   extern unsigned IOCTL_KDGKBTYPE;
+   extern unsigned IOCTL_KDMKTONE;
+   extern unsigned IOCTL_KDSETLED;
+   extern unsigned IOCTL_KDSETMODE;
+   extern unsigned IOCTL_KDSKBMODE;
++#if !SANITIZER_NETBSD
+   extern unsigned IOCTL_KIOCSOUND;
+   extern unsigned IOCTL_PIO_SCRNMAP;
+ #endif
++#endif
+ 
+   extern const int errno_EINVAL;
+   extern const int errno_EOWNERDEAD;
diff --git a/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__procmaps.h b/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__procmaps.h
new file mode 100644
index 0000000000..fac3d0b1c6
--- /dev/null
+++ b/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__procmaps.h
@@ -0,0 +1,31 @@
+$NetBSD$
+
+--- lib/sanitizer_common/sanitizer_procmaps.h.orig	2017-07-03 15:33:06.559675042 +0000
++++ lib/sanitizer_common/sanitizer_procmaps.h
+@@ -20,7 +20,7 @@
+ 
+ namespace __sanitizer {
+ 
+-#if SANITIZER_FREEBSD || SANITIZER_LINUX
++#if SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD
+ struct ProcSelfMapsBuff {
+   char *data;
+   uptr mmaped_size;
+@@ -29,7 +29,7 @@ struct ProcSelfMapsBuff {
+ 
+ // Reads process memory map in an OS-specific way.
+ void ReadProcMaps(ProcSelfMapsBuff *proc_maps);
+-#endif  // SANITIZER_FREEBSD || SANITIZER_LINUX
++#endif  // SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD
+ 
+ class MemoryMappingLayout {
+  public:
+@@ -58,7 +58,7 @@ class MemoryMappingLayout {
+ 
+   // FIXME: Hide implementation details for different platforms in
+   // platform-specific files.
+-# if SANITIZER_FREEBSD || SANITIZER_LINUX
++# if SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD
+   ProcSelfMapsBuff proc_self_maps_;
+   const char *current_;
+ 
diff --git a/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__procmaps__common.cc b/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__procmaps__common.cc
new file mode 100644
index 0000000000..f1ded5011c
--- /dev/null
+++ b/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__procmaps__common.cc
@@ -0,0 +1,19 @@
+$NetBSD$
+
+--- lib/sanitizer_common/sanitizer_procmaps_common.cc.orig	2017-07-03 15:33:06.559737270 +0000
++++ lib/sanitizer_common/sanitizer_procmaps_common.cc
+@@ -12,7 +12,7 @@
+ 
+ #include "sanitizer_platform.h"
+ 
+-#if SANITIZER_FREEBSD || SANITIZER_LINUX
++#if SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD
+ 
+ #include "sanitizer_common.h"
+ #include "sanitizer_placement_new.h"
+@@ -173,4 +173,4 @@ void GetMemoryProfile(fill_profile_f cb,
+ 
+ } // namespace __sanitizer
+ 
+-#endif // SANITIZER_FREEBSD || SANITIZER_LINUX
++#endif // SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD
diff --git a/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__procmaps__netbsd.cc b/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__procmaps__netbsd.cc
new file mode 100644
index 0000000000..81662834ef
--- /dev/null
+++ b/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__procmaps__netbsd.cc
@@ -0,0 +1,84 @@
+$NetBSD$
+
+--- lib/sanitizer_common/sanitizer_procmaps_netbsd.cc.orig	2017-07-03 15:46:54.034469045 +0000
++++ lib/sanitizer_common/sanitizer_procmaps_netbsd.cc
+@@ -0,0 +1,79 @@
++//===-- sanitizer_procmaps_freebsd.cc -------------------------------------===//
++//
++// This file is distributed under the University of Illinois Open Source
++// License. See LICENSE.TXT for details.
++//
++//===----------------------------------------------------------------------===//
++//
++// Information about the process mappings (NetBSD-specific parts).
++//===----------------------------------------------------------------------===//
++
++#include "sanitizer_platform.h"
++#if SANITIZER_NETBSD
++#include "sanitizer_common.h"
++#include "sanitizer_procmaps.h"
++
++#include <unistd.h>
++#include <sys/sysctl.h>
++
++namespace __sanitizer {
++
++void ReadProcMaps(ProcSelfMapsBuff *proc_maps) {
++  struct kinfo_vmentry *kiv;
++  const int Mib[] = { CTL_VM, VM_PROC, VM_PROC_MAP, getpid(), sizeof(*kiv) };
++  size_t Size = 0;
++  int Err = sysctl(Mib, __arraycount(Mib), NULL, &Size, NULL, 0);
++  CHECK_EQ(Err, 0);
++  CHECK_GT(Size, 0);
++
++  size_t MmapedSize = Size * 4 / 3;
++  void *VmMap = MmapOrDie(MmapedSize, "ReadProcMaps()");
++  Size = MmapedSize;
++  Err = sysctl(Mib, __arraycount(Mib), VmMap, &Size, NULL, 0);
++  CHECK_EQ(Err, 0);
++
++  proc_maps->data = (char*)VmMap;
++  proc_maps->mmaped_size = MmapedSize;
++  proc_maps->len = Size;
++}
++
++bool MemoryMappingLayout::Next(uptr *start, uptr *end, uptr *offset,
++                               char filename[], uptr filename_size,
++                               uptr *protection, ModuleArch *arch, u8 *uuid) {
++  CHECK(!arch && "not implemented");
++  CHECK(!uuid && "not implemented");
++  char *last = proc_self_maps_.data + proc_self_maps_.len;
++  if (current_ >= last) return false;
++  uptr dummy;
++  if (!start) start = &dummy;
++  if (!end) end = &dummy;
++  if (!offset) offset = &dummy;
++  if (!protection) protection = &dummy;
++  struct kinfo_vmentry *VmEntry = (struct kinfo_vmentry*)current_;
++
++  *start = (uptr)VmEntry->kve_start;
++  *end = (uptr)VmEntry->kve_end;
++  *offset = (uptr)VmEntry->kve_offset;
++
++  *protection = 0;
++  if ((VmEntry->kve_protection & KVME_PROT_READ) != 0)
++    *protection |= kProtectionRead;
++  if ((VmEntry->kve_protection & KVME_PROT_WRITE) != 0)
++    *protection |= kProtectionWrite;
++  if ((VmEntry->kve_protection & KVME_PROT_EXEC) != 0)
++    *protection |= kProtectionExecute;
++
++  if (filename != NULL && filename_size > 0) {
++    internal_snprintf(filename,
++                      Min(filename_size, (uptr)PATH_MAX),
++                      "%s", VmEntry->kve_path);
++  }
++
++  current_ += sizeof(*VmEntry);
++
++  return true;
++}
++
++}  // namespace __sanitizer
++
++#endif  // SANITIZER_NETBSD
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..be8e60d51a
--- /dev/null
+++ b/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__syscall__generic.inc
@@ -0,0 +1,44 @@
+$NetBSD$
+
+--- lib/sanitizer_common/sanitizer_syscall_generic.inc.orig	2017-07-03 15:33:06.561978756 +0000
++++ lib/sanitizer_common/sanitizer_syscall_generic.inc
+@@ -11,13 +11,37 @@
+ //
+ //===----------------------------------------------------------------------===//
+ 
+-#if SANITIZER_FREEBSD || SANITIZER_MAC
++#ifdef SANITIZER_NETBSD
++# define SYS_stat SYS___stat50
++# define SYS_lstat SYS___lstat50
++# define SYS_fstat SYS___fstat50
++# define SYS_gettimeofday SYS___gettimeofday50
++# define SYS_wait4 SYS___wait450
++# define SYS_getdents SYS___getdents30
++# define SYS_sigaltstack SYS___sigaltstack14
++# define SYS_sigprocmask SYS___sigprocmask14
++# define SYS_nanosleep SYS___nanosleep50
++#endif
++#if SANITIZER_FREEBSD || SANITIZER_MAC || SANITIZER_NETBSD
+ # define SYSCALL(name) SYS_ ## name
+ #else
+ # define SYSCALL(name) __NR_ ## name
+ #endif
+ 
+-#if (SANITIZER_FREEBSD || SANITIZER_MAC) && defined(__x86_64__)
++#if SANITIZER_NETBSD
++// We use 3 kinds of internal_syscall's for different types of retval in order
++// to address problems related to the byte order.
++//   - internal_syscall     for 32-bit length (int, pid_t)
++//   - internal_syscall64   for 64-bit length (off_t)
++//   - internal_syscall_ptr for pointer and (s)size_t
++# define  internal_syscall      syscall                                                                                               
++# define  internal_syscall64    __syscall
++# if SANITIZER_WORDSIZE == 64
++#  define internal_syscall_ptr  __syscall
++# else
++#  define internal_syscall_ptr  syscall
++# endif
++#elif (SANITIZER_FREEBSD || SANITIZER_MAC) && defined(__x86_64__)
+ # define internal_syscall __syscall
+ # else
+ # define internal_syscall syscall
diff --git a/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__unwind__linux__libcdep.cc b/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__unwind__linux__libcdep.cc
new file mode 100644
index 0000000000..ac1a8ffc38
--- /dev/null
+++ b/compiler-rt-git/patches/patch-lib_sanitizer__common_sanitizer__unwind__linux__libcdep.cc
@@ -0,0 +1,43 @@
+$NetBSD$
+
+--- lib/sanitizer_common/sanitizer_unwind_linux_libcdep.cc.orig	2017-07-03 15:33:06.562483709 +0000
++++ lib/sanitizer_common/sanitizer_unwind_linux_libcdep.cc
+@@ -8,11 +8,11 @@
+ //===----------------------------------------------------------------------===//
+ //
+ // This file contains the unwind.h-based (aka "slow") stack unwinding routines
+-// available to the tools on Linux, Android, and FreeBSD.
++// available to the tools on Linux, Android, NetBSD and FreeBSD.
+ //===----------------------------------------------------------------------===//
+ 
+ #include "sanitizer_platform.h"
+-#if SANITIZER_FREEBSD || SANITIZER_LINUX
++#if SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD
+ #include "sanitizer_common.h"
+ #include "sanitizer_stacktrace.h"
+ 
+@@ -78,7 +78,8 @@ void SanitizerInitializeUnwinder() {
+ }
+ #endif
+ 
+-#ifdef __arm__
++#if defined(__arm__) && !SANITIZER_NETBSD
++// NetBSD uses dwarf EH
+ #define UNWIND_STOP _URC_END_OF_STACK
+ #define UNWIND_CONTINUE _URC_NO_REASON
+ #else
+@@ -95,7 +96,7 @@ uptr Unwind_GetIP(struct _Unwind_Context
+   // Clear the Thumb bit.
+   return val & ~(uptr)1;
+ #else
+-  return _Unwind_GetIP(ctx);
++  return (uptr)_Unwind_GetIP(ctx);
+ #endif
+ }
+ 
+@@ -165,4 +166,4 @@ void BufferedStackTrace::SlowUnwindStack
+ 
+ }  // namespace __sanitizer
+ 
+-#endif  // SANITIZER_FREEBSD || SANITIZER_LINUX
++#endif  // SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD



Home | Main Index | Thread Index | Old Index