Skip to content

Commit a524a67

Browse files
committed
Use indirect jmp instead of trashing %rax
1 parent 5a98545 commit a524a67

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

flexdll.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,12 @@ static void relocate(resolver f, void *data, reloctbl *tbl, void **jmptbl) {
256256
return;
257257
}
258258
void* trampoline = sym->trampoline = *jmptbl;
259-
/* movq $(sym->addr), %rax */
260-
*((short*)trampoline) = 0xb848;
261-
*((UINT_PTR*)((char*)trampoline + 2)) = (UINT_PTR)sym->addr;
262-
/* jmp %rax */
263-
*((short*)((char*)trampoline + 10)) = 0xe0ff;
259+
/* rex.W jmpq $0x0(%rip) */
260+
*((__int64*)trampoline) = 0x25ff48;
261+
/* Place the actual symbol immediately after the instruction */
262+
*((UINT_PTR*)((char*)trampoline + 7)) = (UINT_PTR)sym->addr;
263+
/* Pad with nop */
264+
*(((char*)trampoline + 15)) = 0x90;
264265
*((char*)jmptbl) += 16;
265266
}
266267
s = (UINT_PTR)(sym->trampoline);

0 commit comments

Comments
 (0)