Skip to content

Commit

Permalink
deps: update zlib to upstream 8603eee
Browse files Browse the repository at this point in the history
Updated as described in doc/guides/maintaining-zlib.md.
  • Loading branch information
targos committed Jul 3, 2020
1 parent b371213 commit fc19eff
Show file tree
Hide file tree
Showing 40 changed files with 1,581 additions and 363 deletions.
166 changes: 103 additions & 63 deletions deps/zlib/BUILD.gn
Expand Up @@ -4,6 +4,10 @@

import("//build/config/compiler/compiler.gni")

if (build_with_chromium) {
import("//testing/test.gni")
}

if (current_cpu == "arm" || current_cpu == "arm64") {
import("//build/config/arm.gni")
}
Expand All @@ -14,10 +18,18 @@ config("zlib_config") {

config("zlib_internal_config") {
defines = [ "ZLIB_IMPLEMENTATION" ]

if (!is_debug) {
# Build code using -O3, see: crbug.com/1084371.
configs = [ "//build/config/compiler:optimize_speed" ]
}
}

use_arm_neon_optimizations = false
if (current_cpu == "arm" || current_cpu == "arm64") {
if ((current_cpu == "arm" || current_cpu == "arm64") &&
!(is_win && !is_clang)) {
# TODO(richard.townsend@arm.com): Optimizations temporarily disabled for
# Windows on Arm MSVC builds, see http://crbug.com/v8/10012.
if (arm_use_neon) {
use_arm_neon_optimizations = true
}
Expand All @@ -29,6 +41,11 @@ use_x86_x64_optimizations =
config("zlib_adler32_simd_config") {
if (use_x86_x64_optimizations) {
defines = [ "ADLER32_SIMD_SSSE3" ]
if (is_win) {
defines += [ "X86_WINDOWS" ]
} else {
defines += [ "X86_NOT_WINDOWS" ]
}
}

if (use_arm_neon_optimizations) {
Expand All @@ -55,11 +72,6 @@ source_set("zlib_adler32_simd") {
"adler32_simd.c",
"adler32_simd.h",
]
if (!is_debug) {
# Use optimize_speed (-O3) to output the _smallest_ code.
configs -= [ "//build/config/compiler:default_optimization" ]
configs += [ "//build/config/compiler:optimize_speed" ]
}
}

configs += [ ":zlib_internal_config" ]
Expand All @@ -78,6 +90,8 @@ if (use_arm_neon_optimizations) {
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) {
Expand All @@ -94,32 +108,16 @@ if (use_arm_neon_optimizations) {
if (!is_ios) {
include_dirs = [ "." ]

if (is_android) {
import("//build/config/android/config.gni")
if (defined(android_ndk_root) && android_ndk_root != "") {
deps = [
"//third_party/android_ndk:cpu_features",
]
} else {
assert(false, "CPU detection requires the Android NDK")
}
} else if (!is_win && !is_clang) {
if (!is_win && !is_clang) {
assert(!use_thin_lto,
"ThinLTO fails mixing different module-level targets")
cflags_c = [ "-march=armv8-a+crc" ]
}

sources = [
"arm_features.c",
"arm_features.h",
"crc32_simd.c",
"crc32_simd.h",
]

if (!is_debug) {
configs -= [ "//build/config/compiler:default_optimization" ]
configs += [ "//build/config/compiler:optimize_speed" ]
}
}

configs += [ ":zlib_internal_config" ]
Expand All @@ -139,6 +137,7 @@ config("zlib_inflate_chunk_simd_config") {

if (use_arm_neon_optimizations) {
defines = [ "INFLATE_CHUNK_SIMD_NEON" ]

if (current_cpu == "arm64") {
defines += [ "INFLATE_CHUNK_READ_64LE" ]
}
Expand All @@ -157,20 +156,14 @@ source_set("zlib_inflate_chunk_simd") {
"contrib/optimizations/inffast_chunk.h",
"contrib/optimizations/inflate.c",
]

if (use_arm_neon_optimizations && !is_debug) {
# Here we trade better performance on newer/bigger ARMv8 cores
# for less perf on ARMv7, per crbug.com/772870#c40
configs -= [ "//build/config/compiler:default_optimization" ]
configs += [ "//build/config/compiler:optimize_speed" ]
}
}

configs += [ ":zlib_internal_config" ]

# Needed for MSVC, which is still supported by V8 and PDFium. zlib uses K&R C
# style function declarations, which triggers warning C4131.
configs -= [ "//build/config/compiler:chromium_code" ]
configs += [
":zlib_internal_config",
"//build/config/compiler:no_chromium_code",
]
configs += [ "//build/config/compiler:no_chromium_code" ]

public_configs = [ ":zlib_inflate_chunk_simd_config" ]
}
Expand Down Expand Up @@ -203,6 +196,15 @@ source_set("zlib_crc32_simd") {
public_configs = [ ":zlib_crc32_simd_config" ]
}

config("zlib_x86_simd_config") {
if (use_x86_x64_optimizations) {
defines = [
"CRC32_SIMD_SSE42_PCLMUL",
"DEFLATE_FILL_WINDOW_SSE2",
]
}
}

source_set("zlib_x86_simd") {
visibility = [ ":*" ]

Expand All @@ -218,17 +220,11 @@ source_set("zlib_x86_simd") {
"-mpclmul",
]
}
} else {
sources = [
"simd_stub.c",
]
}

configs -= [ "//build/config/compiler:chromium_code" ]
configs += [
":zlib_internal_config",
"//build/config/compiler:no_chromium_code",
]
configs += [ ":zlib_internal_config" ]

public_configs = [ ":zlib_x86_simd_config" ]
}

config("zlib_warnings") {
Expand All @@ -248,6 +244,8 @@ component("zlib") {
"chromeconf.h",
"compress.c",
"contrib/optimizations/insert_string.h",
"cpu_features.c",
"cpu_features.h",
"crc32.c",
"crc32.h",
"deflate.c",
Expand All @@ -267,7 +265,6 @@ component("zlib") {
"trees.c",
"trees.h",
"uncompr.c",
"x86.h",
"zconf.h",
"zlib.h",
"zutil.c",
Expand All @@ -277,14 +274,27 @@ component("zlib") {
defines = []
deps = []

if (!use_x86_x64_optimizations && !use_arm_neon_optimizations) {
# Apparently android_cronet bot builds with NEON disabled and
# we also should disable optimizations for iOS@x86 (a.k.a. simulator).
defines += [ "CPU_NO_SIMD" ]
}

if (is_ios) {
# iOS@ARM is a special case where we always have NEON but don't check
# for crypto extensions.
# TODO(cavalcantii): verify what is the current state of CPU features
# shipped on latest iOS devices.
defines += [ "ARM_OS_IOS" ]
}

if (use_x86_x64_optimizations || use_arm_neon_optimizations) {
deps += [
":zlib_adler32_simd",
":zlib_inflate_chunk_simd",
]

if (use_x86_x64_optimizations) {
sources += [ "x86.c" ]
deps += [ ":zlib_crc32_simd" ]
} else if (use_arm_neon_optimizations) {
sources += [ "contrib/optimizations/slide_hash_neon.h" ]
Expand All @@ -294,18 +304,29 @@ component("zlib") {
sources += [ "inflate.c" ]
}

deps += [ ":zlib_x86_simd" ]

if (is_android) {
import("//build/config/android/config.gni")
if (defined(android_ndk_root) && android_ndk_root != "") {
deps += [ "//third_party/android_ndk:cpu_features" ]
} else {
assert(false, "CPU detection requires the Android NDK")
}
}

configs -= [ "//build/config/compiler:chromium_code" ]
configs += [ "//build/config/compiler:no_chromium_code" ]

public_configs = [ ":zlib_config" ]

configs += [
":zlib_internal_config",
"//build/config/compiler:no_chromium_code",

# Must be after no_chromium_code for warning flags to be ordered correctly.
":zlib_warnings",
]

public_configs = [ ":zlib_config" ]

deps += [ ":zlib_x86_simd" ]
allow_circular_includes_from = deps
}

Expand Down Expand Up @@ -343,37 +364,56 @@ static_library("minizip") {
defines = [ "USE_FILE32API" ]
}

deps = [
":zlib",
]
deps = [ ":zlib" ]

configs -= [ "//build/config/compiler:chromium_code" ]
configs += [
"//build/config/compiler:no_chromium_code",
configs += [ "//build/config/compiler:no_chromium_code" ]

public_configs = [ ":zlib_config" ]

configs += [
# Must be after no_chromium_code for warning flags to be ordered correctly.
":minizip_warnings",
]

public_configs = [ ":zlib_config" ]
}

executable("zlib_bench") {
include_dirs = [ "." ]

sources = [
"contrib/bench/zlib_bench.cc",
]

sources = [ "contrib/bench/zlib_bench.cc" ]
if (!is_debug) {
configs -= [ "//build/config/compiler:default_optimization" ]
configs += [ "//build/config/compiler:optimize_speed" ]
}

deps = [ ":zlib" ]

configs -= [ "//build/config/compiler:chromium_code" ]
configs += [ "//build/config/compiler:no_chromium_code" ]
}

deps = [
":zlib",
]
if (build_with_chromium) {
test("zlib_unittests") {
testonly = true

sources = [
"contrib/tests/infcover.cc",
"contrib/tests/infcover.h",
"contrib/tests/utils_unittest.cc",
"google/compression_utils_portable.cc",
"google/compression_utils_portable.h",
]

deps = [
":zlib",
"//testing/gtest",
"//testing/gtest:gtest_main",
]

include_dirs = [
"//third_party/googletest/src/googletest/include/gtest",
".",
"google",
]
}
}
3 changes: 3 additions & 0 deletions deps/zlib/DEPS
@@ -0,0 +1,3 @@
include_rules = [
"+testing/gtest",
]
4 changes: 2 additions & 2 deletions deps/zlib/OWNERS
@@ -1,7 +1,7 @@
agl@chromium.org
cavalcantii@chromium.org
cblume@chromium.org
mtklein@chromium.org
scroggo@chromium.org
mtklein@google.com
scroggo@google.com

# COMPONENT: Internals
1 change: 1 addition & 0 deletions deps/zlib/README.chromium
Expand Up @@ -2,6 +2,7 @@ Name: zlib
Short Name: zlib
URL: http://zlib.net/
Version: 1.2.11
CPEPrefix: cpe:/a:zlib:zlib:1.2.11
Security Critical: yes
License: Custom license
License File: LICENSE
Expand Down
8 changes: 3 additions & 5 deletions deps/zlib/adler32.c
Expand Up @@ -59,10 +59,8 @@ local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2));
# define MOD63(a) a %= BASE
#endif

#if defined(ADLER32_SIMD_SSSE3)
#include "adler32_simd.h"
#include "x86.h"
#elif defined(ADLER32_SIMD_NEON)
#include "cpu_features.h"
#if defined(ADLER32_SIMD_SSSE3) || defined(ADLER32_SIMD_NEON)
#include "adler32_simd.h"
#endif

Expand Down Expand Up @@ -108,7 +106,7 @@ uLong ZEXPORT adler32_z(adler, buf, len)
*/
if (buf == Z_NULL) {
if (!len) /* Assume user is calling adler32(0, NULL, 0); */
x86_check_features();
cpu_check_features();
return 1L;
}
#else
Expand Down
4 changes: 0 additions & 4 deletions deps/zlib/adler32_simd.c
Expand Up @@ -50,13 +50,9 @@
#define NMAX 5552

#if defined(ADLER32_SIMD_SSSE3)
#ifndef __GNUC__
#define __attribute__()
#endif

#include <tmmintrin.h>

__attribute__((target("ssse3")))
uint32_t ZLIB_INTERNAL adler32_simd_( /* SSSE3 */
uint32_t adler,
const unsigned char *buf,
Expand Down
4 changes: 4 additions & 0 deletions deps/zlib/chromeconf.h
Expand Up @@ -192,4 +192,8 @@
#define arm_check_features Cr_z_arm_check_features
#define armv8_crc32_little Cr_z_armv8_crc32_little

/* Symbols added by cpu_features.c */
#define cpu_check_features Cr_z_cpu_check_features
#define x86_cpu_enable_sse2 Cr_z_x86_cpu_enable_sse2

#endif /* THIRD_PARTY_ZLIB_CHROMECONF_H_ */

0 comments on commit fc19eff

Please sign in to comment.