Skip to content

Commit e47f743

Browse files
committed
gh-130956: emit AArch64 trampolines only for long jumps
Emit the AArch64 trampoline only if the address is more than 27 bits range. Enable the PLT for Linux AArch64: without it no trampolines are emitted at all and symbols are referenced via the GOT.
1 parent 98fa4a4 commit e47f743

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

Python/jit.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,17 @@ void patch_aarch64_trampoline(unsigned char *location, int ordinal, jit_state *s
430430
void
431431
patch_aarch64_trampoline(unsigned char *location, int ordinal, jit_state *state)
432432
{
433+
434+
uint64_t value = (uintptr_t)symbols_map[ordinal];
435+
int64_t range = value - (uintptr_t)location;
436+
437+
// If we are in range of 28 signed bits, we patch the instruction with
438+
// the address of the symbol.
439+
if (range >= -(1 << 27) && range < (1 << 27)) {
440+
patch_aarch64_26r(location, (uintptr_t)value);
441+
return;
442+
}
443+
433444
// Masking is done modulo 32 as the mask is stored as an array of uint32_t
434445
const uint32_t symbol_mask = 1 << (ordinal % 32);
435446
const uint32_t trampoline_mask = state->trampolines.mask[ordinal / 32];
@@ -445,7 +456,6 @@ patch_aarch64_trampoline(unsigned char *location, int ordinal, jit_state *state)
445456
uint32_t *p = (uint32_t*)(state->trampolines.mem + index * TRAMPOLINE_SIZE);
446457
assert((size_t)(index + 1) * TRAMPOLINE_SIZE <= state->trampolines.size);
447458

448-
uint64_t value = (uintptr_t)symbols_map[ordinal];
449459

450460
/* Generate the trampoline
451461
0: 58000048 ldr x8, 8

Tools/jit/_targets.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,7 @@ def get_target(host: str) -> _COFF | _ELF | _MachO:
507507
# On aarch64 Linux, intrinsics were being emitted and this flag
508508
# was required to disable them.
509509
"-mno-outline-atomics",
510+
"-fplt",
510511
]
511512
target = _ELF(host, alignment=8, args=args)
512513
elif re.fullmatch(r"i686-pc-windows-msvc", host):

0 commit comments

Comments
 (0)