5.3 #pragma clang section

Specifies names for one or more section types. The compiler places subsequent functions, global variables, or static variables in the named section depending on the section type. The names only apply within the compilation unit.

Syntax

#pragma clang section [section_type_list]

Where:

section_type_list

specifies an optional list of section names to be used for subsequent functions, global variables, or static variables. The syntax of section_type_list is:

section_type="name"[ section_type="name"]

You can revert to the default section name by specifying an empty string, "", for name.

Valid section types are:

Usage

Use #pragma clang section [section_type_list] to place functions and variables in separate named sections. You can then use the scatter-loading description file to locate these at a particular address in memory.

  • If you specify a section name with _attribute_((section("myname"))), then the attribute name has priority over any applicable section name that you specify with #pragma clang section.
  • #pragma clang section has priority over the -ffunction-section and -fdata-section command-line options.
  • Global variables, including basic types, arrays, and struct that are initialized to zero are placed in the .bss section. For example, int x = 0;.
  • armclang does not try to infer the type of section from the name. For example, assigning a section .bss.mysec does not mean it is placed in a .bss section.
  • If you specify the -ffunction-section and -fdata-section command-line options, then each global variable is in a unique section.

Example

int x1 = 5;                     // Goes in .data section (default)
int y1;                         // Goes in .bss section (default)
const int z1 = 42;              // Goes in .rodata section (default)
char *s1 = "abc1";              // s1 goes in .data section (default). String "abc1" goes in .conststring section.

#pragma clang section bss="myBSS" data="myData" rodata="myRodata"
int x2 = 5;                     // Goes in myData section.
int y2;                         // Goes in myBss section.
const int z2 = 42;              // Goes in myRodata section.
char *s2 = "abc2";              // s2 goes in myData section. String "abc2" goes in .conststring section.

#pragma clang section rodata=""   // Use default name for rodata section.
int x3 = 5;                     // Goes in myData section.
int y3;                         // Goes in myBss section.
const int z3 = 42;              // Goes in .rodata section (default).
char *s3 = "abc3";              // s3 goes in myData section. String "abc3" goes in .conststring section.

#pragma clang section text="myText"
int add1(int x)                 // Goes in myText section.
{
    return x+1;
} 
#pragma clang section bss="" data="" text="" // Use default name for bss, data, and text sections.
Non-ConfidentialPDF file icon PDF version100067_0609_00_en
Copyright © 2014–2017 Arm Limited (or its affiliates). All rights reserved.