Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I'm a bit confused by how gcc encodes relative jumps. I have the following:
int main(void)
__asm__ __volatile__(
"jmp label\n"
"label:\n"
"nop\n"
return 0;
Building this (gcc -c -o test.o test.c) shows the following (objdump -M intel -d test.o):
0000000000000000 <main>:
0: 55 push rbp
1: 48 89 e5 mov rbp,rsp
4: eb 00 jmp 6 <label>
0000000000000006 <label>:
6: 90 nop
rasm2 -d eb00 shows jmp 2, which means the jump is being performed with an offset of 2. Now, I had understood that relative jumps' offsets are added to the current value of eip, which should be pointing at the next instruction (i.e. nop). This encoding makes me think that the offset is relative to the address of the jmp itself. Shouldn't the jmp be encoded as jmp 0, since nop is already at label?
–
–
–
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.