7.2. ELF Sections

ELF's section-based output supports attributes on a per-section basis. These attributes include alloc, exec, write, progbits, and align. Except for align, they can each be negated in NASM syntax by prepending “no”, e.g., “noexec”. The attributes are later read by the operating system to select the proper behavior for each section, with the meanings shown in Table 7.1.

Table 7.1. ELF Section Attributes

Attribute Indicates the section
alloc

is loaded into memory at runtime. This is true for code and data sections, and false for metadata sections.

exec has permission to be run as executable code.
write is writable at runtime.
progbits

is stored in the disk image, as opposed to allocated and initialized at load.

align=n

requires a memory alignment of n bytes. The value n must always be a power of 2.


In NASM syntax, the attribute nobits is provided as an alias for noprogbits.

The standard primary sections have attribute defaults according their expected use, and any unknown section gets its own defaults, as shown in Table 7.2.

Table 7.2. ELF Standard Sections

Section alloc exec write progbits align
.bss alloc   write   4
.data alloc   write progbits 4
.rodata alloc     progbits 4
.text alloc exec   progbits 16
.comment       progbits 0
unknown alloc     progbits 1