Skip to content

_Py_get_machine_stack_pointer() does not compile with MinGW on Windows #158165

Description

@corona10

Bug report

The same bug affects _Py_get_machine_stack_pointer() in Include/internal/pycore_pystate.h: the intrinsic branches are guarded by _M_ARM64/_M_X64 only,
which mingw-w64 also defines, so MinGW toolchains hit MSVC-only intrinsics.

  • ARM64: __getReg(31) is not declared for MinGW (clang or GCC). https://godbolt.org/z/5zvY3W158
    error: call to undeclared function '__getReg'; ISO C99 and later do not support implicit function declarations
    
  • x64: _AddressOfReturnAddress() is only declared by mingw-w64, never defined, so it becomes an undefined external call (jmp _AddressOfReturnAddress) and fails at link time. https://godbolt.org/z/qb7PvvMGG
  • The __x86_64__ fallback "{movq %%rsp, %0" is missing the |intel} half of the dialect alternative. It works in AT&T mode, but breaks with -masm=intel. It should take the same approach as _Py_ThreadId(), something like: "{movq %%rsp, %0|mov %0, rsp}".

This was originally suggested by @kumaraditya303 in #157253 (comment)

Linked PRs

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

OS-windowstype-bugAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions