]> git.ipfire.org Git - thirdparty/openwrt.git/commitdiff
tools: add options to optimize host binaries 18659/head
authorKonstantin Demin <rockdrilla@gmail.com>
Fri, 2 May 2025 20:47:01 +0000 (23:47 +0300)
committerChristian Marangi <ansuelsmth@gmail.com>
Sun, 4 May 2025 16:25:03 +0000 (18:25 +0200)
Mains goals are:
- reduce binary size of host tools;
- reduce i/o load on build host;
- increase performance of host tools being built.

Signed-off-by: Konstantin Demin <rockdrilla@gmail.com>
Link: https://github.com/openwrt/openwrt/pull/18659
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
config/Config-devel.in
rules.mk

index cbac91c09dacf16bb50afaef295921c0f905dfab..3fe78f325bcd5a2646026b0e62e92b3f4b382202 100644 (file)
@@ -62,6 +62,60 @@ menuconfig DEVEL
                  Compile all host host tools even if not needed. This is needed to prepare a
                  universal precompiled host tools archive to use in another buildroot.
 
+       menuconfig OPTIMIZE_HOST_TOOLS
+               bool "Host Tools compile options" if DEVEL
+
+               if OPTIMIZE_HOST_TOOLS
+
+               config HOST_FLAGS_OPT
+                       string "Host Tools optimization flags"
+                       default "-O2"
+                       help
+                         Compiler flags which are used to build host tools.
+
+                         E.g.: "-O2", "-O3 -fno-tree-vectorize".
+
+                         Default is "-O2".
+
+               config HOST_TOOLS_STRIP
+                       bool "Strip Host Tools"
+                       help
+                         Instructs compiler/linker to use flags from HOST_FLAGS_STRIP
+                         in order to reduce binary size of host tools.
+
+               config HOST_FLAGS_STRIP
+                       string "Host Tools compiler/linker flags for stripping symbols"
+                       depends on HOST_TOOLS_STRIP
+                       default "-Wl,-s"
+                       help
+                         Compiler flags which are used to strip symbols from host tools.
+
+                         Each flag should be prefixed with "-Wl," string
+                         because compiler (GCC) passes this value to linker.
+
+                         Default is "-Wl,-s" which means "strip all symbols" - specifically,
+                         debug symbols and other symbols not needed for relocation processing.
+
+               comment "Host Tools miscellaneous flags"
+
+               config HOST_EXTRA_CFLAGS
+                       string "Host Tools extra CFLAGS"
+                       default ""
+
+               config HOST_EXTRA_CXXFLAGS
+                       string "Host Tools extra CXXFLAGS"
+                       default ""
+
+               config HOST_EXTRA_CPPFLAGS
+                       string "Host Tools extra CPPFLAGS"
+                       default ""
+
+               config HOST_EXTRA_LDFLAGS
+                       string "Host Tools extra LDFLAGS"
+                       default ""
+
+               endif
+
        config BUILD_SUFFIX
                string "Build suffix to append to the target BUILD_DIR variable" if DEVEL
                default ""
index dbc448e1a432c92cd11b0af74ba6155a712da2b0..ccf97fe7b7bb9b5eefebd6b173ac1a7b6746f093 100644 (file)
--- a/rules.mk
+++ b/rules.mk
@@ -278,12 +278,19 @@ PKG_CONFIG:=$(STAGING_DIR_HOST)/bin/pkg-config
 
 export PKG_CONFIG
 
+HOST_FLAGS_OPT:=$(call qstrip,$(CONFIG_HOST_FLAGS_OPT))
+HOST_FLAGS_STRIP:=$(call qstrip,$(CONFIG_HOST_FLAGS_STRIP))
+HOST_EXTRA_CFLAGS:=$(call qstrip,$(CONFIG_HOST_EXTRA_CFLAGS))
+HOST_EXTRA_CXXFLAGS:=$(call qstrip,$(CONFIG_HOST_EXTRA_CXXFLAGS))
+HOST_EXTRA_CPPFLAGS:=$(call qstrip,$(CONFIG_HOST_EXTRA_CPPFLAGS))
+HOST_EXTRA_LDFLAGS:=$(call qstrip,$(CONFIG_HOST_EXTRA_LDFLAGS))
+
 HOSTCC:=$(STAGING_DIR_HOST)/bin/gcc
 HOSTCXX:=$(STAGING_DIR_HOST)/bin/g++
-HOST_CPPFLAGS:=-I$(STAGING_DIR_HOST)/include $(if $(IS_PACKAGE_BUILD),-I$(STAGING_DIR_HOSTPKG)/include -I$(STAGING_DIR)/host/include)
-HOST_CFLAGS:=-O2 $(HOST_CPPFLAGS)
-HOST_CXXFLAGS:=$(HOST_CFLAGS)
-HOST_LDFLAGS:=-L$(STAGING_DIR_HOST)/lib $(if $(IS_PACKAGE_BUILD),-L$(STAGING_DIR_HOSTPKG)/lib -L$(STAGING_DIR)/host/lib)
+HOST_CPPFLAGS:=$(strip -I$(STAGING_DIR_HOST)/include $(if $(IS_PACKAGE_BUILD),-I$(STAGING_DIR_HOSTPKG)/include -I$(STAGING_DIR)/host/include) $(HOST_EXTRA_CPPFLAGS))
+HOST_CFLAGS:=$(strip $(HOST_FLAGS_OPT) $(HOST_EXTRA_CFLAGS) $(HOST_CPPFLAGS) $(HOST_FLAGS_STRIP))
+HOST_CXXFLAGS:=$(strip $(HOST_CFLAGS) $(HOST_EXTRA_CXXFLAGS))
+HOST_LDFLAGS:=$(strip -L$(STAGING_DIR_HOST)/lib $(if $(IS_PACKAGE_BUILD),-L$(STAGING_DIR_HOSTPKG)/lib -L$(STAGING_DIR)/host/lib) $(HOST_EXTRA_LDFLAGS) $(HOST_FLAGS_STRIP))
 
 BUILD_KEY=$(TOPDIR)/key-build
 BUILD_KEY_APK_SEC=$(TOPDIR)/private-key.pem