Program sections, or what are
When a program is compiled, the compiler splits the resulting code into different sections (sometimes called segments). Every section corresponds to a particular use, for instance storing variables or executable code.
This document is mainly focused on the ELF (Executable and Linkable Format)
file format used by Linux and the
gcc toolchain, but most of this document is valid for most executable file formats.
Here are some reason why there are separate sections:
- Code and data can be on separate buses (Harvard architecture).
- Code could be read-only and your system can have read-only memory (flash on microcontroller).
- Code can be shared between 2 processes but data can't.
Sections can also have permissions like read, write, execute.
||Executable (machine) code|
||Data initialized to zero|
Not so universal sections
||Global uninitialized data, WARNING : the linker can merge variable with same names!|