python / python/cpython

Windows debug abi3t extensions autolink python316_d.lib instead of python316t_d.lib

未關閉
#157,611 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

type-bug
主要語言
Python
星號
77.2k
分支
36k
PR 合併指標
PR 指標待擷取

描述

Bug report

Bug description:

On the current main branch, an MSVC-compatible debug extension that defines
Py_LIMITED_API and Py_TARGET_ABI3T can select the ordinary debug import
library instead of the free-threaded debug library.

The ordering in the public headers appears to cause the mismatch:

  1. PC/pyconfig.h selects the autolink library.
  2. Only later does Include/pyabi.h derive Py_GIL_DISABLED from
    Py_TARGET_ABI3T.

The debug autolink branch in PC/pyconfig.h currently checks only
Py_GIL_DISABLED. An abi3t extension identifies its target with
Py_TARGET_ABI3T, so it does not necessarily define Py_GIL_DISABLED before
including these headers.

I reproduced this by compiling a minimal Windows x86-64 COFF object with Clang
in MSVC-compatible target mode. The probe defines _DEBUG, Py_LIMITED_API,
and Py_TARGET_ABI3T=0x030f0000, then includes the two headers in their normal
order:

#include "PC/pyconfig.h"
#include "Include/pyabi.h"

#ifndef Py_GIL_DISABLED
#  error "Py_TARGET_ABI3T did not enable Py_GIL_DISABLED"
#endif

int cpython_abi3t_autolink_probe;

The resulting object's .drectve section contains:

/DEFAULTLIB:python316_d.lib

Defining Py_GIL_DISABLED explicitly before including the headers instead
produces:

/DEFAULTLIB:python316t_d.lib

The release abi3t case already selects python3t.lib; the mismatch is specific
to the versioned debug-library branch. The PCbuild naming also identifies
python316t_d.lib as the free-threaded debug import library.

A minimal possible fix is to recognize the ABI target at the point where the
autolink library is selected:

-#if defined(Py_GIL_DISABLED)
+#if defined(Py_GIL_DISABLED) || defined(Py_TARGET_ABI3T)

With that change, the original probe, without an explicit
Py_GIL_DISABLED, emits /DEFAULTLIB:python316t_d.lib.

This test inspects the Windows linker directive emitted by the public headers,
but I have not run a native Windows extension build. Could you confirm whether
Py_TARGET_ABI3T should select the free-threaded debug import library at this
earlier point? If so, I can prepare a pull request with this change, or adjust
it if changing the include/derivation order is preferred.

CPython versions tested on

CPython main.

Operating systems tested on

The reproducer was cross-compiled on Linux for the Windows x86-64 MSVC target.
Native Windows validation has not yet been performed -- as I do not have a windows machine.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs
  • gh-157623

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

從 PC/pyconfig.h 中的 autolink 選擇和 Include/pyabi.h 中的 ABI 推導開始。重現文件化的 probe,或檢查連結的 PR gh-157623,然後驗證 Windows debug abi3t 情況會發出 free-threaded 匯入程式庫指示,而不要求明確的 Py_GIL_DISABLED。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
c, python
領域
build-system, operating-systems
Issue 類型
缺陷
難度
2/5
預估耗時
1-3 小時
活躍度
停滯
描述清晰度
描述清楚
新手友好度
25/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。