revert to previous base llvm-svn.349610

Change-Id: I08740d76c18c91e87f643871953c6feae0081289
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4697dba..d105daf 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -39,6 +39,8 @@
 mark_as_advanced(COMPILER_RT_BUILD_PROFILE)
 option(COMPILER_RT_BUILD_XRAY_NO_PREINIT "Build xray with no preinit patching" OFF)
 mark_as_advanced(COMPILER_RT_BUILD_XRAY_NO_PREINIT)
+option(COMPILER_RT_FUZZER_LINK_LIBCXX "Link a copy of libcxx into libfuzzer" ON)
+mark_as_advanced(COMPILER_RT_FUZZER_LINK_LIBCXX)
 
 set(COMPILER_RT_ASAN_SHADOW_SCALE ""
     CACHE STRING "Override the shadow scale to be used in ASan runtime")
diff --git a/lib/asan/asan_thread.cc b/lib/asan/asan_thread.cc
index b8d6f92..faf423d 100644
--- a/lib/asan/asan_thread.cc
+++ b/lib/asan/asan_thread.cc
@@ -223,11 +223,9 @@
   atomic_store(&stack_switching_, false, memory_order_release);
   CHECK_EQ(this->stack_size(), 0U);
   SetThreadStackAndTls(options);
-  if (stack_top_ != stack_bottom_) {
-    CHECK_GT(this->stack_size(), 0U);
-    CHECK(AddrIsInMem(stack_bottom_));
-    CHECK(AddrIsInMem(stack_top_ - 1));
-  }
+  CHECK_GT(this->stack_size(), 0U);
+  CHECK(AddrIsInMem(stack_bottom_));
+  CHECK(AddrIsInMem(stack_top_ - 1));
   ClearShadowForThreadStackAndTLS();
   fake_stack_ = nullptr;
   if (__asan_option_detect_stack_use_after_return)
@@ -297,17 +295,14 @@
   tls_end_ = tls_begin_ + tls_size;
   dtls_ = DTLS_Get();
 
-  if (stack_top_ != stack_bottom_) {
-    int local;
-    CHECK(AddrIsInStack((uptr)&local));
-  }
+  int local;
+  CHECK(AddrIsInStack((uptr)&local));
 }
 
 #endif  // !SANITIZER_FUCHSIA && !SANITIZER_RTEMS
 
 void AsanThread::ClearShadowForThreadStackAndTLS() {
-  if (stack_top_ != stack_bottom_)
-    PoisonShadow(stack_bottom_, stack_top_ - stack_bottom_, 0);
+  PoisonShadow(stack_bottom_, stack_top_ - stack_bottom_, 0);
   if (tls_begin_ != tls_end_) {
     uptr tls_begin_aligned = RoundDownTo(tls_begin_, SHADOW_GRANULARITY);
     uptr tls_end_aligned = RoundUpTo(tls_end_, SHADOW_GRANULARITY);
@@ -319,9 +314,6 @@
 
 bool AsanThread::GetStackFrameAccessByAddr(uptr addr,
                                            StackFrameAccess *access) {
-  if (stack_top_ == stack_bottom_)
-    return false;
-
   uptr bottom = 0;
   if (AddrIsInStack(addr)) {
     bottom = stack_bottom();
diff --git a/lib/builtins/CMakeLists.txt b/lib/builtins/CMakeLists.txt
index a58bd37..8233296 100644
--- a/lib/builtins/CMakeLists.txt
+++ b/lib/builtins/CMakeLists.txt
@@ -94,7 +94,6 @@
   floatunsisf.c
   floatuntidf.c
   floatuntisf.c
-  fp_mode.c
   int_util.c
   lshrdi3.c
   lshrti3.c
@@ -291,7 +290,6 @@
 set(i686_SOURCES ${i686_SOURCES} ${x86_ARCH_SOURCES})
 
 set(arm_SOURCES
-  arm/fp_mode.c
   arm/bswapdi2.S
   arm/bswapsi2.S
   arm/clzdi2.S
@@ -443,8 +441,7 @@
 
 set(aarch64_SOURCES
   ${GENERIC_TF_SOURCES}
-  ${GENERIC_SOURCES}
-  aarch64/fp_mode.c)
+  ${GENERIC_SOURCES})
 
 if (MINGW)
   set(aarch64_SOURCES
@@ -549,9 +546,7 @@
   if(COMPILER_RT_STANDALONE_BUILD)
     append_list_if(COMPILER_RT_HAS_FPIC_FLAG -fPIC BUILTIN_CFLAGS)
     append_list_if(COMPILER_RT_HAS_FNO_BUILTIN_FLAG -fno-builtin BUILTIN_CFLAGS)
-    if(NOT ANDROID)
-      append_list_if(COMPILER_RT_HAS_VISIBILITY_HIDDEN_FLAG -fvisibility=hidden BUILTIN_CFLAGS)
-    endif()
+    append_list_if(COMPILER_RT_HAS_VISIBILITY_HIDDEN_FLAG -fvisibility=hidden BUILTIN_CFLAGS)
     if(NOT COMPILER_RT_DEBUG)
       append_list_if(COMPILER_RT_HAS_OMIT_FRAME_POINTER_FLAG -fomit-frame-pointer BUILTIN_CFLAGS)
     endif()
@@ -559,9 +554,7 @@
 
   set(BUILTIN_DEFS "")
 
-  if(NOT ANDROID)
-    append_list_if(COMPILER_RT_HAS_VISIBILITY_HIDDEN_FLAG VISIBILITY_HIDDEN BUILTIN_DEFS)
-  endif()
+  append_list_if(COMPILER_RT_HAS_VISIBILITY_HIDDEN_FLAG VISIBILITY_HIDDEN BUILTIN_DEFS)
 
   foreach (arch ${BUILTIN_SUPPORTED_ARCH})
     if (CAN_TARGET_${arch})
diff --git a/lib/builtins/aarch64/fp_mode.c b/lib/builtins/aarch64/fp_mode.c
deleted file mode 100644
index aa81fbc..0000000
--- a/lib/builtins/aarch64/fp_mode.c
+++ /dev/null
@@ -1,53 +0,0 @@
-//===----- lib/aarch64/fp_mode.c - Floaing-point mode utilities ---*- C -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#include <stdint.h>
-
-#include "../fp_mode.h"
-
-#define AARCH64_TONEAREST  0x0
-#define AARCH64_UPWARD     0x1
-#define AARCH64_DOWNWARD   0x2
-#define AARCH64_TOWARDZERO 0x3
-#define AARCH64_RMODE_MASK (AARCH64_TONEAREST | AARCH64_UPWARD | \
-                            AARCH64_DOWNWARD | AARCH64_TOWARDZERO)
-#define AARCH64_RMODE_SHIFT 22
-
-#define AARCH64_INEXACT     0x10
-
-FE_ROUND_MODE __fe_getround() {
-#ifdef __ARM_FP
-  uint64_t fpcr;
-  __asm__ __volatile__("mrs  %0, fpcr" : "=r" (fpcr));
-  fpcr = fpcr >> AARCH64_RMODE_SHIFT & AARCH64_RMODE_MASK;
-  switch (fpcr) {
-    case AARCH64_UPWARD:
-      return FE_UPWARD;
-    case AARCH64_DOWNWARD:
-      return FE_DOWNWARD;
-    case AARCH64_TOWARDZERO:
-      return FE_TOWARDZERO;
-    case AARCH64_TONEAREST:
-    default:
-      return FE_TONEAREST;
-  }
-#else
-  return FE_TONEAREST;
-#endif
-}
-
-int __fe_raise_inexact() {
-#ifdef __ARM_FP
-  uint64_t fpsr;
-  __asm__ __volatile__("mrs  %0, fpsr" : "=r" (fpsr));
-  __asm__ __volatile__("msr  fpsr, %0" : : "ri" (fpsr | AARCH64_INEXACT));
-  return 0;
-#else
-  return 0;
-#endif
-}
diff --git a/lib/builtins/adddf3.c b/lib/builtins/adddf3.c
index f616192..9a39013 100644
--- a/lib/builtins/adddf3.c
+++ b/lib/builtins/adddf3.c
@@ -7,7 +7,8 @@
 //
 //===----------------------------------------------------------------------===//
 //
-// This file implements double-precision soft-float addition.
+// This file implements double-precision soft-float addition with the IEEE-754
+// default rounding (to nearest, ties to even).
 //
 //===----------------------------------------------------------------------===//
 
diff --git a/lib/builtins/addsf3.c b/lib/builtins/addsf3.c
index af92223..c5c1a41 100644
--- a/lib/builtins/addsf3.c
+++ b/lib/builtins/addsf3.c
@@ -7,7 +7,8 @@
 //
 //===----------------------------------------------------------------------===//
 //
-// This file implements single-precision soft-float addition.
+// This file implements single-precision soft-float addition with the IEEE-754
+// default rounding (to nearest, ties to even).
 //
 //===----------------------------------------------------------------------===//
 
diff --git a/lib/builtins/addtf3.c b/lib/builtins/addtf3.c
index 8e21da6..e4bbe02 100644
--- a/lib/builtins/addtf3.c
+++ b/lib/builtins/addtf3.c
@@ -7,7 +7,8 @@
 //
 //===----------------------------------------------------------------------===//
 //
-// This file implements quad-precision soft-float addition.
+// This file implements quad-precision soft-float addition with the IEEE-754
+// default rounding (to nearest, ties to even).
 //
 //===----------------------------------------------------------------------===//
 
diff --git a/lib/builtins/arm/fp_mode.c b/lib/builtins/arm/fp_mode.c
deleted file mode 100644
index 8fecee8..0000000
--- a/lib/builtins/arm/fp_mode.c
+++ /dev/null
@@ -1,53 +0,0 @@
-//===----- lib/arm/fp_mode.c - Floaing-point mode utilities -------*- C -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#include <stdint.h>
-
-#include "../fp_mode.h"
-
-#define ARM_TONEAREST  0x0
-#define ARM_UPWARD     0x1
-#define ARM_DOWNWARD   0x2
-#define ARM_TOWARDZERO 0x3
-#define ARM_RMODE_MASK (ARM_TONEAREST | ARM_UPWARD | \
-                        ARM_DOWNWARD | ARM_TOWARDZERO)
-#define ARM_RMODE_SHIFT 22
-
-#define ARM_INEXACT     0x1000
-
-FE_ROUND_MODE __fe_getround() {
-#ifdef __ARM_FP
-  uint32_t fpscr;
-  __asm__ __volatile__("vmrs  %0, fpscr" : "=r" (fpscr));
-  fpscr = fpscr >> ARM_RMODE_SHIFT & ARM_RMODE_MASK;
-  switch (fpscr) {
-    case ARM_UPWARD:
-      return FE_UPWARD;
-    case ARM_DOWNWARD:
-      return FE_DOWNWARD;
-    case ARM_TOWARDZERO:
-      return FE_TOWARDZERO;
-    case ARM_TONEAREST:
-    default:
-      return FE_TONEAREST;
-  }
-#else
-  return FE_TONEAREST;
-#endif
-}
-
-int __fe_raise_inexact() {
-#ifdef __ARM_FP
-  uint32_t fpscr;
-  __asm__ __volatile__("vmrs  %0, fpscr" : "=r" (fpscr));
-  __asm__ __volatile__("vmsr  fpscr, %0" : : "ri" (fpscr | ARM_INEXACT));
-  return 0;
-#else
-  return 0;
-#endif
-}
diff --git a/lib/builtins/fp_add_impl.inc b/lib/builtins/fp_add_impl.inc
index 5d006dc..b47be1b 100644
--- a/lib/builtins/fp_add_impl.inc
+++ b/lib/builtins/fp_add_impl.inc
@@ -13,7 +13,6 @@
 //===----------------------------------------------------------------------===//
 
 #include "fp_lib.h"
-#include "fp_mode.h"
 
 static __inline fp_t __addXf3__(fp_t a, fp_t b) {
     rep_t aRep = toRep(a);
@@ -139,21 +138,7 @@
 
     // Final rounding.  The result may overflow to infinity, but that is the
     // correct result in that case.
-    switch (__fe_getround()){
-    case FE_TONEAREST:
-      if (roundGuardSticky > 0x4) result++;
-      if (roundGuardSticky == 0x4) result += result & 1;
-      break;
-    case FE_DOWNWARD:
-      if (resultSign && roundGuardSticky) result++;
-      break;
-    case FE_UPWARD:
-      if (!resultSign && roundGuardSticky) result++;
-      break;
-    case FE_TOWARDZERO:
-      break;
-    }
-    if (roundGuardSticky)
-      __fe_raise_inexact();
+    if (roundGuardSticky > 0x4) result++;
+    if (roundGuardSticky == 0x4) result += result & 1;
     return fromRep(result);
 }
diff --git a/lib/builtins/fp_mode.c b/lib/builtins/fp_mode.c
deleted file mode 100644
index 9b82830..0000000
--- a/lib/builtins/fp_mode.c
+++ /dev/null
@@ -1,24 +0,0 @@
-//===----- lib/fp_mode.c - Floaing-point environment mode utilities --C -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// This file provides a default implementaion of fp_mode.h for architectures
-// that does not support or does not have an implementation of floating point
-// environment mode.
-//
-//===----------------------------------------------------------------------===//
-
-#include "fp_mode.h"
-
-// IEEE-754 default rounding (to nearest, ties to even).
-FE_ROUND_MODE __fe_getround() {
-  return FE_TONEAREST;
-}
-
-int __fe_raise_inexact() {
-  return 0;
-}
diff --git a/lib/builtins/fp_mode.h b/lib/builtins/fp_mode.h
deleted file mode 100644
index 51bec04..0000000
--- a/lib/builtins/fp_mode.h
+++ /dev/null
@@ -1,29 +0,0 @@
-//===----- lib/fp_mode.h - Floaing-point environment mode utilities --C -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// This file is not part of the interface of this library.
-//
-// This file defines an interface for accessing hardware floating point
-// environment mode.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef FP_MODE
-#define FP_MODE
-
-typedef enum {
-  FE_TONEAREST,
-  FE_DOWNWARD,
-  FE_UPWARD,
-  FE_TOWARDZERO
-} FE_ROUND_MODE;
-
-FE_ROUND_MODE __fe_getround();
-int __fe_raise_inexact();
-
-#endif // FP_MODE_H
diff --git a/lib/builtins/subdf3.c b/lib/builtins/subdf3.c
index 72b3b1a..a892fa6 100644
--- a/lib/builtins/subdf3.c
+++ b/lib/builtins/subdf3.c
@@ -7,7 +7,8 @@
 //
 //===----------------------------------------------------------------------===//
 //
-// This file implements double-precision soft-float subtraction.
+// This file implements double-precision soft-float subtraction with the
+// IEEE-754 default rounding (to nearest, ties to even).
 //
 //===----------------------------------------------------------------------===//
 
diff --git a/lib/builtins/subsf3.c b/lib/builtins/subsf3.c
index 9974f21..4b27861 100644
--- a/lib/builtins/subsf3.c
+++ b/lib/builtins/subsf3.c
@@ -7,7 +7,8 @@
 //
 //===----------------------------------------------------------------------===//
 //
-// This file implements single-precision soft-float subtraction.
+// This file implements single-precision soft-float subtraction with the
+// IEEE-754 default rounding (to nearest, ties to even).
 //
 //===----------------------------------------------------------------------===//
 
diff --git a/lib/builtins/subtf3.c b/lib/builtins/subtf3.c
index 22871cb..609b816 100644
--- a/lib/builtins/subtf3.c
+++ b/lib/builtins/subtf3.c
@@ -7,7 +7,8 @@
 //
 //===----------------------------------------------------------------------===//
 //
-// This file implements quad-precision soft-float subtraction.
+// This file implements quad-precision soft-float subtraction with the
+// IEEE-754 default rounding (to nearest, ties to even).
 //
 //===----------------------------------------------------------------------===//
 
diff --git a/lib/fuzzer/CMakeLists.txt b/lib/fuzzer/CMakeLists.txt
index 8ba3f8a..5002dfc 100644
--- a/lib/fuzzer/CMakeLists.txt
+++ b/lib/fuzzer/CMakeLists.txt
@@ -55,7 +55,7 @@
 
 set(LIBFUZZER_CFLAGS ${SANITIZER_COMMON_CFLAGS})
 
-if(OS_NAME MATCHES "Linux|Fuchsia" AND COMPILER_RT_LIBCXX_PATH)
+if(OS_NAME MATCHES "Linux|Fuchsia" AND COMPILER_RT_LIBCXX_PATH AND COMPILER_RT_FUZZER_LINK_LIBCXX)
   list(APPEND LIBFUZZER_CFLAGS -nostdinc++ -D_LIBCPP_ABI_VERSION=Fuzzer)
   # Remove -stdlib= which is unused when passing -nostdinc++.
   string(REGEX REPLACE "-stdlib=[a-zA-Z+]*" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
@@ -106,7 +106,7 @@
   CFLAGS ${LIBFUZZER_CFLAGS}
   PARENT_TARGET fuzzer)
 
-if(OS_NAME MATCHES "Linux|Fuchsia" AND COMPILER_RT_LIBCXX_PATH)
+if(OS_NAME MATCHES "Linux|Fuchsia" AND COMPILER_RT_LIBCXX_PATH AND COMPILER_RT_FUZZER_LINK_LIBCXX)
   macro(partially_link_libcxx name dir arch)
     set(cxx_${arch}_merge_dir "${CMAKE_CURRENT_BINARY_DIR}/cxx_${arch}_merge.dir")
     file(MAKE_DIRECTORY ${cxx_${arch}_merge_dir})
diff --git a/lib/hwasan/hwasan.cc b/lib/hwasan/hwasan.cc
index 0980c6d..9f2328d 100644
--- a/lib/hwasan/hwasan.cc
+++ b/lib/hwasan/hwasan.cc
@@ -88,8 +88,6 @@
     cf.check_printf = false;
     cf.intercept_tls_get_addr = true;
     cf.exitcode = 99;
-    // 8 shadow pages ~512kB, small enough to cover common stack sizes.
-    cf.clear_shadow_mmap_threshold = 4096 * (SANITIZER_ANDROID ? 2 : 8);
     // Sigtrap is used in error reporting.
     cf.handle_sigtrap = kHandleSignalExclusive;
 
diff --git a/lib/hwasan/hwasan_allocator.h b/lib/hwasan/hwasan_allocator.h
index 785a806..b3f2d6c 100644
--- a/lib/hwasan/hwasan_allocator.h
+++ b/lib/hwasan/hwasan_allocator.h
@@ -45,22 +45,28 @@
 };
 
 static const uptr kMaxAllowedMallocSize = 2UL << 30;  // 2G
+static const uptr kRegionSizeLog = 20;
+static const uptr kNumRegions = SANITIZER_MMAP_RANGE_SIZE >> kRegionSizeLog;
+typedef TwoLevelByteMap<(kNumRegions >> 12), 1 << 12> ByteMap;
 
-struct AP64 {
-  static const uptr kSpaceBeg = ~0ULL;
-  static const uptr kSpaceSize = 0x2000000000ULL;
+struct AP32 {
+  static const uptr kSpaceBeg = 0;
+  static const u64 kSpaceSize = SANITIZER_MMAP_RANGE_SIZE;
   static const uptr kMetadataSize = sizeof(Metadata);
-  typedef __sanitizer::VeryDenseSizeClassMap SizeClassMap;
+  typedef __sanitizer::CompactSizeClassMap SizeClassMap;
+  static const uptr kRegionSizeLog = __hwasan::kRegionSizeLog;
   using AddressSpaceView = LocalAddressSpaceView;
+  using ByteMap = __hwasan::ByteMap;
   typedef HwasanMapUnmapCallback MapUnmapCallback;
   static const uptr kFlags = 0;
 };
-typedef SizeClassAllocator64<AP64> PrimaryAllocator;
+typedef SizeClassAllocator32<AP32> PrimaryAllocator;
 typedef SizeClassAllocatorLocalCache<PrimaryAllocator> AllocatorCache;
 typedef LargeMmapAllocator<HwasanMapUnmapCallback> SecondaryAllocator;
 typedef CombinedAllocator<PrimaryAllocator, AllocatorCache,
                           SecondaryAllocator> Allocator;
 
+
 void AllocatorSwallowThreadLocalCache(AllocatorCache *cache);
 
 class HwasanChunkView {
diff --git a/lib/hwasan/hwasan_linux.cc b/lib/hwasan/hwasan_linux.cc
index 4b1b618..af9378c 100644
--- a/lib/hwasan/hwasan_linux.cc
+++ b/lib/hwasan/hwasan_linux.cc
@@ -363,27 +363,22 @@
   return AccessInfo{addr, size, is_store, !is_store, recover};
 }
 
-static void HandleTagMismatch(AccessInfo ai, uptr pc, uptr frame,
-                              ucontext_t *uc) {
-  InternalMmapVector<BufferedStackTrace> stack_buffer(1);
-  BufferedStackTrace *stack = stack_buffer.data();
-  stack->Reset();
-  GetStackTrace(stack, kStackTraceMax, pc, frame, uc,
-                common_flags()->fast_unwind_on_fatal);
-
-  ++hwasan_report_count;
-
-  bool fatal = flags()->halt_on_error || !ai.recover;
-  ReportTagMismatch(stack, ai.addr, ai.size, ai.is_store, fatal);
-}
-
 static bool HwasanOnSIGTRAP(int signo, siginfo_t *info, ucontext_t *uc) {
   AccessInfo ai = GetAccessInfo(info, uc);
   if (!ai.is_store && !ai.is_load)
     return false;
 
+  InternalMmapVector<BufferedStackTrace> stack_buffer(1);
+  BufferedStackTrace *stack = stack_buffer.data();
+  stack->Reset();
   SignalContext sig{info, uc};
-  HandleTagMismatch(ai, StackTrace::GetNextInstructionPc(sig.pc), sig.bp, uc);
+  GetStackTrace(stack, kStackTraceMax, StackTrace::GetNextInstructionPc(sig.pc),
+                sig.bp, uc, common_flags()->fast_unwind_on_fatal);
+
+  ++hwasan_report_count;
+
+  bool fatal = flags()->halt_on_error || !ai.recover;
+  ReportTagMismatch(stack, ai.addr, ai.size, ai.is_store, fatal);
 
 #if defined(__aarch64__)
   uc->uc_mcontext.pc += 4;
@@ -394,19 +389,6 @@
   return true;
 }
 
-extern "C" SANITIZER_INTERFACE_ATTRIBUTE void __hwasan_tag_mismatch(
-    uptr addr, uptr access_info) {
-  AccessInfo ai;
-  ai.is_store = access_info & 0x10;
-  ai.recover = false;
-  ai.addr = addr;
-  ai.size = 1 << (access_info & 0xf);
-
-  HandleTagMismatch(ai, (uptr)__builtin_return_address(0),
-                    (uptr)__builtin_frame_address(0), nullptr);
-  __builtin_unreachable();
-}
-
 static void OnStackUnwind(const SignalContext &sig, const void *,
                           BufferedStackTrace *stack) {
   GetStackTrace(stack, kStackTraceMax, StackTrace::GetNextInstructionPc(sig.pc),
diff --git a/lib/hwasan/hwasan_poisoning.cc b/lib/hwasan/hwasan_poisoning.cc
index 6fb7d15..9c8e16b 100644
--- a/lib/hwasan/hwasan_poisoning.cc
+++ b/lib/hwasan/hwasan_poisoning.cc
@@ -16,7 +16,6 @@
 #include "hwasan_mapping.h"
 #include "interception/interception.h"
 #include "sanitizer_common/sanitizer_common.h"
-#include "sanitizer_common/sanitizer_linux.h"
 
 namespace __hwasan {
 
@@ -25,22 +24,7 @@
   CHECK(IsAligned(size, kShadowAlignment));
   uptr shadow_start = MemToShadow(p);
   uptr shadow_size = MemToShadowSize(size);
-
-  uptr page_size = GetPageSizeCached();
-  uptr page_start = RoundUpTo(shadow_start, page_size);
-  uptr page_end = RoundDownTo(shadow_start + shadow_size, page_size);
-  uptr threshold = common_flags()->clear_shadow_mmap_threshold;
-  if (SANITIZER_LINUX &&
-      UNLIKELY(page_end >= page_start + threshold && tag == 0)) {
-    internal_memset((void *)shadow_start, tag, page_start - shadow_start);
-    internal_memset((void *)page_end, tag,
-                    shadow_start + shadow_size - page_end);
-    // For an anonymous private mapping MADV_DONTNEED will return a zero page on
-    // Linux.
-    ReleaseMemoryPagesToOSAndZeroFill(page_start, page_end);
-  } else {
-    internal_memset((void *)shadow_start, tag, shadow_size);
-  }
+  internal_memset((void *)shadow_start, tag, shadow_size);
   return AddTagToPointer(p, tag);
 }
 
diff --git a/lib/hwasan/hwasan_thread.cc b/lib/hwasan/hwasan_thread.cc
index 631c281..0d15c7e 100644
--- a/lib/hwasan/hwasan_thread.cc
+++ b/lib/hwasan/hwasan_thread.cc
@@ -43,18 +43,27 @@
   // ScopedTaggingDisable needs GetCurrentThread to be set up.
   ScopedTaggingDisabler disabler;
 
-  uptr tls_size;
-  uptr stack_size;
-  GetThreadStackAndTls(IsMainThread(), &stack_bottom_, &stack_size, &tls_begin_,
-                       &tls_size);
-  stack_top_ = stack_bottom_ + stack_size;
-  tls_end_ = tls_begin_ + tls_size;
+  // If this process is "init" (pid 1), /proc may not be mounted yet.
+  if (IsMainThread() && !FileExists("/proc/self/maps")) {
+    stack_top_ = stack_bottom_ = 0;
+    tls_begin_ = tls_end_ = 0;
+  } else {
+    uptr tls_size;
+    uptr stack_size;
+    GetThreadStackAndTls(IsMainThread(), &stack_bottom_, &stack_size,
+                         &tls_begin_, &tls_size);
+    stack_top_ = stack_bottom_ + stack_size;
+    tls_end_ = tls_begin_ + tls_size;
 
-  if (stack_bottom_) {
     int local;
     CHECK(AddrIsInStack((uptr)&local));
     CHECK(MemIsApp(stack_bottom_));
     CHECK(MemIsApp(stack_top_ - 1));
+
+    if (stack_bottom_) {
+      CHECK(MemIsApp(stack_bottom_));
+      CHECK(MemIsApp(stack_top_ - 1));
+    }
   }
 
   if (flags()->verbose_threads) {
diff --git a/lib/sanitizer_common/sanitizer_allocator_combined.h b/lib/sanitizer_common/sanitizer_allocator_combined.h
index 3262347..1f874d6 100644
--- a/lib/sanitizer_common/sanitizer_allocator_combined.h
+++ b/lib/sanitizer_common/sanitizer_allocator_combined.h
@@ -25,15 +25,15 @@
 class CombinedAllocator {
  public:
   void InitLinkerInitialized(s32 release_to_os_interval_ms) {
-    stats_.InitLinkerInitialized();
     primary_.Init(release_to_os_interval_ms);
     secondary_.InitLinkerInitialized();
+    stats_.InitLinkerInitialized();
   }
 
   void Init(s32 release_to_os_interval_ms) {
-    stats_.Init();
     primary_.Init(release_to_os_interval_ms);
     secondary_.Init();
+    stats_.Init();
   }
 
   void *Allocate(AllocatorCache *cache, uptr size, uptr alignment) {
diff --git a/lib/sanitizer_common/sanitizer_allocator_size_class_map.h b/lib/sanitizer_common/sanitizer_allocator_size_class_map.h
index 1c05fb8..0795842 100644
--- a/lib/sanitizer_common/sanitizer_allocator_size_class_map.h
+++ b/lib/sanitizer_common/sanitizer_allocator_size_class_map.h
@@ -237,6 +237,3 @@
 // allowing for denser per-class arrays, smaller memory footprint and usually
 // better performances in threaded environments.
 typedef SizeClassMap<3, 4, 8, 17, 8, 10> DenseSizeClassMap;
-// Similar to VeryCompact map above, this one has a small number of different
-// size classes, and also reduced thread-local caches.
-typedef SizeClassMap<2, 5, 9, 16, 8, 10> VeryDenseSizeClassMap;
diff --git a/lib/sanitizer_common/sanitizer_flags.inc b/lib/sanitizer_common/sanitizer_flags.inc
index b047741..8e0d724 100644
--- a/lib/sanitizer_common/sanitizer_flags.inc
+++ b/lib/sanitizer_common/sanitizer_flags.inc
@@ -243,6 +243,3 @@
 COMMON_FLAG(bool, detect_write_exec, false,
           "If true, triggers warning when writable-executable pages requests "
           "are being made")
-COMMON_FLAG(bool, test_only_emulate_no_memorymap, false,
-            "TEST ONLY fail to read memory mappings to emulate sanitized "
-            "\"init\"")
diff --git a/lib/sanitizer_common/sanitizer_linux.cc b/lib/sanitizer_common/sanitizer_linux.cc
index d26925f..6cfb615 100644
--- a/lib/sanitizer_common/sanitizer_linux.cc
+++ b/lib/sanitizer_common/sanitizer_linux.cc
@@ -381,10 +381,6 @@
   return (uptr)st.st_size;
 }
 
-uptr internal_dup(int oldfd) {
-  return internal_syscall(SYSCALL(dup), oldfd);
-}
-
 uptr internal_dup2(int oldfd, int newfd) {
 #if SANITIZER_USES_CANONICAL_LINUX_SYSCALLS
   return internal_syscall(SYSCALL(dup3), oldfd, newfd, 0);
@@ -453,8 +449,6 @@
 
 // ----------------- sanitizer_common.h
 bool FileExists(const char *filename) {
-  if (ShouldMockFailureToOpen(filename))
-    return false;
   struct stat st;
 #if SANITIZER_USES_CANONICAL_LINUX_SYSCALLS
   if (internal_syscall(SYSCALL(newfstatat), AT_FDCWD, filename, &st, 0))
@@ -1010,8 +1004,6 @@
   // Firstly check if there are writable segments
   // mapped to top gigabyte (e.g. stack).
   MemoryMappingLayout proc_maps(/*cache_enabled*/true);
-  if (proc_maps.Error())
-    return 0;
   MemoryMappedSegment segment;
   while (proc_maps.Next(&segment)) {
     if ((segment.end >= 3 * gbyte) && segment.IsWritable()) return 0;
diff --git a/lib/sanitizer_common/sanitizer_linux.h b/lib/sanitizer_common/sanitizer_linux.h
index 522eb09..6f5387e 100644
--- a/lib/sanitizer_common/sanitizer_linux.h
+++ b/lib/sanitizer_common/sanitizer_linux.h
@@ -106,17 +106,6 @@
 // Call cb for each region mapped by map.
 void ForEachMappedRegion(link_map *map, void (*cb)(const void *, uptr));
 
-// Releases memory pages entirely within the [beg, end] address range.
-// The pages no longer count toward RSS; reads are guaranteed to return 0.
-// Requires (but does not verify!) that pages are MAP_PRIVATE.
-INLINE void ReleaseMemoryPagesToOSAndZeroFill(uptr beg, uptr end) {
-  // man madvise on Linux promises zero-fill for anonymous private pages.
-  // Testing shows the same behaviour for private (but not anonymous) mappings
-  // of shm_open() files, as long as the underlying file is untouched.
-  CHECK(SANITIZER_LINUX);
-  ReleaseMemoryPagesToOS(beg, end);
-}
-
 #if SANITIZER_ANDROID
 
 #if defined(__aarch64__)
@@ -145,13 +134,13 @@
 #error "Unsupported architecture."
 #endif
 
-// The Android Bionic team has allocated a TLS slot for sanitizers starting
-// with Q, given that Android currently doesn't support ELF TLS. It is used to
-// store sanitizer thread specific data.
-static const int TLS_SLOT_SANITIZER = 6;
+// The Android Bionic team has allocated a TLS slot for TSan starting with N,
+// given that Android currently doesn't support ELF TLS. It is used to store
+// Sanitizers thread specific data.
+static const int TLS_SLOT_TSAN = 8;
 
 ALWAYS_INLINE uptr *get_android_tls_ptr() {
-  return reinterpret_cast<uptr *>(&__get_tls()[TLS_SLOT_SANITIZER]);
+  return reinterpret_cast<uptr *>(&__get_tls()[TLS_SLOT_TSAN]);
 }
 
 #endif  // SANITIZER_ANDROID
diff --git a/lib/sanitizer_common/sanitizer_linux_libcdep.cc b/lib/sanitizer_common/sanitizer_linux_libcdep.cc
index 6ce47ec..84da23e 100644
--- a/lib/sanitizer_common/sanitizer_linux_libcdep.cc
+++ b/lib/sanitizer_common/sanitizer_linux_libcdep.cc
@@ -100,10 +100,6 @@
 
     // Find the mapping that contains a stack variable.
     MemoryMappingLayout proc_maps(/*cache_enabled*/true);
-    if (proc_maps.Error()) {
-      *stack_top = *stack_bottom = 0;
-      return;
-    }
     MemoryMappedSegment segment;
     uptr prev_end = 0;
     while (proc_maps.Next(&segment)) {
diff --git a/lib/sanitizer_common/sanitizer_mac.cc b/lib/sanitizer_common/sanitizer_mac.cc
index 0828849..95c47ba 100644
--- a/lib/sanitizer_common/sanitizer_mac.cc
+++ b/lib/sanitizer_common/sanitizer_mac.cc
@@ -174,10 +174,6 @@
   return (uptr)st.st_size;
 }
 
-uptr internal_dup(int oldfd) {
-  return dup(oldfd);
-}
-
 uptr internal_dup2(int oldfd, int newfd) {
   return dup2(oldfd, newfd);
 }
@@ -282,8 +278,6 @@
 
 // ----------------- sanitizer_common.h
 bool FileExists(const char *filename) {
-  if (ShouldMockFailureToOpen(filename))
-    return false;
   struct stat st;
   if (stat(filename, &st))
     return false;
diff --git a/lib/sanitizer_common/sanitizer_netbsd.cc b/lib/sanitizer_common/sanitizer_netbsd.cc
index 80d0855..cdf552c 100644
--- a/lib/sanitizer_common/sanitizer_netbsd.cc
+++ b/lib/sanitizer_common/sanitizer_netbsd.cc
@@ -169,11 +169,6 @@
   return (uptr)st.st_size;
 }
 
-uptr internal_dup(int oldfd) {
-  DEFINE__REAL(int, dup, int a);
-  return _REAL(dup, oldfd);
-}
-
 uptr internal_dup2(int oldfd, int newfd) {
   DEFINE__REAL(int, dup2, int a, int b);
   return _REAL(dup2, oldfd, newfd);
diff --git a/lib/sanitizer_common/sanitizer_posix.cc b/lib/sanitizer_common/sanitizer_posix.cc
index 940c199..116270f 100644
--- a/lib/sanitizer_common/sanitizer_posix.cc
+++ b/lib/sanitizer_common/sanitizer_posix.cc
@@ -18,7 +18,6 @@
 
 #include "sanitizer_common.h"
 #include "sanitizer_file.h"
-#include "sanitizer_flags.h"
 #include "sanitizer_libc.h"
 #include "sanitizer_posix.h"
 #include "sanitizer_procmaps.h"
@@ -158,8 +157,6 @@
 #endif
 
 fd_t OpenFile(const char *filename, FileAccessMode mode, error_t *errno_p) {
-  if (ShouldMockFailureToOpen(filename))
-    return kInvalidFd;
   int flags;
   switch (mode) {
     case RdOnly: flags = O_RDONLY; break;
@@ -169,7 +166,7 @@
   fd_t res = internal_open(filename, flags, 0660);
   if (internal_iserror(res, errno_p))
     return kInvalidFd;
-  return ReserveStandardFds(res);
+  return res;
 }
 
 void CloseFile(fd_t fd) {
@@ -233,8 +230,6 @@
 // memory).
 bool MemoryRangeIsAvailable(uptr range_start, uptr range_end) {
   MemoryMappingLayout proc_maps(/*cache_enabled*/true);
-  if (proc_maps.Error())
-    return true; // and hope for the best
   MemoryMappedSegment segment;
   while (proc_maps.Next(&segment)) {
     if (segment.start == segment.end) continue;  // Empty range.
@@ -274,8 +269,13 @@
 
 void ReportFile::Write(const char *buffer, uptr length) {
   SpinMutexLock l(mu);
+  static const char *kWriteError =
+      "ReportFile::Write() can't output requested buffer!\n";
   ReopenIfNecessary();
-  internal_write(fd, buffer, length);
+  if (length != internal_write(fd, buffer, length)) {
+    internal_write(fd, kWriteError, internal_strlen(kWriteError));
+    Die();
+  }
 }
 
 bool GetCodeRangeForFile(const char *module, uptr *start, uptr *end) {
@@ -323,26 +323,6 @@
   return "UNKNOWN SIGNAL";
 }
 
-fd_t ReserveStandardFds(fd_t fd) {
-  CHECK_GE(fd, 0);
-  if (fd > 2)
-    return fd;
-  bool used[3] = {false, false, false};
-  while (fd <= 2) {
-    used[fd] = true;
-    fd = internal_dup(fd);
-  }
-  for (int i = 0; i <= 2; ++i)
-    if (used[i])
-      internal_close(i);
-  return fd;
-}
-
-bool ShouldMockFailureToOpen(const char *path) {
-  return common_flags()->test_only_emulate_no_memorymap &&
-         internal_strncmp(path, "/proc/", 6) == 0;
-}
-
 } // namespace __sanitizer
 
 #endif // SANITIZER_POSIX
diff --git a/lib/sanitizer_common/sanitizer_posix.h b/lib/sanitizer_common/sanitizer_posix.h
index 04a7644..2ebfae8 100644
--- a/lib/sanitizer_common/sanitizer_posix.h
+++ b/lib/sanitizer_common/sanitizer_posix.h
@@ -49,7 +49,6 @@
 uptr internal_stat(const char *path, void *buf);
 uptr internal_lstat(const char *path, void *buf);
 uptr internal_fstat(fd_t fd, void *buf);
-uptr internal_dup(int oldfd);
 uptr internal_dup2(int oldfd, int newfd);
 uptr internal_readlink(const char *path, char *buf, uptr bufsize);
 uptr internal_unlink(const char *path);
@@ -100,11 +99,6 @@
 
 bool IsStateDetached(int state);
 
-// Move the fd out of {0, 1, 2} range.
-fd_t ReserveStandardFds(fd_t fd);
-
-bool ShouldMockFailureToOpen(const char *path);
-
 }  // namespace __sanitizer
 
 #endif  // SANITIZER_POSIX_H
diff --git a/lib/sanitizer_common/sanitizer_procmaps.h b/lib/sanitizer_common/sanitizer_procmaps.h
index acb7104..9fde040 100644
--- a/lib/sanitizer_common/sanitizer_procmaps.h
+++ b/lib/sanitizer_common/sanitizer_procmaps.h
@@ -70,7 +70,6 @@
   explicit MemoryMappingLayout(bool cache_enabled);
   ~MemoryMappingLayout();
   bool Next(MemoryMappedSegment *segment);
-  bool Error() const;
   void Reset();
   // In some cases, e.g. when running under a sandbox on Linux, ASan is unable
   // to obtain the memory mappings. It should fall back to pre-cached data
diff --git a/lib/sanitizer_common/sanitizer_procmaps_bsd.cc b/lib/sanitizer_common/sanitizer_procmaps_bsd.cc
index 362a424..4cebd98 100644
--- a/lib/sanitizer_common/sanitizer_procmaps_bsd.cc
+++ b/lib/sanitizer_common/sanitizer_procmaps_bsd.cc
@@ -99,7 +99,6 @@
 }
 
 bool MemoryMappingLayout::Next(MemoryMappedSegment *segment) {
-  CHECK(!Error()); // can not fail
   char *last = data_.proc_self_maps.data + data_.proc_self_maps.len;
   if (data_.current >= last)
     return false;
diff --git a/lib/sanitizer_common/sanitizer_procmaps_common.cc b/lib/sanitizer_common/sanitizer_procmaps_common.cc
index 17d61b6..1f2b431 100644
--- a/lib/sanitizer_common/sanitizer_procmaps_common.cc
+++ b/lib/sanitizer_common/sanitizer_procmaps_common.cc
@@ -80,14 +80,12 @@
   ReadProcMaps(&data_.proc_self_maps);
   if (cache_enabled && data_.proc_self_maps.mmaped_size == 0)
     LoadFromCache();
+  CHECK_GT(data_.proc_self_maps.mmaped_size, 0);
+  CHECK_GT(data_.proc_self_maps.len, 0);
 
   Reset();
 }
 
-bool MemoryMappingLayout::Error() const {
-  return data_.current == nullptr;
-}
-
 MemoryMappingLayout::~MemoryMappingLayout() {
   // Only unmap the buffer if it is different from the cached one. Otherwise
   // it will be unmapped when the cache is refreshed.
diff --git a/lib/sanitizer_common/sanitizer_procmaps_linux.cc b/lib/sanitizer_common/sanitizer_procmaps_linux.cc
index cf9cb25..633e939 100644
--- a/lib/sanitizer_common/sanitizer_procmaps_linux.cc
+++ b/lib/sanitizer_common/sanitizer_procmaps_linux.cc
@@ -31,7 +31,6 @@
 }
 
 bool MemoryMappingLayout::Next(MemoryMappedSegment *segment) {
-  if (Error()) return false; // simulate empty maps
   char *last = data_.proc_self_maps.data + data_.proc_self_maps.len;
   if (data_.current >= last) return false;
   char *next_line =
diff --git a/lib/sanitizer_common/sanitizer_procmaps_mac.cc b/lib/sanitizer_common/sanitizer_procmaps_mac.cc
index 267c960..d90e4b9 100644
--- a/lib/sanitizer_common/sanitizer_procmaps_mac.cc
+++ b/lib/sanitizer_common/sanitizer_procmaps_mac.cc
@@ -88,10 +88,6 @@
 MemoryMappingLayout::~MemoryMappingLayout() {
 }
 
-bool MemoryMappingLayout::Error() const {
-  return false;
-}
-
 // More information about Mach-O headers can be found in mach-o/loader.h
 // Each Mach-O image has a header (mach_header or mach_header_64) starting with
 // a magic number, and a list of linker load commands directly following the
diff --git a/lib/sanitizer_common/sanitizer_procmaps_solaris.cc b/lib/sanitizer_common/sanitizer_procmaps_solaris.cc
index 49bb46c..9e5e37e 100644
--- a/lib/sanitizer_common/sanitizer_procmaps_solaris.cc
+++ b/lib/sanitizer_common/sanitizer_procmaps_solaris.cc
@@ -21,16 +21,11 @@
 namespace __sanitizer {
 
 void ReadProcMaps(ProcSelfMapsBuff *proc_maps) {
-  if (!ReadFileToBuffer("/proc/self/xmap", &proc_maps->data,
-                        &proc_maps->mmaped_size, &proc_maps->len)) {
-    proc_maps->data = nullptr;
-    proc_maps->mmaped_size = 0;
-    proc_maps->len = 0;
-  }
+  ReadFileToBuffer("/proc/self/xmap", &proc_maps->data, &proc_maps->mmaped_size,
+                   &proc_maps->len);
 }
 
 bool MemoryMappingLayout::Next(MemoryMappedSegment *segment) {
-  if (Error()) return false; // simulate empty maps
   char *last = data_.proc_self_maps.data + data_.proc_self_maps.len;
   if (data_.current >= last) return false;
 
diff --git a/lib/sanitizer_common/sanitizer_solaris.cc b/lib/sanitizer_common/sanitizer_solaris.cc
index cc0201c..9d0c3d9 100644
--- a/lib/sanitizer_common/sanitizer_solaris.cc
+++ b/lib/sanitizer_common/sanitizer_solaris.cc
@@ -88,8 +88,8 @@
 }
 
 uptr OpenFile(const char *filename, bool write) {
-  return ReserveStandardFds(
-      internal_open(filename, write ? O_WRONLY | O_CREAT : O_RDONLY, 0660));
+  return internal_open(filename,
+      write ? O_WRONLY | O_CREAT : O_RDONLY, 0660);
 }
 
 DECLARE__REAL_AND_INTERNAL(uptr, read, fd_t fd, void *buf, uptr count) {
diff --git a/lib/sanitizer_common/sanitizer_stackdepot.cc b/lib/sanitizer_common/sanitizer_stackdepot.cc
index 6aab984..3bd5b67 100644
--- a/lib/sanitizer_common/sanitizer_stackdepot.cc
+++ b/lib/sanitizer_common/sanitizer_stackdepot.cc
@@ -26,7 +26,7 @@
   u32 tag;
   uptr stack[1];  // [size]
 
-  static const u32 kTabSizeLog = SANITIZER_ANDROID ? 16 : 20;
+  static const u32 kTabSizeLog = 20;
   // Lower kTabSizeLog bits are equal for all items in one bucket.
   // We use these bits to store the per-stack use counter.
   static const u32 kUseCountBits = kTabSizeLog;
diff --git a/lib/sanitizer_common/sanitizer_stackdepot.h b/lib/sanitizer_common/sanitizer_stackdepot.h
index e22ed2e..cb73450 100644
--- a/lib/sanitizer_common/sanitizer_stackdepot.h
+++ b/lib/sanitizer_common/sanitizer_stackdepot.h
@@ -32,7 +32,7 @@
   void inc_use_count_unsafe();
 };
 
-const int kStackDepotMaxUseCount = 1U << (SANITIZER_ANDROID ? 16 : 20);
+const int kStackDepotMaxUseCount = 1U << 20;
 
 StackDepotStats *StackDepotGetStats();
 u32 StackDepotPut(StackTrace stack);
diff --git a/lib/scudo/scudo_allocator.cpp b/lib/scudo/scudo_allocator.cpp
index ca2441c..fb04fb2 100644
--- a/lib/scudo/scudo_allocator.cpp
+++ b/lib/scudo/scudo_allocator.cpp
@@ -588,11 +588,11 @@
 }
 
 // Opportunistic RSS limit check. This will update the RSS limit status, if
-// it can, every 250ms, otherwise it will just return the current one.
+// it can, every 100ms, otherwise it will just return the current one.
 NOINLINE bool Allocator::isRssLimitExceeded() {
   u64 LastCheck = atomic_load_relaxed(&RssLastCheckedAtNS);
   const u64 CurrentCheck = MonotonicNanoTime();
-  if (LIKELY(CurrentCheck < LastCheck + (250ULL * 1000000ULL)))
+  if (LIKELY(CurrentCheck < LastCheck + (100ULL * 1000000ULL)))
     return atomic_load_relaxed(&RssLimitExceeded);
   if (!atomic_compare_exchange_weak(&RssLastCheckedAtNS, &LastCheck,
                                     CurrentCheck, memory_order_relaxed))
diff --git a/lib/scudo/scudo_flags.inc b/lib/scudo/scudo_flags.inc
index 0a4a7f1..f180478 100644
--- a/lib/scudo/scudo_flags.inc
+++ b/lib/scudo/scudo_flags.inc
@@ -37,9 +37,7 @@
           "Size in bytes up to which chunks will be quarantined (if lower than"
           "or equal to). Defaults to 256 (32-bit) or 2048 (64-bit)")
 
-// Disable the deallocation type check by default on Android, it causes too many
-// issues with third party libraries.
-SCUDO_FLAG(bool, DeallocationTypeMismatch, !SANITIZER_ANDROID,
+SCUDO_FLAG(bool, DeallocationTypeMismatch, true,
           "Report errors on malloc/delete, new/free, new/delete[], etc.")
 
 SCUDO_FLAG(bool, DeleteSizeMismatch, true,
diff --git a/lib/scudo/scudo_platform.h b/lib/scudo/scudo_platform.h
index fdae00b..3a6f4be 100644
--- a/lib/scudo/scudo_platform.h
+++ b/lib/scudo/scudo_platform.h
@@ -80,7 +80,7 @@
 #endif  // SANITIZER_CAN_USE_ALLOCATOR64
 
 #if !defined(SCUDO_SIZE_CLASS_MAP)
-# define SCUDO_SIZE_CLASS_MAP Dense
+# define SCUDO_SIZE_CLASS_MAP Default
 #endif
 
 #define SIZE_CLASS_MAP_TYPE SIZE_CLASS_MAP_TYPE_(SCUDO_SIZE_CLASS_MAP)
diff --git a/test/asan/TestCases/Posix/no-fd.cc b/test/asan/TestCases/Posix/no-fd.cc
deleted file mode 100644
index b0441e9..0000000
--- a/test/asan/TestCases/Posix/no-fd.cc
+++ /dev/null
@@ -1,43 +0,0 @@
-// RUN: %clangxx_asan -O0 %s -o %t
-// RUN: %run %t 2>&1 | FileCheck %s
-// RUN: %env_asan_opts=debug=1,verbosity=2 %run %t 2>&1 | FileCheck %s
-
-// Test ASan initialization
-
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-extern "C" const char *__asan_default_options() {
-  return "test_only_emulate_no_memorymap=1";
-}
-
-void parent(int argc, char **argv) {
-  fprintf(stderr, "hello\n");
-  // CHECK: hello
-  close(0);
-  close(1);
-  dup2(2, 3);
-  close(2);
-  char *const newargv[] = {argv[0], (char *)"x", nullptr};
-  execv(argv[0], newargv);
-  perror("execve");
-  exit(1);
-}
-
-void child() {
-  assert(dup(3) == 0);
-  assert(dup(3) == 1);
-  assert(dup(3) == 2);
-  fprintf(stderr, "world\n");
-  // CHECK: world
-}
-
-int main(int argc, char **argv) {
-  if (argc == 1) {
-    parent(argc, argv);
-  } else {
-    child();
-  }
-}
diff --git a/test/builtins/Unit/addtf3_test.c b/test/builtins/Unit/addtf3_test.c
index afbca12..57a4729 100644
--- a/test/builtins/Unit/addtf3_test.c
+++ b/test/builtins/Unit/addtf3_test.c
@@ -12,12 +12,11 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include <fenv.h>
+#include "int_lib.h"
 #include <stdio.h>
 
 #if __LDBL_MANT_DIG__ == 113
 
-#include "int_lib.h"
 #include "fp_test.h"
 
 // Returns: a + b
@@ -76,26 +75,6 @@
                      UINT64_C(0x61e58dd6c51eb77c)))
         return 1;
 
-#if (defined(__arm__) || defined(__aarch64__)) && defined(__ARM_FP)
-    // Rounding mode tests on supported architectures
-    long double m = 1234.0L, n = 0.01L;
-    fesetround(FE_UPWARD);
-    if (__addtf3(m, n) != 1235.0L)
-        return 1;
-
-    fesetround(FE_DOWNWARD);
-    if (__addtf3(m, n) != 1234.0L)
-        return 1;
-
-    fesetround(FE_TOWARDZERO);
-    if (__addtf3(m, n) != 1234.0L)
-        return 1;
-
-    fesetround(FE_TONEAREST);
-    if (__addtf3(m, n) != 1234.0L)
-        return 1;
-#endif
-
 #else
     printf("skipped\n");
 
diff --git a/test/builtins/Unit/subtf3_test.c b/test/builtins/Unit/subtf3_test.c
index 96afd57..771242b 100644
--- a/test/builtins/Unit/subtf3_test.c
+++ b/test/builtins/Unit/subtf3_test.c
@@ -12,7 +12,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include <fenv.h>
 #include <stdio.h>
 
 #if __LDBL_MANT_DIG__ == 113
@@ -69,26 +68,6 @@
                      UINT64_C(0xa44a7bca780a166c)))
         return 1;
 
-#if (defined(__arm__) || defined(__aarch64__)) && defined(__ARM_FP)
-    // Rounding mode tests on supported architectures
-    long double m = 1234.0L, n = 0.01L;
-    fesetround(FE_UPWARD);
-    if (__subtf3(m, n) != 1234.0L)
-        return 1;
-
-    fesetround(FE_DOWNWARD);
-    if (__subtf3(m, n) != 1233.0L)
-        return 1;
-
-    fesetround(FE_TOWARDZERO);
-    if (__subtf3(m, n) != 1233.0L)
-        return 1;
-
-    fesetround(FE_TONEAREST);
-    if (__subtf3(m, n) != 1234.0L)
-        return 1;
-#endif
-
 #else
     printf("skipped\n");
 
diff --git a/test/hwasan/TestCases/Linux/release-shadow.c b/test/hwasan/TestCases/Linux/release-shadow.c
deleted file mode 100644
index 9aae350..0000000
--- a/test/hwasan/TestCases/Linux/release-shadow.c
+++ /dev/null
@@ -1,70 +0,0 @@
-// Test that tagging a large region to 0 reduces RSS.
-// RUN: %clang_hwasan -mllvm -hwasan-instrument-stack=0 %s -o %t && %run %t 2>&1
-
-#include <assert.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/mman.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-#include <sanitizer/hwasan_interface.h>
-
-const unsigned char kTag = 42;
-const size_t kNumShadowPages = 256;
-const size_t kNumPages = 16 * kNumShadowPages;
-const size_t kPageSize = 4096;
-const size_t kMapSize = kNumPages * kPageSize;
-
-void sync_rss() {
-  char *page = (char *)mmap(0, kPageSize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
-  // Linux kernel updates RSS counters after a set number of page faults.
-  for (int i = 0; i < 1000; ++i) {
-    page[0] = 42;
-    madvise(page, kPageSize, MADV_DONTNEED);
-  }
-  munmap(page, kPageSize);
-}
-
-size_t current_rss() {
-  sync_rss();
-  int statm_fd = open("/proc/self/statm", O_RDONLY);
-  assert(statm_fd >= 0);
-
-  char buf[100];
-  assert(read(statm_fd, &buf, sizeof(buf)) > 0);
-  size_t size, rss;
-  assert(sscanf(buf, "%zu %zu", &size, &rss) == 2);
-
-  close(statm_fd);
-  return rss;
-}
-
-void test_rss_difference(void *p) {
-  __hwasan_tag_memory(p, kTag, kMapSize);
-  size_t rss_before = current_rss();
-  __hwasan_tag_memory(p, 0, kMapSize);
-  size_t rss_after = current_rss();
-  fprintf(stderr, "%zu -> %zu\n", rss_before, rss_after);
-  assert(rss_before > rss_after);
-  size_t diff = rss_before - rss_after;
-  fprintf(stderr, "diff %zu\n", diff);
-  // Check that the difference is at least close to kNumShadowPages.
-  assert(diff > kNumShadowPages / 4 * 3);
-}
-
-int main() {
-  fprintf(stderr, "starting rss %zu\n", current_rss());
-  fprintf(stderr, "shadow pages: %zu\n", kNumShadowPages);
-
-  void *p = mmap(0, kMapSize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
-  fprintf(stderr, "p = %p\n", p);
-
-  test_rss_difference(p);
-  test_rss_difference(p);
-  test_rss_difference(p);
-
-  return 0;
-}
diff --git a/test/hwasan/TestCases/heap-buffer-overflow.c b/test/hwasan/TestCases/heap-buffer-overflow.c
index 9f605b3..bff39d2 100644
--- a/test/hwasan/TestCases/heap-buffer-overflow.c
+++ b/test/hwasan/TestCases/heap-buffer-overflow.c
@@ -43,6 +43,7 @@
 // CHECK80-RIGHT: allocated heap chunk; size: 32 offset:
 // CHECK80-RIGHT: is located 50 bytes to the right of 30-byte region
 //
+// CHECKm30: allocated heap chunk; size: 32 offset: 2
 // CHECKm30: is located 30 bytes to the left of 30-byte region
 //
 // CHECKMm30: is a large allocated heap chunk; size: 1003520 offset: -30
diff --git a/test/hwasan/TestCases/use-after-free.c b/test/hwasan/TestCases/use-after-free.c
index 03a1771..fcdd077 100644
--- a/test/hwasan/TestCases/use-after-free.c
+++ b/test/hwasan/TestCases/use-after-free.c
@@ -23,7 +23,7 @@
   // CHECK: [[TYPE]] of size 1 at {{.*}} tags: [[PTR_TAG:[0-9a-f][0-9a-f]]]/[[MEM_TAG:[0-9a-f][0-9a-f]]] (ptr/mem)
   // CHECK: #0 {{.*}} in main {{.*}}use-after-free.c:[[@LINE-2]]
   // Offset is 5 or 11 depending on left/right alignment.
-  // CHECK: is a small unallocated heap chunk; size: 32 offset: {{5|11}}
+  // CHECK: is a small unallocated heap chunk; size: 16 offset: {{5|11}}
   // CHECK: is located 5 bytes inside of 10-byte region
   //
   // CHECK: freed by thread {{.*}} here:
diff --git a/test/hwasan/lit.cfg b/test/hwasan/lit.cfg
index c87215f..3ebba51 100644
--- a/test/hwasan/lit.cfg
+++ b/test/hwasan/lit.cfg
@@ -9,8 +9,7 @@
 config.test_source_root = os.path.dirname(__file__)
 
 # Setup default compiler flags used with -fsanitize=memory option.
-clang_hwasan_cflags = ["-fsanitize=hwaddress", "-mllvm", "-hwasan-generate-tags-with-calls",
-                       "-mllvm", "-hwasan-allow-ifunc", config.target_cflags] + config.debug_info_flags
+clang_hwasan_cflags = ["-fsanitize=hwaddress", "-mllvm", "-hwasan-generate-tags-with-calls", config.target_cflags] + config.debug_info_flags
 clang_hwasan_cxxflags = config.cxx_mode_flags + clang_hwasan_cflags
 
 def build_invocation(compile_flags):
diff --git a/test/scudo/rss.c b/test/scudo/rss.c
index f98bf95..4376290 100644
--- a/test/scudo/rss.c
+++ b/test/scudo/rss.c
@@ -1,15 +1,15 @@
 // RUN: %clang_scudo %s -o %t
 // RUN:                                                                                                  %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-nolimit
-// RUN: %env_scudo_opts="soft_rss_limit_mb=128"                                                          %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-nolimit
-// RUN: %env_scudo_opts="hard_rss_limit_mb=128"                                                          %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-nolimit
-// RUN: %env_scudo_opts="soft_rss_limit_mb=32:allocator_may_return_null=0"                           not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-softlimit
-// RUN: %env_scudo_opts="soft_rss_limit_mb=32:allocator_may_return_null=1"                               %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-softlimit-returnnull
-// RUN: %env_scudo_opts="soft_rss_limit_mb=32:allocator_may_return_null=0:can_use_proc_maps_statm=0" not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-softlimit
-// RUN: %env_scudo_opts="soft_rss_limit_mb=32:allocator_may_return_null=1:can_use_proc_maps_statm=0"     %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-softlimit-returnnull
-// RUN: %env_scudo_opts="hard_rss_limit_mb=32:allocator_may_return_null=0"                           not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-hardlimit
-// RUN: %env_scudo_opts="hard_rss_limit_mb=32:allocator_may_return_null=1"                           not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-hardlimit
-// RUN: %env_scudo_opts="hard_rss_limit_mb=32:allocator_may_return_null=0:can_use_proc_maps_statm=0" not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-hardlimit
-// RUN: %env_scudo_opts="hard_rss_limit_mb=32:allocator_may_return_null=1:can_use_proc_maps_statm=0" not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-hardlimit
+// RUN: %env_scudo_opts="soft_rss_limit_mb=256"                                                          %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-nolimit
+// RUN: %env_scudo_opts="hard_rss_limit_mb=256"                                                          %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-nolimit
+// RUN: %env_scudo_opts="soft_rss_limit_mb=64:allocator_may_return_null=0"                           not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-softlimit
+// RUN: %env_scudo_opts="soft_rss_limit_mb=64:allocator_may_return_null=1"                               %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-softlimit-returnnull
+// RUN: %env_scudo_opts="soft_rss_limit_mb=64:allocator_may_return_null=0:can_use_proc_maps_statm=0" not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-softlimit
+// RUN: %env_scudo_opts="soft_rss_limit_mb=64:allocator_may_return_null=1:can_use_proc_maps_statm=0"     %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-softlimit-returnnull
+// RUN: %env_scudo_opts="hard_rss_limit_mb=64:allocator_may_return_null=0"                           not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-hardlimit
+// RUN: %env_scudo_opts="hard_rss_limit_mb=64:allocator_may_return_null=1"                           not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-hardlimit
+// RUN: %env_scudo_opts="hard_rss_limit_mb=64:allocator_may_return_null=0:can_use_proc_maps_statm=0" not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-hardlimit
+// RUN: %env_scudo_opts="hard_rss_limit_mb=64:allocator_may_return_null=1:can_use_proc_maps_statm=0" not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-hardlimit
 
 // Tests that the soft and hard RSS limits work as intended. Without limit or
 // with a high limit, the test should pass without any malloc returning NULL or
@@ -22,7 +22,7 @@
 #include <string.h>
 #include <unistd.h>
 
-static const size_t kNumAllocs = 64;
+static const size_t kNumAllocs = 128;
 static const size_t kAllocSize = 1 << 20;  // 1MB.
 
 static void *allocs[kNumAllocs];
@@ -31,7 +31,7 @@
   int returned_null = 0;
   for (int i = 0; i < kNumAllocs; i++) {
     if ((i & 0xf) == 0)
-      usleep(100000);
+      usleep(50000);
     allocs[i] = malloc(kAllocSize);
     if (allocs[i])
       memset(allocs[i], 0xff, kAllocSize);  // Dirty the pages.