zlib replacement with optimizations for "next generation" systems.
Go to file
Hans Kristian Rosbach aeffa9bbf4 Remove misleading manpage.
README.md changes:
- Added a related projects section at the end.
- Added blank line after header where missing.
- Added extra blank line before header to make them easier to spot as plain-text.
- Changed line-length for Contributing section, to make it more readable as plain-text.
2021-03-09 16:44:07 +01:00
.github/workflows Upload build log for pkgcheck CI when fails. 2021-02-26 09:30:01 +01:00
arch darwin ios/mac m1 cpu features detection update proposal 2021-01-05 17:06:17 +01:00
cmake Move code coverage detection into its own cmake file. 2021-02-17 14:59:16 +01:00
doc zlib 1.2.5.1 2011-09-11 11:04:49 -07:00
test Always canonicalize CHOST when building original zlib even after automatic CHOST detection. 2021-01-28 13:35:56 +01:00
tools Fix error in comment on the polynomial representation of a byte. 2021-02-03 12:41:32 +01:00
win32 Separate crc32 and crc32_combine tables so the crc32_combine tables are not included when not used if statically linking. Reduces code size by 4k. 2020-11-22 20:33:54 +01:00
.gitattributes Add a.exe to cleanup list. 2017-01-30 10:36:53 +01:00
.gitignore Make static libraries produced by cmake and configure identical. 2020-07-13 16:25:34 +02:00
.shellcheckrc Import default codecfactor.io .shellcheckrc file. 2020-03-09 14:13:36 +01:00
adler32_p.h Remove NO_DIVIDE from adler32. 2020-08-16 17:37:04 +02:00
adler32.c Rename ZEXPORT and ZEXTERN for consistency. 2020-08-31 12:33:16 +02:00
chunkset_tpl.h Fixed conditional expression is constant maintainer warnings. 2020-11-02 17:01:58 +01:00
chunkset.c Prevent unaligned double word accesses on ARMv7 in chunkset_c 2020-08-20 12:04:56 +02:00
CMakeLists.txt Remove misleading manpage. 2021-03-09 16:44:07 +01:00
compare258.c Fixed match_byte casting warning in compare256_unaligned_64_static. 2020-09-16 09:10:48 +02:00
compress.c Rename ZEXPORT and ZEXTERN for consistency. 2020-08-31 12:33:16 +02:00
configure Only set CPU feature flags in configure script if not using native instructions. 2021-02-26 09:30:01 +01:00
crc32_comb_tbl.h Separate crc32 and crc32_combine tables so the crc32_combine tables are not included when not used if statically linking. Reduces code size by 4k. 2020-11-22 20:33:54 +01:00
crc32_comb.c Separate crc32 and crc32_combine tables so the crc32_combine tables are not included when not used if statically linking. Reduces code size by 4k. 2020-11-22 20:33:54 +01:00
crc32_p.h Add makecrct test and clean up makecrct.c code 2019-09-20 22:29:21 +02:00
crc32_tbl.h Separate crc32 and crc32_combine tables so the crc32_combine tables are not included when not used if statically linking. Reduces code size by 4k. 2020-11-22 20:33:54 +01:00
crc32.c Separate crc32 and crc32_combine tables so the crc32_combine tables are not included when not used if statically linking. Reduces code size by 4k. 2020-11-22 20:33:54 +01:00
deflate_fast.c Fixed unsigned integer overflow ASAN error when hash_head > s->strstart. 2020-10-18 14:35:55 +02:00
deflate_medium.c Fixed casting warnings when comparing MAX_DIST. 2020-11-02 17:01:58 +01:00
deflate_p.h Fixed casting warnings when comparing MAX_DIST. 2020-11-02 17:01:58 +01:00
deflate_quick.c Fixed unsigned integer overflow ASAN error when hash_head > s->strstart. 2020-10-18 14:35:55 +02:00
deflate_slow.c Fixed unsigned integer overflow ASAN error when hash_head > s->strstart. 2020-10-18 14:35:55 +02:00
deflate.c Remove debug check for match beginning at start of window. 2021-01-28 09:52:05 +01:00
deflate.h Add extra space in deflate internal_state struct for future expansion. 2021-01-27 14:07:22 +01:00
fallback_builtins.h Harmonize the CPU architecture preprocessor definitions. 2020-08-20 12:05:11 +02:00
FAQ.zlib zlib 1.2.11 2017-02-13 10:16:17 +01:00
functable.c Fixed conditional expression is constant maintainer warnings. 2020-11-02 17:01:58 +01:00
functable.h Fix numerous sign-conversion warnings in compare256/compare258 and 2020-08-31 13:22:54 +02:00
gzguts.h Rename ZLIB_INTERNAL to Z_INTERNAL for consistency. 2020-08-31 12:33:16 +02:00
gzlib.c Move gzclose() to gzlib.c. Modern linkers should be smart enough to link it in only if it is used. 2020-09-16 09:10:28 +02:00
gzread.c Fixed ubsan warning in gzfread due to size_t overflow. #783 2020-11-02 17:01:36 +01:00
gzwrite.c Allocate gzlib/gzread/gzwrite structs and in/out buffers using zng_alloc 2020-09-14 12:04:30 +02:00
INDEX.md Remove misleading manpage. 2021-03-09 16:44:07 +01:00
infback.c Fixed left shift ubsan warning in PULLBYTE. 2020-10-09 11:31:03 +02:00
inffast.c Small formatting changes in inflate.c, inflate.h and inffast.c 2020-10-24 15:51:46 +02:00
inffast.h Rename ZLIB_INTERNAL to Z_INTERNAL for consistency. 2020-08-31 12:33:16 +02:00
inffixed_tbl.h Fixed tab indentation for inffixed_tbl.h. 2020-09-24 15:42:02 +02:00
inflate_p.h inflate: add SET_BAD macro, to make inflate.c a little cleaner. 2020-10-24 15:51:46 +02:00
inflate.c Small formatting changes in inflate.c, inflate.h and inffast.c 2020-10-24 15:51:46 +02:00
inflate.h Small formatting changes in inflate.c, inflate.h and inffast.c 2020-10-24 15:51:46 +02:00
inftrees.c Remove some of the references to the unreleased zlib 1.2.12 2020-09-13 13:07:54 +02:00
inftrees.h Rename ZLIB_INTERNAL to Z_INTERNAL for consistency. 2020-08-31 12:33:16 +02:00
insert_string_tpl.h Fixed str uint32_t to uint16_t casting warnings in inflate_string_tpl.h 2020-11-02 17:01:58 +01:00
insert_string.c Increase hash table size from 15 to 16 bits. 2020-08-23 09:57:45 +02:00
LICENSE.md Update readme and create LICENSE.md file 2015-04-10 12:26:51 +02:00
Makefile.in Remove misleading manpage. 2021-03-09 16:44:07 +01:00
match_tpl.h Store result of early exit trigger at the top of longest_match. 2021-01-28 15:08:26 +01:00
PORTING.md Add porting guide. 2021-02-25 13:05:04 +01:00
README.md Remove misleading manpage. 2021-03-09 16:44:07 +01:00
trees_emit.h Rename ZLIB_INTERNAL to Z_INTERNAL for consistency. 2020-08-31 12:33:16 +02:00
trees_tbl.h Rename ZLIB_INTERNAL to Z_INTERNAL for consistency. 2020-08-31 12:33:16 +02:00
trees.c Fixed ubsan error when building tree with no symbols. #782 2020-11-02 18:14:34 +01:00
trees.h Renamed trees_p.h to trees.h. 2020-08-27 19:19:30 +02:00
uncompr.c Rename ZEXPORT and ZEXTERN for consistency. 2020-08-31 12:33:16 +02:00
zbuild.h Add optional support for thread local storage. (#733) 2020-08-23 09:59:38 +02:00
zconf-ng.h.in Rename ZEXPORT and ZEXTERN for consistency. 2020-08-31 12:33:16 +02:00
zconf.h.in Fixed missing large file defines in zconf.in that exist in zconf-ng.in. Accidentally removed from api cleanup. 2021-01-28 13:35:56 +01:00
zendian.h Clean up windows defines, use _WIN32 2020-06-08 15:09:17 +02:00
zlib-ng.h Explicitly note that the 32-bit check values are 32 bits. 2021-02-03 12:41:32 +01:00
zlib-ng.map Version 2.0.0 Release Candidate 1 2021-01-11 22:12:04 +01:00
zlib.h Explicitly note that the 32-bit check values are 32 bits. 2021-02-03 12:41:32 +01:00
zlib.map Fixed extra symbols added to ABI when zlib-compat specified. 2020-08-02 18:32:25 +02:00
zlib.pc.cmakein Sync cmake variable names with names already used by %cmake macros in 2021-01-16 15:17:18 +01:00
zlib.pc.in Rename library based on zlib-compat setting 2018-01-31 10:45:29 +01:00
zutil_p.h Increase zng_alloc alignment to 64-bytes for non-MacOS platforms. 2020-09-14 12:04:30 +02:00
zutil.c Version 2.0.0 Release Candidate 2 2021-01-29 09:48:01 +01:00
zutil.h Remove unused F_OPEN preprocessor macro. 2020-09-20 21:55:48 +02:00

zlib-ng

zlib data compression library for the next generation systems

Maintained by Hans Kristian Rosbach aka Dead2 (zlib-ng àt circlestorm dót org)

CI Status
GitHub Actions Master Branch Status Master Branch Status Master Branch Status
Buildkite Build status
CodeFactor CodeFactor
OSS-Fuzz Fuzzing Status
Codecov codecov.io

Features

  • Zlib compatible API with support for dual-linking
  • Modernized native API based on zlib API for ease of porting
  • Modern C99 syntax and a clean code layout
  • Deflate medium and quick algorithms based on Intels zlib fork
  • Support for CPU intrinsics when available
    • Adler32 implementation using SSSE3, AVX2, Neon & VSX
    • CRC32-B implementation using PCLMULQDQ & ACLE
    • Hash table implementation using CRC32-C intrinsics on x86 and ARM
    • Slide hash implementations using SSE2, AVX2, Neon & VSX
    • Compare256/258 implementations using SSE4.2 & AVX2
    • Inflate chunk copying using SSE2, AVX2 & Neon
    • Support for hardware-accelerated deflate using IBM Z DFLTCC
  • Unaligned memory read/writes and large bit buffer improvements
  • Includes improvements from Cloudflare and Intel forks
  • Configure, CMake, and NMake build system support
  • Comprehensive set of CMake unit tests
  • Code sanitizers, fuzzing, and coverage
  • GitHub Actions continuous integration on Windows, macOS, and Linux
    • Emulated CI for ARM, AARCH64, PPC, PPC64, SPARC64, S390x using qemu

History

The motivation for this fork came after seeing several 3rd party contributions containing new optimizations not getting implemented into the official zlib repository.

Mark Adler has been maintaining zlib for a very long time, and he has done a great job and hopefully he will continue for a long time yet. The idea of zlib-ng is not to replace zlib, but to co-exist as a drop-in replacement with a lower threshold for code change.

zlib has a long history and is incredibly portable, even supporting lots of systems that predate the Internet. This is great, but it does complicate further development and maintainability. The zlib code has numerous workarounds for old compilers that do not understand ANSI-C or to accommodate systems with limitations such as operating in a 16-bit environment.

Many of these workarounds are only maintenance burdens, some of them are pretty huge code-wise. For example, the [v]s[n]printf workaround code has a whopping 8 different implementations just to cater to various old compilers. With this many workarounds cluttered throughout the code, new programmers with an idea/interest for zlib will need to take some time to figure out why all of these seemingly strange things are used, and how to work within those confines.

So I decided to make a fork, merge all the Intel optimizations, merge the Cloudflare optimizations that did not conflict, plus a couple of other smaller patches. Then I started cleaning out workarounds, various dead code, all contrib and example code as there is little point in having those in this fork for various reasons.

A lot of improvements have gone into zlib-ng since its start, and numerous people and companies have contributed both small and big improvements, or valuable testing.

Please read LICENSE.md, it is very simple and very liberal.

Build

There are two ways to build zlib-ng:

Cmake

To build zlib-ng using the cross-platform makefile generator cmake.

cmake .
cmake --build . --config Release
ctest --verbose -C Release

Alternatively, you can use the cmake configuration GUI tool ccmake:

ccmake .

Configure

To build zlib-ng using the bash configure script:

./configure
make
make test

Build Options

CMake configure Description Default
ZLIB_COMPAT --zlib-compat Compile with zlib compatible API OFF
ZLIB_ENABLE_TESTS Build test binaries ON
WITH_GZFILEOP --without-gzfileops Compile with support for gzFile related functions ON
WITH_OPTIM --without-optimizations Build with optimisations ON
WITH_NEW_STRATEGIES --without-new-strategies Use new strategies ON
WITH_NATIVE_INSTRUCTIONS --native Compiles with full instruction set supported on this host (gcc/clang -march=native) OFF
WITH_SANITIZER --with-sanitizer Build with sanitizer (memory, address, undefined) OFF
WITH_FUZZERS --with-fuzzers Build test/fuzz OFF
WITH_MAINTAINER_WARNINGS Build with project maintainer warnings OFF
WITH_CODE_COVERAGE Enable code coverage reporting OFF

Install

WARNING: We do not recommend manually installing unless you really know what you are doing, because this can potentially override the system default zlib library, and any incompatibility or wrong configuration of zlib-ng can make the whole system unusable, requiring recovery or reinstall. If you still want a manual install, we recommend using the /opt/ path prefix.

For Linux distros, an alternative way to use zlib-ng (if compiled in zlib-compat mode) instead of zlib, is through the use of the LD_PRELOAD environment variable. If the program is dynamically linked with zlib, then zlib-ng will temporarily be used instead by the program, without risking system-wide instability.

LD_PRELOAD=/opt/zlib-ng/libz.so.1.2.11.zlib-ng /usr/bin/program

Cmake

To install zlib-ng system-wide using cmake:

cmake --build . --target install

Configure

To install zlib-ng system-wide using the configure script:

make install

Contributing

Zlib-ng is a aiming to be open to contributions, and we would be delighted to receive pull requests on github. Just remember that any code you submit must be your own and it must be zlib licensed. Help with testing and reviewing of pull requests etc is also very much appreciated.

If you are interested in contributing, please consider joining our IRC channel #zlib-ng on the Freenode IRC network.

Acknowledgments

Thanks to Servebolt.com for sponsoring my maintainership of zlib-ng.

Thanks go out to all the people and companies who have taken the time to contribute code reviews, testing and/or patches. Zlib-ng would not have been nearly as good without you.

The deflate format used by zlib was defined by Phil Katz. The deflate and zlib specifications were written by L. Peter Deutsch.

zlib was originally created by Jean-loup Gailly (compression) and Mark Adler (decompression).

Advanced Build Options

CMake configure Description Default
ZLIB_DUAL_LINK Dual link tests with system zlib OFF
UNALIGNED_OK Allow unaligned reads ON (x86, arm)
--force-sse2 Skip runtime check for SSE2 instructions (Always on for x86_64) OFF (x86)
WITH_AVX2 Build with AVX2 intrinsics ON
WITH_SSE2 Build with SSE2 intrinsics ON
WITH_SSE4 Build with SSE4 intrinsics ON
WITH_PCLMULQDQ Build with PCLMULQDQ intrinsics ON
WITH_ACLE --without-acle Build with ACLE intrinsics ON
WITH_NEON --without-neon Build with NEON intrinsics ON
WITH_POWER8 Build with POWER8 optimisations ON
WITH_DFLTCC_DEFLATE --with-dfltcc-deflate Build with DFLTCC intrinsics for compression on IBM Z OFF
WITH_DFLTCC_INFLATE --with-dfltcc-inflate Build with DFLTCC intrinsics for decompression on IBM Z OFF
WITH_UNALIGNED Allow optimizations that use unaligned reads if safe on current arch ON
WITH_INFLATE_STRICT Build with strict inflate distance checking OFF
WITH_INFLATE_ALLOW_INVALID_DIST Build with zero fill for inflate invalid distances OFF
INSTALL_UTILS Copy minigzip and minideflate during install OFF