Linkers, Loaders & Executables

What is an advantage of dynamic linking (shared libraries)?

  1. AIt always runs even if the library is missing from the system
  2. BSeveral programs can share one library in memory, and updating the library applies fixes without rebuilding
  3. CNo start-up work is needed, so it always starts faster than static linking
Show answer and explanation

Answer: B. Several programs can share one library in memory, and updating the library applies fixes without rebuilding

With dynamic linking, the executable records only which functions of which shared libraries it uses, and at run time the dynamic linker loads the libraries and binds them. Shared library code is never modified, so one copy in physical memory can be shared by many processes. Fixing a bug or vulnerability just means replacing the library. Binding does, however, add work at start-up.

  • A. It cannot start if the library is not found.
  • B. Correct. It also saves memory and disk space.
  • C. Binding work is needed at start-up.
Practice this topic Back to topic

More Linkers, Loaders & Executables questions

  1. A dynamically linked program copied to another computer fails to start. What is the most likely cause?
  2. When linking with a static library (.a file), what does the linker put into the executable?
  3. With the GNU linker, writing a static library before the object file that uses it, as in "gcc -lmylib main.o", can cause undefined-reference errors. Why?
  4. Which describes position-independent code (PIC)?
  5. What is the role of the GOT (global offset table) used in shared libraries?