tree: 0d4c77854213d972cbdd0aaf5a0753988afb4247 [path history] [tgz]
  1. .github/
  2. arch/
  3. cmake/
  4. doc/
  5. test/
  6. tools/
  7. win32/
  8. .gitattributes
  9. .gitignore
  10. .shellcheckrc
  11. adler32.c
  12. adler32_p.h
  13. chunkset.c
  14. chunkset_tpl.h
  15. CMakeLists.txt
  16. compare258.c
  17. compress.c
  18. configure
  19. crc32.c
  20. crc32_p.h
  21. crc32_tbl.h
  22. deflate.c
  23. deflate.h
  24. deflate_fast.c
  25. deflate_medium.c
  26. deflate_p.h
  27. deflate_quick.c
  28. deflate_slow.c
  29. fallback_builtins.h
  30. FAQ.zlib
  31. functable.c
  32. functable.h
  33. gzclose.c
  34. gzguts.h
  35. gzlib.c
  36. gzread.c
  37. gzwrite.c
  38. INDEX.md
  39. infback.c
  40. inffast.c
  41. inffast.h
  42. inffixed_tbl.h
  43. inflate.c
  44. inflate.h
  45. inflate_p.h
  46. inftrees.c
  47. inftrees.h
  48. insert_string.c
  49. insert_string_tpl.h
  50. LICENSE.md
  51. Makefile.in
  52. match_tpl.h
  53. README.md
  54. trees.c
  55. trees.h
  56. trees_emit.h
  57. trees_tbl.h
  58. uncompr.c
  59. zbuild.h
  60. zconf-ng.h.in
  61. zconf.h.in
  62. zendian.h
  63. zlib-ng.h
  64. zlib-ng.map
  65. zlib.3
  66. zlib.h
  67. zlib.map
  68. zlib.pc.cmakein
  69. zlib.pc.in
  70. zutil.c
  71. zutil.h
src/zlib-ng/README.md

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)

CIStatus
GitHub ActionsMaster Branch Status Master Branch Status Master Branch Status
BuildkiteBuild status
CodeFactorCodeFactor
OSS-FuzzFuzzing Status
Codecovcodecov.io

Fork Motivation

The motivation for this fork was due to 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 have contributed both small and big improvements, or valuable testing.

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

Features

  • Zlib compatible API with support for dual-linking
  • Modernized native API based on zlib API for ease of porting
  • Intel deflate medium and quick algorithms
  • Support for CPU intrinsics when available
    • Adler32 implementation using SSSE3, AVX2, Neon, & VSX
    • Intel CRC32-B implementation using PCLMULQDQ
    • Intel CRC32-C intrinsics for hash tables
    • ARM CRC32-B implementation using ACLE
    • Slide hash implementations using SSE2, AVX2, Neon, & VSX
    • Inflate chunk copying using SSE2 & Neon
    • Deflate hooks for IBM Z DFLTCC
  • 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
  • Unaligned memory read/writes and large bit buffer improvements
  • Includes improvements from Cloudflare and Intel forks
  • Configure, CMake, and NMake build system support
  • Modern C99 syntax and a clean code layout
  • Comprehensive set of CMake unit tests

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

CMakeconfigureDescriptionDefault
ZLIB_COMPAT--zlib-compatCompile with zlib compatible APIOFF
ZLIB_ENABLE_TESTSBuild test binariesON
WITH_GZFILEOP--with-gzfileopsCompile with support for gzFile related functionsOFF
WITH_MSAN--with-msanBuild with memory sanitizerOFF
WITH_OPTIM--without-optimizationsBuild with optimisationsON
WITH_NEW_STRATEGIES--without-new-strategiesUse new strategiesON
WITH_NATIVE_INSTRUCTIONS--nativeCompiles with full instruction set supported on this host (gcc/clang -march=native)OFF
WITH_SANITIZERS--with-sanitizersBuild with address sanitizer and all supported sanitizers other than memory sanitizerOFF
WITH_FUZZERS--with-fuzzersBuild test/fuzzOFF
WITH_MAINTAINER_WARNINGSBuild with project maintainer warningsOFF
WITH_CODE_COVERAGEEnable code coverage reportingOFF

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 young project, and we aim 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

CMakeconfigureDescriptionDefault
ZLIB_DUAL_LINKDual link tests with system zlibOFF
UNALIGNED_OKAllow unaligned readsON (x86, arm)
--force-sse2Assume SSE2 instructions are always availableON (x86), OFF (x86_64)
WITH_AVX2Build with AVX2 intrinsicsON
WITH_SSE2Build with SSE2 intrinsicsON
WITH_SSE4Build with SSE4 intrinsicsON
WITH_PCLMULQDQBuild with PCLMULQDQ intrinsicsON
WITH_ACLE--without-acleBuild with ACLE intrinsicsON
WITH_NEON--without-neonBuild with NEON intrinsicsON
WITH_POWER8Build with POWER8 optimisationsON
WITH_DFLTCC_DEFLATE--with-dfltcc-deflateUse DEFLATE COMPRESSION CALL instruction for compression on IBM ZOFF
WITH_DFLTCC_INFLATE--with-dfltcc-inflateUse DEFLATE COMPRESSION CALL instruction for decompression on IBM ZOFF
WITH_INFLATE_STRICTBuild with strict inflate distance checkingOFF
WITH_INFLATE_ALLOW_INVALID_DISTBuild with zero fill for inflate invalid distancesOFF
INSTALL_UTILSCopy minigzip and minigzip during installOFF