I have built the CodeSourcery ARM compiler (2008q3). I have a linker script for the STM32 with the following sections:
MEMORY { FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 128K RAM (xrw): ORIGIN = 0x20000000, LENGTH = 20K } SECTIONS { .isr_vector : { . = ALIGN(4); KEEP(*(.isr_vector)) . = ALIGN(4); } >FLASH .text : { . = ALIGN(4); *(.text) *(.text.*) *(.rodata) *(.rodata*) . = ALIGN(4); _etext = .; } >FLASH .data : AT ( _etext ) { . = ALIGN(4); _sdata = .; *(.data) *(.data.*) . = ALIGN(4); _edata = .;
} >RAM .bss : { . = ALIGN(4); _sbss = .; *(.bss) *(COMMON) . = ALIGN(4); _ebss = .; } >RAM }
When I build my application, I create the binary image with
arm-eabi-objcopy -O binary main.elf main.bin
That creates a binary that is 400M in size. Presumably because (0x20000000-0x08000000) is about that size.
The problem seems to occur when there is nothing in the .data section. Possibly because it is being thrown out by the linker. I found some stuff in the ld manual that suggests that, if I change the .data section to this:
.data : AT ( _etext ) { . = ALIGN(4); _sdata = .; KEEP(*(.data)) KEEP(*(.data.*)) . = ALIGN(4); _edata = .; } >RAM
all will be OK in the world. or, at least, my tiny part of it.
Does that sound right? Is this the 'proper' thing to do? there is also mention of the --gc-sections option for the linker. Would it be simpler not to use this?