From f2de010059c526b2d989f3a6da7b5c0c2444999e Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Wed, 8 Sep 2021 12:44:45 -0700 Subject: [PATCH] Fix the nRF builds with GCC 11.2 See adafruit/Adafruit_nRF52_Bootloader#221 for background on the flag. --- ports/nrf/Makefile | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ports/nrf/Makefile b/ports/nrf/Makefile index 66cf4e2008..01050324f5 100755 --- a/ports/nrf/Makefile +++ b/ports/nrf/Makefile @@ -103,6 +103,18 @@ CFLAGS += $(OPTIMIZATION_FLAGS) CFLAGS += $(INC) -Wall -Werror -std=gnu11 -nostdlib -fshort-enums $(BASE_CFLAGS) $(CFLAGS_MOD) $(COPT) +# Nordic Softdevice SDK header files contains inline assembler that has +# broken constraints. As a result the IPA-modref pass, introduced in gcc-11, +# is able to "prove" that arguments to wrapper functions generated with +# the SVCALL() macro are unused and, as a result, the optimizer will remove +# code within the callers that sets up these arguments (which results in +# a broken bootloader). The broken headers come from Nordic-supplied zip +# files and are not trivial to patch so, for now, we'll simply disable the +# new gcc-11 inter-procedural optimizations. +ifeq (,$(findstring unrecognized,$(shell $(CC) $(CFLAGS) -fno-ipa-modref 2>&1))) +CFLAGS += -fno-ipa-modref +endif + # Undo some warnings. # nrfx does casts that increase alignment requirements. CFLAGS += -Wno-cast-align