From 035e017700dde3cf8fbd8d09d69f65e7de86cf72 Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" <68491+gpshead@users.noreply.github.com> Date: Mon, 7 Sep 2026 18:32:36 -0700 Subject: [PATCH] gh-157142: Fix linking _freeze_module with built-in test modules (GH-157143) Programs/_freeze_module is linked with Modules/getpath_noop.o rather than Modules/getpath.o, and getpath_noop.c only defined _PyConfig_InitPathConfig(). With MODULE_BUILDTYPE=static (the default on wasm), _testinternalcapi.o is part of LIBRARY_OBJS_OMIT_FROZEN and its get_getpath_codeobject() left _Py_Get_Getpath_CodeObject() as an undefined reference. Define a stub for it. (cherry picked from commit c8da735f4f051e34ae95a7d50522466e08848136) Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com> --- .../2026-09-07-23-40-00.gh-issue-157142.gpnoop.rst | 4 ++++ Modules/getpath_noop.c | 13 ++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Build/2026-09-07-23-40-00.gh-issue-157142.gpnoop.rst diff --git a/Misc/NEWS.d/next/Build/2026-09-07-23-40-00.gh-issue-157142.gpnoop.rst b/Misc/NEWS.d/next/Build/2026-09-07-23-40-00.gh-issue-157142.gpnoop.rst new file mode 100644 index 000000000000000..ac2890b5324ba4a --- /dev/null +++ b/Misc/NEWS.d/next/Build/2026-09-07-23-40-00.gh-issue-157142.gpnoop.rst @@ -0,0 +1,4 @@ +Fix the link of ``Programs/_freeze_module`` when extension modules are built +in (``MODULE_BUILDTYPE=static``) and the test modules are enabled: +``Modules/getpath_noop.c`` now defines ``_Py_Get_Getpath_CodeObject()``, +which ``_testinternalcapi`` uses. diff --git a/Modules/getpath_noop.c b/Modules/getpath_noop.c index c10e41d07f27c99..25ca25bd42c2516 100644 --- a/Modules/getpath_noop.c +++ b/Modules/getpath_noop.c @@ -1,10 +1,21 @@ /* Implements the getpath API for compiling with no functionality */ #include "Python.h" -#include "pycore_pathconfig.h" +#include "pycore_initconfig.h" // _Py_Get_Getpath_CodeObject() +#include "pycore_pathconfig.h" // _PyConfig_InitPathConfig() PyStatus _PyConfig_InitPathConfig(PyConfig *config, int compute_path_config) { return PyStatus_Error("path configuration is unsupported"); } + +/* Used by _testinternalcapi, which is linked into Programs/_freeze_module + when extension modules are built in (MODULE_BUILDTYPE=static). */ +PyObject * +_Py_Get_Getpath_CodeObject(void) +{ + PyErr_SetString(PyExc_RuntimeError, + "path configuration is unsupported"); + return NULL; +}