Skip to content

gh-160689 : Link only the bootstrap modules into the build helper programs - #160537

Open
itamaro wants to merge 1 commit into
python:mainfrom
itamaro:build-helpers-bootstrap-only
Open

itamaro wants to merge 1 commit into
python:mainfrom
itamaro:build-helpers-bootstrap-only

Conversation

@itamaro

@itamaro itamaro commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

The build-helper programs (Programs/_freeze_module and _bootstrap_python) don't need to link extension modules that they don't need.

This PR makes sure the helper programs get only the modules they need to do their job, regardless of what the build configuration sets for the final built runtime and interpreter.

This follows the same pattern as what PCbuild/_freeze_module.vcxproj does with PC/config_minimal.c, and lets "extra" builtin modules (from Setup.local or MODULE_BUILDTYPE=static) depend on frozen modules or getpath.

Written with assistance from Claude Fable 5.1

@python-cla-bot

python-cla-bot Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

…r programs

Programs/_freeze_module and _bootstrap_python were linked with
$(LIBRARY_OBJS_OMIT_FROZEN), i.e. every static module from all Setup
files (Setup.local, Setup.stdlib with MODULE_BUILDTYPE=static, ...).
That makes it impossible for a builtin module to depend on anything the
helpers produce: a frozen module header, Modules/getpath.o, or generated
sources. A Setup.local module including a header generated by
$(FREEZE_MODULE) is a dependency cycle ("Circular ... dependency
dropped"), and one referencing a getpath.o symbol fails to link, since
_freeze_module links Modules/getpath_noop.o instead. CPython itself
needed a workaround for the latter: a stub of
_Py_Get_Getpath_CodeObject() in getpath_noop.c for _testinternalcapi
in MODULE_BUILDTYPE=static builds.

Mirror what PCbuild/_freeze_module.vcxproj already does on Windows
(a fixed source list plus PC/config_minimal.c): link the helpers with
the core objects plus the modules of Modules/Setup.bootstrap only.

* makesetup: new "-b Setup" option marking a Setup file as the bootstrap
  modules. Their objects and libraries are substituted for
  _BOOTSTRAP_MODOBJS_ / _BOOTSTRAP_MODLIBS_, and a second table,
  config_bootstrap.c, is generated with only those modules. A bootstrap
  module overridden by an earlier rule (Setup.local) keeps the
  overriding static module for the helpers too.
* Makefile.pre.in: BOOTSTRAP_LIBRARY_OBJS (core + Modules/config_bootstrap.o
  + $(BOOTSTRAP_MODOBJS)) replaces LIBRARY_OBJS_OMIT_FROZEN in the
  _freeze_module and _bootstrap_python links. getbuildinfo gets a
  separate object for the helpers, as its prerequisites include
  $(MODOBJS).
* configure.ac / configure: pass -b Modules/Setup.bootstrap and move
  config_bootstrap.c into Modules/ (configure hand-edited in sync).
* Tools/c-analyzer: whitelist _PyImport_Inittab in the generated
  Modules/config_bootstrap.c, as for Modules/config.c.

The final libpython/python link is unchanged.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YD8kPnXaAMJZk2LvSHPXYA
@itamaro
itamaro force-pushed the build-helpers-bootstrap-only branch from 3af290e to ebc936d Compare October 26, 2026 00:25
@itamaro itamaro changed the title Link only the bootstrap modules into the build helper programs gh-160689 : Link only the bootstrap modules into the build helper programs Oct 26, 2026
@bedevere-app bedevere-app Bot added the type-feature A feature request or enhancement label Oct 26, 2026
@itamaro itamaro added the build The build process and cross-build label Oct 26, 2026
@itamaro
itamaro requested a review from brettcannon October 26, 2026 01:03
@itamaro
itamaro marked this pull request as ready for review October 26, 2026 01:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting core review build The build process and cross-build type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant