Linkers, Loaders & Executables

What is the role of the dynamic linker (such as ld.so) when a dynamically linked program starts on Linux?

  1. ACompiling source code into machine code
  2. BFinding and loading the required shared libraries, binding symbols, then starting the program
  3. CDefragmenting free disk space after the program exits
Show answer and explanation

Answer: B. Finding and loading the required shared libraries, binding symbols, then starting the program

A dynamically linked executable names the dynamic linker it uses, and after loading the program the OS first hands control to that dynamic linker. The dynamic linker finds and loads the required shared libraries, applies relocations and binds symbols, then transfers control to the program's entry point. Loading extra libraries at run time with dlopen is also handled by the dynamic linker.

  • A. Compiling is the compiler's job.
  • B. Correct. It performs linking at run time.
  • C. It has nothing to do with disk maintenance.
Practice this topic Back to topic

More Linkers, Loaders & Executables questions

  1. What is the purpose of ASLR (address space layout randomization)?
  2. What is the main reason to build an executable as a PIE (position-independent executable)?
  3. What does the OS loader do when a program is started (for example by execve on Linux)?
  4. In a C program, which statement is correct about the address where the OS first starts execution (the entry point)?
  5. When a C main function ends with "return 3;", what generally happens to the value 3?