Alexey reported that the fraction of unknown filename instances in
kallsyms grew from ~0.3% to ~10% recently; Bill and Greg tracked it down
to assembler defined symbols, which regressed as a result of:
commit b8a9092330da ("Kbuild: do not emit debug info for assembly with LLVM_IAS=1")
In that commit, I allude to restoring debug info for assembler defined
symbols in a follow up patch, but it seems I forgot to do so in
commit a66049e2cf0e ("Kbuild: make DWARF version a choice")
Do so requires a fixup for as-option, which seems to be failing when
used in scripts/Makefile.debug.
Also includes a fix for DEBUG_INFO_SPLIT while I'm here. Dmitrii
reports that this has been broken since gcc-11+ & clang-12+. I'm
guessing no one uses this .config option...since no one else has
reported it being broken yet...
Changes from v1 -> v2:
* 5 patches now, rather than 3.
* Split change to arch/x86/boot/compressed/Makefile off of first patch,
as per Masahiro.
* Introduce compiler specific macros, as per Bill, and eradicate
cc-ifversion while I'm at it.
* Update commit message of final patch to refer to 866ced950bcd.
v1: https://lore.kernel.org/llvm/[email protected]/
Nick Desaulniers (5):
x86/boot/compressed: prefer cc-option for CFLAGS additions
Makefile.compiler: Use KBUILD_AFLAGS for as-option
Makefile.compiler: replace cc-ifversion with compiler-specific macros
Makefile.debug: re-enable debug info for .S files
Makefile.debug: set -g unconditional on CONFIG_DEBUG_INFO_SPLIT
Documentation/kbuild/makefiles.rst | 44 +++++++++++++++------
Makefile | 4 +-
arch/x86/boot/compressed/Makefile | 2 +-
drivers/gpu/drm/amd/display/dc/dml/Makefile | 12 ++----
scripts/Makefile.compiler | 21 +++++++---
scripts/Makefile.debug | 26 ++++++++----
6 files changed, 72 insertions(+), 37 deletions(-)
--
2.37.2.672.g94769d06f0-goog
cc-ifversion is GCC specific. Replace it with compiler specific
variants. Update the users of cc-ifversion to use these new macros.
Provide a helper for checking compiler versions for GCC and Clang
simultaneously, that will be used in a follow up patch.
Cc: Jonathan Corbet <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Link: https://github.com/ClangBuiltLinux/linux/issues/350
Link: https://lore.kernel.org/llvm/CAGG=3QWSAUakO42kubrCap8fp-gm1ERJJAYXTnP1iHk_wrH=BQ@mail.gmail.com/
Suggested-by: Bill Wendling <[email protected]>
Signed-off-by: Nick Desaulniers <[email protected]>
---
Changes v1 -> v2:
* New patch.
Documentation/kbuild/makefiles.rst | 44 +++++++++++++++------
Makefile | 4 +-
drivers/gpu/drm/amd/display/dc/dml/Makefile | 12 ++----
scripts/Makefile.compiler | 15 +++++--
4 files changed, 49 insertions(+), 26 deletions(-)
diff --git a/Documentation/kbuild/makefiles.rst b/Documentation/kbuild/makefiles.rst
index 11a296e52d68..e46f5b45c422 100644
--- a/Documentation/kbuild/makefiles.rst
+++ b/Documentation/kbuild/makefiles.rst
@@ -682,22 +682,42 @@ more details, with real examples.
In the above example, -Wno-unused-but-set-variable will be added to
KBUILD_CFLAGS only if gcc really accepts it.
- cc-ifversion
- cc-ifversion tests the version of $(CC) and equals the fourth parameter
- if version expression is true, or the fifth (if given) if the version
- expression is false.
+ gcc-min-version
+ gcc-min-version tests if the value of $(CONFIG_GCC_VERSION) is greater than
+ or equal to the provided value and evaluates to y if so.
Example::
- #fs/reiserfs/Makefile
- ccflags-y := $(call cc-ifversion, -lt, 0402, -O1)
+ cflags-$(call gcc-min-version, 70100) := -foo
- In this example, ccflags-y will be assigned the value -O1 if the
- $(CC) version is less than 4.2.
- cc-ifversion takes all the shell operators:
- -eq, -ne, -lt, -le, -gt, and -ge
- The third parameter may be a text as in this example, but it may also
- be an expanded variable or a macro.
+ In this example, cflags-y will be assigned the value -foo if $(CC) is gcc and
+ $(CONFIG_GCC_VERSION) is >= 7.1.
+
+ clang-min-version
+ clang-min-version tests if the value of $(CONFIG_CLANG_VERSION) is greater
+ than or equal to the provided value and evaluates to y if so.
+
+ Example::
+
+ cflags-$(call clang-min-version, 110000) := -foo
+
+ In this example, cflags-y will be assigned the value -foo if $(CC) is clang
+ and $(CONFIG_CLANG_VERSION) is >= 11.0.0.
+
+ cc-min-version
+ cc-min-version tests if the value of $(CONFIG_GCC_VERSION) is greater
+ than or equal to the first value provided, or if the value of
+ $(CONFIG_CLANG_VERSION) is greater than or equal to the second value
+ provided, and evaluates
+ to y if so.
+
+ Example::
+
+ cflags-$(call cc-min-version, 70100, 110000) := -foo
+
+ In this example, cflags-y will be assigned the value -foo if $(CC) is gcc and
+ $(CONFIG_GCC_VERSION) is >= 7.1, or if $(CC) is clang and
+ $(CONFIG_CLANG_VERSION) is >= 11.0.0.
cc-cross-prefix
cc-cross-prefix is used to check if there exists a $(CC) in path with
diff --git a/Makefile b/Makefile
index 952d354069a4..caa39ecb1136 100644
--- a/Makefile
+++ b/Makefile
@@ -972,7 +972,7 @@ ifdef CONFIG_CC_IS_GCC
KBUILD_CFLAGS += -Wno-maybe-uninitialized
endif
-ifdef CONFIG_CC_IS_GCC
+ifeq ($(call gcc-min-version, 90100),y)
# The allocators already balk at large sizes, so silence the compiler
# warnings for bounds checks involving those possible values. While
# -Wno-alloc-size-larger-than would normally be used here, earlier versions
@@ -984,7 +984,7 @@ ifdef CONFIG_CC_IS_GCC
# ignored, continuing to default to PTRDIFF_MAX. So, left with no other
# choice, we must perform a versioned check to disable this warning.
# https://lore.kernel.org/lkml/[email protected]
-KBUILD_CFLAGS += $(call cc-ifversion, -ge, 0901, -Wno-alloc-size-larger-than)
+KBUILD_CFLAGS += -Wno-alloc-size-larger-than
endif
# disable invalid "can't wrap" optimizations for signed / pointers
diff --git a/drivers/gpu/drm/amd/display/dc/dml/Makefile b/drivers/gpu/drm/amd/display/dc/dml/Makefile
index 86a3b5bfd699..d8ee4743b2e3 100644
--- a/drivers/gpu/drm/amd/display/dc/dml/Makefile
+++ b/drivers/gpu/drm/amd/display/dc/dml/Makefile
@@ -33,20 +33,14 @@ ifdef CONFIG_PPC64
dml_ccflags := -mhard-float -maltivec
endif
-ifdef CONFIG_CC_IS_GCC
-ifeq ($(call cc-ifversion, -lt, 0701, y), y)
-IS_OLD_GCC = 1
-endif
-endif
-
ifdef CONFIG_X86
-ifdef IS_OLD_GCC
+ifeq ($(call gcc-min-version, 70100),y)
+dml_ccflags += -msse2
+else
# Stack alignment mismatch, proceed with caution.
# GCC < 7.1 cannot compile code using `double` and -mpreferred-stack-boundary=3
# (8B stack alignment).
dml_ccflags += -mpreferred-stack-boundary=4
-else
-dml_ccflags += -msse2
endif
endif
diff --git a/scripts/Makefile.compiler b/scripts/Makefile.compiler
index d1739f0d3ce3..13dade724fa3 100644
--- a/scripts/Makefile.compiler
+++ b/scripts/Makefile.compiler
@@ -61,9 +61,18 @@ cc-option-yn = $(call try-run,\
cc-disable-warning = $(call try-run,\
$(CC) -Werror $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1)))
-# cc-ifversion
-# Usage: EXTRA_CFLAGS += $(call cc-ifversion, -lt, 0402, -O1)
-cc-ifversion = $(shell [ $(CONFIG_GCC_VERSION)0 $(1) $(2)000 ] && echo $(3) || echo $(4))
+# gcc-min-version
+# Usage: cflags-$(call gcc-min-version, 70100) += -foo
+gcc-min-version = $(shell [ $(CONFIG_GCC_VERSION) -ge $(1) ] && echo y)
+
+# clang-min-version
+# Usage: cflags-$(call clang-min-version, 110000) += -foo
+clang-min-version = $(shell [ $(CONFIG_CLANG_VERSION) -ge $(1) ] && echo y)
+
+# cc-min-version
+# Usage: cflags-$(call cc-min-version, 701000, 110000)
+# ^ GCC ^ Clang
+cc-min-version = $(filter y, $(call gcc-min-version, $(1)), $(call clang-min-version, $(2)))
# ld-option
# Usage: KBUILD_LDFLAGS += $(call ld-option, -X, -Y)
--
2.37.2.672.g94769d06f0-goog
as-instr uses KBUILD_AFLAGS, but as-option uses KBUILD_CFLAGS. This can
cause as-option to fail unexpectedly because clang will emit
-Werror,-Wunused-command-line-argument for various -m and -f flags for
assembler sources.
Callers of as-option (and as-instr) likely want to be adding flags to
KBUILD_AFLAGS/aflags-y, not KBUILD_CFLAGS/cflags-y.
Link: https://github.com/ClangBuiltLinux/linux/issues/1699
Signed-off-by: Nick Desaulniers <[email protected]>
---
Changes v1 -> v2:
* Split off changes to arch/x86/boot/compressed/Makefile into parent
patch, as per Masahiro.
scripts/Makefile.compiler | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/scripts/Makefile.compiler b/scripts/Makefile.compiler
index 94d0d40cddb3..d1739f0d3ce3 100644
--- a/scripts/Makefile.compiler
+++ b/scripts/Makefile.compiler
@@ -29,13 +29,13 @@ try-run = $(shell set -e; \
fi)
# as-option
-# Usage: cflags-y += $(call as-option,-Wa$(comma)-isa=foo,)
+# Usage: aflags-y += $(call as-option,-Wa$(comma)-isa=foo,)
as-option = $(call try-run,\
- $(CC) $(KBUILD_CFLAGS) $(1) -c -x assembler /dev/null -o "$$TMP",$(1),$(2))
+ $(CC) $(KBUILD_AFLAGS) $(1) -c -x assembler /dev/null -o "$$TMP",$(1),$(2))
# as-instr
-# Usage: cflags-y += $(call as-instr,instr,option1,option2)
+# Usage: aflags-y += $(call as-instr,instr,option1,option2)
as-instr = $(call try-run,\
printf "%b\n" "$(1)" | $(CC) $(KBUILD_AFLAGS) -c -x assembler -o "$$TMP" -,$(2),$(3))
--
2.37.2.672.g94769d06f0-goog
Alexey reported that the fraction of unknown filename instances in
kallsyms grew from ~0.3% to ~10% recently; Bill and Greg tracked it down
to assembler defined symbols, which regressed as a result of:
commit b8a9092330da ("Kbuild: do not emit debug info for assembly with LLVM_IAS=1")
In that commit, I allude to restoring debug info for assembler defined
symbols in a follow up patch, but it seems I forgot to do so in
commit a66049e2cf0e ("Kbuild: make DWARF version a choice")
This patch does a few things:
1. Add -g to KBUILD_AFLAGS. This will instruct the compiler to instruct
the assembler to emit debug info. But this can cause an issue for
folks using a newer compiler but older assembler, because the
implicit default DWARF version changed from v4 to v5 in gcc-11 and
clang-14.
2. If the user is using CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT, use a
version check to explicitly set -Wa,-gdwarf-<version> for the
assembler. There's another problem with this; GAS only gained support
for explicit DWARF versions 3-5 in the 2.36 GNU binutils release.
3. Wrap -Wa,-gdwarf-<version> in as-option call to test whether the
assembler supports that explicit DWARF version.
Link: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=31bf18645d98b4d3d7357353be840e320649a67d
Fixes: b8a9092330da ("Kbuild: do not emit debug info for assembly with LLVM_IAS=1")
Reported-by: Alexey Alexandrov <[email protected]>
Reported-by: Bill Wendling <[email protected]>
Reported-by: Greg Thelen <[email protected]>
Signed-off-by: Nick Desaulniers <[email protected]>
---
Changes v1 -> v2:
* Use newly added compiler-specific macros, as per Bill.
scripts/Makefile.debug | 22 ++++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)
diff --git a/scripts/Makefile.debug b/scripts/Makefile.debug
index 9f39b0130551..46e88f0ca998 100644
--- a/scripts/Makefile.debug
+++ b/scripts/Makefile.debug
@@ -4,18 +4,32 @@ ifdef CONFIG_DEBUG_INFO_SPLIT
DEBUG_CFLAGS += -gsplit-dwarf
else
DEBUG_CFLAGS += -g
+KBUILD_AFLAGS += -g
endif
-ifndef CONFIG_AS_IS_LLVM
-KBUILD_AFLAGS += -Wa,-gdwarf-2
+ifdef CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT
+# gcc-11+, clang-14+
+ifeq ($(call cc-min-version, 110000, 140000),y)
+dwarf-version-y := 5
+else
+dwarf-version-y := 4
endif
-
-ifndef CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT
+else # !CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT
dwarf-version-$(CONFIG_DEBUG_INFO_DWARF4) := 4
dwarf-version-$(CONFIG_DEBUG_INFO_DWARF5) := 5
DEBUG_CFLAGS += -gdwarf-$(dwarf-version-y)
endif
+# Binutils 2.35+ (or clang) required for -gdwarf-{4|5}.
+# https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=31bf18645d98b4d3d7357353be840e320649a67d
+ifneq ($(call as-option,-Wa$(comma)-gdwarf-$(dwarf-version-y)),)
+KBUILD_AFLAGS += -Wa,-gdwarf-$(dwarf-version-y)
+else
+ifndef CONFIG_AS_IS_LLVM
+KBUILD_AFLAGS += -Wa,-gdwarf-2
+endif
+endif
+
ifdef CONFIG_DEBUG_INFO_REDUCED
DEBUG_CFLAGS += -fno-var-tracking
ifdef CONFIG_CC_IS_GCC
--
2.37.2.672.g94769d06f0-goog
Dmitrii, Fangrui, and Mashahiro note:
Before GCC 11 and Clang 12 -gsplit-dwarf implicitly uses -g2.
Fix CONFIG_DEBUG_INFO_SPLIT for gcc-11+ & clang-12+ which now need -g
specified in order for -gsplit-dwarf to work at all.
-gsplit-dwarf has been mutually exclusive with -g since support for
CONFIG_DEBUG_INFO_SPLIT was introduced in
commit 866ced950bcd ("kbuild: Support split debug info v4")
I don't think it ever needed to be.
Link: https://lore.kernel.org/lkml/[email protected]/
Link: https://lore.kernel.org/lkml/CAK7LNARPAmsJD5XKAw7m_X2g7Fi-CAAsWDQiP7+ANBjkg7R7ng@mail.gmail.com/
Link: https://reviews.llvm.org/D80391
Cc: Andi Kleen <[email protected]>
Reported-by: Dmitrii Bundin <[email protected]>
Reported-by: Fangrui Song <[email protected]>
Reported-by: Masahiro Yamada <[email protected]>
Suggested-by: Dmitrii Bundin <[email protected]>
Signed-off-by: Nick Desaulniers <[email protected]>
---
Changes v1 -> v2:
* Add reference to 866ced950bcd, cc Andi, in commit message.
scripts/Makefile.debug | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/scripts/Makefile.debug b/scripts/Makefile.debug
index 46e88f0ca998..b6eb532af3cc 100644
--- a/scripts/Makefile.debug
+++ b/scripts/Makefile.debug
@@ -1,10 +1,8 @@
-DEBUG_CFLAGS :=
+DEBUG_CFLAGS := -g
+KBUILD_AFLAGS += -g
ifdef CONFIG_DEBUG_INFO_SPLIT
DEBUG_CFLAGS += -gsplit-dwarf
-else
-DEBUG_CFLAGS += -g
-KBUILD_AFLAGS += -g
endif
ifdef CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT
--
2.37.2.672.g94769d06f0-goog
On Wed, Aug 31, 2022 at 11:44:05AM -0700, Nick Desaulniers wrote:
> as-instr uses KBUILD_AFLAGS, but as-option uses KBUILD_CFLAGS. This can
> cause as-option to fail unexpectedly because clang will emit
> -Werror,-Wunused-command-line-argument for various -m and -f flags for
> assembler sources.
Now that I am looking closer at it, where does that '-Werror' come from?
For cc-option, we add it to elevate clang's warnings about unused '-f',
'-m', and '-W' flags to errors so that we do not add those flags.
However, I do not see '-Werror' in as-option. I am going to assume it
came from CONFIG_WERROR, as I believe Android has that turned on by
default. I think that is the real problem: without '-Werror', the only
error that should come from as-option is when an option isn't supported
by the assembler, as clang will still warn but those will not be fatal
but with '-Werror', those warnings turn fatal, causing all subsequent
as-option calls to fail.
Do not get me wrong, I still believe this is the correct fix but I think
it would be good to describe exactly under which conditions this is a
real issue in case we ever have to revisit this.
> Callers of as-option (and as-instr) likely want to be adding flags to
> KBUILD_AFLAGS/aflags-y, not KBUILD_CFLAGS/cflags-y.
>
> Link: https://github.com/ClangBuiltLinux/linux/issues/1699
> Signed-off-by: Nick Desaulniers <[email protected]>
Regardless of changes to the commit message:
Reviewed-by: Nathan Chancellor <[email protected]>
> ---
> Changes v1 -> v2:
> * Split off changes to arch/x86/boot/compressed/Makefile into parent
> patch, as per Masahiro.
>
> scripts/Makefile.compiler | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/scripts/Makefile.compiler b/scripts/Makefile.compiler
> index 94d0d40cddb3..d1739f0d3ce3 100644
> --- a/scripts/Makefile.compiler
> +++ b/scripts/Makefile.compiler
> @@ -29,13 +29,13 @@ try-run = $(shell set -e; \
> fi)
>
> # as-option
> -# Usage: cflags-y += $(call as-option,-Wa$(comma)-isa=foo,)
> +# Usage: aflags-y += $(call as-option,-Wa$(comma)-isa=foo,)
>
> as-option = $(call try-run,\
> - $(CC) $(KBUILD_CFLAGS) $(1) -c -x assembler /dev/null -o "$$TMP",$(1),$(2))
> + $(CC) $(KBUILD_AFLAGS) $(1) -c -x assembler /dev/null -o "$$TMP",$(1),$(2))
>
> # as-instr
> -# Usage: cflags-y += $(call as-instr,instr,option1,option2)
> +# Usage: aflags-y += $(call as-instr,instr,option1,option2)
>
> as-instr = $(call try-run,\
> printf "%b\n" "$(1)" | $(CC) $(KBUILD_AFLAGS) -c -x assembler -o "$$TMP" -,$(2),$(3))
> --
> 2.37.2.672.g94769d06f0-goog
>
On Wed, Aug 31, 2022 at 11:44:06AM -0700, Nick Desaulniers wrote:
> cc-ifversion is GCC specific. Replace it with compiler specific
> variants. Update the users of cc-ifversion to use these new macros.
> Provide a helper for checking compiler versions for GCC and Clang
> simultaneously, that will be used in a follow up patch.
>
> Cc: Jonathan Corbet <[email protected]>
> Cc: [email protected]
> Cc: [email protected]
> Cc: [email protected]
> Link: https://github.com/ClangBuiltLinux/linux/issues/350
> Link: https://lore.kernel.org/llvm/CAGG=3QWSAUakO42kubrCap8fp-gm1ERJJAYXTnP1iHk_wrH=BQ@mail.gmail.com/
> Suggested-by: Bill Wendling <[email protected]>
> Signed-off-by: Nick Desaulniers <[email protected]>
These are so much nicer. I find the name kind of awkward but the only
thing I could come up with that sounded better was 'gcc-is-at-least' or
'clang-is-at-least' and I don't really feel like painting sheds today,
it's hot outside :)
Reviewed-by: Nathan Chancellor <[email protected]>
Some comments below.
> ---
> Changes v1 -> v2:
> * New patch.
>
> Documentation/kbuild/makefiles.rst | 44 +++++++++++++++------
> Makefile | 4 +-
> drivers/gpu/drm/amd/display/dc/dml/Makefile | 12 ++----
> scripts/Makefile.compiler | 15 +++++--
> 4 files changed, 49 insertions(+), 26 deletions(-)
>
> diff --git a/Documentation/kbuild/makefiles.rst b/Documentation/kbuild/makefiles.rst
> index 11a296e52d68..e46f5b45c422 100644
> --- a/Documentation/kbuild/makefiles.rst
> +++ b/Documentation/kbuild/makefiles.rst
> @@ -682,22 +682,42 @@ more details, with real examples.
> In the above example, -Wno-unused-but-set-variable will be added to
> KBUILD_CFLAGS only if gcc really accepts it.
>
> - cc-ifversion
> - cc-ifversion tests the version of $(CC) and equals the fourth parameter
> - if version expression is true, or the fifth (if given) if the version
> - expression is false.
> + gcc-min-version
> + gcc-min-version tests if the value of $(CONFIG_GCC_VERSION) is greater than
> + or equal to the provided value and evaluates to y if so.
>
> Example::
>
> - #fs/reiserfs/Makefile
> - ccflags-y := $(call cc-ifversion, -lt, 0402, -O1)
> + cflags-$(call gcc-min-version, 70100) := -foo
>
> - In this example, ccflags-y will be assigned the value -O1 if the
> - $(CC) version is less than 4.2.
> - cc-ifversion takes all the shell operators:
> - -eq, -ne, -lt, -le, -gt, and -ge
> - The third parameter may be a text as in this example, but it may also
> - be an expanded variable or a macro.
> + In this example, cflags-y will be assigned the value -foo if $(CC) is gcc and
> + $(CONFIG_GCC_VERSION) is >= 7.1.
> +
> + clang-min-version
> + clang-min-version tests if the value of $(CONFIG_CLANG_VERSION) is greater
> + than or equal to the provided value and evaluates to y if so.
> +
> + Example::
> +
> + cflags-$(call clang-min-version, 110000) := -foo
> +
> + In this example, cflags-y will be assigned the value -foo if $(CC) is clang
> + and $(CONFIG_CLANG_VERSION) is >= 11.0.0.
> +
> + cc-min-version
> + cc-min-version tests if the value of $(CONFIG_GCC_VERSION) is greater
> + than or equal to the first value provided, or if the value of
> + $(CONFIG_CLANG_VERSION) is greater than or equal to the second value
> + provided, and evaluates
> + to y if so.
> +
> + Example::
> +
> + cflags-$(call cc-min-version, 70100, 110000) := -foo
> +
> + In this example, cflags-y will be assigned the value -foo if $(CC) is gcc and
> + $(CONFIG_GCC_VERSION) is >= 7.1, or if $(CC) is clang and
> + $(CONFIG_CLANG_VERSION) is >= 11.0.0.
>
> cc-cross-prefix
> cc-cross-prefix is used to check if there exists a $(CC) in path with
> diff --git a/Makefile b/Makefile
> index 952d354069a4..caa39ecb1136 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -972,7 +972,7 @@ ifdef CONFIG_CC_IS_GCC
> KBUILD_CFLAGS += -Wno-maybe-uninitialized
> endif
>
> -ifdef CONFIG_CC_IS_GCC
> +ifeq ($(call gcc-min-version, 90100),y)
> # The allocators already balk at large sizes, so silence the compiler
> # warnings for bounds checks involving those possible values. While
> # -Wno-alloc-size-larger-than would normally be used here, earlier versions
> @@ -984,7 +984,7 @@ ifdef CONFIG_CC_IS_GCC
> # ignored, continuing to default to PTRDIFF_MAX. So, left with no other
> # choice, we must perform a versioned check to disable this warning.
> # https://lore.kernel.org/lkml/[email protected]
> -KBUILD_CFLAGS += $(call cc-ifversion, -ge, 0901, -Wno-alloc-size-larger-than)
> +KBUILD_CFLAGS += -Wno-alloc-size-larger-than
> endif
It might be interesting to move this up to where KBUILD_CFLAGS-y is used
to make it:
KBUILD_CFLAGS-$(call gcc-min-version, 90100) += -Wno-alloc-size-larger-than
But the comment would have to come with so it probably isn't worth
doing. Just throwing it out as an observation.
>
> # disable invalid "can't wrap" optimizations for signed / pointers
> diff --git a/drivers/gpu/drm/amd/display/dc/dml/Makefile b/drivers/gpu/drm/amd/display/dc/dml/Makefile
> index 86a3b5bfd699..d8ee4743b2e3 100644
> --- a/drivers/gpu/drm/amd/display/dc/dml/Makefile
> +++ b/drivers/gpu/drm/amd/display/dc/dml/Makefile
> @@ -33,20 +33,14 @@ ifdef CONFIG_PPC64
> dml_ccflags := -mhard-float -maltivec
> endif
>
> -ifdef CONFIG_CC_IS_GCC
> -ifeq ($(call cc-ifversion, -lt, 0701, y), y)
> -IS_OLD_GCC = 1
> -endif
> -endif
> -
> ifdef CONFIG_X86
> -ifdef IS_OLD_GCC
> +ifeq ($(call gcc-min-version, 70100),y)
> +dml_ccflags += -msse2
I think you just dropped '-msse2' for clang.
I guess this wants to be:
ifeq ($(call cc-min-version, 70100, 110000),y)
but it kind of feels bad to hardcode the kernel's minimum supported
version of clang somewhere that is not super easy to grep for when we
upgrade it (I guess I'll add cc-min-version to my list of things to look
for, in addition to the Kconfig variables). Perhaps we should codify it
in a place that can be used within make (using
'scripts/min-tool-version.sh' even) so that we could do something like:
ifeq ($(call cc-min-version, 70100, $(MIN_CLANG_VERSION)),y)
Up to you though.
> +else
> # Stack alignment mismatch, proceed with caution.
> # GCC < 7.1 cannot compile code using `double` and -mpreferred-stack-boundary=3
> # (8B stack alignment).
> dml_ccflags += -mpreferred-stack-boundary=4
> -else
> -dml_ccflags += -msse2
> endif
> endif
>
> diff --git a/scripts/Makefile.compiler b/scripts/Makefile.compiler
> index d1739f0d3ce3..13dade724fa3 100644
> --- a/scripts/Makefile.compiler
> +++ b/scripts/Makefile.compiler
> @@ -61,9 +61,18 @@ cc-option-yn = $(call try-run,\
> cc-disable-warning = $(call try-run,\
> $(CC) -Werror $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1)))
>
> -# cc-ifversion
> -# Usage: EXTRA_CFLAGS += $(call cc-ifversion, -lt, 0402, -O1)
> -cc-ifversion = $(shell [ $(CONFIG_GCC_VERSION)0 $(1) $(2)000 ] && echo $(3) || echo $(4))
> +# gcc-min-version
> +# Usage: cflags-$(call gcc-min-version, 70100) += -foo
> +gcc-min-version = $(shell [ $(CONFIG_GCC_VERSION) -ge $(1) ] && echo y)
> +
> +# clang-min-version
> +# Usage: cflags-$(call clang-min-version, 110000) += -foo
> +clang-min-version = $(shell [ $(CONFIG_CLANG_VERSION) -ge $(1) ] && echo y)
> +
> +# cc-min-version
> +# Usage: cflags-$(call cc-min-version, 701000, 110000)
> +# ^ GCC ^ Clang
> +cc-min-version = $(filter y, $(call gcc-min-version, $(1)), $(call clang-min-version, $(2)))
>
> # ld-option
> # Usage: KBUILD_LDFLAGS += $(call ld-option, -X, -Y)
> --
> 2.37.2.672.g94769d06f0-goog
>
On Wed, Aug 31, 2022 at 11:44:08AM -0700, Nick Desaulniers wrote:
> Dmitrii, Fangrui, and Mashahiro note:
>
> Before GCC 11 and Clang 12 -gsplit-dwarf implicitly uses -g2.
>
> Fix CONFIG_DEBUG_INFO_SPLIT for gcc-11+ & clang-12+ which now need -g
> specified in order for -gsplit-dwarf to work at all.
>
> -gsplit-dwarf has been mutually exclusive with -g since support for
> CONFIG_DEBUG_INFO_SPLIT was introduced in
> commit 866ced950bcd ("kbuild: Support split debug info v4")
> I don't think it ever needed to be.
>
> Link: https://lore.kernel.org/lkml/[email protected]/
> Link: https://lore.kernel.org/lkml/CAK7LNARPAmsJD5XKAw7m_X2g7Fi-CAAsWDQiP7+ANBjkg7R7ng@mail.gmail.com/
> Link: https://reviews.llvm.org/D80391
> Cc: Andi Kleen <[email protected]>
> Reported-by: Dmitrii Bundin <[email protected]>
> Reported-by: Fangrui Song <[email protected]>
> Reported-by: Masahiro Yamada <[email protected]>
> Suggested-by: Dmitrii Bundin <[email protected]>
> Signed-off-by: Nick Desaulniers <[email protected]>
Reviewed-by: Nathan Chancellor <[email protected]>
> ---
> Changes v1 -> v2:
> * Add reference to 866ced950bcd, cc Andi, in commit message.
>
> scripts/Makefile.debug | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/scripts/Makefile.debug b/scripts/Makefile.debug
> index 46e88f0ca998..b6eb532af3cc 100644
> --- a/scripts/Makefile.debug
> +++ b/scripts/Makefile.debug
> @@ -1,10 +1,8 @@
> -DEBUG_CFLAGS :=
> +DEBUG_CFLAGS := -g
> +KBUILD_AFLAGS += -g
>
> ifdef CONFIG_DEBUG_INFO_SPLIT
> DEBUG_CFLAGS += -gsplit-dwarf
> -else
> -DEBUG_CFLAGS += -g
> -KBUILD_AFLAGS += -g
> endif
>
> ifdef CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT
> --
> 2.37.2.672.g94769d06f0-goog
>
On Wed, Aug 31, 2022 at 11:44:07AM -0700, Nick Desaulniers wrote:
> Alexey reported that the fraction of unknown filename instances in
> kallsyms grew from ~0.3% to ~10% recently; Bill and Greg tracked it down
> to assembler defined symbols, which regressed as a result of:
>
> commit b8a9092330da ("Kbuild: do not emit debug info for assembly with LLVM_IAS=1")
>
> In that commit, I allude to restoring debug info for assembler defined
> symbols in a follow up patch, but it seems I forgot to do so in
>
> commit a66049e2cf0e ("Kbuild: make DWARF version a choice")
>
> This patch does a few things:
> 1. Add -g to KBUILD_AFLAGS. This will instruct the compiler to instruct
> the assembler to emit debug info. But this can cause an issue for
> folks using a newer compiler but older assembler, because the
> implicit default DWARF version changed from v4 to v5 in gcc-11 and
> clang-14.
> 2. If the user is using CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT, use a
> version check to explicitly set -Wa,-gdwarf-<version> for the
> assembler. There's another problem with this; GAS only gained support
> for explicit DWARF versions 3-5 in the 2.36 GNU binutils release.
> 3. Wrap -Wa,-gdwarf-<version> in as-option call to test whether the
> assembler supports that explicit DWARF version.
>
> Link: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=31bf18645d98b4d3d7357353be840e320649a67d
> Fixes: b8a9092330da ("Kbuild: do not emit debug info for assembly with LLVM_IAS=1")
> Reported-by: Alexey Alexandrov <[email protected]>
> Reported-by: Bill Wendling <[email protected]>
> Reported-by: Greg Thelen <[email protected]>
> Signed-off-by: Nick Desaulniers <[email protected]>
Reviewed-by: Nathan Chancellor <[email protected]>
> ---
> Changes v1 -> v2:
> * Use newly added compiler-specific macros, as per Bill.
>
> scripts/Makefile.debug | 22 ++++++++++++++++++----
> 1 file changed, 18 insertions(+), 4 deletions(-)
>
> diff --git a/scripts/Makefile.debug b/scripts/Makefile.debug
> index 9f39b0130551..46e88f0ca998 100644
> --- a/scripts/Makefile.debug
> +++ b/scripts/Makefile.debug
> @@ -4,18 +4,32 @@ ifdef CONFIG_DEBUG_INFO_SPLIT
> DEBUG_CFLAGS += -gsplit-dwarf
> else
> DEBUG_CFLAGS += -g
> +KBUILD_AFLAGS += -g
> endif
>
> -ifndef CONFIG_AS_IS_LLVM
> -KBUILD_AFLAGS += -Wa,-gdwarf-2
> +ifdef CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT
> +# gcc-11+, clang-14+
> +ifeq ($(call cc-min-version, 110000, 140000),y)
> +dwarf-version-y := 5
> +else
> +dwarf-version-y := 4
> endif
> -
> -ifndef CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT
> +else # !CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT
> dwarf-version-$(CONFIG_DEBUG_INFO_DWARF4) := 4
> dwarf-version-$(CONFIG_DEBUG_INFO_DWARF5) := 5
> DEBUG_CFLAGS += -gdwarf-$(dwarf-version-y)
> endif
>
> +# Binutils 2.35+ (or clang) required for -gdwarf-{4|5}.
> +# https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=31bf18645d98b4d3d7357353be840e320649a67d
> +ifneq ($(call as-option,-Wa$(comma)-gdwarf-$(dwarf-version-y)),)
> +KBUILD_AFLAGS += -Wa,-gdwarf-$(dwarf-version-y)
> +else
> +ifndef CONFIG_AS_IS_LLVM
> +KBUILD_AFLAGS += -Wa,-gdwarf-2
> +endif
> +endif
> +
> ifdef CONFIG_DEBUG_INFO_REDUCED
> DEBUG_CFLAGS += -fno-var-tracking
> ifdef CONFIG_CC_IS_GCC
> --
> 2.37.2.672.g94769d06f0-goog
>
On Thu, Sep 1, 2022 at 3:44 AM Nick Desaulniers <[email protected]> wrote:
>
> cc-ifversion is GCC specific. Replace it with compiler specific
> variants. Update the users of cc-ifversion to use these new macros.
> Provide a helper for checking compiler versions for GCC and Clang
> simultaneously, that will be used in a follow up patch.
>
> Cc: Jonathan Corbet <[email protected]>
> Cc: [email protected]
> Cc: [email protected]
> Cc: [email protected]
> Link: https://github.com/ClangBuiltLinux/linux/issues/350
> Link: https://lore.kernel.org/llvm/CAGG=3QWSAUakO42kubrCap8fp-gm1ERJJAYXTnP1iHk_wrH=BQ@mail.gmail.com/
> Suggested-by: Bill Wendling <[email protected]>
> Signed-off-by: Nick Desaulniers <[email protected]>
> ---
> Changes v1 -> v2:
> * New patch.
>
> Documentation/kbuild/makefiles.rst | 44 +++++++++++++++------
> Makefile | 4 +-
> drivers/gpu/drm/amd/display/dc/dml/Makefile | 12 ++----
> scripts/Makefile.compiler | 15 +++++--
> 4 files changed, 49 insertions(+), 26 deletions(-)
>
> diff --git a/Documentation/kbuild/makefiles.rst b/Documentation/kbuild/makefiles.rst
> index 11a296e52d68..e46f5b45c422 100644
> --- a/Documentation/kbuild/makefiles.rst
> +++ b/Documentation/kbuild/makefiles.rst
> @@ -682,22 +682,42 @@ more details, with real examples.
> In the above example, -Wno-unused-but-set-variable will be added to
> KBUILD_CFLAGS only if gcc really accepts it.
>
> - cc-ifversion
> - cc-ifversion tests the version of $(CC) and equals the fourth parameter
> - if version expression is true, or the fifth (if given) if the version
> - expression is false.
> + gcc-min-version
> + gcc-min-version tests if the value of $(CONFIG_GCC_VERSION) is greater than
> + or equal to the provided value and evaluates to y if so.
>
> Example::
>
> - #fs/reiserfs/Makefile
> - ccflags-y := $(call cc-ifversion, -lt, 0402, -O1)
> + cflags-$(call gcc-min-version, 70100) := -foo
>
> - In this example, ccflags-y will be assigned the value -O1 if the
> - $(CC) version is less than 4.2.
> - cc-ifversion takes all the shell operators:
> - -eq, -ne, -lt, -le, -gt, and -ge
> - The third parameter may be a text as in this example, but it may also
> - be an expanded variable or a macro.
> + In this example, cflags-y will be assigned the value -foo if $(CC) is gcc and
> + $(CONFIG_GCC_VERSION) is >= 7.1.
> +
> + clang-min-version
> + clang-min-version tests if the value of $(CONFIG_CLANG_VERSION) is greater
> + than or equal to the provided value and evaluates to y if so.
> +
> + Example::
> +
> + cflags-$(call clang-min-version, 110000) := -foo
> +
> + In this example, cflags-y will be assigned the value -foo if $(CC) is clang
> + and $(CONFIG_CLANG_VERSION) is >= 11.0.0.
> +
> + cc-min-version
> + cc-min-version tests if the value of $(CONFIG_GCC_VERSION) is greater
> + than or equal to the first value provided, or if the value of
> + $(CONFIG_CLANG_VERSION) is greater than or equal to the second value
> + provided, and evaluates
> + to y if so.
> +
> + Example::
> +
> + cflags-$(call cc-min-version, 70100, 110000) := -foo
> +
> + In this example, cflags-y will be assigned the value -foo if $(CC) is gcc and
> + $(CONFIG_GCC_VERSION) is >= 7.1, or if $(CC) is clang and
> + $(CONFIG_CLANG_VERSION) is >= 11.0.0.
>
> cc-cross-prefix
> cc-cross-prefix is used to check if there exists a $(CC) in path with
> diff --git a/Makefile b/Makefile
> index 952d354069a4..caa39ecb1136 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -972,7 +972,7 @@ ifdef CONFIG_CC_IS_GCC
> KBUILD_CFLAGS += -Wno-maybe-uninitialized
> endif
>
> -ifdef CONFIG_CC_IS_GCC
> +ifeq ($(call gcc-min-version, 90100),y)
> # The allocators already balk at large sizes, so silence the compiler
> # warnings for bounds checks involving those possible values. While
> # -Wno-alloc-size-larger-than would normally be used here, earlier versions
> @@ -984,7 +984,7 @@ ifdef CONFIG_CC_IS_GCC
> # ignored, continuing to default to PTRDIFF_MAX. So, left with no other
> # choice, we must perform a versioned check to disable this warning.
> # https://lore.kernel.org/lkml/[email protected]
> -KBUILD_CFLAGS += $(call cc-ifversion, -ge, 0901, -Wno-alloc-size-larger-than)
> +KBUILD_CFLAGS += -Wno-alloc-size-larger-than
> endif
>
> # disable invalid "can't wrap" optimizations for signed / pointers
> diff --git a/drivers/gpu/drm/amd/display/dc/dml/Makefile b/drivers/gpu/drm/amd/display/dc/dml/Makefile
> index 86a3b5bfd699..d8ee4743b2e3 100644
> --- a/drivers/gpu/drm/amd/display/dc/dml/Makefile
> +++ b/drivers/gpu/drm/amd/display/dc/dml/Makefile
> @@ -33,20 +33,14 @@ ifdef CONFIG_PPC64
> dml_ccflags := -mhard-float -maltivec
> endif
>
> -ifdef CONFIG_CC_IS_GCC
> -ifeq ($(call cc-ifversion, -lt, 0701, y), y)
> -IS_OLD_GCC = 1
> -endif
> -endif
> -
> ifdef CONFIG_X86
> -ifdef IS_OLD_GCC
> +ifeq ($(call gcc-min-version, 70100),y)
> +dml_ccflags += -msse2
> +else
> # Stack alignment mismatch, proceed with caution.
> # GCC < 7.1 cannot compile code using `double` and -mpreferred-stack-boundary=3
> # (8B stack alignment).
> dml_ccflags += -mpreferred-stack-boundary=4
> -else
> -dml_ccflags += -msse2
> endif
> endif
>
> diff --git a/scripts/Makefile.compiler b/scripts/Makefile.compiler
> index d1739f0d3ce3..13dade724fa3 100644
> --- a/scripts/Makefile.compiler
> +++ b/scripts/Makefile.compiler
> @@ -61,9 +61,18 @@ cc-option-yn = $(call try-run,\
> cc-disable-warning = $(call try-run,\
> $(CC) -Werror $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1)))
>
> -# cc-ifversion
> -# Usage: EXTRA_CFLAGS += $(call cc-ifversion, -lt, 0402, -O1)
> -cc-ifversion = $(shell [ $(CONFIG_GCC_VERSION)0 $(1) $(2)000 ] && echo $(3) || echo $(4))
> +# gcc-min-version
> +# Usage: cflags-$(call gcc-min-version, 70100) += -foo
> +gcc-min-version = $(shell [ $(CONFIG_GCC_VERSION) -ge $(1) ] && echo y)
> +
> +# clang-min-version
> +# Usage: cflags-$(call clang-min-version, 110000) += -foo
> +clang-min-version = $(shell [ $(CONFIG_CLANG_VERSION) -ge $(1) ] && echo y)
> +
> +# cc-min-version
> +# Usage: cflags-$(call cc-min-version, 701000, 110000)
> +# ^ GCC ^ Clang
> +cc-min-version = $(filter y, $(call gcc-min-version, $(1)), $(call clang-min-version, $(2)))
A more intuitive and more efficient form would be:
cc-min-version = $(or $(call gcc-min-version, $(1)), $(call
clang-min-version, $(2)))
In your implementation, both gcc-min-version and clang-min-version are
expanded before being passed to $(filter ...).
So the shell is always invoked twice.
$(or A, B) is lazily expanded; A is evaluated first.
If and only if A is empty, B is expanded.
If gcc-min-version is met, the shell invocation in clang-min-version
will be short-cut.
But, I do not find a place where cc-min-version is useful.
Looking at the next patch,
# gcc-11+, clang-14+
ifeq ($(call cc-min-version, 110000, 140000),y)
dwarf-version-y := 5
else
dwarf-version-y := 4
endif
... can be written in a more simpler way:
dwarf-version-y := 4
dwarf-version-$(call gcc-min-version, 110000) := 5
dwarf-version-$(call clang-min-version, 140000) := 5
With $(call cc-min-version, 110000, 140000),
you never know the meaning of 110000, 140000
until you see the definition of this macro.
So, you feel like adding the comment "gcc-11+, clang-14+".
The latter form, the code is self-documenting.
> # ld-option
> # Usage: KBUILD_LDFLAGS += $(call ld-option, -X, -Y)
> --
> 2.37.2.672.g94769d06f0-goog
>
--
Best Regards
Masahiro Yamada
On Thu, Sep 1, 2022 at 3:44 AM Nick Desaulniers <[email protected]> wrote:
>
> Alexey reported that the fraction of unknown filename instances in
> kallsyms grew from ~0.3% to ~10% recently; Bill and Greg tracked it down
> to assembler defined symbols, which regressed as a result of:
>
> commit b8a9092330da ("Kbuild: do not emit debug info for assembly with LLVM_IAS=1")
>
> In that commit, I allude to restoring debug info for assembler defined
> symbols in a follow up patch, but it seems I forgot to do so in
>
> commit a66049e2cf0e ("Kbuild: make DWARF version a choice")
>
> This patch does a few things:
> 1. Add -g to KBUILD_AFLAGS. This will instruct the compiler to instruct
> the assembler to emit debug info. But this can cause an issue for
> folks using a newer compiler but older assembler, because the
> implicit default DWARF version changed from v4 to v5 in gcc-11 and
> clang-14.
What kind of bad things happen for "KBUILD_AFLAGS += -g"?
I think 'gcc -g -c -o foo.o foo.S' will invoke 'as --gdwarf-2' as the backend
if gcc is configured to work with old binutils.
> diff --git a/scripts/Makefile.debug b/scripts/Makefile.debug
> index 9f39b0130551..46e88f0ca998 100644
> --- a/scripts/Makefile.debug
> +++ b/scripts/Makefile.debug
> @@ -4,18 +4,32 @@ ifdef CONFIG_DEBUG_INFO_SPLIT
> DEBUG_CFLAGS += -gsplit-dwarf
> else
> DEBUG_CFLAGS += -g
> +KBUILD_AFLAGS += -g
> endif
>
> -ifndef CONFIG_AS_IS_LLVM
> -KBUILD_AFLAGS += -Wa,-gdwarf-2
> +ifdef CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT
> +# gcc-11+, clang-14+
> +ifeq ($(call cc-min-version, 110000, 140000),y)
> +dwarf-version-y := 5
> +else
> +dwarf-version-y := 4
If you explicitly specify the DWARF version
for CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT,
what is the point of CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT?
When CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT=y,
I believe the right thing to do is to pass only -g,
and let the tool do whatever it thinks is appropriate.
> endif
> -
> -ifndef CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT
> +else # !CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT
> dwarf-version-$(CONFIG_DEBUG_INFO_DWARF4) := 4
> dwarf-version-$(CONFIG_DEBUG_INFO_DWARF5) := 5
> DEBUG_CFLAGS += -gdwarf-$(dwarf-version-y)
> endif
>
> +# Binutils 2.35+ (or clang) required for -gdwarf-{4|5}.
> +# https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=31bf18645d98b4d3d7357353be840e320649a67d
> +ifneq ($(call as-option,-Wa$(comma)-gdwarf-$(dwarf-version-y)),)
When is this as-option supposed to fail?
Binutils <= 2.34 always accepts whatever -gdwarf-* option.
Surprisingly or not, it accepts -gdwarf-6, -gdwarf-7, ...
No matter what DWARF version you specify, GAS silently downgrades
it to DWARF-2.
masahiro@zoe:~/tools/binutils-2.34/bin$ ./as --version | head -n 1
GNU assembler (GNU Binutils) 2.34
masahiro@zoe:~/tools/binutils-2.34/bin$ cat /dev/null | ./as -gdwarf-5
-o /dev/null -
masahiro@zoe:~/tools/binutils-2.34/bin$ echo $?
0
masahiro@zoe:~/tools/binutils-2.34/bin$ cat /dev/null | ./as
-gdwarf-100 -o /dev/null -
masahiro@zoe:~/tools/binutils-2.34/bin$ echo $?
0
Overall, I am not convinced with this patch.
Please see the attached patch.
Is there any problem with writing this more simply?
> +KBUILD_AFLAGS += -Wa,-gdwarf-$(dwarf-version-y)
> +else
> +ifndef CONFIG_AS_IS_LLVM
> +KBUILD_AFLAGS += -Wa,-gdwarf-2
> +endif
> +endif
> +
> ifdef CONFIG_DEBUG_INFO_REDUCED
> DEBUG_CFLAGS += -fno-var-tracking
> ifdef CONFIG_CC_IS_GCC
> --
> 2.37.2.672.g94769d06f0-goog
>
--
Best Regards
Masahiro Yamada
On Thu, Sep 1, 2022 at 4:53 AM Nathan Chancellor <[email protected]> wrote:
>
> On Wed, Aug 31, 2022 at 11:44:05AM -0700, Nick Desaulniers wrote:
> > as-instr uses KBUILD_AFLAGS, but as-option uses KBUILD_CFLAGS. This can
> > cause as-option to fail unexpectedly because clang will emit
> > -Werror,-Wunused-command-line-argument for various -m and -f flags for
> > assembler sources.
>
> Now that I am looking closer at it, where does that '-Werror' come from?
The related commit is
c3f0d0bc5b01ad90c45276952802455750444b4f
The previous discussion with Arnd is
https://lore.kernel.org/linux-kbuild/[email protected]/
> For cc-option, we add it to elevate clang's warnings about unused '-f',
> '-m', and '-W' flags to errors so that we do not add those flags.
> However, I do not see '-Werror' in as-option. I am going to assume it
> came from CONFIG_WERROR, as I believe Android has that turned on by
> default.
CONFIG_WERROR is added to CFLAGS.
But, I guess it is more correct to do likewise for others.
(https://patchwork.kernel.org/project/linux-kbuild/patch/[email protected]/)
> I think that is the real problem: without '-Werror', the only
> error that should come from as-option is when an option isn't supported
> by the assembler, as clang will still warn but those will not be fatal
> but with '-Werror', those warnings turn fatal, causing all subsequent
> as-option calls to fail.
Presumably, it is correct to add -Werror to as-option as well.
We have no reason to add it to cc-option, but not to as-option.
I also believe '-x assembler' should be changed to
'-x assembler-with-cpp'.
As I mentioned somewhere before, our assembly code (*.S) is always
preprocessed. There is no *.s file in the kernel source tree.
So, '-x assembler-with-cpp' matches the real situation.
One interesting thing is, clang does not warn
[-Wunused-command-line-argument] for *.S files.
$ clang -fomit-frame-pointer -c -x assembler /dev/null -o /dev/null
clang: warning: argument unused during compilation:
'-fomit-frame-pointer' [-Wunused-command-line-argument]
$ clang -fomit-frame-pointer -c -x assembler-with-cpp /dev/null -o /dev/null
The root cause is we are using '-x assembler', which
never happens in the kernel tree.
To sum up, the code I think correct is:
as-option = $(call try-run,\
$(CC) -Werror $(KBUILD_AFLAGS) $(1) -c -x assembler-with-cpp
/dev/null -o "$$TMP",$(1),$(2))
> Do not get me wrong, I still believe this is the correct fix but I think
> it would be good to describe exactly under which conditions this is a
> real issue in case we ever have to revisit this.
>
> > Callers of as-option (and as-instr) likely want to be adding flags to
> > KBUILD_AFLAGS/aflags-y, not KBUILD_CFLAGS/cflags-y.
> >
> > Link: https://github.com/ClangBuiltLinux/linux/issues/1699
> > Signed-off-by: Nick Desaulniers <[email protected]>
>
> Regardless of changes to the commit message:
>
> Reviewed-by: Nathan Chancellor <[email protected]>
>
> > ---
> > Changes v1 -> v2:
> > * Split off changes to arch/x86/boot/compressed/Makefile into parent
> > patch, as per Masahiro.
> >
> > scripts/Makefile.compiler | 6 +++---
> > 1 file changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/scripts/Makefile.compiler b/scripts/Makefile.compiler
> > index 94d0d40cddb3..d1739f0d3ce3 100644
> > --- a/scripts/Makefile.compiler
> > +++ b/scripts/Makefile.compiler
> > @@ -29,13 +29,13 @@ try-run = $(shell set -e; \
> > fi)
> >
> > # as-option
> > -# Usage: cflags-y += $(call as-option,-Wa$(comma)-isa=foo,)
> > +# Usage: aflags-y += $(call as-option,-Wa$(comma)-isa=foo,)
> >
> > as-option = $(call try-run,\
> > - $(CC) $(KBUILD_CFLAGS) $(1) -c -x assembler /dev/null -o "$$TMP",$(1),$(2))
> > + $(CC) $(KBUILD_AFLAGS) $(1) -c -x assembler /dev/null -o "$$TMP",$(1),$(2))
> >
> > # as-instr
> > -# Usage: cflags-y += $(call as-instr,instr,option1,option2)
> > +# Usage: aflags-y += $(call as-instr,instr,option1,option2)
> >
> > as-instr = $(call try-run,\
> > printf "%b\n" "$(1)" | $(CC) $(KBUILD_AFLAGS) -c -x assembler -o "$$TMP" -,$(2),$(3))
> > --
> > 2.37.2.672.g94769d06f0-goog
> >
--
Best Regards
Masahiro Yamada
On Mon, Sep 05, 2022 at 06:09:28PM +0900, Masahiro Yamada wrote:
> On Thu, Sep 1, 2022 at 4:53 AM Nathan Chancellor <[email protected]> wrote:
> >
> > On Wed, Aug 31, 2022 at 11:44:05AM -0700, Nick Desaulniers wrote:
> > > as-instr uses KBUILD_AFLAGS, but as-option uses KBUILD_CFLAGS. This can
> > > cause as-option to fail unexpectedly because clang will emit
> > > -Werror,-Wunused-command-line-argument for various -m and -f flags for
> > > assembler sources.
> >
> > Now that I am looking closer at it, where does that '-Werror' come from?
>
> The related commit is
> c3f0d0bc5b01ad90c45276952802455750444b4f
>
> The previous discussion with Arnd is
> https://lore.kernel.org/linux-kbuild/[email protected]/
Right, although this is for cc-option, not as-option, no?
> > For cc-option, we add it to elevate clang's warnings about unused '-f',
> > '-m', and '-W' flags to errors so that we do not add those flags.
> > However, I do not see '-Werror' in as-option. I am going to assume it
> > came from CONFIG_WERROR, as I believe Android has that turned on by
> > default.
>
> CONFIG_WERROR is added to CFLAGS.
> But, I guess it is more correct to do likewise for others.
> (https://patchwork.kernel.org/project/linux-kbuild/patch/[email protected]/)
Ack.
> > I think that is the real problem: without '-Werror', the only
> > error that should come from as-option is when an option isn't supported
> > by the assembler, as clang will still warn but those will not be fatal
> > but with '-Werror', those warnings turn fatal, causing all subsequent
> > as-option calls to fail.
>
> Presumably, it is correct to add -Werror to as-option as well.
> We have no reason to add it to cc-option, but not to as-option.
>
> I also believe '-x assembler' should be changed to
> '-x assembler-with-cpp'.
>
> As I mentioned somewhere before, our assembly code (*.S) is always
> preprocessed. There is no *.s file in the kernel source tree.
>
> So, '-x assembler-with-cpp' matches the real situation.
All good points, I think that is a good fix as well.
> One interesting thing is, clang does not warn
> [-Wunused-command-line-argument] for *.S files.
>
> $ clang -fomit-frame-pointer -c -x assembler /dev/null -o /dev/null
> clang: warning: argument unused during compilation:
> '-fomit-frame-pointer' [-Wunused-command-line-argument]
>
> $ clang -fomit-frame-pointer -c -x assembler-with-cpp /dev/null -o /dev/null
Interesting... I suspect that is likely intentional, as some compiler
flags could be used during preprocessing (it's come up before:
https://github.com/llvm/llvm-project/issues/55656) but I was not able to
figure out exactly where in clang the flags were consumed but Driver.cpp
is quite large and I didn't look too hard :)
More importantly, it still allows us to catch invalid assembler
arguments:
$ clang -c -x assembler-with-cpp /dev/null -o /dev/null -Wa,-foo
clang-16: error: unsupported argument '-foo' to option '-Wa,'
$ clang -c -x assembler-with-cpp /dev/null -o /dev/null -Wa,--noexecstack
> The root cause is we are using '-x assembler', which
> never happens in the kernel tree.
>
> To sum up, the code I think correct is:
>
> as-option = $(call try-run,\
> $(CC) -Werror $(KBUILD_AFLAGS) $(1) -c -x assembler-with-cpp
> /dev/null -o "$$TMP",$(1),$(2))
>
Agreed. Thank you as always for your feedback!
Cheers,
Nathan
On Mon, Sep 5, 2022 at 2:11 AM Masahiro Yamada <[email protected]> wrote:
>
> On Thu, Sep 1, 2022 at 4:53 AM Nathan Chancellor <[email protected]> wrote:
> >
> > On Wed, Aug 31, 2022 at 11:44:05AM -0700, Nick Desaulniers wrote:
> > > as-instr uses KBUILD_AFLAGS, but as-option uses KBUILD_CFLAGS. This can
> > > cause as-option to fail unexpectedly because clang will emit
> > > -Werror,-Wunused-command-line-argument for various -m and -f flags for
> > > assembler sources.
> >
> > Now that I am looking closer at it, where does that '-Werror' come from?
>
>
>
>
> The related commit is
> c3f0d0bc5b01ad90c45276952802455750444b4f
>
> The previous discussion with Arnd is
> https://lore.kernel.org/linux-kbuild/[email protected]/
>
>
>
>
>
> > For cc-option, we add it to elevate clang's warnings about unused '-f',
> > '-m', and '-W' flags to errors so that we do not add those flags.
> > However, I do not see '-Werror' in as-option. I am going to assume it
> > came from CONFIG_WERROR, as I believe Android has that turned on by
> > default.
>
>
> CONFIG_WERROR is added to CFLAGS.
> But, I guess it is more correct to do likewise for others.
> (https://patchwork.kernel.org/project/linux-kbuild/patch/[email protected]/)
>
>
>
> > I think that is the real problem: without '-Werror', the only
> > error that should come from as-option is when an option isn't supported
> > by the assembler, as clang will still warn but those will not be fatal
> > but with '-Werror', those warnings turn fatal, causing all subsequent
> > as-option calls to fail.
>
>
>
> Presumably, it is correct to add -Werror to as-option as well.
> We have no reason to add it to cc-option, but not to as-option.
>
>
>
>
> I also believe '-x assembler' should be changed to
> '-x assembler-with-cpp'.
>
>
> As I mentioned somewhere before, our assembly code (*.S) is always
> preprocessed. There is no *.s file in the kernel source tree.
>
>
> So, '-x assembler-with-cpp' matches the real situation.
Should I do this for as-instr then as well? In the same patch?
>
>
> One interesting thing is, clang does not warn
> [-Wunused-command-line-argument] for *.S files.
>
>
>
>
> $ clang -fomit-frame-pointer -c -x assembler /dev/null -o /dev/null
> clang: warning: argument unused during compilation:
> '-fomit-frame-pointer' [-Wunused-command-line-argument]
>
> $ clang -fomit-frame-pointer -c -x assembler-with-cpp /dev/null -o /dev/null
>
>
>
> The root cause is we are using '-x assembler', which
> never happens in the kernel tree.
>
>
>
>
> To sum up, the code I think correct is:
>
>
> as-option = $(call try-run,\
> $(CC) -Werror $(KBUILD_AFLAGS) $(1) -c -x assembler-with-cpp
> /dev/null -o "$$TMP",$(1),$(2))
Does your recent patch affect this?
https://lore.kernel.org/linux-kbuild/[email protected]/
If so, then I should not add -Werror as you suggest above?
--
Thanks,
~Nick Desaulniers
On Mon, Sep 5, 2022 at 12:50 AM Masahiro Yamada <[email protected]> wrote:
>
> On Thu, Sep 1, 2022 at 3:44 AM Nick Desaulniers <[email protected]> wrote:
> >
> > Alexey reported that the fraction of unknown filename instances in
> > kallsyms grew from ~0.3% to ~10% recently; Bill and Greg tracked it down
> > to assembler defined symbols, which regressed as a result of:
> >
> > commit b8a9092330da ("Kbuild: do not emit debug info for assembly with LLVM_IAS=1")
> >
> > In that commit, I allude to restoring debug info for assembler defined
> > symbols in a follow up patch, but it seems I forgot to do so in
> >
> > commit a66049e2cf0e ("Kbuild: make DWARF version a choice")
> >
> > This patch does a few things:
> > 1. Add -g to KBUILD_AFLAGS. This will instruct the compiler to instruct
> > the assembler to emit debug info. But this can cause an issue for
> > folks using a newer compiler but older assembler, because the
> > implicit default DWARF version changed from v4 to v5 in gcc-11 and
> > clang-14.
>
>
>
> What kind of bad things happen for "KBUILD_AFLAGS += -g"?
>
>
> I think 'gcc -g -c -o foo.o foo.S' will invoke 'as --gdwarf-2' as the backend
> if gcc is configured to work with old binutils.
That's fine for CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT I think?
What other problems were you envisioning?
>
>
>
>
> > diff --git a/scripts/Makefile.debug b/scripts/Makefile.debug
> > index 9f39b0130551..46e88f0ca998 100644
> > --- a/scripts/Makefile.debug
> > +++ b/scripts/Makefile.debug
> > @@ -4,18 +4,32 @@ ifdef CONFIG_DEBUG_INFO_SPLIT
> > DEBUG_CFLAGS += -gsplit-dwarf
> > else
> > DEBUG_CFLAGS += -g
> > +KBUILD_AFLAGS += -g
> > endif
> >
> > -ifndef CONFIG_AS_IS_LLVM
> > -KBUILD_AFLAGS += -Wa,-gdwarf-2
> > +ifdef CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT
> > +# gcc-11+, clang-14+
> > +ifeq ($(call cc-min-version, 110000, 140000),y)
> > +dwarf-version-y := 5
> > +else
> > +dwarf-version-y := 4
>
>
>
> If you explicitly specify the DWARF version
> for CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT,
> what is the point of CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT?
>
>
> When CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT=y,
> I believe the right thing to do is to pass only -g,
> and let the tool do whatever it thinks is appropriate.
Ok, sure, I will revise.
>
>
>
>
>
>
> > endif
> > -
> > -ifndef CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT
> > +else # !CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT
> > dwarf-version-$(CONFIG_DEBUG_INFO_DWARF4) := 4
> > dwarf-version-$(CONFIG_DEBUG_INFO_DWARF5) := 5
> > DEBUG_CFLAGS += -gdwarf-$(dwarf-version-y)
> > endif
> >
> > +# Binutils 2.35+ (or clang) required for -gdwarf-{4|5}.
> > +# https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=31bf18645d98b4d3d7357353be840e320649a67d
> > +ifneq ($(call as-option,-Wa$(comma)-gdwarf-$(dwarf-version-y)),)
>
>
>
> When is this as-option supposed to fail?
>
>
> Binutils <= 2.34 always accepts whatever -gdwarf-* option.
> Surprisingly or not, it accepts -gdwarf-6, -gdwarf-7, ...
>
> No matter what DWARF version you specify, GAS silently downgrades
> it to DWARF-2.
>
>
> masahiro@zoe:~/tools/binutils-2.34/bin$ ./as --version | head -n 1
> GNU assembler (GNU Binutils) 2.34
> masahiro@zoe:~/tools/binutils-2.34/bin$ cat /dev/null | ./as -gdwarf-5
> -o /dev/null -
> masahiro@zoe:~/tools/binutils-2.34/bin$ echo $?
> 0
> masahiro@zoe:~/tools/binutils-2.34/bin$ cat /dev/null | ./as
> -gdwarf-100 -o /dev/null -
> masahiro@zoe:~/tools/binutils-2.34/bin$ echo $?
> 0
ah, right. Maybe an explicit version check is necessary then.
>
>
>
>
> Overall, I am not convinced with this patch.
>
>
>
> Please see the attached patch.
> Is there any problem with writing this more simply?
Thanks for the inspiration, I will use that as an inspiration/base for
a new patch.
--
Thanks,
~Nick Desaulniers
On Wed, Sep 7, 2022 at 1:08 AM Nathan Chancellor <[email protected]> wrote:
>
> On Mon, Sep 05, 2022 at 06:09:28PM +0900, Masahiro Yamada wrote:
> > On Thu, Sep 1, 2022 at 4:53 AM Nathan Chancellor <[email protected]> wrote:
> > >
> > > On Wed, Aug 31, 2022 at 11:44:05AM -0700, Nick Desaulniers wrote:
> > > > as-instr uses KBUILD_AFLAGS, but as-option uses KBUILD_CFLAGS. This can
> > > > cause as-option to fail unexpectedly because clang will emit
> > > > -Werror,-Wunused-command-line-argument for various -m and -f flags for
> > > > assembler sources.
> > >
> > > Now that I am looking closer at it, where does that '-Werror' come from?
> >
> > The related commit is
> > c3f0d0bc5b01ad90c45276952802455750444b4f
> >
> > The previous discussion with Arnd is
> > https://lore.kernel.org/linux-kbuild/[email protected]/
>
> Right, although this is for cc-option, not as-option, no?
Sorry, I misunderstood your comments.
My reference is about -Werror in cc-option. It is unrelated to as-option.
You are right.
Currently, as-option takes KBUILD_CFLAGS instead of KBUILD_AFLAGS.
The '-Werror,' of -Werror,-Wunused-command-line-argument
presumably came from CONFIG_WERROR.
--
Best Regards
Masahiro Yamada
On Wed, Sep 7, 2022 at 12:12 PM Nick Desaulniers
<[email protected]> wrote:
> >
> >
> >
> >
> > I also believe '-x assembler' should be changed to
> > '-x assembler-with-cpp'.
> >
> >
> > As I mentioned somewhere before, our assembly code (*.S) is always
> > preprocessed. There is no *.s file in the kernel source tree.
> >
> >
> > So, '-x assembler-with-cpp' matches the real situation.
>
> Should I do this for as-instr then as well? In the same patch?
Probably we should fix as-instr in the same way.
You can do it in the same patch, or in a separate one.
It is up to you.
> >
> >
> > One interesting thing is, clang does not warn
> > [-Wunused-command-line-argument] for *.S files.
> >
> >
> >
> >
> > $ clang -fomit-frame-pointer -c -x assembler /dev/null -o /dev/null
> > clang: warning: argument unused during compilation:
> > '-fomit-frame-pointer' [-Wunused-command-line-argument]
> >
> > $ clang -fomit-frame-pointer -c -x assembler-with-cpp /dev/null -o /dev/null
> >
> >
> >
> > The root cause is we are using '-x assembler', which
> > never happens in the kernel tree.
> >
> >
> >
> >
> > To sum up, the code I think correct is:
> >
> >
> > as-option = $(call try-run,\
> > $(CC) -Werror $(KBUILD_AFLAGS) $(1) -c -x assembler-with-cpp
> > /dev/null -o "$$TMP",$(1),$(2))
>
> Does your recent patch affect this?
> https://lore.kernel.org/linux-kbuild/[email protected]/
No, I do not think so.
> If so, then I should not add -Werror as you suggest above?
I think we should always add -Werror to as-option.
as-option checks the command line options with /dev/null
as the source input (that is, source input is always valid).
If as-option results in a warning, that option will sprinkle
the same warning for all *.S files in the source tree.
So, any warning in as-option should be considered as an error.
--
Best Regards
Masahiro Yamada