Skip to content

Conversation

@savannahostrowski
Copy link
Member

@savannahostrowski savannahostrowski commented Oct 19, 2025

Alright, this took me longer than expected for two reasons:

  • Bumping to LLVM 20 required some changes to the infrastructure we use to grab LLVM as a dependency on Windows. As of 20, LLVM now contains files that exceed GitHub's allowable size, so checking these directly into cpython-bin-deps' tree was not an option. Instead, this PR adds the ability to pull from release artifacts (see https://github.com/python/cpython-bin-deps/releases/tag/llvm-20.1.8.0). This also makes the process of bumping LLVM for Windows a little less hairy. Thank you, @emmatyping, for much of this code, and thank you, @zware, for publishing the release artifact for me 🙏 !

  • For macOS x86_64 debug builds, external symbol references generated by LLVM 20 can exceed the ±2GB PC-relative addressing range that patch_32r requires. This manifested as assertion failures in free-threading tests (see https://github.com/savannahostrowski/cpython/actions/runs/18438327725/job/52537027963?pr=10 as an example). After going down a rabbit hole, I believe the correct fix here is to implement x86_64 trampolines (similar to our existing aarch64 implementation) to handle out-of-range symbols...and so I've done that. AFAICT, trampolines are only needed on macOS right now, as the other target platforms have different relocation mechanisms.

Copy link
Contributor

@ashm-dev ashm-dev left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@diegorusso diegorusso left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for addressing the comments.

@savannahostrowski
Copy link
Member Author

Trying to do my due diligence here before this gets merged...

@python/windows-team Does someone want to have a look at the changes in PCbuild/get_external.py to accommodate downloading LLVM as a release artifact? @emmatyping, maybe you can give me a formal review on this piece as well? 😄

Copy link
Member

@emmatyping emmatyping left a comment

Choose a reason for hiding this comment

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

Two suggestions, but I think get_externals[.py,.bat] look good otherwise!

Copy link
Member

@markshannon markshannon left a comment

Choose a reason for hiding this comment

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

A bit of C pedantry. Otherwise looks good.

@bedevere-app
Copy link

bedevere-app bot commented Oct 30, 2025

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

Copy link
Member

@brandtbucher brandtbucher left a comment

Choose a reason for hiding this comment

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

Awesome! Here's a partial review of everything except the stuff in Tools (I'd like to dig a bit more into the changes to the flags and relocations and see how they affect the code quality).

Python/jit.c Outdated
Comment on lines 537 to 546
/* Generate the trampoline (14 bytes, padded to 16):
0: ff 25 00 00 00 00 jmp *(%rip)
6: XX XX XX XX XX XX XX XX (64-bit target address)
Reference: https://wiki.osdev.org/X86-64_Instruction_Encoding#FF (JMP r/m64)
*/
trampoline[0] = 0xFF;
trampoline[1] = 0x25;
*(uint32_t *)(trampoline + 2) = 0;
*(uint64_t *)(trampoline + 6) = value;
Copy link
Member

Choose a reason for hiding this comment

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

@savannahostrowski... just want to make sure it's not lost on you how badass you are hand-writing x86-64 machine code byte-by-byte like this. 🔥

@markshannon markshannon self-requested a review October 31, 2025 10:25
Copy link
Member

@markshannon markshannon left a comment

Choose a reason for hiding this comment

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

Looks good

Copy link
Member

@emmatyping emmatyping left a comment

Choose a reason for hiding this comment

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

This looks great! Very excited for this

@savannahostrowski
Copy link
Member Author

I am going to merge this since it has multiple reviews and is blocking some other work that we'd like to do. @brandtbucher let's chat offline about any other changes we'd like to make here re. flags/relocations, happy to follow up!

@savannahostrowski savannahostrowski merged commit 4e2ff4a into python:main Nov 3, 2025
74 of 75 checks passed
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.

8 participants