Linkers, Loaders & Executables
What is the role of the dynamic linker (such as ld.so) when a dynamically linked program starts on Linux?
- ACompiling source code into machine code
- BFinding and loading the required shared libraries, binding symbols, then starting the program
- 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.