1. SPARC Assembler for SunOS 5.x
3. Executable and Linking Format
3.2.2 Predefined User Sections
3.2.2.1 Creating an .init Section in an Object File
3.8.1 Section Control Directives
3.8.2 Symbol Attribute Directives
3.8.4 Data Generating Directives
4. Converting Files to the New Format
B. Examples of Pseudo-Operations
C. Using the Assembler Command Line
A section is the smallest unit of an object that can be relocated. The following sections are commonly present in an ELF file:
Section header
Executable text
Read-only data
Read-write data
Read-write uninitialized data (section header only)
Sections do not need to be specified in any particular order. The current section is the section to which code is generated.
These sections contain all other information in an object file and satisfy several conditions.
Every section must have one section header describing the section. However, a section header does not need to be followed by a section.
Each section occupies one contiguous sequence of bytes within a file. The section may be empty (that is, of zero-length).
A byte in a file can reside in only one section. Sections in a file cannot overlap.
An object file may have inactive space. The contents of the data in the inactive space are unspecified.
Sections can be added for multiple text or data segments, shared data, user-defined sections, or information in the object file for debugging.
Note - Not all of the sections need to be present.
The section header allows you to locate all of the file sections. An entry in a section header table contains information characterizing the data in a section.
The section header contains the following information:
addr
Address at which the first byte resides if the section appears in the memory image of a process; the default value is 0.
addralign
Aligns the address if a section has an address alignment constraint; for example, if a section contains a double-word, the entire section must be ensured double-word alignment. Only 0 and positive integral powers of 2 are currently allowed. A value of 0 or 1 indicates no address alignment constraints.
entsize
Size in bytes for entries in fixed-size tables such as the symbol table.
flags
One-bit descriptions of section attributes. Table 3-2 describes the section attribute flags.
Table 3-2
|
info
Extra information. The interpretation of this information depends on the section type, as described in Table 3-3.
link
Section header table index link. The interpretation of this information depends on the section type, as described in Table 3-3.
name
Specifies the section name. An index into the section header string table section specifies the location of a null-terminated string.
offset
Specifies the byte offset from the beginning of the file to the first byte in the section.
Note - If the section type is SHT_NOBITS, offset specifies the conceptual placement of the file.
size
Specifies the size of the section in bytes.
Note - If the section type is SHT_NOBITS, size may be non-zero; however, the section still occupies no space in the file.
type
Categorizes the section contents and semantics. Table 3-3 describes the section types.
Table 3-3
|
Note - Some section header table indexes are reserved and the object file will not contain sections for these special indexes.
A section that can be manipulated by the section control directives is known as a user section. You can use the section control directives to change the user section in which code or data is generated. Table 3-4 lists the predefined user sections that can be named in the section control directives.
Table 3-4
|
The .init sections contain codes that are to be executed before the the main program is executed. To create an .init section in an object file, use the assembler pseudo-ops shown in Example 3-1.
Example 3-1 Creating an .init Section
.section ".init" .align 4 <instructions>
At link time, the .init sections in a sequence of .o files are concatenated into an .init section in the linker output file. The code in the .init section are executed before the main program is executed.
Because the whole .init section is treated as a single function body, it is recommended that the only code added to these sections be in the following form:.
|
The called routine should be located in another section. This will prevent conflicting register and stack usage within the .init sections.
.fini sections contain codes that are to be executed after the the main program is executed. To create an .fini section in an object file, use the assembler pseudo-ops shown in Example 3-2.
Example 3-2 Creating an .fini Section
.section ".fini" .align 4 <instructions>
At link time, the .fini sections in a sequence of .o files are concatenated into a .fini section in the linker output file. The codes in the .fini section are executed after the main program is executed.
Because the whole .fini section is treated as a single function body, it is recommended that the only code added to these section be in the following form:.
|
The called routine should be located in another section. This will prevent conflicting register and stack usage within the .fini sections.
Table 3-5 lists sections that are predefined but cannot be named in the section control directives because they are not under user control.
Table 3-5
|