-
-
Notifications
You must be signed in to change notification settings - Fork 33.6k
GH-136895: Update JIT builds to use LLVM 20 #140329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 33 commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
d145747
LLVM 20 bump
savannahostrowski d86b66e
Merge main
savannahostrowski 9324b14
Add flags for testing
savannahostrowski f3bb6b9
Merge branch 'main' into llvm-20
savannahostrowski b6e7981
Merge main
savannahostrowski e867644
Fix windows
savannahostrowski 13e9f5b
Merge main
savannahostrowski 84781b4
Merge branch 'main' into llvm-20
savannahostrowski 0034f14
Download binaries from GitHub releases
emmatyping cc98d30
Add hash checking
emmatyping 76842eb
Apply Emma's commits for grabbing binaries from release artifacts
savannahostrowski a732cec
Merge branch 'main' into llvm-20
savannahostrowski e8395ce
Fix up LLVM via release artifacts
savannahostrowski d1e4363
Merge branch 'main' into llvm-20
savannahostrowski 01aed67
Remove model flags for x86_64 darwin causing GOT relocation issues
savannahostrowski 94f1a89
Clean up
savannahostrowski e6450de
Only patch x86_64 GOT relocations when relaxation succeeds
savannahostrowski 1adf827
Revert "Only patch x86_64 GOT relocations when relaxation succeeds"
savannahostrowski b9bfacf
mcmodel=large
savannahostrowski 57c44ee
Add macro to handle debug
savannahostrowski 081ee86
fno-pic
savannahostrowski 0b773f9
remove fno-pic
savannahostrowski c78af6f
remove hack
savannahostrowski d715cf2
Trampoline attempt
savannahostrowski 38e11b9
Touch up and add better comments
savannahostrowski 74eb9a4
Merge main
savannahostrowski ca95652
More clean up
savannahostrowski 47153a5
📜🤖 Added by blurb_it.
blurb-it[bot] 7b2df52
Redupe LLVM version reference from jit.yml
savannahostrowski 3a5af39
Merge branch 'llvm-20' of https://github.com/savannahostrowski/cpytho…
savannahostrowski 450dd09
Simplify fetching LLVM from bin-deps
savannahostrowski 5da3349
Remove duplicate 20 reference in jit.yml
savannahostrowski 620cd4f
Fix flags
savannahostrowski d1a68ab
Reduce DATA_ALIGN to 8 bytes
savannahostrowski f3d46bd
Merge branch 'main' into llvm-20
savannahostrowski 4b35c2f
Update Devcontainer readme
savannahostrowski ffcb68e
Merge branch 'llvm-20' of https://github.com/savannahostrowski/cpytho…
savannahostrowski 0540ba3
Merge branch 'main' into llvm-20
savannahostrowski 618a4a6
Revert CI simplication and address comments for memcpy
savannahostrowski 2e9ba92
Address comments about get_externals and trampoline helper
savannahostrowski a21cb31
Merge branch 'main' into llvm-20
savannahostrowski 795f466
Restore get_externals
savannahostrowski b880f26
Fix spacing
savannahostrowski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
1 change: 1 addition & 0 deletions
1
Misc/NEWS.d/next/Core_and_Builtins/2025-10-19-10-32-28.gh-issue-136895.HfsEh0.rst
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Update JIT compilation to use LLVM 20 at build time. |
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -444,12 +444,18 @@ patch_x86_64_32rx(unsigned char *location, uint64_t value) | |
| } | ||
|
|
||
| void patch_aarch64_trampoline(unsigned char *location, int ordinal, jit_state *state); | ||
| void patch_x86_64_trampoline(unsigned char *location, int ordinal, jit_state *state); | ||
|
|
||
| #include "jit_stencils.h" | ||
|
|
||
| #if defined(__aarch64__) || defined(_M_ARM64) | ||
| #define TRAMPOLINE_SIZE 16 | ||
| #define DATA_ALIGN 8 | ||
| #elif defined(__x86_64__) && defined(__APPLE__) | ||
| // LLVM 20 on macOS x86_64 debug builds: GOT entries may exceed ±2GB PC-relative | ||
| // range. | ||
| #define TRAMPOLINE_SIZE 16 // 14 bytes + 2 bytes padding for alignment | ||
| #define DATA_ALIGN 16 | ||
diegorusso marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| #else | ||
| #define TRAMPOLINE_SIZE 0 | ||
| #define DATA_ALIGN 1 | ||
|
|
@@ -501,6 +507,48 @@ patch_aarch64_trampoline(unsigned char *location, int ordinal, jit_state *state) | |
| patch_aarch64_26r(location, (uintptr_t)p); | ||
| } | ||
|
|
||
| // Generate and patch x86_64 trampolines. | ||
| void | ||
| patch_x86_64_trampoline(unsigned char *location, int ordinal, jit_state *state) | ||
| { | ||
| uint64_t value = (uintptr_t)symbols_map[ordinal]; | ||
| int64_t range = (int64_t)value - 4 - (int64_t)location; | ||
|
|
||
| // If we are in range of 32 signed bits, we can patch directly | ||
| if (range >= -(1LL << 31) && range < (1LL << 31)) { | ||
| patch_32r(location, value - 4); | ||
| return; | ||
| } | ||
|
|
||
| // Out of range - need a trampoline | ||
| const uint32_t symbol_mask = 1 << (ordinal % 32); | ||
| const uint32_t trampoline_mask = state->trampolines.mask[ordinal / 32]; | ||
| assert(symbol_mask & trampoline_mask); | ||
|
|
||
| // Count the number of set bits in the trampoline mask lower than ordinal | ||
| int index = _Py_popcount32(trampoline_mask & (symbol_mask - 1)); | ||
| for (int i = 0; i < ordinal / 32; i++) { | ||
| index += _Py_popcount32(state->trampolines.mask[i]); | ||
| } | ||
|
|
||
| unsigned char *trampoline = state->trampolines.mem + index * TRAMPOLINE_SIZE; | ||
| assert((size_t)(index + 1) * TRAMPOLINE_SIZE <= state->trampolines.size); | ||
savannahostrowski marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /* 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; | ||
savannahostrowski marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| *(uint64_t *)(trampoline + 6) = value; | ||
savannahostrowski marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // Patch the call site to call the trampoline instead | ||
| patch_32r(location, (uintptr_t)trampoline - 4); | ||
| } | ||
|
|
||
| static void | ||
| combine_symbol_mask(const symbol_mask src, symbol_mask dest) | ||
| { | ||
|
|
||
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.