diff --git a/ports/atmel-samd/boards/common.template.ld b/ports/atmel-samd/boards/common.template.ld index 53c4cf5eec..b5faf7f458 100644 --- a/ports/atmel-samd/boards/common.template.ld +++ b/ports/atmel-samd/boards/common.template.ld @@ -27,8 +27,12 @@ SECTIONS . = ALIGN(4); _sfixed = .; KEEP(*(.vectors)) /* isr vector table */ - *(.text) /* .text sections (code) */ - *(.text*) /* .text* sections (code) */ + + /* Sort text sections so that they have fewer *fill* bytes needed. */ + *SORT_BY_ALIGNMENT(SORT_BY_NAME(.text)) /* .text sections (code) */ + *SORT_BY_ALIGNMENT(SORT_BY_NAME(.text*)) /* .text* sections (code) */ + + /* Don't sort rodata because it impacts codegen size. */ *(.rodata) /* .rodata sections (constants, strings, etc.) */ *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ @@ -62,8 +66,8 @@ SECTIONS _srelocate = .; /* create a global symbol at data start; used by startup code in order to initialize the .data section in RAM */ *(.ramfunc) *(.ramfunc*) - *(.data) /* .data sections */ - *(.data*) /* .data* sections */ + *SORT_BY_ALIGNMENT(SORT_BY_NAME(.data)) /* .data sections */ + *SORT_BY_ALIGNMENT(SORT_BY_NAME(.data*)) /* .data* sections */ . = ALIGN(4); _erelocate = .; /* define a global symbol at data end; used by startup code in order to initialize the .data section in RAM */ @@ -76,7 +80,7 @@ SECTIONS _sbss = .; _szero = .; /* define a global symbol at bss start; used by startup code */ *(.bss) - *(.bss*) + *SORT_BY_ALIGNMENT(SORT_BY_NAME(.bss*)) *(COMMON) . = ALIGN(4);