Contents|Index|Previous|Next
Section Definitions
The most frequently used statement in the SECTIONS command is the section definition, which specifies the properties of an output section: its location,
alignment, contents, fill pattern, and target memory region. Most of these
specifications are optional; the simplest form of a section definition is like the following.
SECTIONS { ...
secname :{
contents
}
... }
secname
is the name of the output section, and contents a specification of what goes there—for example, a list of input files or
sections of input files (see Section Placement). As you might assume, the whitespace shown is optional. You do need the
colon ‘:’ and the braces ‘{}’, however. secname must meet the constraints of your output format. In formats which only
support a limited number of sections, such as a.out, the name must be one of the names supported by the format (a.out, for example, allows only .text, .data or .bss).
If the output format supports any number of sections, but with numbers and not
names (as is the case for Oasys), the name should be supplied as a quoted
numeric string. A section name may consist of any sequence of characters, but any
name which does not conform to the standard
ld symbol name syntax must be quoted. See Symbol Names. The linker will not create output sections which do not have any contents.
This is for convenience when referring to input sections that may or may not
exist. For instance, input like the following will only create a ‘.foo’ section in the output file if there is a ‘.foo’ section in at least one input file.
.foo { *(.foo }