gcc linker to combine memory blocks into one sector

900 views Asked by At

Is there a way for the gnu linker to combine memory blocks so the linker will use one sector name when assigning memory?

For example:

MEMORY
{
  RAM1 (xrw)               : ORIGIN = 0x20000480, LENGTH = 0x0BB80  
  RAM2 (xrw)              : ORIGIN = 0x2001C000, LENGTH = 0x03C00
}

Can there be a memory block our sector that includes memory blocks RAM1 and RAM2? Something like this below:

.bss : 
{
    _bss_start = .;
    *(.bss)
    *(.bss.*)
    *(COMMON)
    _bss_end = .;
} >RAM >RAM1
1

There are 1 answers

0
Tijs Maas On

Good question. There are multiple ways of to do this. One way would be to actually split the BSS section by selecting which file's BSS goes where.

MEMORY
{
  RAM1 (xrw)               : ORIGIN = 0x20000480, LENGTH = 0x0BB80  
  RAM2 (xrw)              : ORIGIN = 0x2001C000, LENGTH = 0x03C00
}


SECTIONS
   {
           .bss1:
           {
                   f1.o
                   . =+ 0x200;
                   f2.o (.bss)
           } >RAM1
           .bss2:
           {
                   f3.o (.bss)
                   f4.o (.bss) = 0x1234
           } >RAM2
   }

Instead of doing this for each file (only useful if you have tiny RAM/ROM chips), I recommend to just place for example COMMON on RAM2, and .bss on RAM1.