Hi,
i played a bit with GCC 5 and -flto.
It works good and leads to less flash usage.
Howto:
1) Edit linker file. Move the line "*(.startup*)"
below the line "KEEP(*(.flashconfig*))"
This alone leads to about 500 Bytes additional needed space, because these bytes are unused now.
Maybe we can place a table here or other short code.
[edit]
2)
comment out the follwowing lines in avr_functions.h (these functions are now in the library (i think since 4.9 (?) ) and not needed anymore)
3) Edit Boards.txt.
- Choose the arm-none-eabi-gcc-ar tool instead of arm-none-eabi-ar
- add the -flto flag
"Blink" is now reduced from 10.523 Bytes (o1) to 10.248 (plus we have still the ~500 unused bytes)
A larger sketch (about 70KB) was reduced by 3 KB
In addition gcc has some ARM CM4 Improvements for better codegeneration since Version 4.9
(One of them is -mslow-flash-data, i'm nt sure if it improves anything for us, i havn't tested it enough..)
i played a bit with GCC 5 and -flto.
It works good and leads to less flash usage.
Howto:
1) Edit linker file. Move the line "*(.startup*)"
below the line "KEEP(*(.flashconfig*))"
Code:
/* Teensyduino Core Library
* http://www.pjrc.com/teensy/
* Copyright (c) 2013 PJRC.COM, LLC.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* 1. The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* 2. If the Software is incorporated into a build system that allows
* selection among a list of target devices, then similar target
* devices manufactured by PJRC.COM must be included in the list of
* target devices and selectable in the same manner.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
MEMORY
{
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 256K
RAM (rwx) : ORIGIN = 0x1FFF8000, LENGTH = 64K
}
SECTIONS
{
.text : {
. = 0;
KEEP(*(.vectors))
/* TODO: does linker detect startup overflow onto flashconfig? */
. = 0x400;
KEEP(*(.flashconfig*))
*(.startup*)
*(.text*)
*(.rodata*)
. = ALIGN(4);
KEEP(*(.init))
. = ALIGN(4);
__preinit_array_start = .;
KEEP (*(.preinit_array))
__preinit_array_end = .;
__init_array_start = .;
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array))
__init_array_end = .;
} > FLASH = 0xFF
.ARM.exidx : {
__exidx_start = .;
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
__exidx_end = .;
} > FLASH
_etext = .;
.usbdescriptortable (NOLOAD) : {
/* . = ORIGIN(RAM); */
. = ALIGN(512);
*(.usbdescriptortable*)
} > RAM
.dmabuffers (NOLOAD) : {
. = ALIGN(4);
*(.dmabuffers*)
} > RAM
.usbbuffers (NOLOAD) : {
. = ALIGN(4);
*(.usbbuffers*)
} > RAM
.data : AT (_etext) {
. = ALIGN(4);
_sdata = .;
*(.fastrun*)
*(.data*)
. = ALIGN(4);
_edata = .;
} > RAM
.noinit (NOLOAD) : {
*(.noinit*)
} > RAM
.bss : {
. = ALIGN(4);
_sbss = .;
__bss_start__ = .;
*(.bss*)
*(COMMON)
. = ALIGN(4);
_ebss = .;
__bss_end = .;
__bss_end__ = .;
} > RAM
_estack = ORIGIN(RAM) + LENGTH(RAM);
}
This alone leads to about 500 Bytes additional needed space, because these bytes are unused now.
Maybe we can place a table here or other short code.
[edit]
2)
comment out the follwowing lines in avr_functions.h (these functions are now in the library (i think since 4.9 (?) ) and not needed anymore)
Code:
/*
static inline char * utoa(unsigned int val, char *buf, int radix) __attribute__((always_inline, unused));
static inline char * utoa(unsigned int val, char *buf, int radix) { return ultoa(val, buf, radix); }
static inline char * itoa(int val, char *buf, int radix) __attribute__((always_inline, unused));
static inline char * itoa(int val, char *buf, int radix) { return ltoa(val, buf, radix); }
*/
3) Edit Boards.txt.
- Choose the arm-none-eabi-gcc-ar tool instead of arm-none-eabi-ar
- add the -flto flag
Code:
teensy31.build.command.ar=arm-none-eabi-gcc-ar
teensy31.build.flags.common=-g -Wall -ffunction-sections -fdata-sections -nostdlib -flto
teensy31.build.flags.ld=-flto -Wl,--gc-sections,--relax,--defsym=__rtc_localtime={extra.time.local} "-T{build.core.path}/mk20dx256.ld"
"Blink" is now reduced from 10.523 Bytes (o1) to 10.248 (plus we have still the ~500 unused bytes)
A larger sketch (about 70KB) was reduced by 3 KB
In addition gcc has some ARM CM4 Improvements for better codegeneration since Version 4.9
(One of them is -mslow-flash-data, i'm nt sure if it improves anything for us, i havn't tested it enough..)
Last edited: