Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I place a group of variables in a specific section in gcc, is there anything like #pragma default_variable_attributes available with arm

Tags:

c++

gcc

linker

The below link https://www.iar.com/support/tech-notes/linker/how-do-i-place-a-group-of-functions-or-variables-in-a-specific-section/ explains how a group of variables can be placed in a specific section, this is with IAR arm linker.

Pasting the example (for which i want a gcc equivalent) from the link here

/* Place following data in section MY_DATA */
#pragma default_variable_attributes = @ "MY_DATA"

int data1;
int data2;

/* Stop placing data in section MY_DATA */
#pragma default_variable_attributes =

In gcc do we have any such feature, which helps me to define in the source code how the variables can be place contiguously.

Regards

like image 575
Sid Avatar asked Sep 18 '25 18:09

Sid


1 Answers

With gcc you use the compiler's __attribute__ extension of the declarator syntax, e.g.

int my_global_1 __attribute__ ((section ("MyData"))) = 0;
int my_global_2 __attribute__ ((section ("MyData"))) = 0;

__attribute__ ((section ("MyFuncs"))) int foo(int i) 
{
    return i * i;
}
like image 94
Mike Kinghan Avatar answered Sep 21 '25 09:09

Mike Kinghan