Why does the linker script map the .text section at a different address depending on build?
I noticed that my .text section gets mapped at one of two different addresses depending on my build. In one instance the hex file had a small (8 byte) gap in it which was causing some issues with some hex file parsing that I do. I've since worked around that, but now I'm curious as to the root cause.
I've been able to reproduce the two different results by commenting out a single print statement. I'm not an expert with linkers so I was hoping someone could help:
- Explain why this might happen?
- Suggest what I could do to ensure no gap in the hex file
This is on an STM32F3, using the CubeMX generated System Workbench project. Here's the relevant part of the linked script (the .ld is unchanged from the auto generated one) and the relevant sections of the two resulting .map files.
/* Define output sections */
SECTIONS
{
/* The startup code goes first into FLASH */
.isr_vector :
{
. = ALIGN(4);
KEEP(*(.isr_vector)) /* Startup code */
. = ALIGN(4);
} >FLASH
/* The program code and other data goes into FLASH */
.text :
{
. = ALIGN(4);
*(.text) /* .text sections (code) */
*(.text*) /* .text* sections (code) */
*(.glue_7) /* glue arm to thumb code */
*(.glue_7t) /* glue thumb to arm code */
*(.eh_frame)
KEEP (*(.init))
KEEP (*(.fini))
. = ALIGN(4);
_etext = .; /* define a global symbols at end of code */
} >FLASH