diff options
| author | Angus Gratton <gus@projectgus.com> | 2022-06-07 17:34:40 +1000 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2022-06-28 10:31:32 +1000 |
| commit | e76d88b531ec42a75833800d04962e0dc660cef0 (patch) | |
| tree | c08be861d7373e3d77befc4420452f88cba2126c | |
| parent | 2c015375d1e795b4c1a996e50b27234e07f3f638 (diff) | |
stm32/Makefile: Enable link-time-optimisation via LTO=1 make option.
When tested, this reduces default MP binary sizes by approx 2-2.5%, and
very marginally increases performance in benchmarks. Build times seem very
similar to non-LTO when using gcc 12.
See #8733 for further discussion.
Signed-off-by: Angus Gratton <gus@projectgus.com>
| -rw-r--r-- | ports/stm32/Makefile | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/ports/stm32/Makefile b/ports/stm32/Makefile index 5cde84e67..53d1bb4ac 100644 --- a/ports/stm32/Makefile +++ b/ports/stm32/Makefile @@ -96,13 +96,22 @@ CFLAGS += -fsingle-precision-constant endif endif -LDFLAGS = -nostdlib -L $(LD_DIR) $(addprefix -T,$(LD_FILES)) -Map=$(@:.elf=.map) --cref -LDFLAGS += --defsym=_estack_reserve=8 +LDFLAGS = -nostdlib -L $(LD_DIR) $(addprefix -T,$(LD_FILES)) -Wl,-Map=$(@:.elf=.map) -Wl,--cref +LDFLAGS += -Wl,--defsym=_estack_reserve=8 LIBS += "$(shell $(CC) $(CFLAGS) -print-libgcc-file-name)" # Remove uncalled code from the final image. CFLAGS += -fdata-sections -ffunction-sections -LDFLAGS += --gc-sections +LDFLAGS += -Wl,--gc-sections + +ifeq ($(LTO),1) +CFLAGS += -flto=auto +# LTO requires passing compiler flags to the linker as it will run the assembler. +# To avoid risk of missing something relevant, pass all flags except for preprocessor args +LDFLAGS += $(filter-out -I%,$(filter-out -D%,$(CFLAGS))) + +$(BUILD)/stm32_it.o $(BUILD)/pendsv.o: CFLAGS += -fno-lto +endif # Debugging/Optimization ifeq ($(DEBUG), 1) @@ -592,7 +601,7 @@ endef define GENERATE_ELF $(ECHO) "LINK $(1)" - $(Q)$(LD) $(LDFLAGS) -o $(1) $(2) $(LDFLAGS_MOD) $(LIBS) + $(Q)$(CC) $(LDFLAGS) -o $(1) $(2) $(LDFLAGS_MOD) $(LIBS) $(Q)$(SIZE) $(1) $(if $(filter-out $(TEXT0_ADDR),0x08000000), \ $(ECHO) "INFO: this build requires mboot to be installed first") |
