This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

How to specify the order of sections in link command file?

Hi,

Below is the link command file. I want to put all r and rx code sections, like interrupt, text, const, init table at the beginning of CODE_DATA_MEMORY, then put all rw data sections behind code section. Now the problem is linking will fail. What is the problem? Why it fail? 

If move .cinit out of code_section, just use, 

.cinit                >       CODE_DATA_MEMORY

then the .cinit will be located behind of data_section, this is not what I want.

error #10247-D: creating output section ".cinit" without a SECTIONS specification

MEMORY
{
   CODE_DATA_MEMORY  : org = CODE_DATA_MEM_ADDR,     len = CODE_DATA_MEM_LEN
}

SECTIONS
{
   code_section :
   {
      *(.intvecs)
      *(.text)
      *(.const)
      *(.cinit)
   } > CODE_DATA_MEM_ADDR

   data_section :
   {
      bss_start = .;
      *(.bss)
      bss_end = .;
      
      *(.data)
      *(.cio)
      *(.sysmem)
      
      __stack_start = .;
      *(.stack)
      __stack_end = .;
      __STACK_SIZE = __stack_end - __stack_start + 1;
            
   } > CODE_DATA_MEMORY
}

  • Unfortunately, the only solution is to create two separate memory ranges.  All the initialized sections, like .text, go into one memory range.  All the uninitialized sections, like .data, go into the other memory range.

    For example ...

    MEMORY
    {
       /* Change to match your system */
       INITIALIZED     : o = 0x1000, l = 0x3000
       NOT_INITIALIZED : o = 0x4000, l = 0x3000
    }
    
    SECTIONS
    {
        .intvecs > INITIALIZED
        .text    > INITIALIZED
        .const   > INITIALIZED
        .cinit   > INITIALIZED
    
        .bss     > NOT_INITIALIZED, START(bss_start), END(bss_end)
        .data    > NOT_INITIALIZED
        .cio     > NOT_INITIALIZED
        .sysmem  > NOT_INITIALIZED
        .stack   > NOT_INITIALIZED, START(__stack_start), END(__stack_end)
    }
    
    /* Do not overwrite __STACK_SIZE that is created by default */
    __MY_STACK_SIZE = __stack_end - __stack_start + 1;

    Note the linker creates a symbol named __STACK_SIZE by default.  You are welcome to create a similar symbol, but it has to have a different name.

    If you want to make the INITIALIZED memory range just big enough to fit those sections ... Unfortunately, the only way to do it is with trial and error.  If you use this method, give it a bit more memory than absolutely required, so you have some room for the sections to get bigger.

    Thanks and regards,

    -George