python / python/cpython

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

Ouverte
#157,611 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

type-bug
Langage dominant
Python
Étoiles
77.2k
Forks
35.9k
Métriques de merge des PR
Métriques de PR en attente

Description

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

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par la sélection de l’autolink dans PC/pyconfig.h et la dérivation de l’ABI dans Include/pyabi.h. Reproduisez la sonde documentée ou inspectez la PR liée gh-157623, puis vérifiez que le cas abi3t de débogage Windows émette la directive de bibliothèque d’importation free-threaded sans nécessiter de Py_GIL_DISABLED explicite.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
c, python
Domaine
build-system, operating-systems
Type d'issue
Bug
Difficulté
2/5
Temps estimé
1-3 heures
Activité
À l'abandon
Clarté
Clairement spécifiée
Accessibilité débutants
25/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.