GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-91349: Replace zlib with zlib-ng in Windows build by zooba · Pull Request #131438 · python/cpython

Conversation

@zooba

@zooba zooba commented Mar 19, 2025 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member
  • Issue: Use zlib-ng (fast!) rather than mainline stale zlib in binary releases #91349

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Wulian233 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
zooba added 4 commits March 19, 2025 00:56
@zooba
pythongh-91349: Replace zlib with zlib-ng in Windows build
de56164
@zooba
Updated readme.txt
1347c50
@zooba
Fix includes for PGO build
7fd8f26
@zooba
Use correct include dirs
f919749
@zooba
zooba requested a review from gpshead March 19, 2025 01:11
@zooba
zooba requested review from a team and sethmlarson as code owners March 19, 2025 01:11
@bedevere-app bedevere-app Bot added the awaiting core review label Mar 19, 2025
@bedevere-app bedevere-app Bot mentioned this pull request Mar 19, 2025
Use zlib-ng (fast!) rather than mainline stale zlib in binary releases #91349
Closed
@zooba
Add NEWS
fb6500d
zooba
zooba commented Mar 19, 2025
View reviewed changes
Comment thread Misc/externals.spdx.json
{
"referenceCategory": "SECURITY",
"referenceLocator": "cpe:2.3:a:zlib:zlib:1.3.1:*:*:*:*:*:*:*",
"referenceLocator": "cpe:2.3:a:zlib-ng:zlib-ng:2.2.4:*:*:*:*:*:*:*",

@zooba zooba Mar 19, 2025

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll admit I just guessed this, in order to unblock my testing (couldn't build at all with an invalid SBOM). If it's not right, let me know

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@sethmlarson sethmlarson Mar 19, 2025

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is likely the CPE that would get used, although we can't be for certain until a CVE exists with it... the only one I could find with some searching is cpe:...:zlib-ng:minizip-ng which is for a different component but at least the organization is a match.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

zooba and gpshead reacted with thumbs up emoji
All reactions
  • 👍 2 reactions
zooba
zooba commented Mar 19, 2025
View reviewed changes
Comment thread Modules/zlibmodule.c
return -1;
}
#ifdef ZLIBNG_VERSION
if (PyModule_Add(mod, "ZLIBNG_VERSION",

@zooba zooba Mar 19, 2025

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Figured we'd want some way to detect this other than looking at the text in ZLIB_VERSION

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@gpshead gpshead Mar 19, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense. annoying to have optional attributes that one would use hasattr or getattr on instead of blindly accessing, but realistically nobody should care as this is more internal informational so this is fine.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@zooba zooba Mar 19, 2025

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the main place it'll be used is in pythoninfo, which already handles absent attributes.

We have more offensive optional attributes in our extension modules 😆

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@zooba

zooba commented Mar 19, 2025

Copy link
Copy Markdown
Member Author

I've reviewed the three header files added to PC and they seem generic. It's a shame they aren't part of the sources, but figured it's easier/safer to just copy them into our source tree so that the cpython-source-deps repo is a straight import.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

zooba added 2 commits March 19, 2025 01:25
@zooba
Fix debug reference and some warnings
89d44a1
@zooba
Exclude Intel optimizations better on ARM64
08eecb1
@zooba zooba added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Mar 19, 2025
@bedevere-bot

bedevere-bot commented Mar 19, 2025

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @zooba for commit 08eecb1 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F131438%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Mar 19, 2025
rhpvorderman
rhpvorderman reviewed Mar 19, 2025
View reviewed changes
Comment thread PCbuild/pythoncore.vcxproj Resolved

Uh oh!

There was an error while loading. Please reload this page.

@zooba
Update docs and whatsnew
548daa7
@zooba

zooba commented Mar 19, 2025

Copy link
Copy Markdown
Member Author

The two failing buildbots appear unrelated, and everything else passed. All I changed in the last commit was docs, so I'm not going to rerun the buildbots unless someone thinks it's necessary or worthwhile.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

sethmlarson
sethmlarson approved these changes Mar 19, 2025
View reviewed changes

@sethmlarson sethmlarson left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SBOM changes LGTM!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Misc/externals.spdx.json
{
"referenceCategory": "SECURITY",
"referenceLocator": "cpe:2.3:a:zlib:zlib:1.3.1:*:*:*:*:*:*:*",
"referenceLocator": "cpe:2.3:a:zlib-ng:zlib-ng:2.2.4:*:*:*:*:*:*:*",

@sethmlarson sethmlarson Mar 19, 2025

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is likely the CPE that would get used, although we can't be for certain until a CVE exists with it... the only one I could find with some searching is cpe:...:zlib-ng:minizip-ng which is for a different component but at least the organization is a match.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

zooba and gpshead reacted with thumbs up emoji
All reactions
  • 👍 2 reactions
@mdboom

mdboom commented Mar 19, 2025

Copy link
Copy Markdown
Contributor

I'm kicking off a pyperformance benchmarking run with this -- we have a non-zero usage of zlib in that suite.

zooba and morotti reacted with hooray emoji
All reactions
  • 🎉 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@zooba
Remove unresolved reference from docs
f108044
@mdboom

mdboom commented Mar 19, 2025

Copy link
Copy Markdown
Contributor

The results for this on pyperformance are basically within the noise / no change. Not all that surprising, given that there are no benchmarks specifically aimed at zlib. https://github.com/faster-cpython/benchmarking-public/tree/main/results/bm-20250319-3.14.0a6+-548daa7

zooba reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

gpshead
gpshead approved these changes Mar 19, 2025
View reviewed changes
Comment thread Modules/zlibmodule.c
return -1;
}
#ifdef ZLIBNG_VERSION
if (PyModule_Add(mod, "ZLIBNG_VERSION",

@gpshead gpshead Mar 19, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense. annoying to have optional attributes that one would use hasattr or getattr on instead of blindly accessing, but realistically nobody should care as this is more internal informational so this is fine.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels Mar 19, 2025
@zooba
Include ZLIBNG_VERSION in pythoninfo
085fa10
@zooba
zooba enabled auto-merge (squash) March 19, 2025 18:38
@zooba
zooba merged commit 63a638c into python:main Mar 19, 2025
@bedevere-app bedevere-app Bot removed the awaiting merge label Mar 19, 2025
@zooba
zooba deleted the gh-91349 branch March 19, 2025 19:25
@chris-eibl

chris-eibl commented Mar 20, 2025

Copy link
Copy Markdown
Member

This has broken the tailcall builds on Windows: https://github.com/python/cpython/actions/runs/13967899073/job/39102464260

D:\a\cpython\cpython\externals\\zlib-ng-2.2.4\\functable.c(79,26): error : use of undeclared identifier 'slide_hash_sse2'; did you mean 'slide_hash_c'? [D:\a\cpython\cpython\PCbuild\zlib-ng.vcxproj]
D:\a\cpython\cpython\externals\\zlib-ng-2.2.4\\functable.c(123,26): error : use of undeclared identifier 'slide_hash_avx2'; did you mean 'slide_hash_c'? [D:\a\cpython\cpython\PCbuild\zlib-ng.vcxproj]
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@zooba

zooba commented Mar 20, 2025

Copy link
Copy Markdown
Member Author

Probably needs some fixed preprocessor checks (hopefully only in what's in the PC directory) to better handle the intrinsics being present/absent.

Though I notice that build warns NOTE: Visual Studio not detected. LLVM does not provide a C/C++ standard library and may be unable to locate MSVC headers., which might also be relevant.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@chris-eibl

chris-eibl commented Mar 20, 2025

Copy link
Copy Markdown
Member

I think, this is because here
https://github.com/zlib-ng/zlib-ng/blob/860e4cff7917d93f54f5d7f0bc1d0e8b1a3cb988/fallback_builtins.h#L4-L25
in line 4 __clang__ gets excluded and hence #define HAVE_BUILTIN_CTZ is not set (but in the MSVC case it is).

Then, in
https://github.com/zlib-ng/zlib-ng/blob/860e4cff7917d93f54f5d7f0bc1d0e8b1a3cb988/arch/x86/x86_functions.h#L13-L20
we dont get the prototype for slide_hash_sse2 in line 17, hence the error.

Sorry, I cannot get the permalinks to work here the usual way I am doing it :(

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@chris-eibl

chris-eibl commented Mar 20, 2025

Copy link
Copy Markdown
Member

Though I notice that build warns NOTE: Visual Studio not detected. LLVM does not provide a C/C++ standard library and may be unable to locate MSVC headers., which might also be relevant.

FWIW, when building with the bundled clang-cl of VS I do not have these warnings, but get the same error.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@zooba

zooba commented Mar 20, 2025

Copy link
Copy Markdown
Member Author

Most likely zlib-ng would generate different versions of the header files I checked into the PC directory for Clang. Figuring out what differences belong in there and detecting it dynamically rather than using CMake is the way forward.

This should get a new issue (because clang-cl isn't a supported configuration, so we don't have to revert this change until it's working). Tag me on it and we can continue there.

chris-eibl reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

chris-eibl
chris-eibl reviewed Mar 20, 2025
View reviewed changes
Comment thread PCbuild/zlib-ng.vcxproj
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<AdditionalIncludeDirectories>$(zlibNgDir);$(PySourceDir)PC;$(GeneratedZlibNgDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>%(PreprocessorDefinitions);ZLIB_COMPAT;WITH_GZFILEOP;NO_FSEEKO;HAVE_BUILTIN_ASSUME_ALIGNED;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="$(Platform) == 'Win32' or $(Platform) == 'x64'">%(PreprocessorDefinitions);X86_FEATURES;X86_HAVE_XSAVE_INTRIN;X86_SSE2;X86_SSSE3;X86_SSE42;X86_PCLMULQDQ_CRC;X86_AVX2;X86_AVX512;X86_AVX512VNNI;X86_VPCLMULQDQ_CRC</PreprocessorDefinitions>

@chris-eibl chris-eibl Mar 20, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean that for all executables X86_AVX512 code will be emitted and used?
See e.g. adler32_avx512.c, where the whole file is guarded with X86_AVX512 and there is code like __m512i in it.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@zooba zooba Mar 20, 2025

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it's detected and called dynamically based on availability, but it's all compiled at compile time.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@chris-eibl chris-eibl Mar 20, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I hope so, too.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@chris-eibl chris-eibl mentioned this pull request Mar 20, 2025
clang-cl on Windows fails to compile after zlib-ng #131521
Closed
chris-eibl
chris-eibl reviewed Mar 20, 2025
View reviewed changes
Comment thread PCbuild/zlib-ng.vcxproj
<PreprocessorDefinitions>%(PreprocessorDefinitions);ZLIB_COMPAT;WITH_GZFILEOP;NO_FSEEKO;HAVE_BUILTIN_ASSUME_ALIGNED;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="$(Platform) == 'Win32' or $(Platform) == 'x64'">%(PreprocessorDefinitions);X86_FEATURES;X86_HAVE_XSAVE_INTRIN;X86_SSE2;X86_SSSE3;X86_SSE42;X86_PCLMULQDQ_CRC;X86_AVX2;X86_AVX512;X86_AVX512VNNI;X86_VPCLMULQDQ_CRC</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="$(Configuration) == 'Debug'">%(PreprocessorDefinitions);ZLIB_DEBUG</PreprocessorDefinitions>
<EnableEnhancedInstructionSet Condition="$(Platform) == 'Win32' or $(Platform) == 'x64'">AdvancedVectorExtensions2</EnableEnhancedInstructionSet>

@chris-eibl chris-eibl Mar 20, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unconditionally letting the compiler generate code up to AVX2 for all *.c files here might result in the binary not running on all CPUs?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@hugovk hugovk mentioned this pull request Mar 21, 2025
Consider distributing zlib-ng astral-sh/python-build-standalone#464
Open
@chris-eibl chris-eibl mentioned this pull request Mar 22, 2025
GH-131521: fix clangcl build on Windows for zlib-ng #131526
Merged
@zanieb zanieb mentioned this pull request Apr 9, 2025
Bump to 3.14.0a7 astral-sh/python-build-standalone#580
Merged
zanieb added a commit to astral-sh/python-build-standalone that referenced this pull request May 17, 2025
@zanieb @geofft
Bump to 3.14.0a7 (#580)
0964f0f
The big changes here are:

- Switching to zlib-ng on Windows
(python/cpython#131438)
- Using hmac for hashing functions
(python/cpython#130157)

---------

Co-authored-by: Geoffrey Thomas <[email protected]>
@andersonhc andersonhc mentioned this pull request Oct 15, 2025
Add Python 3.14 support py-pdf/fpdf2#1622
Merged
1 of 4 tasks
@maikschulze

maikschulze commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Hi @zooba, a heads-up on zlib-ng 2.2.4, in case it's useful to anyone: PGO builds made with Visual Studio 17.11 (MSVC 14.41) decompress deflate data wrongly on CPUs with AVX-512 (test_zlib: "incorrect data check", test_gzip: "CRC check failed"). It's the known zlib-ng bug zlib-ng/zlib-ng#1883 (MSVC before 17.13 miscompiles the AVX-512 GET_CHUNK_MAG()), worked around in zlib-ng 2.2.5 by zlib-ng/zlib-ng#1884. On a Ryzen 9 7950X, adding just that pragma to 2.2.4 fixes the build, and removing it brings the wrong output back.

It doesn't affect CI or the python.org builds, which use newer compilers, but it does affect building from source with an older Visual Studio, which is how I stumbled upon it. Is there any chance of updating the Windows build to zlib-ng 2.2.5? main, 3.15 and 3.14 still bundle 2.2.4.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@zooba

zooba commented Nov 9, 2026

Copy link
Copy Markdown
Member Author

@maikschulze Yes, that sounds like an update we'd make. Can you file a new issue?

zware reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@maikschulze

maikschulze commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Hi, thanks for the quick response! I will file an issue and along with a pull request tomorrow.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@zooba

zooba commented Nov 9, 2026

Copy link
Copy Markdown
Member Author

I think we keep the zlib-ng sources in a separate repo, so just file the issue without a PR as we'll need a core developer to update that. We don't accept PRs, as it's too hard to validate that the sources are unmodified (but if you've got a link to the right download page, that will be appreciated)

zware, maikschulze, and chris-eibl reacted with thumbs up emoji
All reactions
  • 👍 3 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@maikschulze maikschulze mentioned this pull request Nov 10, 2026
Windows: update zlib-ng to 2.2.5 (PGO builds with Visual Studio 17.11 decompress wrongly on AVX-512 CPUs) #161735
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@chris-eibl chris-eibl chris-eibl left review comments
@gpshead gpshead gpshead approved these changes
@sethmlarson sethmlarson sethmlarson approved these changes
+2 more reviewers
@morotti morotti morotti left review comments
@rhpvorderman rhpvorderman rhpvorderman left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

9 participants

@zooba @bedevere-bot @mdboom @chris-eibl @maikschulze @gpshead @morotti @sethmlarson @rhpvorderman
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.