Linkers, Loaders & Executables

Which statement is correct about the object file (.o) a compiler produces from one source file?

  1. AIt is a finished program that the OS can run as is
  2. BIt is just compressed source code and contains no machine code
  3. CIt contains machine code, but the addresses of functions and variables in other files are not yet fixed
Show answer and explanation

Answer: C. It contains machine code, but the addresses of functions and variables in other files are not yet fixed

An object file holds the machine code translated from that file's functions, initial values of variables, a list of names it defines and references (the symbol table) and a list of places whose addresses must be filled in later (relocation entries). An instruction calling a function in another file, such as printf, keeps a placeholder because the address is unknown. The linker combines several object files, fixes the addresses and produces an executable.

  • A. It must be linked before it can run.
  • B. It contains machine code and accompanying information.
  • C. Correct. Addresses are fixed at link time.
Practice this topic Back to topic

More Linkers, Loaders & Executables questions

  1. What is the main role of a linker?
  2. Which describes the symbol resolution a linker performs?
  3. Which describes the relocation a linker performs?
  4. Linking a C program gives "undefined reference to `foo'". What is the most likely cause?
  5. 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?