Hasty Briefsbeta

Bilingual

Understanding the Go Compiler: The Linker

3 months ago
  • #linker
  • #executable
  • #compiler
  • The linker combines separate object files into a single executable.
  • Symbol resolution connects cross-file references like function calls.
  • Relocation patches placeholder addresses in machine code with actual addresses.
  • Dead code elimination removes unused functions to keep binaries small.
  • Layout and executable generation organizes code and data into sections and segments.
  • Sections include .text (code), .rodata (read-only data), .data (initialized globals), and .bss (zero-initialized globals).
  • Segments group sections for memory mapping with appropriate permissions (W^X).
  • Go prefers static linking but supports dynamic linking with cgo.
  • Different build modes produce executables, static libraries, shared libraries, or plugins.
  • The entry point is runtime startup code, not main.main.