【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 @   壹点灵异  阅读(308)  评论(0编辑  收藏  举报
编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
点击右上角即可分享
微信分享提示