JMP to absolute address (op codes)
opcode for absolute indirect jump is FF + 4byte address. This is most often used for jumptables of addresses stored in data.
Absolute addresses do require relocation when not loaded to the expected address, so relative addresses are generally preferred. Code for relative jumps is also 2 bytes smaller.
Intel optimization manual states that the cpu expects call and ret to be used in pairs, so the ret without a call suggested in answer 2 would cause what they call a "performance penalty".
Also, if the code was not loaded to the same address that the compiler assumed, the ret would probably crash the program. It would be safer to calculate a relative address.
I think that E9
is an opcode for a relative jump: its operand specifies a relative distance to be jumped, plus or minus from the start of the next instruction.
If you want the operand to specify an absolute address, you would need a different opcode.
you could use:
push DESTINATION_VA
ret
or
mov eax,DESTINATION_VA
jmp eax
relative E9 jmp encoding is used like this:
CURRENT_RVA: jmp (DESTINATION_RVA - CURRENT_RVA - 5 [sizeof(E9 xx xx xx xx)])
push + ret is the best solution if you have VA address and the image is not relocated