Skip to content

Commit 235c0fa

Browse files
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.
1 parent f82d1bc commit 235c0fa

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,18 @@ CFLAGS += -Wno-unused-parameter -Wno-expansion-to-defined
270270
# TinyUSB tusb_hal_nrf_power_event
271271
CFLAGS += -Wno-cast-function-type
272272

273+
# Nordic Softdevice SDK header files contains inline assembler that has
274+
# broken constraints. As a result the IPA-modref pass, introduced in gcc-11,
275+
# is able to "prove" that arguments to wrapper functions generated with
276+
# the SVCALL() macro are unused and, as a result, the optimizer will remove
277+
# code within the callers that sets up these arguments (which results in
278+
# a broken bootloader). The broken headers come from Nordic-supplied zip
279+
# files and are not trivial to patch so, for now, we'll simply disable the
280+
# new gcc-11 inter-procedural optimizations.
281+
ifeq (,$(findstring unrecognized,$(shell $(CC) $(CFLAGS) -fno-ipa-modref 2>&1)))
282+
CFLAGS += -fno-ipa-modref
283+
endif
284+
273285
# Defined Symbol (MACROS)
274286
CFLAGS += -D__HEAP_SIZE=0
275287
CFLAGS += -DCONFIG_GPIO_AS_PINRESET

0 commit comments

Comments
 (0)