diff --git a/Makefile b/Makefile index e3c5eb6..da60383 100644 --- a/Makefile +++ b/Makefile @@ -313,14 +313,13 @@ KALLSYMS = scripts/kallsyms PERL = perl CHECK = sparse -CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ -Wbitwise $(CF) +CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ MODFLAGS = -DMODULE -CFLAGS_MODULE = $(MODFLAGS) -AFLAGS_MODULE = $(MODFLAGS) -LDFLAGS_MODULE = -CFLAGS_KERNEL = -AFLAGS_KERNEL = - +CFLAGS_MODULE = $(MODFLAGS) $(CUSTOM_CFLAGS) +AFLAGS_MODULE = $(MODFLAGS) $(CUSTOM_AFLAGS) +LDFLAGS_MODULE = $(CUSTOM_LDFLAGS) +CFLAGS_KERNEL = $(CUSTOM_CFLAGS) +AFLAGS_KERNEL = $(CUSTOM_AFLAGS) # Use LINUXINCLUDE when you must reference the include/ directory. # Needed to be compatible with the O= option @@ -330,6 +329,10 @@ LINUXINCLUDE := -Iinclude \ KBUILD_CPPFLAGS := -D__KERNEL__ $(LINUXINCLUDE) +# Apply custom flags +KBUILD_CFLAGS += $(CUSTOM_CFLAGS) +KBUILD_AFLAGS += $(CUSTOM_AFLAGS) + KBUILD_CFLAGS := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \ -fno-strict-aliasing -fno-common \ -Werror-implicit-function-declaration @@ -343,6 +346,7 @@ export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION export ARCH SRCARCH CONFIG_SHELL HOSTCC HOSTCFLAGS CROSS_COMPILE AS LD CC export CPP AR NM STRIP OBJCOPY OBJDUMP MAKE AWK GENKSYMS PERL UTS_MACHINE export HOSTCXX HOSTCXXFLAGS LDFLAGS_MODULE CHECK CHECKFLAGS +export NAME export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS LDFLAGS export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE @@ -515,6 +519,13 @@ endif # Arch Makefiles may override this setting KBUILD_CFLAGS += $(call cc-option, -fno-stack-protector) +#Strips debugging symbols if enabled +#Use only if you want a super small kernel +#Without the ability to debug +ifdef CONFIG_CC_STRIP_DEBUG +KBUILD_CFLAGS += -s +endif + include $(srctree)/arch/$(SRCARCH)/Makefile ifdef CONFIG_FRAME_POINTER @@ -565,7 +576,7 @@ endif LDFLAGS_BUILD_ID = $(patsubst -Wl$(comma)%,%,\ $(call ld-option, -Wl$(comma)--build-id,)) LDFLAGS_MODULE += $(LDFLAGS_BUILD_ID) -LDFLAGS_vmlinux += $(LDFLAGS_BUILD_ID) +LDFLAGS_vmlinux += $(LDFLAGS_BUILD_ID) $(CUSTOM_LDFLAGS) # Default kernel image to build when no specific target is given. # KBUILD_IMAGE may be overruled on the command line or diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu index 2ad6301..288c77d 100644 --- a/arch/x86/Kconfig.cpu +++ b/arch/x86/Kconfig.cpu @@ -290,6 +290,17 @@ config X86_GENERIC This is really intended for distributors who need more generic optimizations. +config X86_MARCH_NATIVE + bool "Use -march=native cflag (EXPERIMENTAL)" + depends on EXPERIMENTAL + help + Setting Y here, will result in passing the -march=native and + -mtune=native cflags to GCC while compiling the kernel, which + makes GCC check the CPU capabilities and use the best cflags + for your computer. + + Set Y here only if you use >=gcc-4.2.0. + endif config X86_CPU diff --git a/arch/x86/Makefile_32.cpu b/arch/x86/Makefile_32.cpu index e372b58..6605c8e 100644 --- a/arch/x86/Makefile_32.cpu +++ b/arch/x86/Makefile_32.cpu @@ -10,6 +10,9 @@ tune = $(call cc-option,-mcpu=$(1),$(2)) endif align := $(cc-option-align) +ifeq ($(CONFIG_X86_MARCH_NATIVE),y) +cflags-y += -march=native -mtune=native +else cflags-$(CONFIG_M386) += -march=i386 cflags-$(CONFIG_M486) += -march=i486 cflags-$(CONFIG_M586) += -march=i586 @@ -25,12 +28,12 @@ cflags-$(CONFIG_MK6) += -march=k6 # They make zero difference whatsosever to performance at this time. cflags-$(CONFIG_MK7) += -march=athlon cflags-$(CONFIG_MK8) += $(call cc-option,-march=k8,-march=athlon) -cflags-$(CONFIG_MCRUSOE) += -march=i686 $(align)-functions=0 $(align)-jumps=0 $(align)-loops=0 -cflags-$(CONFIG_MEFFICEON) += -march=i686 $(call tune,pentium3) $(align)-functions=0 $(align)-jumps=0 $(align)-loops=0 +cflags-$(CONFIG_MCRUSOE) += -march=i686 +cflags-$(CONFIG_MEFFICEON) += -march=i686 $(call tune,pentium3) cflags-$(CONFIG_MWINCHIPC6) += $(call cc-option,-march=winchip-c6,-march=i586) cflags-$(CONFIG_MWINCHIP2) += $(call cc-option,-march=winchip2,-march=i586) cflags-$(CONFIG_MWINCHIP3D) += $(call cc-option,-march=winchip2,-march=i586) -cflags-$(CONFIG_MCYRIXIII) += $(call cc-option,-march=c3,-march=i486) $(align)-functions=0 $(align)-jumps=0 $(align)-loops=0 +cflags-$(CONFIG_MCYRIXIII) += $(call cc-option,-march=c3,-march=i486) cflags-$(CONFIG_MVIAC3_2) += $(call cc-option,-march=c3-2,-march=i686) cflags-$(CONFIG_MVIAC7) += -march=i686 cflags-$(CONFIG_MCORE2) += -march=i686 $(call tune,core2) @@ -40,6 +43,11 @@ cflags-$(CONFIG_X86_ELAN) += -march=i486 # Geode GX1 support cflags-$(CONFIG_MGEODEGX1) += -march=pentium-mmx +endif + +cflags-$(CONFIG_MCRUSOE) += $(align)-functions=0 $(align)-jumps=0 $(align)-loops=0 +cflags-$(CONFIG_MEFFICEON) += $(align)-functions=0 $(align)-jumps=0 $(align)-loops=0 +cflags-$(CONFIG_MCYRIXIII) += $(align)-functions=0 $(align)-jumps=0 $(align)-loops=0 # add at the end to overwrite eventual tuning options from earlier # cpu entries diff --git a/init/Kconfig b/init/Kconfig index 6199d11..cfa1e96 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -524,6 +548,65 @@ config CC_OPTIMIZE_FOR_SIZE If unsure, say N. +config CC_STRIP_DEBUG + bool "Strip Debugging Symbols" + default n + depends on EXPERIMENTAL + help + Enabling this option will pass "-s" to gcc, which strips debug + symbols, resulting in a MUCH smaller kernel. + + WARNING: Use this only if you don't plan on using a debugger, + or debug information. + + If unsure, say N. + +menu "Custom flags" + +config CUSTOM_CFLAGS + string "Custom CFLAGS for kernel" + default "" + help + You can use this to easily set custom gcc CFLAGS to be used for the + entire kernel (including modules). + + ONLY ADD CUSTOM CFLAGS IF YOU KNOW WHAT YOU ARE DOING + + If unsure, leave blank. + +config CUSTOM_LDFLAGS + string "Custom LDFLAGS for kernel" + default "" + help + You can use this to easily set custom gcc LDFLAGS to be used for the + entire kernel (including modules). + + ONLY ADD CUSTOM LDFLAGS IF YOU KNOW WHAT YOU ARE DOING + + If unsure, leave blank. + +config CUSTOM_AFLAGS + string "Custom AFLAGS for kernel" + default "" + help + You can use this to easily set custom gcc AFLAGS to be used for the + entire kernel (including modules). + + ONLY ADD CUSTOM AFLAGS IF YOU KNOW WHAT YOU ARE DOING + + If unsure, leave blank. + +config CUSTOM_MAKEFLAGS + string "Custom MAKEFLAGS for kernel" + default "" + help + You can use this to easily set custom MAKEFLAGS to be used for building + the entire kernel. + + If unsure, leave blank. + +endmenu + config SYSCTL bool