What for linker read-only memory section exists?
I declared in linker script new memory region (ROM), defined as read only:
MEMORY { text (rx) : ORIGIN = 0, LENGTH = 128K /*data (rw!x) : ORIGIN = 0x800060, LENGTH = 0xffa0*/ data (rw!x) : ORIGIN = 0x800060, LENGTH = 0x7fa0 ROM (r) : ORIGIN = 0x808000, LENGTH = 0x7fff eeprom (rw!x) : ORIGIN = 0x810000, LENGTH = 64K fuse (rw!x) : ORIGIN = 0x820000, LENGTH = 1K lock (rw!x) : ORIGIN = 0x830000, LENGTH = 1K signature (rw!x) : ORIGIN = 0x840000, LENGTH = 1K }
Next, I put into it new section:
.XMEM : { *(.XMEM*) } > ROM
Everything is fine, my variables go where I wanted. I expected that read only memory section is read only, so every attempt to write something into it will result a linker error. So the test program:
#define XMEM __attribute__ ((section (".XMEM"))) XMEM int xx2; int XMEM xx3; int main() { xx2=10; xx3=xx2+1; }
Should not compile. But it compiles without any problems, warnings, errors, etc. I checked generated map file and everything is as I expected:
Name Origin Length Attributes text 0x00000000 0x00020000 xr data 0x00800060 0x00007fa0 rw !x ROM 0x00808000 0x00007fff r eeprom 0x00810000 0x00010000 rw !x fuse 0x00820000 0x00000400 rw !x lock 0x00830000 0x00000400 rw !x signature 0x00840000 0x00000400 rw !x *default* 0x00000000 0xffffffff "¦ .XMEM 0x00808000 0x6 *(.XMEM*) .XMEM 0x00808000 0x6 ksiazka.o 0x00808002 xx2 0x00808000 xx1 0x00808004 xx3
So what for is read only attribute? Or how I can force gcc to generate warnings/errors when attempt to read only memory section is performed?