Everything You Never Wanted To Know About Linker Script logo

Everything You Never Wanted To Know About Linker Script

Free

In-depth guide to linker scripts for low-level software

FreeFree tier
Type
Open Source

About Everything You Never Wanted To Know About Linker Script

A comprehensive technical blog post that explains linker scripts in detail, covering the entire toolchain from source code to executable. Written by Sunny Young de la Sota (mcyoung), the post describes how linker scripts are used as templates for organizing code in low-level software such as firmware, kernels, and drivers. It covers the linker script language syntax, its use with GNU ld and LLVM lld, and provides historical context for naming conventions. The introduction requires no prior toolchain knowledge, making it accessible to newcomers while still being detailed enough for experienced developers. The post also touches on the C compilation model, object files, and the roles of the compiler, assembler, and linker.

Key Features

Explains linker script syntax and usage with GNU ld and LLVM lld
Covers the complete C compilation model: compiler, assembler, linker
Provides historical context for toolchain naming and conventions
Accessible to readers with no prior toolchain knowledge
Focuses on POSIX systems and executable linking
Includes practical examples and explanations of object file organization

Pros & Cons

Pros
  • Friendly and approachable introduction to a niche topic
  • Covers both GNU ld and LLVM lld for broad applicability
  • Includes historical context to explain seemingly arbitrary naming
  • No prior toolchain knowledge required; suitable for beginners
  • Thorough explanation of the entire linking process
Cons
  • Only covers POSIX linkers (not MSVC/link.exe)
  • Exclusively focuses on linking executables, not shared libraries
  • Single blog post may not cover every linker script edge case
  • Assumes reader is interested in low-level software development

Best For

Writing firmware for embedded systemsDeveloping operating system kernels and driversCreating custom executable layouts for low-level softwareLearning about linker internals and toolchain fundamentalsDebugging linking issues in C/C++/Rust projects

FAQ

What is a linker script?
A linker script is a template for the final executable that tells the linker how to organize code from input object files. It permits extremely precise control over the toolchain's output and is used primarily for firmware, kernels, and drivers.
Which linkers support the syntax described in this post?
The post covers syntax compatible with GNU ld (documented in excruciating detail in its manual) and notes that lld accepts basically the same syntax.
Is prior knowledge of toolchains required to understand this guide?
No prior knowledge of how toolchains work is necessary; the post states it is intended as a friendly introduction for newcomers.