aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Fries <cfries@google.com>2017-11-07 14:46:13 -0500
committerMasahiro Yamada <yamada.masahiro@socionext.com>2017-11-22 23:12:37 -0500
commitae6b289a37890909fea0e4a1666e19377fa0ed2c (patch)
tree1fa1e2f8859c6b66bf6c928f83198e922d2db86f
parentbf070bb0e6c62ba3075db0a666763ba52c677102 (diff)
kbuild: Set KBUILD_CFLAGS before incl. arch Makefile
Set the clang KBUILD_CFLAGS up before including arch/ Makefiles, so that ld-options (etc.) can work correctly. This fixes errors with clang such as ld-options trying to CC against your host architecture, but LD trying to link against your target architecture. Signed-off-by: Chris Fries <cfries@google.com> Signed-off-by: Nick Desaulniers <ndesaulniers@google.com> Reviewed-by: Matthias Kaehlcke <mka@chromium.org> Tested-by: Matthias Kaehlcke <mka@chromium.org> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
-rw-r--r--Makefile64
1 files changed, 32 insertions, 32 deletions
diff --git a/Makefile b/Makefile
index b248be104ee0..86d3329a8ae3 100644
--- a/Makefile
+++ b/Makefile
@@ -474,6 +474,38 @@ ifneq ($(KBUILD_SRC),)
474 $(srctree) $(objtree) $(VERSION) $(PATCHLEVEL) 474 $(srctree) $(objtree) $(VERSION) $(PATCHLEVEL)
475endif 475endif
476 476
477ifeq ($(cc-name),clang)
478ifneq ($(CROSS_COMPILE),)
479CLANG_TARGET := --target=$(notdir $(CROSS_COMPILE:%-=%))
480GCC_TOOLCHAIN := $(realpath $(dir $(shell which $(LD)))/..)
481endif
482ifneq ($(GCC_TOOLCHAIN),)
483CLANG_GCC_TC := --gcc-toolchain=$(GCC_TOOLCHAIN)
484endif
485KBUILD_CFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC)
486KBUILD_AFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC)
487KBUILD_CPPFLAGS += $(call cc-option,-Qunused-arguments,)
488KBUILD_CFLAGS += $(call cc-disable-warning, unused-variable)
489KBUILD_CFLAGS += $(call cc-disable-warning, format-invalid-specifier)
490KBUILD_CFLAGS += $(call cc-disable-warning, gnu)
491KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member)
492# Quiet clang warning: comparison of unsigned expression < 0 is always false
493KBUILD_CFLAGS += $(call cc-disable-warning, tautological-compare)
494# CLANG uses a _MergedGlobals as optimization, but this breaks modpost, as the
495# source of a reference will be _MergedGlobals and not on of the whitelisted names.
496# See modpost pattern 2
497KBUILD_CFLAGS += $(call cc-option, -mno-global-merge,)
498KBUILD_CFLAGS += $(call cc-option, -fcatch-undefined-behavior)
499KBUILD_CFLAGS += $(call cc-option, -no-integrated-as)
500KBUILD_AFLAGS += $(call cc-option, -no-integrated-as)
501else
502
503# These warnings generated too much noise in a regular build.
504# Use make W=1 to enable them (see scripts/Makefile.extrawarn)
505KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable)
506KBUILD_CFLAGS += $(call cc-disable-warning, unused-const-variable)
507endif
508
477ifeq ($(config-targets),1) 509ifeq ($(config-targets),1)
478# =========================================================================== 510# ===========================================================================
479# *config targets only - make sure prerequisites are updated, and descend 511# *config targets only - make sure prerequisites are updated, and descend
@@ -684,38 +716,6 @@ ifdef CONFIG_CC_STACKPROTECTOR
684endif 716endif
685KBUILD_CFLAGS += $(stackp-flag) 717KBUILD_CFLAGS += $(stackp-flag)
686 718
687ifeq ($(cc-name),clang)
688ifneq ($(CROSS_COMPILE),)
689CLANG_TARGET := --target=$(notdir $(CROSS_COMPILE:%-=%))
690GCC_TOOLCHAIN := $(realpath $(dir $(shell which $(LD)))/..)
691endif
692ifneq ($(GCC_TOOLCHAIN),)
693CLANG_GCC_TC := --gcc-toolchain=$(GCC_TOOLCHAIN)
694endif
695KBUILD_CFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC)
696KBUILD_AFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC)
697KBUILD_CPPFLAGS += $(call cc-option,-Qunused-arguments,)
698KBUILD_CFLAGS += $(call cc-disable-warning, unused-variable)
699KBUILD_CFLAGS += $(call cc-disable-warning, format-invalid-specifier)
700KBUILD_CFLAGS += $(call cc-disable-warning, gnu)
701KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member)
702# Quiet clang warning: comparison of unsigned expression < 0 is always false
703KBUILD_CFLAGS += $(call cc-disable-warning, tautological-compare)
704# CLANG uses a _MergedGlobals as optimization, but this breaks modpost, as the
705# source of a reference will be _MergedGlobals and not on of the whitelisted names.
706# See modpost pattern 2
707KBUILD_CFLAGS += $(call cc-option, -mno-global-merge,)
708KBUILD_CFLAGS += $(call cc-option, -fcatch-undefined-behavior)
709KBUILD_CFLAGS += $(call cc-option, -no-integrated-as)
710KBUILD_AFLAGS += $(call cc-option, -no-integrated-as)
711else
712
713# These warnings generated too much noise in a regular build.
714# Use make W=1 to enable them (see scripts/Makefile.extrawarn)
715KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable)
716KBUILD_CFLAGS += $(call cc-disable-warning, unused-const-variable)
717endif
718
719ifdef CONFIG_FRAME_POINTER 719ifdef CONFIG_FRAME_POINTER
720KBUILD_CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls 720KBUILD_CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls
721else 721else