Merge "Merge cherrypicks of [1275206, 1275207, 1275375, 1275579, 1275580, 1275581, 1275582, 1275583, 1275584, 1275585, 1275586, 1275587, 1275588, 1275589, 1275398, 1275399, 1275223, 1275540, 1275541, 1275542, 1275435] into ndk-release-r21" into ndk-release-r21
diff --git a/build/cmake/android.toolchain.cmake b/build/cmake/android.toolchain.cmake
index cf5312f..c3a56a9 100644
--- a/build/cmake/android.toolchain.cmake
+++ b/build/cmake/android.toolchain.cmake
@@ -347,6 +347,13 @@
 endif()
 
 # Don't re-export libgcc symbols in every binary.
+list(APPEND ANDROID_LINKER_FLAGS -Wl,--exclude-libs,libgcc.a)
+# arm32 currently uses a linker script in place of libgcc to ensure that
+# libunwind is linked in the correct order. --exclude-libs does not propagate to
+# the contents of the linker script and can't be specified within the linker
+# script. Hide both regardless of architecture to future-proof us in case we
+# move other architectures to a linker script (which we may want to do so we
+# automatically link libclangrt on other architectures).
 list(APPEND ANDROID_LINKER_FLAGS -Wl,--exclude-libs,libgcc_real.a)
 list(APPEND ANDROID_LINKER_FLAGS -Wl,--exclude-libs,libatomic.a)
 
diff --git a/build/core/default-build-commands.mk b/build/core/default-build-commands.mk
index 138707b..98af9cf 100644
--- a/build/core/default-build-commands.mk
+++ b/build/core/default-build-commands.mk
@@ -84,7 +84,13 @@
 
 cmd-strip = $(PRIVATE_STRIP) $(PRIVATE_STRIP_MODE) $(call host-path,$1)
 
-TARGET_LIBGCC = -lgcc -Wl,--exclude-libs,libgcc_real.a
+# arm32 currently uses a linker script in place of libgcc to ensure that
+# libunwind is linked in the correct order. --exclude-libs does not propagate to
+# the contents of the linker script and can't be specified within the linker
+# script. Hide both regardless of architecture to future-proof us in case we
+# move other architectures to a linker script (which we may want to do so we
+# automatically link libclangrt on other architectures).
+TARGET_LIBGCC = -lgcc -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libgcc_real.a
 TARGET_LIBATOMIC = -latomic -Wl,--exclude-libs,libatomic.a
 TARGET_LDLIBS := -lc -lm
 
diff --git a/build/core/setup-abi.mk b/build/core/setup-abi.mk
index 0e278c5..bdb3501 100644
--- a/build/core/setup-abi.mk
+++ b/build/core/setup-abi.mk
@@ -26,17 +26,19 @@
 
 TARGET_OUT := $(NDK_APP_OUT)/$(_app)/$(TARGET_ARCH_ABI)
 
-# For x86 and mips: the minimal platform level is android-9
-TARGET_PLATFORM_SAVED := $(TARGET_PLATFORM)
+TARGET_PLATFORM_LEVEL := $(APP_PLATFORM_LEVEL)
 
-# For 64-bit ABIs: the minimal platform level is android-21
+# 64-bit ABIs were first supported in API 21. Pull up these ABIs if the app has
+# a lower minSdkVersion.
 ifneq ($(filter $(NDK_KNOWN_DEVICE_ABI64S),$(TARGET_ARCH_ABI)),)
-$(foreach _plat,3 4 5 8 9 10 11 12 13 14 15 16 17 18 19 20,\
-    $(eval TARGET_PLATFORM := $$(subst android-$(_plat),android-21,$$(TARGET_PLATFORM)))\
-)
+    ifneq ($(call lt,$(TARGET_PLATFORM_LEVEL),21),)
+        TARGET_PLATFORM_LEVEL := 21
+    endif
 endif
 
-TARGET_PLATFORM_LEVEL := $(strip $(subst android-,,$(TARGET_PLATFORM)))
+# Not used by ndk-build, but are documented for use by Android.mk files.
+TARGET_PLATFORM := android-$(TARGET_PLATFORM_LEVEL)
+TARGET_ABI := $(TARGET_PLATFORM)-$(TARGET_ARCH_ABI)
 
 # If we're targeting a new enough platform version, we don't actually need to
 # cover any gaps in libc for libc++ support. In those cases, save size in the
@@ -82,6 +84,3 @@
 endif
 
 include $(BUILD_SYSTEM)/setup-toolchain.mk
-
-# Restore TARGET_PLATFORM, see above.
-TARGET_PLATFORM := $(TARGET_PLATFORM_SAVED)
diff --git a/build/core/setup-app.mk b/build/core/setup-app.mk
index dbd25e1..f893c73 100644
--- a/build/core/setup-app.mk
+++ b/build/core/setup-app.mk
@@ -39,9 +39,6 @@
 ndk-app-$(_app): $(NDK_APP_MODULES)
 all: ndk-app-$(_app)
 
-# which platform/abi/toolchain are we going to use?
-TARGET_PLATFORM := $(call get,$(_map),APP_PLATFORM)
-
 # The ABI(s) to use
 NDK_APP_ABI := $(subst $(comma),$(space),$(strip $(NDK_APP_ABI)))
 ifndef NDK_APP_ABI
diff --git a/build/core/setup-toolchain.mk b/build/core/setup-toolchain.mk
index 7c058ba..6973dd4 100644
--- a/build/core/setup-toolchain.mk
+++ b/build/core/setup-toolchain.mk
@@ -17,7 +17,7 @@
 # to setup the target toolchain for a given platform/abi combination.
 #
 
-$(call assert-defined,TARGET_PLATFORM TARGET_ARCH TARGET_ARCH_ABI)
+$(call assert-defined,TARGET_PLATFORM_LEVEL TARGET_ARCH TARGET_ARCH_ABI)
 $(call assert-defined,NDK_APPS NDK_APP_STL)
 
 # Check that we have a toolchain that supports the current ABI.
@@ -61,8 +61,6 @@
     TARGET_TOOLCHAIN := $(NDK_TOOLCHAIN)
 endif # NDK_TOOLCHAIN is not empty
 
-TARGET_ABI := $(TARGET_PLATFORM)-$(TARGET_ARCH_ABI)
-
 TARGET_PREBUILT_SHARED_LIBRARIES :=
 
 # Define default values for TOOLCHAIN_NAME, this can be overriden in
diff --git a/build/tools/prebuilt-common.sh b/build/tools/prebuilt-common.sh
index 3a0e095..8b4423a 100644
--- a/build/tools/prebuilt-common.sh
+++ b/build/tools/prebuilt-common.sh
@@ -1247,7 +1247,7 @@
 {
     local NAME DIR BINPREFIX
     local SYSTEM=${1:-$(get_prebuilt_host_tag)}
-    local VERSION=r365631c
+    local VERSION=r365631c1
     SYSTEM=${SYSTEM%_64} # Trim _64 suffix. We only have one LLVM.
     BINPREFIX=$ANDROID_BUILD_TOP/prebuilts/clang/host/$SYSTEM/clang-$VERSION/bin
     echo "$BINPREFIX"
diff --git a/docs/BuildSystemMaintainers.md b/docs/BuildSystemMaintainers.md
index d23860a..922d844 100644
--- a/docs/BuildSystemMaintainers.md
+++ b/docs/BuildSystemMaintainers.md
@@ -241,12 +241,6 @@
 instead of `<triple>-strip` or the `strip` binary from the triple-specific
 directory.
 
-Note: llvm-strip's `--strip-unneeded` is not currently pruning all that it
-should. As a workaround, `--strip-all` (which differs in behavior from GNU's
-`--strip-all`) can be used instead. See [Issue 1083] for more information.
-
-[Issue 1083]: https://github.com/android/ndk/issues/1083
-
 Android is moving away from GNU Binutils in favor of LLVM tools. This is a work
 in progress, but it is likely that a future release of the NDK will deprecate
 and eventually remove GNU Binutils. For now, ensure that your build system works
@@ -416,10 +410,11 @@
 linked binary.
 
 If this behavior is not desired for your build system, ensure that these flags
-are at least used for `libgcc_real.a` (`libgcc.a` is a linker script, and
-`--exclude-libs` does not have any effect on the contents of linker scripts) and
-`libunwind.a` (libunwind is only used for ARM32). This is necessary to avoid
-unwinding bugs on ARM32. See [Unwinding] for more information.
+are at least used for `libgcc.a` (`libgcc_real.a` on Arm32, where `libgcc.a` is
+a linker script, as `--exclude-libs` does not have any effect on the contents of
+linker scripts) and `libunwind.a` (libunwind is only used for ARM32). This is
+necessary to avoid unwinding bugs on Arm32. See [Unwinding] for more
+information.
 
 [visibility]: https://gcc.gnu.org/wiki/Visibility
 
@@ -519,9 +514,12 @@
 unwinder, it is possible for one unwinder to call into the other. As they are
 not compatible, this will likely result in either a crash or a failed unwind. To
 avoid this problem, libraries should always be built with
-`-Wl,--exclude-libs,libgcc_real.a` and `-Wl,--exclude-libs,libunwind.a` (the
-latter is only necessary for 32-bit ARM) to ensure that unwind symbols are not
-re-exported from shared libraries.
+`-Wl,--exclude-libs,libgcc.a`, `-Wl,--exclude-libs,libgcc_real.a` and
+`-Wl,--exclude-libs,libunwind.a` (the latter is only necessary for 32-bit Arm)
+to ensure that unwind symbols are not re-exported from shared libraries. Note
+that `libgcc_real.a` is needed because on some architectures (currently only
+32-bit Arm) `libgcc.a` is a linker script and `--exclude-libs` does not extend
+to the contents of linker scripts.
 
 Even with the above precautions, it is still possible for an improperly built
 external dependency to provide an incorrect unwind implementation as described
diff --git a/docs/changelogs/Changelog-r21.md b/docs/changelogs/Changelog-r21.md
index defa211..0449ed3 100644
--- a/docs/changelogs/Changelog-r21.md
+++ b/docs/changelogs/Changelog-r21.md
@@ -24,10 +24,9 @@
    will affect builds using LLD with binutils strip and objcopy as opposed to
    llvm-strip and llvm-objcopy.
 
- * The legacy toolchain install paths will be removed before the next LTS
-   release (likely in r22). These paths have been obsolete since NDK r19 and
-   take up a considerable amount of space in the NDK. The paths being removed
-   are:
+ * The legacy toolchain install paths will be removed over the coming releases.
+   These paths have been obsolete since NDK r19 and take up a considerable
+   amount of space in the NDK. The paths being removed are:
 
    * platforms
    * sources/cxx-stl
@@ -49,6 +48,40 @@
 
 [Build System Maintainers Guide]: https://android.googlesource.com/platform/ndk/+/master/docs/BuildSystemMaintainers.md
 
+## r21b
+
+ * Fixed debugging processes containing Java with gdb. Cherrypicked
+   "gdb: Don't fault for 'maint print psymbols' when using an index", which
+   fixes a bug that caused gdb to fail when debugging a process with Java.
+   Pure C/C++ executables were fine, but this effectively broke all app
+   debugging. The error from gdb that confirms you were affected by this was
+   `gdb-8.3/gdb/psymtab.c:316: internal-error: sect_index_text not initialized`.
+ * [Issue 1166]: Rehid unwinder symbols all architectures.
+ * [Issue 1173]: Fix gdb python symbol missing issue on Darwin.
+ * [Issue 1176]: Fix strip failing with "File truncated" errors on Windows.
+ * [Issue 1178]: Revert changes to stdatomic.h to maintain compatibility with
+   C's `_Atomic` type qualifier. Note that the C++ standard will likely mandate
+   this breakage in the future. See [P0943R4] for more details.
+ * [Issue 1184]: Fix Clang crash for x86_64.
+ * [Issue 1198]: Fix incorrect constant folding of long doubles on Windows.
+ * [Issue 1201]: Fixed issue in ndk-build that was causing `APP_PLATFORM` to be
+   corrupted for API 30+ with LP64 ABIs.
+ * [Issue 1203]: libc++ prebuilts and CRT objects are no longer built as Neon.
+ * [Issue 1205]: Potential fixes for relocation out of range issues with LLD.
+ * [Issue 1206]: LLD support for --fix-cortex-a8.
+
+[Issue 1166]: https://github.com/android/ndk/issues/1166
+[Issue 1173]: https://github.com/android/ndk/issues/1173
+[Issue 1176]: https://github.com/android/ndk/issues/1176
+[Issue 1178]: https://github.com/android/ndk/issues/1178
+[Issue 1184]: https://github.com/android/ndk/issues/1184
+[Issue 1198]: https://github.com/android/ndk/issues/1198
+[Issue 1201]: https://github.com/android/ndk/issues/1201
+[Issue 1203]: https://github.com/android/ndk/issues/1203
+[Issue 1205]: https://github.com/android/ndk/issues/1205
+[Issue 1206]: https://github.com/android/ndk/issues/1206
+[P0943R4]: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0943r4.html
+
 ## Changes
 
  * Updated Clang and LLD to r365631.
diff --git a/ndk/checkbuild.py b/ndk/checkbuild.py
index 2aa91b4..c7cfa83 100755
--- a/ndk/checkbuild.py
+++ b/ndk/checkbuild.py
@@ -925,6 +925,9 @@
             dst,
         ] + srcs
 
+        if arch == ndk.abis.Arch('arm'):
+            args.append('-mfpu=vfpv3-d16')
+
         return args
 
     def check_elf_note(self, obj_file: str) -> None:
@@ -1129,18 +1132,11 @@
         """Returns the lazily initialized gdb builder for this module."""
         if self._gdb_builder is None:
             no_build_or_host = False
-            no_strip = False
             additional_flags = []
             if self.host == ndk.hosts.Host.Darwin:
                 # Awful Darwin hack. For some reason GDB doesn't produce a gdb
                 # executable when using --build/--host.
                 no_build_or_host = True
-                # -s caused mysterious linking error on old macOS like:
-                # "ld: internal error: atom not found in symbolIndex(...)"
-                # Seems old ld64 wrongly stripped some symbols.
-                # Remove this when build server upgrades to xcode 7.3
-                # (ld64-264.3.101) or above.
-                no_strip = True
                 additional_flags.append('-Wl,-rpath,@loader_path/../lib')
             if self.host == ndk.hosts.Host.Linux:
                 additional_flags.append('-Wl,-rpath,$$$$\\ORIGIN/../lib')
@@ -1153,7 +1149,9 @@
                 self.host,
                 use_clang=True,
                 no_build_or_host=no_build_or_host,
-                no_strip=no_strip,
+                # Since we statically link libpython, python dynamic libraries may
+                # depend on symbols in gdb binary.
+                no_strip=True,
                 additional_flags=additional_flags)
         return self._gdb_builder
 
@@ -1284,11 +1282,6 @@
         exe_suffix = '.exe' if self.host.is_windows else ''
         gdb_exe = install_dir / ('bin/gdb' + exe_suffix)
 
-        # Strip is skipped when build. Strip the binary now.
-        if self.host == ndk.hosts.Host.Darwin:
-            cmd = [str(self.gdb_builder.toolchain.strip), str(gdb_exe)]
-            subprocess.check_call(cmd)
-
         # gdb is currently gdb(.exe)? and the gdb stub is currently gdb-stub.
         # Make them gdb-orig(.exe)? and gdb(.exe)? respectively.
         gdb_exe.rename(install_dir / ('bin/gdb-orig' + exe_suffix))
diff --git a/ndk/config.py b/ndk/config.py
index 449bdb0..dbf3ace 100644
--- a/ndk/config.py
+++ b/ndk/config.py
@@ -2,7 +2,7 @@
 
 
 major = 21
-hotfix = 0
+hotfix = 1
 hotfix_str = chr(ord('a') + hotfix) if hotfix else ''
 beta = 0
 beta_str = '-beta{}'.format(beta) if beta > 0 else ''
diff --git a/ndk/toolchains.py b/ndk/toolchains.py
index 1e719bf..1f5480b 100644
--- a/ndk/toolchains.py
+++ b/ndk/toolchains.py
@@ -23,7 +23,7 @@
 import ndk.paths
 
 
-CLANG_VERSION = 'clang-r365631c'
+CLANG_VERSION = 'clang-r365631c1'
 
 
 HOST_TRIPLE_MAP = {
diff --git a/sources/android/support/Android.mk b/sources/android/support/Android.mk
index d4728a5..c9a908f 100644
--- a/sources/android/support/Android.mk
+++ b/sources/android/support/Android.mk
@@ -118,6 +118,7 @@
 LOCAL_SRC_FILES := $(android_support_sources)
 LOCAL_C_INCLUDES := $(android_support_c_includes)
 LOCAL_CFLAGS := $(android_support_cflags)
+LOCAL_ARM_NEON := false
 
 LOCAL_CPPFLAGS := \
     -fvisibility-inlines-hidden \