Skip to content

Commit c2e7c99

Browse files
authored
Update to zlib-ng 2.2.5 (#118457)
* Update to zlib-ng 2.2.5 * Update zlib-ng hash + tag with release
1 parent d104e3e commit c2e7c99

22 files changed

+336
-98
lines changed

src/native/external/zlib-ng-version.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
v2.2.4
2-
860e4cff7917d93f54f5d7f0bc1d0e8b1a3cb988
1+
v2.2.5
2+
425439062b114a0f6cf625022c41d929c7e879f9
33

4-
https://github.com/zlib-ng/zlib-ng/releases/tag/2.2.4
4+
https://github.com/zlib-ng/zlib-ng/releases/tag/2.2.5
55

66
We have removed the following folders from our local copy as these files are not needed for our compilation:
77

src/native/external/zlib-ng/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,7 @@ gzread.c
103103
MinSizeRel
104104
RelWithDebInfo
105105
/_deps/googletest*
106+
107+
# Test datasets
108+
test/data/corpora/
109+
test/data/local/

src/native/external/zlib-ng/CMakeLists.txt

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ include(CMakeDependentOption)
4747
include(CMakePackageConfigHelpers)
4848
include(FeatureSummary)
4949

50+
# We need to enable C++ before trying to check for coverage
51+
option(WITH_GTEST "Build gtest_zlib" ON)
52+
option(WITH_FUZZERS "Build test/fuzz" OFF)
53+
option(WITH_BENCHMARKS "Build test/benchmarks" OFF)
54+
55+
if(WITH_GTEST OR WITH_FUZZERS OR WITH_BENCHMARKS)
56+
enable_language(CXX)
57+
endif()
58+
5059
include(cmake/detect-arch.cmake)
5160
include(cmake/detect-install-dirs.cmake)
5261
include(cmake/detect-coverage.cmake)
@@ -79,9 +88,6 @@ option(WITH_GZFILEOP "Compile with support for gzFile related functions" ON)
7988
option(ZLIB_COMPAT "Compile with zlib compatible API" OFF)
8089
option(ZLIB_ENABLE_TESTS "Build test binaries" ON)
8190
option(ZLIBNG_ENABLE_TESTS "Test zlib-ng specific API" ON)
82-
option(WITH_GTEST "Build gtest_zlib" ON)
83-
option(WITH_FUZZERS "Build test/fuzz" OFF)
84-
option(WITH_BENCHMARKS "Build test/benchmarks" OFF)
8591
option(WITH_BENCHMARK_APPS "Build application benchmarks" OFF)
8692
option(WITH_OPTIM "Build with optimisation" ON)
8793
option(WITH_REDUCED_MEM "Reduced memory usage for special cases (reduces performance)" OFF)
@@ -362,6 +368,21 @@ if(MSVC)
362368
endif()
363369
endif()
364370

371+
#
372+
# Additional flags for features checking
373+
#
374+
set(ADDITIONAL_CHECK_FLAGS )
375+
if(APPLE)
376+
check_c_compiler_flag(-Werror=unguarded-availability HAVE_W_ERROR_UNGUARDED_AVAILABILITY)
377+
if(HAVE_W_ERROR_UNGUARDED_AVAILABILITY)
378+
set(ADDITIONAL_CHECK_FLAGS "${ADDITIONAL_CHECK_FLAGS} -Werror=unguarded-availability")
379+
endif()
380+
check_c_compiler_flag(-Werror=unguarded-availability-new HAVE_W_ERROR_UNGUARDED_AVAILABILITY_NEW)
381+
if(HAVE_W_ERROR_UNGUARDED_AVAILABILITY_NEW)
382+
set(ADDITIONAL_CHECK_FLAGS "${ADDITIONAL_CHECK_FLAGS} -Werror=unguarded-availability-new")
383+
endif()
384+
endif()
385+
365386
#
366387
# Check for standard/system includes
367388
#
@@ -407,28 +428,42 @@ set(CMAKE_REQUIRED_DEFINITIONS) # clear variable
407428
#
408429
# Check for fseeko and other optional functions
409430
#
431+
set(CMAKE_REQUIRED_FLAGS "${ADDITIONAL_CHECK_FLAGS}")
410432
check_function_exists(fseeko HAVE_FSEEKO)
411433
if(NOT HAVE_FSEEKO)
412434
add_definitions(-DNO_FSEEKO)
413435
endif()
436+
set(CMAKE_REQUIRED_FLAGS)
414437

438+
set(CMAKE_REQUIRED_FLAGS "${ADDITIONAL_CHECK_FLAGS}")
415439
check_function_exists(strerror HAVE_STRERROR)
416440
if(NOT HAVE_STRERROR)
417441
add_definitions(-DNO_STRERROR)
418442
endif()
443+
set(CMAKE_REQUIRED_FLAGS)
419444

420-
set(CMAKE_REQUIRED_DEFINITIONS -D_POSIX_C_SOURCE=200112L)
445+
#
446+
# Check for aligned memory allocation support: POSIX
447+
#
448+
set(CMAKE_REQUIRED_DEFINITIONS -D_POSIX_C_SOURCE=200112L -D_ISOC11_SOURCE=1)
449+
set(CMAKE_REQUIRED_FLAGS "${ADDITIONAL_CHECK_FLAGS}")
421450
check_symbol_exists(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN)
422451
if(HAVE_POSIX_MEMALIGN)
423452
add_definitions(-DHAVE_POSIX_MEMALIGN)
424453
endif()
454+
set(CMAKE_REQUIRED_FLAGS)
425455
set(CMAKE_REQUIRED_DEFINITIONS)
426456

427-
set(CMAKE_REQUIRED_DEFINITIONS -D_ISOC11_SOURCE=1)
457+
#
458+
# Check for aligned memory allocation support: C11
459+
#
460+
set(CMAKE_REQUIRED_DEFINITIONS -D_POSIX_C_SOURCE=200112L -D_ISOC11_SOURCE=1)
461+
set(CMAKE_REQUIRED_FLAGS "${ADDITIONAL_CHECK_FLAGS}")
428462
check_symbol_exists(aligned_alloc stdlib.h HAVE_ALIGNED_ALLOC)
429463
if(HAVE_ALIGNED_ALLOC)
430464
add_definitions(-DHAVE_ALIGNED_ALLOC)
431465
endif()
466+
set(CMAKE_REQUIRED_FLAGS)
432467
set(CMAKE_REQUIRED_DEFINITIONS)
433468

434469
if(WITH_SANITIZER STREQUAL "Address")
@@ -577,13 +612,6 @@ if(MSVC)
577612
add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)
578613
endif()
579614

580-
if(BASEARCH_X86_FOUND)
581-
# FORCE_SSE2 option will only be shown if HAVE_SSE2_INTRIN is true
582-
if("${ARCH}" MATCHES "i[3-6]86")
583-
cmake_dependent_option(FORCE_SSE2 "Always assume CPU is SSE2 capable" OFF "HAVE_SSE2_INTRIN" OFF)
584-
endif()
585-
endif()
586-
587615
#
588616
# Enable deflate_quick at level 1
589617
#
@@ -902,6 +930,10 @@ if(WITH_OPTIM)
902930
endif()
903931
if(WITH_SSE2)
904932
check_sse2_intrinsics()
933+
# FORCE_SSE2 option will only be shown if HAVE_SSE2_INTRIN is true
934+
if("${ARCH}" MATCHES "i[3-6]86")
935+
cmake_dependent_option(FORCE_SSE2 "Always assume CPU is SSE2 capable" OFF "HAVE_SSE2_INTRIN" OFF)
936+
endif()
905937
if(HAVE_SSE2_INTRIN)
906938
add_definitions(-DX86_SSE2)
907939
set(SSE2_SRCS ${ARCHDIR}/chunkset_sse2.c ${ARCHDIR}/compare256_sse2.c ${ARCHDIR}/slide_hash_sse2.c)
@@ -1064,6 +1096,12 @@ else()
10641096
set(PC_INC_INSTALL_DIR "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
10651097
endif()
10661098

1099+
if(IS_ABSOLUTE "${CMAKE_INSTALL_BINDIR}")
1100+
set(PC_BIN_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}")
1101+
else()
1102+
set(PC_BIN_INSTALL_DIR "\${exec_prefix}/${CMAKE_INSTALL_BINDIR}")
1103+
endif()
1104+
10671105
if(IS_ABSOLUTE "${CMAKE_INSTALL_LIBDIR}")
10681106
set(PC_LIB_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}")
10691107
else()

src/native/external/zlib-ng/Makefile.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ LDSHARED=$(CC)
3030
LDSHAREDFLAGS=-shared
3131
LDVERSIONSCRIPT=
3232

33-
VER=2.2.4
33+
VER=2.2.5
3434
VER1=2
3535

3636
STATICLIB=$(LIBNAME1).a
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Makefile for zlib-ng
2+
# Copyright (C) 1995-2013 Jean-loup Gailly, Mark Adler
3+
# Copyright (C) 2024 Hans Kristian Rosbach
4+
# Copyright (C) 2025 Yin Tong <[email protected]>, ByteDance
5+
# For conditions of distribution and use, see copyright notice in zlib.h
6+
7+
CC=
8+
CFLAGS=
9+
SFLAGS=
10+
INCLUDES=
11+
SUFFIX=
12+
13+
SRCDIR=.
14+
SRCTOP=../..
15+
TOPDIR=$(SRCTOP)
16+
17+
RVVFLAG=
18+
19+
all: \
20+
riscv_features.o riscv_features.lo \
21+
adler32_rvv.o adler32_rvv.lo \
22+
chunkset_rvv.o chunkset_rvv.lo \
23+
compare256_rvv.o compare256_rvv.lo \
24+
slide_hash_rvv.o slide_hash_rvv.lo
25+
26+
riscv_features.o: $(SRCDIR)/riscv_features.c
27+
$(CC) $(CFLAGS) $(RVVFLAG) $(INCLUDES) -c -o $@ $(SRCDIR)/riscv_features.c
28+
29+
riscv_features.lo: $(SRCDIR)/riscv_features.c
30+
$(CC) $(SFLAGS) $(RVVFLAG) -DPIC $(INCLUDES) -c -o $@ $(SRCDIR)/riscv_features.c
31+
32+
adler32_rvv.o: $(SRCDIR)/adler32_rvv.c
33+
$(CC) $(CFLAGS) $(RVVFLAG) $(INCLUDES) -c -o $@ $(SRCDIR)/adler32_rvv.c
34+
35+
adler32_rvv.lo: $(SRCDIR)/adler32_rvv.c
36+
$(CC) $(SFLAGS) $(RVVFLAG) -DPIC $(INCLUDES) -c -o $@ $(SRCDIR)/adler32_rvv.c
37+
38+
chunkset_rvv.o: $(SRCDIR)/chunkset_rvv.c
39+
$(CC) $(CFLAGS) $(RVVFLAG) $(INCLUDES) -c -o $@ $(SRCDIR)/chunkset_rvv.c
40+
41+
chunkset_rvv.lo: $(SRCDIR)/chunkset_rvv.c
42+
$(CC) $(SFLAGS) $(RVVFLAG) -DPIC $(INCLUDES) -c -o $@ $(SRCDIR)/chunkset_rvv.c
43+
44+
compare256_rvv.o: $(SRCDIR)/compare256_rvv.c
45+
$(CC) $(CFLAGS) $(RVVFLAG) $(INCLUDES) -c -o $@ $(SRCDIR)/compare256_rvv.c
46+
47+
compare256_rvv.lo: $(SRCDIR)/compare256_rvv.c
48+
$(CC) $(SFLAGS) $(RVVFLAG) -DPIC $(INCLUDES) -c -o $@ $(SRCDIR)/compare256_rvv.c
49+
50+
slide_hash_rvv.o: $(SRCDIR)/slide_hash_rvv.c
51+
$(CC) $(CFLAGS) $(RVVFLAG) $(INCLUDES) -c -o $@ $(SRCDIR)/slide_hash_rvv.c
52+
53+
slide_hash_rvv.lo: $(SRCDIR)/slide_hash_rvv.c
54+
$(CC) $(SFLAGS) $(RVVFLAG) -DPIC $(INCLUDES) -c -o $@ $(SRCDIR)/slide_hash_rvv.c
55+
56+
mostlyclean: clean
57+
clean:
58+
rm -f *.o *.lo *~
59+
rm -rf objs
60+
rm -f *.gcda *.gcno *.gcov
61+
62+
distclean: clean
63+
rm -f Makefile

src/native/external/zlib-ng/arch/riscv/chunkset_rvv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ static inline uint8_t* CHUNKCOPY(uint8_t *out, uint8_t const *from, unsigned len
9292
from += align;
9393
len -= align;
9494
ptrdiff_t dist = out - from;
95-
if (dist >= len) {
95+
if (dist < 0 || dist >= len) {
9696
memcpy(out, from, len);
9797
out += len;
9898
from += len;

src/native/external/zlib-ng/arch/s390/s390_functions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ uint32_t crc32_s390_vx(uint32_t crc, const uint8_t *buf, size_t len);
2020
#ifdef DISABLE_RUNTIME_CPU_DETECTION
2121
# if defined(S390_CRC32_VX) && defined(__zarch__) && __ARCH__ >= 11 && defined(__VX__)
2222
# undef native_crc32
23-
# define native_crc32 = crc32_s390_vx
23+
# define native_crc32 crc32_s390_vx
2424
# endif
2525
#endif
2626

src/native/external/zlib-ng/arch/x86/chunkset_avx512.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ static inline uint8_t* CHUNKCOPY(uint8_t *out, uint8_t const *from, unsigned len
9898
return out;
9999
}
100100

101+
/* MSVC compiler decompression bug when optimizing for size */
102+
#if defined(_MSC_VER) && _MSC_VER < 1943
103+
# pragma optimize("", off)
104+
#endif
101105
static inline chunk_t GET_CHUNK_MAG(uint8_t *buf, uint32_t *chunk_rem, uint32_t dist) {
102106
lut_rem_pair lut_rem = perm_idx_lut[dist - 3];
103107
__m256i ret_vec;
@@ -128,6 +132,9 @@ static inline chunk_t GET_CHUNK_MAG(uint8_t *buf, uint32_t *chunk_rem, uint32_t
128132

129133
return ret_vec;
130134
}
135+
#if defined(_MSC_VER) && _MSC_VER < 1943
136+
# pragma optimize("", on)
137+
#endif
131138

132139
static inline void storehalfchunk(uint8_t *out, halfchunk_t *chunk) {
133140
_mm_storeu_si128((__m128i *)out, *chunk);

src/native/external/zlib-ng/arch/x86/x86_features.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,17 @@ void Z_INTERNAL x86_check_features(struct x86_cpu_features *features) {
8686
}
8787

8888
if (maxbasic >= 7) {
89+
// Reference: https://software.intel.com/sites/default/files/article/405250/how-to-detect-new-instruction-support-in-the-4th-generation-intel-core-processor-family.pdf
8990
cpuidex(7, 0, &eax, &ebx, &ecx, &edx);
9091

91-
// check BMI1 bit
92-
// Reference: https://software.intel.com/sites/default/files/article/405250/how-to-detect-new-instruction-support-in-the-4th-generation-intel-core-processor-family.pdf
93-
features->has_vpclmulqdq = ecx & 0x400;
92+
// check BMI2 bit
93+
features->has_bmi2 = ebx & 0x8;
9494

9595
// check AVX2 bit if the OS supports saving YMM registers
9696
if (features->has_os_save_ymm) {
9797
features->has_avx2 = ebx & 0x20;
9898
}
9999

100-
features->has_bmi2 = ebx & 0x8;
101-
102100
// check AVX512 bits if the OS supports saving ZMM registers
103101
if (features->has_os_save_zmm) {
104102
features->has_avx512f = ebx & 0x00010000;
@@ -112,6 +110,7 @@ void Z_INTERNAL x86_check_features(struct x86_cpu_features *features) {
112110
features->has_avx512_common = features->has_avx512f && features->has_avx512dq && features->has_avx512bw \
113111
&& features->has_avx512vl && features->has_bmi2;
114112
features->has_avx512vnni = ecx & 0x800;
113+
features->has_vpclmulqdq = ecx & 0x400;
115114
}
116115
}
117116
}

src/native/external/zlib-ng/arch/x86/x86_functions.h

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ uint32_t crc32_vpclmulqdq(uint32_t crc32, const uint8_t *buf, size_t len);
9090
# undef native_longest_match_slow
9191
# define native_longest_match_slow longest_match_slow_sse2
9292
# endif
93-
#endif
93+
# endif
9494
// X86 - SSSE3
9595
# if defined(X86_SSSE3) && defined(__SSSE3__)
9696
# undef native_adler32
@@ -105,21 +105,20 @@ uint32_t crc32_vpclmulqdq(uint32_t crc32, const uint8_t *buf, size_t len);
105105
# undef native_adler32_fold_copy
106106
# define native_adler32_fold_copy adler32_fold_copy_sse42
107107
# endif
108-
109108
// X86 - PCLMUL
110-
#if defined(X86_PCLMULQDQ_CRC) && defined(__PCLMUL__)
111-
# undef native_crc32
112-
# define native_crc32 crc32_pclmulqdq
113-
# undef native_crc32_fold
114-
# define native_crc32_fold crc32_fold_pclmulqdq
115-
# undef native_crc32_fold_copy
116-
# define native_crc32_fold_copy crc32_fold_pclmulqdq_copy
117-
# undef native_crc32_fold_final
118-
# define native_crc32_fold_final crc32_fold_pclmulqdq_final
119-
# undef native_crc32_fold_reset
120-
# define native_crc32_fold_reset crc32_fold_pclmulqdq_reset
121-
#endif
122-
// X86 - AVX
109+
# if defined(X86_PCLMULQDQ_CRC) && defined(__PCLMUL__)
110+
# undef native_crc32
111+
# define native_crc32 crc32_pclmulqdq
112+
# undef native_crc32_fold
113+
# define native_crc32_fold crc32_fold_pclmulqdq
114+
# undef native_crc32_fold_copy
115+
# define native_crc32_fold_copy crc32_fold_pclmulqdq_copy
116+
# undef native_crc32_fold_final
117+
# define native_crc32_fold_final crc32_fold_pclmulqdq_final
118+
# undef native_crc32_fold_reset
119+
# define native_crc32_fold_reset crc32_fold_pclmulqdq_reset
120+
# endif
121+
// X86 - AVX2
123122
# if defined(X86_AVX2) && defined(__AVX2__)
124123
# undef native_adler32
125124
# define native_adler32 adler32_avx2
@@ -142,7 +141,6 @@ uint32_t crc32_vpclmulqdq(uint32_t crc32, const uint8_t *buf, size_t len);
142141
# define native_longest_match_slow longest_match_slow_avx2
143142
# endif
144143
# endif
145-
146144
// X86 - AVX512 (F,DQ,BW,Vl)
147145
# if defined(X86_AVX512) && defined(__AVX512F__) && defined(__AVX512DQ__) && defined(__AVX512BW__) && defined(__AVX512VL__)
148146
# undef native_adler32

0 commit comments

Comments
 (0)