Linkers, Loaders & Executables
In a C program, which statement is correct about the address where the OS first starts execution (the entry point)?
- AIt is always the start of main
- BIt is always the first byte of the executable
- CIt is usually not main but start-up code such as _start, which initializes things and then calls main
Show answer and explanation
Answer: C. It is usually not main but start-up code such as _start, which initializes things and then calls main
The linker adds start-up objects supplied by the C runtime (such as crt1.o) to the program and makes the _start inside them the entry point. _start takes the command-line arguments from the stack, initializes the standard library and global objects, and then calls main. When main returns, its return value is passed to exit, which performs the shutdown steps.
- A. Preparation code runs before main.
- B. The entry address is recorded in the ELF header.
- C. Correct. It is start-up code supplied by the C runtime.