Compiler Pragmas to allocate object to a section

Asked by Deepa Ballari

Hello,

In my application, I want to allocate objects to a particular section using GNU tools. Something like,
#pragma data_seg( "MY_DATA_FOO" )
__declspec(allocate("MY_DATA_FOO")) int foo1;

Compiler should create MY_DATA_FOO section and place foo1 in it.

Does GNU compiler support this and if yes what's the equivalent syntax?

Thanks,
Deepa

Question information

Language:
English Edit question
Status:
Answered
For:
GNU Arm Embedded Toolchain Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Joey Ye (jinyun-ye) said :
#1

From GCC manual:
extern void foobar (void) __attribute__ ((section ("MY_DATA_FOO")));

Thanks - Joey

On Fri, Aug 10, 2012 at 5:05 PM, Deepa Ballari <
<email address hidden>> wrote:

> New question #205467 on GCC ARM Embedded:
> https://answers.launchpad.net/gcc-arm-embedded/+question/205467
>
> Hello,
>
> In my application, I want to allocate objects to a particular section
> using GNU tools. Something like,
> #pragma data_seg( "MY_DATA_FOO" )
> __declspec(allocate("MY_DATA_FOO")) int foo1;
>
> Compiler should create MY_DATA_FOO section and place foo1 in it.
>
> Does GNU compiler support this and if yes what's the equivalent syntax?
>
> Thanks,
> Deepa
>
> --
> You received this question notification because you are an answer
> contact for GCC ARM Embedded.
>

Revision history for this message
chengbin (can-finner) said :
#2

I am not sure whether we can do this in gcc by using pragma,
but yes,
objects/functions can be put into special sections using "__attribute__".
For example,
int init_data __attribute__ ((section ("INITDATA"))) = 0;
will put init_data in section INITDATA.

For more information, please refer to gcc manual, sections
"Declaring Attributes of Functions/Variables".

Thanks.

Can you help with this problem?

Provide an answer of your own, or ask Deepa Ballari for more information if necessary.

To post a message you must log in.