From a16a330da54afd392252d7ea04139fd4702f48f8 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Mon, 15 Aug 2022 16:07:00 +1000 Subject: [PATCH] nrf,stm32: Don't enable debug info by default if LTO is on. It seems sometimes gcc with LTO will generate otherwise valid assembly listings that cause 'as' to error out when generating DWARF debug info; see https://sourceware.org/bugzilla/show_bug.cgi?id=29494 Therefore, don't enable -g by default if LTO is on. Enabling LTO=1 DEBUG=1 is still possible but may result in random errors at link time due to 'as' (the error in this case is "Error: unaligned opcodes detected in executable segment", and the only other easy workaround is CFLAGS+=-fno-jump-tables which may increase code size significantly). Follows on from fdfe4eca745dce5f20fb65a3c197006b9053999a --- ports/nrf/Makefile | 6 ++++-- ports/stm32/Makefile | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/ports/nrf/Makefile b/ports/nrf/Makefile index 23be4430f3..bc295cac80 100644 --- a/ports/nrf/Makefile +++ b/ports/nrf/Makefile @@ -138,12 +138,14 @@ LDFLAGS += -Wl,'--defsym=_fs_size=$(FS_SIZE)' endif #Debugging/Optimization -CFLAGS += -g # always include debug info in the ELF ifeq ($(DEBUG), 1) #ASMFLAGS += -g -gtabs+ -CFLAGS += -O0 +CFLAGS += -g -O0 LDFLAGS += -O0 else +ifneq ($(LTO), 1) +CFLAGS += -g # always include debug info in the ELF, unless LTO is on +endif CFLAGS += -Os -DNDEBUG LDFLAGS += -Os endif diff --git a/ports/stm32/Makefile b/ports/stm32/Makefile index 657524798c..14a93a5aa7 100644 --- a/ports/stm32/Makefile +++ b/ports/stm32/Makefile @@ -114,13 +114,15 @@ $(BUILD)/stm32_it.o $(BUILD)/pendsv.o: CFLAGS += -fno-lto endif # Debugging/Optimization -CFLAGS += -g # always include debug info in the ELF ifeq ($(DEBUG), 1) -CFLAGS += -DPENDSV_DEBUG +CFLAGS += -g -DPENDSV_DEBUG COPT ?= -Og # Disable text compression in debug builds MICROPY_ROM_TEXT_COMPRESSION = 0 else +ifneq ($(LTO), 1) +CFLAGS += -g # always include debug info in the ELF, unless LTO is on +endif COPT ?= -Os -DNDEBUG endif