From: Mark Shannon Date: Thu, 23 Oct 2025 15:45:57 +0000 (+0100) Subject: GH-135904: JIT compiler: Support 19 bit branch instructions on AArch64 for Mach-O... X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=61e759c2ee521ccf817293d6150094b618fbeee5;p=thirdparty%2FPython%2Fcpython.git GH-135904: JIT compiler: Support 19 bit branch instructions on AArch64 for Mach-O. (GH-140453) * Insert labels into assembly for custom relocation during stencil creation. --- diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2025-10-22-11-30-16.gh-issue-135904.3WE5oW.rst b/Misc/NEWS.d/next/Core_and_Builtins/2025-10-22-11-30-16.gh-issue-135904.3WE5oW.rst new file mode 100644 index 000000000000..b52a57dba4ac --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2025-10-22-11-30-16.gh-issue-135904.3WE5oW.rst @@ -0,0 +1,3 @@ +Add special labels to the assembly created during stencil creation to +support relocations that the native object file format does not support. +Specifically, 19 bit branches for AArch64 in Mach-O object files. diff --git a/Tools/jit/_optimizers.py b/Tools/jit/_optimizers.py index 866417398b0b..0adc550ba5e8 100644 --- a/Tools/jit/_optimizers.py +++ b/Tools/jit/_optimizers.py @@ -9,7 +9,7 @@ import typing _RE_NEVER_MATCH = re.compile(r"(?!)") # Dictionary mapping branch instructions to their inverted branch instructions. # If a branch cannot be inverted, the value is None: -_X86_BRANCHES = { +_X86_BRANCH_NAMES = { # https://www.felixcloutier.com/x86/jcc "ja": "jna", "jae": "jnae", @@ -37,7 +37,11 @@ _X86_BRANCHES = { "loopz": None, } # Update with all of the inverted branches, too: -_X86_BRANCHES |= {v: k for k, v in _X86_BRANCHES.items() if v} +_X86_BRANCH_NAMES |= {v: k for k, v in _X86_BRANCH_NAMES.items() if v} +# No custom relocations needed +_X86_BRANCHES: dict[str, tuple[str | None, str | None]] = { + k: (v, None) for k, v in _X86_BRANCH_NAMES.items() +} _AARCH64_COND_CODES = { # https://developer.arm.com/documentation/dui0801/b/CJAJIHAD?lang=en @@ -58,12 +62,15 @@ _AARCH64_COND_CODES = { "hi": "ls", "ls": "hi", } +# MyPy doesn't understand that a invariant variable can be initialized by a covariant value +CUSTOM_AARCH64_BRANCH19: str | None = "CUSTOM_AARCH64_BRANCH19" + # Branches are either b.{cond} or bc.{cond} -_AARCH64_BRANCHES = { - "b." + cond: ("b." + inverse if inverse else None) +_AARCH64_BRANCHES: dict[str, tuple[str | None, str | None]] = { + "b." + cond: (("b." + inverse if inverse else None), CUSTOM_AARCH64_BRANCH19) for (cond, inverse) in _AARCH64_COND_CODES.items() } | { - "bc." + cond: ("bc." + inverse if inverse else None) + "bc." + cond: (("bc." + inverse if inverse else None), CUSTOM_AARCH64_BRANCH19) for (cond, inverse) in _AARCH64_COND_CODES.items() } @@ -113,7 +120,8 @@ class Optimizer: r'\s*(?P