Skip to content

Commit 80ea07a

Browse files
committed
Mach-O does not support 19 bit branches
1 parent 3cc7eed commit 80ea07a

File tree

3 files changed

+10
-18
lines changed

3 files changed

+10
-18
lines changed

Python/jit.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,6 @@ patch_aarch64_21rx(unsigned char *location, uint64_t value)
334334
patch_aarch64_21r(location, value);
335335
}
336336

337-
338337
// 21-bit relative branch.
339338
void
340339
patch_aarch64_19r(unsigned char *location, uint64_t value)
@@ -350,21 +349,6 @@ patch_aarch64_19r(unsigned char *location, uint64_t value)
350349
set_bits(loc32, 5, value, 2, 19);
351350
}
352351

353-
// 16-bit relative branch.
354-
void
355-
patch_aarch64_14r(unsigned char *location, uint64_t value)
356-
{
357-
uint32_t *loc32 = (uint32_t *)location;
358-
assert(IS_AARCH64_TEST_AND_BRANCH(*loc32));
359-
value -= (uintptr_t)location;
360-
// Check that we're not out of range of 16 signed bits:
361-
assert((int64_t)value >= -(1 << 15));
362-
assert((int64_t)value < (1 << 15));
363-
// Since instructions are 4-byte aligned, only use 14 bits:
364-
assert(get_bits(value, 0, 2) == 0);
365-
set_bits(loc32, 5, value, 2, 14);
366-
}
367-
368352
// 28-bit relative branch.
369353
void
370354
patch_aarch64_26r(unsigned char *location, uint64_t value)

Tools/jit/_optimizers.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,16 @@ def run(self) -> None:
311311
self.path.write_text(self._body())
312312

313313

314+
# Mach-O does not support the 19 bit branch locations needed for branch reordering
315+
class OptimizerAArch64_MachO(Optimizer): # pylint: disable = too-few-public-methods
316+
"""aarch64-apple-darwin"""
317+
318+
# https://developer.arm.com/documentation/ddi0602/2025-03/Base-Instructions/B--Branch-
319+
_re_jump = re.compile(r"\s*b\s+(?P<target>[\w.]+)")
320+
321+
314322
class OptimizerAArch64(Optimizer): # pylint: disable = too-few-public-methods
315-
"""aarch64-apple-darwin/aarch64-pc-windows-msvc/aarch64-unknown-linux-gnu"""
323+
"""aarch64-pc-windows-msvc/aarch64-unknown-linux-gnu"""
316324

317325
_branches = _AARCH64_BRANCHES
318326
_re_branch = re.compile(

Tools/jit/_targets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ def get_target(host: str) -> _COFF32 | _COFF64 | _ELF | _MachO:
565565
if re.fullmatch(r"aarch64-apple-darwin.*", host):
566566
host = "aarch64-apple-darwin"
567567
condition = "defined(__aarch64__) && defined(__APPLE__)"
568-
optimizer = _optimizers.OptimizerAArch64
568+
optimizer = _optimizers.OptimizerAArch64_MachO
569569
target = _MachO(host, condition, optimizer=optimizer)
570570
elif re.fullmatch(r"aarch64-pc-windows-msvc", host):
571571
host = "aarch64-pc-windows-msvc"

0 commit comments

Comments
 (0)