Difference between "section" and "segment" in NASM

From the nasm documentation:

The SECTION directive (SEGMENT is an exactly equivalent synonym)

Nasm can produce output in various formats, some of which support sections. Certain section names can be arbitrary (such as the three you listed), for them only the section flags count. The predefined ones are just convenience shortcuts, .text is marked as containing code, .data as read-write initialized data and .bss as zero-initialized read-write data. You could put your code in a section named foo as long as it was marked as a code section, and you can use multiple sections as you see fit.


Also, it's worth to note that you can define your own sections with special flags (and change flags on default sections) which is elf extensions to the section directive. From the docs:

Like the obj format, elf allows you to specify additional information on the SECTION directive line, to control the type and properties of sections you declare.

For instance, you can create a section like this:

section .special write

After assembling you can examine it: readelf -S test.o

[3] .special          PROGBITS         0000000000000000  00000250
   0000000000000005  0000000000000000  WA       0     0     1