From ba321203b70eac94e84cc66a97753fb415b8d904 Mon Sep 17 00:00:00 2001 From: Diego Russo Date: Wed, 25 Mar 2026 08:40:37 +0000 Subject: [PATCH 1/3] GH-115802: Remove no-plt for Linux targets --- Python/jit.c | 15 +++++++++++---- Tools/jit/_stencils.py | 1 + Tools/jit/_targets.py | 4 ++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Python/jit.c b/Python/jit.c index d56ff6ad156c03..6d1ce8d456365f 100644 --- a/Python/jit.c +++ b/Python/jit.c @@ -316,18 +316,25 @@ patch_32(unsigned char *location, uint64_t value) memcpy(location, &final_value, sizeof(final_value)); } -// 32-bit relative address. +// 32-bit absolute address, sign-extended by the instruction. void -patch_32r(unsigned char *location, uint64_t value) +patch_32s(unsigned char *location, uint64_t value) { - value -= (uintptr_t)location; // Check that we're not out of range of 32 signed bits: assert((int64_t)value >= -(1LL << 31)); assert((int64_t)value < (1LL << 31)); - uint32_t final_value = (uint32_t)value; + int32_t final_value = (int32_t)value; memcpy(location, &final_value, sizeof(final_value)); } +// 32-bit relative address. +void +patch_32r(unsigned char *location, uint64_t value) +{ + value -= (uintptr_t)location; + patch_32s(location, value); +} + // 64-bit absolute address. void patch_64(unsigned char *location, uint64_t value) diff --git a/Tools/jit/_stencils.py b/Tools/jit/_stencils.py index 55a4aece5427c2..423c1774cf4279 100644 --- a/Tools/jit/_stencils.py +++ b/Tools/jit/_stencils.py @@ -90,6 +90,7 @@ class HoleValue(enum.Enum): "R_AARCH64_MOVW_UABS_G2_NC": "patch_aarch64_16c", "R_AARCH64_MOVW_UABS_G3": "patch_aarch64_16d", # x86_64-unknown-linux-gnu: + "R_X86_64_32S": "patch_32s", "R_X86_64_64": "patch_64", "R_X86_64_GOTPCRELX": "patch_x86_64_32rx", "R_X86_64_PLT32": "patch_32r", diff --git a/Tools/jit/_targets.py b/Tools/jit/_targets.py index 787fcf53260f3d..d55e235c35c7a5 100644 --- a/Tools/jit/_targets.py +++ b/Tools/jit/_targets.py @@ -594,7 +594,7 @@ def get_target(host: str) -> _COFF32 | _COFF64 | _ELF | _MachO: host = "aarch64-unknown-linux-gnu" condition = "defined(__aarch64__) && defined(__linux__)" # -mno-outline-atomics: Keep intrinsics from being emitted. - args = ["-fpic", "-mno-outline-atomics", "-fno-plt"] + args = ["-fpic", "-mno-outline-atomics"] optimizer = _optimizers.OptimizerAArch64 target = _ELF( host, condition, args=args, optimizer=optimizer, frame_pointers=True @@ -622,7 +622,7 @@ def get_target(host: str) -> _COFF32 | _COFF64 | _ELF | _MachO: elif re.fullmatch(r"x86_64-.*-linux-gnu", host): host = "x86_64-unknown-linux-gnu" condition = "defined(__x86_64__) && defined(__linux__)" - args = ["-fno-pic", "-mcmodel=medium", "-mlarge-data-threshold=0", "-fno-plt"] + args = ["-fno-pic", "-mcmodel=medium", "-mlarge-data-threshold=0"] optimizer = _optimizers.OptimizerX86 target = _ELF( host, condition, args=args, optimizer=optimizer, frame_pointers=True From 89e4994d8fe6206a116f356825ea9931553543bc Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Wed, 8 Apr 2026 06:59:29 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2026-04-08-06-59-23.gh-issue-115802.jqfZty.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2026-04-08-06-59-23.gh-issue-115802.jqfZty.rst diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-04-08-06-59-23.gh-issue-115802.jqfZty.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-04-08-06-59-23.gh-issue-115802.jqfZty.rst new file mode 100644 index 00000000000000..17571ed77ec0c6 --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-04-08-06-59-23.gh-issue-115802.jqfZty.rst @@ -0,0 +1 @@ +Improve JIT code generation on Linux targets by reducing the indirect call to external symbols. Patch by Diego Russo. From 67149067417cac6d5b1ce00723180dead5af16c1 Mon Sep 17 00:00:00 2001 From: Diego Russo Date: Wed, 8 Apr 2026 15:09:59 +0100 Subject: [PATCH 3/3] Revert changes for Linux x86-64 --- ...2026-04-08-06-59-23.gh-issue-115802.jqfZty.rst | 2 +- Python/jit.c | 15 ++++----------- Tools/jit/_stencils.py | 1 - Tools/jit/_targets.py | 2 +- 4 files changed, 6 insertions(+), 14 deletions(-) diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-04-08-06-59-23.gh-issue-115802.jqfZty.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-04-08-06-59-23.gh-issue-115802.jqfZty.rst index 17571ed77ec0c6..13ed51be0e6c5c 100644 --- a/Misc/NEWS.d/next/Core_and_Builtins/2026-04-08-06-59-23.gh-issue-115802.jqfZty.rst +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-04-08-06-59-23.gh-issue-115802.jqfZty.rst @@ -1 +1 @@ -Improve JIT code generation on Linux targets by reducing the indirect call to external symbols. Patch by Diego Russo. +Improve JIT code generation on Linux AArch64 by reducing the indirect call to external symbols. Patch by Diego Russo. diff --git a/Python/jit.c b/Python/jit.c index 6d1ce8d456365f..d56ff6ad156c03 100644 --- a/Python/jit.c +++ b/Python/jit.c @@ -316,25 +316,18 @@ patch_32(unsigned char *location, uint64_t value) memcpy(location, &final_value, sizeof(final_value)); } -// 32-bit absolute address, sign-extended by the instruction. +// 32-bit relative address. void -patch_32s(unsigned char *location, uint64_t value) +patch_32r(unsigned char *location, uint64_t value) { + value -= (uintptr_t)location; // Check that we're not out of range of 32 signed bits: assert((int64_t)value >= -(1LL << 31)); assert((int64_t)value < (1LL << 31)); - int32_t final_value = (int32_t)value; + uint32_t final_value = (uint32_t)value; memcpy(location, &final_value, sizeof(final_value)); } -// 32-bit relative address. -void -patch_32r(unsigned char *location, uint64_t value) -{ - value -= (uintptr_t)location; - patch_32s(location, value); -} - // 64-bit absolute address. void patch_64(unsigned char *location, uint64_t value) diff --git a/Tools/jit/_stencils.py b/Tools/jit/_stencils.py index 423c1774cf4279..55a4aece5427c2 100644 --- a/Tools/jit/_stencils.py +++ b/Tools/jit/_stencils.py @@ -90,7 +90,6 @@ class HoleValue(enum.Enum): "R_AARCH64_MOVW_UABS_G2_NC": "patch_aarch64_16c", "R_AARCH64_MOVW_UABS_G3": "patch_aarch64_16d", # x86_64-unknown-linux-gnu: - "R_X86_64_32S": "patch_32s", "R_X86_64_64": "patch_64", "R_X86_64_GOTPCRELX": "patch_x86_64_32rx", "R_X86_64_PLT32": "patch_32r", diff --git a/Tools/jit/_targets.py b/Tools/jit/_targets.py index d55e235c35c7a5..ea0a9722c3cdf8 100644 --- a/Tools/jit/_targets.py +++ b/Tools/jit/_targets.py @@ -622,7 +622,7 @@ def get_target(host: str) -> _COFF32 | _COFF64 | _ELF | _MachO: elif re.fullmatch(r"x86_64-.*-linux-gnu", host): host = "x86_64-unknown-linux-gnu" condition = "defined(__x86_64__) && defined(__linux__)" - args = ["-fno-pic", "-mcmodel=medium", "-mlarge-data-threshold=0"] + args = ["-fno-pic", "-mcmodel=medium", "-mlarge-data-threshold=0", "-fno-plt"] optimizer = _optimizers.OptimizerX86 target = _ELF( host, condition, args=args, optimizer=optimizer, frame_pointers=True