From c4f0860660631b24cece97bfe8ec2bea5b56f038 Mon Sep 17 00:00:00 2001 From: Tim Niemueller Date: Mon, 6 Mar 2017 17:02:44 +0100 Subject: [PATCH] Arduino.mk: make LTO optional, enabled by default On Fedora 25 with avr-gcc 6.2.0 LTO crashes, e.g., if Serial is used. --- Arduino.mk | 19 +++++++++++++++---- HISTORY.md | 1 + 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Arduino.mk b/Arduino.mk index 82b4964..89e8149 100644 --- a/Arduino.mk +++ b/Arduino.mk @@ -1039,9 +1039,17 @@ ifndef AR_NAME endif endif +ifeq ($(shell expr $(CC_VERNUM) '>' 490), 1) + USE_LTO ?= 1 +endif + + ifndef CFLAGS_STD ifeq ($(shell expr $(CC_VERNUM) '>' 490), 1) - CFLAGS_STD = -std=gnu11 -flto -fno-fat-lto-objects + CFLAGS_STD = -std=gnu11 + ifeq ($(USE_LTO),1) + CFLAGS_STD += -flto -fno-fat-lto-objects + endif else CFLAGS_STD = endif @@ -1052,7 +1060,10 @@ endif ifndef CXXFLAGS_STD ifeq ($(shell expr $(CC_VERNUM) '>' 490), 1) - CXXFLAGS_STD = -std=gnu++11 -fno-threadsafe-statics -flto + CXXFLAGS_STD = -std=gnu++11 -fno-threadsafe-statics + ifeq ($(USE_LTO),1) + CXXFLAGS_STD += -flto + endif else CXXFLAGS_STD = endif @@ -1064,11 +1075,11 @@ endif CFLAGS += $(CFLAGS_STD) CXXFLAGS += -fpermissive -fno-exceptions $(CXXFLAGS_STD) ASFLAGS += -x assembler-with-cpp -ifeq ($(shell expr $(CC_VERNUM) '>' 490), 1) +ifeq ($(USE_LTO), 1) ASFLAGS += -flto endif LDFLAGS += -$(MCU_FLAG_NAME)=$(MCU) -Wl,--gc-sections -O$(OPTIMIZATION_LEVEL) -ifeq ($(shell expr $(CC_VERNUM) '>' 490), 1) +ifeq ($(USE_LTO), 1) LDFLAGS += -flto -fuse-linker-plugin endif SIZEFLAGS ?= --mcu=$(MCU) -C diff --git a/HISTORY.md b/HISTORY.md index c772c04..2e1ebfe 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -7,6 +7,7 @@ I tried to give credit whenever possible. If I have missed anyone, kindly add it ### In Development - Fix: Do not include the Arduino header when calling generate_assembly on .cpp files. (https://github.com/Batchyx) - Fix: Auto-detect F_CPU on Teensy from boards.txt (https://github.com/DaWelter) +- Tweak: Allow to disable LTO (currently crashes on Fedora 25) ### 1.5.2 (2017-01-11)