I have to place array at specific address in memory. I'm using GCC.
I declare variable like this:
uint8_t __attribute__((section (".mySection"))) buffer[1234];
And in linker script I've got:
MEMORY { FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 1024K RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 145K MYSEC (x) : ORIGIN = 0x20025000, LENGTH = 155K }
and later:
.mySection : { *(.mySection); } > MYSEC
It's of course code for embedded system (ARM). Normally my program takes 22 KB, with this modification it takes 384 MB (!).
I don't understand why. If I remove __attribute__
it takes 22 KB again. What am I missing?
Code used:
#inculde (...) uint8_t __attribute__((section (".mySection"))) buffer = 5; int main(void){ buffer = 10; }
Full linker script (default, not written by me, parts are shortened:
/* Entry Point */ ENTRY(Reset_Handler) /* Highest address of the user mode stack */ _estack = 0x20050000; /* end of RAM */ /* Generate a link error if heap and stack don't fit into RAM */ _Min_Heap_Size = 0x200; /* required amount of heap */ _Min_Stack_Size = 0x400; /* required amount of stack */ /* Specify the memory areas */ MEMORY { FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 1024K RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 145K MYSEC (x) : ORIGIN = 0x20025000, LENGTH = 155K } /* Define output sections */ SECTIONS { /* The startup code goes first into FLASH */ .isr_vector : { (...) } >FLASH /* The program code and other data goes into FLASH */ .text : { (...) } >FLASH /* Constant data goes into FLASH */ .rodata : { (...) } >FLASH .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH .ARM : { (...) } >FLASH .preinit_array : { (...) } >FLASH .init_array : { (...) } >FLASH .fini_array : { (...) } >FLASH /* used by the startup to initialize data */ _sidata = LOADADDR(.data); /* Initialized data sections goes into RAM, load LMA copy after code */ .data : { (...) } >RAM AT> FLASH .mySection : { *(.mySection); } > MYSEC /* Uninitialized data section */ . = ALIGN(4); .bss : { (...) } >RAM /* User_heap_stack section, used to check that there is enough RAM left */ ._user_heap_stack : { (...) } >RAM /* Remove information from the standard libraries */ /DISCARD/ : { (...) } .ARM.attributes 0 : { *(.ARM.attributes) } }