Compiling Object Files
Resourceful Code Reuse — by Dmitry Zinoviev (14 / 20)
👈 Chapter 2 Reuse Code at Link Time (C Only) | TOC | Building Static Libraries 👉
A compiler (say, a C compiler) translates a source file into an object file: a fragment of the future program that must be later linked with other object files (in all non-trivial cases) and with system and application-specific libraries (almost always). The name of an object file usually is the same as the source file’s name with the extension changed to o or obj.
An object file contains the executable code, the names of all global objects (variables and functions), and all unresolved external references (variables and functions, collectively known as symbols). It may also include debugging numbers), but debugging is outside this book’s scope.
As an example, here are the first 2560 bytes (the so-called hexadecimal dump) of jsontool.o obtained by compiling jsontool.c introduced here. The dump shows the offsets in the left column, the hexadecimal character codes in the middle eight columns, and the characters themselves, if printable, in the right column. Note the strings their_file.json, my_json.json, and Success! from the C file. The executable code is unrecognizable, and the symbols are elsewhere in the dump.
00000000: 7f45 4c46 0201 0100 0000 0000 0000 0000 .ELF............
00000010: 0100 3e00 0100 0000 0000 0000 0000 0000 ..>.............
00000020: 0000 0000 0000 0000 7006 0000 0000 0000…