build: add a config knob to enable gc-sections for all packages
authorAndre Heider <a.heider@gmail.com>
Fri, 3 Feb 2023 12:15:43 +0000 (13:15 +0100)
committerChristian Marangi <ansuelsmth@gmail.com>
Tue, 21 Mar 2023 17:28:23 +0000 (18:28 +0100)
This enables the linker's garbage collection for all packages which haven't
opted-out.

Signed-off-by: Andre Heider <a.heider@gmail.com>
config/Config-build.in
include/package.mk

index 8c81ef654cfe6021a0f5e1e5af943221b5632c05..f93ad37586c5a4c0339fe4e43159344d594f6e23 100644 (file)
@@ -144,6 +144,14 @@ menu "Global build settings"
                help
                  Adds -g3 to the CFLAGS.
 
+       config USE_GC_SECTIONS
+               bool
+               prompt "Dead code and data elimination for all packages (EXPERIMENTAL)"
+               help
+                 Places functions and data items into its own sections to use the linker's
+                 garbage collection capabilites.
+                 Packages can choose to opt-out via setting PKG_BUILD_FLAGS:=no-gc-sections
+
        config IPV6
                def_bool y
 
index 0fb947f035c21d3177cb5b99923b2739722fb8bc..687f74edc1cf1b7b82d0462b488e163056759512 100644 (file)
@@ -51,7 +51,7 @@ ifdef CONFIG_USE_MIPS16
     TARGET_CXXFLAGS += -mips16 -minterlink-mips16
   endif
 endif
-ifeq ($(call pkg_build_flag,gc-sections,0),1)
+ifeq ($(call pkg_build_flag,gc-sections,$(if $(CONFIG_USE_GC_SECTIONS),1,0)),1)
   TARGET_CFLAGS+= -ffunction-sections -fdata-sections
   TARGET_CXXFLAGS+= -ffunction-sections -fdata-sections
   TARGET_LDFLAGS+= -Wl,--gc-sections