Reputation: 1341
I am confused at to whether there is a difference between "segment" and "section" when referring to object files/executables.
According to https://en.wikipedia.org/wiki/Object_file:
Most object file formats are structured as separate sections of data, each section containing a certain type of data.
However, the article later goes on to talking about segments (e.g. code segment, data segment, etc).
Additionally, the PE file format (.exe/.dll/.coff in Windows) refers to these different parts as sections (https://msdn.microsoft.com/en-us/library/windows/desktop/ms680547(v=vs.85).aspx).
So my question: Is there a difference between the two or are they practically synonyms?
Upvotes: 6
Views: 1443
Reputation: 1518
The terminology may depend on the specific object file format, but typically a section is a more fine-grained "chunk" of code or data than a segment, in the sense that a segment might consist of multiple sections.
For example, the PE/COFF standard document does not have a concept of segments -- only sections, whereas the ELF object format has both. In the case of ELF, segments in the object file are analogous to what is known as segments in context of a CPU or instruction set architecture, such as x86 -- that is, a segment is some contiguous partition of memory with a specific set of memory access rights (or similar) associated with it. The typical examples are executable "code segments" vs non-executable "data segments".
Sections, on the other hand, have more to do with how code or data are logically organized in an object file. For example, a table of exported symbols might be stored in a section separate from the data that is accessed by the application during its exection, although both are considered data.
If an object file format has a concept of both segments and sections, each section is typically fully contained within a single segment (at least that is the case with ELF).
Upvotes: 4