cancel
Showing results for 
Search instead for 
Did you mean: 

GCC Linker script sections

yakabmarci
Senior

How to put all code from one file in one linker section?

I'm using Cubeide with gcc

The following functionality should work but it doesn't for some reason, can anyone help here?

It shall be possible to group functions in a section based on some filters. e.g. some pattern in the name, individually specifying each and every function, all functions from one file. etc..

In my case what i would like to do is to automatically put all functions from one file in a separate section apart from the rest (.text)

However trying several variations of this it doesn't work, i can't set up the filter properly so this is applied only to functions from specific_file.c

.specific_code : {
specific_file.c *(.text*)
} > FLASH

GCC complains that either the file is not found or the format is not recognized or there are multiple definitions.

(function name pattern matching, or specifying the attribute manually for each function works as expected)

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
MikaelM
ST Employee

hello @yakabmarci ,

to put the entire file into a specific region you have to define first a memory region : 

/* Memories definition */
MEMORY
{
RAM (xrw) : ORIGIN = 0x28000000, LENGTH = 16K
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 2040K
my_memory(rx) : ORIGIN = 0x081FE000, LENGTH = 8K
}

then create a section :
.myCode :
{
. = ALIGN(4);
__my_section_start__ = .;
*my_file.o (.text .text*)
__my_section_end__ = .;
/*. = ALIGN(4); */
} > my_memory /* new section for my special code files */

ASSERT( LENGTH(my_memory) >= (__my_section_end__ - __my_section_start__), "my_memory overflowed !")

you have to create your section before the .text section.

in the map file you will have something like that :

.myCode 0x00000000081fe000 0xc8
0x00000000081fe000 . = ALIGN (0x4)
0x00000000081fe000 __my_section_start__ = .
*my_file.o(.text .text* .rodata .rodata*)
.text.init
0x00000000081fe000 0x3c ./my_file.o
0x00000000081fe000 init
.text.read
0x00000000081fe03c 0x8c ./my_file.o
0x00000000081fe03c read
0x00000000081fe0c8 __my_section_end__ = .
0x0000000000000001 ASSERT ((LENGTH (my_memory) >= (__my_section_end__ - __my_section_start__)), my_memory overflowed !)

best regards

Mikael

If you feel a post has answered your question, please click "Accept as Solution".

If you feel a post has answered your question, please click Accept as Solution.

View solution in original post

4 REPLIES 4
TDK
Guru

You can individually specify functions to put in different sections using the function attributes. GCC isn't set up to do it any other way.

e.g. 

__attribute__ ((section(".RamFunc")))

 

If you feel a post has answered your question, please click "Accept as Solution".

Typically it's the .O object file that you're calling out at this level, not the source. Look at the .MAP file.

Or the wildcard or full naming of the text sections from the object (.textxyz)

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
MikaelM
ST Employee

hello @yakabmarci ,

to put the entire file into a specific region you have to define first a memory region : 

/* Memories definition */
MEMORY
{
RAM (xrw) : ORIGIN = 0x28000000, LENGTH = 16K
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 2040K
my_memory(rx) : ORIGIN = 0x081FE000, LENGTH = 8K
}

then create a section :
.myCode :
{
. = ALIGN(4);
__my_section_start__ = .;
*my_file.o (.text .text*)
__my_section_end__ = .;
/*. = ALIGN(4); */
} > my_memory /* new section for my special code files */

ASSERT( LENGTH(my_memory) >= (__my_section_end__ - __my_section_start__), "my_memory overflowed !")

you have to create your section before the .text section.

in the map file you will have something like that :

.myCode 0x00000000081fe000 0xc8
0x00000000081fe000 . = ALIGN (0x4)
0x00000000081fe000 __my_section_start__ = .
*my_file.o(.text .text* .rodata .rodata*)
.text.init
0x00000000081fe000 0x3c ./my_file.o
0x00000000081fe000 init
.text.read
0x00000000081fe03c 0x8c ./my_file.o
0x00000000081fe03c read
0x00000000081fe0c8 __my_section_end__ = .
0x0000000000000001 ASSERT ((LENGTH (my_memory) >= (__my_section_end__ - __my_section_start__)), my_memory overflowed !)

best regards

Mikael

If you feel a post has answered your question, please click "Accept as Solution".

If you feel a post has answered your question, please click Accept as Solution.

thank you, this is exactly what i needed, and works as expected