Master the fundamental concepts of linkers & loaders through this focused micro-challenge.
The compiler emits code with placeholder offsets for symbols not yet located. Relocation entries tell the linker: at offset X in section Y, add the runtime address of symbol Z using relocation type R.
For call foo when foo is in another object, the compiler emits a PC-relative displacement with addend 0. The linker sets displacement = addr(foo) - (addr(call site) + 4).
cLoading…
Production compilers embed this step inside a longer pipeline. GCC flows through cpp, cc1, assembly, and ld; Clang uses the driver, Sema, LLVM IR passes, and a target backend. LLVM bitcode, JVM bytecode, and WASM are other familiar IRs at the same layer. The exercise isolates one pass so you can test it alone before chaining it to the next stage.
You will implement relocation processing that patches object file bytes. This exercise asks you to apply relocation formulas to machine code and data sections given symbol final addresses.
Implement relocation processing for x86-64.
Requirements:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github