Compiling static library with `-fPIC` throws error
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 36k
- PR merge metrics
- PR metrics pending
Description
Bug report
I'm compiling python as a static library to embed in my c++ shared library, and -fPIC is necessary to get it working!
compilation command: CFLAGS=-fPIC ./configure --enable-shared=no --enable-optimizations
the following error happens:
Objects/typeobject.c: In function ‘inherit_special’:
Objects/typeobject.c:5777:1: error: the control flow of function ‘inherit_special’ does not match its profile data (counter ‘arcs’) [-Werror=coverage-mismatch]
5777 | inherit_special(PyTypeObject *type, PyTypeObject *base)
| ^~~~~~~~~~~~~~~
Objects/typeobject.c:5777:1: error: the control flow of function ‘inherit_special’ does not match its profile data (counter ‘time_profiler’) [-Werror=coverage-mismatch]
Objects/typeobject.c: In function ‘object_set_class’:
Objects/typeobject.c:4774:1: error: the control flow of function ‘object_set_class’ does not match its profile data (counter ‘arcs’) [-Werror=coverage-mismatch]
4774 | object_set_class(PyObject *self, PyObject *value, void *closure)
| ^~~~~~~~~~~~~~~~
Objects/typeobject.c:4774:1: error: the control flow of function ‘object_set_class’ does not match its profile data (counter ‘time_profiler’) [-Werror=coverage-mismatch]
Objects/obmalloc.c:1449:1: warning: ‘always_inline’ function might not be inlinable [-Wattributes]
1449 | arena_map_get(block *p, int create)
| ^~~~~~~~~~~~~
if I remove the -fPIC it compiles fine!
edit: Just tried removing --enable-optimizations and it worked, but I think it should work with optimizations?
Your environment
- CPython versions tested on: branch 3.11
- Operating system and architecture: Manjaro Linux x64
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with CFLAGS=-fPIC ./configure --enable-shared=no --enable-optimizations on CPython 3.11, then compare it with the successful build without -fPIC or --enable-optimizations. Start with the reported failures in Objects/typeobject.c and warning in Objects/obmalloc.c; done means the optimized static build completes with -fPIC.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, python
- Domain
- build-system, compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100