diff options
author | Chris Fries <cfries@google.com> | 2017-11-07 14:46:13 -0500 |
---|---|---|
committer | Masahiro Yamada <yamada.masahiro@socionext.com> | 2017-11-22 23:12:37 -0500 |
commit | ae6b289a37890909fea0e4a1666e19377fa0ed2c (patch) | |
tree | 1fa1e2f8859c6b66bf6c928f83198e922d2db86f | |
parent | bf070bb0e6c62ba3075db0a666763ba52c677102 (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-- | Makefile | 64 |
1 files changed, 32 insertions, 32 deletions
@@ -474,6 +474,38 @@ ifneq ($(KBUILD_SRC),) | |||
474 | $(srctree) $(objtree) $(VERSION) $(PATCHLEVEL) | 474 | $(srctree) $(objtree) $(VERSION) $(PATCHLEVEL) |
475 | endif | 475 | endif |
476 | 476 | ||
477 | ifeq ($(cc-name),clang) | ||
478 | ifneq ($(CROSS_COMPILE),) | ||
479 | CLANG_TARGET := --target=$(notdir $(CROSS_COMPILE:%-=%)) | ||
480 | GCC_TOOLCHAIN := $(realpath $(dir $(shell which $(LD)))/..) | ||
481 | endif | ||
482 | ifneq ($(GCC_TOOLCHAIN),) | ||
483 | CLANG_GCC_TC := --gcc-toolchain=$(GCC_TOOLCHAIN) | ||
484 | endif | ||
485 | KBUILD_CFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC) | ||
486 | KBUILD_AFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC) | ||
487 | KBUILD_CPPFLAGS += $(call cc-option,-Qunused-arguments,) | ||
488 | KBUILD_CFLAGS += $(call cc-disable-warning, unused-variable) | ||
489 | KBUILD_CFLAGS += $(call cc-disable-warning, format-invalid-specifier) | ||
490 | KBUILD_CFLAGS += $(call cc-disable-warning, gnu) | ||
491 | KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member) | ||
492 | # Quiet clang warning: comparison of unsigned expression < 0 is always false | ||
493 | KBUILD_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 | ||
497 | KBUILD_CFLAGS += $(call cc-option, -mno-global-merge,) | ||
498 | KBUILD_CFLAGS += $(call cc-option, -fcatch-undefined-behavior) | ||
499 | KBUILD_CFLAGS += $(call cc-option, -no-integrated-as) | ||
500 | KBUILD_AFLAGS += $(call cc-option, -no-integrated-as) | ||
501 | else | ||
502 | |||
503 | # These warnings generated too much noise in a regular build. | ||
504 | # Use make W=1 to enable them (see scripts/Makefile.extrawarn) | ||
505 | KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable) | ||
506 | KBUILD_CFLAGS += $(call cc-disable-warning, unused-const-variable) | ||
507 | endif | ||
508 | |||
477 | ifeq ($(config-targets),1) | 509 | ifeq ($(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 | |||
684 | endif | 716 | endif |
685 | KBUILD_CFLAGS += $(stackp-flag) | 717 | KBUILD_CFLAGS += $(stackp-flag) |
686 | 718 | ||
687 | ifeq ($(cc-name),clang) | ||
688 | ifneq ($(CROSS_COMPILE),) | ||
689 | CLANG_TARGET := --target=$(notdir $(CROSS_COMPILE:%-=%)) | ||
690 | GCC_TOOLCHAIN := $(realpath $(dir $(shell which $(LD)))/..) | ||
691 | endif | ||
692 | ifneq ($(GCC_TOOLCHAIN),) | ||
693 | CLANG_GCC_TC := --gcc-toolchain=$(GCC_TOOLCHAIN) | ||
694 | endif | ||
695 | KBUILD_CFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC) | ||
696 | KBUILD_AFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC) | ||
697 | KBUILD_CPPFLAGS += $(call cc-option,-Qunused-arguments,) | ||
698 | KBUILD_CFLAGS += $(call cc-disable-warning, unused-variable) | ||
699 | KBUILD_CFLAGS += $(call cc-disable-warning, format-invalid-specifier) | ||
700 | KBUILD_CFLAGS += $(call cc-disable-warning, gnu) | ||
701 | KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member) | ||
702 | # Quiet clang warning: comparison of unsigned expression < 0 is always false | ||
703 | KBUILD_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 | ||
707 | KBUILD_CFLAGS += $(call cc-option, -mno-global-merge,) | ||
708 | KBUILD_CFLAGS += $(call cc-option, -fcatch-undefined-behavior) | ||
709 | KBUILD_CFLAGS += $(call cc-option, -no-integrated-as) | ||
710 | KBUILD_AFLAGS += $(call cc-option, -no-integrated-as) | ||
711 | else | ||
712 | |||
713 | # These warnings generated too much noise in a regular build. | ||
714 | # Use make W=1 to enable them (see scripts/Makefile.extrawarn) | ||
715 | KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable) | ||
716 | KBUILD_CFLAGS += $(call cc-disable-warning, unused-const-variable) | ||
717 | endif | ||
718 | |||
719 | ifdef CONFIG_FRAME_POINTER | 719 | ifdef CONFIG_FRAME_POINTER |
720 | KBUILD_CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls | 720 | KBUILD_CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls |
721 | else | 721 | else |