* [PATCH] kbuild: do not call cc-option before KBUILD_CFLAGS initialization
@ 2017-10-12 9:22 Masahiro Yamada
2017-10-12 17:12 ` Doug Anderson
2017-10-18 16:53 ` Masahiro Yamada
0 siblings, 2 replies; 3+ messages in thread
From: Masahiro Yamada @ 2017-10-12 9:22 UTC (permalink / raw)
To: linux-kbuild
Cc: Sam Ravnborg, Douglas Anderson, Masahiro Yamada, Michal Marek,
linux-kernel
Some $(call cc-option,...) are invoked very early, even before
KBUILD_CFLAGS, etc. are initialized.
The returned string from $(call cc-option,...) depends on
KBUILD_CPPFLAGS, KBUILD_CFLAGS, and GCC_PLUGINS_CFLAGS.
Since they are exported, they are not empty when the top Makefile
is recursively invoked.
The recursion occurs in several places. For example, the top
Makefile invokes itself for silentoldconfig. "make tinyconfig",
"make rpm-pkg" are the cases, too.
In those cases, the second call of cc-option from the same line
runs a different shell command due to non-pristine KBUILD_CFLAGS.
To get the same result all the time, KBUILD_* and GCC_PLUGINS_CFLAGS
must be initialized before any call of cc-option. This avoids
garbage data in the .cache.mk file.
Move all calls of cc-option below the config targets because target
compiler flags are unnecessary for Kconfig.
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---
Makefile | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/Makefile b/Makefile
index e5c20ee..2c4a238 100644
--- a/Makefile
+++ b/Makefile
@@ -392,9 +392,6 @@ LDFLAGS_MODULE =
CFLAGS_KERNEL =
AFLAGS_KERNEL =
LDFLAGS_vmlinux =
-CFLAGS_GCOV := -fprofile-arcs -ftest-coverage -fno-tree-loop-im $(call cc-disable-warning,maybe-uninitialized,)
-CFLAGS_KCOV := $(call cc-option,-fsanitize-coverage=trace-pc,)
-
# Use USERINCLUDE when you must reference the UAPI directories only.
USERINCLUDE := \
@@ -413,21 +410,19 @@ LINUXINCLUDE := \
-I$(objtree)/include \
$(USERINCLUDE)
-KBUILD_CPPFLAGS := -D__KERNEL__
-
+KBUILD_AFLAGS := -D__ASSEMBLY__
KBUILD_CFLAGS := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
-fno-strict-aliasing -fno-common -fshort-wchar \
-Werror-implicit-function-declaration \
-Wno-format-security \
- -std=gnu89 $(call cc-option,-fno-PIE)
-
-
+ -std=gnu89
+KBUILD_CPPFLAGS := -D__KERNEL__
KBUILD_AFLAGS_KERNEL :=
KBUILD_CFLAGS_KERNEL :=
-KBUILD_AFLAGS := -D__ASSEMBLY__ $(call cc-option,-fno-PIE)
KBUILD_AFLAGS_MODULE := -DMODULE
KBUILD_CFLAGS_MODULE := -DMODULE
KBUILD_LDFLAGS_MODULE := -T $(srctree)/scripts/module-common.lds
+GCC_PLUGINS_CFLAGS :=
export ARCH SRCARCH CONFIG_SHELL HOSTCC HOSTCFLAGS CROSS_COMPILE AS LD CC
export CPP AR NM STRIP OBJCOPY OBJDUMP HOSTLDFLAGS HOST_LOADLIBES
@@ -435,7 +430,7 @@ export MAKE AWK GENKSYMS INSTALLKERNEL PERL PYTHON UTS_MACHINE
export HOSTCXX HOSTCXXFLAGS LDFLAGS_MODULE CHECK CHECKFLAGS
export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS LDFLAGS
-export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE CFLAGS_GCOV CFLAGS_KCOV CFLAGS_KASAN CFLAGS_UBSAN
+export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE CFLAGS_KASAN CFLAGS_UBSAN
export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE
export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_LDFLAGS_MODULE
export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL
@@ -607,6 +602,12 @@ endif
# Defaults to vmlinux, but the arch makefile usually adds further targets
all: vmlinux
+KBUILD_CFLAGS += $(call cc-option,-fno-PIE)
+KBUILD_AFLAGS += $(call cc-option,-fno-PIE)
+CFLAGS_GCOV := -fprofile-arcs -ftest-coverage -fno-tree-loop-im $(call cc-disable-warning,maybe-uninitialized,)
+CFLAGS_KCOV := $(call cc-option,-fsanitize-coverage=trace-pc,)
+export CFLAGS_GCOV CFLAGS_KCOV
+
# The arch Makefile can set ARCH_{CPP,A,C}FLAGS to override the default
# values of the respective KBUILD_* variables
ARCH_CPPFLAGS :=
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] kbuild: do not call cc-option before KBUILD_CFLAGS initialization
2017-10-12 9:22 [PATCH] kbuild: do not call cc-option before KBUILD_CFLAGS initialization Masahiro Yamada
@ 2017-10-12 17:12 ` Doug Anderson
2017-10-18 16:53 ` Masahiro Yamada
1 sibling, 0 replies; 3+ messages in thread
From: Doug Anderson @ 2017-10-12 17:12 UTC (permalink / raw)
To: Masahiro Yamada
Cc: Linux Kbuild mailing list, Sam Ravnborg, Michal Marek, linux-kernel
Hi,
On Thu, Oct 12, 2017 at 2:22 AM, Masahiro Yamada
<yamada.masahiro@socionext.com> wrote:
> Some $(call cc-option,...) are invoked very early, even before
> KBUILD_CFLAGS, etc. are initialized.
>
> The returned string from $(call cc-option,...) depends on
> KBUILD_CPPFLAGS, KBUILD_CFLAGS, and GCC_PLUGINS_CFLAGS.
>
> Since they are exported, they are not empty when the top Makefile
> is recursively invoked.
>
> The recursion occurs in several places. For example, the top
> Makefile invokes itself for silentoldconfig. "make tinyconfig",
> "make rpm-pkg" are the cases, too.
>
> In those cases, the second call of cc-option from the same line
> runs a different shell command due to non-pristine KBUILD_CFLAGS.
>
> To get the same result all the time, KBUILD_* and GCC_PLUGINS_CFLAGS
> must be initialized before any call of cc-option. This avoids
> garbage data in the .cache.mk file.
>
> Move all calls of cc-option below the config targets because target
> compiler flags are unnecessary for Kconfig.
>
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
> ---
>
> Makefile | 21 +++++++++++----------
> 1 file changed, 11 insertions(+), 10 deletions(-)
I can't pretend that I know of all the subtleties involved in the
twisty turny passages of the kernel Makefiles, but as far as I can
tell this looks good. Thanks!
Reviewed-by: Douglas Anderson <dianders@chromium.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] kbuild: do not call cc-option before KBUILD_CFLAGS initialization
2017-10-12 9:22 [PATCH] kbuild: do not call cc-option before KBUILD_CFLAGS initialization Masahiro Yamada
2017-10-12 17:12 ` Doug Anderson
@ 2017-10-18 16:53 ` Masahiro Yamada
1 sibling, 0 replies; 3+ messages in thread
From: Masahiro Yamada @ 2017-10-18 16:53 UTC (permalink / raw)
To: Linux Kbuild mailing list
Cc: Sam Ravnborg, Douglas Anderson, Masahiro Yamada, Michal Marek,
Linux Kernel Mailing List
2017-10-12 18:22 GMT+09:00 Masahiro Yamada <yamada.masahiro@socionext.com>:
> Some $(call cc-option,...) are invoked very early, even before
> KBUILD_CFLAGS, etc. are initialized.
>
> The returned string from $(call cc-option,...) depends on
> KBUILD_CPPFLAGS, KBUILD_CFLAGS, and GCC_PLUGINS_CFLAGS.
>
> Since they are exported, they are not empty when the top Makefile
> is recursively invoked.
>
> The recursion occurs in several places. For example, the top
> Makefile invokes itself for silentoldconfig. "make tinyconfig",
> "make rpm-pkg" are the cases, too.
>
> In those cases, the second call of cc-option from the same line
> runs a different shell command due to non-pristine KBUILD_CFLAGS.
>
> To get the same result all the time, KBUILD_* and GCC_PLUGINS_CFLAGS
> must be initialized before any call of cc-option. This avoids
> garbage data in the .cache.mk file.
>
> Move all calls of cc-option below the config targets because target
> compiler flags are unnecessary for Kconfig.
>
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
> ---
Applied to linux-kbuild/kbuild.
--
Best Regards
Masahiro Yamada
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-10-18 16:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-12 9:22 [PATCH] kbuild: do not call cc-option before KBUILD_CFLAGS initialization Masahiro Yamada
2017-10-12 17:12 ` Doug Anderson
2017-10-18 16:53 ` Masahiro Yamada
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).