Merge "Upgrade zlib to 89bddfee9cf8fde3ab1212ed63bf03d76baf8914" am: 28320305b9 am: 05537a8139

Original change: https://android-review.googlesource.com/c/platform/external/zlib/+/1360669

Change-Id: I72aae48ac01c06c4417934962ce0f54e59713fbb
diff --git a/BUILD.gn b/BUILD.gn
index 64cddc7..19718ce 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -90,6 +90,8 @@
         defines += [ "ARMV8_OS_ANDROID" ]
       } else if (is_linux || is_chromeos) {
         defines += [ "ARMV8_OS_LINUX" ]
+      } else if (is_mac) {
+        defines += [ "ARMV8_OS_MACOS" ]
       } else if (is_fuchsia) {
         defines += [ "ARMV8_OS_FUCHSIA" ]
       } else if (is_win) {
diff --git a/METADATA b/METADATA
index 34236a4..a215336 100644
--- a/METADATA
+++ b/METADATA
@@ -5,11 +5,11 @@
     type: GIT
     value: "https://chromium.googlesource.com/chromium/src/third_party/zlib/"
   }
-  version: "eaf99a4e2009b0e5759e6070ad1760ac1dd75461"
+  version: "89bddfee9cf8fde3ab1212ed63bf03d76baf8914"
   license_type: NOTICE
   last_upgrade_date {
     year: 2020
-    month: 6
-    day: 16
+    month: 7
+    day: 10
   }
 }
diff --git a/cpu_features.c b/cpu_features.c
index 0c10a00..70f01be 100644
--- a/cpu_features.c
+++ b/cpu_features.c
@@ -17,7 +17,13 @@
 
 /* TODO(cavalcantii): remove checks for x86_flags on deflate.
  */
+#if defined(ARMV8_OS_MACOS)
+/* crc32 is a baseline feature in ARMv8.1-A, and macOS running on arm64 is new
+ * enough that this can be assumed without runtime detection. */
+int ZLIB_INTERNAL arm_cpu_enable_crc32 = 1;
+#else
 int ZLIB_INTERNAL arm_cpu_enable_crc32 = 0;
+#endif
 int ZLIB_INTERNAL arm_cpu_enable_pmull = 0;
 int ZLIB_INTERNAL x86_cpu_enable_sse2 = 0;
 int ZLIB_INTERNAL x86_cpu_enable_ssse3 = 0;
@@ -46,15 +52,23 @@
 #error cpu_features.c CPU feature detection in not defined for your platform
 #endif
 
-#if !defined(CPU_NO_SIMD) && !defined(ARM_OS_IOS)
+#if !defined(CPU_NO_SIMD) && !defined(ARMV8_OS_MACOS) && !defined(ARM_OS_IOS)
 static void _cpu_check_features(void);
 #endif
 
-#if defined(ARMV8_OS_ANDROID) || defined(ARMV8_OS_LINUX) || defined(ARMV8_OS_FUCHSIA) || defined(X86_NOT_WINDOWS)
+#if defined(ARMV8_OS_ANDROID) || defined(ARMV8_OS_LINUX) || defined(ARMV8_OS_MACOS) || defined(ARMV8_OS_FUCHSIA) || defined(X86_NOT_WINDOWS)
+#if !defined(ARMV8_OS_MACOS)
+// _cpu_check_features() doesn't need to do anything on mac/arm since all
+// features are known at build time, so don't call it.
+// Do provide cpu_check_features() (with a no-op implementation) so that we
+// don't have to make all callers of it check for mac/arm.
 static pthread_once_t cpu_check_inited_once = PTHREAD_ONCE_INIT;
+#endif
 void ZLIB_INTERNAL cpu_check_features(void)
 {
+#if !defined(ARMV8_OS_MACOS)
     pthread_once(&cpu_check_inited_once, _cpu_check_features);
+#endif
 }
 #elif defined(ARMV8_OS_WINDOWS) || defined(X86_WINDOWS)
 static INIT_ONCE cpu_check_inited_once = INIT_ONCE_STATIC_INIT;
@@ -75,7 +89,7 @@
  * iOS@ARM is a special case where we always have NEON but don't check
  * for crypto extensions.
  */
-#ifndef ARM_OS_IOS
+#if !defined(ARMV8_OS_MACOS) && !defined(ARM_OS_IOS)
 /*
  * See http://bit.ly/2CcoEsr for run-time detection of ARM features and also
  * crbug.com/931275 for android_getCpuFeatures() use in the Android sandbox.
diff --git a/google/compression_utils.cc b/google/compression_utils.cc
index 9f63a84..d6ee2b6 100644
--- a/google/compression_utils.cc
+++ b/google/compression_utils.cc
@@ -5,7 +5,7 @@
 #include "third_party/zlib/google/compression_utils.h"
 
 #include "base/bit_cast.h"
-#include "base/logging.h"
+#include "base/check_op.h"
 #include "base/process/memory.h"
 #include "base/strings/string_piece.h"
 #include "base/sys_byteorder.h"
diff --git a/google/compression_utils_unittest.cc b/google/compression_utils_unittest.cc
index b0e04b8..398984b 100644
--- a/google/compression_utils_unittest.cc
+++ b/google/compression_utils_unittest.cc
@@ -9,7 +9,6 @@
 
 #include <string>
 
-#include "base/logging.h"
 #include "base/stl_util.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
diff --git a/google/zip_internal.cc b/google/zip_internal.cc
index a67b6c9..9cbb78c 100644
--- a/google/zip_internal.cc
+++ b/google/zip_internal.cc
@@ -10,6 +10,7 @@
 #include <algorithm>
 
 #include "base/logging.h"
+#include "base/notreached.h"
 #include "base/strings/utf_string_conversions.h"
 
 #if defined(USE_SYSTEM_MINIZIP)
diff --git a/google/zip_reader_unittest.cc b/google/zip_reader_unittest.cc
index 87190c7..bba4365 100644
--- a/google/zip_reader_unittest.cc
+++ b/google/zip_reader_unittest.cc
@@ -12,11 +12,11 @@
 #include <string>
 
 #include "base/bind.h"
+#include "base/check.h"
 #include "base/files/file.h"
 #include "base/files/file_util.h"
 #include "base/files/scoped_temp_dir.h"
 #include "base/hash/md5.h"
-#include "base/logging.h"
 #include "base/path_service.h"
 #include "base/run_loop.h"
 #include "base/stl_util.h"
diff --git a/google/zip_unittest.cc b/google/zip_unittest.cc
index 7ea3c36..10f2ef7 100644
--- a/google/zip_unittest.cc
+++ b/google/zip_unittest.cc
@@ -16,6 +16,7 @@
 #include "base/files/file_path.h"
 #include "base/files/file_util.h"
 #include "base/files/scoped_temp_dir.h"
+#include "base/logging.h"
 #include "base/macros.h"
 #include "base/path_service.h"
 #include "base/strings/string_util.h"
diff --git a/google/zip_writer.cc b/google/zip_writer.cc
index 1f2f073..6f38d42 100644
--- a/google/zip_writer.cc
+++ b/google/zip_writer.cc
@@ -5,6 +5,7 @@
 #include "third_party/zlib/google/zip_writer.h"
 
 #include "base/files/file.h"
+#include "base/logging.h"
 #include "base/strings/string_util.h"
 #include "third_party/zlib/google/zip_internal.h"