3.6.8.1 Output Section Type

Each output section may have a type. The type is a keyword in parentheses. The following types are defined:

NOLOAD

The section should be marked as not loadable, so that it will not be loaded into memory when the program is run.

READONLY

The section should be marked as read-only.

DSECT
COPY
INFO
OVERLAY

These type names are supported for backward compatibility, and are rarely used. They all have the same effect: the section should be marked as not allocatable, so that no memory is allocated for the section when the program is run.

TYPE = type

Set the section type to the integer type. When generating an ELF output file, type names SHT_PROGBITS, SHT_STRTAB, SHT_NOTE, SHT_NOBITS, SHT_INIT_ARRAY, SHT_FINI_ARRAY, and SHT_PREINIT_ARRAY are also allowed for type. It is the user’s responsibility to ensure that any special requirements of the section type are met.

Note - the TYPE only is used if some or all of the contents of the section do not have an implicit type of their own. So for example:

  .foo . TYPE = SHT_PROGBITS { *(.bar) }

will set the type of section ‘.foo’ to the type of the section ‘.bar’ in the input files, which may not be the SHT_PROGBITS type. Whereas:

  .foo . TYPE = SHT_PROGBITS { BYTE(1) }

will set the type of ‘.foo’ to SHT_PROGBBITS. If it is necessary to override the type of incoming sections and force the output section type then an extra piece of untyped data will be needed:

  .foo . TYPE = SHT_PROGBITS { BYTE(1); *(.bar) }
READONLY ( TYPE = type )

This form of the syntax combines the READONLY type with the type specified by type.

The linker normally sets the attributes of an output section based on the input sections which map into it. You can override this by using the section type. For example, in the script sample below, the ‘ROM’ section is addressed at memory location ‘0’ and does not need to be loaded when the program is run.

SECTIONS {
  ROM 0 (NOLOAD) : { … }
  …
}