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:
bss.
data.
rodata.
text.
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.
Note:
Section names must be unique. If you use the same
section name for different section types the compiler produces an error message.
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.
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.