Keil Logo

Sections

5.7 Sections

Sections are independent, named, indivisible chunks of code or data that are manipulated by the linker.

armasm syntax

The AREA directive instructs the assembler to assemble a new code or data section.

Section attributes within the AREA directive provide information about the section. Available section attributes include the following:

  • CODE specifies that the section contains machine instructions.
  • READONLY specifies that the section must not be written to.
  • ALIGN=n specifies that the section is aligned on a 2n byte boundary

For example:

AREA mysection, CODE, READONLY, ALIGN=3

Note:

The ALIGN attribute does not take the same values as the ALIGN directive. ALIGN=n (the AREA attribute) aligns on a 2n byte boundary. ALIGN n (the ALIGN directive) aligns on an n-byte boundary.

GNU syntax

The .section directive instructs the assembler to assemble a new code or data section.

Flags provide information about the section. Available section flags include the following:

  • a specifies that the section is allocatable.
  • x specifies that the section is executable.
  • w specifies that the section is writable.
  • S specifies that the section contains null-terminated strings.

For example:

.section  mysection,"ax"

Not all armasm syntax AREA attributes map onto GNU syntax .section flags. For example, the armasm syntax ALIGN attribute corresponds to the GNU syntax .balign directive, rather than a .section flag:

.section  mysection,"ax"
.balign 8

Note:

When using Arm® Compiler 5, section names do not need to be unique. Therefore, you could use the same section name to create different section types.

Arm Compiler 6 supports multiple sections with the same section name only if you specify a unique ID. You must ensure that different section types either:

  • Have a unique section name.
  • Have a unique ID, if they have the same section name.

If you use the same section name for another section or symbol, without a unique ID, then armclang integrated assembler merges the sections and gives the merged section the flags of the first section with that name.

// stores both the code and data in one section
// uses the flags from the first section
  .section "sectionX", "ax"
  mov r0, r0
  .section "sectionX", "a", %progbits
  .word 0xdeadbeef
 
// stores both the code and data in one section
// uses the flags from the first section
  .section "sectionY", "a", %progbits
  .word 0xdeadbeef
  .section "sectionY", "ax"
  mov r0, r0

When you assemble the above example code with:

armclang --target=arm-arm-none-eabi -c -march=armv8-m.main example_sections.s

The armclang integrated assembler:

  • merges the two sections named sectionX into one section with the flags "ax".
  • merges the two sections named sectionY into one section with the flags "a", %progbits.
Non-ConfidentialPDF file icon PDF version100068_0613_00_en
Copyright © 2014–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.