From a2c21dbdd5edc4bc9c550544a33d6875ffada328 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Thu, 20 Nov 2025 23:02:34 +0100 Subject: [PATCH 1/5] gh-141808: Don't remove the JIT stencils when building with PGO See https://discuss.python.org/t/building-the-jit-with-pre-built-stencils/91838/12 --- Makefile.pre.in | 3 ++- .../next/Build/2025-11-20-23-15-39.gh-issue-141808.NEewZC.rst | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Build/2025-11-20-23-15-39.gh-issue-141808.NEewZC.rst diff --git a/Makefile.pre.in b/Makefile.pre.in index 13108b1baf976a..e2e28424f83492 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -3239,7 +3239,6 @@ clean-retain-profile: pycremoval -rm -rf Python/deepfreeze -rm -f Python/frozen_modules/*.h -rm -f Python/frozen_modules/MANIFEST - -rm -f jit_stencils*.h -find build -type f -a ! -name '*.gc??' -exec rm -f {} ';' -rm -f Include/pydtrace_probes.h -rm -f profile-gen-stamp @@ -3290,6 +3289,8 @@ distclean: clobber docclean Modules/ld_so_aix Modules/python.exp Misc/python.pc \ Misc/python-embed.pc Misc/python-config.sh -rm -f python*-gdb.py + # gh-141808: The JIT stencils are deliberately kept in make clean(-retain-profile) + -rm -f jit_stencils*.h # Issue #28258: set LC_ALL to avoid issues with Estonian locale. # Expansion is performed here by shell (spawned by make) itself before # arguments are passed to find. So LC_ALL=C must be set as a separate diff --git a/Misc/NEWS.d/next/Build/2025-11-20-23-15-39.gh-issue-141808.NEewZC.rst b/Misc/NEWS.d/next/Build/2025-11-20-23-15-39.gh-issue-141808.NEewZC.rst new file mode 100644 index 00000000000000..6ef06ed206ae1d --- /dev/null +++ b/Misc/NEWS.d/next/Build/2025-11-20-23-15-39.gh-issue-141808.NEewZC.rst @@ -0,0 +1,4 @@ +When running ``make clean`` or ``make clean-retain-profile``, keep the +genearted JIT stencils. That way, the stencils are not genearted twice when +Profile-guided optimization (PGO) is used. It also allows distributors to +supply their own pre-built JIT stencils. From 3d969c6d5873c5b8114bd65bbc1fb0daf4b99f76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Fri, 21 Nov 2025 09:04:35 +0100 Subject: [PATCH 2/5] Fix typo in Misc/NEWS.d/next/Build/2025-11-20-23-15-39.gh-issue-141808.NEewZC.rst Co-authored-by: Mikhail Efimov --- .../next/Build/2025-11-20-23-15-39.gh-issue-141808.NEewZC.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Build/2025-11-20-23-15-39.gh-issue-141808.NEewZC.rst b/Misc/NEWS.d/next/Build/2025-11-20-23-15-39.gh-issue-141808.NEewZC.rst index 6ef06ed206ae1d..c1d9b2939a970d 100644 --- a/Misc/NEWS.d/next/Build/2025-11-20-23-15-39.gh-issue-141808.NEewZC.rst +++ b/Misc/NEWS.d/next/Build/2025-11-20-23-15-39.gh-issue-141808.NEewZC.rst @@ -1,4 +1,4 @@ When running ``make clean`` or ``make clean-retain-profile``, keep the -genearted JIT stencils. That way, the stencils are not genearted twice when +generated JIT stencils. That way, the stencils are not generated twice when Profile-guided optimization (PGO) is used. It also allows distributors to supply their own pre-built JIT stencils. From 24075b3963e1d5ca6c2f24470f38a2a9096c201a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Thu, 27 Nov 2025 14:11:22 +0100 Subject: [PATCH 3/5] Have a separate clean-jit-stencils make target --- Makefile.pre.in | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Makefile.pre.in b/Makefile.pre.in index e2e28424f83492..02e8da8b708834 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -3276,11 +3276,16 @@ clobber: clean -rm -f python-config.py python-config -rm -rf cross-build +# gh-141808: The JIT stencils are deliberately kept in make clean(-retain-profile) +.PHONY: clean-jit-stencils +clean-jit-stencils: + -rm -f jit_stencils*.h + # Make things extra clean, before making a distribution: # remove all generated files, even Makefile[.pre] # Keep configure and Python-ast.[ch], it's possible they can't be generated .PHONY: distclean -distclean: clobber docclean +distclean: clobber docclean clean-jit-stencils for file in $(srcdir)/Lib/test/data/* ; do \ if test "$$file" != "$(srcdir)/Lib/test/data/README"; then rm "$$file"; fi; \ done @@ -3289,8 +3294,6 @@ distclean: clobber docclean Modules/ld_so_aix Modules/python.exp Misc/python.pc \ Misc/python-embed.pc Misc/python-config.sh -rm -f python*-gdb.py - # gh-141808: The JIT stencils are deliberately kept in make clean(-retain-profile) - -rm -f jit_stencils*.h # Issue #28258: set LC_ALL to avoid issues with Estonian locale. # Expansion is performed here by shell (spawned by make) itself before # arguments are passed to find. So LC_ALL=C must be set as a separate From 349a92e855cbf8894228fae3b781b1cf262cc782 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Thu, 27 Nov 2025 14:19:21 +0100 Subject: [PATCH 4/5] Have a separate clean-profile make target This allows us not to call make clean from the PGO task. --- Makefile.pre.in | 19 +++++++++++-------- ...-11-20-23-15-39.gh-issue-141808.NEewZC.rst | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/Makefile.pre.in b/Makefile.pre.in index 02e8da8b708834..efd4b8b82bb70e 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -837,7 +837,7 @@ check-app-store-compliance: # Profile generation build must start from a clean tree. profile-clean-stamp: - $(MAKE) clean + $(MAKE) clean-profile touch $@ # Compile with profile generation enabled. @@ -3257,13 +3257,21 @@ profile-removal: rm -f profile-run-stamp rm -f profile-bolt-stamp -.PHONY: clean -clean: clean-retain-profile clean-bolt +.PHONY: clean-profile +clean-profile: clean-retain-profile clean-bolt @if test @DEF_MAKE_ALL_RULE@ = profile-opt -o @DEF_MAKE_ALL_RULE@ = bolt-opt; then \ rm -f profile-gen-stamp profile-clean-stamp; \ $(MAKE) profile-removal; \ fi +# gh-141808: The JIT stencils are deliberately kept in clean-profile +.PHONY: clean-jit-stencils +clean-jit-stencils: + -rm -f jit_stencils*.h + +.PHONY: clean +clean: clean-profile clean-jit-stencils + .PHONY: clobber clobber: clean -rm -f $(BUILDPYTHON) $(LIBRARY) $(LDLIBRARY) $(DLLLIBRARY) \ @@ -3276,11 +3284,6 @@ clobber: clean -rm -f python-config.py python-config -rm -rf cross-build -# gh-141808: The JIT stencils are deliberately kept in make clean(-retain-profile) -.PHONY: clean-jit-stencils -clean-jit-stencils: - -rm -f jit_stencils*.h - # Make things extra clean, before making a distribution: # remove all generated files, even Makefile[.pre] # Keep configure and Python-ast.[ch], it's possible they can't be generated diff --git a/Misc/NEWS.d/next/Build/2025-11-20-23-15-39.gh-issue-141808.NEewZC.rst b/Misc/NEWS.d/next/Build/2025-11-20-23-15-39.gh-issue-141808.NEewZC.rst index c1d9b2939a970d..73220e1990006b 100644 --- a/Misc/NEWS.d/next/Build/2025-11-20-23-15-39.gh-issue-141808.NEewZC.rst +++ b/Misc/NEWS.d/next/Build/2025-11-20-23-15-39.gh-issue-141808.NEewZC.rst @@ -1,4 +1,4 @@ -When running ``make clean`` or ``make clean-retain-profile``, keep the +When running ``make clean-retain-profile``, keep the generated JIT stencils. That way, the stencils are not generated twice when Profile-guided optimization (PGO) is used. It also allows distributors to supply their own pre-built JIT stencils. From a3dbb5915a2f8a77e41c244fedd9c3ba772fd98d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Thu, 27 Nov 2025 14:29:43 +0100 Subject: [PATCH 5/5] fixup! Have a separate clean-profile make target --- Makefile.pre.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.pre.in b/Makefile.pre.in index efd4b8b82bb70e..09dd3ff92a226c 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -3288,7 +3288,7 @@ clobber: clean # remove all generated files, even Makefile[.pre] # Keep configure and Python-ast.[ch], it's possible they can't be generated .PHONY: distclean -distclean: clobber docclean clean-jit-stencils +distclean: clobber docclean for file in $(srcdir)/Lib/test/data/* ; do \ if test "$$file" != "$(srcdir)/Lib/test/data/README"; then rm "$$file"; fi; \ done