用C代码定义一个程序部分(GCC) [英] define a program section in C code (GCC)
问题描述
.section foo
这怎么能在C代码中完成?我想将一段C代码放在一个特殊的部分而不是 .text
中,这样我就可以将该部分放在链接器脚本中的特殊位置。 / p>
我使用GCC。
在你的意思上说sections是什么意思,所以你需要使用扩展特定的编译器。
部分
属性: extern void foobar(void)__attribute __((部分( 条)));
有一些有限的文件这里,包括一个警告:
一些文件格式不支持
任意部分,所以部分
属性在所有
平台上都不可用。如果您需要将模块的
全部内容映射到
特定部分,请考虑使用链接器的
工具。
In assembly language, it's easy to define a section like:
.section foo
How can this be done in C code? I want to put a piece of C code in a special section rather than .text
, so I will be able to put that section in a special location in the linker script.
I'm using GCC.
The C standard doesn't say anything about "sections" in the sense that you mean, so you'll need to use extensions specific to your compiler.
With GCC, you will want to use the section
attribute:
extern void foobar(void) __attribute__((section("bar")));
There is some limited documentation here, including a warning:
Some file formats do not support arbitrary sections so the section attribute is not available on all platforms. If you need to map the entire contents of a module to a particular section, consider using the facilities of the linker instead.
这篇关于用C代码定义一个程序部分(GCC)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!