I have the following piece of C code:
#include <stdio.h>
int main()
{
int i;
for(i=0; i<10; i++)
puts("hello, friend");
return 0;
}
which I compiled this way: gcc firstprog.c -o firstprog
Then, when using gdb
to disassemble it, I see:
(gdb) disassemble
Dump of assembler code for function main:
=> 0x0000555555555149 <+0>: endbr64
0x000055555555514d <+4>: push rbp
0x000055555555514e <+5>: mov rbp,rsp
0x0000555555555151 <+8>: sub rsp,0x10
0x0000555555555155 <+12>: mov DWORD PTR [rbp-0x4],0x0
0x000055555555515c <+19>: jmp 0x55555555516e <main+37>
0x000055555555515e <+21>: lea rdi,[rip+0xe9f] # 0x555555556004
0x0000555555555165 <+28>: call 0x555555555050 <puts@plt>
0x000055555555516a <+33>: add DWORD PTR [rbp-0x4],0x1
0x000055555555516e <+37>: cmp DWORD PTR [rbp-0x4],0x9
0x0000555555555172 <+41>: jle 0x55555555515e <main+21>
0x0000555555555174 <+43>: mov eax,0x0
0x0000555555555179 <+48>: leave
0x000055555555517a <+49>: ret
End of assembler dump.
So my question is: what is rip+0xe9f
referring to at <main+21> ?
If I use objdump
on the same file, I've got the following output:
$ objdump -M intel -D firstprog | grep -A16 main.:
0000000000001149 <main>:
1149: f3 0f 1e fa endbr64
114d: 55 push rbp
114e: 48 89 e5 mov rbp,rsp
1151: 48 83 ec 10 sub rsp,0x10
1155: c7 45 fc 00 00 00 00 mov DWORD PTR [rbp-0x4],0x0
115c: eb 10 jmp 116e <main+0x25>
115e: 48 8d 3d 9f 0e 00 00 lea rdi,[rip+0xe9f] # 2004 <_IO_stdin_used+0x4>
1165: e8 e6 fe ff ff call 1050 <puts@plt>
116a: 83 45 fc 01 add DWORD PTR [rbp-0x4],0x1
116e: 83 7d fc 09 cmp DWORD PTR [rbp-0x4],0x9
1172: 7e ea jle 115e <main+0x15>
1174: b8 00 00 00 00 mov eax,0x0
1179: c9 leave
117a: c3 ret
117b: 0f 1f 44 00 00 nop DWORD PTR [rax+rax*1+0x0]
It seems that it's related to file descriptors, but as puts
write to stdout, I was not expecting to see IO_stdin.