From 235c0fac5b1419b83f191501fe5f5f68d96f7ae0 Mon Sep 17 00:00:00 2001 From: Daniel Thompson Date: Sun, 5 Sep 2021 20:34:55 +0100 Subject: [PATCH] Use -fno-ipa-modref when building with gcc-11 (or later) As the large comment in the body of the patch, there are mistakes in the inline assembler fragments contained in the Nordic Softdevice header files. Fixing the problem is a bit fiddly so for now we'll simply work around the issue by disabling an optimization pass that was introduced in gcc-11. --- Makefile | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Makefile b/Makefile index 238dbb9..94f52b6 100644 --- a/Makefile +++ b/Makefile @@ -270,6 +270,18 @@ CFLAGS += -Wno-unused-parameter -Wno-expansion-to-defined # TinyUSB tusb_hal_nrf_power_event CFLAGS += -Wno-cast-function-type +# 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 + # Defined Symbol (MACROS) CFLAGS += -D__HEAP_SIZE=0 CFLAGS += -DCONFIG_GPIO_AS_PINRESET