I wrote this Hello World in C :
#include<stdio.h>
int main() {
printf("Hello world !\n");
return 0;
}
Compiling with gcc to assembly code I get this :
.file "file.c"
.section .rodata.str1.1,"aMS",@progbits,1
.LC0:
.string "Hello world !"
.section .text.unlikely,"ax",@progbits
.LCOLDB1:
.section .text.startup,"ax",@progbits
.LHOTB1:
.p2align 4,,15
.globl main
.type main, @function
main:
.LFB11:
.cfi_startproc
subq $8, %rsp
.cfi_def_cfa_offset 16
movl $.LC0, %edi
call puts
xorl %eax, %eax
addq $8, %rsp
.cfi_def_cfa_offset 8
ret
.cfi_endproc
.LFE11:
.size main, .-main
.section .text.unlikely
.LCOLDE1:
.section .text.startup
.LHOTE1:
.ident "GCC: (GNU) 4.9.2 20150304 (prerelease)"
.section .note.GNU-stack,"",@progbits
No problem here. But now, I want to compare the assembly code with a code disassembled by objdump :
For the main function I get this :
0000000000000000 <main>:
0: 48 83 ec 08 sub $0x8,%rsp
4: bf 00 00 00 00 mov $0x0,%edi
5: R_X86_64_32 .rodata.str1.1
9: e8 00 00 00 00 callq e <main+0xe>
a: R_X86_64_PC32 puts-0x4
e: 31 c0 xor %eax,%eax
10: 48 83 c4 08 add $0x8,%rsp
14: c3 retq
I don't understand two things :
Why move the number 0 on edi
means to load the string "Hello world" ?
Moreover, the instruction callq
call the address e
. But the instruction at the addresse e
is not the function puts
but a xor
. So what is the real address ?