]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
GH-142621: JIT: Avoid memory load for symbols within 4GB on AArch64 (GH-142820)
authorMark Shannon <mark@hotpy.org>
Wed, 17 Dec 2025 12:07:07 +0000 (12:07 +0000)
committerGitHub <noreply@github.com>
Wed, 17 Dec 2025 12:07:07 +0000 (12:07 +0000)
Python/jit.c

index 602d7a519bd3fc7eaa1c6f8ef00e73f375e0abb0..ccafe0ce497f430568a214bfaf4dd87a653c7d3d 100644 (file)
@@ -432,6 +432,15 @@ patch_aarch64_33rx(unsigned char *location, uint64_t value)
         loc32[1] = 0xF2A00000 | (get_bits(relaxed, 16, 16) << 5) | reg;
         return;
     }
+    int64_t page_delta = (relaxed >> 12) - ((uintptr_t)location >> 12);
+    if (page_delta >= -(1L << 20) &&
+        page_delta < (1L << 20))
+    {
+        // adrp reg, AAA; ldr reg, [reg + BBB] -> adrp reg, AAA; add reg, reg, BBB
+        patch_aarch64_21rx(location, relaxed);
+        loc32[1] = 0x91000000 | get_bits(relaxed, 0, 12) << 10 | reg << 5 | reg;
+        return;
+    }
     relaxed = value - (uintptr_t)location;
     if ((relaxed & 0x3) == 0 &&
         (int64_t)relaxed >= -(1L << 19) &&