Defines a section of an ELF (Executable and Linkable Format) object file.
.section name [,alignment [,type [,flags]]]
name
Name of the section.
alignment
Alignment boundary.
type
Numeric value for the ELF section type, per ELF Section Header Types (SHT) . The default type value is 1: (SHT_PROGBITS).
flags
Numeric value for the ELF section flags, per ELF Section Header Flags (SHF) . The default flags value is 0x00000002, 0x00000001: (SHF_ALLOC+SHF_WRITE).
| Type | Name | Meaning |
|---|---|---|
| 0 | NULL | Section header is inactive. |
| 1 | PROGBITS | Section contains information that the program defines. |
| 2 | SYMTAB | Section contains a symbol table. |
| 3 | STRTAB | Section contains a string table. |
| 4 | RELA | Section contains relocation entries with explicit addends. |
| 5 | HASH | Section contains a symbol hash table. |
| 6 | DYNAMIC | Section contains information used for dynamic linking. |
| 7 | NOTE | Section contains information that marks the file, often for compatibility purposes between programs. |
| 8 | NOBITS | Section occupies no space in the object file. |
| 9 | REL | Section contains relocation entries without explicit addends. |
| 10 | SHLIB | Section has unspecified semantics, so does not conform to the Application Binary Interface (ABI) standard. |
| 11 | DYNSYM | Section contains a minimal set of symbols for dynamic linking. |
| Flag | Name | Meaning |
|---|---|---|
| 0x00000001 | WRITE | Section contains data that is writable during execution. |
| 0x00000002 | ALLOC | Section occupies memory during execution. |
| 0x00000004 | EXECINSTR | Section contains executable machine instructions. |
| 0xF0000000 | MASKPROC | Bits this mask specifies are reserved for processor-specific purposes. |
Use this directive to create arbitrary relocatable sections, including sections to be loaded at an absolute address.
The section directive accepts a number of different syntax forms, partly for convenience and partly for compatibility with other assemblers. A section declaration requires four pieces of information: a section name, alignment, ELF section type (for example, SHT_PROGBITS) and ELF section flags (for example, SHF_ALLOC+SHF_EXECINSTR).
The possible syntax forms are as follows:
.section text
This example specifies a built-in section name text. Equivalently, .text is also a valid syntax form.
| Name | ELF Type | ELF Flag |
|---|---|---|
| .text | SHT_PROGBITS | SHF_ALLOC+SHF_EXECINSTR |
| .data | SHT_PROGBITS | SHF_ALLOC+SHF_WRITE |
| .rodata | SHT_PROGBITS | SHF_ALLOC |
| .bss | SHT_NOBITS | SHF_ALLOC+SHF_WRITE |
| .sdata | SHT_PROGBITS | SHF_ALLOC+SHF_WRITE |
| .sdata0 | SHT_PROGBITS | SHF_ALLOC+SHF_WRITE |
| .sdata2 | SHT_PROGBITS | SHF_ALLOC |
| .sbss | SHT_NOBITS | SHF_ALLOC+SHF_WRITE |
| .sbss0 | SHT_NOBITS | SHF_ALLOC+SHF_WRITE |
| .sbss2 | SHT_PROGBITS | SHF_ALLOC |
| .debug | SHT_PROGBITS | 0 |
| .text_vle | SHT_PROGBITS | SHF_ALLOC+SHF_EXECINSTR+ SHF_PE_EXECINSTR |
| .PPC.EMB.sdata0 | SHT_PROGBITS | SHF_ALLOC+SHF_WRITE |
| .PPC.EMB.sbss0 | SHT_PROGBITS | SHF_ALLOC+SHF_WRITE |
In general, .text is for instructions, .data for initialised data, .rodata for read-only data (constants) and .bss for uninitialised data. The additional forms like .sdata are for small data areas. The built-in section names are architecture-specific, and are intended to make access to data more efficient. The alignment used for these sections is architecture-specific and is usually 4.
.section mySection,text
This example is equivalent to writing .text except that the section will be called mySection.
.section name [,alignment [,type [,flags]]]
In the syntax above, if the alignment is not specified it defaults to 16. If the type or flags are not specified, the defaults are as follows:
.section mySection,4,"rx" or .section mySection,4,rx
The values are additive. For example, rx is equivalent to SHF_ALLOC+SHF_WRITE+SHF_EXECINSTR
| Character | ELF Type | ELF Flag |
|---|---|---|
| b | SHT_NOBITS | SHF_ALLOC+SHF_WRITE |
| c | SHT_PROGBITS | SHF_ALLOC+SHF_EXECINSTR |
| d | SHT_PROGBITS | SHF_ALLOC+SHF_WRITE |
| m | SHT_PROGBITS | SHF_ALLOC+SHF_WRITE+ SHF_EXECINSTR |
| r | 0 | SHF_ALLOC |
| w | 0 | SHF_ALLOC+SHF_WRITE |
| x | 0 | SHF_ALLOC+SHF_EXECINSTR |