Skip to content

gh-144942: Fix macOS dylib build by adding $(MODLIBS) and removing -undefined dy… - #145186

Closed
gourijain029-del wants to merge 1 commit into
python:mainfrom
gourijain029-del:fix-macos-dylib-missing-modlibs
Closed

gourijain029-del wants to merge 1 commit into
python:mainfrom
gourijain029-del:fix-macos-dylib-missing-modlibs

Conversation

@gourijain029-del

Copy link
Copy Markdown

PR Title
gh-144942: Add $(MODLIBS) to macOS dylib build and remove -undefined dynamic_lookup

PR Description
Summary
This PR fixes an issue where the macOS libpython.dylib was missing $(MODLIBS) in its link command. This caused modules built statically (e.g., via

Modules/Setup.local
) to have their symbols omitted from the dynamic library, leading to runtime failures.

Additionally, this PR removes -undefined dynamic_lookup from the dylib link command. This ensures that any missing symbols are caught at build-time rather than resulting in null pointer dereferences or silent failures at runtime.

Changes
Updated

Makefile.pre.in
to include $(MODLIBS) when linking libpython$(LDVERSION).dylib.
Removed -undefined dynamic_lookup from the same link command to enforce symbol resolution at build-time.

@bedevere-app

bedevere-app Bot commented Feb 24, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@StanFromIreland StanFromIreland changed the title Fix macOS dylib build by adding $(MODLIBS) and removing -undefined dy… gh-144942: Fix macOS dylib build by adding $(MODLIBS) and removing -undefined dy… Feb 24, 2026
@bedevere-app

bedevere-app Bot commented Feb 25, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@python-cla-bot

python-cla-bot Bot commented Feb 25, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app

bedevere-app Bot commented Feb 25, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@gourijain029-del
gourijain029-del force-pushed the fix-macos-dylib-missing-modlibs branch 2 times, most recently from eeb5f4f to 10eb5ad Compare February 25, 2026 06:35
@gourijain029-del
gourijain029-del force-pushed the fix-macos-dylib-missing-modlibs branch from 10eb5ad to b76620c Compare February 25, 2026 07:10
@ned-deily
ned-deily requested a review from a team February 26, 2026 05:29
@github-actions

github-actions Bot commented May 7, 2026

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label May 7, 2026
@zeha

zeha commented Jun 21, 2026

Copy link
Copy Markdown

Could this be reviewed please?
I also need this fix.

@ned-deily maybe you could route this to the appropriate team?

thanks 🙏

zeha added a commit to Deduktiva/magnolia-python that referenced this pull request Jun 21, 2026
zeha added a commit to Deduktiva/magnolia-python that referenced this pull request Jun 21, 2026
zeha added a commit to Deduktiva/magnolia-python that referenced this pull request Jun 21, 2026
@github-actions github-actions Bot removed the stale Stale PR or inactive for long period of time. label Jun 23, 2026
itamaro added a commit that referenced this pull request Oct 22, 2026
…ork (#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.
itamaro added a commit that referenced this pull request Oct 22, 2026
… 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](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>
itamaro added a commit that referenced this pull request Oct 22, 2026
… 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants