What does an object file contain? What does an object file contain? c c

What does an object file contain?


Object files can contain a bunch of stuff: Basically it's some or all of the list below:

  • Symbol Names
  • Compiled code
  • Constant data, eg. strings
  • Imports - which symbols the compiled code references (gets fixed up by linker)
  • Exports - which symbols the object file makes available to OTHER object files.

The linker turns a bunch of object files into an executable, by matching up all the imports and exports, and modifying the compiled code so the correct functions get called.


There are several standardized formats (COFF, ELF on Unix), basically they are variants of the same formats that those used for executables but missing some informations. These missing informations will be completed when linking.

Objects files formats basically contains the same informations:

  • binary code resulting of compilation (for a target processor)
  • static data used by that part of the program (like constant strings, etc). You can make a finer distinction between BSS (exported data) and Text (data that won't be modified by the program). But that is mostly important for compiler and linker. Note that like binary code, data are also dependant on target (big-endian, little-endian, 32bits, 64bits).
  • tables of symbols exported by this part of the program (mostly functions entry points)
  • tables of external symbols used by this part of the program

When objects will be linked together the parts of the code that refers to external symbols will be replaced by actual values (well, that is still oversimplified, there is a last part that will be done at loading time when running the program, but that's the idea).

The object file may also contain more symbols information that strictly necessary for resolving imports and export (useful for debug). That information can be removed using the strip command.


First read the wiki page. You can use objdump to examine such a file :)