as: Section
1
1 7.79 '.section NAME'
1 ====================
1
1 Use the '.section' directive to assemble the following code into a
1 section named NAME.
1
1 This directive is only supported for targets that actually support
1 arbitrarily named sections; on 'a.out' targets, for example, it is not
1 accepted, even with a standard 'a.out' section name.
1
1 COFF Version
1 ------------
1
1 For COFF targets, the '.section' directive is used in one of the
1 following ways:
1
1 .section NAME[, "FLAGS"]
1 .section NAME[, SUBSECTION]
1
1 If the optional argument is quoted, it is taken as flags to use for
1 the section. Each flag is a single character. The following flags are
1 recognized:
1
1 'b'
1 bss section (uninitialized data)
1 'n'
1 section is not loaded
1 'w'
1 writable section
1 'd'
1 data section
1 'e'
1 exclude section from linking
1 'r'
1 read-only section
1 'x'
1 executable section
1 's'
1 shared section (meaningful for PE targets)
1 'a'
1 ignored. (For compatibility with the ELF version)
1 'y'
1 section is not readable (meaningful for PE targets)
1 '0-9'
1 single-digit power-of-two section alignment (GNU extension)
1
1 If no flags are specified, the default flags depend upon the section
1 name. If the section name is not recognized, the default will be for
1 the section to be loaded and writable. Note the 'n' and 'w' flags
1 remove attributes from the section, rather than adding them, so if they
1 are used on their own it will be as if no flags had been specified at
1 all.
1
1 If the optional argument to the '.section' directive is not quoted,
1 it is taken as a subsection number (⇒Sub-Sections).
1
1 ELF Version
1 -----------
1
1 This is one of the ELF section stack manipulation directives. The
DONTPRINTYET 1 others are '.subsection' (⇒SubSection), '.pushsection' (*note1DONTPRINTYET 1 others are '.subsection' (⇒SubSection), '.pushsection' (⇒
PushSection), '.popsection' (⇒PopSection), and '.previous'
1 (⇒Previous).
1
1 For ELF targets, the '.section' directive is used like this:
1
1 .section NAME [, "FLAGS"[, @TYPE[,FLAG_SPECIFIC_ARGUMENTS]]]
1
1 If the '--sectname-subst' command-line option is provided, the NAME
1 argument may contain a substitution sequence. Only '%S' is supported at
1 the moment, and substitutes the current section name. For example:
1
1 .macro exception_code
1 .section %S.exception
1 [exception code here]
1 .previous
1 .endm
1
1 .text
1 [code]
1 exception_code
1 [...]
1
1 .section .init
1 [init code]
1 exception_code
1 [...]
1
1 The two 'exception_code' invocations above would create the
1 '.text.exception' and '.init.exception' sections respectively. This is
1 useful e.g. to discriminate between ancillary sections that are tied to
1 setup code to be discarded after use from ancillary sections that need
1 to stay resident without having to define multiple 'exception_code'
1 macros just for that purpose.
1
1 The optional FLAGS argument is a quoted string which may contain any
1 combination of the following characters:
1
1 'a'
1 section is allocatable
1 'd'
1 section is a GNU_MBIND section
1 'e'
1 section is excluded from executable and shared library.
1 'w'
1 section is writable
1 'x'
1 section is executable
1 'M'
1 section is mergeable
1 'S'
1 section contains zero terminated strings
1 'G'
1 section is a member of a section group
1 'T'
1 section is used for thread-local-storage
1 '?'
1 section is a member of the previously-current section's group, if
1 any
1 '<number>'
1 a numeric value indicating the bits to be set in the ELF section
1 header's flags field. Note - if one or more of the alphabetic
1 characters described above is also included in the flags field,
1 their bit values will be ORed into the resulting value.
1 '<target specific>'
1 some targets extend this list with their own flag characters
1
1 Note - once a section's flags have been set they cannot be changed.
1 There are a few exceptions to this rule however. Processor and
1 application specific flags can be added to an already defined section.
1 The '.interp', '.strtab' and '.symtab' sections can have the allocate
1 flag ('a') set after they are initially defined, and the
1 '.note-GNU-stack' section may have the executable ('x') flag added.
1
1 The optional TYPE argument may contain one of the following
1 constants:
1
1 '@progbits'
1 section contains data
1 '@nobits'
1 section does not contain data (i.e., section only occupies space)
1 '@note'
1 section contains data which is used by things other than the
1 program
1 '@init_array'
1 section contains an array of pointers to init functions
1 '@fini_array'
1 section contains an array of pointers to finish functions
1 '@preinit_array'
1 section contains an array of pointers to pre-init functions
1 '@<number>'
1 a numeric value to be set as the ELF section header's type field.
1 '@<target specific>'
1 some targets extend this list with their own types
1
1 Many targets only support the first three section types. The type
1 may be enclosed in double quotes if necessary.
1
1 Note on targets where the '@' character is the start of a comment (eg
1 ARM) then another character is used instead. For example the ARM port
1 uses the '%' character.
1
1 Note - some sections, eg '.text' and '.data' are considered to be
1 special and have fixed types. Any attempt to declare them with a
1 different type will generate an error from the assembler.
1
1 If FLAGS contains the 'M' symbol then the TYPE argument must be
1 specified as well as an extra argument--ENTSIZE--like this:
1
1 .section NAME , "FLAGS"M, @TYPE, ENTSIZE
1
1 Sections with the 'M' flag but not 'S' flag must contain fixed size
1 constants, each ENTSIZE octets long. Sections with both 'M' and 'S'
1 must contain zero terminated strings where each character is ENTSIZE
1 bytes long. The linker may remove duplicates within sections with the
1 same name, same entity size and same flags. ENTSIZE must be an absolute
1 expression. For sections with both 'M' and 'S', a string which is a
1 suffix of a larger string is considered a duplicate. Thus '"def"' will
1 be merged with '"abcdef"'; A reference to the first '"def"' will be
1 changed to a reference to '"abcdef"+3'.
1
1 If FLAGS contains the 'G' symbol then the TYPE argument must be
1 present along with an additional field like this:
1
1 .section NAME , "FLAGS"G, @TYPE, GROUPNAME[, LINKAGE]
1
1 The GROUPNAME field specifies the name of the section group to which
1 this particular section belongs. The optional linkage field can
1 contain:
1
1 'comdat'
1 indicates that only one copy of this section should be retained
1 '.gnu.linkonce'
1 an alias for comdat
1
1 Note: if both the M and G flags are present then the fields for the
1 Merge flag should come first, like this:
1
1 .section NAME , "FLAGS"MG, @TYPE, ENTSIZE, GROUPNAME[, LINKAGE]
1
1 If FLAGS contains the '?' symbol then it may not also contain the 'G'
1 symbol and the GROUPNAME or LINKAGE fields should not be present.
1 Instead, '?' says to consider the section that's current before this
1 directive. If that section used 'G', then the new section will use 'G'
1 with those same GROUPNAME and LINKAGE fields implicitly. If not, then
1 the '?' symbol has no effect.
1
1 If no flags are specified, the default flags depend upon the section
1 name. If the section name is not recognized, the default will be for
1 the section to have none of the above flags: it will not be allocated in
1 memory, nor writable, nor executable. The section will contain data.
1
1 For ELF targets, the assembler supports another type of '.section'
1 directive for compatibility with the Solaris assembler:
1
1 .section "NAME"[, FLAGS...]
1
1 Note that the section name is quoted. There may be a sequence of
1 comma separated flags:
1
1 '#alloc'
1 section is allocatable
1 '#write'
1 section is writable
1 '#execinstr'
1 section is executable
1 '#exclude'
1 section is excluded from executable and shared library.
1 '#tls'
1 section is used for thread local storage
1
1 This directive replaces the current section and subsection. See the
1 contents of the gas testsuite directory 'gas/testsuite/gas/elf' for some
1 examples of how this directive and the other section stack directives
1 work.
1