From 73f40d8a2385543464d79d4461ab68eb56783d26 Mon Sep 17 00:00:00 2001 From: Solomon Peachy Date: Sun, 2 Jul 2023 20:43:01 -0400 Subject: build: Experimental LTO support, phase one * Only codecs and plugins are enabled * Only native builds (so far) * Only tested on xDuoo X3 (MIPS, monochrome) * opus & speex generate some warnings * Significant compile time impact Change-Id: I519b0d179631a54b2103cd67225bd5ec6ad3bd2f --- apps/plugins/plugins.make | 12 ++++++++++++ lib/rbcodec/codecs/codecs.make | 7 +++++++ lib/rbcodec/codecs/lib/libcodec.make | 5 +++++ tools/configure | 8 +++++++- 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/apps/plugins/plugins.make b/apps/plugins/plugins.make index b430bd2792..4a126f812c 100644 --- a/apps/plugins/plugins.make +++ b/apps/plugins/plugins.make @@ -37,6 +37,12 @@ PLUGINLIB_OBJ := $(PLUGINLIB_SRC:.c=.o) PLUGINLIB_OBJ := $(PLUGINLIB_OBJ:.S=.o) PLUGINLIB_OBJ := $(call full_path_subst,$(ROOTDIR)/%,$(BUILDDIR)/%,$(PLUGINLIB_OBJ)) +ifdef USE_LTO +# We do NOT want LTO on the GCC support file. +$(BUILDDIR)/apps/plugins/lib/gcc-support.o: PLUGINFLAGS += -fno-lto +$(BUILDDIR)/apps/plugins/plugin_crt0.o: PLUGINFLAGS += -fno-lto +endif + ### build data / rules ifndef APP_TYPE CONFIGFILE := $(FIRMDIR)/export/config/$(MODELNAME).h @@ -147,6 +153,12 @@ else endif PLUGINLDFLAGS += $(GLOBAL_LDOPTS) +ifdef USE_LTO + PLUGINFLAGS += -flto -fno-builtin -ffreestanding + PLUGINLDFLAGS += -flto -fno-builtin -ffreestanding + PLUGINLDFLAGS += -e plugin_start +endif + $(BUILDDIR)/%.rock: $(call PRINTS,LD $(@F))$(CC) $(PLUGINFLAGS) -o $(BUILDDIR)/$*.elf \ $(filter %.o, $^) \ diff --git a/lib/rbcodec/codecs/codecs.make b/lib/rbcodec/codecs/codecs.make index 27ba73ab3c..83dc784ee3 100644 --- a/lib/rbcodec/codecs/codecs.make +++ b/lib/rbcodec/codecs/codecs.make @@ -33,6 +33,13 @@ else endif CODECLDFLAGS += $(GLOBAL_LDOPTS) +ifdef USE_LTO + CODECLDFLAGS += -flto -fno-builtin -ffreestanding + CODECFLAGS += -flto -fno-builtin -ffreestanding + CODECLDFLAGS += -e __header +endif + + # the codec libraries include $(RBCODECLIB_DIR)/codecs/demac/libdemac.make include $(RBCODECLIB_DIR)/codecs/liba52/liba52.make diff --git a/lib/rbcodec/codecs/lib/libcodec.make b/lib/rbcodec/codecs/lib/libcodec.make index 0788dd6705..b197464528 100644 --- a/lib/rbcodec/codecs/lib/libcodec.make +++ b/lib/rbcodec/codecs/lib/libcodec.make @@ -23,6 +23,11 @@ ifneq ($(findstring sdl-sim, $(APP_TYPE)), sdl-sim) CODECLIBFLAGS += -ffunction-sections endif +ifdef USE_LTO +# We do NOT want LTO on the GCC support file +$(CODECDIR)/lib/codeclib.o: CODECLIBFLAGS += -fno-lto +endif + $(CODECDIR)/lib/%.o: $(RBCODECLIB_DIR)/codecs/lib/%.c $(SILENT)mkdir -p $(dir $@) $(call PRINTS,CC $(subst $(ROOTDIR)/,,$<))$(CC) \ diff --git a/tools/configure b/tools/configure index c58ce164ac..bf96bf0058 100755 --- a/tools/configure +++ b/tools/configure @@ -945,13 +945,14 @@ whichadvanced () { echo "" printf "Enter your developer options (press only enter when done)\n\ (D)EBUG, (L)ogf, Boot(c)hart, (S)imulator, (P)rofiling, (V)oice, (U)SB Serial, (W)in32 crosscompile,\n\ -Win(6)4 crosscompile, (T)est plugins, (O)mit plugins, S(m)all C lib, Logf to Ser(i)al port:" +Win(6)4 crosscompile, (T)est plugins, (O)mit plugins, S(m)all C lib, Logf to Ser(i)al port, LTO (B)uild " if [ "$modelname" = "iaudiom5" ]; then printf ", (F)M radio MOD" fi if [ "$modelname" = "iriverh120" ]; then printf ", (R)TC MOD" fi + printf ":" echo "" fi @@ -1043,6 +1044,10 @@ Win(6)4 crosscompile, (T)est plugins, (O)mit plugins, S(m)all C lib, Logf to Ser win32crosscompile="yes" win64="yes" ;; + [Bb]) + echo "LTO build enabled" + LTO_ARG="export USE_LTO=y" + ;; "") # Match enter press when finished with advanced options cont=0 ;; @@ -4806,6 +4811,7 @@ export ANDROID_PLATFORM_VERSION=${ANDROID_PLATFORM_VERSION} export TOOLSET=${toolset} export PIPER_MODEL_DIR=${PIPER_MODEL_DIR} $CCACHE_ARG +$LTO_ARG CONFIGURE_OPTIONS=${cmdline} -- cgit v1.2.3