Skip to main content
yakabmarci
Associate III
September 11, 2023
Solved

GCC Linker script sections

  • September 11, 2023
  • 3 replies
  • 9962 views

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)

 

 

This topic has been closed for replies.
Best answer by MikaelM

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".

3 replies

TDK
Super User
September 11, 2023

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""."
Tesla DeLorean
Guru
September 11, 2023

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 VenmoUp vote any posts that you find helpful, it shows what's working..
MikaelM
MikaelMBest answer
ST Employee
September 11, 2023

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.
yakabmarci
Associate III
September 12, 2023

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