最近研究了一下自定义section,总结一下以备不时之需。
定义:使用__attribute__((section(“mysection.test”)))
在定义变量时,加上该属性,则编译后相同section的变量会被链接到一个连续的区域。
特别的,当section名中只有字母数字(不含._等字符)时,可以方便的使用sectionname$$Base sectionname$$Limit sectionname$$Lenght
获取sectionname这个section的起始、结束和长度信息。
例如定义为type __attribute__((section("mysection"))) s1,s2;
的变量,可以这样使用
extern type mysection$$Base;
extern type mysection$$Limit;
extern int mysection$$Lenght;
type *pStart = &mysection$$Base;
type *pEnd =&mysection$$Limit;
int Count= mysection$$Lenght/sizeof(type);
在GCC中,起止分别为__start_mysection,__stop_mysection.
用法与armcc和armclang一样。