Master the fundamental concepts of linkers & loaders through this focused micro-challenge.
You have read the whole brief, and the concepts above stay free on every task. Writing and running the code needs a plan.
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
Every task includes starter code, theory, and hidden tests so you can implement and verify locally in the browser.
How it worksStatic linking merges all .o files and libraries into a single binary. LLD, GNU ld, and MSVC's link.exe assign final addresses, resolve symbols, apply relocations, and emit the executable. No runtime loader needed beyond the OS program loader.
Collect input objects. Lay out sections (VMA/LMA). Resolve symbols: each undefined gets a definition's address. Apply relocations. Emit ELF executable with entry point _start or main.
cLoading…
--gc-sections drops unreferenced codeProduction 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 a simple static linker that merges object files. This exercise requires resolving symbols, laying out sections, applying relocations, and writing a minimal executable image.
Write a small static linker: lay out the sections of several object files, resolve every symbol reference (reporting duplicates and undefined references like ld does), and compute each relocation's final value.
cLoading…
Lines up to the next object belong to the current object. Sizes and offsets are decimal.
.text sections of all objects, in input order, starting at 0x401000, each aligned to 16. .data sections, in input order, start at the first multiple of 0x1000 after the end of all text, each aligned to 8. A symbol's address is its section's start plus its offset.O: a local definition in O wins; otherwise the global definition.global beats weak; two weak → the first in input order; two global → error duplicate symbol 'S' in A and B (the first definition is kept).undefined reference to 'S' in O.P = address of the patched field: PC32 = S + A - P, ABS64 = S + A.cLoading…
Layout lists all .text entries first, then all .data entries; objects without a section are skipped. A missing main is itself an error: undefined reference to 'main' in <entry>.
Input:
cLoading…
Output:
cLoading…
Hidden tests cover weak/strong overrides, a duplicate strong symbol, an undefined reference, ABS64 into .data, and alignment padding between objects.