Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Altera_Forum
Honored Contributor I
716 Views

Set function section

how do i put a function or a code file in a specific memory section? 

other than .text... 

 

tnx...
0 Kudos
3 Replies
Altera_Forum
Honored Contributor I
41 Views

Add (IIRC) __attribute__((section("section_name"))) to the definition, 

either at the end of a declaration, or (I think) before the function name itself.
Altera_Forum
Honored Contributor I
41 Views

The attribute directive must be added after the function declaration. 

 

For example you declare: 

int myFunction (void) __attribute__ ((section (".onchip_mem_code"))); 

 

Then the function definition without any attribute: 

int myFunction (void) 

// function body 

 

 

Similarly for data, except here you must specify attribute when you define the variable, not when you declare it: 

int myVariable __attribute__ ((section (".onchip_mem_data"))); 

For external referencing the variable, don't use any attribute: 

extern int myVariable;
Altera_Forum
Honored Contributor I
41 Views

You can also put the section attribute before the function name, eg: 

 

static __attribute__((section(".text.foo"))) int foo(void) { /* function body */ } 

 

(It can go either side of the return type, not sure which is preferred.) 

For non-static functions this rather depends on whether you want the section info in the .c file or the .h one. 

 

For data, the section in an 'extern' is used to determine whether to use 'small data' (%gp relative) addressing (.sdata or .sbss). The location of the data itself depends on the actual definition.
Reply