How to associate the beginning and size of a segment with C code

I am transferring the ARM chip program from the IAR compiler to gcc.

In the source code, special IAR operators, such as __segment_begin and __segment_size , are used to get the beginning and size of specific memory segments.

Is there a way to do the same with GCC? I was looking for a GCC manual but could not find anything relevant.


More details:
The considered memory segments must be in fixed locations so that the program can correctly interact with some peripheral devices on the chip. The source code uses the __segment_begin operator to get the address of this memory and __segment_size to make sure that it does not overflow this memory.

I can achieve the same functionality by adding variables to indicate the beginning and end of these memory segments, but if GCC had similar statements that would help minimize the amount of code dependent on the compiler, I had to write and maintain.

+6
gcc porting iar
source share
2 answers

What about the --section-start linker flag? What I read is supported here .

An example of how to use it can be found on the AVR Freaks forum :

 const char __attribute__((section (".honk"))) ProjString[16] = "MY PROJECT V1.1"; 

Then you need to add the linker options: -Wl,--section-start=.honk=address .

+2
source share

Modern versions of GCC will declare two variables for each segment, namely __start_MY_SEGMENT and __stop_MY_SEGMENT. To use these variables, you need to declare them as externs with the desired type. After that, you use "&"; operator to get the address of the beginning and end of this segment.

 extern uint8_t __start_MY_SEGMENT; extern uint8_t __stop_MY_SEGMENT; #define MY_SEGMENT_LEN (&__stop_MY_SEGMENT - &__start_MY_SEGMENT) 
0
source share

All Articles