Skip to content

[Python] Export only PyInit_* from macOS extension modules - #116

Open
mmattice wants to merge 1 commit into
cel-expr:mainfrom
mmattice:macos-hide-bundled-symbols
Open

mmattice wants to merge 1 commit into
cel-expr:mainfrom
mmattice:macos-hide-bundled-symbols

Conversation

@mmattice

Copy link
Copy Markdown

Each extension statically links protobuf, abseil and cel-cpp. On macOS, pybind_extension links with only -undefined dynamic_lookup, so those copies are exported, including thousands of weak definitions. dyld coalesces exported weak definitions across every loaded image, so importing cel_expr_python alongside another extension that ships protobuf (e.g. ortools) binds one runtime's code to the other's parse tables and crashes in AddDescriptors at import time.

Wrap pybind_extension to add -Wl,-exported_symbol,_PyInit_<name> on macOS, matching the isolation Linux already gets from -Wl,-Bsymbolic, and add a macOS test that each extension exports only its init function.

Fixes #115

Each extension statically links protobuf, abseil and cel-cpp. On macOS,
pybind_extension links with only `-undefined dynamic_lookup`, so those
copies are exported, including thousands of weak definitions. dyld
coalesces exported weak definitions across every loaded image, so
importing cel_expr_python alongside another extension that ships protobuf
(e.g. ortools) binds one runtime's code to the other's parse tables and
crashes in AddDescriptors at import time.

Wrap pybind_extension to add `-Wl,-exported_symbol,_PyInit_<name>` on
macOS, matching the isolation Linux already gets from `-Wl,-Bsymbolic`,
and add a macOS test that each extension exports only its init function.

Fixes cel-expr#115
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

macOS wheels export bundled protobuf/abseil symbols → segfault on import alongside any other protobuf C++ (e.g. ortools)

1 participant