Keil Logo

Technical Support

On-Line Manuals

Compiler Reference Guide

Preface Arm Compiler Tools Overview armclang Reference armclang Command-line Options Summary of armclang command-line options -C (armclang) -c (armclang) -D -E -e -fbare-metal-pie -fbracket-depth=N -fcommon, -fno-common -fdata-sections, -fno-data-sections -ffast-math, -fno-fast-math -ffixed-rN -ffp-mode -ffunction-sections, -fno-function-sections -fident, -fno-ident @file -fldm-stm, -fno-ldm-stm -fno-builtin -fno-inline-functions -flto, -fno-lto -fexceptions, -fno-exceptions -fomit-frame-pointer, -fno-omit-frame-pointer -fpic, -fno-pic -fropi, -fno-ropi -fropi-lowering, -fno-ropi-lowering -frwpi, -fno-rwpi -frwpi-lowering, -fno-rwpi-lowering -fsanitize -fshort-enums, -fno-short-enums -fshort-wchar, -fno-short-wchar -fstack-protector, -fstack-protector-all, -fstack- -fstrict-aliasing, -fno-strict-aliasing -fsysv, -fno-sysv -ftrapv -fvectorize, -fno-vectorize -fvisibility -fwrapv -g, -gdwarf-2, -gdwarf-3, -gdwarf-4 (armclang) -I -include -L -l -M, -MM -MD, -MMD -MF -MG -MP -MT -march -marm -masm -mbig-endian -mbranch-protection -mcmodel -mcmse -mcpu -mexecute-only -mfloat-abi -mfpu -mimplicit-it -mlittle-endian -mno-neg-immediates -moutline, -mno-outline -mpixolib -munaligned-access, -mno-unaligned-access -mthumb -nostdlib -nostdlibinc -o (armclang) -O (armclang) -pedantic -pedantic-errors -Rpass -S -save-temps -shared (armclang) -std --target -U -u (armclang) -v (armclang) --version (armclang) --version_number (armclang) --vsn (armclang) -W -Wl -Xlinker -x (armclang) -### Compiler-specific Keywords and Operators Compiler-specific keywords and operators __alignof__ __asm __declspec attributes __declspec(noinline) __declspec(noreturn) __declspec(nothrow) __inline __promise __unaligned Global named register variables Compiler-specific Function, Variable, and Type Att Function attributes __attribute__((always_inline)) function attribute __attribute__((cmse_nonsecure_call)) function attr __attribute__((cmse_nonsecure_entry)) function att __attribute__((const)) function attribute __attribute__((constructor(priority))) function at __attribute__((format_arg(string-index))) function __attribute__((interrupt("type"))) function attrib __attribute__((malloc)) function attribute __attribute__((naked)) function attribute __attribute__((noinline)) function attribute __attribute__((nonnull)) function attribute __attribute__((noreturn)) function attribute __attribute__((nothrow)) function attribute __attribute__((pcs("calling_convention"))) functio __attribute__((pure)) function attribute __attribute__((section("name"))) function attribut __attribute__((unused)) function attribute __attribute__((used)) function attribute __attribute__((value_in_regs)) function attribute __attribute__((visibility("visibility_type"))) fun __attribute__((weak)) function attribute __attribute__((weakref("target"))) function attrib Type attributes __attribute__((aligned)) type attribute __attribute__((packed)) type attribute __attribute__((transparent_union)) type attribute Variable attributes __attribute__((alias)) variable attribute __attribute__((aligned)) variable attribute __attribute__((deprecated)) variable attribute __attribute__((packed)) variable attribute __attribute__((section("name"))) variable attribut __attribute__((unused)) variable attribute __attribute__((used)) variable attribute __attribute__((visibility("visibility_type"))) var __attribute__((weak)) variable attribute __attribute__((weakref("target"))) variable attrib Compiler-specific Intrinsics __breakpoint intrinsic __current_pc intrinsic __current_sp intrinsic __disable_fiq intrinsic __disable_irq intrinsic __enable_fiq intrinsic __enable_irq intrinsic __force_stores intrinsic __memory_changed intrinsic __schedule_barrier intrinsic __semihost intrinsic __vfp_status intrinsic Compiler-specific Pragmas #pragma clang system_header #pragma clang diagnostic #pragma clang section #pragma once #pragma pack(...) #pragma unroll[(n)], #pragma unroll_completely #pragma weak symbol, #pragma weak symbol1 = symbol Other Compiler-specific Features ACLE support Predefined macros Inline functions Half-precision floating-point data types Half-precision floating-point number format Half-precision floating-point intrinsics Library support for _Float16 data type BFloat16 floating-point number format TT instruction intrinsics Non-secure function pointer intrinsics armclang Integrated Assembler Syntax of assembly files for integrated assembler Assembly expressions Alignment directives Data definition directives String definition directives Floating-point data definition directives Section directives Conditional assembly directives Macro directives Symbol binding directives Org directive AArch32 Target selection directives AArch64 Target selection directives Space-filling directives Type directive Integrated assembler support for the CSDB instruct armclang Inline Assembler Inline Assembly File-scope inline assembly Inline assembly statements within a function Assembly string Output and input operands Clobber list volatile Inline assembly constraint strings Constraint modifiers Constraint codes Constraint codes common to AArch32 state and AArch Constraint codes for AArch32 state Constraint codes for AArch64 state Using multiple alternative operand constraints Inline assembly template modifiers Template modifiers common to AArch32 state and AAr Template modifiers for AArch32 state Template modifiers for AArch64 state Forcing inline assembly operands into specific reg Symbol references and branches into and out of inl Duplication of labels in inline assembly statement armlink Reference fromelf Reference armar Reference armasm Legacy Assembler Reference Appendixes

Section directives

B7.7 Section directives

The section directives instruct the assembler to change the ELF section that code and data are emitted into.

Syntax

.section name [, "flags" [, %type [, entry_size] [, group_name [, linkage]] [, link_order_symbol] [, unique, unique_id] ]]
.pushsection .section name [, "flags" [, %type [, entry_size] [, group_name [, linkage]] [, link_order_symbol] [, unique, unique_id] ]]
.popsection
.text
.data
.rodata
.bss

Description

name

The name argument gives the name of the section to switch to.

By default, if the name is identical to a previous section, or one of the built-in sections, the assembler will switch back to that section. Any code or data that is assembled will be appended to the end of that section. The unique-id argument can be used to override this behavior.

flags

The optional flags argument is a quoted string containing any of the following characters, which correspond to the sh_flags field in the ELF section header.

Table B7-14 Section flags

Flag Meaning
a SHF_ALLOC: the section is allocatable.
w SHF_WRITE: the section is writable.
y SHF_ARM_PURECODE: the section is not readable.
x SHF_EXECINSTR: the section is executable.
o SHF_LINK_ORDER: the section has a link-order restriction.
M SHF_MERGE: the section is mergeable.
S SHF_STRINGS: the section contains null-terminated string.
T SHF_TLS: the section is thread-local storage.
G SHF_GROUP: the section is a member of a section group.
? if the previous section was part of a group, this section is in the same group, otherwise ignored.

The flags can be specified as a numeric value, with the same encoding as the sh_flags field in the ELF section header. This cannot be combined with the flag characters listed above. When using this syntax, the quotes around the flags value are still required.

Note:

Certain flags need extra arguments, as described in the respective arguments.
type

The optional type argument is accepted with two different syntaxes: %type and "type". It corresponds to the sh_type field in the ELF section header. The following values for the type argument are accepted:

Table B7-15 Section Type

Argument ELF type Meaning
%progbits SHT_PROGBITS Section contains initialized data and/or instructions.
%nobits SHT_NOBITS Section consists only of zero-initialized data.
%note SHT_NOTE Section contains information that the linker or loader use to check compatibility.
%init_array SHT_INIT_ARRAY Section contains an array of pointers to initialization functions.
%fini_array SHT_FINI_ARRAY Section contains an array of pointers to termination functions.
%preinit_array SHT_PREINIT_ARRAY Section contains an array of pointers to pre-initialization functions.

The type can be specified as a numeric value, with the same encoding as the sh_type field in the ELF section header. When using this syntax, the quotes around the type value are still required.

entry_size

If the M flag is specified, the entry_size argument is required. This argument must be an integer value, which is the size of the records that are contained within this section, that the linker can merge.

group_name

If the G flag is specified, the group_name argument is required. This argument is a symbol name to be used as the signature to identify the section group. All sections in the same object file and with the same group_name are part of the same section group.

If the ? flag is specified, the section is implicitly in the same group as the previous section, and the group_name and linkage options are not accepted.

It is an error to specify both the G and ? flags on the same section.

linkage

If the G flag is specified, the optional linkage argument is allowed. The only valid value for this argument is comdat, which has the same effect as not providing the linkage argument. If any arguments after the group_name and linkage arguments are to be provided, then the linkage argument must be provided.

If the ? flag is specified, the section is implicitly in the same group as the previous section, and the group_name and linkage options are not accepted.

It is an error to specify both the G and ? flags on the same section.

link_order_symbol

If the o flag is specified, the link_order_symbol argument is required. This argument must be a symbol which is defined earlier in the same file. If multiple sections with the o flag are present at link time, the linker ensures that they are in the same order in the image as the sections that define the symbols they reference.

unique and unique_id

If the optional unique argument is provided, then the unique_id argument must also be provided. This argument should be a constant expression which evaluates to a positive integer. If a section has previously been created with the same name and unique ID, then the assembler will switch to the existing section, appending content to it. Otherwise, a new section is created. Sections without a unique ID specified will never be merged with sections that do have one. This allows creating multiple sections with the same name. The exact value of the unique ID is not important, and it has no effect on the generated object file.

Operation

The .section directive switches the current target section to the one described by its arguments. The .pushsection directive pushes the current target section onto a stack, and switches to the section described by its arguments. The .popsection directive takes no arguments, and reverts the current target section to the previous one on the stack. The rest of the directives (.text, .data, .rodata, .bss) switch to one of the built-in sections.

If continuing a previous section, and the flags, type, or other arguments do not match the previous definition of the section, then the arguments of the current .section directive will have no effect on the section. Instead, the assembler uses the arguments from the previous .section directive. The assembler does not currently emit a diagnostic when this happens.

Default

Some section names and section name prefixes implicitly have some flags set. Additional flags can be set using the flags argument, but it is not possible to clear these implicit flags. The section names that have implicit flags are listed in the table here. For sections names not mentioned in the table, the default is to have no flags.

If the %type argument is not provided, the type is inferred from the section name. For sections names not mentioned in the table here, the default section type is %progbits.

Table B7-16 Sections with implicit flags and default types

Section name Implicit Flags Default Type
.rodata a %progbits
.rodata.* a %progbits
.rodata1 a %progbits
.text ax %progbits
.text.* ax %progbits
.init ax %progbits
.fini ax %progbits
.data aw %progbits
.data.* aw %progbits
.data1 aw %progbits
.bss aw %nobits
.bss.* aw %nobits
.init_array aw %init_array
.init_array.* aw %init_array
.fini_array aw %fini_array
.fini_array.* aw %fini_array
.preinit_array aw %preinit_array
.preinit_array.* aw %preinit_array
.tdata awT %progbits
.tdata.* awT %progbits
.tbss awT %nobits
.tbss.* awT %nobits
.note* No default %note

Examples

Splitting code and data into the built-in .text and .data sections. The linker can place these sections independently, for example to place the code in flash memory, and the writable data in RAM.

     .text
    get_value:
      movw r0, #:lower16:value
      movt r0, #:upper16:value
      ldr r0, [r0]
      bx lr

      .data
    value:
      .word 42

Creating a section containing constant, mergeable records. This section contains a series of 8-byte records, where the linker is allowed to merge two records with identical content (possibly coming from different object files) into one record to reduce the image size.

      .section mergable, "aM", %progbits, 8
    entry1:
      .word label1
      .word 42
    entry2:
      .word label2
      .word 0x1234

Creating two sections with the same name:

      .section .data, "aw", %progbits, unique, 1
      .word 1
      .section .data, "aw", %progbits, unique, 2
      .word 2

Creating a section group containing two sections. Here, the G flag is used for the first section, using the group_signature symbol. The second section uses the ? flag to simplify making it part of the same group. Any further sections in this file using the G flag and group_signature symbol are placed in the same group.

      .section foo, "axG", %progbits, group_signature
    get_value:
      movw r0, #:lower16:value
      movt r0, #:upper16:value
      ldr r0, [r0]
      bx lr

      .section bar, "aw?"
      .local value
    value:
      .word 42
Non-ConfidentialPDF file icon PDF version101754_0613_00_en
Copyright © 2019 Arm Limited or its affiliates. All rights reserved. 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.