@@ -428,8 +428,9 @@ void patch_x86_64_trampoline(unsigned char *location, int ordinal, jit_state *st
428428    #define  TRAMPOLINE_SIZE  16
429429    #define  DATA_ALIGN  8
430430#elif  defined(__x86_64__ ) &&  defined(__APPLE__ )
431-     // x86_64 trampolines: jmp *(%rip); .quad address (6 bytes + 8 bytes = 14 bytes) 
432-     #define  TRAMPOLINE_SIZE  16  // Round up to 16 for alignment
431+     // LLVM 20 on macOS x86_64 debug builds: GOT entries may exceed ±2GB PC-relative 
432+     // range. Trampolines provide indirect jumps using 64-bit absolute addresses. 
433+     #define  TRAMPOLINE_SIZE  16  // 14 bytes + 2 bytes padding for alignment
433434    #define  DATA_ALIGN  16
434435#else 
435436    #define  TRAMPOLINE_SIZE  0
@@ -489,7 +490,7 @@ patch_x86_64_trampoline(unsigned char *location, int ordinal, jit_state *state)
489490    uint64_t  value  =  (uintptr_t )symbols_map [ordinal ];
490491    int64_t  range  =  (int64_t )value  -  4  -  (int64_t )location ;
491492
492-     // If we are in range of 32 signed bits, patch directly 
493+     // If we are in range of 32 signed bits, we can  patch directly 
493494    if  (range  >= - (1LL  << 31 ) &&  range  <  (1LL  << 31 )) {
494495        patch_32r (location , value  -  4 );
495496        return ;
@@ -510,12 +511,13 @@ patch_x86_64_trampoline(unsigned char *location, int ordinal, jit_state *state)
510511    assert ((size_t )(index  +  1 ) *  TRAMPOLINE_SIZE  <= state -> trampolines .size );
511512
512513    /* Generate the trampoline (14 bytes, padded to 16): 
513-        0: ff 25 00 00 00 00    jmp *(%rip)  # Jump to address at offset 6 
514-        6: XX XX XX XX XX XX XX XX   .quad value (64-bit address) 
514+        0: ff 25 00 00 00 00    jmp *(%rip) 
515+        6: XX XX XX XX XX XX XX XX   (64-bit target address) 
516+ 
517+        Reference: https://wiki.osdev.org/X86-64_Instruction_Encoding#FF (JMP r/m64) 
515518    */ 
516-     trampoline [0 ] =  0xFF ;  // jmp opcode 
517-     trampoline [1 ] =  0x25 ;  // ModRM byte for jmp *disp32(%rip) 
518-     // Offset 0: the address is right after this instruction (at offset 6) 
519+     trampoline [0 ] =  0xFF ;
520+     trampoline [1 ] =  0x25 ;
519521    * (uint32_t  * )(trampoline  +  2 ) =  0 ;
520522    * (uint64_t  * )(trampoline  +  6 ) =  value ;
521523
0 commit comments