您的位置:首页 > 其它

__attribute__宏与link脚本的用法

2011-11-03 16:23 211 查看
__attribute__宏用于定义变量或函数的编译属性,编译器在链接时参考这些属性参数进行相应的链接操作.

比如format属性用于检查函数参数合法性,.section属性用于将变量或函数放入指定段内.

__attribute__宏通常与link脚本./arch/ia64/kernel/vmlinux.lds.S配合使用

例子:

vmlinux.lds.S会将如下函数放入.init.text段,初始化时被调用且只调用一次,然后改段所占用内存被释放.

# define __section(S) __attribute__ ((__section__(#S)))

#define __init __section(.init.text) __cold notrace

asmlinkage void __init start_kernel(void)
{

}

具体用法参考 GCC手册

变量属性:

http://gcc.gnu.org/onlinedocs/gcc-4.5.3/gcc/Variable-Attributes.html#Variable-Attributes

函数属性:

http://gcc.gnu.org/onlinedocs/gcc-4.5.3/gcc/Function-Attributes.html#Function-Attributes

类型定义属性:

http://gcc.gnu.org/onlinedocs/gcc-4.5.3/gcc/Type-Attributes.html#Type-Attributes
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  脚本 编译器 gcc