6

I am porting a program for an ARM chip from a IAR compiler to gcc.

In the original code, IAR specific operators such as __segment_begin and __segment_size are used to obtain the beginning and size respectively of certain memory segments.

Is there any way to do the same thing with GCC? I've searched the GCC manual but was unable to find anything relevant.


More details:
The memory segments in question have to be in fixed locations so that the program can interface correctly with certain peripherals on the chip. The original code uses the __segment_begin operator to get the address of this memory and the __segment_size to ensure that it doesn't overflow this memory.

I can achieve the same functionality by adding variables to indicate the start and end of these memory segments but if GCC had similar operators that would help minimise the amount of compiler dependent code I end up having to write and maintain.

tomsgd
  • 1,080
  • 1
  • 11
  • 24
  • can you be more specific as to what you need those segment addresses and sizes for, and for which segments? – JeSuisse Mar 07 '11 at 13:49

2 Answers2

2

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

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

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

You will then have to add to the linker's options: -Wl,--section-start=.honk=address.

JoeSlav
  • 4,479
  • 4
  • 31
  • 50
  • Thanks. I wanted to avoid having to change linker settings because the code I'm porting is intended to be for a library and that would mean that all users of the library will have to edit linker settings to get it to work, which if possible I'd like to avoid. – tomsgd Mar 18 '11 at 00:43
1

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. Following that, you and then use the '&' operator to get the address of the start and end of that segment.

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