【ARM】CODE RO RW ZI 程序分布

Relationship between the default armclang-generated sections and scatter-loading input sections

How the default sections that armclang generates relate to the sections in an image depends on the attributes of the sections. Without a scatter file, the scatter-loading mechanism maps the sections using default input section selectors. However, you can modify the mapping with a scatter file.

The following table shows the relationship between armclang-generated sections and scatter-loading input sections:

Table 1. Relationship between the default armclang-generated sections and input section selectors
Default section names that armclang generates Input section selectors for scatter-loading Corresponding execution regions for scatter-loading without a scatter file Example
.bss .bss, ZI, or BSS ER_ZI Zero-Initialized data int b=0; and uninitialized data int a;
.data .data, RW, RW-DATA, or DATA ER_RW Read/write data int z=5;
.constdata .constdata, RO, RO-DATA, or CONST ER_RO Read-only constants.
.rodata .rodata, RO, RO-DATA, or CONST ER_RO Read-only numerical constants int const x=5
.rodata.str1.1 .rodata.str1.1, RO, RO-DATA, or CONST ER_RO

String contained in

printf("const string");

.text .text, RO, RO-CODE, or CODE ER_RO Source that translates to instructions.
.text with SHF_ARM_NOREAD flag XO ER_XO

Source code built with

-mexecute_only

.llvmbc (LLVM bitcode) RO-CODE, or CODE ER_RO Section containing bitcode generated by the link time optimizer.

Note

This table shows the default section names that armclang generates. You can create sections with different names using the __attribute__((section("name"))) function and variable attribute, for example.

armlink prioritizes the most specific selector first, with no ambiguity allowed. The input section selector .rodata* also selects .rodata.str1.1. Specifying both *(.rodata*) and *(.rodata.str1.*) matches *(.rodata.str1.*) sections then any remaining RO data sections with *(.rodata*). For more information, see How the linker resolves multiple matches when processing scatter files.

Example

The following example shows the placement of code and data, with default section names and user-specified section names:

int x1 = 5;                                                // in .data.x1 (default) - RW
int y1[100];                                               // in .bss.y1 (default) - ZI
int const z1[3] = {1,2,3};                                 // in .rodata.z1 (default) - RO

int x2 __attribute__((section("foo"))) = 5;                // in foo (data part of region) - RW
int y2[100];                                               // in .bss.y2 (default) - ZI
int const z2[3] __attribute__((section("bar"))) = {1,2,3}; // in bar - RW
char *s2 __attribute__((section("foo"))) = "abc";          // s2 in foo, "abc" in .rodata.str1.1 - RO

int x3 __attribute__((section("foo"))) = 5;                // in foo (data part of region) - RW
int y3[100];                                               // in .bss.y3 (default) - RW
int const z3[3] = {1,2,3};                                 // in .rodata.z3 (default) - RO
char *s3 __attribute__((section("foo"))) = "def";          // s3 in foo, "def" in .rodata.str1.1 - RW

int add1(int x) __attribute__((section("foo")));
int add1(int x)                                            // in foo (code part of region) - CODE
{
    return x+1;
}

 

来源

posted @ 2019-02-14 12:44  壹点灵异  阅读(301)  评论(0编辑  收藏  举报