[PATCH] build system: allow users to select the optimization level

Bartosz Golaszewski bartekgola at gmail.com
Wed Apr 15 10:15:34 UTC 2015


In some scenarios busybox performance may be prefered over its
small size.

Allow users to select the compiler optimization level by adding
appropriate config options.

Signed-off-by: Bartosz Golaszewski <bartekgola at gmail.com>
---
 Config.in      | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 Makefile.flags | 16 ++++++++++------
 2 files changed, 60 insertions(+), 6 deletions(-)

diff --git a/Config.in b/Config.in
index 07b4bf3..9a237b9 100644
--- a/Config.in
+++ b/Config.in
@@ -514,6 +514,56 @@ config PIE
 
 	  Most people will leave this set to 'N'.
 
+choice
+	prompt "Compiler optimization level"
+	default OPTIMIZE_S
+	help
+	  Set the optimization level for the compiler.
+
+config OPTIMIZE_S
+	bool "Optimize for size"
+	help
+	  Optimize for size. -Os enables all -O2 optimizations that do
+	  not typically increase code size. It also performs further
+	  optimizations designed to reduce code size.
+
+	  This is the default for busybox.
+
+config OPTIMIZE_0
+	bool "Optimization level 0"
+	help
+	  Don't optimize.
+
+	  Analogous to CONFIG_DEBUG_PESSIMIZE.
+
+config OPTIMIZE_1
+	bool "Optimization level 1"
+	help
+	  Optimize. Optimizing compilation takes somewhat more time,
+	  and a lot more memory for a large function.
+
+	  With -O1, the compiler tries to reduce code size and execution
+	  time, without performing any optimizations that take a great
+	  deal of compilation time.
+
+config OPTIMIZE_2
+	bool "Optimization level 2"
+	help
+	  Optimize even more. GCC performs nearly all supported
+	  optimizations that do not involve a space-speed tradeoff.
+
+	  As compared to -O, this option increases both compilation
+	  time and the performance of the generated code.
+
+config OPTIMIZE_3
+	bool "Optimization level 3"
+	help
+	  Optimize yet more. Enable full optimization as in -O2 and also
+	  use more aggressive automatic inlining of subprograms within
+	  a unit and attempt to vectorize loops.
+
+endchoice
+
 config NOMMU
 	bool "Force NOMMU build"
 	default n
diff --git a/Makefile.flags b/Makefile.flags
index a1ed148..c81a107 100644
--- a/Makefile.flags
+++ b/Makefile.flags
@@ -61,17 +61,21 @@ CFLAGS += $(call cc-option,-fno-asynchronous-unwind-tables,)
 # be fixed..
 #CFLAGS += $(call cc-option,-Wconversion,)
 
-ifneq ($(CONFIG_DEBUG),y)
-CFLAGS += $(call cc-option,-Os,$(call cc-option,-O2,))
-else
+ifeq ($(CONFIG_DEBUG),y)
 CFLAGS += $(call cc-option,-g,)
-#CFLAGS += "-D_FORTIFY_SOURCE=2"
-ifeq ($(CONFIG_DEBUG_PESSIMIZE),y)
+endif
+
+ifeq (y,$(filter y,$(CONFIG_DEBUG_PESSIMIZE) $(CONFIG_OPTIMIZE_0)))
 CFLAGS += $(call cc-option,-O0,)
+else ifeq ($(CONFIG_OPTIMIZE_1),y)
+CFLAGS += $(call cc-option,-O1,)
+else ifeq ($(CONFIG_OPTIMIZE_2),y)
+CFLAGS += $(call cc-option,-O2,)
+else ifeq ($(CONFIG_OPTIMIZE_3),y)
+CFLAGS += $(call cc-option,-O3,$(call cc-option,-O2,))
 else
 CFLAGS += $(call cc-option,-Os,$(call cc-option,-O2,))
 endif
-endif
 
 # If arch/$(ARCH)/Makefile did not override it (with, say, -fPIC)...
 ARCH_FPIC ?= -fpic
-- 
2.1.4



More information about the busybox mailing list