Message ID | 20171115204231.34914-1-ndesaulniers@google.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Hi Nick, 2017-11-16 5:42 GMT+09:00 Nick Desaulniers <ndesaulniers@google.com>: > From: Chris Fries <cfries@google.com> > > 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. > > Reviewed-by: Matthias Kaehlcke <mka@chromium.org> > Signed-off-by: Chris Fries <cfries@google.com> > Signed-off-by: Nick Desaulniers <ndesaulniers@google.com> > Suggested-by: Masahiro Yamada <yamada.masahiro@socionext.com> > Tested-by: Matthias Kaehlcke <mka@chromium.org> > --- > Changes since v2: > * Move clang block lower in Makefile, so as not to run it when running > configuration, per Masahiro. > * Remove paragraphs from commit message, per Masahiro. > * Add Masahiro to Suggested-by line in commit message. > > Makefile | 64 ++++++++++++++++++++++++++++++++-------------------------------- > 1 file changed, 32 insertions(+), 32 deletions(-) > > diff --git a/Makefile b/Makefile > index a7476e6934f1..b3352becc7df 100644 > --- a/Makefile > +++ b/Makefile > @@ -608,6 +608,38 @@ CFLAGS_GCOV := -fprofile-arcs -ftest-coverage -fno-tree-loop-im $(call cc-disabl > CFLAGS_KCOV := $(call cc-option,-fsanitize-coverage=trace-pc,) > export CFLAGS_GCOV CFLAGS_KCOV > > +ifeq ($(cc-name),clang) > +ifneq ($(CROSS_COMPILE),) > +CLANG_TARGET := -target $(notdir $(CROSS_COMPILE:%-=%)) > +GCC_TOOLCHAIN := $(realpath $(dir $(shell which $(LD)))/..) > +endif > +ifneq ($(GCC_TOOLCHAIN),) > +CLANG_GCC_TC := -gcc-toolchain $(GCC_TOOLCHAIN) > +endif > +KBUILD_CFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC) > +KBUILD_AFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC) > +KBUILD_CPPFLAGS += $(call cc-option,-Qunused-arguments,) > +KBUILD_CFLAGS += $(call cc-disable-warning, unused-variable) > +KBUILD_CFLAGS += $(call cc-disable-warning, format-invalid-specifier) > +KBUILD_CFLAGS += $(call cc-disable-warning, gnu) > +KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member) > +# Quiet clang warning: comparison of unsigned expression < 0 is always false > +KBUILD_CFLAGS += $(call cc-disable-warning, tautological-compare) > +# CLANG uses a _MergedGlobals as optimization, but this breaks modpost, as the > +# source of a reference will be _MergedGlobals and not on of the whitelisted names. > +# See modpost pattern 2 > +KBUILD_CFLAGS += $(call cc-option, -mno-global-merge,) > +KBUILD_CFLAGS += $(call cc-option, -fcatch-undefined-behavior) > +KBUILD_CFLAGS += $(call cc-option, -no-integrated-as) > +KBUILD_AFLAGS += $(call cc-option, -no-integrated-as) > +else > + > +# These warnings generated too much noise in a regular build. > +# Use make W=1 to enable them (see scripts/Makefile.extrawarn) > +KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable) > +KBUILD_CFLAGS += $(call cc-disable-warning, unused-const-variable) > +endif > + > # The arch Makefile can set ARCH_{CPP,A,C}FLAGS to override the default > # values of the respective KBUILD_* variables > ARCH_CPPFLAGS := > @@ -682,38 +714,6 @@ ifdef CONFIG_CC_STACKPROTECTOR > endif > KBUILD_CFLAGS += $(stackp-flag) > > -ifeq ($(cc-name),clang) > -ifneq ($(CROSS_COMPILE),) > -CLANG_TARGET := -target $(notdir $(CROSS_COMPILE:%-=%)) > -GCC_TOOLCHAIN := $(realpath $(dir $(shell which $(LD)))/..) > -endif > -ifneq ($(GCC_TOOLCHAIN),) > -CLANG_GCC_TC := -gcc-toolchain $(GCC_TOOLCHAIN) > -endif > -KBUILD_CFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC) > -KBUILD_AFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC) > -KBUILD_CPPFLAGS += $(call cc-option,-Qunused-arguments,) > -KBUILD_CFLAGS += $(call cc-disable-warning, unused-variable) > -KBUILD_CFLAGS += $(call cc-disable-warning, format-invalid-specifier) > -KBUILD_CFLAGS += $(call cc-disable-warning, gnu) > -KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member) > -# Quiet clang warning: comparison of unsigned expression < 0 is always false > -KBUILD_CFLAGS += $(call cc-disable-warning, tautological-compare) > -# CLANG uses a _MergedGlobals as optimization, but this breaks modpost, as the > -# source of a reference will be _MergedGlobals and not on of the whitelisted names. > -# See modpost pattern 2 > -KBUILD_CFLAGS += $(call cc-option, -mno-global-merge,) > -KBUILD_CFLAGS += $(call cc-option, -fcatch-undefined-behavior) > -KBUILD_CFLAGS += $(call cc-option, -no-integrated-as) > -KBUILD_AFLAGS += $(call cc-option, -no-integrated-as) > -else > - > -# These warnings generated too much noise in a regular build. > -# Use make W=1 to enable them (see scripts/Makefile.extrawarn) > -KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable) > -KBUILD_CFLAGS += $(call cc-disable-warning, unused-const-variable) > -endif > - > ifdef CONFIG_FRAME_POINTER > KBUILD_CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls > else > -- > 2.15.0.448.gf294e3d99a-goog > BTW, I notice another issue. If we move clang settings before including arch Makefile, "ifneq ($(CROSS_COMPILE),)" comes early. Some arch Makefiles (arch/mips/Makefile, arch/blackfin/Makefile, etc.) set CROSS_COMPILE there if CROSS_COMPILE is not given. Then, we have a conflict between two requirements among arch. [1] arm64, powerpc use ld-option in their Makefile. So, clang flags must be set before inc. arch Makefile. [2] mips, blackfin, etc. may set CROSS_COMPILE in their Makefile. So, we want to reference CROSS_COMPILE only after inc. arch Makefile I have no idea how to solve it. At this moment, I guess clang is intended to support only limited architectures. It might be OK to be compromised here.
2017-11-16 5:42 GMT+09:00 Nick Desaulniers <ndesaulniers@google.com>: > From: Chris Fries <cfries@google.com> > > 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. > > Reviewed-by: Matthias Kaehlcke <mka@chromium.org> > Signed-off-by: Chris Fries <cfries@google.com> > Signed-off-by: Nick Desaulniers <ndesaulniers@google.com> > Suggested-by: Masahiro Yamada <yamada.masahiro@socionext.com> > Tested-by: Matthias Kaehlcke <mka@chromium.org> > --- Applied to linux-kbuild/kbuild. Thanks!
Hi. 2017-11-18 13:09 GMT+09:00 Masahiro Yamada <yamada.masahiro@socionext.com>: > 2017-11-16 5:42 GMT+09:00 Nick Desaulniers <ndesaulniers@google.com>: >> From: Chris Fries <cfries@google.com> >> >> 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. >> >> Reviewed-by: Matthias Kaehlcke <mka@chromium.org> >> Signed-off-by: Chris Fries <cfries@google.com> >> Signed-off-by: Nick Desaulniers <ndesaulniers@google.com> >> Suggested-by: Masahiro Yamada <yamada.masahiro@socionext.com> >> Tested-by: Matthias Kaehlcke <mka@chromium.org> >> --- > > Applied to linux-kbuild/kbuild. Thanks! > > -- > Best Regards > Masahiro Yamada After more thought, I picked up your v2. (clang variables before kernel configuration) Linus suggests to move compiler flag testing to Kconfig. To do it, we need to feed target CC information to Kconfig. Sorry for spending your time.
Hi Masahiro, Thanks for merging Chris' patch, and sorry for taking so long to respond. On Wed, Nov 22, 2017 at 8:24 PM, Masahiro Yamada <yamada.masahiro@socionext.com> wrote: > Linus suggests to move compiler flag testing to Kconfig. Do you have an LKML link for context? On Wed, Nov 15, 2017 at 6:32 PM, Masahiro Yamada <yamada.masahiro@socionext.com> wrote: > BTW, I notice another issue. > > If we move clang settings before including arch Makefile, > "ifneq ($(CROSS_COMPILE),)" comes early. > > Some arch Makefiles (arch/mips/Makefile, arch/blackfin/Makefile, etc.) > set CROSS_COMPILE there if CROSS_COMPILE is not given. > > Then, we have a conflict between two requirements among arch. > > [1] arm64, powerpc use ld-option in their Makefile. > So, clang flags must be set before inc. arch Makefile. > [2] mips, blackfin, etc. may set CROSS_COMPILE in their Makefile. > So, we want to reference CROSS_COMPILE only after inc. arch Makefile > > I have no idea how to solve it. > > At this moment, I guess clang is intended to support > only limited architectures. > > It might be OK to be compromised here. I definitely find it curious that certain arch's define CROSS_COMPILE themselves. The benefit is one less argument to supply at compile time, but it assumes that the toolchain always has a certain prefix. This makes sense to me when cross compiling, but seems odd when compiling natively on that arch as the host and target. Maybe those arch's use that convention, or simply are always cross compiled for? Taking a survey of all arch's currently in the kernel via `cd arch; ag CROSS_COMPILE` and quickly eyeballing the result: m68k if not set arc if not set openrisc for some configs (openrisc/configs/or1ksim_defconfig, openrisc/configs/simple_smp_defconfig) blackfin if not set hexagon for some configs (hexagon/configs/comet_defconfig) parisc if not set sh if not set xtensa if not set score always arm for some configs (arm/configs/lpc18xx_defconfig) h8300 if not set mips if not set (and explicitly emptied for some configs, mips/configs/nlm_xlr_defconfig ) unicore32 if not set tile if not set The * if not set (or not being on the list) seems correct, as the top level Makefile will handle this correctly. Setting it for some configs seems curious (not necessarily wrong?), emptying it/always setting it via config sounds wrong to me, but maybe those hosts don't have toolchains and must always be cross compiled for? For reference, this file in LLVM source defines the supported backend targets: https://llvm.org/doxygen/Triple_8h_source.html Either way, it sounds like we're all set here, I guess I'm just curious about the LKML link/context and why some configs set CROSS_COMPILE themselves? -- To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi Nick, On Tue, Nov 28, 2017 at 7:18 PM, Nick Desaulniers <ndesaulniers@google.com> wrote: > Thanks for merging Chris' patch, and sorry for taking so long to respond. > > On Wed, Nov 22, 2017 at 8:24 PM, Masahiro Yamada > <yamada.masahiro@socionext.com> wrote: >> Linus suggests to move compiler flag testing to Kconfig. > > Do you have an LKML link for context? > > On Wed, Nov 15, 2017 at 6:32 PM, Masahiro Yamada > <yamada.masahiro@socionext.com> wrote: >> BTW, I notice another issue. >> >> If we move clang settings before including arch Makefile, >> "ifneq ($(CROSS_COMPILE),)" comes early. >> >> Some arch Makefiles (arch/mips/Makefile, arch/blackfin/Makefile, etc.) >> set CROSS_COMPILE there if CROSS_COMPILE is not given. >> >> Then, we have a conflict between two requirements among arch. >> >> [1] arm64, powerpc use ld-option in their Makefile. >> So, clang flags must be set before inc. arch Makefile. >> [2] mips, blackfin, etc. may set CROSS_COMPILE in their Makefile. >> So, we want to reference CROSS_COMPILE only after inc. arch Makefile >> >> I have no idea how to solve it. >> >> At this moment, I guess clang is intended to support >> only limited architectures. >> >> It might be OK to be compromised here. > > I definitely find it curious that certain arch's define CROSS_COMPILE > themselves. The benefit is one less argument to supply at compile > time, but it assumes that the toolchain always has a certain prefix. > This makes sense to me when cross compiling, but seems odd when > compiling natively on that arch as the host and target. Maybe those > arch's use that convention, or simply are always cross compiled for? > > Taking a survey of all arch's currently in the kernel via `cd arch; ag > CROSS_COMPILE` and quickly eyeballing the result: > > m68k if not set And inside "ifneq ($(SUBARCH),$(ARCH))", so the prefix is not used for native compilation. Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds -- To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi Nick, 2017-11-29 3:18 GMT+09:00 Nick Desaulniers <ndesaulniers@google.com>: > Hi Masahiro, > > Thanks for merging Chris' patch, and sorry for taking so long to respond. > > On Wed, Nov 22, 2017 at 8:24 PM, Masahiro Yamada > <yamada.masahiro@socionext.com> wrote: >> Linus suggests to move compiler flag testing to Kconfig. > > Do you have an LKML link for context? https://lkml.org/lkml/2017/11/19/291 > On Wed, Nov 15, 2017 at 6:32 PM, Masahiro Yamada > <yamada.masahiro@socionext.com> wrote: >> BTW, I notice another issue. >> >> If we move clang settings before including arch Makefile, >> "ifneq ($(CROSS_COMPILE),)" comes early. >> >> Some arch Makefiles (arch/mips/Makefile, arch/blackfin/Makefile, etc.) >> set CROSS_COMPILE there if CROSS_COMPILE is not given. >> >> Then, we have a conflict between two requirements among arch. >> >> [1] arm64, powerpc use ld-option in their Makefile. >> So, clang flags must be set before inc. arch Makefile. >> [2] mips, blackfin, etc. may set CROSS_COMPILE in their Makefile. >> So, we want to reference CROSS_COMPILE only after inc. arch Makefile >> >> I have no idea how to solve it. >> >> At this moment, I guess clang is intended to support >> only limited architectures. >> >> It might be OK to be compromised here. > > I definitely find it curious that certain arch's define CROSS_COMPILE > themselves. The benefit is one less argument to supply at compile > time, but it assumes that the toolchain always has a certain prefix. > This makes sense to me when cross compiling, but seems odd when > compiling natively on that arch as the host and target. Maybe those > arch's use that convention, or simply are always cross compiled for? > > Taking a survey of all arch's currently in the kernel via `cd arch; ag > CROSS_COMPILE` and quickly eyeballing the result: > > m68k if not set > arc if not set > openrisc for some configs (openrisc/configs/or1ksim_defconfig, > openrisc/configs/simple_smp_defconfig) > blackfin if not set > hexagon for some configs (hexagon/configs/comet_defconfig) > parisc if not set > sh if not set > xtensa if not set > score always > arm for some configs (arm/configs/lpc18xx_defconfig) > h8300 if not set > mips if not set (and explicitly emptied for some configs, > mips/configs/nlm_xlr_defconfig ) > unicore32 if not set > tile if not set > > The * if not set (or not being on the list) seems correct, as the top > level Makefile will handle this correctly. Setting it for some > configs seems curious (not necessarily wrong?), Perhaps, the maintainer of those platforms may want to save one command-line argument at compile time. > emptying it/always > setting it via config sounds wrong to me, arch/mips/configs/nlm_xlr_defconfig explicitly empties it. It is just redundant because CONFIG_CROSS_COMPILE="" is the default in Kconfig. Not necessarily wrong, I think. > but maybe those hosts don't > have toolchains and must always be cross compiled for? > > For reference, this file in LLVM source defines the supported backend > targets: https://llvm.org/doxygen/Triple_8h_source.html > > Either way, it sounds like we're all set here, I guess I'm just > curious about the LKML link/context and why some configs set > CROSS_COMPILE themselves? > -- > To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/Makefile b/Makefile index a7476e6934f1..b3352becc7df 100644 --- a/Makefile +++ b/Makefile @@ -608,6 +608,38 @@ CFLAGS_GCOV := -fprofile-arcs -ftest-coverage -fno-tree-loop-im $(call cc-disabl CFLAGS_KCOV := $(call cc-option,-fsanitize-coverage=trace-pc,) export CFLAGS_GCOV CFLAGS_KCOV +ifeq ($(cc-name),clang) +ifneq ($(CROSS_COMPILE),) +CLANG_TARGET := -target $(notdir $(CROSS_COMPILE:%-=%)) +GCC_TOOLCHAIN := $(realpath $(dir $(shell which $(LD)))/..) +endif +ifneq ($(GCC_TOOLCHAIN),) +CLANG_GCC_TC := -gcc-toolchain $(GCC_TOOLCHAIN) +endif +KBUILD_CFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC) +KBUILD_AFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC) +KBUILD_CPPFLAGS += $(call cc-option,-Qunused-arguments,) +KBUILD_CFLAGS += $(call cc-disable-warning, unused-variable) +KBUILD_CFLAGS += $(call cc-disable-warning, format-invalid-specifier) +KBUILD_CFLAGS += $(call cc-disable-warning, gnu) +KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member) +# Quiet clang warning: comparison of unsigned expression < 0 is always false +KBUILD_CFLAGS += $(call cc-disable-warning, tautological-compare) +# CLANG uses a _MergedGlobals as optimization, but this breaks modpost, as the +# source of a reference will be _MergedGlobals and not on of the whitelisted names. +# See modpost pattern 2 +KBUILD_CFLAGS += $(call cc-option, -mno-global-merge,) +KBUILD_CFLAGS += $(call cc-option, -fcatch-undefined-behavior) +KBUILD_CFLAGS += $(call cc-option, -no-integrated-as) +KBUILD_AFLAGS += $(call cc-option, -no-integrated-as) +else + +# These warnings generated too much noise in a regular build. +# Use make W=1 to enable them (see scripts/Makefile.extrawarn) +KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable) +KBUILD_CFLAGS += $(call cc-disable-warning, unused-const-variable) +endif + # The arch Makefile can set ARCH_{CPP,A,C}FLAGS to override the default # values of the respective KBUILD_* variables ARCH_CPPFLAGS := @@ -682,38 +714,6 @@ ifdef CONFIG_CC_STACKPROTECTOR endif KBUILD_CFLAGS += $(stackp-flag) -ifeq ($(cc-name),clang) -ifneq ($(CROSS_COMPILE),) -CLANG_TARGET := -target $(notdir $(CROSS_COMPILE:%-=%)) -GCC_TOOLCHAIN := $(realpath $(dir $(shell which $(LD)))/..) -endif -ifneq ($(GCC_TOOLCHAIN),) -CLANG_GCC_TC := -gcc-toolchain $(GCC_TOOLCHAIN) -endif -KBUILD_CFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC) -KBUILD_AFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC) -KBUILD_CPPFLAGS += $(call cc-option,-Qunused-arguments,) -KBUILD_CFLAGS += $(call cc-disable-warning, unused-variable) -KBUILD_CFLAGS += $(call cc-disable-warning, format-invalid-specifier) -KBUILD_CFLAGS += $(call cc-disable-warning, gnu) -KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member) -# Quiet clang warning: comparison of unsigned expression < 0 is always false -KBUILD_CFLAGS += $(call cc-disable-warning, tautological-compare) -# CLANG uses a _MergedGlobals as optimization, but this breaks modpost, as the -# source of a reference will be _MergedGlobals and not on of the whitelisted names. -# See modpost pattern 2 -KBUILD_CFLAGS += $(call cc-option, -mno-global-merge,) -KBUILD_CFLAGS += $(call cc-option, -fcatch-undefined-behavior) -KBUILD_CFLAGS += $(call cc-option, -no-integrated-as) -KBUILD_AFLAGS += $(call cc-option, -no-integrated-as) -else - -# These warnings generated too much noise in a regular build. -# Use make W=1 to enable them (see scripts/Makefile.extrawarn) -KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable) -KBUILD_CFLAGS += $(call cc-disable-warning, unused-const-variable) -endif - ifdef CONFIG_FRAME_POINTER KBUILD_CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls else