Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
JIT: harden LLVM 20 upgrade with defensive improvements
- Enable x86_64 trampoline support on all x86_64 platforms, not just
  macOS. While currently only macOS emits X86_64_RELOC_BRANCH
  relocations, this ensures the trampoline infrastructure is ready if
  future LLVM changes produce out-of-range calls on other x86_64
  platforms.

- Add error handling to extract_tarball() in get_external.py so that
  corrupted or incomplete downloads produce a clear error message
  instead of an opaque traceback.

- Replace hardcoded LLVM version check in get_externals.bat with a
  prefix-based 'llvm-' match using findstr, so future LLVM version
  bumps only require changing the version string in one place.
  • Loading branch information
mcepl committed Mar 25, 2026
commit 4a2251e79b29b01dbba0a6013f3284d0a9fad0d8
8 changes: 7 additions & 1 deletion PCbuild/get_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ def fetch_release(tag, tarball_dir, *, org='python', verbose=False):

def extract_tarball(externals_dir, tarball_path, tag):
output_path = externals_dir / tag
shutil.unpack_archive(os.fspath(tarball_path), os.fspath(output_path))
try:
shutil.unpack_archive(os.fspath(tarball_path), os.fspath(output_path))
except Exception as ex:
raise OSError(
f'Failed to extract {tarball_path}. The archive may be '
f'corrupted; try deleting it and re-running.'
) from ex
return output_path


Expand Down
10 changes: 4 additions & 6 deletions PCbuild/get_externals.bat
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@echo off
setlocal
setlocal EnableDelayedExpansion
rem Simple script to fetch source for external libraries

if NOT DEFINED PCBUILD (set PCBUILD=%~dp0)
Expand Down Expand Up @@ -92,11 +92,9 @@ for %%b in (%binaries%) do (
git clone --depth 1 https://github.com/%ORG%/cpython-bin-deps --branch %%b "%EXTERNALS_DIR%\%%b"
) else (
echo.Fetching %%b...
if "%%b"=="llvm-20.1.8.0" (
%PYTHON% -E "%PCBUILD%\get_external.py" --release --organization %ORG% --externals-dir "%EXTERNALS_DIR%" %%b
) else (
%PYTHON% -E "%PCBUILD%\get_external.py" --binary --organization %ORG% --externals-dir "%EXTERNALS_DIR%" %%b
)
set _fetch_args=--binary
echo %%b | findstr /B "llvm-" >nul && set _fetch_args=--release
%PYTHON% -E "%PCBUILD%\get_external.py" !_fetch_args! --organization %ORG% --externals-dir "%EXTERNALS_DIR%" %%b
)
)

Expand Down
9 changes: 5 additions & 4 deletions Python/jit.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,10 +426,11 @@ void patch_x86_64_trampoline(unsigned char *location, int ordinal, jit_state *st
#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
#elif defined(__x86_64__) || defined(_M_X64)
// x86_64 trampolines: 14 bytes (jmp *(%rip) + 8-byte addr) + 2 bytes padding.
// Currently used on macOS where LLVM 20 GOT entries may exceed ±2GB
// PC-relative range, but enabled on all x86_64 platforms defensively.
#define TRAMPOLINE_SIZE 16
#define DATA_ALIGN 8
#else
#define TRAMPOLINE_SIZE 0
Expand Down