AnsweredAssumed Answered

IAR compiler is removing "unused" sections

Question asked by Ryan Lush on Jan 25, 2018
Latest reply on Jan 25, 2018 by Mark Butcher

I have a linker script setup like so

 

define symbol m_interrupts_start       = 0x00000000;
define symbol m_interrupts_end         = 0x000003FF;

 

define symbol m_flash_config_start     = 0x00000400;
define symbol m_flash_config_end       = 0x0000040F;

 

define symbol m_boottable_start           = 0x00000410;
define symbol m_boottable_end           = 0x000004FF;

 

define symbol m_text_start             = 0x00000500;
define symbol m_text_end               = 0x000FFFFF;

 

define symbol m_data_start             = 0x1FFF0000;
define symbol m_data_end               = 0x1FFFFFFF;

 

define symbol m_data_2_start           = 0x20000000;
define symbol m_data_2_end             = 0x2002FFFF;

 


/* Sizes */
if (isdefinedsymbol(__stack_size__)) {
  define symbol __size_cstack__        = __stack_size__;
} else {
  define symbol __size_cstack__        = 0x8000;
}

 

if (isdefinedsymbol(__heap_size__)) {
  define symbol __size_heap__          = __heap_size__;
} else {
  define symbol __size_heap__          = 0x4000;
}

 

define memory mem with size = 4G;
define region m_flash_config_region = mem:[from m_flash_config_start to m_flash_config_end];
define region TEXT_region = mem:[from m_interrupts_start to m_interrupts_end]
                          | mem:[from m_text_start to m_text_end];
define region DATA_region = mem:[from m_data_start to m_data_end];
define region CSTACK_region = mem:[from m_data_end-__size_cstack__+1 to m_data_end];
define region m_boottable_region = mem:[from m_boottable_start to m_boottable_end];

 

define block CSTACK    with alignment = 8, size = __size_cstack__   { };
define block HEAP      with alignment = 8, size = __size_heap__     { };
define block RW        { readwrite };
define block ZI        { zi };

 

initialize by copy { readwrite, section .textrw };
do not initialize  { section .noinit };

 

place at address mem: m_interrupts_start    { readonly section .intvec };
place at address mem: m_boottable_start     { readonly section .boottable };
place in m_flash_config_region              { section FlashConfig };
place in TEXT_region                        { readonly };
place in DATA_region                        { block RW };
place in DATA_region                        { block ZI };
place in DATA_region                        { last block HEAP };
place in CSTACK_region                      { block CSTACK };

 

 

and then in my code I have a function table like so

 

#pragma location=".boottable"
BootFunctionTable_t bootFunctions =
{
    MAJOR_REVISION,
    MINOR_REVISION,
    BootUsbInit,
    BootUsbDeinit,
    BootUsbWrite,
    BootUsbRead,
    BootUsbAttached,
    BootExitToApp,
    BootJump,
    BootGetCRC,
    BootEncrypt,
    BootDecrypt,
    BootReset,
    BootGetTickCount,
    BootSleep,
};

 

BootFunctionTable_t * bootTable = (BootFunctionTable_t *)BOOT_TABLE; // BOOT_TABLE = 0x410

 

but when I look at the binary image the vector table seems to spill out past the defined region and the boottable region is all zeros. When I look at the map file I see

 

*******************************************************************************
*** PLACEMENT SUMMARY
***

 

"A0":  place at 0x00000000 { ro section .intvec };
"P1":  place in [from 0x00000400 to 0x0000040f] { section FlashConfig };
"P2":  place in [from 0x00000000 to 0x000003ff] |
                [from 0x00000500 to 0x000fffff] { ro };
define block RW { rw };
"P3":  place in [from 0x1fff0000 to 0x1fffffff] { block RW };
define block ZI { zi };
"P4":  place in [from 0x1fff0000 to 0x1fffffff] { block ZI };
define block CSTACK with size = 32K, alignment = 8 { };
"P6":  place in [from 0x1fff8000 to 0x1fffffff] { block CSTACK };
initialize by copy { rw, section .textrw };

 

No sections matched the following patterns:

 

  ro section .boottable  in "A1"

 

Why is there no section matching .boottable? Is this an optimization thing?

Outcomes