From 73c128cf198edd1515a2d392ff05741dba047653 Mon Sep 17 00:00:00 2001 From: Stefan Kerkmann Date: Mon, 7 Feb 2022 22:11:16 +0100 Subject: [PATCH 1/2] [Core] Enable linker relaxation for AVR targets This can save some bytes for by using RJMP instructions to memory location that are +-2k relative to the current program counter position. Unfortunately this is only possible when LTO is disabled. --- platforms/avr/platform.mk | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/platforms/avr/platform.mk b/platforms/avr/platform.mk index 4d9cafaeef4a..621cd73ba20e 100644 --- a/platforms/avr/platform.mk +++ b/platforms/avr/platform.mk @@ -19,6 +19,12 @@ COMPILEFLAGS += -fdata-sections COMPILEFLAGS += -fpack-struct COMPILEFLAGS += -fshort-enums +# Linker relaxation is only possible if +# link time optimizations are not enabled. +ifeq ($(strip $(LTO_ENABLE)), no) + COMPILEFLAGS += -mrelax +endif + ASFLAGS += $(AVR_ASFLAGS) CFLAGS += $(COMPILEFLAGS) $(AVR_CFLAGS) @@ -28,7 +34,7 @@ CFLAGS += -fno-strict-aliasing CXXFLAGS += $(COMPILEFLAGS) CXXFLAGS += -fno-exceptions -std=c++11 -LDFLAGS +=-Wl,--gc-sections +LDFLAGS += -Wl,--gc-sections OPT_DEFS += -DF_CPU=$(F_CPU)UL From 32dfd75fb1802ae1548bc6b27327981dac49fcd8 Mon Sep 17 00:00:00 2001 From: Stefan Kerkmann Date: Mon, 7 Feb 2022 22:59:08 +0100 Subject: [PATCH 2/2] [Core] Use -mcall-prologues the save code size From GCC Manual: Functions prologues/epilogues are expanded as calls to appropriate subroutines. Code size is smaller. Small programs with few functions can increase in size, but QMK benefits from this as it is rather large. See: https://www.nongnu.org/avr-libc/user-manual/FAQ.html#faq_optflags --- platforms/avr/platform.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/platforms/avr/platform.mk b/platforms/avr/platform.mk index 621cd73ba20e..9f304d2e209d 100644 --- a/platforms/avr/platform.mk +++ b/platforms/avr/platform.mk @@ -18,6 +18,7 @@ COMPILEFLAGS += -ffunction-sections COMPILEFLAGS += -fdata-sections COMPILEFLAGS += -fpack-struct COMPILEFLAGS += -fshort-enums +COMPILEFLAGS += -mcall-prologues # Linker relaxation is only possible if # link time optimizations are not enabled.