Linkers, Loaders & Executables
What does the OS loader do when a program is started (for example by execve on Linux)?
- AIt reads the source code and compiles it on the spot before running it
- BIt maps each part into memory according to the program headers, sets up arguments and more on the stack, and starts execution at the entry address
- CIt prints every symbol name in the executable before running it
Show answer and explanation
Answer: B. It maps each part into memory according to the program headers, sets up arguments and more on the stack, and starts execution at the entry address
The loader reads the executable's headers and maps each part (segment) described by the program headers into the virtual address space with read, write and execute permissions. It prepares zero-filled memory for BSS and the stack, and pushes the command-line arguments and environment variables onto the stack. It then starts the dynamic linker if the program is dynamically linked, or otherwise begins at the executable's entry address.
- A. The executable is already machine code.
- B. Correct. Preparing memory and starting execution is the loader's job.
- C. It does not print symbol names.