From: Adrian Bunk <bunk@fs.tum.de>

Allow the kernel to be built with `-Os'.

It requires CONFIG_EMBEDDED.  This is to make it "hard to get at" because
one gcc version (3.2.x I think) from RH9 generates crashy kernels with this
option set.



 25-akpm/Makefile            |    8 +++++++-
 25-akpm/arch/arm/Makefile   |    2 --
 25-akpm/arch/h8300/Kconfig  |    4 ++++
 25-akpm/arch/h8300/Makefile |    2 +-
 25-akpm/init/Kconfig        |   13 +++++++++++++
 5 files changed, 25 insertions(+), 4 deletions(-)

diff -puN arch/arm/Makefile~gcc-Os-if-embedded arch/arm/Makefile
--- 25/arch/arm/Makefile~gcc-Os-if-embedded	Fri Nov  7 14:39:31 2003
+++ 25-akpm/arch/arm/Makefile	Fri Nov  7 14:39:31 2003
@@ -14,8 +14,6 @@ OBJCOPYFLAGS	:=-O binary -R .note -R .co
 GZFLAGS		:=-9
 #CFLAGS		+=-pipe
 
-CFLAGS		:=$(CFLAGS:-O2=-Os)
-
 ifeq ($(CONFIG_FRAME_POINTER),y)
 CFLAGS		+=-fno-omit-frame-pointer -mapcs -mno-sched-prolog
 endif
diff -puN arch/h8300/Kconfig~gcc-Os-if-embedded arch/h8300/Kconfig
--- 25/arch/h8300/Kconfig~gcc-Os-if-embedded	Fri Nov  7 14:39:31 2003
+++ 25-akpm/arch/h8300/Kconfig	Fri Nov  7 14:39:31 2003
@@ -5,6 +5,10 @@
 
 mainmenu "uClinux/h8300 (w/o MMU) Kernel Configuration"
 
+config H8300
+	bool
+	default y
+
 config MMU
 	bool
 	default n
diff -puN arch/h8300/Makefile~gcc-Os-if-embedded arch/h8300/Makefile
--- 25/arch/h8300/Makefile~gcc-Os-if-embedded	Fri Nov  7 14:39:31 2003
+++ 25-akpm/arch/h8300/Makefile	Fri Nov  7 14:39:31 2003
@@ -34,7 +34,7 @@ cflags-$(CONFIG_CPU_H8S)	:= -ms
 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\"
diff -puN init/Kconfig~gcc-Os-if-embedded init/Kconfig
--- 25/init/Kconfig~gcc-Os-if-embedded	Fri Nov  7 14:39:31 2003
+++ 25-akpm/init/Kconfig	Fri Nov  7 14:39:40 2003
@@ -196,6 +196,19 @@ config EPOLL
 
 source "drivers/block/Kconfig.iosched"
 
+config CC_OPTIMIZE_FOR_SIZE
+	bool "Optimize for size" if EMBEDDED
+	default y if ARM || H8300
+	default n
+	help
+	  Enabling this option will pass "-Os" instead of "-O2" to gcc
+	  resulting in a smaller kernel.
+
+	  WARNING: some versions of gcc may generate incorrect code with this
+	  option.  If problems are observed, a gcc upgrade may be needed.
+
+	  If unsure, say N.
+
 endmenu		# General setup
 
 
diff -puN Makefile~gcc-Os-if-embedded Makefile
--- 25/Makefile~gcc-Os-if-embedded	Fri Nov  7 14:39:31 2003
+++ 25-akpm/Makefile	Fri Nov  7 14:39:31 2003
@@ -275,7 +275,7 @@ NOSTDINC_FLAGS  = -nostdinc -iwithprefix
 CPPFLAGS        := -D__KERNEL__ -Iinclude \
 		   $(if $(KBUILD_SRC),-Iinclude2 -I$(srctree)/include)
 
-CFLAGS 		:= -Wall -Wstrict-prototypes -Wno-trigraphs -O2 \
+CFLAGS 		:= -Wall -Wstrict-prototypes -Wno-trigraphs \
 	  	   -fno-strict-aliasing -fno-common
 AFLAGS		:= -D__ASSEMBLY__
 
@@ -431,6 +431,12 @@ libs-y		:= $(libs-y1) $(libs-y2)
 # ---------------------------------------------------------------------------
 
 
+ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
+CFLAGS		+= -Os
+else
+CFLAGS		+= -O2
+endif
+
 ifndef CONFIG_FRAME_POINTER
 CFLAGS		+= -fomit-frame-pointer
 endif

_