Skip to content

gh-158165: Fix _Py_get_machine_stack_pointer() compilation with MinGW - #158167

Merged
corona10 merged 1 commit into
python:mainfrom
corona10:gh-158165
Oct 2, 2026
Merged

corona10 merged 1 commit into
python:mainfrom
corona10:gh-158165

Conversation

@corona10

@corona10 corona10 commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

@corona10

Copy link
Copy Markdown
Member Author

See godbolt generated code: https://godbolt.org/z/Thbs6Ec3K

@corona10

Copy link
Copy Markdown
Member Author

@markshannon markshannon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think repeating the code in the

result = (uintptr_t)_AddressOfReturnAddress();
#elif defined(__aarch64__)
__asm__ ("mov %0, sp" : "=r" (result));
#elif defined(__x86_64__)
__asm__("{movq %%rsp, %0" : "=r" (result));
__asm__ ("{movq %%rsp, %0|mov %0, rsp}" : "=r" (result));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this necessary? Does MinGW use a different assembler?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__asm__("{movq %%fs:0, %0|mov %0, qword ptr fs:[0]}" : "=r" (tid)); // x86_64 Linux, BSD uses FS

Just following _Py_ThreadId support for both assembler types.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's about defined(__x86_64__)

@corona10

Copy link
Copy Markdown
Member Author

I don't think repeating the code in the

@markshannon
Agree in most cases. Do you have better suggestions, or should we just leave it as is?

@corona10

Copy link
Copy Markdown
Member Author

@markshannon gentle ping?

@corona10
corona10 merged commit 5c7445b into python:main Oct 2, 2026
59 checks passed
@corona10 corona10 added the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Oct 2, 2026
@miss-islington-app

Copy link
Copy Markdown

Thanks @corona10 for the PR 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

Sorry, @corona10, I could not cleanly backport this to 3.15 due to a conflict.

Please backport manually with cherry_picker, see the devguide for more information.

cherry_picker 5c7445be431698c6764af1246b2f5d7ca5c5c930 3.15

@corona10 corona10 removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Oct 2, 2026
@bedevere-bot

Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot AMD64 Windows PGO NoGIL 3.x (tier-1) has failed when building commit 5c7445b.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/1622/builds/5794) and take a look at the build logs.
  4. Check if the failure is related to this commit (5c7445b) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/1622/builds/5794

Failed tests:

  • test_external_inspection
  • test_logging

Failed subtests:

  • test_rollover_based_on_st_birthtime_only - test.test_logging.TimedRotatingFileHandlerTest.test_rollover_based_on_st_birthtime_only
  • test_tlbc_cache_refresh_after_slot_fill - test.test_external_inspection.TestGetStackTrace.test_tlbc_cache_refresh_after_slot_fill

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (most recent call last):
  File "<string>", line 40, in <module>
    cached = lines(u, 2)
  File "<string>", line 18, in lines
    traces = u.get_stack_trace()
OSError: ReadProcessMemory failed for PID 14728 at address 0x1 (size 80, partial read 0 bytes): Windows error 299


Traceback (most recent call last):
  File "C:\bbarea\3.x.itamaro-win64-srv-22-aws.nogil.pgo\build\Lib\test\test_logging.py", line 6831, in test_rollover_based_on_st_birthtime_only
    self.assertTrue(found, msg=msg)
    ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
AssertionError: False is not true : No rotated files found, went back 5 seconds


Traceback (most recent call last):
  File "C:\bbarea\3.x.itamaro-win64-srv-22-aws.nogil.pgo\build\Lib\test\test_external_inspection.py", line 2446, in test_tlbc_cache_refresh_after_slot_fill
    self.assertEqual(
    ~~~~~~~~~~~~~~~~^
        result.returncode, 0,
        ^^^^^^^^^^^^^^^^^^^^^
        f"stdout: {result.stdout}\nstderr: {result.stderr}",
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
AssertionError: 1 != 0 : stdout: 
stderr: OSError: [WinError 299] Only part of a ReadProcessMemory or WriteProcessMemory request was completed


Traceback (most recent call last):
  File "<string>", line 40, in <module>
    cached = lines(u, 2)
  File "<string>", line 18, in lines
    traces = u.get_stack_trace()
OSError: ReadProcessMemory failed for PID 7940 at address 0x1 (size 80, partial read 0 bytes): Windows error 299

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants