Linkers, Loaders & Executables

What is the main role of a linker?

  1. ATo combine object files and libraries, bind names to addresses and produce an executable
  2. BTo find and report grammar errors in source code
  3. CTo automatically free a running program's memory when it is no longer used
Show answer and explanation

Answer: A. To combine object files and libraries, bind names to addresses and produce an executable

The linker matches each name (symbol) referenced in the object files with a definition somewhere (symbol resolution), lays out every file's code and data to decide final addresses, and rewrites placeholder addresses in instructions with the right values (relocation). It also pulls in functions from libraries as needed. The result is an executable that the OS can load and run.

  • A. Correct. It performs symbol resolution and relocation.
  • B. The compiler finds grammar errors.
  • C. That is a garbage collector's job.
Practice this topic Back to topic

More Linkers, Loaders & Executables questions

  1. Which describes the symbol resolution a linker performs?
  2. Which describes the relocation a linker performs?
  3. Linking a C program gives "undefined reference to `foo'". What is the most likely cause?
  4. Both a.c and b.c define a non-static global function void init(void) with the same name, and they are linked. What happens?
  5. In C, what is the effect of defining a function with static (e.g. static int helper(void))?