Skip to content

Commit 0a15b1c

Browse files
also fix x86-64
1 parent c3e35f2 commit 0a15b1c

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

Python/jit.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,7 @@ void patch_got_symbol(jit_state *state, int ordinal);
556556
void patch_aarch64_trampoline(unsigned char *location, int ordinal, jit_state *state);
557557
void patch_aarch64_trampoline_addr(unsigned char *location, int ordinal, uint64_t value, jit_state *state);
558558
void patch_x86_64_trampoline(unsigned char *location, int ordinal, jit_state *state);
559+
void patch_x86_64_trampoline_addr(unsigned char *location, int ordinal, uint64_t value, jit_state *state);
559560

560561
#include "jit_stencils.h"
561562

@@ -618,7 +619,13 @@ void
618619
patch_x86_64_trampoline(unsigned char *location, int ordinal, jit_state *state)
619620
{
620621
uint64_t value = (uintptr_t)symbols_map[ordinal];
621-
int64_t range = (int64_t)value - 4 - (int64_t)location;
622+
patch_x86_64_trampoline_addr(location, ordinal, value, state);
623+
}
624+
625+
void
626+
patch_x86_64_trampoline_addr(unsigned char *location, int ordinal, uint64_t value, jit_state *state)
627+
{
628+
int64_t range = (int64_t)value - 4 - (int64_t)(uintptr_t)location;
622629

623630
// If we are in range of 32 signed bits, we can patch directly
624631
if (range >= -(1LL << 31) && range < (1LL << 31)) {

Tools/jit/_stencils.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,19 @@ def process_relocations(self, known_symbols: dict[str, int]) -> None:
310310
hole.func = "patch_aarch64_trampoline_addr"
311311
hole.need_state = True
312312
hole.custom_value = f"{ordinal}, {value_expr}"
313+
# x86_64 trampolines for operand-based call targets (e.g. inlined cfunc)
314+
elif (
315+
hole.kind in {"R_X86_64_PLT32", "X86_64_RELOC_BRANCH"}
316+
and hole.value in {HoleValue.OPERAND0, HoleValue.OPERAND1}
317+
):
318+
value_expr = _HOLE_EXPRS[hole.value]
319+
ordinal = len(known_symbols)
320+
synth_name = f"_JIT_TRAMPOLINE_{hole.value.name}_{ordinal}"
321+
known_symbols[synth_name] = ordinal
322+
self._trampolines.add(ordinal)
323+
hole.func = "patch_x86_64_trampoline_addr"
324+
hole.need_state = True
325+
hole.custom_value = f"{ordinal}, {value_expr}"
313326
# x86_64 Darwin trampolines for external symbols
314327
elif (
315328
hole.kind == "X86_64_RELOC_BRANCH"

0 commit comments

Comments
 (0)