Zero distance jumps
I think there is a problem, if the target of a jump is located directly after the jump instruction.
To reproduce the problem, compile the attached file test.c and, use gdb to look at the disassembled code, like this:
shell> gdb test-native-test
(gdb) b run_test
Breakpoint 1 at 0x121e2: file test.c, line 6.
(gdb) r
Starting program: /scratch/lightening/tests/test-native-test
Breakpoint 1, run_test (j=0x555555571260, arena_base=0x7ffff7fce000 "",
arena_size=4096) at test.c:6
6 jit_begin(j, arena_base, arena_size);
(gdb) n
7 size_t align = jit_enter_jit_abi(j, 0, 0, 0);
(gdb)
8 jit_load_args_1(j, jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R0));
(gdb)
10 jit_reloc_t r = jit_jmp(j);
(gdb)
11 jit_patch_here(j, r);
(gdb)
12 jit_leave_jit_abi(j, 0, 0, align);
(gdb)
13 jit_reti(j, 1);
(gdb)
15 jit_word_t (*f)(jit_word_t) = jit_end(j, NULL);
(gdb)
17 }
(gdb) disas f,+25
Dump of assembler code from 0x7ffff7fce000 to 0x7ffff7fce019:
0x00007ffff7fce000: sub $0x8,%rsp
0x00007ffff7fce004: mov %rdi,%rax
0x00007ffff7fce007: jmp 0x7ffff7fce00c
0x00007ffff7fce009: add $0x8,%rsp
0x00007ffff7fce00d: mov $0x1,%eax
0x00007ffff7fce012: retq
0x00007ffff7fce013: add %al,(%rax)
0x00007ffff7fce015: add %al,(%rax)
0x00007ffff7fce017: add %al,(%rax)
End of assembler dump.
The jump goes to 0x7ffff7fce00c but it should be 0x00007ffff7fce009.