Linkers, Loaders & Executables
What is the difference between "sections" and "segments" in an ELF file?
- ASection is the Windows term and segment the Linux term for the same thing
- BSections are fine-grained units handled by the linker; segments group sections with the same permissions as units the loader maps into memory
- 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.