Here is a sample code of hello world program:
#include <stdio.h>
int main(void)
{
printf("Hello, world!\n");
return 0;
}
This is a disassembly of object file I've got:
File Type: COFF OBJECT
main:
0000000000000000: 48 83 EC 28 sub rsp,28h
0000000000000016: C3 ret
__local_stdio_printf_options:
0000000000000000: 48 8D 05 00 00 00 lea rax,[?_OptionsStorage@?1??__local_stdio_printf_options@@9@9]
00
0000000000000007: C3 ret
_vfprintf_l:
0000000000000000: 4C 89 4C 24 20 mov qword ptr [rsp+20h],r9
0000000000000014: 48 83 EC 38 sub rsp,38h
0000000000000018: E8 00 00 00 00 call __local_stdio_printf_options
0000000000000039: E8 00 00 00 00 call __stdio_common_vfprintf
000000000000003E: 48 83 C4 38 add rsp,38h
0000000000000042: C3 ret
printf:
0000000000000000: 48 89 4C 24 08 mov qword ptr [rsp+8],rcx
0000000000000027: E8 00 00 00 00 call __acrt_iob_func
000000000000002C: 4C 8B 4C 24 28 mov r9,qword ptr [rsp+28h]
000000000000003C: E8 00 00 00 00 call _vfprintf_l
0000000000000041: 89 44 24 20 mov dword ptr [rsp+20h],eax
000000000000004E: 8B 44 24 20 mov eax,dword ptr [rsp+20h]
0000000000000056: C3 ret
In the printf
function, we have two more function calls: __acrt_iob_func
and _vfprintf_l
.
What exactly does the first function do?
How do we have the
_vprintf_l
function in the object file?
A detailed explanation would be appreciated.
Compiled with: cl /TC main.cpp
Disassembled with: dumpbin /disasm main.obj
PS: I removed assembly code partly so that I can post the question.