Join our Newsletter — 33% off our NHI Course

What is the difference between ELF sections and ELF segments?

Sections are the logical building blocks used during linking, such as .text, .data, and symbol tables. Segments are the runtime view used by the loader, combining related sections into loadable memory regions. In practice, sections describe what is in the file, while segments describe how the operating system loads it.

ELF sections: the linker’s view of the file

ELF sections are the logical units that matter most during compilation and linking. They group related content such as executable code, initialized data, uninitialized data, relocation records, symbol tables, and debugging information. A section can exist for build-time purposes even if it is not meant to be loaded into memory at runtime.

That distinction is why section names often look familiar to developers, while the rest of the toolchain treats them as packaging and bookkeeping structures. The linker uses them to combine object files, resolve references, place code and data, and emit a final executable or shared object.

ELF segments: the loader’s view of memory

ELF segments are the runtime units consumed by the operating system loader. They describe how parts of the file are mapped into process memory, including permissions, alignment, and which sections belong together in a loadable region. A single segment may contain multiple sections if they share the same loading and protection requirements.

Segments are therefore about execution, not symbol resolution. The loader cares about what must be mapped as readable, writable, or executable, and in what layout, while ignoring many of the file’s link-time conveniences that sections provide.

How sections and segments relate in practice

The simplest way to think about the difference is that sections answer “what is in the file?” and segments answer “what should the OS load?” Sections are more granular and numerous; segments are fewer and more operational. The same section can contribute to a segment, but the mapping is not one-to-one.

This is also why tools show different views: readelf -S exposes sections, while readelf -l exposes program headers and segments. When diagnosing binaries, the relevant view depends on the question: linker layout issues usually point to sections, while runtime mapping or memory-permission issues usually point to segments.

Practitioner Guidance

What to verify: If you are inspecting a binary, confirm whether the issue is build-time placement or runtime loading before choosing the tool. A section problem can be invisible in the segment view, and a segment permission problem can look fine if you only inspect sections.

Common mistake: Treating sections and segments as interchangeable leads to bad diagnosis, especially when debugging stripped binaries, linker scripts, or memory-protection failures. Always ask whether you are reasoning about the file format or the loaded process image.

Practitioner takeaway: Sections describe structure for linking; segments describe mapping for execution. If you keep that split clear, most ELF layout questions become straightforward to troubleshoot.