Skip to content

Commit 03864a2

Browse files
authored
gh-144942: Link $(MODLIBS) into the macOS shared library and framework (#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](astral-sh/python-build-standalone#870)). This PR doesn't remove `-undefined dynamic_lookup`, as the earlier gh-145186 did.
1 parent 9f8f8d9 commit 03864a2

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

‎Makefile.pre.in‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,7 @@ libpython3.so: libpython$(LDVERSION).so
10171017
$(BLDSHARED) $(NO_AS_NEEDED) -o $@ -Wl,-h$@ $^
10181018

10191019
libpython$(LDVERSION).dylib: $(LIBRARY_OBJS)
1020-
$(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); \
1020+
$(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); \
10211021

10221022

10231023
libpython$(VERSION).sl: $(LIBRARY_OBJS)
@@ -1051,7 +1051,7 @@ $(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK): \
10511051
-install_name $(PYTHONFRAMEWORKINSTALLNAMEPREFIX)/$(PYTHONFRAMEWORK) \
10521052
-compatibility_version $(VERSION) \
10531053
-current_version $(VERSION) \
1054-
-framework CoreFoundation $(LIBS);
1054+
-framework CoreFoundation $(MODLIBS) $(LIBS);
10551055
$(INSTALL) -d -m $(DIRMODE) \
10561056
$(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/Resources/English.lproj
10571057
$(INSTALL_DATA) $(RESSRCDIR)/Info.plist \
@@ -1072,7 +1072,7 @@ $(PYTHONFRAMEWORKDIR)/$(PYTHONFRAMEWORK): \
10721072
-install_name $(PYTHONFRAMEWORKINSTALLNAMEPREFIX)/$(PYTHONFRAMEWORK) \
10731073
-compatibility_version $(VERSION) \
10741074
-current_version $(VERSION) \
1075-
-framework CoreFoundation $(LIBS);
1075+
-framework CoreFoundation $(MODLIBS) $(LIBS);
10761076
$(INSTALL_DATA) $(RESSRCDIR)/Info.plist $(PYTHONFRAMEWORKDIR)/Info.plist
10771077

10781078
# This rule builds the Cygwin Python DLL and import library if configured
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix the macOS shared library and framework builds not linking the libraries
2+
required by built-in modules, such as the HACL* objects needed by ``_blake2``
3+
when it is built in via :file:`Modules/Setup.local`.

0 commit comments

Comments
 (0)