rust-embedded/cortex-m

More-helpful linker errors

tomhampshire opened this issue · 2 comments

Having just debugged an issue, it is clear that it would have helped me if the following asserts gave some clear information as to why/how "The .text section must be placed inside the FLASH memory.". For example, add to this: "It is likely that this is failing because you are using more FLASH than you actually have"

/* ## .text */
ASSERT(ADDR(.vector_table) + SIZEOF(.vector_table) <= _stext, "
ERROR(cortex-m-rt): The .text section can't be placed inside the .vector_table section
Set _stext to an address greater than the end of .vector_table (See output of `nm`)");
ASSERT(_stext + SIZEOF(.text) < ORIGIN(FLASH) + LENGTH(FLASH), "
ERROR(cortex-m-rt): The .text section must be placed inside the FLASH memory.
Set _stext to an address smaller than 'ORIGIN(FLASH) + LENGTH(FLASH)'");

Errors as it looks today:

  = note: rust-lld: error: 
          ERROR(cortex-m-rt): The .text section must be placed inside the FLASH memory.
          Set _stext to an address smaller than 'ORIGIN(FLASH) + LENGTH(FLASH)'
          
          rust-lld: error: 
          ERROR(cortex-m-rt): The .text section must be placed inside the FLASH memory.
          Set _stext to an address smaller than 'ORIGIN(FLASH) + LENGTH(FLASH)'
          
          rust-lld: error: 
          ERROR(cortex-m-rt): The .text section must be placed inside the FLASH memory.
          Set _stext to an address smaller than 'ORIGIN(FLASH) + LENGTH(FLASH)'

Thanks for reporting this.

I think we should change this assert to just check that _stext is inside FLASH without checking the whole of .text fits, and leave that check to the linker instead (which will give a better error message).

Something like:

 ASSERT(_stext > ORIGIN(FLASH) && _stext < ORIGIN(FLASH) + LENGTH(FLASH), " 
 ERROR(cortex-m-rt): The .text section must be placed inside the FLASH memory. 
 Set _stext to an address inside the FLASH region.'");