From b86366e34eb4a1f85a1bbaaae602b74d2d4cd938 Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Fri, 21 Apr 2023 08:57:30 +0200 Subject: [PATCH] makefiles/toolchain: Fix incorrect assumptions on address space layout GCC 12 gives out of bounds warnings when the resulting address is out of bounds of what GCC assumes to be the valid address space. It seems that by default the address 0x0 is not considered valid (which would be a NULL pointer and typically not mapped in a userspace behind an MMU scenario), but in fact is valid on bare metal hardware. At least on AVR and MSP430 this needs to be set. On many Cortex M MCUs 0x0 is also a valid address (e.g. often the flash is mapped there), but seemingly for them `--param=min-pagesize=0` is already the default. In any case, it won't hurt to set it explicit for them as well. --- makefiles/arch/avr8.inc.mk | 7 ------- makefiles/toolchain/gnu.inc.mk | 7 +++++++ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/makefiles/arch/avr8.inc.mk b/makefiles/arch/avr8.inc.mk index d316264803..f94bd34ad3 100644 --- a/makefiles/arch/avr8.inc.mk +++ b/makefiles/arch/avr8.inc.mk @@ -41,10 +41,3 @@ endif OPTIONAL_CFLAGS_BLACKLIST += -Wformat-overflow OPTIONAL_CFLAGS_BLACKLIST += -Wformat-truncation OPTIONAL_CFLAGS_BLACKLIST += -gz - -ifeq ($(TOOLCHAIN),gnu) - # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523 - ifneq ($(findstring 12.,$(shell $(TARGET_ARCH)-gcc --version 2>/dev/null)),) - CFLAGS += --param=min-pagesize=0 - endif -endif diff --git a/makefiles/toolchain/gnu.inc.mk b/makefiles/toolchain/gnu.inc.mk index e3e10485b5..0be76867e9 100644 --- a/makefiles/toolchain/gnu.inc.mk +++ b/makefiles/toolchain/gnu.inc.mk @@ -32,3 +32,10 @@ endif # We use GDB for debugging include $(RIOTMAKE)/tools/gdb.inc.mk + +# Data address spaces starts at zero for all supported architectures. This fixes +# compilation at least on MSP430 and AVR. +# See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523 +ifeq ($(GCC_VERSION),12) + CFLAGS += --param=min-pagesize=0 +endif