Skip to content

Commit 7e41ae6

Browse files
authored
Update zlib-ng to 2.2.4 (dotnet#116044)
* Update zlib-ng to 2.2.4 * Fix MSVC build of zlib-ng
1 parent d44d5d6 commit 7e41ae6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+1144
-1503
lines changed
Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
v2.2.1
2-
d54e3769be0c522015b784eca2af258b1c026107
1+
v2.2.4
2+
860e4cff7917d93f54f5d7f0bc1d0e8b1a3cb988
33

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

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

8+
- zlib-ng/.github/
89
- zlib-ng/doc/
910
- zlib-ng/test/
1011
- zlib-ng/arch/s390/self-hosted-builder/
1112

12-
Also, if the next version does not yet contain the fixes included in 12bc7edc73308f017ec40c6b2db694a6e3490ac2, cherry-pick it as a patch.
13-
14-
Apply https://github.com/zlib-ng/zlib-ng/pull/1812
15-
Apply https://github.com/zlib-ng/zlib-ng/pull/1853

src/native/external/zlib-ng.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ if (CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI)
3131
endif()
3232
endif()
3333

34+
if (MSVC)
35+
#zlib-ng sets /utf-8 which clashes with /source-charset:utf-8 that we set centrally
36+
get_directory_property(dirCompileOptions COMPILE_OPTIONS)
37+
string(REPLACE "/source-charset:utf-8" "" dirCompileOptions "${dirCompileOptions}")
38+
set_directory_properties(PROPERTIES COMPILE_OPTIONS "${dirCompileOptions}")
39+
endif()
40+
3441
set(BUILD_SHARED_LIBS OFF) # Shared libraries aren't supported in wasm
3542
set(SKIP_INSTALL_ALL ON)
3643
FetchContent_MakeAvailable(fetchzlibng)
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
* text=auto
2-
*.abi text eol=lf
3-
*.c text
4-
*.h text
5-
*.sh text eol=lf
1+
# By default, enforce LF line-endings on all files that are not considered binary files!
2+
* text=auto eol=lf
3+
64
crc32_braid_tbl.h hooks-max-size=1000000
7-
Makefile text
8-
configure text eol=lf
5+
6+
# Don't export git/github-related files in tar/zip archives
7+
/.github export-ignore
8+
.gitattributes export-ignore
9+
.gitignore export-ignore

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
/switchlevels
2828
/zlib.pc
2929
/zlib-ng.pc
30+
/zconf-ng.h.included
31+
/zlib_name_mangling-ng.h
32+
/zlib-ng.h
3033

3134
.DS_Store
3235
*_fuzzer
@@ -61,6 +64,7 @@ zconf-ng.h.cmakein
6164
ztest*
6265
/test/CTestTestfile.cmake
6366
/test/cmake_install.cmake
67+
/.cache
6468

6569
configure.log
6670
a.out
@@ -72,6 +76,10 @@ a.out
7276
/arch/x86/Makefile
7377
.kdev4
7478
*.kdev4
79+
Makefile.tmp
80+
/makecrct
81+
/maketrees
82+
gzread.c
7583

7684
/Debug
7785
/example.dir

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

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,20 @@ if(CMAKE_VERSION VERSION_LESS 3.12)
44
endif()
55
message(STATUS "Using CMake version ${CMAKE_VERSION}")
66

7+
if(POLICY CMP0169)
8+
cmake_policy(SET CMP0169 OLD) # CMake 3.30: call FetchContent_Populate() with just the name of a dependency
9+
endif()
10+
711
# If not specified on the command line, enable C11 as the default
812
# Configuration items that affect the global compiler environment standards
913
# should be issued before the "project" command.
10-
if(NOT CMAKE_C_STANDARD)
14+
if(NOT DEFINED CMAKE_C_STANDARD)
1115
set(CMAKE_C_STANDARD 11) # The C standard whose features are requested to build this target
1216
endif()
13-
if(NOT CMAKE_C_STANDARD_REQUIRED)
17+
if(NOT DEFINED CMAKE_C_STANDARD_REQUIRED)
1418
set(CMAKE_C_STANDARD_REQUIRED ON) # Boolean describing whether the value of C_STANDARD is a requirement
1519
endif()
16-
if(NOT CMAKE_C_EXTENSIONS)
20+
if(NOT DEFINED CMAKE_C_EXTENSIONS)
1721
set(CMAKE_C_EXTENSIONS OFF) # Boolean specifying whether compiler specific extensions are requested
1822
endif()
1923
set(VALID_C_STANDARDS "99" "11")
@@ -89,7 +93,6 @@ option(WITH_MAINTAINER_WARNINGS "Build with project maintainer warnings" OFF)
8993
option(WITH_CODE_COVERAGE "Enable code coverage reporting" OFF)
9094
option(WITH_INFLATE_STRICT "Build with strict inflate distance checking" OFF)
9195
option(WITH_INFLATE_ALLOW_INVALID_DIST "Build with zero fill for inflate invalid distances" OFF)
92-
option(WITH_UNALIGNED "Support unaligned reads on platforms that support it" ON)
9396

9497
set(ZLIB_SYMBOL_PREFIX "" CACHE STRING "Give this prefix to all publicly exported symbols.
9598
Useful when embedding into a larger library.
@@ -102,7 +105,7 @@ set_property(CACHE WITH_SANITIZER PROPERTY STRINGS "Memory" "Address" "Undefined
102105
if(BASEARCH_ARM_FOUND)
103106
option(WITH_ACLE "Build with ACLE" ON)
104107
option(WITH_NEON "Build with NEON intrinsics" ON)
105-
cmake_dependent_option(WITH_ARMV6 "Build with ARMv6 SIMD" ON "NOT ARCH STREQUAL \"aarch64\"" OFF)
108+
cmake_dependent_option(WITH_ARMV6 "Build with ARMv6 SIMD" ON "NOT ARCH MATCHES \"aarch64\"" OFF)
106109
elseif(BASEARCH_PPC_FOUND)
107110
option(WITH_ALTIVEC "Build with AltiVec (VMX) optimisations for PowerPC" ON)
108111
option(WITH_POWER8 "Build with optimisations for POWER8" ON)
@@ -143,7 +146,6 @@ mark_as_advanced(FORCE
143146
WITH_RVV
144147
WITH_INFLATE_STRICT
145148
WITH_INFLATE_ALLOW_INVALID_DIST
146-
WITH_UNALIGNED
147149
INSTALL_UTILS
148150
)
149151

@@ -189,9 +191,9 @@ elseif(MSVC)
189191
# (who'd use cmake from an IDE...) but checking for ICC before checking for MSVC should
190192
# avoid mistakes.
191193
# /Oi ?
192-
set(WARNFLAGS /W3)
194+
set(WARNFLAGS /W3 /w34242 /WX)
193195
set(WARNFLAGS_MAINTAINER /W4)
194-
set(WARNFLAGS_DISABLE)
196+
set(WARNFLAGS_DISABLE /wd4206 /wd4054 /wd4324)
195197
if(BASEARCH_ARM_FOUND)
196198
add_definitions(-D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE)
197199
if(NOT "${ARCH}" MATCHES "aarch64")
@@ -299,7 +301,7 @@ if(NOT WITH_RUNTIME_CPU_DETECTION)
299301
message(STATUS "WARNING: Microsoft Visual Studio does not support compile time detection of CPU features for \"/arch\" before \"AVX\"")
300302
# Workaround for MSVC. By default MSVC does not define the __SSE*__ macros.
301303
# Fix it if AVX is enabled.
302-
set(CMAKE_REQUIRED_FLAGS "${NATIVEFLAG}")
304+
set(CMAKE_REQUIRED_FLAGS "${NATIVEFLAG} ${ZNOLTOFLAG}")
303305
check_c_source_compiles(
304306
"#ifndef __AVX__
305307
# error \"AVX is not enabled.\"
@@ -332,12 +334,6 @@ if(NOT WITH_NATIVE_INSTRUCTIONS)
332334
endforeach()
333335
endif()
334336

335-
# Set architecture alignment requirements
336-
if(NOT WITH_UNALIGNED)
337-
add_definitions(-DNO_UNALIGNED)
338-
message(STATUS "Unaligned reads manually disabled")
339-
endif()
340-
341337
# Apply warning compiler flags
342338
if(WITH_MAINTAINER_WARNINGS)
343339
add_compile_options(${WARNFLAGS} ${WARNFLAGS_MAINTAINER} ${WARNFLAGS_DISABLE})
@@ -356,6 +352,16 @@ if(NOT WITH_CODE_COVERAGE AND NOT MSVC AND NOT CMAKE_C_FLAGS MATCHES "([\\/\\-]O
356352
CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
357353
endif()
358354

355+
# Force Visual C++ to use UTF-8
356+
if(MSVC)
357+
if (NOT CMAKE_C_FLAGS MATCHES "[\\/\\-]utf-8")
358+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /utf-8")
359+
endif()
360+
if (NOT CMAKE_CXX_FLAGS MATCHES "[\\/\\-]utf-8")
361+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8")
362+
endif()
363+
endif()
364+
359365
#
360366
# Check for standard/system includes
361367
#
@@ -485,6 +491,7 @@ endif()
485491
#
486492
# Check for __builtin_assume_aligned(x,n) support in the compiler
487493
#
494+
set(CMAKE_REQUIRED_FLAGS ${ZNOLTOFLAG})
488495
check_c_source_compiles(
489496
"char *test(char *buffer) {
490497
char *abuffer = __builtin_assume_aligned(buffer,64);
@@ -497,10 +504,12 @@ check_c_source_compiles(
497504
if(HAVE_BUILTIN_ASSUME_ALIGNED)
498505
add_definitions(-DHAVE_BUILTIN_ASSUME_ALIGNED)
499506
endif()
507+
set(CMAKE_REQUIRED_FLAGS)
500508

501509
#
502510
# check for __builtin_ctz() support in the compiler
503511
#
512+
set(CMAKE_REQUIRED_FLAGS ${ZNOLTOFLAG})
504513
check_c_source_compiles(
505514
"int main(void) {
506515
unsigned int zero = 0;
@@ -513,10 +522,12 @@ check_c_source_compiles(
513522
if(HAVE_BUILTIN_CTZ)
514523
add_definitions(-DHAVE_BUILTIN_CTZ)
515524
endif()
525+
set(CMAKE_REQUIRED_FLAGS)
516526

517527
#
518528
# check for __builtin_ctzll() support in the compiler
519529
#
530+
set(CMAKE_REQUIRED_FLAGS ${ZNOLTOFLAG})
520531
check_c_source_compiles(
521532
"int main(void) {
522533
unsigned int zero = 0;
@@ -529,6 +540,7 @@ check_c_source_compiles(
529540
if(HAVE_BUILTIN_CTZLL)
530541
add_definitions(-DHAVE_BUILTIN_CTZLL)
531542
endif()
543+
set(CMAKE_REQUIRED_FLAGS)
532544

533545
#
534546
# check for ptrdiff_t support
@@ -965,8 +977,10 @@ if(WITH_OPTIM)
965977
add_definitions(-DX86_AVX512)
966978
list(APPEND AVX512_SRCS ${ARCHDIR}/adler32_avx512.c)
967979
add_feature_info(AVX512_ADLER32 1 "Support AVX512-accelerated adler32, using \"${AVX512FLAG}\"")
968-
list(APPEND ZLIB_ARCH_SRCS ${AVX512_SRCS})
980+
list(APPEND AVX512_SRCS ${ARCHDIR}/chunkset_avx512.c)
981+
add_feature_info(AVX512_CHUNKSET 1 "Support AVX512 optimized chunkset, using \"${AVX512FLAG}\"")
969982
list(APPEND ZLIB_ARCH_HDRS ${ARCHDIR}/adler32_avx512_p.h)
983+
list(APPEND ZLIB_ARCH_SRCS ${AVX512_SRCS})
970984
set_property(SOURCE ${AVX512_SRCS} PROPERTY COMPILE_FLAGS "${AVX512FLAG} ${NOLTOFLAG}")
971985
else()
972986
set(WITH_AVX512 OFF)
@@ -1066,6 +1080,9 @@ set(ZLIB_PUBLIC_HDRS
10661080
${CMAKE_CURRENT_BINARY_DIR}/zlib${SUFFIX}.h
10671081
)
10681082
set(ZLIB_PRIVATE_HDRS
1083+
arch/generic/chunk_permute_table.h
1084+
arch/generic/compare256_p.h
1085+
arch/generic/generic_functions.h
10691086
adler32_p.h
10701087
chunkset_tpl.h
10711088
compare256_rle.h
@@ -1172,10 +1189,6 @@ if (ZLIB_COMPAT)
11721189
endif()
11731190
endif()
11741191

1175-
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
1176-
include_directories(${ARCHDIR})
1177-
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/arch/generic)
1178-
11791192
foreach(ZLIB_INSTALL_LIBRARY ${ZLIB_INSTALL_LIBRARIES})
11801193
if(NOT ZLIB_COMPAT)
11811194
target_compile_definitions(${ZLIB_INSTALL_LIBRARY} PUBLIC ZLIBNG_NATIVE_API)

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.1
33+
VER=2.2.4
3434
VER1=2
3535

3636
STATICLIB=$(LIBNAME1).a

src/native/external/zlib-ng/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Features
2525
* Compare256 implementations using SSE2, AVX2, Neon, POWER9 & RVV
2626
* Inflate chunk copying using SSE2, SSSE3, AVX, Neon & VSX
2727
* Support for hardware-accelerated deflate using IBM Z DFLTCC
28-
* Unaligned memory read/writes and large bit buffer improvements
28+
* Safe unaligned memory read/writes and large bit buffer improvements
2929
* Includes improvements from Cloudflare and Intel forks
3030
* Configure, CMake, and NMake build system support
3131
* Comprehensive set of CMake unit tests
@@ -213,7 +213,6 @@ Advanced Build Options
213213
| WITH_CRC32_VX | --without-crc32-vx | Build with vectorized CRC32 on IBM Z | ON |
214214
| WITH_DFLTCC_DEFLATE | --with-dfltcc-deflate | Build with DFLTCC intrinsics for compression on IBM Z | OFF |
215215
| WITH_DFLTCC_INFLATE | --with-dfltcc-inflate | Build with DFLTCC intrinsics for decompression on IBM Z | OFF |
216-
| WITH_UNALIGNED | --without-unaligned | Allow optimizations that use unaligned reads if safe on current arch| ON |
217216
| WITH_INFLATE_STRICT | | Build with strict inflate distance checking | OFF |
218217
| WITH_INFLATE_ALLOW_INVALID_DIST | | Build with zero fill for inflate invalid distances | OFF |
219218
| INSTALL_UTILS | | Copy minigzip and minideflate during install | OFF |

src/native/external/zlib-ng/adler32_fold.c

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/native/external/zlib-ng/adler32_fold.h

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/native/external/zlib-ng/arch/arm/arm_functions.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#ifdef ARM_NEON
99
uint32_t adler32_neon(uint32_t adler, const uint8_t *buf, size_t len);
1010
uint32_t chunksize_neon(void);
11-
uint8_t* chunkmemset_safe_neon(uint8_t *out, unsigned dist, unsigned len, unsigned left);
11+
uint8_t* chunkmemset_safe_neon(uint8_t *out, uint8_t *from, unsigned len, unsigned left);
1212

1313
# ifdef HAVE_BUILTIN_CTZLL
1414
uint32_t compare256_neon(const uint8_t *src0, const uint8_t *src1);
@@ -56,7 +56,7 @@ void slide_hash_armv6(deflate_state *s);
5656
# endif
5757
# endif
5858
// ARM - ACLE
59-
# if defined(ARM_ACLE) && defined(__ARM_ACLE) && defined(__ARM_FEATURE_CRC32)
59+
# if defined(ARM_ACLE) && (defined(__ARM_ACLE) || defined(__ARM_FEATURE_CRC32))
6060
# undef native_crc32
6161
# define native_crc32 crc32_acle
6262
# endif

0 commit comments

Comments
 (0)