Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e852f31

Browse files
Andrew MortonDavid S. Miller
Andrew Morton
authored and
David S. Miller
committedFeb 19, 2004
[PATCH] Add CONFIG for -mregparm=3
From: Andi Kleen <ak@muc.de>, me. Using -mregparm=3 shrinks the kernel further: (compiled with gcc 3.4, without -funit-at-a-time, using the later and together with -Os shrinks .text even more, making over 700KB difference) 4129346 708629 207240 5045215 4cfbdf vmlinux 3892905 708629 207240 4808774 496046 vmlinux-regparm This one helps even more, >236KB .text difference. Clearly worth the effort. This patch adds an option to use -mregparm=3 while compiling the kernel. I did an LTP run and it showed no additional failures over an non regparm kernel. According to some gcc developers it should be safe to use in all gccs that are still supports (2.95 and up) I didn't make it the default because it will break all binary only modules (although they can be fixed by adding a wrapper that calls them with "asmlinkage"). Actually it may be a good idea to make this default with 2.7.1 or somesuch. We add new kbuild infrastructure: the command scripts/gcc-version.sh $(CC) will print out the version of gcc in a canonical 4-digit form suitable for performing numerical tests against. DESC arch/i386/Makefile,scripts/gcc-version.sh,Makefile small fixes EDESC From: Serge Belyshev <33554432@mtu-net.ru> arch/i386/Makefile: * omitted $(KBUILD_SRC)/ in script call. scripts/gcc-version.sh: * GNU tail no longer supports 'tail -1' syntax. We should consider adding -fweb option: vanilla: $ size vmlinux text data bss dec hex filename 3056270 526780 386056 3969106 3c9052 vmlinux with -fweb: $ size vmlinux text data bss dec hex filename 3049523 526780 386056 3962359 3c75f7 vmlinux Also note 0.1 ... 1.0% speedup in various benchmarks. This option is not enabled by default at -O2 because it (like -fomit-frame-pointer) makes debugging impossible.
1 parent 56cf705 commit e852f31

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed
 

‎arch/i386/Kconfig

+13
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,19 @@ config BOOT_IOREMAP
838838
depends on (((X86_SUMMIT || X86_GENERICARCH) && NUMA) || (X86 && EFI))
839839
default y
840840

841+
config REGPARM
842+
bool "Use register arguments (EXPERIMENTAL)"
843+
depends on EXPERIMENTAL
844+
default n
845+
help
846+
Compile the kernel with -mregparm=3. This uses an different ABI
847+
and passes the first three arguments of a function call in registers.
848+
This will probably break binary only modules.
849+
850+
This feature is only enabled for gcc-3.0 and later - earlier compilers
851+
generate incorrect output with certain kernel constructs when
852+
-mregparm=3 is used.
853+
841854
endmenu
842855

843856

‎arch/i386/Makefile

+5
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ cflags-$(CONFIG_MVIAC3_2) += $(call check_gcc,-march=c3-2,-march=i686)
5151
# AMD Elan support
5252
cflags-$(CONFIG_X86_ELAN) += -march=i486
5353

54+
# -mregparm=3 works ok on gcc-3.0 and later
55+
#
56+
GCC_VERSION := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-version.sh $(CC))
57+
cflags-$(CONFIG_REGPARM) += $(shell if [ $(GCC_VERSION) -ge 0300 ] ; then echo "-mregparm=3"; fi ;)
58+
5459
CFLAGS += $(cflags-y)
5560

5661
# Default subarch .c files

‎include/asm-i386/module.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ struct mod_arch_specific
5454
#error unknown processor family
5555
#endif
5656

57-
#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
57+
#ifdef CONFIG_REGPARM
58+
#define MODULE_REGPARM "REGPARM "
59+
#else
60+
#define MODULE_REGPARM ""
61+
#endif
62+
63+
#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_REGPARM
5864

5965
#endif /* _ASM_I386_MODULE_H */

‎scripts/gcc-version.sh

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/sh
2+
#
3+
# gcc-version gcc-command
4+
#
5+
# Prints the gcc version of `gcc-command' in a canonical 4-digit form
6+
# such as `0295' for gcc-2.95, `0303' for gcc-3.3, etc.
7+
#
8+
9+
compiler="$*"
10+
11+
MAJOR=$(echo __GNUC__ | $compiler -E -xc - | tail -n 1)
12+
MINOR=$(echo __GNUC_MINOR__ | $compiler -E -xc - | tail -n 1)
13+
printf "%02d%02d\\n" $MAJOR $MINOR
14+

0 commit comments

Comments
 (0)
Failed to load comments.