PyO3 / PyO3/pyo3

cdylib builds with `-Cprofile-generate` RUSTFLAGS are broken under Unix with PyO3 0.23

Open
#4,796 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
16.2k
Forks
1k
Avg merge
2d 6h
Merged PRs (30d)
66

Description

Bug Description

During the process of releasing a new version of Granian I realised it seems not possible to create PGO builds in Linux and MacOS.
Maturin successfully builds the wheels with RUSTFLAGS=-Cprofile-generate=$(pwd)/profdata, but importing the library results in a segfault under MacOS and the following in Linux:

ImportError: /home/runner/work/granian/granian/.venv/lib/python3.9/site-packages/granian/_granian.cpython-39-x86_64-linux-gnu.so: undefined symbol: __gcov_indirect_call

Tested both on GHA (you can inspect the run here) and locally on MacOS.

Also tried to test different maturin versions (1.7.4->1.7.8) and reverting changes on other cargo dependencies from the last successful build with PyO3 0.22: nothing seems to work, reverting to PyO3 0.22 immediately fix the issue. Also, Windows seems to be unaffected by this.
Not sure this is 100% PyO3 fault, but given my limited knowledge on the inner processes it's also hard to identify other major responsibilities on something else. To maintainers: if you think this is Maturin related or it involves other components, feel free to close this and point me out to the right place.

Steps to Reproduce
  1. Run RUSTFLAGS=-Cprofile-generate=$(pwd)/profdata maturin build --release -i {interpreter}
  2. Install the generated wheel
  3. Import the library in Python
Backtrace

No response

Your operating system and version

Ubuntu 22.04, MacOS 13, MacOS 14

Your Python version (python --version)

Python 3.9->3.13

Your Rust version (rustc --version)

1.82.0, 1.83.0

Your PyO3 version

0.23.3

How did you install python? Did you use a virtualenv?

pyenv, brew, uv

Additional Info

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with the provided RUSTFLAGS and maturin build steps, then compare behavior with PyO3 0.22 and 0.23.3 on Linux and macOS. Trace the generated extension's linking and import path; done means the wheel imports without a segfault or __gcov_indirect_call error under Unix.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, rust
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.