From 19569b848cc166120d91b74c5beb7403eee1f670 Mon Sep 17 00:00:00 2001 From: Taylor R Campbell Date: Sat, 19 Jan 2019 23:57:08 +0000 Subject: [PATCH] Fix scaling of PC offsets: they're byte offsets, not word offsets. --- src/microcode/cmpintmd/aarch64.c | 2 +- src/microcode/cmpintmd/aarch64.h | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/microcode/cmpintmd/aarch64.c b/src/microcode/cmpintmd/aarch64.c index 6bf4bfc88..db565c812 100644 --- a/src/microcode/cmpintmd/aarch64.c +++ b/src/microcode/cmpintmd/aarch64.c @@ -183,7 +183,7 @@ skip_compiled_closure_padding (insn_t * start) SCHEME_OBJECT compiled_closure_entry_to_target (insn_t * entry) { - return (MAKE_CC_ENTRY (entry + (((int64_t *) entry)[-1]))); + return (MAKE_CC_ENTRY (CC_ENTRY_ADDRESS_PC (entry))); } /* Execution caches (UUO links) diff --git a/src/microcode/cmpintmd/aarch64.h b/src/microcode/cmpintmd/aarch64.h index cae5abf0f..2e9c232af 100644 --- a/src/microcode/cmpintmd/aarch64.h +++ b/src/microcode/cmpintmd/aarch64.h @@ -182,16 +182,19 @@ struct cc_entry /* We don't put GC trap code before an entry any more. */ #define CC_ENTRY_GC_TRAP_SIZE 0 -/* A compiled entry address points to _after_ the PC offset that, when - added to the entry address, gives the address of instructions for - the CPU to execute. +/* A compiled entry address points to _after_ the PC byte offset that, + when added to the entry address, gives the address of instructions + for the CPU to execute. - XXX This is suboptimal because aarch64 does not have immediate - negative load offsets, but putting the offset after the label causes - other annoying issues. */ + PC offset is in units of bytes, not instruction words. Since it's 64 + bits, there's no advantage to using units of words. There's no + disadvantage either, except that we'd have to update all the code + that assumes byte offsets rather than word (or object) offsets to + scale them appropriately. */ #define CC_ENTRY_ADDRESS_PTR(e) (e) -#define CC_ENTRY_ADDRESS_PC(e) ((e) + (((const int64_t *) (e))[-1])) +#define CC_ENTRY_ADDRESS_PC(e) \ + ((insn_t *) (((char *) (e)) + (((const int64_t *) (e))[-1]))) /* A compiled return address points to a jump instruction that jumps to the continuation's body. */ -- 2.25.1