Skip to content

Commit d5b4ec7

Browse files
committed
Fix GCC 12 infinite loop in strlen
Strlen was jumping to strlen as part of -ftree-loop-distribute-patterns. Seems this sort of issue can be common and generally fixed with -fno-builtin. However, some of those optimizations may be useful and I don't think our semantics for the functions are wildly different than the standard, so I'm fixing this surgically with -ftree-loop-distribute-patterns to just util.c. That may be the wrong call, so if this bites us again, let's go more aggressive. Fixes #660. Below are some filesizes for stm32f105/prod/floppy/target.bin with different compilers/branches that I trialed to get an idea of the impact of these optimizations. stable-v3: GCC 11: 83180 baseline GCC 11: 83180 util.c no-tree-loop-distribute-pattern GCC 11: 83180 util.c no-builtin GCC 11: 83200 all no-tree-loop-distribute-pattern GCC 11: 83336 all no-builtin GCC 12: 83500 baseline (broken) GCC 12: 83512 util.c no-tree-loop-distribute-pattern GCC 12: 83512 util.c no-builtin GCC 12: 83524 all no-tree-loop-distribute-pattern GCC 12: 83544 all no-builtin master: GCC 12: 89996 baseline (broken) GCC 12: 90008 util.c no-tree-loop-distribute-pattern GCC 12: 90020 util.c no-builtin GCC 12: 90020 all no-tree-loop-distribute-patterns GCC 12: 90064 all no-builtin
1 parent 317b347 commit d5b4ec7

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ endif
5252
.PHONY: $(SRCDIR)/build_info.c
5353
build_info.o: CFLAGS += -DFW_VER="\"$(FW_VER)\""
5454

55+
# Avoid infinite loops due to GCC noticing code that can be replaced by a call
56+
# to a standard library function... within our implementation of that function.
57+
util.o: CFLAGS += -fno-tree-loop-distribute-patterns
58+
5559
ff_cfg_defaults.h: $(ROOT)/examples/FF.CFG
5660
$(PYTHON) $(ROOT)/scripts/mk_config.py $< $@
5761

0 commit comments

Comments
 (0)