Skip to contentSkip to conversation

fix Makefile to ensure proper options get passed from gcc

PATCH New Jory A. Pratt 1 participant 1 message Aug 28, 2009 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix Makefile to ensure proper options get passed from gcc

if -D__KERNEL__ is not passed via KBUILD_CFLAGS the compiler can have options passed by default that will unset other options such as -ffreestanding or -fno-toplevel-reorder if the compiler is passing -fPIE.

refer to fix-fpie-from-being-used.diff

Another option that was suggested from another user was to pass -D__KERNEL__ via Kbuild.include, patch is also attached. either patch would work, There is no risk of breakage, benefit is for those who use a hardened toolchain.

fix-cc-options-check.patch

I believe we should pass the option via KBUILD_CFLAGS as to not confuse the fact that we are not building CPP code, but rather C code.

Also correct me if I am wrong but last I knew only part of kernel that was cpp was qconfig.

-Jory

signed off by: Jory A. Pratt <[email protected]>

When -fPIE is pass to cc1 it can't use -ffreestanding or -fno-toplevel-reorder. This will cause issues in video-vga.c when compiled leaving a user with no video modes avaliable when booting system.
Many thanks to Vinky for tracking down bug.

Makefile renamed from Makefile~ +2 -1
@@ -348,7 +348,8 @@
 		   -fno-strict-aliasing -fno-common \
 		   -Werror-implicit-function-declaration \
 		   -Wno-format-security \
-		   -fno-delete-null-pointer-checks
+		   -fno-delete-null-pointer-checks \
+		   -D__KERNEL__
 KBUILD_AFLAGS   := -D__ASSEMBLY__
 
 # Read KERNELRELEASE from include/config/kernel.release (if it exists)

2009-08-28 Magnus Granberg <[email protected]>

		#282201
		* scripts/Kbuild.incude		add $(KBUILD_CPPFLAGS)
Kbuild.include renamed from Kbuild.include.zorry +2 -2
@@ -105,12 +105,12 @@
 # Usage: cflags-y += $(call cc-option,-march=winchip-c6,-march=i586)
 
 cc-option = $(call try-run,\
-	$(CC) $(KBUILD_CFLAGS) $(1) -c -xc /dev/null -o "$$TMP",$(1),$(2))
+	$(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(1) -c -xc /dev/null -o "$$TMP",$(1),$(2))
 
 # cc-option-yn
 # Usage: flag := $(call cc-option-yn,-march=winchip-c6)
 cc-option-yn = $(call try-run,\
-	$(CC) $(KBUILD_CFLAGS) $(1) -c -xc /dev/null -o "$$TMP",y,n)
+	$(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(1) -c -xc /dev/null -o "$$TMP",y,n)
 
 # cc-option-align
 # Prefix align with either -falign or -malign