Skip to content

Commit ecc3408

Browse files
committed
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.
1 parent efbeaa5 commit ecc3408

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

PCbuild/get_external.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,13 @@ def fetch_release(tag, tarball_dir, *, org='python', verbose=False):
5656

5757
def extract_tarball(externals_dir, tarball_path, tag):
5858
output_path = externals_dir / tag
59-
shutil.unpack_archive(os.fspath(tarball_path), os.fspath(output_path))
59+
try:
60+
shutil.unpack_archive(os.fspath(tarball_path), os.fspath(output_path))
61+
except Exception as ex:
62+
raise OSError(
63+
f'Failed to extract {tarball_path}. The archive may be '
64+
f'corrupted; try deleting it and re-running.'
65+
) from ex
6066
return output_path
6167

6268

PCbuild/get_externals.bat

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@echo off
2-
setlocal
2+
setlocal EnableDelayedExpansion
33
rem Simple script to fetch source for external libraries
44

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

Python/jit.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -426,10 +426,11 @@ void patch_x86_64_trampoline(unsigned char *location, int ordinal, jit_state *st
426426
#if defined(__aarch64__) || defined(_M_ARM64)
427427
#define TRAMPOLINE_SIZE 16
428428
#define DATA_ALIGN 8
429-
#elif defined(__x86_64__) && defined(__APPLE__)
430-
// LLVM 20 on macOS x86_64 debug builds: GOT entries may exceed ±2GB PC-relative
431-
// range.
432-
#define TRAMPOLINE_SIZE 16 // 14 bytes + 2 bytes padding for alignment
429+
#elif defined(__x86_64__) || defined(_M_X64)
430+
// x86_64 trampolines: 14 bytes (jmp *(%rip) + 8-byte addr) + 2 bytes padding.
431+
// Currently used on macOS where LLVM 20 GOT entries may exceed ±2GB
432+
// PC-relative range, but enabled on all x86_64 platforms defensively.
433+
#define TRAMPOLINE_SIZE 16
433434
#define DATA_ALIGN 8
434435
#else
435436
#define TRAMPOLINE_SIZE 0

0 commit comments

Comments
 (0)