Linkers, Loaders & Executables

What is the difference between "sections" and "segments" in an ELF file?

  1. ASection is the Windows term and segment the Linux term for the same thing
  2. BSections are fine-grained units handled by the linker; segments group sections with the same permissions as units the loader maps into memory
  3. CSegments exist only on disk and are never loaded into memory
Show answer and explanation

Answer: B. Sections are fine-grained units handled by the linker; segments group sections with the same permissions as units the loader maps into memory

ELF has two views. The linker combines and relocates in units of fine-grained sections such as .text, .rodata, .data and .bss. The loader maps memory in units of segments described by the program headers, grouping, for example, .text and .rodata into a read-execute segment and .data and .bss into a read-write segment. Grouping by permission makes page-level protection easy to set up.

  • A. Both are ELF terms with different roles.
  • B. Correct. One is the view for linking, the other for execution.
  • C. Segments are exactly what gets loaded into memory.
Practice this topic Back to topic

More Linkers, Loaders & Executables questions

  1. Which attack does W^X (never allowing a page to be both writable and executable) make harder?
  2. On Linux, when is the version number in a shared library's soname, such as the ".1" in libfoo.so.1, generally increased?
  3. What does running the ldd command on an executable on Linux show?
  4. Which pairs major operating systems with the executable formats they use correctly?
  5. When recursion goes so deep that it exceeds the stack limit, what generally happens on Linux and similar systems?