Defines a section of an object file.
.section name [ ,alignment ] [ ,type ] [ ,flags ]
name
Name of the section.
alignment
Alignment boundary.
type
Numeric value for the ELF section type, per the following table. The default type value is 1: (SHT_PROGBITS).
| 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. |
flags
Numeric value for the ELF section flags, per the the following table. The default flags value is 0x00000002, 0x00000001: (SHF_ALLOC+SHF_WRITE).
| 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. |
You can use this directive to create arbitrary relocatable sections, including sections to be loaded at an absolute address.
Most assemblers generate ELF (Executable and Linkable Format) object files, but a few assemblers generate COFF (Common Object File Format) object files.
The assembler supports this alternative syntax, which you may find convenient:
.section name,typestring
(The name parameter has the same role as in the full syntax. The typestring value can be text, data, rodata, bss, sdata, or so forth.)
Normally, repeating a .text directive would resume the previous .text section. But to have each .text directive create a separate section, include in this relocatable section the statement .option no_section_resume_on.
This example specifies a section named vector, with an alignment of 4 bytes, and default type and flag values:
.section vector,4