关于__attribute__中section部分的一些了解
来源:互联网 发布:js 数字字母正则 编辑:程序博客网 时间:2024/05/22 13:27
诸如我辈菜鸟,对编译器了解比较少,面对代码中出现的陌生字眼真是茫然不知所措。今天查阅了一些资料,总算是有了一点了解,现在将些许理解记录在案。
__attribute__这个关键词是GNU编译器中的编译属性,ARM编译器也支持这个用法。__attribute__主要用于改变所声明或定义的函数或 数据的特性,它有很多子项,用于改变作用对象的特性。比如对函数,noline将禁止进行内联扩展、noreturn表示没有返回值、pure表明函数除 返回值外,不会通过其它(如全局变量、指针)对函数外部产生任何影响。当然,__attribute__肯定有很多的用法,今天就用到了section部分,所以就只针对这个做一些记录。
提到section,就得说RO RI ZI了,在ARM编译器编译之后,代码被划分为不同的段,RO Section(ReadOnly)中存放代码段和常量,RW Section(ReadWrite)中存放可读写静态变量和全局变量,ZI Section(ZeroInit)是存放在RW段中初始化为0的变量。
于是本文的大体意思就清晰了,__attribute__((section("section_name"))),其作用是将作用的函数或数据放入指定名为"section_name"对应的段中。
MDK给出的帮助文档如下,他将__attribute__的用法归类到编译器特性里,以变量和函数的两种用法做区分。
__attribute__这个关键词是GNU编译器中的编译属性,ARM编译器也支持这个用法。__attribute__主要用于改变所声明或定义的函数或 数据的特性,它有很多子项,用于改变作用对象的特性。比如对函数,noline将禁止进行内联扩展、noreturn表示没有返回值、pure表明函数除 返回值外,不会通过其它(如全局变量、指针)对函数外部产生任何影响。当然,__attribute__肯定有很多的用法,今天就用到了section部分,所以就只针对这个做一些记录。
提到section,就得说RO RI ZI了,在ARM编译器编译之后,代码被划分为不同的段,RO Section(ReadOnly)中存放代码段和常量,RW Section(ReadWrite)中存放可读写静态变量和全局变量,ZI Section(ZeroInit)是存放在RW段中初始化为0的变量。
于是本文的大体意思就清晰了,__attribute__((section("section_name"))),其作用是将作用的函数或数据放入指定名为"section_name"对应的段中。
MDK给出的帮助文档如下,他将__attribute__的用法归类到编译器特性里,以变量和函数的两种用法做区分。
1.编译时为变量指定段
__attribute__((section("name")))RealView Compilation Tools for µVision Compiler Reference Guide Version 4.0 Home > Compiler-specific Features > Variable attributes > __attribute__((section("name"))) 4.5.6. __attribute__((section("name")))Normally, the ARM compiler places the objects it generates in sections like data and bss. However, you might require additional data sections or you might want a variable to appear in a special section, for example, to map to special hardware. The section attribute specifies that a variable must be placed in a particular data section. If you use the section attribute, read-only variables are placed in RO data sections, read-write variables are placed in RW data sections unless you use the zero_init attribute. In this case, the variable is placed in a ZI section.NoteThis variable attribute is a GNU compiler extension supported by the ARM compiler.Example/* in RO section */const int descriptor[3] __attribute__ ((section ("descr"))) = { 1,2,3 };/* in RW section */long long rw[10] __attribute__ ((section ("RW")));/* in ZI section *long long altstack[10] __attribute__ ((section ("STACK"), zero_init));/
__attribute__((section("name")))RealView Compilation Tools for µVision Compiler Reference Guide Version 4.0 Home > Compiler-specific Features > Function attributes > __attribute__((section("name"))) 4.3.13. __attribute__((section("name")))The section function attribute enables you to place code in different sections of the image.NoteThis function attribute is a GNU compiler extension that is supported by the ARM compiler.ExampleIn the following example, Function_Attributes_section_0 is placed into the RO section new_section rather than .text.void Function_Attributes_section_0 (void) __attribute__ ((section ("new_section")));void Function_Attributes_section_0 (void){ static int aStatic =0; aStatic++;}In the following example, section function attribute overrides the #pragma arm section setting.#pragma arm section code="foo" int f2() { return 1; } // into the 'foo' area __attribute__ ((section ("bar"))) int f3() { return 1; } // into the 'bar' area int f4() { return 1; } // into the 'foo' area#pragma arm section
记录完毕,希望能够给遇到同样问题的朋友些许帮助。
- 关于__attribute__中section部分的一些了解
- __attribute__的一点了解
- gcc的__attribute__((section(“”)))属性含义
- gcc的一些 __attribute__
- 关于MeasureSpec的一些了解
- 关于session的一些了解
- 关于UNIGINE的一些了解
- 关于openstack的一些了解
- __attribute__编译属性---section
- gcc编译器 __attribute__ ((section(".")))
- __attribute__的一些小用法
- __attribute__使用的一些总结
- __attribute__使用的一些总结
- __attribute__使用的一些总结
- 关于GCC的__attribute__ ((constructor))
- 关于GCC的__attribute__ ((constructor))
- 关于GCC的__attribute__(constructor)
- 关于GCC的__attribute__ ((constructor))
- 往死里写——ECAT_Main()状态机处理
- Apple Developer Website Update
- 豆瓣的curl测试
- Java 的 vector 中非基本类型的删除
- 初始化一个list集合
- 关于__attribute__中section部分的一些了解
- 互斥信号量 二进制信号量
- 【jiasuba】教你快速对异常错误进行更正
- 黑马程序员__集合工具类
- XML语法规则
- tornado io 阻塞 线程
- 学生信息管理系统解析之宏观把控篇
- Android 高级控件学习--ProgressBar
- 通过Java调用音频文件 不需要播放器