From b5bbacdc17815bbf1c6353322a7eb85cd3994399 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Fri, 5 Apr 2013 20:22:41 +0200 Subject: [PATCH] Fix jump-range constrained mcode allocation. --- src/lj_mcode.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lj_mcode.c b/src/lj_mcode.c index 5f7582c4..cb79e8cd 100644 --- a/src/lj_mcode.c +++ b/src/lj_mcode.c @@ -206,6 +206,7 @@ static void *mcode_alloc(jit_State *J, size_t sz) { /* Target an address in the static assembler code (64K aligned). ** Try addresses within a distance of target-range/2+1MB..target+range/2-1MB. + ** Use half the jump range so every address in the range can reach any other. */ #if LJ_TARGET_MIPS /* Use the middle of the 256MB-aligned region. */ @@ -214,7 +215,7 @@ static void *mcode_alloc(jit_State *J, size_t sz) #else uintptr_t target = (uintptr_t)(void *)lj_vm_exit_handler & ~(uintptr_t)0xffff; #endif - const uintptr_t range = (1u << LJ_TARGET_JUMPRANGE) - (1u << 21); + const uintptr_t range = (1u << (LJ_TARGET_JUMPRANGE-1)) - (1u << 21); /* First try a contiguous area below the last one. */ uintptr_t hint = J->mcarea ? (uintptr_t)J->mcarea - sz : 0; int i;