gh-157212: Fix _Py_ThreadId() on Windows ARM64 with MinGW - #157253
Open
christianaurichzm wants to merge 1 commit into
Open
gh-157212: Fix _Py_ThreadId() on Windows ARM64 with MinGW#157253christianaurichzm wants to merge 1 commit into
christianaurichzm wants to merge 1 commit into
Conversation
The __MINGW32__ && _M_ARM64 branch calls __getReg(18), mirroring the MSVC branch above it. The intrinsic is not available for MinGW ARM64: mingw-w64 declares __getReg only for Itanium, and GCC does not provide a corresponding builtin. The branch is reached by AArch64 MinGW toolchains because mingw-w64 defines _M_ARM64 when __aarch64__ is defined. Falling through to the generic __aarch64__ branch would not provide the Windows thread pointer. The Windows ARM64 ABI reserves x18 as the platform register pointing to the TEB, so read x18 directly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #157212
_Py_ThreadId()currently uses__getReg(18)for the MinGW ARM64 branch:That intrinsic is not available for MinGW ARM64. For a
*-windows-gnutarget, Clang'sintrin.hdefers to mingw-w64's header, which declares__getRegonly for Itanium. GCC does not provide a corresponding builtin either.The branch is reached by AArch64 MinGW toolchains because mingw-w64 defines
_M_ARM64when__aarch64__is defined.Falling through to the generic
__aarch64__implementation is not a valid alternative. The Windows ARM64 ABI reservesx18as the platform register pointing to the Thread Environment Block (TEB). In the system tested in gh-157212,x18also matchedNtCurrentTeb()for each tested thread, whiletpidr_el0was observed as zero.This change therefore reads the TEB address directly from
x18for MinGWARM64:
The MSVC branch is unchanged.
Verification
I reproduced the original compile failure with
zig cc/Clang targetingaarch64-windows-gnu:With this change, the same target compiles successfully and at
-O2emits the expected register read:The change is limited to the MinGW ARM64 branch.
AI tools were used to help organize and edit the wording of this PR description.