@@ -554,6 +554,7 @@ patch_x86_64_32rx(unsigned char *location, uint64_t value)
554554
555555void patch_got_symbol (jit_state * state , int ordinal );
556556void patch_aarch64_trampoline (unsigned char * location , int ordinal , jit_state * state );
557+ void patch_aarch64_trampoline_addr (unsigned char * location , int ordinal , uint64_t value , jit_state * state );
557558void patch_x86_64_trampoline (unsigned char * location , int ordinal , jit_state * state );
558559
559560#include "jit_stencils.h"
@@ -585,28 +586,27 @@ patch_got_symbol(jit_state *state, int ordinal)
585586void
586587patch_aarch64_trampoline (unsigned char * location , int ordinal , jit_state * state )
587588{
588-
589589 uint64_t value = (uintptr_t )symbols_map [ordinal ];
590- int64_t range = value - (uintptr_t )location ;
590+ patch_aarch64_trampoline_addr (location , ordinal , value , state );
591+ }
592+
593+ // Generate and patch AArch64 trampolines for dynamic addresses (e.g. operands).
594+ // Unlike patch_aarch64_trampoline, the target address is passed directly rather
595+ // than looked up from symbols_map. The ordinal is used to allocate a trampoline slot.
596+ void
597+ patch_aarch64_trampoline_addr (unsigned char * location , int ordinal , uint64_t value , jit_state * state )
598+ {
599+ int64_t range = (int64_t )value - (int64_t )(uintptr_t )location ;
591600
592- // If we are in range of 28 signed bits, we patch the instruction with
593- // the address of the symbol.
594601 if (range >= - (1 << 27 ) && range < (1 << 27 )) {
595- patch_aarch64_26r (location , ( uintptr_t ) value );
602+ patch_aarch64_26r (location , value );
596603 return ;
597604 }
598605
599- // Out of range - need a trampoline
600606 uint32_t * p = (uint32_t * )get_symbol_slot (ordinal , & state -> trampolines , TRAMPOLINE_SIZE );
601607
602- /* Generate the trampoline
603- 0: 58000048 ldr x8, 8
604- 4: d61f0100 br x8
605- 8: 00000000 // The next two words contain the 64-bit address to jump to.
606- c: 00000000
607- */
608- p [0 ] = 0x58000048 ;
609- p [1 ] = 0xD61F0100 ;
608+ p [0 ] = 0x58000048 ; // ldr x8, 8
609+ p [1 ] = 0xD61F0100 ; // br x8
610610 p [2 ] = value & 0xffffffff ;
611611 p [3 ] = value >> 32 ;
612612
0 commit comments