fix debug info for asm and DEBUG_INFO_SPLIT
Subsystems (8)
v2 cover fix debug info for asm and DEBUG_INFO_SPLIT
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(-)
Signature · 1 line
2.37.2.672.g94769d06f0-goog
PATCH v2 1/5 x86/boot/compressed: prefer cc-option for CFLAGS additions
We have an issue where as-option is testing new options with accumulated CFLAGS. This makes it so that we can't use as-option to update AFLAGS since many CFLAGS aren't valid AFLAGS. This is being fixed in a follow up patch. Before doing so, move the assembler test for -Wa,-mrelax-relocations=no from using as-option to cc-option.
---
Changes v1 -> v2:
* Split off of v1 [1/3].
* Use cc-option to update CFLAGS, as per Masahiro.
* Add Masahiro's Suggested-by, Cc Arvind.
arch/x86/boot/compressed/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/boot/compressed/Makefile +1 -1
@@ -49,7 +49,7 @@ KBUILD_CFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=) KBUILD_CFLAGS += -fno-asynchronous-unwind-tables KBUILD_CFLAGS += -D__DISABLE_EXPORTS # Disable relocation relaxation in case the link is not PIE. -KBUILD_CFLAGS += $(call as-option,-Wa$(comma)-mrelax-relocations=no) +KBUILD_CFLAGS += $(call cc-option,-Wa$(comma)-mrelax-relocations=no) KBUILD_CFLAGS += -include $(srctree)/include/linux/hidden.h # sev.c indirectly inludes inat-table.h which is generated during
Signature · 1 line
2.37.2.672.g94769d06f0-goog
Re: [PATCH v2 1/5] x86/boot/compressed: prefer cc-option for CFLAGS additions
Quoted 5 lines · Nick Desaulniers
We have an issue where as-option is testing new options with accumulated CFLAGS. This makes it so that we can't use as-option to update AFLAGS since many CFLAGS aren't valid AFLAGS. This is being fixed in a follow up patch. Before doing so, move the assembler test for -Wa,-mrelax-relocations=no from using as-option to cc-option.
I think the first couple of sentences might sound clearer without the "we". Maybe something like the following?
"as-option tests new options using KBUILD_CFLAGS, which causes problems when using as-option to update KBUILD_AFLAGS because many compiler options are not valid assembler options."
Quoted 5 lines
Cc Arvind Sankar <[email protected]>Link https://lore.kernel.org/llvm/CAK7LNATcHt7GcXZ=jMszyH=+M_LC9Qr6yeAGRCBbE6xriLxtUQ@mail.gmail.com/ open hereSuggested-by Masahiro Yamada <[email protected]>Signed-off-by Nick Desaulniers <[email protected]>
Regardless of the commit message:
Additionally, I did verify that '-Wa,-mrelax-relocations=no' still shows up in arch/x86/boot/compressed so:
Quoted 25 lines
---
Changes v1 -> v2:
* Split off of v1 [1/3].
* Use cc-option to update CFLAGS, as per Masahiro.
* Add Masahiro's Suggested-by, Cc Arvind.arch/x86/boot/compressed/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/boot/compressed/Makefile +1
-1@@ -49,7 +49,7 @@ KBUILD_CFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=) KBUILD_CFLAGS += -fno-asynchronous-unwind-tables KBUILD_CFLAGS += -D__DISABLE_EXPORTS # Disable relocation relaxation in case the link is not PIE. -KBUILD_CFLAGS += $(call as-option,-Wa$(comma)-mrelax-relocations=no) +KBUILD_CFLAGS += $(call cc-option,-Wa$(comma)-mrelax-relocations=no) KBUILD_CFLAGS += -include $(srctree)/include/linux/hidden.h # sev.c indirectly inludes inat-table.h which is generated duringSignature · 1 line
2.37.2.672.g94769d06f0-goog
PATCH v2 2/5 Makefile.compiler: Use KBUILD_AFLAGS for as-option
In reply to Nick Desaulniersas-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.
---
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(-)
scripts/Makefile.compiler +3 -3
@@ -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))
Signature · 1 line
2.37.2.672.g94769d06f0-goog
Re: [PATCH v2 2/5] Makefile.compiler: Use KBUILD_AFLAGS for as-option
Quoted 4 lines · Nick Desaulniers
as-instr uses
KBUILD_AFLAGS, but as-option usesKBUILD_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.
Quoted 5 lines
Callers of as-option (and as-instr) likely want to be adding flags to KBUILD_AFLAGS/aflags-y, not KBUILD_CFLAGS/cflags-y.
Regardless of changes to the commit message:
Quoted 32 lines
---
Changes v1 -> v2:
* Split off changes toarch/x86/boot/compressed/Makefileinto parent patch, as per Masahiro.scripts/Makefile.compiler | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)scripts/Makefile.compiler +3
-3@@ -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))Signature · 1 line
2.37.2.672.g94769d06f0-goog
Re: [PATCH v2 2/5] Makefile.compiler: Use KBUILD_AFLAGS for as-option
Quoted 8 lines · Nathan Chancellor
Quoted 4 lines · Nick Desaulniers
as-instr uses
KBUILD_AFLAGS, but as-option usesKBUILD_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 isc3f0d0bc5b01ad90c45276952802455750444b4f
The previous discussion with Arnd is
https://lore.kernel.org/linux-kbuild/[email protected]/
Quoted 5 lines
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]/)
Quoted 5 lines
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))
Quoted 41 lines
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.
Quoted 5 lines
Callers of as-option (and as-instr) likely want to be adding flags to KBUILD_AFLAGS/aflags-y, not KBUILD_CFLAGS/cflags-y.
Regardless of changes to the commit message:
Reviewed-by Nathan Chancellor <[email protected]>Quoted 27 lines
---
Changes v1 -> v2:
* Split off changes toarch/x86/boot/compressed/Makefileinto parent patch, as per Masahiro.scripts/Makefile.compiler | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)scripts/Makefile.compiler +3
-3@@ -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)
Quoted 5 lines
Quoted 5 lines
scripts/Makefile.compiler +0
-1as-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
Nathan Chancellor
maintainerRe: [PATCH v2 2/5] Makefile.compiler: Use KBUILD_AFLAGS for as-option
Quoted 8 lines · Masahiro Yamada
Quoted 7 lines · Nathan Chancellor
Quoted 4 lines · Nick Desaulniers
as-instr uses
KBUILD_AFLAGS, but as-option usesKBUILD_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.
Quoted 7 lines
Quoted 1 line
Now that I am looking closer at it, where does that '-Werror' come from?
The related commit is
c3f0d0bc5b01ad90c45276952802455750444b4fThe previous discussion with Arnd is
https://lore.kernel.org/linux-kbuild/[email protected]/
Right, although this is for cc-option, not as-option, no?
Quoted 9 lines
Quoted 5 lines
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_WERRORis 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.
Quoted 9 lines
Quoted 5 lines
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.
Quoted 7 lines
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.
Quoted 8 lines
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
Quoted 9 lines
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
Re: [PATCH v2 2/5] Makefile.compiler: Use KBUILD_AFLAGS for as-option
Quoted 12 lines · Nathan Chancellor
Quoted 10 lines · Masahiro Yamada
Quoted 8 lines · Nathan Chancellor
Quoted 4 lines · Nick Desaulniers
as-instr uses
KBUILD_AFLAGS, but as-option usesKBUILD_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?
Quoted 7 lines
Quoted 5 lines
The related commit is
c3f0d0bc5b01ad90c45276952802455750444b4fThe 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.
Signature · 2 lines
Best Regards Masahiro Yamada
Re: [PATCH v2 2/5] Makefile.compiler: Use KBUILD_AFLAGS for as-option
In reply to Masahiro YamadaQuoted 55 lines · Masahiro Yamada
Quoted 8 lines · Nathan Chancellor
Quoted 4 lines · Nick Desaulniers
as-instr uses
KBUILD_AFLAGS, but as-option usesKBUILD_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
c3f0d0bc5b01ad90c45276952802455750444b4fThe previous discussion with Arnd is
https://lore.kernel.org/linux-kbuild/[email protected]/Quoted 5 lines
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_WERRORis 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]/)Quoted 5 lines
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'.
Quoted 5 lines
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?
Quoted 22 lines
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/nullThe root cause is we are using '-x assembler', which never happens in the kernel tree.
Quoted 6 lines
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?
Signature · 2 lines
Thanks, ~Nick Desaulniers
Re: [PATCH v2 2/5] Makefile.compiler: Use KBUILD_AFLAGS for as-option
Quoted 8 lines · Nick Desaulniers
Quoted 8 lines
I also believe '-x assembler' should be changed to '-x assembler-with-cpp'.
Quoted 7 lines
Quoted 5 lines
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.
Quoted 25 lines
Quoted 25 lines
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/nullThe root cause is we are using '-x assembler', which never happens in the kernel tree.
To sum up, the code I think correct is:
Quoted 6 lines
Quoted 3 lines
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.
Quoted 1 line
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.
Signature · 2 lines
Best Regards Masahiro Yamada
PATCH v2 3/5 Makefile.compiler: replace cc-ifversion with compiler-specific macros
In reply to Nick Desaulnierscc-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.
---
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(-)
Documentation/kbuild/makefiles.rst +32 -12
@@ -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
Makefile +2 -2
@@ -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
drivers/gpu/drm/amd/display/dc/dml/Makefile +3 -9
@@ -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
scripts/Makefile.compiler +12 -3
@@ -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)
Signature · 1 line
2.37.2.672.g94769d06f0-goog
Re: [PATCH v2 3/5] Makefile.compiler: replace cc-ifversion with compiler-specific macros
Quoted 5 lines · Nick Desaulniers
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.
Quoted 8 lines
Cc Jonathan Corbet <[email protected]>Link https://lore.kernel.org/llvm/CAGG=3QWSAUakO42kubrCap8fp-gm1ERJJAYXTnP1iHk_wrH=BQ@mail.gmail.com/ open hereSuggested-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 :)
Some comments below.
Quoted 83 lines
---
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(-)Documentation/kbuild/makefiles.rst +32
-12@@ -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 withMakefile +1
-1@@ -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
Makefile ifdef CONFIG_CC_IS_GCC · line 988
Quoted 6 lines
Makefile +1
-1@@ -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.
Quoted 10 lines
Makefile +0
-0# disable invalid "can't wrap" optimizations for signed / pointersdrivers/gpu/drm/amd/display/dc/dml/Makefile +0
-0@@ -33,20 +33,14 @@ ifdef CONFIG_PPC64 dml_ccflags := -mhard-float -maltivec endif
drivers/gpu/drm/amd/display/dc/dml/Makefile ifdef CONFIG_PPC64 · line 38
Quoted 10 lines
drivers/gpu/drm/amd/display/dc/dml/Makefile +2
-7-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.
Quoted 39 lines
drivers/gpu/drm/amd/display/dc/dml/Makefile +1
-2+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 endifscripts/Makefile.compiler +12
-3@@ -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)Signature · 1 line
2.37.2.672.g94769d06f0-goog
Re: [PATCH v2 3/5] Makefile.compiler: replace cc-ifversion with compiler-specific macros
In reply to Nick DesaulniersQuoted 146 lines · Nick Desaulniers
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]>Link https://lore.kernel.org/llvm/CAGG=3QWSAUakO42kubrCap8fp-gm1ERJJAYXTnP1iHk_wrH=BQ@mail.gmail.com/ open hereSuggested-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(-)Documentation/kbuild/makefiles.rst +32
-12@@ -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 withMakefile +2
-2@@ -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 / pointersdrivers/gpu/drm/amd/display/dc/dml/Makefile +3
-9@@ -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 endifscripts/Makefile.compiler +2
-3@@ -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
scripts/Makefile.compiler cc-option-yn = $(call try-run,\ · line 75
Quoted 10 lines
scripts/Makefile.compiler +10
-0+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.
Quoted 5 lines
scripts/Makefile.compiler +0
-1# ld-option # Usage: KBUILD_LDFLAGS += $(call ld-option, -X, -Y) --2.37.2.672.g94769d06f0-goog
Signature · 2 lines
Best Regards Masahiro Yamada
PATCH v2 4/5 Makefile.debug: re-enable debug info for .S files
In reply to Nick DesaulniersAlexey 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.
---
Changes v1 -> v2:
* Use newly added compiler-specific macros, as per Bill.
scripts/Makefile.debug | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-)
scripts/Makefile.debug +18 -4
@@ -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
Signature · 1 line
2.37.2.672.g94769d06f0-goog
Re: [PATCH v2 4/5] Makefile.debug: re-enable debug info for .S files
Quoted 24 lines · Nick Desaulniers
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 toKBUILD_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 usingCONFIG_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.
Quoted 6 lines
Link https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=31bf18645d98b4d3d7357353be840e320649a67dFixes 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]>
Quoted 51 lines
---
Changes v1 -> v2:
* Use newly added compiler-specific macros, as per Bill.scripts/Makefile.debug | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-)scripts/Makefile.debug +18
-4@@ -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_GCCSignature · 1 line
2.37.2.672.g94769d06f0-goog
Re: [PATCH v2 4/5] Makefile.debug: re-enable debug info for .S files
In reply to Nick DesaulniersQuoted 10 lines · Nick Desaulniers
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
Quoted 8 lines
commit
a66049e2cf0e("Kbuild: make DWARF version a choice")This patch does a few things:
1. Add -g toKBUILD_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.
Quoted 9 lines
scripts/Makefile.debug +1
-0@@ -4,18 +4,32 @@ ifdef CONFIG_DEBUG_INFO_SPLIT DEBUG_CFLAGS += -gsplit-dwarf else DEBUG_CFLAGS += -g +KBUILD_AFLAGS += -g
scripts/Makefile.debug ifdef CONFIG_DEBUG_INFO_SPLIT · line 15
Quoted 10 lines
scripts/Makefile.debug +6
-2endif -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.
scripts/Makefile.debug ifdef CONFIG_DEBUG_INFO_SPLIT · line 25
Quoted 12 lines
scripts/Makefile.debug +4
-2endif - -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?
Quoted 11 lines
scripts/Makefile.debug +7
-1+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 --
Quoted 2 lines
2.37.2.672.g94769d06f0-goog
--
Best Regards
Masahiro Yamada
lib/Kconfig.debug +1 -0
@@ -264,6 +264,7 @@ config DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT config DEBUG_INFO_DWARF4 bool "Generate DWARF Version 4 debuginfo" select DEBUG_INFO + depends on !CC_IS_CLANG || (CC_IS_CLANG && (AS_IS_LLVM || (AS_IS_GNU && AS_VERSION >= 23500))) help Generate DWARF v4 debug info. This requires gcc 4.5+ and gdb 7.0+.
scripts/Makefile.debug +11 -8
@@ -3,17 +3,20 @@ DEBUG_CFLAGS := ifdef CONFIG_DEBUG_INFO_SPLIT DEBUG_CFLAGS += -gsplit-dwarf else -DEBUG_CFLAGS += -g +debug-flags-y += -g endif -ifndef CONFIG_AS_IS_LLVM -KBUILD_AFLAGS += -Wa,-gdwarf-2 -endif +debug-flags-$(CONFIG_DEBUG_INFO_DWARF4) += -gdwarf-4 +debug-flags-$(CONFIG_DEBUG_INFO_DWARF5) += -gdwarf-5 + +DEBUG_CFLAGS += $(debug-flags-y) -ifndef 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) +ifeq ($(CONFIG_CC_IS_CLANG)$(CONFIG_AS_IS_GNU),yy) +# Clang does not pass -g or -gdwarf-* option down to GAS. +# Add -Wa, prefix to explicitly specify the flags. +KBUILD_AFLAGS += $(addprefix -Wa$(comma), $(debug-flags-y)) +else +KBUILD_AFLAGS += $(debug-flags-y) endif ifdef CONFIG_DEBUG_INFO_REDUCED
Re: [PATCH v2 4/5] Makefile.debug: re-enable debug info for .S files
Quoted 23 lines · Masahiro Yamada
Quoted 10 lines · Nick Desaulniers
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
Quoted 8 lines
commit
a66049e2cf0e("Kbuild: make DWARF version a choice")This patch does a few things:
1. Add -g toKBUILD_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.
Quoted 5 lines
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?
Quoted 31 lines
Quoted 13 lines
scripts/Makefile.debug +1
-0@@ -4,18 +4,32 @@ ifdef CONFIG_DEBUG_INFO_SPLIT DEBUG_CFLAGS += -gsplit-dwarf else DEBUG_CFLAGS += -g +KBUILD_AFLAGS += -gscripts/Makefile.debug ifdef CONFIG_DEBUG_INFO_SPLIT · line 15
Quoted 10 lines
scripts/Makefile.debug +6
-2endif -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 := 4If you explicitly specify the DWARF version
forCONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT,
what is the point ofCONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT?
Quoted 3 lines
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.
Quoted 31 lines
Quoted 8 lines
scripts/Makefile.debug +0
-1endif -scripts/Makefile.debug ifdef CONFIG_DEBUG_INFO_SPLIT · line 25
Quoted 10 lines
scripts/Makefile.debug +4
-1-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.
Quoted 10 lines
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.
Quoted 10 lines
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.
Signature · 2 lines
Thanks, ~Nick Desaulniers
PATCH v2 5/5 Makefile.debug: set -g unconditional on CONFIG_DEBUG_INFO_SPLIT
In reply to Nick DesaulniersDmitrii, 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.
---
Changes v1 -> v2:
* Add reference to 866ced950bcd, cc Andi, in commit message.
scripts/Makefile.debug | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
scripts/Makefile.debug +2 -4
@@ -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
Signature · 1 line
2.37.2.672.g94769d06f0-goog
Re: [PATCH v2 5/5] Makefile.debug: set -g unconditional on CONFIG_DEBUG_INFO_SPLIT
Quoted 12 lines · Nick Desaulniers
Dmitrii, Fangrui, and Mashahiro note:
Before GCC 11 and Clang 12 -gsplit-dwarf implicitly uses -g2.
Fix
CONFIG_DEBUG_INFO_SPLITfor 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_SPLITwas introduced in
commit866ced950bcd("kbuild: Support split debug info v4") I don't think it ever needed to be.
Quoted 9 lines
Link https://lore.kernel.org/lkml/CAK7LNARPAmsJD5XKAw7m_X2g7Fi-CAAsWDQiP7+ANBjkg7R7ng@mail.gmail.com/ open hereCc 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]>
Quoted 27 lines
---
Changes v1 -> v2:
* Add reference to866ced950bcd, cc Andi, in commit message.scripts/Makefile.debug | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)scripts/Makefile.debug +2
-4@@ -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_DEFAULTSignature · 1 line
2.37.2.672.g94769d06f0-goog