Linkers, Loaders & Executables
Which statement is correct about the object file (.o) a compiler produces from one source file?
- AIt is a finished program that the OS can run as is
- BIt is just compressed source code and contains no machine code
- 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.