Master the fundamental concepts of linkers & loaders through this focused micro-challenge.
Each .o file exports defined symbols and imports undefined ones. The linker's job is to match undefined call foo relocations with global foo definitions. nm, objdump -t, and LLD's verbose mode show the same tables.
Name, value (address), size, type (FUNC, OBJECT), binding (LOCAL, GLOBAL, WEAK), and section index. Undefined symbols have section index 0 and value 0 until resolved.
cLoading…
T/t: text (code), defined/localU: undefined, needs linker resolutionProduction 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 parse and display symbol tables from object files. This exercise requires reading symbol entries and reporting name, address, type, and binding for each symbol.
Read an ELF object's symbol table (the list of functions, variables and external references a linker resolves) and present it the way readelf -s does, plus a summary grouped by kind.
The raw bytes of one ELF64 or ELF32 little-endian file as hexadecimal pairs separated by whitespace (the format of Parse and Understand Object File Formats (ELF); the header and section-header fields are decoded the same way).
sh_type is 2 (SYMTAB).sh_link (offset 40 in ELF64 / 24 in ELF32) is the index of the string table holding symbol names; its sh_entsize (56 / 36) is the size of one entry; sh_size / sh_entsize is the number of entries.| Field | ELF64 offset, size | ELF32 offset, size |
|---|---|---|
st_name | 0, 4 | 0, 4 |
st_info | 4, 1 | 12, 1 |
st_shndx | 6, 2 | 14, 2 |
st_value | 8, 8 | 4, 4 |
st_size | 16, 8 | 8, 4 |
st_info holds the type in its low 4 bits (0 NOTYPE, 1 OBJECT, 2 FUNC, 3 SECTION, 4 FILE, 5 COMMON, 6 TLS) and the binding in its high 4 bits (0 LOCAL, 1 GLOBAL, 2 WEAK).
cLoading…
NDX is UND for 0, ABS for 0xfff1, COM for 0xfff2, otherwise the name of section st_shndx. An empty NAME prints as -.none if empty): functions = FUNC symbols that are defined (st_shndx ≠ 0); objects = defined OBJECT symbols; undefined = named symbols with st_shndx 0; weak = WEAK-bound symbols.locals/globals count entries 1..N-1 by binding (WEAK counts as global).Input:
cLoading…
Output:
cLoading…
Hidden tests include an AArch64 object with a SECTION symbol and weak undefined references, and an object with a COMMON symbol, a TLS symbol and a defined weak function.
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 works