Skip to contentSkip to conversation

add a config option for -Os

PATCH In review Adrian Bunk 3 participants 3 messages Aug 25, 2003 – Aug 26, 2003

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 add a config option for -Os

The patch below adds a config option for compiling the kernel with -Os.

Compared to the last patch, the option moved to the embedded to the General Setup menu and depends on EXPERIMENTAL instead of EMBEDDED (retionale: it might even produce a faster kernel but it's less tested).

I removed the special cases in the arm, arm26 and h8300 Makefiles, users on these architectures can now use OPTIMIZE_FOR_SIZE.

Compiling with this option enabled produced a working kernel for me on i386.

cu
Adrian

init/Kconfig renamed from init/Kconfig.old +9 -0
@@ -48,6 +48,15 @@
 
 menu "General setup"
 
+config OPTIMIZE_FOR_SIZE
+	bool "Optimize for size" if EXPERIMENTAL
+	default n
+	help
+	  Enabling this option will pass "-Os" instead of "-O2" to gcc
+	  resulting in a smaller kernel.
+
+	  If unsure, say N.
+
 config SWAP
 	bool "Support for paging of anonymous memory"
 	depends on MMU
Makefile renamed from Makefile.old +7 -1
@@ -223,7 +223,7 @@
 NOSTDINC_FLAGS  = -nostdinc -iwithprefix include
 
 CPPFLAGS	:= -D__KERNEL__ -Iinclude
-CFLAGS 		:= -Wall -Wstrict-prototypes -Wno-trigraphs -O2 \
+CFLAGS 		:= -Wall -Wstrict-prototypes -Wno-trigraphs \
 	  	   -fno-strict-aliasing -fno-common
 AFLAGS		:= -D__ASSEMBLY__
 
@@ -318,6 +318,12 @@
 
 -include .config.cmd
 
+ifdef CONFIG_OPTIMIZE_FOR_SIZE
+CFLAGS		+= -Os
+else
+CFLAGS		+= -O2
+endif
+
 ifndef CONFIG_FRAME_POINTER
 CFLAGS		+= -fomit-frame-pointer
 endif
arch/arm26/Makefile renamed from arch/arm26/Makefile.old +0 -1
@@ -13,7 +13,6 @@
 OBJCOPYFLAGS	:=-O binary -R .note -R .comment -S
 GZFLAGS		:=-9
 #CFLAGS		+=-pipe
-CFLAGS		:=$(CFLAGS:-O2=-Os)
 
 ifeq ($(CONFIG_FRAME_POINTER),y)
 CFLAGS		+=-fno-omit-frame-pointer -mno-sched-prolog
arch/arm/Makefile renamed from arch/arm/Makefile.old +0 -2
@@ -14,8 +14,6 @@
 GZFLAGS		:=-9
 #CFLAGS		+=-pipe
 
-CFLAGS		:=$(CFLAGS:-O2=-Os)
-
 ifeq ($(CONFIG_FRAME_POINTER),y)
 CFLAGS		+=-fno-omit-frame-pointer -mapcs -mno-sched-prolog
 endif
arch/h8300/Makefile renamed from arch/h8300/Makefile.old +1 -1
@@ -34,7 +34,7 @@
 ldflags-$(CONFIG_CPU_H8S)	:= -mh8300self
 
 CFLAGS += $(cflags-y)
-CFLAGS += -mint32 -fno-builtin -Os
+CFLAGS += -mint32 -fno-builtin
 CFLAGS += -g
 CFLAGS += -D__linux__
 CFLAGS += -DUTS_SYSNAME=\"uClinux\"
#1 lore raw

At Tue, 26 Aug 2003 00:47:17 +0200,

Quoted 7 lines · Adrian Bunk

The patch below adds a config option for compiling the kernel with -Os.

Compared to the last patch, the option moved to the embedded to the General Setup menu and depends on EXPERIMENTAL instead of EMBEDDED (retionale: it might even produce a faster kernel but it's less tested).

Quoted 6 lines

I removed the special cases in the arm, arm26 and h8300 Makefiles, users on these architectures can now use OPTIMIZE_FOR_SIZE.

Compiling with this option enabled produced a working kernel for me on i386.

An idea do not change -O2, and to add specification of -Os to with "OPTIMIZE_SIZE" ? If there are a few the ones, degradation of speed means.

vmlinux size of h8300

        -O2     -Os   -O2&-Os
.text  561200  554368  555088
.data   59148   58612   58868
.bss    45244   45260   45244

total 665592 658240 659200

Signature · 2 lines
Yoshinori Sato
<[email protected]>
#2 lore raw
Quoted 5 lines · Yoshinori Sato
        -O2     -Os   -O2&-Os
.text  561200  554368  555088
.data   59148   58612   58868
.bss    45244   45260   45244

total 665592 658240 659200

Note that specifying -O2 *and* -Os together is probably counter-productive.

'info gcc' says:

If you use multiple `-O' options, with or without level numbers,
the last such option is the one that is effective.

You might want to investigate why the 3rd column of numbers is different from both of the first two.