Linkers, Loaders & Executables

Which describes the relocation a linker performs?

  1. AAfter final addresses of code and data are decided, rewriting the addresses inside instructions and data with the correct values
  2. BMoving a running program to another computer and continuing there
  3. CEvicting pages to storage when memory runs short
Show answer and explanation

Answer: A. After final addresses of code and data are decided, rewriting the addresses inside instructions and data with the correct values

The compiler builds each file as if it started at address 0 and records, as relocation entries, every place that uses the address of another file's function or of its own variables. After laying out all files and deciding real addresses, the linker computes the correct address (or PC-relative distance) for each recorded place and writes it into the instruction. With dynamic linking, part of this patching is done at run time by the dynamic linker.

  • A. Correct. It patches the places listed in relocation entries.
  • B. That is process migration.
  • C. That is the OS paging out memory.
Practice this topic Back to topic

More Linkers, Loaders & Executables questions

  1. Linking a C program gives "undefined reference to `foo'". What is the most likely cause?
  2. 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?
  3. In C, what is the effect of defining a function with static (e.g. static int helper(void))?
  4. In C, what does writing "extern int count;" mean?
  5. Which statement is correct about files in the ELF format commonly used on Linux and similar systems?