My system : Ubuntu 22.04.3 running on x86_64 CPU.
I have this C program in a file named test.c :
int main(){
long int a = 10;
long int b = 20;
}
I've compiled the file with "gcc test.c -fno-stack-protector -mno-red-zone -o test" and then I executed "objdump -dw -M suffix test" ( I only show the _start function ) :
0000000000001040 <_start>:
1040: f3 0f 1e fa endbr64
1044: 31 ed xorl %ebp,%ebp
1046: 49 89 d1 movq %rdx,%r9
1049: 5e popq %rsi
104a: 48 89 e2 movq %rsp,%rdx
104d: 48 83 e4 f0 andq $0xfffffffffffffff0,%rsp
1051: 50 pushq %rax
1052: 54 pushq %rsp
1053: 45 31 c0 xorl %r8d,%r8d
1056: 31 c9 xorl %ecx,%ecx
1058: 48 8d 3d ca 00 00 00 leaq 0xca(%rip),%rdi # 1129 <main>
105f: ff 15 73 2f 00 00 callq *0x2f73(%rip) # 3fd8
<__libc_start_main@GLIBC_2.34>
1065: f4 hlt
1066: 66 2e 0f 1f 84 00 00 00 00 00 cs nopw 0x0(%rax,%rax,1)
My assumption is that we have the following call chain within which _start calls __libc_start_main which in turn calls main :
_start -> __libc_start_main -> main
My question :
Is the main function of my C program called by __libc_start_main in my specific Ubuntu system ?
mainfunction, anything before that is irrelevant.site:stackoverflow.com __libc_start_mainfinds multiple highly-relevant questions. Except that What is __libc_start_main and _start? is wrong, just a random guess at how things might work. (See my comments on pax's answer.)