Linkers, Loaders & Executables

What does the OS loader do when a program is started (for example by execve on Linux)?

  1. AIt reads the source code and compiles it on the spot before running it
  2. 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
  3. 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.
Practice this topic Back to topic

More Linkers, Loaders & Executables questions

  1. In a C program, which statement is correct about the address where the OS first starts execution (the entry point)?
  2. When a C main function ends with "return 3;", what generally happens to the value 3?
  3. What happens when the strip command is applied to an executable?
  4. How does a linker treat a weak symbol?
  5. What is the main purpose of name mangling, in which a C++ compiler encodes argument types and other information into symbol names?