diff --git a/arch/avr/src/avr/Kconfig b/arch/avr/src/avr/Kconfig index 1baf8d6dd74..35bd611e981 100644 --- a/arch/avr/src/avr/Kconfig +++ b/arch/avr/src/avr/Kconfig @@ -57,6 +57,26 @@ config AVR_BUILDROOT_TOOLCHAIN endchoice # Toolchain +config AVR_LINUXGCC_TOOLCHAIN_IS_GCC + bool "Mark the toolchain as a GCC toolchain" + default n + depends on AVR_LINUXGCC_TOOLCHAIN + select ARCH_TOOLCHAIN_GCC + ---help--- + This option marks the toolchain as a GCC toolchain. Enabling + this will in turn enable other configuration option. Among + them, there is DEBUG_OPT_UNUSED_SECTIONS which will instruct + the compiler and linker to remove unused sections from the final + binary, saving flash space. + + There is, however, a catch to this. Linker script for the board + in use must mark unreferenced sections as "KEEP". Most notably, + this applies to .vectors section which is not referenced anywhere + but must be present. If not marked to be kept, the resulting + binary will be faulty. + + Consult linker script of your board before enabling this option. + config AVR_HAS_MEMX_PTR bool "Enable in-flash static const strings" depends on AVR_ATMEL_AVR_TOOLCHAIN || AVR_LINUXGCC_TOOLCHAIN diff --git a/arch/avr/src/avr/Toolchain.defs b/arch/avr/src/avr/Toolchain.defs index 511de17b576..c3ce2ef04ea 100644 --- a/arch/avr/src/avr/Toolchain.defs +++ b/arch/avr/src/avr/Toolchain.defs @@ -90,6 +90,13 @@ else ifeq ($(CONFIG_DEBUG_FULLOPT),y) ARCHOPTIMIZATION += -O2 endif +# Optimization of unused sections + +ifeq ($(CONFIG_DEBUG_OPT_UNUSED_SECTIONS),y) + LDFLAGS += --gc-sections + ARCHOPTIMIZATION += -ffunction-sections -fdata-sections +endif + ifneq ($(CONFIG_DEBUG_NOOPT),y) ARCHOPTIMIZATION += -fno-strict-aliasing endif