Linkers, Loaders & Executables

When building a shared library, what is the advantage of exporting only the public functions and giving internal functions "hidden" symbol visibility?

  1. AInternal functions are encrypted and cannot be analyzed
  2. BThe dynamic linker has fewer symbols to process, loading is faster, and internal calls can skip the PLT
  3. CThe library becomes runnable on any OS
Show answer and explanation

Answer: B. The dynamic linker has fewer symbols to process, loading is faster, and internal calls can skip the PLT

A shared library's exported symbols might be overridden by a same-named definition in another module, so even internal calls must go through the PLT or GOT. Making them hidden removes them from outside view, reduces the symbols the dynamic linker must process and lets internal calls be direct PC-relative calls. It also avoids name collisions with other libraries and keeps the public ABI small.

  • A. Nothing is encrypted.
  • B. Correct. It also prevents name collisions.
  • C. It does not bridge different OSes.
Practice this topic Back to topic

More Linkers, Loaders & Executables questions

  1. How does C++ run the constructors of global objects before main?
  2. Which statement is correct about the object file (.o) a compiler produces from one source file?
  3. What is the main role of a linker?
  4. Which describes the symbol resolution a linker performs?
  5. Which describes the relocation a linker performs?