I am experimenting with disassembling binary files of clangsimple C programs (compiled with -O0), and I am confused by some of the command that is being generated.
Here are two empty mainfunctions with standard arguments, one of which does not return a value, and the other:
void main(int argc, char** argv)
{
}
int main(int argc, char** argv)
{
return 0;
}
Now, when I parse their assemblies, they look different, but there is one line that I do not understand:
return_void.bin:
(__TEXT,__text) section
_main:
0000000000000000 pushq %rbp
0000000000000001 movq %rsp, %rbp
0000000000000004 movl %edi, -0x4(%rbp)
0000000000000007 movq %rsi, -0x10(%rbp)
000000000000000b popq %rbp
000000000000000c retq
return_0.bin:
(__TEXT,__text) section
_main:
0000000100000f80 pushq %rbp
0000000100000f81 movq %rsp, %rbp
0000000100000f84 xorl %eax, %eax
0000000100000f86 movl $0x0, -0x4(%rbp)
0000000100000f8d movl %edi, -0x8(%rbp)
0000000100000f90 movq %rsi, -0x10(%rbp)
0000000100000f94 popq %rbp
0000000100000f95 retq
It is only generated when I use this function, it is not void, so I thought it might be a different way to return 0, but when I changed the returned constant, this line did not change at all:
// return_1.c
int main(int argc, char** argv)
{
return 1;
}
empty_return_1.bin:
(__TEXT,__text) section
_main:
0000000100000f80 pushq %rbp
0000000100000f81 movq %rsp, %rbp
0000000100000f84 movl $0x1, %eax
0000000100000f89 movl $0x0, -0x4(%rbp)
0000000100000f90 movl %edi, -0x8(%rbp)
0000000100000f93 movq %rsi, -0x10(%rbp)
0000000100000f97 popq %rbp
0000000100000f98 retq
Why is this line created and what is its purpose?