Skip to content

Commit a5285c7

Browse files
[3.15] gh-144942: Link $(MODLIBS) into the macOS shared library and framework (GH-159966) (#160158)
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](astral-sh/python-build-standalone#870)). This PR doesn't remove `-undefined dynamic_lookup`, as the earlier gh-145186 did. (cherry picked from commit 03864a2) Co-authored-by: Itamar Oren <itamarost@gmail.com>
1 parent ef1cf22 commit a5285c7

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
@@ -1049,7 +1049,7 @@ libpython3.so: libpython$(LDVERSION).so
10491049
$(BLDSHARED) $(NO_AS_NEEDED) -o $@ -Wl,-h$@ $^
10501050

10511051
libpython$(LDVERSION).dylib: $(LIBRARY_OBJS)
1052-
$(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); \
1052+
$(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); \
10531053

10541054

10551055
libpython$(VERSION).sl: $(LIBRARY_OBJS)
@@ -1083,7 +1083,7 @@ $(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK): \
10831083
-install_name $(PYTHONFRAMEWORKINSTALLNAMEPREFIX)/$(PYTHONFRAMEWORK) \
10841084
-compatibility_version $(VERSION) \
10851085
-current_version $(VERSION) \
1086-
-framework CoreFoundation $(LIBS);
1086+
-framework CoreFoundation $(MODLIBS) $(LIBS);
10871087
$(INSTALL) -d -m $(DIRMODE) \
10881088
$(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/Resources/English.lproj
10891089
$(INSTALL_DATA) $(RESSRCDIR)/Info.plist \
@@ -1104,7 +1104,7 @@ $(PYTHONFRAMEWORKDIR)/$(PYTHONFRAMEWORK): \
11041104
-install_name $(PYTHONFRAMEWORKINSTALLNAMEPREFIX)/$(PYTHONFRAMEWORK) \
11051105
-compatibility_version $(VERSION) \
11061106
-current_version $(VERSION) \
1107-
-framework CoreFoundation $(LIBS);
1107+
-framework CoreFoundation $(MODLIBS) $(LIBS);
11081108
$(INSTALL_DATA) $(RESSRCDIR)/Info.plist $(PYTHONFRAMEWORKDIR)/Info.plist
11091109

11101110
# 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)