Skip to contentSkip to conversation

fix debug info for asm and DEBUG_INFO_SPLIT

PATCH Superseded Nick Desaulniers 3 participants 19 messages Aug 31, 2022 – Sep 7, 2022

Subsystems (8)
DRM drivers Documentation x86 Kbuild +4 more subsystems

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

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
#1 lore raw

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
index 35ce1a64068b..85934204d905 100644
@@ -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
maintainer Reviewed-by Tested-by on v2 1/5
#2 lore raw

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

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
index 35ce1a64068b..85934204d905 100644
@@ -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
#3 lore raw

PATCH v2 2/5 Makefile.compiler: Use KBUILD_AFLAGS for as-option

In reply to Nick Desaulniers

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.

---
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
index 94d0d40cddb3..d1739f0d3ce3 100644
@@ -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
maintainer Reviewed-by on v2 2/5
#4 lore raw

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 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.

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 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
index 94d0d40cddb3..d1739f0d3ce3 100644
@@ -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
#5 lore raw

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 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]/

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:

Quoted 27 lines

---
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
index 94d0d40cddb3..d1739f0d3ce3 100644
@@ -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 -1
 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

#6 lore raw

Re: [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 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.

Quoted 7 lines
Quoted 1 line

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?

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_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.

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

#7 lore raw

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 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?

Quoted 7 lines
Quoted 5 lines

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.

Signature · 2 lines
Best Regards
Masahiro Yamada
#8 lore raw

Re: [PATCH v2 2/5] Makefile.compiler: Use KBUILD_AFLAGS for as-option

In reply to Masahiro Yamada
Quoted 55 lines · Masahiro Yamada
Quoted 8 lines · Nathan Chancellor
Quoted 4 lines · Nick Desaulniers

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]/

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'.

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/null

The 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
#9 lore raw

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/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:

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
#10 lore raw

PATCH v2 3/5 Makefile.compiler: replace cc-ifversion with compiler-specific macros

In reply to 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.

---
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
index 11a296e52d68..e46f5b45c422 100644
@@ -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
index 952d354069a4..caa39ecb1136 100644
@@ -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
index 86a3b5bfd699..d8ee4743b2e3 100644
@@ -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
index d1739f0d3ce3..13dade724fa3 100644
@@ -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
maintainer Reviewed-by on v2 3/5
#11 lore raw

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

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
index 11a296e52d68..e46f5b45c422 100644
@@ -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 +1 -1
index 952d354069a4..caa39ecb1136 100644
@@ -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 / pointers
drivers/gpu/drm/amd/display/dc/dml/Makefile +0 -0
index 86a3b5bfd699..d8ee4743b2e3 100644
@@ -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
 endif
 
scripts/Makefile.compiler +12 -3
index d1739f0d3ce3..13dade724fa3 100644
@@ -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
#12 lore raw

Re: [PATCH v2 3/5] Makefile.compiler: replace cc-ifversion with compiler-specific macros

In reply to Nick Desaulniers
Quoted 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.

---
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
index 11a296e52d68..e46f5b45c422 100644
@@ -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
index 952d354069a4..caa39ecb1136 100644
@@ -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
index 86a3b5bfd699..d8ee4743b2e3 100644
@@ -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 +2 -3
index d1739f0d3ce3..13dade724fa3 100644
@@ -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
#13 lore raw

PATCH v2 4/5 Makefile.debug: re-enable debug info for .S files

In reply to 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 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
index 9f39b0130551..46e88f0ca998 100644
@@ -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
maintainer Reviewed-by on v2 4/5
#14 lore raw

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 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.

Quoted 6 lines
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
index 9f39b0130551..46e88f0ca998 100644
@@ -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
#15 lore raw

Re: [PATCH v2 4/5] Makefile.debug: re-enable debug info for .S files

In reply to Nick Desaulniers
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 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.

Quoted 9 lines
scripts/Makefile.debug +1 -0
index 9f39b0130551..46e88f0ca998 100644
@@ -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 -2
 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.

scripts/Makefile.debug ifdef CONFIG_DEBUG_INFO_SPLIT · line 25

Quoted 12 lines
scripts/Makefile.debug +4 -2
 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?

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
index bcbe60d6c80c..37aa19f0f7b0 100644
@@ -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
index 9f39b0130551..c5ecb882a638 100644
@@ -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
#16 lore raw

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 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.

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
index 9f39b0130551..46e88f0ca998 100644
@@ -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 -2
 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?

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 -1
 endif
-

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
#17 lore raw

PATCH v2 5/5 Makefile.debug: set -g unconditional on CONFIG_DEBUG_INFO_SPLIT

In reply to Nick Desaulniers

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.

---
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
index 46e88f0ca998..b6eb532af3cc 100644
@@ -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
maintainer Reviewed-by on v2 5/5
#18 lore raw

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_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.

Quoted 9 lines
Quoted 27 lines

---
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
index 46e88f0ca998..b6eb532af3cc 100644
@@ -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