Saltar al contenido ForoHackers

Toolchains and linkers: start here

Toolchains y enlazadores
#883 · Ophuscado · · Denunciar

A toolchain is the chain of programs that turns source code into something a machine runs: preprocessor, compiler, assembler, linker and the tools that inspect and debug the result. The linker, which joins pieces and resolves names to addresses, is the least understood and the source of many baffling errors.

Key concepts

  • Stages: source becomes assembly, then object files, then a linked executable or library.
  • Symbols and relocation: object files list names they define and need; the linker matches them and fixes the addresses.
  • Static and dynamic linking: code is copied into the program, or found at load time in shared libraries.
  • Object formats and ABI: file formats such as ELF, and the calling conventions that let separately built code work together.
  • Cross toolchains: compiling on one machine for another architecture, with a matching library and headers.

Vocabulary

  • Object file: compiled code for one source file, not yet runnable.
  • Linker script: instructions placing sections of code and data at chosen addresses.
  • ABI: the binary agreement on layout and calling between compiled pieces.
  • Debug symbols: extra information that maps machine code back to source.

What to study, in order

  1. Compile a small C program in separate steps, saving and reading each intermediate output.
  2. Inspect an object file and an executable with the standard tools: symbols, sections, dependencies.
  3. Cause and fix an undefined-reference error and a duplicate-symbol error.
  4. Build a static library and a shared library, and compare how the program loads each.
  5. Write a minimal linker script and run a tiny program bare metal.

Related tags

#compilers #c #assembly #build-systems #embedded-linux

Inicia sesión o únete para responder.