From 2023452aff7ad6dbd346b7c0e636b9d2ceb9d534 Mon Sep 17 00:00:00 2001 From: Brandt Bucher Date: Thu, 13 Jul 2023 17:37:52 -0700 Subject: [PATCH] Try just setting the implict shift as needed --- .github/workflows/jit.yml | 4 ++-- Python/jit.c | 37 +++++++++++++++++++++++++------------ 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/.github/workflows/jit.yml b/.github/workflows/jit.yml index 51322410a06474..b665ce0097272a 100644 --- a/.github/workflows/jit.yml +++ b/.github/workflows/jit.yml @@ -21,9 +21,9 @@ jobs: - true # - false llvm: - # - 14 + - 14 # - 15 - - 16 + # - 16 include: # - target: i686-pc-windows-msvc/msvc # architecture: i686 diff --git a/Python/jit.c b/Python/jit.c index f20dc85eda42ed..1c1c9781e4a536 100644 --- a/Python/jit.c +++ b/Python/jit.c @@ -67,29 +67,42 @@ patch_one(unsigned char *location, HoleKind kind, uint64_t value, uint64_t adden uint32_t instruction = *addr; assert(((instruction & 0x3B000000) == 0x39000000) || ((instruction & 0x11C00000) == 0x11000000)); - if ((value + addend) & 0x7) { // XXX: Remote debugging info. - printf("PATCH_ABS_12: possibly unaligned value %lu + %lu (at %p)\n", value, addend, location); - }; value = (value + addend) & ((1 << 12) - 1); int implicit_shift = 0; if ((instruction & 0x3B000000) == 0x39000000) { implicit_shift = ((instruction >> 30) & 0x3); + // XXX: We shouldn't have to rewrite these (we *should* be + // able to just assert the alignment), but something's up with + // aarch64 + ELF (at least with LLVM 14, I haven't tested 15 + // and 16): switch (implicit_shift) { + case 3: + if ((value & 0x7) == 0) { + break; + } + implicit_shift = 2; + instruction = (instruction & ~(0x3UL << 30)) | (implicit_shift << 30); + // Fall through... + case 2: + if ((value & 0x3) == 0) { + break; + } + implicit_shift = 1; + instruction = (instruction & ~(0x3UL << 30)) | (implicit_shift << 30); + // Fall through... + case 1: + if ((value & 0x1) == 0) { + break; + } + implicit_shift = 0; + instruction = (instruction & ~(0x3UL << 30)) | (implicit_shift << 30); + // Fall through... case 0: if ((instruction & 0x04800000) == 0x04800000) { implicit_shift = 4; assert(((value & 0xF) == 0)); } break; - case 1: - assert(((value & 0x1) == 0)); - break; - case 2: - assert(((value & 0x3) == 0)); - break; - case 3: - assert(((value & 0x7) == 0)); - break; } } value >>= implicit_shift;