tags:

views:

52

answers:

1

we know in assembly language, it's easy to define a section like: .section foo

but how to do it in c code? I want put a peice of c code in a special section rather than .text, so I will be able to put that section in a special location in link script.

I'm using gcc

Thanks

+6  A: 

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.

Stephen Canon
thanks men/women. extern void foobar(void) __attribute__((section("bar"))); works for me.
richard