On 10/01/13 19:32, Marcin S wrote: > Hello, > > I have a program for ARM microcontroller (barebone STM32). Default > linker script puts all global const variables in .text block, which is > later loaded into flash memory of the cpu. Processor I am using have > an ability to change contents of flash on the fly, what I want to > achieve is to read const variable from flash, that might been changed > from other location of the program. (...) > And this works well, but only with disabled optimizations -O0, > however, with -O1+ it all gets "eaten" into simple printf("NOT > CHANGED) because variable is constant and under normal circumstances > result is always the same. > I have tried various tricks to avoid optimizing of that varaible, and > some are working, but I don't like it and it gives me no guarantee it > will work in the future. > > Is there any way to ensure this variable allocation in .text as it's > in source file (other then expilicitly disabling optimization for unit > it is defined in)? > > Marcin > I think you could use __attribute__ ((section (".text"))) to get the same effect without marking it as const (which is what guides the optimizations).