Skip Navigation Links | |
Exit Print View | |
SPARC Assembly Language Reference Manual Oracle Solaris 11.1 Information Library |
2. Executable and Linking Format
2.1.2 Predefined User Sections
2.1.2.1 Creating an .init Section in an Object File
2.1.2.2 Creating a .fini Section in an Object File
3. Directives and Pseudo-Operations
6. Writing Functions -- The SPARC ABI
7. Assembler Inline Functions and __asm Code
A. Using the Assembler Command Line
A section is the smallest unit of an object that can be relocated. Use the elfdump(1) command to inspect the components of an object or executable file generated by the assembler.
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 component 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 a number of fields as described in detail in sys/elf.h and Sections in Oracle Solaris 11.1 Linkers and Libraries Guide. However, only the following fields are of immediate interest to the assembly language programmer because they can be specified in assembler pseudo-operations (directives):
sh_flags
Description: One-bit descriptions of section attributes. Table 2-1 describes the some of the section attribute flags. For details and additional flags, see Sections in Oracle Solaris 11.1 Linkers and Libraries Guide
sh_info
Description: Extra information. The interpretation of this information depends on the section type, as described in . Table 2-2
sh_link
Description: Section header table index link. The interpretation of this information depends on the section type, as described in . Table 2-2
sh_name
Description: Specifies the section name. An index into the section header string table section specifies the location of a null-terminated string.
Table 2-1 Section Attribute Flags
|
Table 2-2 Section Types Modified by Assembler Pseudo-ops
|
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 2-3 lists some of the predefined user sections that can be named in the section control directives. For details and additional information, see Special Sections in Oracle Solaris 11.1 Linkers and Libraries Guide
Table 2-3 User Sections In Section Control Directives
|
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 2-1.
Example 2-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 recommented 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 2-2.
Example 2-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 2-4 lists sections that are predefined and not under user control. Therefore, these section names are reserved by the assembler and should be avoided.
Table 2-4 Reserved Sections
|
A symbol table contains information to locate and relocate symbolic definitions and references. The Oracle Solaris SPARC assembler creates a symbol table section for the object file. It makes an entry in the symbol table for each symbol that is defined or referenced in the input file and is needed during linking. The symbol table is then used by the Oracle Solaris linker during relocation. The section header contains the symbol table index for the first non-local symbol.
A symbol table contains the following information defined by Elf32_Sym and Elf64_Sym in sys/elf.h and Symbol Table Section in Oracle Solaris 11.1 Linkers and Libraries Guide:
st_name
Description: Index into the object file symbol string table. A value of zero indicates the symbol table entry has no name; otherwise, the value represents the string table index that gives the symbol name.
st_value
Description: Value of the associated symbol. This value is dependent on the context; for example, it may be an address, or it may be an absolute value.
st_size
Description: Size of symbol. A value of 0 indicates that the symbol has either no size or an unknown size.
st_info
Description: Specifies the symbol type and binding attributes. Table 2-5 and Table 2-6 describe these values.
st_other
Description: Specifies a symbol's visibility.
st_shndx
Description: Contains the section header table index to another relevant section, if specified. As a section moves during relocation, references to the symbol will continue to point to the same location because the value of the symbol will change as well.
Table 2-5 Symbol Type Attributes ELF32_ST_TYPE and ELF64_ST_TYPE
|
Table 2-6 shows the symbol binding attributes.
Table 2-6 Symbol Binding Attributes ELF32_ST_BIND and ELF64_ST_BIND
|
A string table is a section which contains null-terminated variable-length character sequences, or strings, in the object file; for example, symbol names and file names. The strings are referenced in the section header as indexes into the string table section.
A string table index may refer to any byte in the section.
Empty string table sections are permitted; however, the index referencing this section must contain zero.
A string may appear multiple times and may also be referenced multiple times. References to substrings may exist, and unreferenced strings are allowed.