I am working on an embedded C project using GCC for ARM V-4.8.3 toolchain. I have an array of look-up structures that are read only during the life cycle of the entire program. Since I am running out of RAM (and have plenty of Flash unused) it is better idea to push them into the flash, which will not affect the function of the program. The problem is how.
One way to do so is using the variable __attribute__ ((section ("TEXT")))
provided by GCC. In this case my code is compiler dependent. If I want to use my code using Microchip compiler for instance I need to edit the code to port to the new environment.
The other way coming to my mind is using the linker script. The structure is only declared into the code.
It seems to me that the second approach is a bit more portable. Although it is still needed to adjust the linker script, to me it is better. Is there more general approach that would make the code more portable into the context of placing variables into the flash?
Qualifying them as a constant, means that they will be placed into rodata
section. Not into the text section where they "belong".