pkgsrc-WIP-changes archive

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

compiler-rt-netbsd: Update to SVN r. 308147



Module Name:	pkgsrc-wip
Committed By:	Kamil Rytarowski <n54%gmx.com@localhost>
Pushed By:	kamil
Date:		Mon Jul 17 01:13:15 2017 +0200
Changeset:	0e047945e3ffbb433d62b369eee23c69a632b35b

Modified Files:
	compiler-rt-netbsd/Makefile
	compiler-rt-netbsd/distinfo
	compiler-rt-netbsd/patches/patch-cmake_config-ix.cmake
	compiler-rt-netbsd/patches/patch-lib_interception_interception.h
	compiler-rt-netbsd/patches/patch-lib_interception_interception__linux.cc
	compiler-rt-netbsd/patches/patch-lib_interception_interception__linux.h
	compiler-rt-netbsd/patches/patch-lib_sanitizer__common_CMakeLists.txt
	compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__internal__defs.h
	compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__libignore.cc
	compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__linux.cc
	compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__linux.h
	compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__linux__libcdep.cc
	compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__platform.h
	compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__platform__interceptors.h
	compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__platform__limits__posix.cc
	compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__platform__limits__posix.h
	compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__procmaps.h
	compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__procmaps__common.cc
	compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__syscall__generic.inc
	compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__unwind__linux__libcdep.cc
Removed Files:
	compiler-rt-netbsd/patches/patch-lib_asan_asan__interceptors.cc
	compiler-rt-netbsd/patches/patch-lib_asan_asan__interceptors.h
	compiler-rt-netbsd/patches/patch-lib_asan_asan__linux.cc
	compiler-rt-netbsd/patches/patch-lib_asan_asan__malloc__linux.cc
	compiler-rt-netbsd/patches/patch-lib_asan_asan__stack.h
	compiler-rt-netbsd/patches/patch-lib_asan_scripts_asan__symbolize.py
	compiler-rt-netbsd/patches/patch-lib_builtins_gcc__personality__v0.c
	compiler-rt-netbsd/patches/patch-lib_lsan_lsan__common.h
	compiler-rt-netbsd/patches/patch-lib_lsan_lsan__linux.cc
	compiler-rt-netbsd/patches/patch-lib_msan_msan.h
	compiler-rt-netbsd/patches/patch-lib_msan_msan__interceptors.cc
	compiler-rt-netbsd/patches/patch-lib_msan_msan__linux.cc
	compiler-rt-netbsd/patches/patch-lib_safestack_safestack.cc
	compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__common__interceptors.inc
	compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__netbsd.h
	compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__procmaps__netbsd.cc
	compiler-rt-netbsd/patches/patch-lib_tsan_rtl_tsan__interceptors.cc
	compiler-rt-netbsd/patches/patch-lib_tsan_rtl_tsan__platform__linux.cc
	compiler-rt-netbsd/patches/patch-lib_tsan_rtl_tsan__rtl__amd64.S
	compiler-rt-netbsd/patches/patch-lib_ubsan_ubsan__platform.h
	compiler-rt-netbsd/patches/patch-test_asan_TestCases_heavy__uar__test.cc
	compiler-rt-netbsd/patches/patch-test_asan_TestCases_non-executable-pc.cpp
	compiler-rt-netbsd/patches/patch-test_asan_TestCases_verbose-log-path__test.cc
	compiler-rt-netbsd/patches/patch-test_asan_lit.cfg
	compiler-rt-netbsd/patches/patch-test_msan_ftime.cc
	compiler-rt-netbsd/patches/patch-test_msan_iconv.cc
	compiler-rt-netbsd/patches/patch-test_msan_initgroups.cc
	compiler-rt-netbsd/patches/patch-test_msan_lit.cfg
	compiler-rt-netbsd/patches/patch-test_profile_lit.cfg
	compiler-rt-netbsd/patches/patch-test_safestack_lit.cfg
	compiler-rt-netbsd/patches/patch-test_sanitizer__common_CMakeLists.txt
	compiler-rt-netbsd/patches/patch-test_sanitizer__common_print__address.h
	compiler-rt-netbsd/patches/patch-test_tsan_lit.cfg
	compiler-rt-netbsd/patches/patch-test_tsan_tls__race.cc
	compiler-rt-netbsd/patches/patch-test_tsan_tls__race2.cc
	compiler-rt-netbsd/patches/patch-test_ubsan_lit.common.cfg

Log Message:
compiler-rt-netbsd: Update to SVN r. 308147

Drop all local patches besides common sanitizer.

As of now, all we want to upstream is the common sanitizer part.

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=0e047945e3ffbb433d62b369eee23c69a632b35b

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

diffstat:
 compiler-rt-netbsd/Makefile                        |   2 +-
 compiler-rt-netbsd/distinfo                        |  73 ++---
 .../patches/patch-cmake_config-ix.cmake            |  58 +---
 .../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 --
 .../patch-lib_builtins_gcc__personality__v0.c      |  45 ---
 .../patches/patch-lib_interception_interception.h  |   8 +-
 .../patch-lib_interception_interception__linux.cc  |  15 +-
 .../patch-lib_interception_interception__linux.h   |   2 +-
 .../patches/patch-lib_lsan_lsan__common.h          |   2 -
 .../patches/patch-lib_lsan_lsan__linux.cc          |  10 -
 compiler-rt-netbsd/patches/patch-lib_msan_msan.h   |  13 -
 .../patches/patch-lib_msan_msan__interceptors.cc   | 184 ------------
 .../patches/patch-lib_msan_msan__linux.cc          |  19 --
 .../patches/patch-lib_safestack_safestack.cc       |  14 -
 .../patch-lib_sanitizer__common_CMakeLists.txt     |   4 +-
 ...zer__common_sanitizer__common__interceptors.inc |  12 -
 ...b_sanitizer__common_sanitizer__internal__defs.h |   8 +-
 ...h-lib_sanitizer__common_sanitizer__libignore.cc |   4 +-
 ...patch-lib_sanitizer__common_sanitizer__linux.cc | 121 ++++----
 .../patch-lib_sanitizer__common_sanitizer__linux.h |   4 +-
 ..._sanitizer__common_sanitizer__linux__libcdep.cc |  33 +--
 ...patch-lib_sanitizer__common_sanitizer__netbsd.h |  25 --
 ...tch-lib_sanitizer__common_sanitizer__platform.h |  17 +-
 ...zer__common_sanitizer__platform__interceptors.h |  58 ++--
 ...r__common_sanitizer__platform__limits__posix.cc | 108 ++++----
 ...er__common_sanitizer__platform__limits__posix.h | 308 ++++++++++++---------
 ...tch-lib_sanitizer__common_sanitizer__procmaps.h |  10 +-
 ...anitizer__common_sanitizer__procmaps__common.cc |   6 +-
 ...anitizer__common_sanitizer__procmaps__netbsd.cc |  84 ------
 ...nitizer__common_sanitizer__syscall__generic.inc |  12 +-
 ...er__common_sanitizer__unwind__linux__libcdep.cc |   2 +-
 .../patch-lib_tsan_rtl_tsan__interceptors.cc       | 133 ---------
 .../patch-lib_tsan_rtl_tsan__platform__linux.cc    |  25 --
 .../patches/patch-lib_tsan_rtl_tsan__rtl__amd64.S  |  40 ---
 .../patches/patch-lib_ubsan_ubsan__platform.h      |  13 -
 .../patch-test_asan_TestCases_heavy__uar__test.cc  |  13 -
 ...patch-test_asan_TestCases_non-executable-pc.cpp |  15 -
 ...h-test_asan_TestCases_verbose-log-path__test.cc |  13 -
 compiler-rt-netbsd/patches/patch-test_asan_lit.cfg |  24 --
 .../patches/patch-test_msan_ftime.cc               |  12 -
 .../patches/patch-test_msan_iconv.cc               |  15 -
 .../patches/patch-test_msan_initgroups.cc          |  13 -
 compiler-rt-netbsd/patches/patch-test_msan_lit.cfg |  15 -
 .../patches/patch-test_profile_lit.cfg             |  13 -
 .../patches/patch-test_safestack_lit.cfg           |  15 -
 .../patch-test_sanitizer__common_CMakeLists.txt    |  17 --
 .../patch-test_sanitizer__common_print__address.h  |  13 -
 compiler-rt-netbsd/patches/patch-test_tsan_lit.cfg |  15 -
 .../patches/patch-test_tsan_tls__race.cc           |  10 -
 .../patches/patch-test_tsan_tls__race2.cc          |  10 -
 .../patches/patch-test_ubsan_lit.common.cfg        |  13 -
 56 files changed, 433 insertions(+), 1401 deletions(-)

diffs:
diff --git a/compiler-rt-netbsd/Makefile b/compiler-rt-netbsd/Makefile
index 8b0952a3f0..c3467b87c5 100644
--- a/compiler-rt-netbsd/Makefile
+++ b/compiler-rt-netbsd/Makefile
@@ -5,7 +5,7 @@ CATEGORIES=	lang devel
 
 SVN_REPOSITORIES=	compiler-rt
 SVN_REPO.compiler-rt=	http://llvm.org/svn/llvm-project/compiler-rt/trunk
-SVN_REVISION.compiler-rt=	306751
+SVN_REVISION.compiler-rt=	308147
 
 MAINTAINER=	pkgsrc-users%NetBSD.org@localhost
 HOMEPAGE=	http://compiler-rt.llvm.org/
diff --git a/compiler-rt-netbsd/distinfo b/compiler-rt-netbsd/distinfo
index f021f28c17..603feea10f 100644
--- a/compiler-rt-netbsd/distinfo
+++ b/compiler-rt-netbsd/distinfo
@@ -12,57 +12,22 @@ Size (libcxx-3.6.2.src.tar.xz) = 944020 bytes
 SHA1 (llvm-3.6.2.src.tar.xz) = 7a00257eb2bc9431e4c77c3a36b033072c54bc7e
 RMD160 (llvm-3.6.2.src.tar.xz) = 521cbc5fe2925ea3c6e90c7a31f752a04045c972
 Size (llvm-3.6.2.src.tar.xz) = 12802380 bytes
-SHA1 (patch-cmake_config-ix.cmake) = bbe5cf5945995d58d500f265baaadaeb99f35237
-SHA1 (patch-lib_asan_asan__interceptors.cc) = 8711f7919ad676a2a9d323caf7f152afe8b0e545
-SHA1 (patch-lib_asan_asan__interceptors.h) = cca1e74041e37d366c512d23547063d6a4dee008
-SHA1 (patch-lib_asan_asan__linux.cc) = fcbf780af6bcd3b43c86d9e5e2c8a92e3a8885da
-SHA1 (patch-lib_asan_asan__malloc__linux.cc) = 3e971de691b1939ef1b2fe864cfa38a64e159cec
-SHA1 (patch-lib_asan_asan__stack.h) = a3dd10b42713265f6a54a2b86e33420b052f431f
-SHA1 (patch-lib_asan_scripts_asan__symbolize.py) = d6c079e7092b22b5379293dbb8d1e2445e077932
-SHA1 (patch-lib_builtins_gcc__personality__v0.c) = 66c36733afc7043f662328303de2573fd9005bf3
-SHA1 (patch-lib_interception_interception.h) = f18c140feec3c88fec57ac7ba1fbedb03db2bac6
-SHA1 (patch-lib_interception_interception__linux.cc) = a7c8a898784eb8424ca17dd96cf8faac4b3057bb
-SHA1 (patch-lib_interception_interception__linux.h) = 2f37344082e935a99fc04203453d387fe78bd6d3
-SHA1 (patch-lib_lsan_lsan__common.h) = adc83b19e793491b1c6ea0fd8b46cd9f32e592fc
-SHA1 (patch-lib_lsan_lsan__linux.cc) = 1c2e4b088f1ac244f733f326a0cd9642e6c55c75
-SHA1 (patch-lib_msan_msan.h) = 255eb26b3e6c4b728376cd8b12f7efa3caccc7b5
-SHA1 (patch-lib_msan_msan__interceptors.cc) = aa4e4f78a25a51959787aaf54afa3fed35ed52bc
-SHA1 (patch-lib_msan_msan__linux.cc) = 059a26cbff5082a964b90314bccb0b994b323053
-SHA1 (patch-lib_safestack_safestack.cc) = 6ccd97d3253eb3e284fc8375e651f2527317d88a
-SHA1 (patch-lib_sanitizer__common_CMakeLists.txt) = 45b18179c5d1d9f284ccfe4670a989ac30d05e92
-SHA1 (patch-lib_sanitizer__common_sanitizer__common__interceptors.inc) = b0815e88864b3f8f9c577811fb56bc8f9791a64c
-SHA1 (patch-lib_sanitizer__common_sanitizer__internal__defs.h) = b0cd6dd321ad5a9e0461806a2c44be7edad18c46
-SHA1 (patch-lib_sanitizer__common_sanitizer__libignore.cc) = 4b711c72fb64752eb17cc8e0b810526f33d64023
-SHA1 (patch-lib_sanitizer__common_sanitizer__linux.cc) = ec71e0189426780d32d83e25b1713040a8407e4f
-SHA1 (patch-lib_sanitizer__common_sanitizer__linux.h) = 88b1ebffc90f47b1dfd4e21e1ec3980a4ab9f4c3
-SHA1 (patch-lib_sanitizer__common_sanitizer__linux__libcdep.cc) = 3f2be0e646495cbd7988782d8a57da6c4b022401
-SHA1 (patch-lib_sanitizer__common_sanitizer__netbsd.h) = c1c19a402137e21ddc5bb48f8825400a34f010cc
-SHA1 (patch-lib_sanitizer__common_sanitizer__platform.h) = 47360a8352cc34fddc71c8f71081d7d589a63dad
-SHA1 (patch-lib_sanitizer__common_sanitizer__platform__interceptors.h) = cb3ae73d6ea041180116112c2a6b081a13155e60
-SHA1 (patch-lib_sanitizer__common_sanitizer__platform__limits__posix.cc) = dcc754f1711fe3391b9c59b5cc003f8dfbdf6a93
-SHA1 (patch-lib_sanitizer__common_sanitizer__platform__limits__posix.h) = 4046349ebafb006b63b7d7a1b84b558a66cf9aa4
-SHA1 (patch-lib_sanitizer__common_sanitizer__procmaps.h) = ec0b5c576463639a3ee66c33ff7e9d94076f40df
-SHA1 (patch-lib_sanitizer__common_sanitizer__procmaps__common.cc) = 0c30494654cfc0294804434d40468f6f722a6786
-SHA1 (patch-lib_sanitizer__common_sanitizer__procmaps__netbsd.cc) = a7e97fdb92e166f9d1def5a169c1fd079d8bb40a
-SHA1 (patch-lib_sanitizer__common_sanitizer__syscall__generic.inc) = 73db63809d0972346e76cc6eaebf0d7d047f0bea
-SHA1 (patch-lib_sanitizer__common_sanitizer__unwind__linux__libcdep.cc) = 3ede46a0dae62481ae6e82d7aac9de88899683ed
-SHA1 (patch-lib_tsan_rtl_tsan__interceptors.cc) = 80dfeebfd74f5470604b8cebfd90aae810a10cc0
-SHA1 (patch-lib_tsan_rtl_tsan__platform__linux.cc) = 3bb2c418b3d4bedad9014309abdd2cbad58b252c
-SHA1 (patch-lib_tsan_rtl_tsan__rtl__amd64.S) = 743e52c14f6aa21d0002b05a1be4f972dff0206f
-SHA1 (patch-lib_ubsan_ubsan__platform.h) = 8b9419ed6d3f40357eb73e71680d070bd64bd5cc
-SHA1 (patch-test_asan_TestCases_heavy__uar__test.cc) = 080def2df403f087152a28ad0a678d36ba9cf5bd
-SHA1 (patch-test_asan_TestCases_non-executable-pc.cpp) = 9812e7dd4a584a3a51e43ef54331b23dbe32778a
-SHA1 (patch-test_asan_TestCases_verbose-log-path__test.cc) = c44b2245b1bf03caddf74cb37cad4122ee877593
-SHA1 (patch-test_asan_lit.cfg) = 259b0e262b5975b862a51f015ec6b646ce2af10a
-SHA1 (patch-test_msan_ftime.cc) = d47efaedd6a5eff178d74d3ace45dc204ef484ae
-SHA1 (patch-test_msan_iconv.cc) = c93283b98af0c011b85048a9cea9f19d8f1a24ba
-SHA1 (patch-test_msan_initgroups.cc) = f79818e43593692dea95391b9c407353e69d2085
-SHA1 (patch-test_msan_lit.cfg) = 1dce33544537b11ae7d73a3dabeb6a5781bb6b49
-SHA1 (patch-test_profile_lit.cfg) = 3e2258f824b37cc66dc460a21b5eaed0d1d85f6b
-SHA1 (patch-test_safestack_lit.cfg) = 3c70326672bee0e8167cdb13f8aa32e56a09bf9e
-SHA1 (patch-test_sanitizer__common_CMakeLists.txt) = db49cd6d3eb4729eae14e6d92e71576c4e53f78a
-SHA1 (patch-test_sanitizer__common_print__address.h) = f49afc10c532f76b4b0d17b5dfc7e7237675dd7f
-SHA1 (patch-test_tsan_lit.cfg) = 26e7d54d1417ac4634cf1bf8d4713ef7165d0bf6
-SHA1 (patch-test_tsan_tls__race.cc) = 637f7bae561a1e6a760837a242026d967b4fed0c
-SHA1 (patch-test_tsan_tls__race2.cc) = 0006e6f20b193268e9c73e404716ee59d4ca48d2
-SHA1 (patch-test_ubsan_lit.common.cfg) = d60d738aaf8525cf3f5f028dc2fc2fe54a7d691b
+SHA1 (patch-cmake_config-ix.cmake) = cda8fd307a7bb6817a2119b5140b3bb107f6d105
+SHA1 (patch-lib_interception_interception.h) = df1c7a5291279f43a195d2de769e7fee8357271c
+SHA1 (patch-lib_interception_interception__linux.cc) = 41e29e48d879a7c1a8e8c5c466439310783d5e9f
+SHA1 (patch-lib_interception_interception__linux.h) = ebbdd314aeff8be22107a78872a71b9606748b36
+SHA1 (patch-lib_sanitizer__common_CMakeLists.txt) = d21d5fad13c0881b144265313075826bf285789a
+SHA1 (patch-lib_sanitizer__common_sanitizer__internal__defs.h) = 041c1036c925dad11040c6724c90ab2b4851f1cd
+SHA1 (patch-lib_sanitizer__common_sanitizer__libignore.cc) = 6f5d8730af229ae6ba9f7799a4b46eb7f83c56de
+SHA1 (patch-lib_sanitizer__common_sanitizer__linux.cc) = f2a8938cf1162a4c820f17f5b28879cdbc01cba0
+SHA1 (patch-lib_sanitizer__common_sanitizer__linux.h) = b3177dc169208b1b3e0c951fe3fd9c07e82fff49
+SHA1 (patch-lib_sanitizer__common_sanitizer__linux__libcdep.cc) = 90831f802b22365c6f51600496988b0886858fa0
+SHA1 (patch-lib_sanitizer__common_sanitizer__platform.h) = 85de2f512fc1386f21e2d20bde66c78731f2d55f
+SHA1 (patch-lib_sanitizer__common_sanitizer__platform__interceptors.h) = f402a33b98e1a657c780f587003b942afa98a96e
+SHA1 (patch-lib_sanitizer__common_sanitizer__platform__limits__posix.cc) = 36a89517584891a1a50536a681a5d42e99ef904d
+SHA1 (patch-lib_sanitizer__common_sanitizer__platform__limits__posix.h) = 5a5d7bf3dc0bb74fecc7f94d7cd84e0c54ea4343
+SHA1 (patch-lib_sanitizer__common_sanitizer__procmaps.h) = 2f58ff97566505a5f2027bf29322c66930c444f2
+SHA1 (patch-lib_sanitizer__common_sanitizer__procmaps__common.cc) = 6d40fdfc327d8042f1e48480cd84c59aeca81cf2
+SHA1 (patch-lib_sanitizer__common_sanitizer__syscall__generic.inc) = 0ec7db864f385794972a79d85d04f72fb8894a9d
+SHA1 (patch-lib_sanitizer__common_sanitizer__unwind__linux__libcdep.cc) = 446f72ab0d740dd441c208b08360175e0f0b992c
+SHA1 (patch-lib_sanitizer__common_tests_sanitizer__test__utils.h) = 3bd1a39352b4ee76e6e366c06fbbf329cb5d970b
diff --git a/compiler-rt-netbsd/patches/patch-cmake_config-ix.cmake b/compiler-rt-netbsd/patches/patch-cmake_config-ix.cmake
index 82745899d9..7ded072da0 100644
--- a/compiler-rt-netbsd/patches/patch-cmake_config-ix.cmake
+++ b/compiler-rt-netbsd/patches/patch-cmake_config-ix.cmake
@@ -1,8 +1,8 @@
 $NetBSD$
 
---- cmake/config-ix.cmake.orig	2017-07-04 05:53:17.000000000 +0000
+--- cmake/config-ix.cmake.orig	2017-07-16 22:40:10.000000000 +0000
 +++ cmake/config-ix.cmake
-@@ -441,7 +441,7 @@ set(COMPILER_RT_SANITIZERS_TO_BUILD ${AL
+@@ -440,7 +440,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
@@ -11,53 +11,13 @@ $NetBSD$
      (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)
+@@ -453,7 +453,8 @@ else()
+   set(COMPILER_RT_HAS_INTERCEPTION 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)
+-if (COMPILER_RT_HAS_SANITIZER_COMMON AND ASAN_SUPPORTED_ARCH)
++if (COMPILER_RT_HAS_SANITIZER_COMMON AND ASAN_SUPPORTED_ARCH AND
++    (NOT OS_NAME MATCHES "NetBSD"))
+   set(COMPILER_RT_HAS_ASAN TRUE)
  else()
-   set(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME FALSE)
-@@ -483,35 +483,35 @@ else()
- endif()
- 
- if (COMPILER_RT_HAS_SANITIZER_COMMON AND MSAN_SUPPORTED_ARCH AND
--    OS_NAME MATCHES "Linux")
-+    OS_NAME MATCHES "Linux|NetBSD")
-   set(COMPILER_RT_HAS_MSAN TRUE)
- else()
-   set(COMPILER_RT_HAS_MSAN FALSE)
- endif()
- 
- if (PROFILE_SUPPORTED_ARCH AND NOT LLVM_USE_SANITIZER AND
--    OS_NAME MATCHES "Darwin|Linux|FreeBSD|Windows|Android")
-+    OS_NAME MATCHES "Darwin|Linux|FreeBSD|Windows|Android|NetBSD")
-   set(COMPILER_RT_HAS_PROFILE TRUE)
- else()
-   set(COMPILER_RT_HAS_PROFILE FALSE)
- endif()
- 
- if (COMPILER_RT_HAS_SANITIZER_COMMON AND TSAN_SUPPORTED_ARCH AND
--    OS_NAME MATCHES "Darwin|Linux|FreeBSD|Android")
-+    OS_NAME MATCHES "Darwin|Linux|FreeBSD|Android|NetBSD")
-   set(COMPILER_RT_HAS_TSAN TRUE)
- else()
-   set(COMPILER_RT_HAS_TSAN FALSE)
- endif()
- 
- if (COMPILER_RT_HAS_SANITIZER_COMMON AND UBSAN_SUPPORTED_ARCH AND
--    OS_NAME MATCHES "Darwin|Linux|FreeBSD|Windows|Android")
-+    OS_NAME MATCHES "Darwin|Linux|FreeBSD|NetBSD|Windows|Android")
-   set(COMPILER_RT_HAS_UBSAN TRUE)
- else()
-   set(COMPILER_RT_HAS_UBSAN FALSE)
- endif()
- 
- if (COMPILER_RT_HAS_SANITIZER_COMMON AND SAFESTACK_SUPPORTED_ARCH AND
--    OS_NAME MATCHES "Darwin|Linux|FreeBSD")
-+    OS_NAME MATCHES "Darwin|Linux|FreeBSD|NetBSD")
-   set(COMPILER_RT_HAS_SAFESTACK TRUE)
- else()
-   set(COMPILER_RT_HAS_SAFESTACK FALSE)
+   set(COMPILER_RT_HAS_ASAN FALSE)
diff --git a/compiler-rt-netbsd/patches/patch-lib_asan_asan__interceptors.cc b/compiler-rt-netbsd/patches/patch-lib_asan_asan__interceptors.cc
deleted file mode 100644
index 23c14c5a3f..0000000000
--- a/compiler-rt-netbsd/patches/patch-lib_asan_asan__interceptors.cc
+++ /dev/null
@@ -1,16 +0,0 @@
-$NetBSD$
-
---- lib/asan/asan_interceptors.cc.orig	2017-06-12 15:01:29.000000000 +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-netbsd/patches/patch-lib_asan_asan__interceptors.h b/compiler-rt-netbsd/patches/patch-lib_asan_asan__interceptors.h
deleted file mode 100644
index 19e2db7d80..0000000000
--- a/compiler-rt-netbsd/patches/patch-lib_asan_asan__interceptors.h
+++ /dev/null
@@ -1,13 +0,0 @@
-$NetBSD$
-
---- lib/asan/asan_interceptors.h.orig	2017-06-03 23:53:58.000000000 +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-netbsd/patches/patch-lib_asan_asan__linux.cc b/compiler-rt-netbsd/patches/patch-lib_asan_asan__linux.cc
deleted file mode 100644
index c490ddabfd..0000000000
--- a/compiler-rt-netbsd/patches/patch-lib_asan_asan__linux.cc
+++ /dev/null
@@ -1,53 +0,0 @@
-$NetBSD$
-
---- lib/asan/asan_linux.cc.orig	2017-06-03 23:53:58.000000000 +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-netbsd/patches/patch-lib_asan_asan__malloc__linux.cc b/compiler-rt-netbsd/patches/patch-lib_asan_asan__malloc__linux.cc
deleted file mode 100644
index 6825c1e344..0000000000
--- a/compiler-rt-netbsd/patches/patch-lib_asan_asan__malloc__linux.cc
+++ /dev/null
@@ -1,19 +0,0 @@
-$NetBSD$
-
---- lib/asan/asan_malloc_linux.cc.orig	2017-06-12 15:01:29.000000000 +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-netbsd/patches/patch-lib_asan_asan__stack.h b/compiler-rt-netbsd/patches/patch-lib_asan_asan__stack.h
deleted file mode 100644
index e1a7255615..0000000000
--- a/compiler-rt-netbsd/patches/patch-lib_asan_asan__stack.h
+++ /dev/null
@@ -1,13 +0,0 @@
-$NetBSD$
-
---- lib/asan/asan_stack.h.orig	2017-06-03 23:53:58.000000000 +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-netbsd/patches/patch-lib_asan_scripts_asan__symbolize.py b/compiler-rt-netbsd/patches/patch-lib_asan_scripts_asan__symbolize.py
deleted file mode 100644
index 235c15e4f5..0000000000
--- a/compiler-rt-netbsd/patches/patch-lib_asan_scripts_asan__symbolize.py
+++ /dev/null
@@ -1,22 +0,0 @@
-$NetBSD$
-
---- lib/asan/scripts/asan_symbolize.py.orig	2017-06-03 23:53:58.000000000 +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-netbsd/patches/patch-lib_builtins_gcc__personality__v0.c b/compiler-rt-netbsd/patches/patch-lib_builtins_gcc__personality__v0.c
deleted file mode 100644
index 9e39ff79a1..0000000000
--- a/compiler-rt-netbsd/patches/patch-lib_builtins_gcc__personality__v0.c
+++ /dev/null
@@ -1,45 +0,0 @@
-$NetBSD$
-
---- lib/builtins/gcc_personality_v0.c.orig	2017-06-03 23:53:58.000000000 +0000
-+++ lib/builtins/gcc_personality_v0.c
-@@ -24,6 +24,12 @@
- #include "unwind-ehabi-helpers.h"
- #endif
- 
-+#if defined(__NetBSD__) && !defined(__clang__)
-+#define TYPE_UNWIND_PTR void*
-+#else
-+#define TYPE_UNWIND_PTR uintptr_t
-+#endif
-+
- /*
-  * Pointer encodings documented at:
-  *   http://refspecs.freestandards.org/LSB_1.3.0/gLSB/gLSB/ehframehdr.html
-@@ -206,8 +212,8 @@ __gcc_personality_v0(int version, _Unwin
-     if ( lsda == (uint8_t*) 0 )
-         return continueUnwind(exceptionObject, context);
- 
--    uintptr_t pc = _Unwind_GetIP(context)-1;
--    uintptr_t funcStart = _Unwind_GetRegionStart(context);
-+    uintptr_t pc = (uintptr_t)_Unwind_GetIP(context) - 1;
-+    uintptr_t funcStart = (uintptr_t)_Unwind_GetRegionStart(context);
-     uintptr_t pcOffset = pc - funcStart;
- 
-     /* Parse LSDA header. */
-@@ -239,9 +245,9 @@ __gcc_personality_v0(int version, _Unwin
-              * to take two parameters in registers.
-              */
-             _Unwind_SetGR(context, __builtin_eh_return_data_regno(0),
--                          (uintptr_t)exceptionObject);
-+                          (TYPE_UNWIND_PTR)exceptionObject);
-             _Unwind_SetGR(context, __builtin_eh_return_data_regno(1), 0);
--            _Unwind_SetIP(context, (funcStart + landingPad));
-+            _Unwind_SetIP(context, (TYPE_UNWIND_PTR)(funcStart + landingPad));
-             return _URC_INSTALL_CONTEXT;
-         }
-     }
-@@ -249,4 +255,3 @@ __gcc_personality_v0(int version, _Unwin
-     /* No landing pad found, continue unwinding. */
-     return continueUnwind(exceptionObject, context);
- }
--
diff --git a/compiler-rt-netbsd/patches/patch-lib_interception_interception.h b/compiler-rt-netbsd/patches/patch-lib_interception_interception.h
index 7c2870d790..5923526677 100644
--- a/compiler-rt-netbsd/patches/patch-lib_interception_interception.h
+++ b/compiler-rt-netbsd/patches/patch-lib_interception_interception.h
@@ -1,16 +1,18 @@
 $NetBSD$
 
---- lib/interception/interception.h.orig	2017-06-03 23:53:56.000000000 +0000
+--- lib/interception/interception.h.orig	2017-07-04 05:53:20.000000000 +0000
 +++ lib/interception/interception.h
-@@ -15,7 +15,7 @@
+@@ -15,8 +15,8 @@
  #ifndef INTERCEPTION_H
  #define INTERCEPTION_H
  
 -#if !defined(__linux__) && !defined(__FreeBSD__) && \
+-  !defined(__APPLE__) && !defined(_WIN32)
 +#if !defined(__linux__) && !defined(__FreeBSD__) && !defined(__NetBSD__) && \
-   !defined(__APPLE__) && !defined(_WIN32)
++    !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, ...) \
diff --git a/compiler-rt-netbsd/patches/patch-lib_interception_interception__linux.cc b/compiler-rt-netbsd/patches/patch-lib_interception_interception__linux.cc
index 388322ef1c..1038330d7c 100644
--- a/compiler-rt-netbsd/patches/patch-lib_interception_interception__linux.cc
+++ b/compiler-rt-netbsd/patches/patch-lib_interception_interception__linux.cc
@@ -1,8 +1,8 @@
 $NetBSD$
 
---- lib/interception/interception_linux.cc.orig	2017-06-03 23:53:56.000000000 +0000
+--- lib/interception/interception_linux.cc.orig	2017-07-04 05:53:20.000000000 +0000
 +++ lib/interception/interception_linux.cc
-@@ -12,14 +12,28 @@
+@@ -12,14 +12,26 @@
  // Linux-specific interception methods.
  //===----------------------------------------------------------------------===//
  
@@ -15,8 +15,7 @@ $NetBSD$
 +#ifdef __NetBSD__
 +static int mystrcmp(const char *s1, const char *s2) {
 +  while (*s1 == *s2++)
-+    if (*s1++ == 0)
-+      return (0);
++    if (*s1++ == 0) return (0);
 +  return (*(const unsigned char *)s1 - *(const unsigned char *)--s2);
 +}
 +#endif
@@ -26,15 +25,15 @@ $NetBSD$
      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";
++  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
+@@ -32,5 +44,4 @@ void *GetFuncAddrVer(const char *func_na
  
+ }  // namespace __interception
  
+-
 -#endif  // __linux__ || __FreeBSD__
 +#endif  // __linux__ || __FreeBSD__ || __NetBSD__
diff --git a/compiler-rt-netbsd/patches/patch-lib_interception_interception__linux.h b/compiler-rt-netbsd/patches/patch-lib_interception_interception__linux.h
index 0325239dfc..12e8b384ec 100644
--- a/compiler-rt-netbsd/patches/patch-lib_interception_interception__linux.h
+++ b/compiler-rt-netbsd/patches/patch-lib_interception_interception__linux.h
@@ -1,6 +1,6 @@
 $NetBSD$
 
---- lib/interception/interception_linux.h.orig	2017-06-03 23:53:56.000000000 +0000
+--- lib/interception/interception_linux.h.orig	2017-07-04 05:53:20.000000000 +0000
 +++ lib/interception/interception_linux.h
 @@ -12,7 +12,7 @@
  // Linux-specific interception methods.
diff --git a/compiler-rt-netbsd/patches/patch-lib_lsan_lsan__common.h b/compiler-rt-netbsd/patches/patch-lib_lsan_lsan__common.h
deleted file mode 100644
index afc76512f4..0000000000
--- a/compiler-rt-netbsd/patches/patch-lib_lsan_lsan__common.h
+++ /dev/null
@@ -1,2 +0,0 @@
-$NetBSD$
-
diff --git a/compiler-rt-netbsd/patches/patch-lib_lsan_lsan__linux.cc b/compiler-rt-netbsd/patches/patch-lib_lsan_lsan__linux.cc
deleted file mode 100644
index e2a67300c3..0000000000
--- a/compiler-rt-netbsd/patches/patch-lib_lsan_lsan__linux.cc
+++ /dev/null
@@ -1,10 +0,0 @@
-$NetBSD$
-
---- lib/lsan/lsan_linux.cc.orig	2017-07-04 05:53:20.000000000 +0000
-+++ lib/lsan/lsan_linux.cc
-@@ -30,4 +30,4 @@ void ReplaceSystemMalloc() {}
- 
- } // namespace __lsan
- 
--#endif // SANITIZER_LINUX
-+#endif // SANITIZER_LINUX || SANITIZER_NETBSD
diff --git a/compiler-rt-netbsd/patches/patch-lib_msan_msan.h b/compiler-rt-netbsd/patches/patch-lib_msan_msan.h
deleted file mode 100644
index ade60273f3..0000000000
--- a/compiler-rt-netbsd/patches/patch-lib_msan_msan.h
+++ /dev/null
@@ -1,13 +0,0 @@
-$NetBSD$
-
---- lib/msan/msan.h.orig	2017-06-03 23:53:56.000000000 +0000
-+++ lib/msan/msan.h
-@@ -178,7 +178,7 @@ const MappingDesc kMemoryLayout[] = {
- #define MEM_TO_SHADOW(mem) (LINEARIZE_MEM((mem)) + 0x080000000000ULL)
- #define SHADOW_TO_ORIGIN(shadow) (((uptr)(shadow)) + 0x140000000000ULL)
- 
--#elif SANITIZER_FREEBSD && SANITIZER_WORDSIZE == 64
-+#elif (SANITIZER_FREEBSD && SANITIZER_WORDSIZE == 64) || SANITIZER_NETBSD
- 
- // Low memory: main binary, MAP_32BIT mappings and modules
- // High memory: heap, modules and main thread stack
diff --git a/compiler-rt-netbsd/patches/patch-lib_msan_msan__interceptors.cc b/compiler-rt-netbsd/patches/patch-lib_msan_msan__interceptors.cc
deleted file mode 100644
index a31f747d83..0000000000
--- a/compiler-rt-netbsd/patches/patch-lib_msan_msan__interceptors.cc
+++ /dev/null
@@ -1,184 +0,0 @@
-$NetBSD$
-
---- lib/msan/msan_interceptors.cc.orig	2017-06-12 15:01:29.000000000 +0000
-+++ lib/msan/msan_interceptors.cc
-@@ -48,7 +48,7 @@ DECLARE_REAL(SIZE_T, strnlen, const char
- DECLARE_REAL(void *, memcpy, void *dest, const void *src, uptr n)
- DECLARE_REAL(void *, memset, void *dest, int c, uptr n)
- 
--#if SANITIZER_FREEBSD
-+#if SANITIZER_FREEBSD || SANITIZER_NETBSD
- #define __errno_location __error
- #endif
- 
-@@ -123,7 +123,7 @@ static void *AllocateFromLocalPool(uptr 
- #define CHECK_UNPOISONED_STRING(x, n)                           \
-     CHECK_UNPOISONED_STRING_OF_LEN((x), internal_strlen(x), (n))
- 
--#if !SANITIZER_FREEBSD
-+#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
- INTERCEPTOR(SIZE_T, fread_unlocked, void *ptr, SIZE_T size, SIZE_T nmemb,
-             void *file) {
-   ENSURE_MSAN_INITED();
-@@ -174,7 +174,7 @@ INTERCEPTOR(int, posix_memalign, void **
-   return 0;
- }
- 
--#if !SANITIZER_FREEBSD
-+#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
- INTERCEPTOR(void *, memalign, SIZE_T boundary, SIZE_T size) {
-   GET_MALLOC_STACK_TRACE;
-   CHECK_EQ(boundary & (boundary - 1), 0);
-@@ -207,7 +207,7 @@ INTERCEPTOR(void *, valloc, SIZE_T size)
-   return ptr;
- }
- 
--#if !SANITIZER_FREEBSD
-+#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
- INTERCEPTOR(void *, pvalloc, SIZE_T size) {
-   GET_MALLOC_STACK_TRACE;
-   uptr PageSize = GetPageSizeCached();
-@@ -230,7 +230,7 @@ INTERCEPTOR(void, free, void *ptr) {
-   MsanDeallocate(&stack, ptr);
- }
- 
--#if !SANITIZER_FREEBSD
-+#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
- INTERCEPTOR(void, cfree, void *ptr) {
-   GET_MALLOC_STACK_TRACE;
-   if (!ptr || UNLIKELY(IsInDlsymAllocPool(ptr))) return;
-@@ -245,7 +245,7 @@ INTERCEPTOR(uptr, malloc_usable_size, vo
-   return __sanitizer_get_allocated_size(ptr);
- }
- 
--#if !SANITIZER_FREEBSD
-+#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
- // This function actually returns a struct by value, but we can't unpoison a
- // temporary! The following is equivalent on all supported platforms but
- // aarch64 (which uses a different register for sret value).  We have a test
-@@ -264,7 +264,7 @@ INTERCEPTOR(void, mallinfo, __sanitizer_
- #define MSAN_MAYBE_INTERCEPT_MALLINFO
- #endif
- 
--#if !SANITIZER_FREEBSD
-+#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
- INTERCEPTOR(int, mallopt, int cmd, int value) {
-   return -1;
- }
-@@ -273,7 +273,7 @@ INTERCEPTOR(int, mallopt, int cmd, int v
- #define MSAN_MAYBE_INTERCEPT_MALLOPT
- #endif
- 
--#if !SANITIZER_FREEBSD
-+#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
- INTERCEPTOR(void, malloc_stats, void) {
-   // FIXME: implement, but don't call REAL(malloc_stats)!
- }
-@@ -326,7 +326,7 @@ INTERCEPTOR(char *, strdup, char *src) {
-   return res;
- }
- 
--#if !SANITIZER_FREEBSD
-+#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
- INTERCEPTOR(char *, __strdup, char *src) {
-   ENSURE_MSAN_INITED();
-   GET_STORE_STACK_TRACE;
-@@ -491,7 +491,7 @@ INTERCEPTOR(SIZE_T, strftime_l, char *s,
-   INTERCEPTOR_STRFTIME_BODY(char, SIZE_T, strftime_l, s, max, format, tm, loc);
- }
- 
--#if !SANITIZER_FREEBSD
-+#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
- INTERCEPTOR(SIZE_T, __strftime_l, char *s, SIZE_T max, const char *format,
-             __sanitizer_tm *tm, void *loc) {
-   INTERCEPTOR_STRFTIME_BODY(char, SIZE_T, __strftime_l, s, max, format, tm,
-@@ -513,7 +513,7 @@ INTERCEPTOR(SIZE_T, wcsftime_l, wchar_t 
-                             loc);
- }
- 
--#if !SANITIZER_FREEBSD
-+#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
- INTERCEPTOR(SIZE_T, __wcsftime_l, wchar_t *s, SIZE_T max, const wchar_t *format,
-             __sanitizer_tm *tm, void *loc) {
-   INTERCEPTOR_STRFTIME_BODY(wchar_t, SIZE_T, __wcsftime_l, s, max, format, tm,
-@@ -675,7 +675,7 @@ INTERCEPTOR(int, putenv, char *string) {
-   return res;
- }
- 
--#if !SANITIZER_FREEBSD
-+#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
- INTERCEPTOR(int, __fxstat, int magic, int fd, void *buf) {
-   ENSURE_MSAN_INITED();
-   int res = REAL(__fxstat)(magic, fd, buf);
-@@ -688,7 +688,7 @@ INTERCEPTOR(int, __fxstat, int magic, in
- #define MSAN_MAYBE_INTERCEPT___FXSTAT
- #endif
- 
--#if !SANITIZER_FREEBSD
-+#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
- INTERCEPTOR(int, __fxstat64, int magic, int fd, void *buf) {
-   ENSURE_MSAN_INITED();
-   int res = REAL(__fxstat64)(magic, fd, buf);
-@@ -701,7 +701,7 @@ INTERCEPTOR(int, __fxstat64, int magic, 
- #define MSAN_MAYBE_INTERCEPT___FXSTAT64
- #endif
- 
--#if SANITIZER_FREEBSD
-+#if SANITIZER_FREEBSD || SANITIZER_NETBSD
- INTERCEPTOR(int, fstatat, int fd, char *pathname, void *buf, int flags) {
-   ENSURE_MSAN_INITED();
-   int res = REAL(fstatat)(fd, pathname, buf, flags);
-@@ -720,7 +720,7 @@ INTERCEPTOR(int, __fxstatat, int magic, 
- # define MSAN_INTERCEPT_FSTATAT INTERCEPT_FUNCTION(__fxstatat)
- #endif
- 
--#if !SANITIZER_FREEBSD
-+#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
- INTERCEPTOR(int, __fxstatat64, int magic, int fd, char *pathname, void *buf,
-             int flags) {
-   ENSURE_MSAN_INITED();
-@@ -767,7 +767,7 @@ INTERCEPTOR(char *, fgets, char *s, int 
-   return res;
- }
- 
--#if !SANITIZER_FREEBSD
-+#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
- INTERCEPTOR(char *, fgets_unlocked, char *s, int size, void *stream) {
-   ENSURE_MSAN_INITED();
-   char *res = REAL(fgets_unlocked)(s, size, stream);
-@@ -790,7 +790,7 @@ INTERCEPTOR(int, getrlimit, int resource
-   return res;
- }
- 
--#if !SANITIZER_FREEBSD
-+#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
- INTERCEPTOR(int, getrlimit64, int resource, void *rlim) {
-   if (msan_init_is_running) return REAL(getrlimit64)(resource, rlim);
-   ENSURE_MSAN_INITED();
-@@ -866,7 +866,7 @@ INTERCEPTOR(int, gethostname, char *name
-   return res;
- }
- 
--#if !SANITIZER_FREEBSD
-+#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
- INTERCEPTOR(int, epoll_wait, int epfd, void *events, int maxevents,
-     int timeout) {
-   ENSURE_MSAN_INITED();
-@@ -881,7 +881,7 @@ INTERCEPTOR(int, epoll_wait, int epfd, v
- #define MSAN_MAYBE_INTERCEPT_EPOLL_WAIT
- #endif
- 
--#if !SANITIZER_FREEBSD
-+#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
- INTERCEPTOR(int, epoll_pwait, int epfd, void *events, int maxevents,
-     int timeout, void *sigmask) {
-   ENSURE_MSAN_INITED();
-@@ -970,7 +970,7 @@ INTERCEPTOR(void *, mmap, void *addr, SI
-   return res;
- }
- 
--#if !SANITIZER_FREEBSD
-+#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
- INTERCEPTOR(void *, mmap64, void *addr, SIZE_T length, int prot, int flags,
-             int fd, OFF64_T offset) {
-   ENSURE_MSAN_INITED();
diff --git a/compiler-rt-netbsd/patches/patch-lib_msan_msan__linux.cc b/compiler-rt-netbsd/patches/patch-lib_msan_msan__linux.cc
deleted file mode 100644
index 4b426f0bb8..0000000000
--- a/compiler-rt-netbsd/patches/patch-lib_msan_msan__linux.cc
+++ /dev/null
@@ -1,19 +0,0 @@
-$NetBSD$
-
---- lib/msan/msan_linux.cc.orig	2017-06-03 23:53:56.000000000 +0000
-+++ lib/msan/msan_linux.cc
-@@ -13,7 +13,7 @@
- //===----------------------------------------------------------------------===//
- 
- #include "sanitizer_common/sanitizer_platform.h"
--#if SANITIZER_FREEBSD || SANITIZER_LINUX
-+#if SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD
- 
- #include "msan.h"
- #include "msan_thread.h"
-@@ -213,4 +213,4 @@ void MsanTSDDtor(void *tsd) {
- 
- } // namespace __msan
- 
--#endif // SANITIZER_FREEBSD || SANITIZER_LINUX
-+#endif // SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD
diff --git a/compiler-rt-netbsd/patches/patch-lib_safestack_safestack.cc b/compiler-rt-netbsd/patches/patch-lib_safestack_safestack.cc
deleted file mode 100644
index 42bc33981f..0000000000
--- a/compiler-rt-netbsd/patches/patch-lib_safestack_safestack.cc
+++ /dev/null
@@ -1,14 +0,0 @@
-$NetBSD$
-
---- lib/safestack/safestack.cc.orig	2017-06-03 23:53:56.000000000 +0000
-+++ lib/safestack/safestack.cc
-@@ -21,7 +21,9 @@
- #include <unistd.h>
- #include <sys/resource.h>
- #include <sys/types.h>
-+#if !defined(__NetBSD__)
- #include <sys/user.h>
-+#endif
- 
- #include "interception/interception.h"
- #include "sanitizer_common/sanitizer_common.h"
diff --git a/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_CMakeLists.txt b/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_CMakeLists.txt
index bbde6992e0..7c41adac5b 100644
--- a/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_CMakeLists.txt
+++ b/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_CMakeLists.txt
@@ -1,8 +1,8 @@
 $NetBSD$
 
---- lib/sanitizer_common/CMakeLists.txt.orig	2017-06-03 23:53:58.000000000 +0000
+--- lib/sanitizer_common/CMakeLists.txt.orig	2017-07-16 22:40:10.000000000 +0000
 +++ lib/sanitizer_common/CMakeLists.txt
-@@ -22,6 +22,7 @@ set(SANITIZER_SOURCES_NOTERMINATION
+@@ -23,6 +23,7 @@ set(SANITIZER_SOURCES_NOTERMINATION
    sanitizer_procmaps_freebsd.cc
    sanitizer_procmaps_linux.cc
    sanitizer_procmaps_mac.cc
diff --git a/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__common__interceptors.inc b/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__common__interceptors.inc
deleted file mode 100644
index 86275a4025..0000000000
--- a/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__common__interceptors.inc
+++ /dev/null
@@ -1,12 +0,0 @@
-$NetBSD$
-
---- lib/sanitizer_common/sanitizer_common_interceptors.inc.orig	2017-06-12 15:01:29.000000000 +0000
-+++ lib/sanitizer_common/sanitizer_common_interceptors.inc
-@@ -3799,6 +3799,7 @@ INTERCEPTOR(int, pthread_mutex_lock, voi
-   COMMON_INTERCEPTOR_ENTER(ctx, pthread_mutex_lock, m);
-   COMMON_INTERCEPTOR_MUTEX_PRE_LOCK(ctx, m);
-   int res = REAL(pthread_mutex_lock)(m);
-+
-   if (res == errno_EOWNERDEAD)
-     COMMON_INTERCEPTOR_MUTEX_REPAIR(ctx, m);
-   if (res == 0 || res == errno_EOWNERDEAD)
diff --git a/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__internal__defs.h b/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__internal__defs.h
index d11ae81221..464261b02c 100644
--- a/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__internal__defs.h
+++ b/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__internal__defs.h
@@ -1,13 +1,15 @@
 $NetBSD$
 
---- lib/sanitizer_common/sanitizer_internal_defs.h.orig	2017-06-03 23:53:57.000000000 +0000
+--- lib/sanitizer_common/sanitizer_internal_defs.h.orig	2017-07-04 05:53:22.000000000 +0000
 +++ lib/sanitizer_common/sanitizer_internal_defs.h
-@@ -133,7 +133,7 @@ typedef int pid_t;
+@@ -133,8 +133,8 @@ 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 || \
+-  (SANITIZER_LINUX && defined(__x86_64__))
 +#if SANITIZER_FREEBSD || SANITIZER_NETBSD || SANITIZER_MAC || \
-   (SANITIZER_LINUX && defined(__x86_64__))
++    (SANITIZER_LINUX && defined(__x86_64__))
  typedef u64 OFF_T;
  #else
+ typedef uptr OFF_T;
diff --git a/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__libignore.cc b/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__libignore.cc
index b961420492..5191758c08 100644
--- a/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__libignore.cc
+++ b/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__libignore.cc
@@ -1,6 +1,6 @@
 $NetBSD$
 
---- lib/sanitizer_common/sanitizer_libignore.cc.orig	2017-06-03 23:53:57.000000000 +0000
+--- lib/sanitizer_common/sanitizer_libignore.cc.orig	2017-07-04 05:53:22.000000000 +0000
 +++ lib/sanitizer_common/sanitizer_libignore.cc
 @@ -9,7 +9,7 @@
  
@@ -16,4 +16,4 @@ $NetBSD$
  } // namespace __sanitizer
  
 -#endif // #if SANITIZER_FREEBSD || SANITIZER_LINUX
-+#endif // #if SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD
++#endif  // #if SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD
diff --git a/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__linux.cc b/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__linux.cc
index c9a486a290..a4688fd968 100644
--- a/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__linux.cc
+++ b/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__linux.cc
@@ -1,6 +1,6 @@
 $NetBSD$
 
---- lib/sanitizer_common/sanitizer_linux.cc.orig	2017-06-16 23:00:11.000000000 +0000
+--- lib/sanitizer_common/sanitizer_linux.cc.orig	2017-07-16 22:40:10.000000000 +0000
 +++ lib/sanitizer_common/sanitizer_linux.cc
 @@ -14,7 +14,7 @@
  
@@ -27,36 +27,36 @@ $NetBSD$
  // 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" {
+@@ -79,6 +83,12 @@ extern "C" {
  extern char **environ;  // provided by crt1
  #endif  // SANITIZER_FREEBSD
  
 +#if SANITIZER_NETBSD
-+#include <limits.h>     // For NAME_MAX
++#include <limits.h>  // For NAME_MAX
 +#include <sys/sysctl.h>
 +extern char **environ;  // provided by crt1
-+#endif  // SANITIZER_NETBSD 
++#endif                  // SANITIZER_NETBSD
 +
  #if !SANITIZER_ANDROID
  #include <sys/signal.h>
  #endif
-@@ -131,7 +141,10 @@ namespace __sanitizer {
+@@ -139,7 +149,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     
++#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,
+@@ -182,26 +195,39 @@ uptr internal_open(const char *filename,
  
  uptr internal_read(fd_t fd, void *buf, uptr count) {
    sptr res;
-+#ifdef SANITIZER_NETBSD  
++#if SANITIZER_NETBSD
 +  HANDLE_EINTR(res, internal_syscall_ptr(SYSCALL(read), fd, buf, count));
 +#else
    HANDLE_EINTR(res, (sptr)internal_syscall(SYSCALL(read), fd, (uptr)buf,
@@ -67,7 +67,7 @@ $NetBSD$
  
  uptr internal_write(fd_t fd, const void *buf, uptr count) {
    sptr res;
-+#ifdef SANITIZER_NETBSD
++#if SANITIZER_NETBSD
 +  HANDLE_EINTR(res, internal_syscall_ptr(SYSCALL(write), fd, buf, count));
 +#else
    HANDLE_EINTR(res, (sptr)internal_syscall(SYSCALL(write), fd, (uptr)buf,
@@ -78,7 +78,7 @@ $NetBSD$
  
  uptr internal_ftruncate(fd_t fd, uptr size) {
    sptr res;
-+#ifdef SANITIZER_NETBSD
++#if SANITIZER_NETBSD
 +  HANDLE_EINTR(res, internal_syscall(SYSCALL(ftruncate), fd, 0, (s64)size));
 +#else
    HANDLE_EINTR(res, (sptr)internal_syscall(SYSCALL(ftruncate), fd,
@@ -88,11 +88,12 @@ $NetBSD$
  }
  
 -#if !SANITIZER_LINUX_USES_64BIT_SYSCALLS && !SANITIZER_FREEBSD
-+#if !SANITIZER_LINUX_USES_64BIT_SYSCALLS && !SANITIZER_FREEBSD && !SANITIZER_NETBSD
++#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
+@@ -240,7 +266,7 @@ static void kernel_stat_to_stat(struct k
  #endif
  
  uptr internal_stat(const char *path, void *buf) {
@@ -101,7 +102,7 @@ $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
+@@ -265,7 +291,9 @@ uptr internal_stat(const char *path, voi
  }
  
  uptr internal_lstat(const char *path, void *buf) {
@@ -112,7 +113,7 @@ $NetBSD$
    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
+@@ -290,7 +318,7 @@ uptr internal_lstat(const char *path, vo
  }
  
  uptr internal_fstat(fd_t fd, void *buf) {
@@ -121,7 +122,7 @@ $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)
+@@ -324,7 +352,9 @@ uptr internal_dup2(int oldfd, int newfd)
  }
  
  uptr internal_readlink(const char *path, char *buf, uptr bufsize) {
@@ -132,7 +133,7 @@ $NetBSD$
    return internal_syscall(SYSCALL(readlinkat), AT_FDCWD,
                            (uptr)path, (uptr)buf, bufsize);
  #else
-@@ -348,7 +377,7 @@ uptr internal_sched_yield() {
+@@ -354,7 +384,7 @@ uptr internal_sched_yield() {
  }
  
  void internal__exit(int exitcode) {
@@ -141,7 +142,7 @@ $NetBSD$
    internal_syscall(SYSCALL(exit), exitcode);
  #else
    internal_syscall(SYSCALL(exit_group), exitcode);
-@@ -387,19 +416,25 @@ bool FileExists(const char *filename) {
+@@ -393,19 +423,25 @@ bool FileExists(const char *filename) {
  tid_t GetTid() {
  #if SANITIZER_FREEBSD
    return (uptr)pthread_self();
@@ -168,7 +169,7 @@ $NetBSD$
    return (u64)tv.tv_sec * 1000*1000*1000 + tv.tv_usec * 1000;
  }
  
-@@ -407,7 +442,7 @@ u64 NanoTime() {
+@@ -413,7 +449,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) {
@@ -177,7 +178,7 @@ $NetBSD$
    if (::environ != 0) {
      uptr NameLen = internal_strlen(name);
      for (char **Env = ::environ; *Env != 0; Env++) {
-@@ -541,6 +576,8 @@ void BlockingMutex::Lock() {
+@@ -547,6 +583,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);
@@ -186,16 +187,16 @@ $NetBSD$
  #else
      internal_syscall(SYSCALL(futex), (uptr)m, FUTEX_WAIT, MtxSleeping, 0, 0, 0);
  #endif
-@@ -554,6 +591,8 @@ void BlockingMutex::Unlock() {
+@@ -560,6 +598,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 */
++                   /* 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() {
+@@ -575,6 +615,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.
@@ -203,17 +204,17 @@ $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
++  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 {
+@@ -589,16 +640,34 @@ struct linux_dirent {
  #endif
    char               d_name[256];
  };
@@ -222,15 +223,15 @@ $NetBSD$
  // 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.
++  // 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);
++                              (uptr)data);
 +#else
    return internal_syscall(SYSCALL(ptrace), request, pid, (uptr)addr,
                            (uptr)data);
@@ -248,7 +249,7 @@ $NetBSD$
  }
  
  uptr internal_getpid() {
-@@ -604,7 +672,9 @@ uptr internal_getppid() {
+@@ -610,7 +679,9 @@ uptr internal_getppid() {
  }
  
  uptr internal_getdents(fd_t fd, struct linux_dirent *dirp, unsigned int count) {
@@ -259,7 +260,7 @@ $NetBSD$
    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
+@@ -620,7 +691,11 @@ uptr internal_getdents(fd_t fd, struct l
  }
  
  uptr internal_lseek(fd_t fd, OFF_T offset, int whence) {
@@ -271,7 +272,7 @@ $NetBSD$
  }
  
  #if SANITIZER_LINUX
-@@ -706,7 +780,7 @@ int internal_sigaction_syscall(int signu
+@@ -711,7 +786,7 @@ int internal_sigaction_syscall(int signu
  
  uptr internal_sigprocmask(int how, __sanitizer_sigset_t *set,
      __sanitizer_sigset_t *oldset) {
@@ -280,22 +281,32 @@ $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() {
+@@ -856,7 +931,9 @@ static uptr GetKernelAreaSize() {
+ #endif  // SANITIZER_WORDSIZE == 32
+ 
+ uptr GetMaxVirtualAddress() {
+-#if SANITIZER_WORDSIZE == 64
++#if SANITIZER_NETBSD && defined(__x86_64__)
++  return 0x7f7ffffff000ULL;  // (0x00007f8000000000 - PAGE_SIZE)
++#elif SANITIZER_WORDSIZE == 64
+ # if defined(__powerpc64__) || defined(__aarch64__)
+   // On PowerPC64 we have two different address space layouts: 44- and 46-bit.
+   // We somehow need to figure out which one we are using now and choose
+@@ -900,8 +977,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
+ #if SANITIZER_FREEBSD
+-  const int Mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
++  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::
+@@ -1545,6 +1626,8 @@ SignalContext::WriteFlag SignalContext::
    static const uptr PF_WRITE = 1U << 1;
  #if SANITIZER_FREEBSD
    uptr err = ucontext->uc_mcontext.mc_err;
@@ -304,33 +315,33 @@ $NetBSD$
  #else
    uptr err = ucontext->uc_mcontext.gregs[REG_ERR];
  #endif
-@@ -1520,6 +1600,11 @@ void GetPcSpBp(void *context, uptr *pc, 
+@@ -1591,6 +1674,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;
++#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, 
+@@ -1603,6 +1691,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;
++#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];
-@@ -1606,4 +1696,4 @@ uptr FindAvailableMemoryRange(uptr size,
+@@ -1704,4 +1797,4 @@ bool GetRandom(void *buffer, uptr length
  
  } // namespace __sanitizer
  
 -#endif // SANITIZER_FREEBSD || SANITIZER_LINUX
-+#endif // SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD
++#endif  // SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD
diff --git a/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__linux.h b/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__linux.h
index 08241ea928..f59e5c1790 100644
--- a/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__linux.h
+++ b/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__linux.h
@@ -1,6 +1,6 @@
 $NetBSD$
 
---- lib/sanitizer_common/sanitizer_linux.h.orig	2017-06-03 23:53:57.000000000 +0000
+--- lib/sanitizer_common/sanitizer_linux.h.orig	2017-07-16 22:40:10.000000000 +0000
 +++ lib/sanitizer_common/sanitizer_linux.h
 @@ -14,7 +14,7 @@
  #define SANITIZER_LINUX_H
@@ -11,7 +11,7 @@ $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(
+@@ -128,5 +128,5 @@ ALWAYS_INLINE uptr *get_android_tls_ptr(
  
  }  // namespace __sanitizer
  
diff --git a/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__linux__libcdep.cc b/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__linux__libcdep.cc
index a520666148..732c2da4d0 100644
--- a/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__linux__libcdep.cc
+++ b/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__linux__libcdep.cc
@@ -1,8 +1,8 @@
 $NetBSD$
 
---- lib/sanitizer_common/sanitizer_linux_libcdep.cc.orig	2017-06-16 23:00:11.000000000 +0000
+--- lib/sanitizer_common/sanitizer_linux_libcdep.cc.orig	2017-07-16 22:40:10.000000000 +0000
 +++ lib/sanitizer_common/sanitizer_linux_libcdep.cc
-@@ -14,13 +14,14 @@
+@@ -14,7 +14,7 @@
  
  #include "sanitizer_platform.h"
  
@@ -11,45 +11,46 @@ $NetBSD$
  
  #include "sanitizer_allocator_internal.h"
  #include "sanitizer_atomic.h"
- #include "sanitizer_common.h"
+@@ -22,6 +22,7 @@
  #include "sanitizer_flags.h"
  #include "sanitizer_freebsd.h"
-+#include "sanitizer_netbsd.h"
  #include "sanitizer_linux.h"
++#include "sanitizer_netbsd.h"
  #include "sanitizer_placement_new.h"
  #include "sanitizer_procmaps.h"
-@@ -151,7 +152,7 @@ bool SanitizerGetThreadName(char *name, 
+ #include "sanitizer_stacktrace.h"
+@@ -148,7 +149,8 @@ bool SanitizerGetThreadName(char *name, 
  #endif
  }
  
 -#if !SANITIZER_FREEBSD && !SANITIZER_ANDROID && !SANITIZER_GO
-+#if !SANITIZER_FREEBSD && !SANITIZER_ANDROID && !SANITIZER_GO && !SANITIZER_NETBSD
++#if !SANITIZER_FREEBSD && !SANITIZER_ANDROID && !SANITIZER_GO && \
++    !SANITIZER_NETBSD
  static uptr g_tls_size;
  
  #ifdef __i386__
-@@ -179,7 +180,7 @@ void InitTlsSize() {
+@@ -176,7 +178,8 @@ void InitTlsSize() {
  }
  #else
  void InitTlsSize() { }
 -#endif  // !SANITIZER_FREEBSD && !SANITIZER_ANDROID && !SANITIZER_GO
-+#endif  // !SANITIZER_FREEBSD && !SANITIZER_ANDROID && !SANITIZER_GO && !SANITIZER_NETBSD
++#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() {
+@@ -333,6 +336,10 @@ uptr ThreadSelf() {
  }
  #endif  // SANITIZER_FREEBSD
  
-+#if SANITIZER_NETBSD                                                                                                                                                                          
-+uptr ThreadSelf() {
-+  return (uptr)pthread_self();
-+}
-+#endif // SANITIZER_NETBSD
++#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
+@@ -362,7 +369,7 @@ static void GetTls(uptr *addr, uptr *siz
      *addr = (uptr) dtv[2];
      *size = (*addr == 0) ? 0 : ((uptr) segbase[0] - (uptr) dtv[2]);
    }
@@ -58,7 +59,7 @@ $NetBSD$
    *addr = 0;
    *size = 0;
  #else
-@@ -376,7 +383,7 @@ static void GetTls(uptr *addr, uptr *siz
+@@ -373,7 +380,7 @@ static void GetTls(uptr *addr, uptr *siz
  
  #if !SANITIZER_GO
  uptr GetTlsSize() {
diff --git a/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__netbsd.h b/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__netbsd.h
deleted file mode 100644
index f863f508ca..0000000000
--- a/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__netbsd.h
+++ /dev/null
@@ -1,25 +0,0 @@
-$NetBSD$
-
---- lib/sanitizer_common/sanitizer_netbsd.h.orig	2017-06-18 15:16:00.541244551 +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-netbsd/patches/patch-lib_sanitizer__common_sanitizer__platform.h b/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__platform.h
index 406c5382bd..240fe9bd18 100644
--- a/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__platform.h
+++ b/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__platform.h
@@ -1,35 +1,38 @@
 $NetBSD$
 
---- lib/sanitizer_common/sanitizer_platform.h.orig	2017-06-03 23:53:57.000000000 +0000
+--- lib/sanitizer_common/sanitizer_platform.h.orig	2017-07-04 05:53:23.000000000 +0000
 +++ lib/sanitizer_common/sanitizer_platform.h
-@@ -13,7 +13,7 @@
+@@ -13,8 +13,8 @@
  #ifndef SANITIZER_PLATFORM_H
  #define SANITIZER_PLATFORM_H
  
 -#if !defined(__linux__) && !defined(__FreeBSD__) && \
+-  !defined(__APPLE__) && !defined(_WIN32)
 +#if !defined(__linux__) && !defined(__FreeBSD__) && !defined(__NetBSD__) && \
-   !defined(__APPLE__) && !defined(_WIN32)
++    !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
++#define SANITIZER_NETBSD 1
 +#else
-+# define SANITIZER_NETBSD 0
++#define SANITIZER_NETBSD 0
 +#endif
 +
  #if defined(__APPLE__)
  # define SANITIZER_MAC     1
  # include <TargetConditionals.h>
-@@ -79,7 +85,7 @@
+@@ -79,7 +85,8 @@
  # 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)
++#define SANITIZER_POSIX \
++  (SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD || SANITIZER_MAC)
  
  #if __LP64__ || defined(_WIN64)
  #  define SANITIZER_WORDSIZE 64
diff --git a/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__platform__interceptors.h b/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__platform__interceptors.h
index d47e671fde..5180a5164d 100644
--- a/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__platform__interceptors.h
+++ b/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__platform__interceptors.h
@@ -1,15 +1,15 @@
 $NetBSD$
 
---- lib/sanitizer_common/sanitizer_platform_interceptors.h.orig	2017-06-12 15:01:29.000000000 +0000
+--- lib/sanitizer_common/sanitizer_platform_interceptors.h.orig	2017-07-07 06:32:45.000000000 +0000
 +++ lib/sanitizer_common/sanitizer_platform_interceptors.h
 @@ -49,6 +49,12 @@
  # define SI_FREEBSD 0
  #endif
  
 +#if SANITIZER_NETBSD
-+# define SI_NETBSD 1
++#define SI_NETBSD 1
 +#else
-+# define SI_NETBSD 0
++#define SI_NETBSD 0
 +#endif
 +
  #if SANITIZER_LINUX
@@ -24,25 +24,26 @@ $NetBSD$
  
  #define SANITIZER_INTERCEPT_READ   SI_NOT_WINDOWS
  #define SANITIZER_INTERCEPT_PREAD  SI_NOT_WINDOWS
-@@ -127,7 +133,7 @@
+@@ -127,7 +133,8 @@
  #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_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 @@
+@@ -142,7 +149,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_PRINTF_L SI_FREEBSD || SI_NETBSD
  # define SANITIZER_INTERCEPT_ISOC99_PRINTF SI_LINUX_NOT_ANDROID
  #endif
  
-@@ -151,13 +157,13 @@
+@@ -151,13 +158,14 @@
  
  #define SANITIZER_INTERCEPT_GETPWNAM_AND_FRIENDS SI_NOT_WINDOWS
  #define SANITIZER_INTERCEPT_GETPWNAM_R_AND_FRIENDS \
@@ -53,14 +54,15 @@ $NetBSD$
 +  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_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 @@
+@@ -200,41 +208,43 @@
  #define SANITIZER_INTERCEPT_MBSNRTOWCS SI_MAC || SI_LINUX_NOT_ANDROID
  #define SANITIZER_INTERCEPT_WCSTOMBS SI_NOT_WINDOWS
  #define SANITIZER_INTERCEPT_WCSNRTOMBS \
@@ -99,23 +101,26 @@ $NetBSD$
  #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_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_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 @@
+@@ -242,18 +252,19 @@
    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)
++  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 \
@@ -133,19 +138,21 @@ $NetBSD$
  #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 @@
+@@ -272,29 +283,31 @@
  #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_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_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
@@ -171,7 +178,7 @@ $NetBSD$
  #define SANITIZER_INTERCEPT_CAPGET SI_LINUX_NOT_ANDROID
  #if SI_LINUX && defined(__arm__)
  #define SANITIZER_INTERCEPT_AEABI_MEM 1
-@@ -302,32 +308,32 @@
+@@ -302,32 +315,33 @@
  #define SANITIZER_INTERCEPT_AEABI_MEM 0
  #endif
  #define SANITIZER_INTERCEPT___BZERO SI_MAC
@@ -192,7 +199,7 @@ $NetBSD$
  #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
++  SI_FREEBSD || SI_NETBSD || SI_LINUX_NOT_ANDROID || SI_MAC
  #endif
  
 -#define SANITIZER_INTERCEPT_GETPASS SI_LINUX_NOT_ANDROID || SI_MAC
@@ -208,20 +215,22 @@ $NetBSD$
 +#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 \
++  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 @@
+@@ -335,7 +349,8 @@
  #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_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 @@
+@@ -345,12 +360,13 @@
  #define SANITIZER_INTERCEPT_UTMPX SI_LINUX_NOT_ANDROID || SI_MAC || SI_FREEBSD
  
  #define SANITIZER_INTERCEPT_GETLOADAVG \
@@ -232,7 +241,8 @@ $NetBSD$
 -#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_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)
diff --git a/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__platform__limits__posix.cc b/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__platform__limits__posix.cc
index 3e51df77dc..b6fd1aad26 100644
--- a/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__platform__limits__posix.cc
+++ b/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__platform__limits__posix.cc
@@ -1,6 +1,6 @@
 $NetBSD$
 
---- lib/sanitizer_common/sanitizer_platform_limits_posix.cc.orig	2017-06-03 23:53:57.000000000 +0000
+--- lib/sanitizer_common/sanitizer_platform_limits_posix.cc.orig	2017-07-16 22:40:10.000000000 +0000
 +++ lib/sanitizer_common/sanitizer_platform_limits_posix.cc
 @@ -14,7 +14,7 @@
  
@@ -11,7 +11,7 @@ $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 @@
+@@ -78,7 +78,7 @@
  #include <net/if_arp.h>
  #endif
  
@@ -20,7 +20,7 @@ $NetBSD$
  # include <sys/mount.h>
  # include <sys/sockio.h>
  # include <sys/socket.h>
-@@ -94,16 +94,18 @@
+@@ -93,16 +93,18 @@
  # include <sys/statvfs.h>
  # include <sys/soundcard.h>
  # include <sys/mtio.h>
@@ -36,24 +36,24 @@ $NetBSD$
 +#endif
  
 +#if SANITIZER_FREEBSD
-+# include <sys/consio.h>
-+# include <sys/kbio.h>
-+# include <sys/link_elf.h>
-+# include <net/ethernet.h>
++#include <net/ethernet.h>
++#include <sys/consio.h>
++#include <sys/kbio.h>
++#include <sys/link_elf.h>
  #define _KERNEL  // to declare 'shminfo' structure
  # include <sys/shm.h>
  #undef _KERNEL
-@@ -111,11 +113,19 @@
+@@ -110,11 +112,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 
++#include <link_elf.h>
++#include <net/if_ether.h>
++#include <sys/shm.h>
++#define statfs statvfs
++#define d_ino d_fileno
 +#endif
 +
 +#if SANITIZER_FREEBSD || SANITIZER_IOS || SANITIZER_NETBSD
@@ -65,19 +65,19 @@ $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_
+@@ -199,9 +209,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
++#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
++#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 {
+@@ -244,12 +254,12 @@ namespace __sanitizer {
    unsigned struct_oldold_utsname_sz = sizeof(struct oldold_utsname);
  #endif // SANITIZER_LINUX
  
@@ -88,31 +88,35 @@ $NetBSD$
    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
++#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 {
+@@ -257,12 +267,14 @@ 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
++#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
++#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 {
+@@ -272,10 +284,17 @@ namespace __sanitizer {
+   int e_tabsz = (int)E_TABSZ;
  #endif
  
- 
+-
 -#if (SANITIZER_LINUX || SANITIZER_FREEBSD) && !SANITIZER_ANDROID
-+#if (SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD) && !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);
@@ -125,43 +129,50 @@ $NetBSD$
    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
+@@ -309,9 +328,10 @@ 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;
+-  int glob_nomatch = GLOB_NOMATCH;
+-  int glob_altdirfunc = GLOB_ALTDIRFUNC;
++#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
+ 
+ #if SANITIZER_LINUX && !SANITIZER_ANDROID && \
+@@ -451,7 +471,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
++#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
+@@ -478,7 +498,8 @@ 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
++#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
+@@ -534,7 +555,8 @@ 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)
++#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
+@@ -966,7 +988,7 @@ COMPILER_CHECK(IOC_NR(0x12345678) == _IO
  COMPILER_CHECK(IOC_TYPE(0x12345678) == _IOC_TYPE(0x12345678));
  #endif // SANITIZER_LINUX
  
@@ -170,19 +181,20 @@ $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
+@@ -974,9 +996,10 @@ 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
++#endif  // SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD
  
 -#if (SANITIZER_LINUX || SANITIZER_FREEBSD) && !SANITIZER_ANDROID
-+#if (SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD) && !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
+@@ -1028,7 +1051,7 @@ COMPILER_CHECK(sizeof(__sanitizer_dirent
  CHECK_SIZE_AND_OFFSET(dirent, d_ino);
  #if SANITIZER_MAC
  CHECK_SIZE_AND_OFFSET(dirent, d_seekoff);
@@ -191,23 +203,24 @@ $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
+@@ -1125,11 +1148,15 @@ 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
++#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
++#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)
+@@ -1166,20 +1193,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);
@@ -219,7 +232,7 @@ $NetBSD$
  #undef ifa_dstaddr
  #endif
 -# if SANITIZER_FREEBSD
-+# if SANITIZER_FREEBSD || SANITIZER_NETBSD
++#if SANITIZER_FREEBSD || SANITIZER_NETBSD
  CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_dstaddr);
  # else
  COMPILER_CHECK(sizeof(((__sanitizer_ifaddrs *)nullptr)->ifa_dstaddr) ==
@@ -227,13 +240,14 @@ $NetBSD$
  COMPILER_CHECK(offsetof(__sanitizer_ifaddrs, ifa_dstaddr) ==
                 offsetof(ifaddrs, ifa_ifu));
 -# endif // SANITIZER_FREEBSD
-+# endif // SANITIZER_FREEBSD || SANITIZER_NETBSD
++#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);
+@@ -1280,4 +1307,5 @@ 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
++#endif  // SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_MAC ||
++        // SANITIZER_NETBSD
diff --git a/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__platform__limits__posix.h b/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__platform__limits__posix.h
index a0c154811d..6e85b934d1 100644
--- a/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__platform__limits__posix.h
+++ b/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__platform__limits__posix.h
@@ -1,6 +1,6 @@
 $NetBSD$
 
---- lib/sanitizer_common/sanitizer_platform_limits_posix.h.orig	2017-06-12 15:01:29.000000000 +0000
+--- lib/sanitizer_common/sanitizer_platform_limits_posix.h.orig	2017-07-16 22:40:10.000000000 +0000
 +++ lib/sanitizer_common/sanitizer_platform_limits_posix.h
 @@ -18,18 +18,31 @@
  #include "sanitizer_internal_defs.h"
@@ -18,11 +18,11 @@ $NetBSD$
 -#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)))
++#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)))
++#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
@@ -73,7 +73,7 @@ $NetBSD$
  #elif !defined(__sparc__)
    const unsigned struct___old_kernel_stat_sz = 32;
  #endif
-+#endif // SANITIZER_LINUX || SANITIZER_FREEBSD
++#endif  // SANITIZER_LINUX || SANITIZER_FREEBSD
 +
 +#if SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD
  
@@ -92,27 +92,27 @@ $NetBSD$
      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;
++    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;
++    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
@@ -147,19 +147,19 @@ $NetBSD$
      unsigned long ___unused[4];
 +#else
 +#if defined(__x86_64__)
-+    u64   name;
-+    u32   namelen;
-+    u64   oldp;
-+    u64   oldlenp;
-+    u64   newp;
-+    u64   newlen;
++    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;
++    u32 name;
++    u32 namelen;
++    u32 oldp;
++    u32 oldlenp;
++    u32 newp;
++    u32 newlen;
 +#else
 +#error port this
 +#endif
@@ -189,11 +189,11 @@ $NetBSD$
  #endif
    };
 -#endif // SANITIZER_LINUX || SANITIZER_FREEBSD
-+#endif // SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD
++#endif  // SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD
  
  #if SANITIZER_ANDROID
    struct __sanitizer_mallinfo {
-@@ -324,14 +407,37 @@ namespace __sanitizer {
+@@ -324,14 +407,39 @@ namespace __sanitizer {
      unsigned long shm_dtime;
      unsigned long shm_ctime;
    };
@@ -223,17 +223,19 @@ $NetBSD$
  #endif
  
 -#if (SANITIZER_LINUX || SANITIZER_FREEBSD) && !SANITIZER_ANDROID
-+#if (SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD) && !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
++#endif  // (SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD) &&
++        // !SANITIZER_ANDROID
  
    struct __sanitizer_iovec {
      void *iov_base;
-@@ -351,6 +457,9 @@ namespace __sanitizer {
+@@ -351,6 +459,9 @@ namespace __sanitizer {
  # endif
      void *ifa_dstaddr; // (struct sockaddr *)
      void *ifa_data;
@@ -243,7 +245,7 @@ $NetBSD$
    };
  #endif  // !SANITIZER_ANDROID
  
-@@ -376,13 +485,24 @@ namespace __sanitizer {
+@@ -376,13 +487,24 @@ namespace __sanitizer {
    const int __sanitizer_XDR_FREE = 2;
  #endif
  
@@ -270,7 +272,7 @@ $NetBSD$
      char *pw_class;
  #endif
  #if !(SANITIZER_ANDROID && (SANITIZER_WORDSIZE == 32))
-@@ -390,8 +510,8 @@ namespace __sanitizer {
+@@ -390,8 +512,8 @@ namespace __sanitizer {
  #endif
      char *pw_dir;
      char *pw_shell;
@@ -281,7 +283,7 @@ $NetBSD$
  #endif
  #if SANITIZER_FREEBSD
      int pw_fields;
-@@ -405,12 +525,6 @@ namespace __sanitizer {
+@@ -405,12 +527,6 @@ namespace __sanitizer {
      char **gr_mem;
    };
  
@@ -294,7 +296,7 @@ $NetBSD$
    struct __sanitizer_timeb {
      __sanitizer_time_t time;
      unsigned short millitm;
-@@ -447,7 +561,7 @@ namespace __sanitizer {
+@@ -447,7 +563,7 @@ namespace __sanitizer {
    };
  #endif
  
@@ -303,7 +305,7 @@ $NetBSD$
    struct __sanitizer_msghdr {
      void *msg_name;
      unsigned msg_namelen;
-@@ -497,6 +611,16 @@ namespace __sanitizer {
+@@ -497,6 +613,12 @@ namespace __sanitizer {
      unsigned short d_reclen;
      // more fields that we don't care about
    };
@@ -311,16 +313,12 @@ $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
++    // more fields that we don't care about
 +  };
  #elif SANITIZER_ANDROID || defined(__x86_64__)
    struct __sanitizer_dirent {
      unsigned long long d_ino;
-@@ -523,7 +647,7 @@ namespace __sanitizer {
+@@ -523,7 +645,7 @@ namespace __sanitizer {
  #endif
  
  // 'clock_t' is 32 bits wide on x64 FreeBSD
@@ -329,7 +327,7 @@ $NetBSD$
    typedef int __sanitizer_clock_t;
  #elif defined(__x86_64__) && !defined(_LP64)
    typedef long long __sanitizer_clock_t;
-@@ -531,7 +655,7 @@ namespace __sanitizer {
+@@ -531,7 +653,7 @@ namespace __sanitizer {
    typedef long __sanitizer_clock_t;
  #endif
  
@@ -338,7 +336,7 @@ $NetBSD$
    typedef int __sanitizer_clockid_t;
  #endif
  
-@@ -562,8 +686,22 @@ namespace __sanitizer {
+@@ -562,8 +684,22 @@ namespace __sanitizer {
    typedef struct {
      unsigned long fds_bits[1024 / (8 * sizeof(long))];
    } __sanitizer___kernel_fd_set;
@@ -361,7 +359,7 @@ $NetBSD$
    // 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 {
+@@ -571,6 +707,7 @@ namespace __sanitizer {
      char size[pthread_attr_t_max_sz]; // NOLINT
      void *align;
    };
@@ -369,18 +367,18 @@ $NetBSD$
  
  #if SANITIZER_ANDROID
  # if SANITIZER_MIPS
-@@ -590,6 +729,10 @@ namespace __sanitizer {
+@@ -590,6 +727,10 @@ namespace __sanitizer {
       // uint32_t * 4
       unsigned int __bits[4];
    };
 +#elif SANITIZER_NETBSD
 +  struct __sanitizer_sigset_t {
-+     u32 __bits[4];
++    u32 __bits[4];
 +  };
  #endif
  
    // Linux system headers define the 'sa_handler' and 'sa_sigaction' macros.
-@@ -622,6 +765,15 @@ namespace __sanitizer {
+@@ -622,6 +763,15 @@ namespace __sanitizer {
      uptr sa_flags;
      void (*sa_restorer)();
    };
@@ -396,7 +394,7 @@ $NetBSD$
  #else // !SANITIZER_ANDROID
    struct __sanitizer_sigaction {
  #if defined(__mips__) && !SANITIZER_FREEBSD
-@@ -640,6 +792,7 @@ namespace __sanitizer {
+@@ -640,6 +790,7 @@ namespace __sanitizer {
  #else
      __sanitizer_sigset_t sa_mask;
  #endif
@@ -404,7 +402,7 @@ $NetBSD$
  #ifndef __mips__
  #if defined(__sparc__)
  #if __GLIBC_PREREQ (2, 20)
-@@ -670,7 +823,7 @@ namespace __sanitizer {
+@@ -670,7 +821,7 @@ namespace __sanitizer {
    };
  #endif // !SANITIZER_ANDROID
  
@@ -413,7 +411,7 @@ $NetBSD$
    typedef __sanitizer_sigset_t __sanitizer_kernel_sigset_t;
  #elif defined(__mips__)
    struct __sanitizer_kernel_sigset_t {
-@@ -717,7 +870,7 @@ namespace __sanitizer {
+@@ -717,7 +868,7 @@ namespace __sanitizer {
    extern int af_inet6;
    uptr __sanitizer_in_addr_sz(int af);
  
@@ -422,7 +420,7 @@ $NetBSD$
    struct __sanitizer_dl_phdr_info {
      uptr dlpi_addr;
      const char *dlpi_name;
-@@ -733,7 +886,7 @@ namespace __sanitizer {
+@@ -733,7 +884,7 @@ namespace __sanitizer {
      int ai_family;
      int ai_socktype;
      int ai_protocol;
@@ -431,7 +429,7 @@ $NetBSD$
      unsigned ai_addrlen;
      char *ai_canonname;
      void *ai_addr;
-@@ -759,7 +912,7 @@ namespace __sanitizer {
+@@ -759,7 +910,7 @@ namespace __sanitizer {
      short revents;
    };
  
@@ -440,28 +438,28 @@ $NetBSD$
    typedef unsigned __sanitizer_nfds_t;
  #else
    typedef unsigned long __sanitizer_nfds_t;
-@@ -779,7 +932,7 @@ namespace __sanitizer {
+@@ -779,7 +930,7 @@ namespace __sanitizer {
      int (*gl_lstat)(const char *, void *);
      int (*gl_stat)(const char *, void *);
    };
 -# elif SANITIZER_FREEBSD
-+# elif SANITIZER_FREEBSD || SANITIZER_NETBSD
++#elif SANITIZER_FREEBSD || SANITIZER_NETBSD
    struct __sanitizer_glob_t {
      uptr gl_pathc;
      uptr gl_matchc;
-@@ -793,9 +946,9 @@ namespace __sanitizer {
+@@ -793,9 +944,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
++#endif  // SANITIZER_FREEBSD || SANITIZER_NETBSD
  
 -# if SANITIZER_LINUX || SANITIZER_FREEBSD
-+# if SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD
++#if SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD
    extern int glob_nomatch;
    extern int glob_altdirfunc;
  # endif
-@@ -807,7 +960,7 @@ namespace __sanitizer {
+@@ -807,7 +958,7 @@ namespace __sanitizer {
      uptr we_wordc;
      char **we_wordv;
      uptr we_offs;
@@ -470,81 +468,127 @@ $NetBSD$
      char *we_strings;
      uptr we_nbytes;
  #endif
-@@ -832,6 +985,37 @@ namespace __sanitizer {
+@@ -832,6 +983,37 @@ namespace __sanitizer {
      int _fileno;
    };
  # define SANITIZER_HAS_STRUCT_FILE 1
 +#elif SANITIZER_NETBSD
 +  struct __sanitizer_FILE {
 +    unsigned char *_p;
-+    int     _r;
-+    int     _w;
++    int _r;
++    int _w;
 +    unsigned short _flags;
-+    short   _file;
-+    struct  {
-+        unsigned char *_base;
-+        int     _size;
++    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);
++    int _lbfsize;
++    void *_cookie;
++    int (*_close)(void *ptr);
++    u64 (*_read)(void *, void *, uptr);
++    u64 (*_seek)(void *, u64, int);
 +    uptr (*_write)(void *, const void *, uptr);
 +    struct {
-+        unsigned char *_base;
-+        int     _size;
++      unsigned char *_base;
++      int _size;
 +    } _ext;
 +    unsigned char *_up;
-+    int     _ur;
++    int _ur;
 +    unsigned char _ubuf[3];
 +    unsigned char _nbuf[1];
-+    int     (*_flush)(void *);
-+    char    _lb_unused[sizeof(uptr)];
-+    int     _blksize;
++    int (*_flush)(void *ptr);
++    char _lb_unused[sizeof(uptr)];
++    int _blksize;
 +    u64 _offset;
 +  };
-+# define SANITIZER_HAS_STRUCT_FILE 0 // not ported
++#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 {
+@@ -864,7 +1046,8 @@ namespace __sanitizer {
    extern int ptrace_geteventmsg;
  #endif
  
 -#if (SANITIZER_LINUX || SANITIZER_FREEBSD) && !SANITIZER_ANDROID
-+#if (SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD) && !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
+@@ -967,38 +1150,41 @@ struct __sanitizer_cookie_io_functions_t
  #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
+-  extern unsigned struct_ifreq_sz;
+-  extern unsigned struct_termios_sz;
+-  extern unsigned struct_winsize_sz;
++extern unsigned struct_ifreq_sz;
++extern unsigned struct_termios_sz;
++extern unsigned struct_winsize_sz;
++
 +#if SANITIZER_LINUX || SANITIZER_NETBSD
-   extern unsigned struct_arpreq_sz;
++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
+ 
+ #if SANITIZER_LINUX
+-  extern unsigned struct_arpreq_sz;
+-  extern unsigned struct_cdrom_msf_sz;
+-  extern unsigned struct_cdrom_multisession_sz;
+-  extern unsigned struct_cdrom_read_audio_sz;
+-  extern unsigned struct_cdrom_subchnl_sz;
+-  extern unsigned struct_cdrom_ti_sz;
+-  extern unsigned struct_cdrom_tocentry_sz;
+-  extern unsigned struct_cdrom_tochdr_sz;
+-  extern unsigned struct_cdrom_volctrl_sz;
+-  extern unsigned struct_ff_effect_sz;
+-  extern unsigned struct_floppy_drive_params_sz;
+-  extern unsigned struct_floppy_drive_struct_sz;
+-  extern unsigned struct_floppy_fdc_state_sz;
+-  extern unsigned struct_floppy_max_errors_sz;
+-  extern unsigned struct_floppy_raw_cmd_sz;
+-  extern unsigned struct_floppy_struct_sz;
+-  extern unsigned struct_floppy_write_errors_sz;
+-  extern unsigned struct_format_descr_sz;
+-  extern unsigned struct_hd_driveid_sz;
+-  extern unsigned struct_hd_geometry_sz;
+-  extern unsigned struct_input_absinfo_sz;
+-  extern unsigned struct_input_id_sz;
+-  extern unsigned struct_mtpos_sz;
+-  extern unsigned struct_termio_sz;
+-  extern unsigned struct_vt_consize_sz;
+-  extern unsigned struct_vt_sizes_sz;
+-  extern unsigned struct_vt_stat_sz;
++extern unsigned struct_cdrom_msf_sz;
++extern unsigned struct_cdrom_multisession_sz;
++extern unsigned struct_cdrom_read_audio_sz;
++extern unsigned struct_cdrom_subchnl_sz;
++extern unsigned struct_cdrom_ti_sz;
++extern unsigned struct_cdrom_tocentry_sz;
++extern unsigned struct_cdrom_tochdr_sz;
++extern unsigned struct_cdrom_volctrl_sz;
++extern unsigned struct_ff_effect_sz;
++extern unsigned struct_floppy_drive_params_sz;
++extern unsigned struct_floppy_drive_struct_sz;
++extern unsigned struct_floppy_fdc_state_sz;
++extern unsigned struct_floppy_max_errors_sz;
++extern unsigned struct_floppy_raw_cmd_sz;
++extern unsigned struct_floppy_struct_sz;
++extern unsigned struct_floppy_write_errors_sz;
++extern unsigned struct_format_descr_sz;
++extern unsigned struct_hd_driveid_sz;
++extern unsigned struct_hd_geometry_sz;
++extern unsigned struct_input_absinfo_sz;
++extern unsigned struct_input_id_sz;
++extern unsigned struct_mtpos_sz;
++extern unsigned struct_termio_sz;
++extern unsigned struct_vt_consize_sz;
++extern unsigned struct_vt_sizes_sz;
++extern unsigned struct_vt_stat_sz;
+ #endif  // SANITIZER_LINUX
+ 
+ #if SANITIZER_LINUX || SANITIZER_FREEBSD
+@@ -1006,6 +1192,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;
@@ -554,38 +598,41 @@ $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
+@@ -1013,7 +1202,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
++#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
+@@ -1035,10 +1224,12 @@ 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
++#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
++#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
+@@ -1095,7 +1286,8 @@ 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
++#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
+@@ -1258,7 +1450,7 @@ struct __sanitizer_cookie_io_functions_t
    extern unsigned IOCTL_VT_RESIZEX;
    extern unsigned IOCTL_VT_SENDSIG;
  #endif  // SANITIZER_LINUX
@@ -593,11 +640,7 @@ $NetBSD$
 +#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;
+   extern unsigned IOCTL_SIOCADDRT;
 @@ -1359,7 +1551,7 @@ struct __sanitizer_cookie_io_functions_t
    extern unsigned IOCTL_VT_RELDISP;
    extern unsigned IOCTL_VT_SETMODE;
@@ -607,12 +650,13 @@ $NetBSD$
  
  #if SANITIZER_LINUX && !SANITIZER_ANDROID
    extern unsigned IOCTL_CYGETDEFTHRESH;
-@@ -1448,21 +1640,27 @@ struct __sanitizer_cookie_io_functions_t
+@@ -1448,21 +1640,28 @@ 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_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD) && \
++    !SANITIZER_ANDROID
 +#if !SANITIZER_NETBSD
    extern unsigned IOCTL_GIO_SCRNMAP;
 +#endif
@@ -634,5 +678,5 @@ $NetBSD$
  #endif
 +#endif
  
-   extern const int errno_EINVAL;
-   extern const int errno_EOWNERDEAD;
+   extern const int si_SEGV_MAPERR;
+   extern const int si_SEGV_ACCERR;
diff --git a/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__procmaps.h b/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__procmaps.h
index f9fe12c807..11a9fdb83f 100644
--- a/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__procmaps.h
+++ b/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__procmaps.h
@@ -1,6 +1,6 @@
 $NetBSD$
 
---- lib/sanitizer_common/sanitizer_procmaps.h.orig	2017-06-03 23:53:58.000000000 +0000
+--- lib/sanitizer_common/sanitizer_procmaps.h.orig	2017-07-16 22:40:10.000000000 +0000
 +++ lib/sanitizer_common/sanitizer_procmaps.h
 @@ -20,7 +20,7 @@
  
@@ -18,14 +18,14 @@ $NetBSD$
 -#endif  // SANITIZER_FREEBSD || SANITIZER_LINUX
 +#endif  // SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD
  
- class MemoryMappingLayout {
-  public:
-@@ -58,7 +58,7 @@ class MemoryMappingLayout {
+ // Memory protection masks.
+ static const uptr kProtectionRead = 1;
+@@ -76,7 +76,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
++#if SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD
    ProcSelfMapsBuff proc_self_maps_;
    const char *current_;
  
diff --git a/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__procmaps__common.cc b/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__procmaps__common.cc
index 5aeb0bc1f4..80db9b92f2 100644
--- a/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__procmaps__common.cc
+++ b/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__procmaps__common.cc
@@ -1,6 +1,6 @@
 $NetBSD$
 
---- lib/sanitizer_common/sanitizer_procmaps_common.cc.orig	2017-06-03 23:53:58.000000000 +0000
+--- lib/sanitizer_common/sanitizer_procmaps_common.cc.orig	2017-07-16 22:40:10.000000000 +0000
 +++ lib/sanitizer_common/sanitizer_procmaps_common.cc
 @@ -12,7 +12,7 @@
  
@@ -11,9 +11,9 @@ $NetBSD$
  
  #include "sanitizer_common.h"
  #include "sanitizer_placement_new.h"
-@@ -173,4 +173,4 @@ void GetMemoryProfile(fill_profile_f cb,
+@@ -171,4 +171,4 @@ void GetMemoryProfile(fill_profile_f cb,
  
  } // namespace __sanitizer
  
 -#endif // SANITIZER_FREEBSD || SANITIZER_LINUX
-+#endif // SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD
++#endif  // SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD
diff --git a/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__procmaps__netbsd.cc b/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__procmaps__netbsd.cc
deleted file mode 100644
index 1cd0ef534d..0000000000
--- a/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__procmaps__netbsd.cc
+++ /dev/null
@@ -1,84 +0,0 @@
-$NetBSD$
-
---- lib/sanitizer_common/sanitizer_procmaps_netbsd.cc.orig	2017-06-18 15:16:00.620497444 +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-netbsd/patches/patch-lib_sanitizer__common_sanitizer__syscall__generic.inc b/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__syscall__generic.inc
index b824fd129c..55f1599b51 100644
--- a/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__syscall__generic.inc
+++ b/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__syscall__generic.inc
@@ -1,8 +1,8 @@
 $NetBSD$
 
---- lib/sanitizer_common/sanitizer_syscall_generic.inc.orig	2017-06-03 23:53:57.000000000 +0000
+--- lib/sanitizer_common/sanitizer_syscall_generic.inc.orig	2017-07-04 05:53:23.000000000 +0000
 +++ lib/sanitizer_common/sanitizer_syscall_generic.inc
-@@ -11,13 +11,37 @@
+@@ -11,13 +11,39 @@
  //
  //===----------------------------------------------------------------------===//
  
@@ -18,6 +18,7 @@ $NetBSD$
 +# define SYS_sigprocmask SYS___sigprocmask14
 +# define SYS_nanosleep SYS___nanosleep50
 +#endif
++
 +#if SANITIZER_FREEBSD || SANITIZER_MAC || SANITIZER_NETBSD
  # define SYSCALL(name) SYS_ ## name
  #else
@@ -27,18 +28,19 @@ $NetBSD$
 -#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.
++// to address differences in calling conventions (e.g. registers to place the
++// return value in).
 +//   - 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_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__)
++#elif defined(__x86_64__) && (SANITIZER_FREEBSD || SANITIZER_MAC)
  # define internal_syscall __syscall
  # else
  # define internal_syscall syscall
diff --git a/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__unwind__linux__libcdep.cc b/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__unwind__linux__libcdep.cc
index 850ef8b482..b558b004d4 100644
--- a/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__unwind__linux__libcdep.cc
+++ b/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__unwind__linux__libcdep.cc
@@ -1,6 +1,6 @@
 $NetBSD$
 
---- lib/sanitizer_common/sanitizer_unwind_linux_libcdep.cc.orig	2017-06-03 23:53:57.000000000 +0000
+--- lib/sanitizer_common/sanitizer_unwind_linux_libcdep.cc.orig	2017-07-04 05:53:22.000000000 +0000
 +++ lib/sanitizer_common/sanitizer_unwind_linux_libcdep.cc
 @@ -8,11 +8,11 @@
  //===----------------------------------------------------------------------===//
diff --git a/compiler-rt-netbsd/patches/patch-lib_tsan_rtl_tsan__interceptors.cc b/compiler-rt-netbsd/patches/patch-lib_tsan_rtl_tsan__interceptors.cc
deleted file mode 100644
index 90f7ca81b1..0000000000
--- a/compiler-rt-netbsd/patches/patch-lib_tsan_rtl_tsan__interceptors.cc
+++ /dev/null
@@ -1,133 +0,0 @@
-$NetBSD$
-
---- lib/tsan/rtl/tsan_interceptors.cc.orig	2017-06-03 23:53:57.000000000 +0000
-+++ lib/tsan/rtl/tsan_interceptors.cc
-@@ -39,6 +39,14 @@ using namespace __tsan;  // NOLINT
- #define stderr __stderrp
- #endif
- 
-+#if SANITIZER_NETBSD
-+#define __errno_location __errno
-+#define pthread_yield sched_yield
-+#define fileno_unlocked fileno
-+#define stdout __sF[1]
-+#define stderr __sF[2]
-+#endif
-+
- #if SANITIZER_ANDROID
- #define __errno_location __errno
- #define mallopt(a, b)
-@@ -87,11 +95,15 @@ extern "C" void _exit(int status);
- extern "C" int *__errno_location();
- extern "C" int fileno_unlocked(void *stream);
- extern "C" int dirfd(void *dirp);
--#if !SANITIZER_FREEBSD && !SANITIZER_ANDROID
-+#if !SANITIZER_FREEBSD && !SANITIZER_ANDROID && !SANITIZER_NETBSD
- extern "C" int mallopt(int param, int value);
- #endif
-+#if SANITIZER_NETBSD
-+extern __sanitizer_FILE **__sF;
-+#else
- extern __sanitizer_FILE *stdout, *stderr;
--#if !SANITIZER_FREEBSD && !SANITIZER_MAC
-+#endif
-+#if !SANITIZER_FREEBSD && !SANITIZER_MAC && !SANITIZER_NETBSD
- const int PTHREAD_MUTEX_RECURSIVE = 1;
- const int PTHREAD_MUTEX_RECURSIVE_NP = 1;
- #else
-@@ -100,8 +112,12 @@ const int PTHREAD_MUTEX_RECURSIVE_NP = 2
- #endif
- const int EINVAL = 22;
- const int EBUSY = 16;
-+#if SANITIZER_NETBSD
-+const int EOWNERDEAD = -1;
-+#else
- const int EOWNERDEAD = 130;
--#if !SANITIZER_FREEBSD && !SANITIZER_MAC
-+#endif
-+#if !SANITIZER_FREEBSD && !SANITIZER_MAC && !SANITIZER_NETBSD
- const int EPOLL_CTL_ADD = 1;
- #endif
- const int SIGILL = 4;
-@@ -110,7 +126,7 @@ const int SIGFPE = 8;
- const int SIGSEGV = 11;
- const int SIGPIPE = 13;
- const int SIGTERM = 15;
--#if defined(__mips__) || SANITIZER_FREEBSD || SANITIZER_MAC
-+#if defined(__mips__) || SANITIZER_FREEBSD || SANITIZER_MAC || SANITIZER_NETBSD
- const int SIGBUS = 10;
- const int SIGSYS = 12;
- #else
-@@ -154,7 +170,7 @@ struct sigaction_t {
-     sighandler_t sa_handler;
-     sigactionhandler_t sa_sigaction;
-   };
--#if SANITIZER_FREEBSD
-+#if SANITIZER_FREEBSD || SANITIZER_NETBSD
-   int sa_flags;
-   __sanitizer_sigset_t sa_mask;
- #elif SANITIZER_MAC
-@@ -173,7 +189,7 @@ struct sigaction_t {
- const sighandler_t SIG_DFL = (sighandler_t)0;
- const sighandler_t SIG_IGN = (sighandler_t)1;
- const sighandler_t SIG_ERR = (sighandler_t)-1;
--#if SANITIZER_FREEBSD || SANITIZER_MAC
-+#if SANITIZER_FREEBSD || SANITIZER_MAC || SANITIZER_NETBSD
- const int SA_SIGINFO = 0x40;
- const int SIG_SETMASK = 3;
- #elif defined(__mips__)
-@@ -289,7 +305,7 @@ void ScopedInterceptor::DisableIgnores()
- }
- 
- #define TSAN_INTERCEPT(func) INTERCEPT_FUNCTION(func)
--#if SANITIZER_FREEBSD
-+#if SANITIZER_FREEBSD || SANITIZER_NETBSD
- # define TSAN_INTERCEPT_VER(func, ver) INTERCEPT_FUNCTION(func)
- #else
- # define TSAN_INTERCEPT_VER(func, ver) INTERCEPT_FUNCTION_VER(func, ver)
-@@ -466,7 +482,7 @@ static void SetJmp(ThreadState *thr, upt
- static void LongJmp(ThreadState *thr, uptr *env) {
- #ifdef __powerpc__
-   uptr mangled_sp = env[0];
--#elif SANITIZER_FREEBSD || SANITIZER_MAC
-+#elif SANITIZER_FREEBSD || SANITIZER_MAC || SANITIZER_NETBSD
-   uptr mangled_sp = env[2];
- #elif defined(SANITIZER_LINUX)
- # ifdef __aarch64__
-@@ -1348,7 +1364,7 @@ TSAN_INTERCEPTOR(int, __fxstat, int vers
- #endif
- 
- TSAN_INTERCEPTOR(int, fstat, int fd, void *buf) {
--#if SANITIZER_FREEBSD || SANITIZER_MAC || SANITIZER_ANDROID
-+#if SANITIZER_FREEBSD || SANITIZER_MAC || SANITIZER_ANDROID || SANITIZER_NETBSD
-   SCOPED_TSAN_INTERCEPTOR(fstat, fd, buf);
-   if (fd > 0)
-     FdAccess(thr, pc, fd);
-@@ -1929,7 +1945,7 @@ TSAN_INTERCEPTOR(int, sigaction, int sig
-   sigactions[sig].sa_flags = *(volatile int*)&act->sa_flags;
-   internal_memcpy(&sigactions[sig].sa_mask, &act->sa_mask,
-       sizeof(sigactions[sig].sa_mask));
--#if !SANITIZER_FREEBSD && !SANITIZER_MAC
-+#if !SANITIZER_FREEBSD && !SANITIZER_MAC && !SANITIZER_NETBSD
-   sigactions[sig].sa_restorer = act->sa_restorer;
- #endif
-   sigaction_t newact;
-@@ -2291,7 +2307,7 @@ struct ScopedSyscall {
-   }
- };
- 
--#if !SANITIZER_FREEBSD && !SANITIZER_MAC
-+#if !SANITIZER_FREEBSD && !SANITIZER_MAC && !SANITIZER_NETBSD
- static void syscall_access_range(uptr pc, uptr p, uptr s, bool write) {
-   TSAN_SYSCALL();
-   MemoryAccessRange(thr, pc, p, s, write);
-@@ -2571,7 +2587,9 @@ void InitializeInterceptors() {
- #endif
-   TSAN_INTERCEPT(on_exit);
-   TSAN_INTERCEPT(__cxa_atexit);
-+#if !SANITIZER_NETBSD
-   TSAN_INTERCEPT(_exit);
-+#endif
- 
- #ifdef NEED_TLS_GET_ADDR
-   TSAN_INTERCEPT(__tls_get_addr);
diff --git a/compiler-rt-netbsd/patches/patch-lib_tsan_rtl_tsan__platform__linux.cc b/compiler-rt-netbsd/patches/patch-lib_tsan_rtl_tsan__platform__linux.cc
deleted file mode 100644
index 14c551d631..0000000000
--- a/compiler-rt-netbsd/patches/patch-lib_tsan_rtl_tsan__platform__linux.cc
+++ /dev/null
@@ -1,25 +0,0 @@
-$NetBSD$
-
---- lib/tsan/rtl/tsan_platform_linux.cc.orig	2017-06-03 23:53:57.000000000 +0000
-+++ lib/tsan/rtl/tsan_platform_linux.cc
-@@ -9,12 +9,12 @@
- //
- // This file is a part of ThreadSanitizer (TSan), a race detector.
- //
--// Linux- and FreeBSD-specific code.
-+// Linux-, FreeBSD- and NetBSD-specific code.
- //===----------------------------------------------------------------------===//
- 
- 
- #include "sanitizer_common/sanitizer_platform.h"
--#if SANITIZER_LINUX || SANITIZER_FREEBSD
-+#if SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD
- 
- #include "sanitizer_common/sanitizer_common.h"
- #include "sanitizer_common/sanitizer_libc.h"
-@@ -404,4 +404,4 @@ void cur_thread_finalize() {
- 
- }  // namespace __tsan
- 
--#endif  // SANITIZER_LINUX || SANITIZER_FREEBSD
-+#endif  // SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD
diff --git a/compiler-rt-netbsd/patches/patch-lib_tsan_rtl_tsan__rtl__amd64.S b/compiler-rt-netbsd/patches/patch-lib_tsan_rtl_tsan__rtl__amd64.S
deleted file mode 100644
index cebeda20a5..0000000000
--- a/compiler-rt-netbsd/patches/patch-lib_tsan_rtl_tsan__rtl__amd64.S
+++ /dev/null
@@ -1,40 +0,0 @@
-$NetBSD$
-
---- lib/tsan/rtl/tsan_rtl_amd64.S.orig	2017-06-03 23:53:57.000000000 +0000
-+++ lib/tsan/rtl/tsan_rtl_amd64.S
-@@ -178,7 +178,7 @@ ASM_TSAN_SYMBOL_INTERCEPTOR(setjmp):
-   CFI_ADJUST_CFA_OFFSET(8)
-   CFI_REL_OFFSET(%rdi, 0)
-   // obtain %rsp
--#if defined(__FreeBSD__)
-+#if defined(__FreeBSD__) || defined(__NetBSD__)
-   lea 8(%rsp), %rdi
-   mov %rdi, %rsi
- #elif defined(__APPLE__)
-@@ -219,7 +219,7 @@ ASM_TSAN_SYMBOL_INTERCEPTOR(_setjmp):
-   CFI_ADJUST_CFA_OFFSET(8)
-   CFI_REL_OFFSET(%rdi, 0)
-   // obtain %rsp
--#if defined(__FreeBSD__)
-+#if defined(__FreeBSD__) || defined(__NetBSD__)
-   lea 8(%rsp), %rdi
-   mov %rdi, %rsi
- #elif defined(__APPLE__)
-@@ -267,7 +267,7 @@ ASM_TSAN_SYMBOL_INTERCEPTOR(sigsetjmp):
-   sub $8, %rsp
-   CFI_ADJUST_CFA_OFFSET(8)
-   // obtain %rsp
--#if defined(__FreeBSD__)
-+#if defined(__FreeBSD__) || defined(__NetBSD__)
-   lea 24(%rsp), %rdi
-   mov %rdi, %rsi
- #elif defined(__APPLE__)
-@@ -323,7 +323,7 @@ ASM_TSAN_SYMBOL_INTERCEPTOR(__sigsetjmp)
-   sub $8, %rsp
-   CFI_ADJUST_CFA_OFFSET(8)
-   // obtain %rsp
--#if defined(__FreeBSD__)
-+#if defined(__FreeBSD__) || defined(__NetBSD__)
-   lea 24(%rsp), %rdi
-   mov %rdi, %rsi
- #else
diff --git a/compiler-rt-netbsd/patches/patch-lib_ubsan_ubsan__platform.h b/compiler-rt-netbsd/patches/patch-lib_ubsan_ubsan__platform.h
deleted file mode 100644
index bc72a8f8de..0000000000
--- a/compiler-rt-netbsd/patches/patch-lib_ubsan_ubsan__platform.h
+++ /dev/null
@@ -1,13 +0,0 @@
-$NetBSD$
-
---- lib/ubsan/ubsan_platform.h.orig	2017-06-03 23:53:57.000000000 +0000
-+++ lib/ubsan/ubsan_platform.h
-@@ -14,7 +14,7 @@
- #define UBSAN_PLATFORM_H
- 
- // Other platforms should be easy to add, and probably work as-is.
--#if (defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__)) && \
-+#if (defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__APPLE__)) && \
-     (defined(__x86_64__) || defined(__i386__) || defined(__arm__) || \
-      defined(__aarch64__) || defined(__mips__) || defined(__powerpc64__) || \
-      defined(__s390__))
diff --git a/compiler-rt-netbsd/patches/patch-test_asan_TestCases_heavy__uar__test.cc b/compiler-rt-netbsd/patches/patch-test_asan_TestCases_heavy__uar__test.cc
deleted file mode 100644
index 3db39c7c5a..0000000000
--- a/compiler-rt-netbsd/patches/patch-test_asan_TestCases_heavy__uar__test.cc
+++ /dev/null
@@ -1,13 +0,0 @@
-$NetBSD$
-
---- test/asan/TestCases/heavy_uar_test.cc.orig	2017-06-03 23:53:55.000000000 +0000
-+++ test/asan/TestCases/heavy_uar_test.cc
-@@ -49,7 +49,7 @@ int main(int argc, char **argv) {
-     RecursiveFunctionWithStackFrame<2000>(depth);
-     // The stack size is tight for the main thread in multithread
-     // environment on FreeBSD.
--#if !defined(__FreeBSD__)
-+#if !defined(__FreeBSD__) // XXX: NetBSD?
-     RecursiveFunctionWithStackFrame<5000>(depth);
-     RecursiveFunctionWithStackFrame<10000>(depth);
- #endif
diff --git a/compiler-rt-netbsd/patches/patch-test_asan_TestCases_non-executable-pc.cpp b/compiler-rt-netbsd/patches/patch-test_asan_TestCases_non-executable-pc.cpp
deleted file mode 100644
index e12ffb87ad..0000000000
--- a/compiler-rt-netbsd/patches/patch-test_asan_TestCases_non-executable-pc.cpp
+++ /dev/null
@@ -1,15 +0,0 @@
-$NetBSD$
-
---- test/asan/TestCases/non-executable-pc.cpp.orig	2017-06-03 23:53:56.000000000 +0000
-+++ test/asan/TestCases/non-executable-pc.cpp
-@@ -2,8 +2,8 @@
- // RUN: not %run %t 0 2>&1 | FileCheck %s
- // RUN: not %run %t n 2>&1 | FileCheck %s -check-prefix=CHECK -check-prefix=NON_EXEC
- 
--// Only Linux and FreeBSD list every memory region in MemoryMappingLayout, for now.
--// REQUIRES: linux || freebsd
-+// Only Linux, FreeBSD and NetBSD list every memory region in MemoryMappingLayout, for now.
-+// REQUIRES: linux || freebsd || netbsd
- 
- #include <assert.h>
- 
diff --git a/compiler-rt-netbsd/patches/patch-test_asan_TestCases_verbose-log-path__test.cc b/compiler-rt-netbsd/patches/patch-test_asan_TestCases_verbose-log-path__test.cc
deleted file mode 100644
index 685d10e169..0000000000
--- a/compiler-rt-netbsd/patches/patch-test_asan_TestCases_verbose-log-path__test.cc
+++ /dev/null
@@ -1,13 +0,0 @@
-$NetBSD$
-
---- test/asan/TestCases/verbose-log-path_test.cc.orig	2017-06-03 23:53:56.000000000 +0000
-+++ test/asan/TestCases/verbose-log-path_test.cc
-@@ -8,7 +8,7 @@
- // RUN: %env_asan_opts=log_path=%T/asan.log:log_exe_name=1 not %run %T/verbose-log-path_test-binary 2> %t.out
- // RUN: FileCheck %s --check-prefix=CHECK-ERROR < %T/asan.log.verbose-log-path_test-binary.*
- 
--// FIXME: only FreeBSD and Linux have verbose log paths now.
-+// FIXME: only FreeBSD, NetBSD and Linux have verbose log paths now.
- // XFAIL: win32,android
- // UNSUPPORTED: ios
- 
diff --git a/compiler-rt-netbsd/patches/patch-test_asan_lit.cfg b/compiler-rt-netbsd/patches/patch-test_asan_lit.cfg
deleted file mode 100644
index 92bf2e30d2..0000000000
--- a/compiler-rt-netbsd/patches/patch-test_asan_lit.cfg
+++ /dev/null
@@ -1,24 +0,0 @@
-$NetBSD$
-
---- test/asan/lit.cfg.orig	2017-06-03 23:53:55.000000000 +0000
-+++ test/asan/lit.cfg
-@@ -58,8 +58,8 @@ config.substitutions.append(('%env_asan_
- # Setup source root.
- config.test_source_root = os.path.dirname(__file__)
- 
--# There is no libdl on FreeBSD.
--if config.host_os != 'FreeBSD':
-+# There is no libdl on FreeBSD and NetBSD.
-+if config.host_os != 'FreeBSD' and config.host_os != 'NetBSD':
-   libdl_flag = "-ldl"
- else:
-   libdl_flag = ""
-@@ -256,7 +256,7 @@ else:
-   config.substitutions.append(('%pie', '-pie'))
- 
- # Only run the tests on supported OSs.
--if config.host_os not in ['Linux', 'Darwin', 'FreeBSD', 'Windows']:
-+if config.host_os not in ['Linux', 'Darwin', 'FreeBSD', 'NetBSD', 'Windows']:
-   config.unsupported = True
- 
- if config.host_os == 'Darwin' and config.target_arch in ["x86_64", "x86_64h"]:
diff --git a/compiler-rt-netbsd/patches/patch-test_msan_ftime.cc b/compiler-rt-netbsd/patches/patch-test_msan_ftime.cc
deleted file mode 100644
index c9808f7ab2..0000000000
--- a/compiler-rt-netbsd/patches/patch-test_msan_ftime.cc
+++ /dev/null
@@ -1,12 +0,0 @@
-$NetBSD$
-
---- test/msan/ftime.cc.orig	2017-06-03 23:53:55.000000000 +0000
-+++ test/msan/ftime.cc
-@@ -1,6 +1,6 @@
- // RUN: %clangxx_msan -O0 -g %s -o %t && %run %t
- 
--// ftime() is deprecated on FreeBSD.
-+// ftime() is deprecated on FreeBSD/NetBSD.
- // XFAIL: freebsd
- 
- #include <assert.h>
diff --git a/compiler-rt-netbsd/patches/patch-test_msan_iconv.cc b/compiler-rt-netbsd/patches/patch-test_msan_iconv.cc
deleted file mode 100644
index 66273a8991..0000000000
--- a/compiler-rt-netbsd/patches/patch-test_msan_iconv.cc
+++ /dev/null
@@ -1,15 +0,0 @@
-$NetBSD$
-
---- test/msan/iconv.cc.orig	2017-06-03 23:53:55.000000000 +0000
-+++ test/msan/iconv.cc
-@@ -15,8 +15,8 @@ int main(void) {
-   char inbuf_[100];
-   strcpy(inbuf_, "sample text");
-   char outbuf_[100];
--#if defined(__FreeBSD__)
--  // FreeBSD's iconv() expects the 2nd argument be of type 'const char**'.
-+#if defined(__FreeBSD__) || defined(__NetBSD__)
-+  // FreeBSD/NetBSD's iconv() expects the 2nd argument be of type 'const char**'.
-   const char *inbuf = inbuf_;
- #else
-   char *inbuf = inbuf_;
diff --git a/compiler-rt-netbsd/patches/patch-test_msan_initgroups.cc b/compiler-rt-netbsd/patches/patch-test_msan_initgroups.cc
deleted file mode 100644
index b138735fa9..0000000000
--- a/compiler-rt-netbsd/patches/patch-test_msan_initgroups.cc
+++ /dev/null
@@ -1,13 +0,0 @@
-$NetBSD$
-
---- test/msan/initgroups.cc.orig	2017-06-03 23:53:55.000000000 +0000
-+++ test/msan/initgroups.cc
-@@ -2,7 +2,7 @@
- 
- #include <sys/types.h>
- #include <grp.h>
--#include <unistd.h>  // FreeBSD declares initgroups() here.
-+#include <unistd.h>  // FreeBSD/NetBSD declares initgroups() here.
- 
- int main(void) {
-   initgroups("root", 0);
diff --git a/compiler-rt-netbsd/patches/patch-test_msan_lit.cfg b/compiler-rt-netbsd/patches/patch-test_msan_lit.cfg
deleted file mode 100644
index 9684bee415..0000000000
--- a/compiler-rt-netbsd/patches/patch-test_msan_lit.cfg
+++ /dev/null
@@ -1,15 +0,0 @@
-$NetBSD$
-
---- test/msan/lit.cfg.orig	2017-06-03 23:53:55.000000000 +0000
-+++ test/msan/lit.cfg
-@@ -15,8 +15,8 @@ clang_msan_cflags = (["-fsanitize=memory
-                       "-fno-optimize-sibling-calls"] +
-                       [config.target_cflags] +
-                       config.debug_info_flags)
--# Some Msan tests leverage backtrace() which requires libexecinfo on FreeBSD.
--if config.host_os == 'FreeBSD':
-+# Some Msan tests leverage backtrace() which requires libexecinfo on FreeBSD/NetBSD.
-+if config.host_os == 'FreeBSD' or config.host_os == 'NetBSD':
-   clang_msan_cflags += ["-lexecinfo"]
- clang_msan_cxxflags = config.cxx_mode_flags + clang_msan_cflags
- 
diff --git a/compiler-rt-netbsd/patches/patch-test_profile_lit.cfg b/compiler-rt-netbsd/patches/patch-test_profile_lit.cfg
deleted file mode 100644
index 425f31bff5..0000000000
--- a/compiler-rt-netbsd/patches/patch-test_profile_lit.cfg
+++ /dev/null
@@ -1,13 +0,0 @@
-$NetBSD$
-
---- test/profile/lit.cfg.orig	2017-06-03 23:53:55.000000000 +0000
-+++ test/profile/lit.cfg
-@@ -78,7 +78,7 @@ config.substitutions.append( ("%clangxx_
- 
- config.substitutions.append( ("%clang_lto_profgen=", build_invocation(clang_cflags, True) + " -fprofile-instr-generate=") )
- 
--if config.host_os not in ['Darwin', 'FreeBSD', 'Linux']:
-+if config.host_os not in ['Darwin', 'FreeBSD', 'Linux', 'NetBSD']:
-   config.unsupported = True
- 
- if config.target_arch in ['armv7l']:
diff --git a/compiler-rt-netbsd/patches/patch-test_safestack_lit.cfg b/compiler-rt-netbsd/patches/patch-test_safestack_lit.cfg
deleted file mode 100644
index 157e86c462..0000000000
--- a/compiler-rt-netbsd/patches/patch-test_safestack_lit.cfg
+++ /dev/null
@@ -1,15 +0,0 @@
-$NetBSD$
-
---- test/safestack/lit.cfg.orig	2017-06-03 23:53:55.000000000 +0000
-+++ test/safestack/lit.cfg
-@@ -18,8 +18,8 @@ config.substitutions.append( ("%clang_sa
- if config.lto_supported:
-   config.substitutions.append((r"%clang_lto_safestack ", ' '.join(config.lto_launch + [config.clang] + config.lto_flags + ['-fsanitize=safe-stack '])))
- 
--# SafeStack tests are currently supported on Linux, FreeBSD and Darwin only.
--if config.host_os not in ['Linux', 'FreeBSD', 'Darwin']:
-+# SafeStack tests are currently supported on Linux, FreeBSD, NetBSD and Darwin only.
-+if config.host_os not in ['Linux', 'FreeBSD', 'Darwin', 'NetBSD']:
-    config.unsupported = True
- 
- # Allow tests to use REQUIRES=stable-runtime.  For use when you cannot use XFAIL
diff --git a/compiler-rt-netbsd/patches/patch-test_sanitizer__common_CMakeLists.txt b/compiler-rt-netbsd/patches/patch-test_sanitizer__common_CMakeLists.txt
deleted file mode 100644
index ea72725428..0000000000
--- a/compiler-rt-netbsd/patches/patch-test_sanitizer__common_CMakeLists.txt
+++ /dev/null
@@ -1,17 +0,0 @@
-$NetBSD$
-
---- test/sanitizer_common/CMakeLists.txt.orig	2017-06-03 23:53:55.000000000 +0000
-+++ test/sanitizer_common/CMakeLists.txt
-@@ -4,10 +4,10 @@ set(SANITIZER_COMMON_TEST_DEPS ${SANITIZ
- set(SANITIZER_COMMON_TESTSUITES)
- 
- set(SUPPORTED_TOOLS)
--if(CMAKE_SYSTEM_NAME MATCHES "Darwin|Linux|FreeBSD" AND NOT ANDROID)
-+if(CMAKE_SYSTEM_NAME MATCHES "Darwin|Linux|FreeBSD|NetBSD" AND NOT ANDROID)
-   list(APPEND SUPPORTED_TOOLS asan)
- endif()
--if(CMAKE_SYSTEM_NAME MATCHES "Linux" AND NOT ANDROID)
-+if(CMAKE_SYSTEM_NAME MATCHES "Linux|NetBSD" AND NOT ANDROID)
-   list(APPEND SUPPORTED_TOOLS tsan)
-   list(APPEND SUPPORTED_TOOLS msan)
-   list(APPEND SUPPORTED_TOOLS lsan)
diff --git a/compiler-rt-netbsd/patches/patch-test_sanitizer__common_print__address.h b/compiler-rt-netbsd/patches/patch-test_sanitizer__common_print__address.h
deleted file mode 100644
index fec047da8d..0000000000
--- a/compiler-rt-netbsd/patches/patch-test_sanitizer__common_print__address.h
+++ /dev/null
@@ -1,13 +0,0 @@
-$NetBSD$
-
---- test/sanitizer_common/print_address.h.orig	2017-06-03 23:53:55.000000000 +0000
-+++ test/sanitizer_common/print_address.h
-@@ -8,7 +8,7 @@ void print_address(const char *str, int 
-   while (n--) {
-     void *p = va_arg(ap, void *);
- #if defined(__x86_64__) || defined(__aarch64__) || defined(__powerpc64__)
--    // On FreeBSD, the %p conversion specifier works as 0x%x and thus does not
-+    // On FreeBSD/NetBSD, the %p conversion specifier works as 0x%x and thus does not
-     // match to the format used in the diagnotic message.
-     fprintf(stderr, "0x%012lx ", (unsigned long) p);
- #elif defined(__i386__) || defined(__arm__)
diff --git a/compiler-rt-netbsd/patches/patch-test_tsan_lit.cfg b/compiler-rt-netbsd/patches/patch-test_tsan_lit.cfg
deleted file mode 100644
index 77673e4cf9..0000000000
--- a/compiler-rt-netbsd/patches/patch-test_tsan_lit.cfg
+++ /dev/null
@@ -1,15 +0,0 @@
-$NetBSD$
-
---- test/tsan/lit.cfg.orig	2017-06-03 23:53:55.000000000 +0000
-+++ test/tsan/lit.cfg
-@@ -79,8 +79,8 @@ config.substitutions.append( ("%deflake 
- # Default test suffixes.
- config.suffixes = ['.c', '.cc', '.cpp', '.m', '.mm']
- 
--# ThreadSanitizer tests are currently supported on FreeBSD, Linux and Darwin.
--if config.host_os not in ['FreeBSD', 'Linux', 'Darwin']:
-+# ThreadSanitizer tests are currently supported on FreeBSD, NetBSD, Linux and Darwin.
-+if config.host_os not in ['FreeBSD', 'Linux', 'Darwin', 'NetBSD']:
-   config.unsupported = True
- 
- # Allow tests to use REQUIRES=stable-runtime.  For use when you cannot use XFAIL
diff --git a/compiler-rt-netbsd/patches/patch-test_tsan_tls__race.cc b/compiler-rt-netbsd/patches/patch-test_tsan_tls__race.cc
deleted file mode 100644
index d3c4b74d9d..0000000000
--- a/compiler-rt-netbsd/patches/patch-test_tsan_tls__race.cc
+++ /dev/null
@@ -1,10 +0,0 @@
-$NetBSD$
-
---- test/tsan/tls_race.cc.orig	2017-06-03 23:53:55.000000000 +0000
-+++ test/tsan/tls_race.cc
-@@ -20,4 +20,5 @@ int main() {
- // CHECK: WARNING: ThreadSanitizer: data race
- // CHECK-Linux:   Location is TLS of main thread.
- // CHECK-FreeBSD:   Location is TLS of main thread.
-+// CHECK-NetBSD:   Location is TLS of main thread.
- // CHECK-Darwin:   Location is heap block of size 4
diff --git a/compiler-rt-netbsd/patches/patch-test_tsan_tls__race2.cc b/compiler-rt-netbsd/patches/patch-test_tsan_tls__race2.cc
deleted file mode 100644
index 96191826a5..0000000000
--- a/compiler-rt-netbsd/patches/patch-test_tsan_tls__race2.cc
+++ /dev/null
@@ -1,10 +0,0 @@
-$NetBSD$
-
---- test/tsan/tls_race2.cc.orig	2017-06-03 23:53:55.000000000 +0000
-+++ test/tsan/tls_race2.cc
-@@ -27,4 +27,5 @@ int main() {
- // CHECK: WARNING: ThreadSanitizer: data race
- // CHECK-Linux:   Location is TLS of thread T1.
- // CHECK-FreeBSD:   Location is TLS of thread T1.
-+// CHECK-NetBSD:   Location is TLS of thread T1.
- // CHECK-Darwin:   Location is heap block of size 4
diff --git a/compiler-rt-netbsd/patches/patch-test_ubsan_lit.common.cfg b/compiler-rt-netbsd/patches/patch-test_ubsan_lit.common.cfg
deleted file mode 100644
index f17988d9b8..0000000000
--- a/compiler-rt-netbsd/patches/patch-test_ubsan_lit.common.cfg
+++ /dev/null
@@ -1,13 +0,0 @@
-$NetBSD$
-
---- test/ubsan/lit.common.cfg.orig	2017-06-03 23:53:55.000000000 +0000
-+++ test/ubsan/lit.common.cfg
-@@ -70,7 +70,7 @@ config.substitutions.append( ("%gmlt ", 
- config.suffixes = ['.c', '.cc', '.cpp']
- 
- # Check that the host supports UndefinedBehaviorSanitizer tests
--if config.host_os not in ['Linux', 'Darwin', 'FreeBSD', 'Windows']:
-+if config.host_os not in ['Linux', 'Darwin', 'FreeBSD', 'NetBSD', 'Windows']:
-   config.unsupported = True
- 
- # Allow tests to use REQUIRES=stable-runtime.  For use when you cannot use XFAIL



Home | Main Index | Thread Index | Old Index