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

gh-147805: handles large addresses in arm64 relocations by kumaraditya303 · Pull Request #147941 · python/cpython · GitHub

Repository navigation

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .py  (2) 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
15 changes: 12 additions & 3 deletions 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 @@ -554,6 +554,7 @@ patch_x86_64_32rx(unsigned char *location, uint64_t value)

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);

#include "jit_stencils.h"
Expand Down Expand Up @@ -585,14 +586,22 @@ patch_got_symbol(jit_state *state, int ordinal)
void
patch_aarch64_trampoline(unsigned char *location, int ordinal, jit_state *state)
{

uint64_t value = (uintptr_t)symbols_map[ordinal];
int64_t range = value - (uintptr_t)location;
patch_aarch64_trampoline_addr(location, ordinal, value, state);
}

// Generate and patch AArch64 trampolines for dynamic addresses (e.g. operands).
// Unlike patch_aarch64_trampoline, the target address is passed directly rather
// than looked up from symbols_map. The ordinal is used to allocate a trampoline slot.
void
patch_aarch64_trampoline_addr(unsigned char *location, int ordinal, uint64_t value, jit_state *state)
{
int64_t range = (int64_t)value - (int64_t)(uintptr_t)location;

// If we are in range of 28 signed bits, we patch the instruction with
// the address of the symbol.
if (range >= -(1 << 27) && range < (1 << 27)) {
patch_aarch64_26r(location, (uintptr_t)value);
patch_aarch64_26r(location, value);
return;
}

Expand Down
17 changes: 17 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 @@ -296,6 +296,23 @@ def process_relocations(self, known_symbols: dict[str, int]) -> None:
self._trampolines.add(ordinal)
hole.addend = ordinal
hole.symbol = None
# aarch64 trampolines for operand-based call targets (e.g. inlined cfunc)
elif (
hole.kind
in {"R_AARCH64_CALL26", "R_AARCH64_JUMP26", "ARM64_RELOC_BRANCH26"}
and hole.value in {HoleValue.OPERAND0, HoleValue.OPERAND1}
):
value_expr = _HOLE_EXPRS[hole.value]
synth_name = f"_JIT_TRAMPOLINE_{hole.value.name}"
if synth_name in known_symbols:
ordinal = known_symbols[synth_name]
else:
ordinal = len(known_symbols)
known_symbols[synth_name] = ordinal
self._trampolines.add(ordinal)
hole.func = "patch_aarch64_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
5 changes: 4 additions & 1 deletion Tools/jit/_writer.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 @@ -35,7 +35,10 @@ def _dump_footer(
yield f"static const void * const symbols_map[{max(len(symbols), 1)}] = {{"
if symbols:
for symbol, ordinal in symbols.items():
yield f" [{ordinal}] = &{symbol},"
if symbol.startswith("_JIT_TRAMPOLINE_"):
yield f" [{ordinal}] = 0,"
else:
yield f" [{ordinal}] = &{symbol},"
else:
yield " 0"
yield "};"
Expand Down
Loading

Back | FazBrowse Home | New Git URL