开发者

define a program section in C code (GCC)

开发者 https://www.devze.com 2023-01-11 23:08 出处:网络
In assembly language, it\'开发者_如何学Pythons 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

In assembly language, it'开发者_如何学Pythons 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消