Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

kbuild: add endianness flag to CHEKCFLAGS

The kernel depends on macros like __BYTE_ORDER__,
__BIG_ENDIAN__ or __LITTLE_ENDIAN__.

OTOH, sparse doesn't know about the endianness of the kernel and
by default uses the same as the machine on which sparse was built.

Ensure that sparse can predefine the macros corresponding to
how the kernel was configured by adding -m{big,little}-endian
to CHECKFLAGS in the main Makefile (and so for all archs).
Also, remove the equivalent done in arch specific Makefiles.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

authored by

Luc Van Oostenryck and committed by
Masahiro Yamada
14516765 59f7b584

+5 -3
+3
Makefile
··· 874 874 LDFLAGS_vmlinux += $(call ld-option, -X,) 875 875 endif 876 876 877 + # insure the checker run with the right endianness 878 + CHECKFLAGS += $(if $(CONFIG_CPU_BIG_ENDIAN),-mbig-endian,-mlittle-endian) 879 + 877 880 # Default kernel image to build when no specific target is given. 878 881 # KBUILD_IMAGE may be overruled on the command line or 879 882 # set in the environment
-1
arch/openrisc/Makefile
··· 25 25 LIBGCC := $(shell $(CC) $(KBUILD_CFLAGS) -print-libgcc-file-name) 26 26 27 27 KBUILD_CFLAGS += -pipe -ffixed-r10 -D__linux__ 28 - CHECKFLAGS += -mbig-endian 29 28 30 29 ifeq ($(CONFIG_OPENRISC_HAVE_INST_MUL),y) 31 30 KBUILD_CFLAGS += $(call cc-option,-mhard-mul)
+1 -1
arch/parisc/Makefile
··· 22 22 KBUILD_DEFCONFIG := default_defconfig 23 23 24 24 NM = sh $(srctree)/arch/parisc/nm 25 - CHECKFLAGS += -D__hppa__=1 -mbig-endian 25 + CHECKFLAGS += -D__hppa__=1 26 26 LIBGCC = $(shell $(CC) $(KBUILD_CFLAGS) -print-libgcc-file-name) 27 27 export LIBGCC 28 28
+1 -1
arch/s390/Makefile
··· 18 18 KBUILD_AFLAGS += -m64 19 19 UTS_MACHINE := s390x 20 20 STACK_SIZE := 16384 21 - CHECKFLAGS += -D__s390__ -D__s390x__ -mbig-endian 21 + CHECKFLAGS += -D__s390__ -D__s390x__ 22 22 23 23 export LD_BFD 24 24