Linkers, Loaders & Executables

When dynamic linking uses lazy binding through the PLT (procedure linkage table), which statement is correct?

  1. AA shared-library function's address is resolved the first time it is called, and later calls jump straight to the resolved address
  2. BAll function addresses are always resolved before the program starts
  3. CThe library file is reread from disk on every call
Show answer and explanation

Answer: A. A shared-library function's address is resolved the first time it is called, and later calls jump straight to the resolved address

The program calls external functions through small PLT stubs. With lazy binding, the first call makes the stub jump to the dynamic linker's resolver, which finds the real address and writes it into the GOT. Later calls jump directly to the address in the GOT. Skipping resolution of unused functions speeds up start-up. For security, though, resolving everything at start-up and making the GOT read-only is also widely used.

  • A. Correct. Functions never called are never resolved.
  • B. That is immediate binding at start-up.
  • C. The file is not reread from disk.
Practice this topic Back to topic

More Linkers, Loaders & Executables questions

  1. What is the role of the dynamic linker (such as ld.so) when a dynamically linked program starts on Linux?
  2. What is the purpose of ASLR (address space layout randomization)?
  3. What is the main reason to build an executable as a PIE (position-independent executable)?
  4. What does the OS loader do when a program is started (for example by execve on Linux)?
  5. In a C program, which statement is correct about the address where the OS first starts execution (the entry point)?