python / python/cpython

Compiling static library with `-fPIC` throws error

オープン
#100,707 コメント 1 件 リアクション 5 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

build type-bug
主要言語
Python
スター
77.2k
フォーク
36k
PR マージ指標
PR 指標を取得中

説明

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

CPython 3.11 で CFLAGS=-fPIC ./configure --enable-shared=no --enable-optimizations を使って問題を再現し、その後、-fPIC--enable-optimizations も付けない場合の成功するビルドと比較します。まず Objects/typeobject.c で報告されている失敗と、Objects/obmalloc.c の警告から始めます。最適化された静的ビルドが -fPIC 付きで完了すれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
cpp, python
領域
build-system, compilers
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
38/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。