Simplified Compiler Linker Class Development

Job ID: 39322878

Budget: €10 – €20 EUR

The task is to develop a class that implements a simplified linker.

Linker is a component of a compiler. Linker is given object file(s) in its input, these are used to assemble the final executable. Each object file contains machine code compiled from a single module (usually, from a single source). The machine code is not ready to use, there may be missing references to functions from other modules. Next, object files include tables of so called exports and imports. The linker reads the object files, it connects the imports with the exports, it check the correctness (all imports covered by an export, no duplicate exports), it fills in the computed addresses, and it writes the finished machine code back to disk. The required class implements a simplification of the above tasks.

The core of an object file is the compiled machine code. It contains the processor instructions (we consider only functions in this task). The bytes that form the machine instructions are saved in one continuous block. However, some instructions may miss the addresses - the bytes that form the address contain invalid values, often zeros. The linker overwrites these bytes with valid addresses, which are created when the functions are serialized into the resulting file. The machine code in this task is just a random sequence of bytes of some length (definitely, these are not valid instructions of any existing processor).

The linker needs to know the names of the functions that are included in the object file. The table of exports is used for this purpose. In the task, the table has a simplified structure - it contains only the name of the function (symbol) and its position in the translated code (offset, counted in bytes from the beginning of the machine code block). An object file can contain multiple functions, the functions do not overlap in the machine code block. Therefore, it is easy to identify the beginning and end of a function in the translated code; a function ends where the next function begins. Note that the order of functions in the export table may not match the order of functions in the machine code block (see the figure).