https://github.com/python/cpython/commit/313c817874d492e6761465ff4aff0c9217e01507
commit: 313c817874d492e6761465ff4aff0c9217e01507
branch: 3.14
author: Miss Islington (bot) <[email protected]>
committer: itamaro <[email protected]>
date: 2026-10-21T19:06:17-07:00
summary:

[3.14] gh-144942: Link `$(MODLIBS)` into the macOS shared library and framework 
(GH-159966) (#160160)

gh-144942: Link `$(MODLIBS)` into the macOS shared library and framework 
(GH-159966)

The rules that link `libpython$(LDVERSION).dylib` and the macOS and iOS 
frameworks don't pass `$(MODLIBS)`, unlike the `libpython$(LDVERSION).so` rule. 
When a module is built in, for example via `Modules/Setup.local`, the libraries 
that module needs are left out:

- **`--enable-framework`:** the build fails with undefined symbols.
- **`--enable-shared`:** the dylib is linked with `-undefined dynamic_lookup`, 
so the build succeeds and the failure only shows up at runtime.

To reproduce, build on macOS with this `Modules/Setup.local`:

```
*static*
_blake2 blake2module.c
```

On `main`:

- **`--enable-framework`:** linking `Python.framework` fails with 12 undefined 
`_Py_LibHacl_*` symbols.
- **`--enable-shared`:** `nm -u libpython3.16.dylib` lists the same 12 symbols. 
After `make install`, `python3 -c "import _blake2; _blake2.blake2b(b'abc')"` 
aborts with `dyld: missing symbol called`, and so does a C program that embeds 
Python.

With this change, both builds link with no undefined HACL symbols, and 
`_blake2` works as a built-in module. In default builds `$(MODLIBS)` is empty, 
so they are unaffected. `test_hashlib`, `test_hmac`, `test_embed` and 
`test_sysconfig` pass for shared and framework builds, both with and without 
the `Setup.local` above (macOS 14, arm64). I haven't tested the iOS framework 
rule, which gets the same one-line change.

python-build-standalone already carries the dylib part of this as a patch 
([astral-sh/python-build-standalone#870](https://github.com/astral-sh/python-build-standalone/issues/870)).
 This PR doesn't remove `-undefined dynamic_lookup`, as the earlier gh-145186 
did.
(cherry picked from commit 03864a26212a80fec120137a6161ff7c859d179c)

Co-authored-by: Itamar Oren <[email protected]>

files:
A Misc/NEWS.d/next/Build/2026-10-20-20-00-00.gh-issue-144942.MdLibs.rst
M Makefile.pre.in

diff --git a/Makefile.pre.in b/Makefile.pre.in
index 7b3e508d819459..ca46f1a8984976 100644
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -1034,7 +1034,7 @@ libpython3.so:    libpython$(LDVERSION).so
        $(BLDSHARED) $(NO_AS_NEEDED) -o $@ -Wl,-h$@ $^
 
 libpython$(LDVERSION).dylib: $(LIBRARY_OBJS)
-        $(CC) -dynamiclib $(PY_CORE_LDFLAGS) -undefined dynamic_lookup 
-Wl,-install_name,$(prefix)/lib/libpython$(LDVERSION).dylib 
-Wl,-compatibility_version,$(VERSION) -Wl,-current_version,$(VERSION) -o $@ 
$(LIBRARY_OBJS) $(DTRACE_OBJS) $(SHLIBS) $(LIBC) $(LIBM); \
+        $(CC) -dynamiclib $(PY_CORE_LDFLAGS) -undefined dynamic_lookup 
-Wl,-install_name,$(prefix)/lib/libpython$(LDVERSION).dylib 
-Wl,-compatibility_version,$(VERSION) -Wl,-current_version,$(VERSION) -o $@ 
$(LIBRARY_OBJS) $(DTRACE_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM); \
 
 
 libpython$(VERSION).sl: $(LIBRARY_OBJS)
@@ -1068,7 +1068,7 @@ 
$(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK): \
                -install_name 
$(PYTHONFRAMEWORKINSTALLNAMEPREFIX)/$(PYTHONFRAMEWORK) \
                -compatibility_version $(VERSION) \
                -current_version $(VERSION) \
-               -framework CoreFoundation $(LIBS);
+               -framework CoreFoundation $(MODLIBS) $(LIBS);
        $(INSTALL) -d -m $(DIRMODE)  \
                
$(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/Resources/English.lproj
        $(INSTALL_DATA) $(RESSRCDIR)/Info.plist \
@@ -1089,7 +1089,7 @@ $(PYTHONFRAMEWORKDIR)/$(PYTHONFRAMEWORK): \
                -install_name 
$(PYTHONFRAMEWORKINSTALLNAMEPREFIX)/$(PYTHONFRAMEWORK) \
                -compatibility_version $(VERSION) \
                -current_version $(VERSION) \
-               -framework CoreFoundation $(LIBS);
+               -framework CoreFoundation $(MODLIBS) $(LIBS);
        $(INSTALL_DATA) $(RESSRCDIR)/Info.plist $(PYTHONFRAMEWORKDIR)/Info.plist
 
 # This rule builds the Cygwin Python DLL and import library if configured
diff --git 
a/Misc/NEWS.d/next/Build/2026-10-20-20-00-00.gh-issue-144942.MdLibs.rst 
b/Misc/NEWS.d/next/Build/2026-10-20-20-00-00.gh-issue-144942.MdLibs.rst
new file mode 100644
index 00000000000000..94b25d67af2fe4
--- /dev/null
+++ b/Misc/NEWS.d/next/Build/2026-10-20-20-00-00.gh-issue-144942.MdLibs.rst
@@ -0,0 +1,3 @@
+Fix the macOS shared library and framework builds not linking the libraries
+required by built-in modules, such as the HACL* objects needed by ``_blake2``
+when it is built in via :file:`Modules/Setup.local`.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to