* [PATCH] kbuild: consolidate Clang compiler flags
@ 2018-11-05 2:48 Masahiro Yamada
2018-11-05 9:09 ` Stefan Agner
0 siblings, 1 reply; 4+ messages in thread
From: Masahiro Yamada @ 2018-11-05 2:48 UTC (permalink / raw)
To: linux-kbuild
Cc: Kees Cook, Nick Desaulniers, Stefan Agner, Matthias Kaehlcke,
Chris Fries, Joel Stanley, Daniel Axtens, Masahiro Yamada,
Michal Marek, linux-kernel
Add basic options for Clang such as --target, --prefix, --gcc-toolchain,
-no-integrated-as to a single variable CLANG_FLAGS.
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---
Makefile | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/Makefile b/Makefile
index 93315eb..58c838a 100644
--- a/Makefile
+++ b/Makefile
@@ -487,18 +487,17 @@ endif
ifneq ($(shell $(CC) --version 2>&1 | head -n 1 | grep clang),)
ifneq ($(CROSS_COMPILE),)
-CLANG_TARGET := --target=$(notdir $(CROSS_COMPILE:%-=%))
+CLANG_FLAGS = --target=$(notdir $(CROSS_COMPILE:%-=%))
GCC_TOOLCHAIN_DIR := $(dir $(shell which $(LD)))
-CLANG_PREFIX := --prefix=$(GCC_TOOLCHAIN_DIR)
+CLANG_FLAGS += --prefix=$(GCC_TOOLCHAIN_DIR)
GCC_TOOLCHAIN := $(realpath $(GCC_TOOLCHAIN_DIR)/..)
endif
ifneq ($(GCC_TOOLCHAIN),)
-CLANG_GCC_TC := --gcc-toolchain=$(GCC_TOOLCHAIN)
+CLANG_FLAGS += --gcc-toolchain=$(GCC_TOOLCHAIN)
endif
-KBUILD_CFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC) $(CLANG_PREFIX)
-KBUILD_AFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC) $(CLANG_PREFIX)
-KBUILD_CFLAGS += $(call cc-option, -no-integrated-as)
-KBUILD_AFLAGS += $(call cc-option, -no-integrated-as)
+CLANG_FLAGS += $(call cc-option, -no-integrated-as)
+KBUILD_CFLAGS += $(CLANG_FLAGS)
+KBUILD_AFLAGS += $(CLANG_FLAGS)
endif
RETPOLINE_CFLAGS_GCC := -mindirect-branch=thunk-extern -mindirect-branch-register
--
2.7.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] kbuild: consolidate Clang compiler flags
2018-11-05 2:48 [PATCH] kbuild: consolidate Clang compiler flags Masahiro Yamada
@ 2018-11-05 9:09 ` Stefan Agner
2018-11-05 9:18 ` Masahiro Yamada
0 siblings, 1 reply; 4+ messages in thread
From: Stefan Agner @ 2018-11-05 9:09 UTC (permalink / raw)
To: Masahiro Yamada
Cc: linux-kbuild, Kees Cook, Nick Desaulniers, Matthias Kaehlcke,
Chris Fries, Joel Stanley, Daniel Axtens, Michal Marek,
linux-kernel
On 05.11.2018 03:48, Masahiro Yamada wrote:
> Add basic options for Clang such as --target, --prefix, --gcc-toolchain,
> -no-integrated-as to a single variable CLANG_FLAGS.
>
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
> ---
>
> Makefile | 13 ++++++-------
> 1 file changed, 6 insertions(+), 7 deletions(-)
>
> diff --git a/Makefile b/Makefile
> index 93315eb..58c838a 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -487,18 +487,17 @@ endif
>
> ifneq ($(shell $(CC) --version 2>&1 | head -n 1 | grep clang),)
> ifneq ($(CROSS_COMPILE),)
> -CLANG_TARGET := --target=$(notdir $(CROSS_COMPILE:%-=%))
> +CLANG_FLAGS = --target=$(notdir $(CROSS_COMPILE:%-=%))
> GCC_TOOLCHAIN_DIR := $(dir $(shell which $(LD)))
> -CLANG_PREFIX := --prefix=$(GCC_TOOLCHAIN_DIR)
> +CLANG_FLAGS += --prefix=$(GCC_TOOLCHAIN_DIR)
So this will expand later now, is this ok?
--
Stefan
> GCC_TOOLCHAIN := $(realpath $(GCC_TOOLCHAIN_DIR)/..)
> endif
> ifneq ($(GCC_TOOLCHAIN),)
> -CLANG_GCC_TC := --gcc-toolchain=$(GCC_TOOLCHAIN)
> +CLANG_FLAGS += --gcc-toolchain=$(GCC_TOOLCHAIN)
> endif
> -KBUILD_CFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC) $(CLANG_PREFIX)
> -KBUILD_AFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC) $(CLANG_PREFIX)
> -KBUILD_CFLAGS += $(call cc-option, -no-integrated-as)
> -KBUILD_AFLAGS += $(call cc-option, -no-integrated-as)
> +CLANG_FLAGS += $(call cc-option, -no-integrated-as)
> +KBUILD_CFLAGS += $(CLANG_FLAGS)
> +KBUILD_AFLAGS += $(CLANG_FLAGS)
> endif
>
> RETPOLINE_CFLAGS_GCC := -mindirect-branch=thunk-extern
> -mindirect-branch-register
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] kbuild: consolidate Clang compiler flags
2018-11-05 9:09 ` Stefan Agner
@ 2018-11-05 9:18 ` Masahiro Yamada
2018-11-05 17:59 ` Nick Desaulniers
0 siblings, 1 reply; 4+ messages in thread
From: Masahiro Yamada @ 2018-11-05 9:18 UTC (permalink / raw)
To: Stefan Agner
Cc: Linux Kbuild mailing list, Kees Cook, Nick Desaulniers,
Matthias Kaehlcke, Chris Fries, Joel Stanley, dja, Michal Marek,
Linux Kernel Mailing List
On Mon, Nov 5, 2018 at 6:10 PM Stefan Agner <stefan@agner.ch> wrote:
>
> On 05.11.2018 03:48, Masahiro Yamada wrote:
> > Add basic options for Clang such as --target, --prefix, --gcc-toolchain,
> > -no-integrated-as to a single variable CLANG_FLAGS.
> >
> > Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
> > ---
> >
> > Makefile | 13 ++++++-------
> > 1 file changed, 6 insertions(+), 7 deletions(-)
> >
> > diff --git a/Makefile b/Makefile
> > index 93315eb..58c838a 100644
> > --- a/Makefile
> > +++ b/Makefile
> > @@ -487,18 +487,17 @@ endif
> >
> > ifneq ($(shell $(CC) --version 2>&1 | head -n 1 | grep clang),)
> > ifneq ($(CROSS_COMPILE),)
> > -CLANG_TARGET := --target=$(notdir $(CROSS_COMPILE:%-=%))
> > +CLANG_FLAGS = --target=$(notdir $(CROSS_COMPILE:%-=%))
> > GCC_TOOLCHAIN_DIR := $(dir $(shell which $(LD)))
> > -CLANG_PREFIX := --prefix=$(GCC_TOOLCHAIN_DIR)
> > +CLANG_FLAGS += --prefix=$(GCC_TOOLCHAIN_DIR)
>
> So this will expand later now, is this ok?
>
> --
> Stefan
>
> > GCC_TOOLCHAIN := $(realpath $(GCC_TOOLCHAIN_DIR)/..)
> > endif
> > ifneq ($(GCC_TOOLCHAIN),)
> > -CLANG_GCC_TC := --gcc-toolchain=$(GCC_TOOLCHAIN)
> > +CLANG_FLAGS += --gcc-toolchain=$(GCC_TOOLCHAIN)
> > endif
> > -KBUILD_CFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC) $(CLANG_PREFIX)
> > -KBUILD_AFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC) $(CLANG_PREFIX)
> > -KBUILD_CFLAGS += $(call cc-option, -no-integrated-as)
> > -KBUILD_AFLAGS += $(call cc-option, -no-integrated-as)
> > +CLANG_FLAGS += $(call cc-option, -no-integrated-as)
> > +KBUILD_CFLAGS += $(CLANG_FLAGS)
> > +KBUILD_AFLAGS += $(CLANG_FLAGS)
CLANG_FLAGS is expanded here because KBUILD_CFLAGS and KBUILD_AFLAGS
are defined by using :=
So, it should be OK, but turning CLANG_FLAGS into a simple variable
will be a little more efficient since $(call cc-option, -no-integrated-as)
is evaluated just once.
(Or, this cc-option may not be necessary any longer.)
Will send v2.
Thanks.
> > endif
> >
> > RETPOLINE_CFLAGS_GCC := -mindirect-branch=thunk-extern
> > -mindirect-branch-register
--
Best Regards
Masahiro Yamada
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] kbuild: consolidate Clang compiler flags
2018-11-05 9:18 ` Masahiro Yamada
@ 2018-11-05 17:59 ` Nick Desaulniers
0 siblings, 0 replies; 4+ messages in thread
From: Nick Desaulniers @ 2018-11-05 17:59 UTC (permalink / raw)
To: Masahiro Yamada
Cc: Stefan Agner, Linux Kbuild mailing list, Kees Cook,
Matthias Kaehlcke, Chris Fries, joel, dja, Michal Marek, LKML
On Mon, Nov 5, 2018 at 1:19 AM Masahiro Yamada
<yamada.masahiro@socionext.com> wrote:
>
> On Mon, Nov 5, 2018 at 6:10 PM Stefan Agner <stefan@agner.ch> wrote:
> >
> > On 05.11.2018 03:48, Masahiro Yamada wrote:
> > > Add basic options for Clang such as --target, --prefix, --gcc-toolchain,
> > > -no-integrated-as to a single variable CLANG_FLAGS.
> > >
> > > Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
> > > ---
> > >
> > > Makefile | 13 ++++++-------
> > > 1 file changed, 6 insertions(+), 7 deletions(-)
> > >
> > > diff --git a/Makefile b/Makefile
> > > index 93315eb..58c838a 100644
> > > --- a/Makefile
> > > +++ b/Makefile
> > > @@ -487,18 +487,17 @@ endif
> > >
> > > ifneq ($(shell $(CC) --version 2>&1 | head -n 1 | grep clang),)
> > > ifneq ($(CROSS_COMPILE),)
> > > -CLANG_TARGET := --target=$(notdir $(CROSS_COMPILE:%-=%))
> > > +CLANG_FLAGS = --target=$(notdir $(CROSS_COMPILE:%-=%))
> > > GCC_TOOLCHAIN_DIR := $(dir $(shell which $(LD)))
> > > -CLANG_PREFIX := --prefix=$(GCC_TOOLCHAIN_DIR)
> > > +CLANG_FLAGS += --prefix=$(GCC_TOOLCHAIN_DIR)
> >
> > So this will expand later now, is this ok?
> >
> > --
> > Stefan
> >
> > > GCC_TOOLCHAIN := $(realpath $(GCC_TOOLCHAIN_DIR)/..)
> > > endif
> > > ifneq ($(GCC_TOOLCHAIN),)
> > > -CLANG_GCC_TC := --gcc-toolchain=$(GCC_TOOLCHAIN)
> > > +CLANG_FLAGS += --gcc-toolchain=$(GCC_TOOLCHAIN)
> > > endif
> > > -KBUILD_CFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC) $(CLANG_PREFIX)
> > > -KBUILD_AFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC) $(CLANG_PREFIX)
> > > -KBUILD_CFLAGS += $(call cc-option, -no-integrated-as)
> > > -KBUILD_AFLAGS += $(call cc-option, -no-integrated-as)
> > > +CLANG_FLAGS += $(call cc-option, -no-integrated-as)
> > > +KBUILD_CFLAGS += $(CLANG_FLAGS)
> > > +KBUILD_AFLAGS += $(CLANG_FLAGS)
>
>
> CLANG_FLAGS is expanded here because KBUILD_CFLAGS and KBUILD_AFLAGS
> are defined by using :=
>
> So, it should be OK, but turning CLANG_FLAGS into a simple variable
> will be a little more efficient since $(call cc-option, -no-integrated-as)
> is evaluated just once.
>
> (Or, this cc-option may not be necessary any longer.)
>
> Will send v2.
If the ultimate goal is not evaluate cc-option more than once,
removing cc-option from both KBUILD_CFLAGS and KBUILD_AFLAGS for clang
is the better approach; we always want those for clang
unconditionally. And if you by chance have an ancient version of clang
that doesn't support those flags, you wont be able to compile a kernel
anyways. Eventually we want to get Clang's integrated assembler in
shape to be used to assemble the kernel, but I think we're a ways off
there still.
--
Thanks,
~Nick Desaulniers
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-11-05 17:59 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-05 2:48 [PATCH] kbuild: consolidate Clang compiler flags Masahiro Yamada
2018-11-05 9:09 ` Stefan Agner
2018-11-05 9:18 ` Masahiro Yamada
2018-11-05 17:59 ` Nick Desaulniers
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).