FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-131798: JIT inline function addresses of builtin methods by kumaraditya303 · Pull Request #146906 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension .c  (1) .py  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
Prev Previous commit
Next Next commit
also fix x86-64
  • Loading branch information
kumaraditya303 committed Apr 3, 2026
commit a30fcb87e6077256e453b5b3f774488629761d1b
9 changes: 8 additions & 1 deletion Python/jit.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@ void patch_got_symbol(jit_state *state, int ordinal);
void patch_aarch64_trampoline(unsigned char *location, int ordinal, jit_state *state);
void patch_aarch64_trampoline_addr(unsigned char *location, int ordinal, uint64_t value, jit_state *state);
void patch_x86_64_trampoline(unsigned char *location, int ordinal, jit_state *state);
void patch_x86_64_trampoline_addr(unsigned char *location, int ordinal, uint64_t value, jit_state *state);

#include "jit_stencils.h"

Expand Down Expand Up @@ -618,7 +619,13 @@ void
patch_x86_64_trampoline(unsigned char *location, int ordinal, jit_state *state)
{
uint64_t value = (uintptr_t)symbols_map[ordinal];
int64_t range = (int64_t)value - 4 - (int64_t)location;
patch_x86_64_trampoline_addr(location, ordinal, value, state);
}

void
patch_x86_64_trampoline_addr(unsigned char *location, int ordinal, uint64_t value, jit_state *state)
{
int64_t range = (int64_t)value - 4 - (int64_t)(uintptr_t)location;

// If we are in range of 32 signed bits, we can patch directly
if (range >= -(1LL << 31) && range < (1LL << 31)) {
Expand Down
13 changes: 13 additions & 0 deletions Tools/jit/_stencils.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,19 @@ def process_relocations(self, known_symbols: dict[str, int]) -> None:
hole.func = "patch_aarch64_trampoline_addr"
hole.need_state = True
hole.custom_value = f"{ordinal}, {value_expr}"
# x86_64 trampolines for operand-based call targets (e.g. inlined cfunc)
elif (
hole.kind in {"R_X86_64_PLT32", "X86_64_RELOC_BRANCH"}
and hole.value in {HoleValue.OPERAND0, HoleValue.OPERAND1}
):
value_expr = _HOLE_EXPRS[hole.value]
ordinal = len(known_symbols)
synth_name = f"_JIT_TRAMPOLINE_{hole.value.name}_{ordinal}"
known_symbols[synth_name] = ordinal
self._trampolines.add(ordinal)
hole.func = "patch_x86_64_trampoline_addr"
hole.need_state = True
hole.custom_value = f"{ordinal}, {value_expr}"
# x86_64 Darwin trampolines for external symbols
elif (
hole.kind == "X86_64_RELOC_BRANCH"
Expand Down

Back | FazBrowse Home | New Git URL