3.1 The structure of an ARM ELF image
名词
Extensible Linking Format(ELF)
3.1 The structure of an ARM ELF image
ARM ELF映像包含sections, regions, and segments,每个链接阶段都有不同的映像视图。
The structure of an image is defined by the:
Number of its constituent regions and output sections.
Positions in memory of these regions and sections when the image is loaded.
Positions in memory of these regions and sections when the image executes.
Each link stage has a different view of the image:
- ELF object file view (linker input)
The ELF object file view comprises包含 input sections. The ELF object file can be:
A relocatable(浮动的)file that holds code and data suitable for linking with other object files to create an executable or a shared object file.
A shared object file that holds code and data.
- Linker view
The linker has two views for the address space of a program that become distinct in the presence of overlaid(覆盖层的存在), position-independent, and relocatable program fragments (code or data):
The load address of a program fragment is the target address that the linker expects an external agent such as a program loader, dynamic linker, or debugger to copy the fragment from the ELF file. This might not be the address at which the fragment executes.
The execution address of a program fragment is the target address where the linker expects the fragment to reside(属于,归于) whenever it participates(参加) in the execution of the program.
If a fragment is position-independent or relocatable, its execution address can vary during execution.
- ELF image file view (linker output)
The ELF image file view comprises program segments and output sections:
A load region corresponds to a program segment.
An execution region contains one or more of the following output sections:
- RO section.
- RW section.
- XO section.
- ZI section.
One or more execution regions make up a load region.
Note
With armlink, the maximum size of a program segment is 2GB.
When describing a memory view:
The term root region means a region that has the same load and execution addresses.
Load regions are equivalent to ELF segments.
The following figure shows the relationship between the views at each link stage:
Figure 3-1 Relationship between sections, regions, and segments
3.2 Input sections, output sections, regions, and program segments
An object or image file is constructed from a hierarchy of input sections, output sections, regions, and program segments.
- Input section
An input section is an individual section from an input object file. It contains code, initialized data, or describes a fragment of memorythat is not initialized or that must be set to zero before the image can execute. These properties are represented by attributes such as RO, RW, XO, and ZI. These attributes are used by armlink to group input sections into bigger building blocks called output sections and regions.
- Output section
An output section is a group of input sections that have the same RO, RW, XO, or ZI attribute, and that are placed contiguously in memory by the linker. An output section has the same attributes as its constituent input sections. Within an output section, the input sections are sorted according to the section placement rules.
- Region
A region contains up to four output sections depending on the contents and the number of sections with different attributes. By default, the output sections in a region are sorted according to their attributes. Any XO output section is first, followed by the RO output section, then the RW output section, and finally the ZI output section. A region typically maps onto a physical memory device, such as ROM, RAM, or peripheral. You can change the order of output sections using scatter-loading.
- Program segment
A program segment corresponds to a load region and contains execution regions. Program segments hold information such as text and data.
3.3 Load view and execution view of an image
Image regions are placed in the system memory map at load time. The location of the regions in memory might change during execution.
Before you can execute the image, you might have to move some of its regions to their execution addresses and create the ZI output sections. For example, initialized RW data might have to be copied from its load address in ROM to its execution address in RAM.
The memory map of an image has the following distinct views:
- Load view
Describes each image region and section in terms of the address where it is located when the image is loaded into memory, that is, the location before image execution starts.
- Execution view
Describes each image region and section in terms of the address where it is located during image execution.
The following figure shows these views for an image without an execute-only (XO) section:
Figure 3-2 Load and execution memory maps for an image without an XO section
The following figure shows load and execution views for an image with an XO section:
Figure 3-3 Load and execution memory maps for an image with an XO section
The following table compares the load and execution views:
Table 3-1 Comparing load and execution views
Load | Description | Execution | Description |
---|---|---|---|
Load address | The address where a section or region is loaded into memory before the image containing it starts executing. The load address of a section or a non-root region can differ from its execution address | Execution address | The address where a section or region is located while the image containing it is being executed |
Load region | A load region describes the layout of a contiguous chunk of memory in load address space. | Execution region | An execution region describes the layout of a contiguous chunk of memory in execution address space. |