const volatile objects are not stored in .rodata
I often use const data tables that may be changed by a configuration process at runtime. Depending on how these tables are used, it is sometimes necessary to make them volatile so that accesses to the values are not replaced by the use of inline constant values during optimisation.
However, these tables are unexpectedly placed in the .data RAM section - which is not the case when they are simply const, when they are, as expected, placed in the .rodata FLASH section.
static const T table1[]; // This is placed in .rodata
static const volatile T table2[]; // This is placed in .dataAfter a bit of research, I found that this behaviour does not agree with that in Clang/LLVM. See:
A patch was added to GCC to bring its behaviour in line with that of Clang. However, it appears as if the current version of GCC used by the STM32CubeIDE (V.1.15.1) is too old for this to have been included.
It is easy enough to use an attribute as a work-around:
static const volatile T table3[] __attribute__((section( ".rodata" ))); // This is placed in .rodatabut I thought it was worth mentioning here in case anyone else runs into this and to warn of a potential change in behaviour when the supported version of GCC changes.
