Quiz Entry - updated: 2026.07.10
What is the entry point of a C program and what happens before main()?
The real entry point is _start; it and the C runtime (__libc_start_main, the init constructors) run first, then call your main.
* Your main sits in the middle of a runtime sandwich: _start and the CRT set things up and run constructors before it, and run destructors and _exit after. *
The C runtime (CRT) executes before your code:
_start (entry point)
↓
__libc_start_main()
↓
__libc_csu_init()
↓
Calls constructors
↓
main(argc, argv, envp) ← Your code starts here
↓
exit() or return
↓
__libc_csu_fini()
↓
Calls destructors
↓
_exit()
What _start does:
- Sets up the stack pointer
- Clears frame pointer (for stack traces)
- Calls
__libc_start_main(main, argc, argv, ...)
View entry point:
$ readelf -h program | grep Entry
Entry point address: 0x1040
$ objdump -d program | grep -A5 "<_start>"
0000000000001040 <_start>:
1040: xor %ebp,%ebp
1042: mov %rdx,%r9
...
Tip: You can change the entry point with gcc -e my_entry or ld --entry=my_entry, but you lose CRT initialization.
Go deeper:
crt0 (Wikipedia) — the startup object that sets up the environment and calls
main.LWN — How programs get run: ELF binaries — the kernel-to-
_starthandoff that precedes all of this.