Re: [2.6 patch] add a config option for -Os compilation

From: Adrian Bunk
Date: Sun Sep 14 2003 - 08:30:03 EST


On Sun, Sep 14, 2003 at 01:33:49PM +0100, Russell King wrote:
> On Sun, Sep 14, 2003 at 02:16:56PM +0200, Adrian Bunk wrote:
> > The patch below adds a config option OPTIMIZE_FOR_SIZE for telling gcc
> > to use -Os instead of -O2. Besides this, it removes constructs on
> > architectures that had a -Os hardcoded in their Makefiles.
>
> I'd rather retain the -Os default for ARM please. (The init/Kconfig
> defaults it to 'n' for everything.)

Below is the patch with the ARM part omitted.

cu
Adrian

--- linux-2.6.0-test5-Os/init/Kconfig.old 2003-09-13 17:30:50.000000000 +0200
+++ linux-2.6.0-test5-Os/init/Kconfig 2003-09-13 17:30:59.000000000 +0200
@@ -65,6 +65,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
--- linux-2.6.0-test5-Os/Makefile.old 2003-09-13 17:30:50.000000000 +0200
+++ linux-2.6.0-test5-Os/Makefile 2003-09-13 17:30:59.000000000 +0200
@@ -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__

@@ -370,6 +370,12 @@
# ---------------------------------------------------------------------------


+ifdef CONFIG_OPTIMIZE_FOR_SIZE
+CFLAGS += -Os
+else
+CFLAGS += -O2
+endif
+
ifndef CONFIG_FRAME_POINTER
CFLAGS += -fomit-frame-pointer
endif
--- linux-2.6.0-test5-Os/arch/h8300/Makefile.old 2003-09-13 17:30:50.000000000 +0200
+++ linux-2.6.0-test5-Os/arch/h8300/Makefile 2003-09-13 17:30:59.000000000 +0200
@@ -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\"
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/