Skip to contentSkip to conversation

Kbuild: DWARF v5 support

PATCH Superseded Nick Desaulniers 6 participants 37 messages Jan 29, 2021 – Feb 3, 2021

Subsystems (3)

v6 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v6 cover Kbuild: DWARF v5 support

DWARF v5 is the latest standard of the DWARF debug info format.

DWARF5 wins significantly in terms of size and especially so when mixed with compression (CONFIG_DEBUG_INFO_COMPRESSED).

Patch 1 is a cleanup that lays the ground work and isn't DWARF v5 specific.
Patch 2 implements Kconfig and Kbuild support for DWARFv5.

Changes from v5:
* Drop previous patch 1, it has been accepted into kbuild:
https://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild.git/commit/?h=kbuild&id=3f4d8ce271c7082be75bacbcbd2048aa78ce2b44
* Trying to set -Wa,-gdwarf-4 in the earlier patch was the source of additional complexity. Drop it that part of the patch. We can revisit clang without the integrated assembler setting -Wa,-gdwarf-4 later. That is a separate problem from generally supporting DWARF v5.
* Rework the final patch for clang without the integrated assembler. -Wa,-gdwarf-5 is required for DWARF5 in that case otherwise GAS will not accept the assembler directives clang produces from C code when generating asm.

Changes from v4:
* drop set -e from script as per Nathan.
* add dependency on !CONFIG_DEBUG_INFO_BTF for DWARF v5 as per Sedat.
* Move LLVM_IAS=1 complexity from patch 2 to patch 3 as per Arvind and Masahiro. Sorry it took me a few tries to understand the point (I might still not), but it looks much cleaner this way. Sorry Nathan, I did not carry forward your previous reviews as a result, but I would appreciate if you could look again.
* Add Nathan's reviewed by tag to patch 1.
* Reword commit message for patch 3 to mention LLVM_IAS=1 and -gdwarf-5 binutils addition later, and BTF issue.
* I still happen to see a pahole related error spew for the combination of:
* LLVM=1
* LLVM_IAS=1
* CONFIG_DEBUG_INFO_DWARF4
* CONFIG_DEBUG_INFO_BTF
Though they're non-fatal to the build. I'm not sure yet why removing any one of the above prevents the warning spew. Maybe we'll need a v6.

Changes from v3:

Changes as per Arvind:
* only add -Wa,-gdwarf-5 for (LLVM=1|CC=clang)+LLVM_IAS=0 builds.
* add -gdwarf-5 to Kconfig shell script.
* only run Kconfig shell script for Clang.

Apologies to Sedat and Nathan; I appreciate previous testing/review, but I did no carry forward your Tested-by and Reviewed-by tags, as the patches have changed too much IMO.

Changes from v2:
* Drop two of the earlier patches that have been accepted already.
* Add measurements with GCC 10.2 to commit message.
* Update help text as per Arvind with help from Caroline.
* Improve case/wording between DWARF Versions as per Masahiro.

Changes from the RFC:
* split patch in 3 patch series, include Fangrui's patch, too.
* prefer DWARF vX format, as per Fangrui.
* use spaces between assignment in Makefile as per Masahiro.
* simplify setting dwarf-version-y as per Masahiro.
* indent prompt in Kconfig change as per Masahiro.
* remove explicit default in Kconfig as per Masahiro.
* add comments to test_dwarf5_support.sh.
* change echo in test_dwarf5_support.sh as per Masahiro.
* remove -u from test_dwarf5_support.sh as per Masahiro.
* add a -gdwarf-5 cc-option check to Kconfig as per Jakub.

Nick Desaulniers (2):
Kbuild: make DWARF version a choice
Kbuild: implement support for DWARF v5

 Makefile                          | 16 ++++++++++--
 include/asm-generic/vmlinux.lds.h |  6 ++++-
 lib/Kconfig.debug                 | 41 ++++++++++++++++++++++++++-----
 scripts/test_dwarf5_support.sh    |  8 ++++++
 4 files changed, 62 insertions(+), 9 deletions(-)
 create mode 100755 scripts/test_dwarf5_support.sh
Signature · 1 line
2.30.0.365.g02bc693789-goog
#1 lore raw

PATCH v6 1/2 Kbuild: make DWARF version a choice

Modifies CONFIG_DEBUG_INFO_DWARF4 to be a member of a choice. Adds an explicit CONFIG_DEBUG_INFO_DWARF2, which is the default. Does so in a way that's forward compatible with existing configs, and makes adding future versions more straightforward.

---
 Makefile          |  6 +++---
 lib/Kconfig.debug | 21 ++++++++++++++++-----
 2 files changed, 19 insertions(+), 8 deletions(-)
Makefile +3 -3
index 95ab9856f357..20141cd9319e 100644
@@ -830,9 +830,9 @@ ifneq ($(LLVM_IAS),1)
 KBUILD_AFLAGS	+= -Wa,-gdwarf-2
 endif
 
-ifdef CONFIG_DEBUG_INFO_DWARF4
-DEBUG_CFLAGS	+= -gdwarf-4
-endif
+dwarf-version-$(CONFIG_DEBUG_INFO_DWARF2) := 2
+dwarf-version-$(CONFIG_DEBUG_INFO_DWARF4) := 4
+DEBUG_CFLAGS	+= -gdwarf-$(dwarf-version-y)
 
 ifdef CONFIG_DEBUG_INFO_REDUCED
 DEBUG_CFLAGS	+= $(call cc-option, -femit-struct-debug-baseonly) \
lib/Kconfig.debug +16 -5
index e906ea906cb7..1850728b23e6 100644
@@ -256,13 +256,24 @@ config DEBUG_INFO_SPLIT
 	  to know about the .dwo files and include them.
 	  Incompatible with older versions of ccache.
 
+choice
+	prompt "DWARF version"
+	help
+	  Which version of DWARF debug info to emit.
+
+config DEBUG_INFO_DWARF2
+	bool "Generate DWARF Version 2 debuginfo"
+	help
+	  Generate DWARF v2 debug info.
+
 config DEBUG_INFO_DWARF4
-	bool "Generate dwarf4 debuginfo"
+	bool "Generate DWARF Version 4 debuginfo"
 	help
-	  Generate dwarf4 debug info. This requires recent versions
-	  of gcc and gdb. It makes the debug information larger.
-	  But it significantly improves the success of resolving
-	  variables in gdb on optimized code.
+	  Generate DWARF v4 debug info. This requires gcc 4.5+ and gdb 7.0+.
+	  It makes the debug information larger, but it significantly
+	  improves the success of resolving variables in gdb on optimized code.
+
+endchoice # "DWARF version"
 
 config DEBUG_INFO_BTF
 	bool "Generate BTF typeinfo"
Signature · 1 line
2.30.0.365.g02bc693789-goog
#2 lore raw

Re: [PATCH v6 1/2] Kbuild: make DWARF version a choice

Quoted 20 lines · Nick Desaulniers

Modifies CONFIG_DEBUG_INFO_DWARF4 to be a member of a choice. Adds an explicit CONFIG_DEBUG_INFO_DWARF2, which is the default. Does so in a way that's forward compatible with existing configs, and makes adding future versions more straightforward.

---
 Makefile          |  6 +++---
 lib/Kconfig.debug | 21 ++++++++++++++++-----
 2 files changed, 19 insertions(+), 8 deletions(-)
Makefile +0 -0
index 95ab9856f357..20141cd9319e 100644

Makefile ifneq ($(LLVM_IAS),1) · line 835

Quoted 9 lines
Makefile +3 -3
@@ -830,9 +830,9 @@ ifneq ($(LLVM_IAS),1)
 KBUILD_AFLAGS	+= -Wa,-gdwarf-2
 endif
 
-ifdef CONFIG_DEBUG_INFO_DWARF4
-DEBUG_CFLAGS	+= -gdwarf-4
-endif
+dwarf-version-$(CONFIG_DEBUG_INFO_DWARF2) := 2
+dwarf-version-$(CONFIG_DEBUG_INFO_DWARF4) := 4
+DEBUG_CFLAGS	+= -gdwarf-$(dwarf-version-y)

Why do you make DWARF2 the default? That seems a big step back from what the Makefile used to do before, where it defaulted to whatever DWARF version the compiler defaulted to?
E.g. GCC 4.8 up to 10 defaults to -gdwarf-4 and GCC 11 will default to -gdwarf-5.
DWARF2 is more than 27 years old standard, DWARF3 15 years old, DWARF4 over 10 years old and DWARF5 almost 4 years old...
It is true that some tools aren't DWARF5 ready at this point, but with GCC defaulting to that it will change quickly, but at least DWARF4 support has been around for years.

Jakub

#3 lore raw

Re: [PATCH v6 1/2] Kbuild: make DWARF version a choice

Quoted 34 lines · Jakub Jelinek
Quoted 20 lines · Nick Desaulniers

Modifies CONFIG_DEBUG_INFO_DWARF4 to be a member of a choice. Adds an explicit CONFIG_DEBUG_INFO_DWARF2, which is the default. Does so in a way that's forward compatible with existing configs, and makes adding future versions more straightforward.

---
 Makefile          |  6 +++---
 lib/Kconfig.debug | 21 ++++++++++++++++-----
 2 files changed, 19 insertions(+), 8 deletions(-)
Makefile +0 -0
index 95ab9856f357..20141cd9319e 100644

Makefile ifneq ($(LLVM_IAS),1) · line 835

Quoted 9 lines
Makefile +3 -3
@@ -830,9 +830,9 @@ ifneq ($(LLVM_IAS),1)
 KBUILD_AFLAGS        += -Wa,-gdwarf-2
 endif
 
-ifdef CONFIG_DEBUG_INFO_DWARF4
-DEBUG_CFLAGS += -gdwarf-4
-endif
+dwarf-version-$(CONFIG_DEBUG_INFO_DWARF2) := 2
+dwarf-version-$(CONFIG_DEBUG_INFO_DWARF4) := 4
+DEBUG_CFLAGS += -gdwarf-$(dwarf-version-y)

Why do you make DWARF2 the default? That seems a big step back from what the Makefile used to do before, where it defaulted to whatever DWARF version

Quoted 8 lines

the compiler defaulted to?
E.g. GCC 4.8 up to 10 defaults to -gdwarf-4 and GCC 11 will default to -gdwarf-5.
DWARF2 is more than 27 years old standard, DWARF3 15 years old, DWARF4 over 10 years old and DWARF5 almost 4 years old...
It is true that some tools aren't DWARF5 ready at this point, but with GCC defaulting to that it will change quickly, but at least DWARF4 support has been around for years.

I agree with you; I also do not want to change the existing defaults in this series. That is a separate issue to address.

Signature · 2 lines
Thanks,
~Nick Desaulniers
#4 lore raw

Re: [PATCH v6 1/2] Kbuild: make DWARF version a choice

Quoted 45 lines · Nick Desaulniers
Quoted 34 lines · Jakub Jelinek
Quoted 20 lines · Nick Desaulniers

Modifies CONFIG_DEBUG_INFO_DWARF4 to be a member of a choice. Adds an explicit CONFIG_DEBUG_INFO_DWARF2, which is the default. Does so in a way that's forward compatible with existing configs, and makes adding future versions more straightforward.

---
 Makefile          |  6 +++---
 lib/Kconfig.debug | 21 ++++++++++++++++-----
 2 files changed, 19 insertions(+), 8 deletions(-)
Makefile +0 -0
index 95ab9856f357..20141cd9319e 100644

Makefile ifneq ($(LLVM_IAS),1) · line 835

Quoted 9 lines
Makefile +3 -3
@@ -830,9 +830,9 @@ ifneq ($(LLVM_IAS),1)
 KBUILD_AFLAGS        += -Wa,-gdwarf-2
 endif
 
-ifdef CONFIG_DEBUG_INFO_DWARF4
-DEBUG_CFLAGS += -gdwarf-4
-endif
+dwarf-version-$(CONFIG_DEBUG_INFO_DWARF2) := 2
+dwarf-version-$(CONFIG_DEBUG_INFO_DWARF4) := 4
+DEBUG_CFLAGS += -gdwarf-$(dwarf-version-y)

Why do you make DWARF2 the default? That seems a big step back from what the Makefile used to do before, where it defaulted to whatever DWARF version

Quoted 8 lines

the compiler defaulted to?
E.g. GCC 4.8 up to 10 defaults to -gdwarf-4 and GCC 11 will default to -gdwarf-5.
DWARF2 is more than 27 years old standard, DWARF3 15 years old, DWARF4 over 10 years old and DWARF5 almost 4 years old...
It is true that some tools aren't DWARF5 ready at this point, but with GCC defaulting to that it will change quickly, but at least DWARF4 support has been around for years.

Quoted 2 lines

I agree with you; I also do not want to change the existing defaults in this series. That is a separate issue to address.

Thinking more about this over lunch...

I agree that DWARF v2 is quite old and I don't have a concrete reason why the Linux kernel should continue to support it in 2021.

I agree that this patch takes away the compiler vendor's choice as to what the implicit default choice is for dwarf version for the kernel. (We, the Linux kernel, do so already for implicit default -std=gnuc* as well).

I would not mind making this commit more explicit along the lines of:
"""
If you previously had not explicitly opted into CONFIG_DEBUG_INFO_DWARF4, you will be opted in to CONFIG_DEBUG_INFO_DWARF2 rather than the compiler's implicit default (which changes over time).
"""
If you would rather see dwarf4 be the explicit default, that can be done before or after this patch series, but to avoid further "rope-a-dope" over getting DWARFv5 enabled, I suggest waiting until after.

If Masahiro or Arvind (or whoever) feel differently about preserving the previous "don't care" behavior related to DWARF version for developers who had previously not opted in to CONFIG_DEBUG_INFO_DWARF4, I can drop this patch, and resend v7 of 0002/0002 simply adding CONFIG_DEBUG_INFO_DWARF5 and making that and CONFIG_DEBUG_INFO_DWARF4 depend on ! each other (I think). But I'm going to suggest we follow the Zen of Python: explicit is better than implicit. Supporting "I choose not to choose (my dwarf version)" doesn't seem worthwhile to me, but could be convinced otherwise.

Signature · 2 lines
Thanks,
~Nick Desaulniers
#5 lore raw

Re: [PATCH v6 1/2] Kbuild: make DWARF version a choice

Quoted 72 lines · Nick Desaulniers
Quoted 45 lines · Nick Desaulniers
Quoted 34 lines · Jakub Jelinek
Quoted 20 lines · Nick Desaulniers

Modifies CONFIG_DEBUG_INFO_DWARF4 to be a member of a choice. Adds an explicit CONFIG_DEBUG_INFO_DWARF2, which is the default. Does so in a way that's forward compatible with existing configs, and makes adding future versions more straightforward.

---
 Makefile          |  6 +++---
 lib/Kconfig.debug | 21 ++++++++++++++++-----
 2 files changed, 19 insertions(+), 8 deletions(-)
Makefile +0 -0
index 95ab9856f357..20141cd9319e 100644

Makefile ifneq ($(LLVM_IAS),1) · line 835

Quoted 9 lines
Makefile +3 -3
@@ -830,9 +830,9 @@ ifneq ($(LLVM_IAS),1)
 KBUILD_AFLAGS        += -Wa,-gdwarf-2
 endif
 
-ifdef CONFIG_DEBUG_INFO_DWARF4
-DEBUG_CFLAGS += -gdwarf-4
-endif
+dwarf-version-$(CONFIG_DEBUG_INFO_DWARF2) := 2
+dwarf-version-$(CONFIG_DEBUG_INFO_DWARF4) := 4
+DEBUG_CFLAGS += -gdwarf-$(dwarf-version-y)

Why do you make DWARF2 the default? That seems a big step back from what the Makefile used to do before, where it defaulted to whatever DWARF version

Quoted 8 lines

the compiler defaulted to?
E.g. GCC 4.8 up to 10 defaults to -gdwarf-4 and GCC 11 will default to -gdwarf-5.
DWARF2 is more than 27 years old standard, DWARF3 15 years old, DWARF4 over 10 years old and DWARF5 almost 4 years old...
It is true that some tools aren't DWARF5 ready at this point, but with GCC defaulting to that it will change quickly, but at least DWARF4 support has been around for years.

Quoted 2 lines

I agree with you; I also do not want to change the existing defaults in this series. That is a separate issue to address.

Thinking more about this over lunch...

I agree that DWARF v2 is quite old and I don't have a concrete reason why the Linux kernel should continue to support it in 2021.

I agree that this patch takes away the compiler vendor's choice as to what the implicit default choice is for dwarf version for the kernel. (We, the Linux kernel, do so already for implicit default -std=gnuc* as well).

I would not mind making this commit more explicit along the lines of:
"""
If you previously had not explicitly opted into CONFIG_DEBUG_INFO_DWARF4, you will be opted in to CONFIG_DEBUG_INFO_DWARF2 rather than the compiler's implicit default (which changes over time).
"""
If you would rather see dwarf4 be the explicit default, that can be done before or after this patch series, but to avoid further "rope-a-dope" over getting DWARFv5 enabled, I suggest waiting until after.

Quoted 12 lines

If Masahiro or Arvind (or whoever) feel differently about preserving the previous "don't care" behavior related to DWARF version for developers who had previously not opted in to CONFIG_DEBUG_INFO_DWARF4, I can drop this patch, and resend v7 of 0002/0002 simply adding CONFIG_DEBUG_INFO_DWARF5 and making that and CONFIG_DEBUG_INFO_DWARF4 depend on ! each other (I think). But I'm going to suggest we follow the Zen of Python: explicit is better than implicit. Supporting "I choose not to choose (my dwarf version)" doesn't seem worthwhile to me, but could be convinced otherwise.

Signature · 2 lines
Thanks,
~Nick Desaulniers

Given what Jakub is saying, i.e. it was previously impossible to get dwarf2 with gcc, and you get dwarf4 whether or not DEBUG_INFO_DWARF4 was actually selected, we should make the default choice DEBUG_INFO_DWARF4 with the new menu to avoid surprising users. We should probably just drop DWARF2 and make the menu in this patch have only DWARF4, and then add DWARF5 as the second choice. The menu is still a good thing for future-proofing even if it only has two options currently.

Thanks.

#6 lore raw

Re: [PATCH v6 1/2] Kbuild: make DWARF version a choice

Quoted 2 lines · Arvind Sankar

Given what Jakub is saying, i.e. it was previously impossible to get dwarf2 with gcc, and you get dwarf4 whether or not DEBUG_INFO_DWARF4 was

It isn't impossible to get it, -gdwarf-2 works, it is just not a very good choice (at least unless one knows some debug info consumer is not DWARF3 or later ready).
Though, even gcc -gdwarf-2 will use many extensions from DWARF3 and later, as long as there is no way to describe stuff in DWARF2. -gstrict-dwarf option requests that no DWARF extensions are used.

Jakub

#7 lore raw

Re: [PATCH v6 1/2] Kbuild: make DWARF version a choice

Quoted 11 lines · Jakub Jelinek
Quoted 2 lines · Arvind Sankar

Given what Jakub is saying, i.e. it was previously impossible to get dwarf2 with gcc, and you get dwarf4 whether or not DEBUG_INFO_DWARF4 was

It isn't impossible to get it, -gdwarf-2 works, it is just not a very good choice (at least unless one knows some debug info consumer is not DWARF3 or later ready).
Though, even gcc -gdwarf-2 will use many extensions from DWARF3 and later, as long as there is no way to describe stuff in DWARF2. -gstrict-dwarf option requests that no DWARF extensions are used.

Playing with this in godbolt, it looks like the implicit default dwarf version changed from 2 to 4 in somewhere between the GCC 4.7.4 and 4.8.1 release. The precise version, and whether it was strictly that version or not doesn't matter much; the minimum supported version of GCC for building the kernel currently being 4.9 means that without specifying DEBUG_INFO_DWARF4, that all kernel developers regardless of toolchain and supported toolchain version have been building as DWARF v4 (implicitly, or explicitly). DWARF v2 is quite irrelevant then.

Ok, so I think Arvind's suggestion of "make DEBUG_INFO_DWARF4 a menu option, just don't add a DEBUG_INFO_DWARF2" makes a lot of sense. Will drop DEBUG_INFO_DWARF2 in v7.

Signature · 2 lines
Thanks,
~Nick Desaulniers
#8 lore raw

PATCH v6 2/2 Kbuild: implement support for DWARF v5

In reply to Nick Desaulniers

DWARF v5 is the latest standard of the DWARF debug info format.

Feature detection of DWARF5 is onerous, especially given that we've removed $(AS), so we must query $(CC) for DWARF5 assembler directive support.

The DWARF version of a binary can be validated with:

$ llvm-dwarfdump vmlinux | head -n 4 | grep version
or
$ readelf --debug-dump=info vmlinux 2>/dev/null | grep Version

DWARF5 wins significantly in terms of size when mixed with compression (CONFIG_DEBUG_INFO_COMPRESSED).

363M    vmlinux.clang12.dwarf5.compressed
434M    vmlinux.clang12.dwarf4.compressed
439M    vmlinux.clang12.dwarf2.compressed
457M    vmlinux.clang12.dwarf5
536M    vmlinux.clang12.dwarf4
548M    vmlinux.clang12.dwarf2
515M    vmlinux.gcc10.2.dwarf5.compressed
599M    vmlinux.gcc10.2.dwarf4.compressed
624M    vmlinux.gcc10.2.dwarf2.compressed
630M    vmlinux.gcc10.2.dwarf5
765M    vmlinux.gcc10.2.dwarf4
809M    vmlinux.gcc10.2.dwarf2

Though the quality of debug info is harder to quantify; size is not a proxy for quality.

Jakub notes:
All [GCC] 5.1 - 6.x did was start accepting -gdwarf-5 as experimental option that enabled some small DWARF subset (initially only a few DW_LANG_* codes newly added to DWARF5 drafts). Only GCC 7 (released after DWARF 5 has been finalized) started emitting DWARF5 section headers and got most of the DWARF5 changes in...

Version check GCC so that we don't need to worry about the difference in command line args between GNU readelf and llvm-readelf/llvm-dwarfdump to validate the DWARF Version in the assembler feature detection script.

GNU as only recently gained support for specifying -gdwarf-5, so when compiling with Clang but without Clang's integrated assembler (LLVM_IAS=1 is not set), explicitly add -Wa,-gdwarf-5 to DEBUG_CFLAGS.

Disabled for now if CONFIG_DEBUG_INFO_BTF is set; pahole doesn't yet recognize the new additions to the DWARF debug info. Thanks to Sedat for the report.

---
 Makefile                          | 12 ++++++++++++
 include/asm-generic/vmlinux.lds.h |  6 +++++-
 lib/Kconfig.debug                 | 18 ++++++++++++++++++
 scripts/test_dwarf5_support.sh    |  8 ++++++++
 4 files changed, 43 insertions(+), 1 deletion(-)
 create mode 100755 scripts/test_dwarf5_support.sh
Makefile +12 -0
index 20141cd9319e..bed8b3b180b8 100644
@@ -832,8 +832,20 @@ endif
 
 dwarf-version-$(CONFIG_DEBUG_INFO_DWARF2) := 2
 dwarf-version-$(CONFIG_DEBUG_INFO_DWARF4) := 4
+dwarf-version-$(CONFIG_DEBUG_INFO_DWARF5) := 5
 DEBUG_CFLAGS	+= -gdwarf-$(dwarf-version-y)
 
+# If using clang without the integrated assembler, we need to explicitly tell
+# GAS that we will be feeding it DWARF v5 assembler directives. Kconfig should
+# detect whether the version of GAS supports DWARF v5.
+ifdef CONFIG_CC_IS_CLANG
+ifneq ($(LLVM_IAS),1)
+ifeq ($(dwarf-version-y),5)
+DEBUG_CFLAGS	+= -Wa,-gdwarf-5
+endif
+endif
+endif
+
 ifdef CONFIG_DEBUG_INFO_REDUCED
 DEBUG_CFLAGS	+= $(call cc-option, -femit-struct-debug-baseonly) \
 		   $(call cc-option,-fno-var-tracking)
include/asm-generic/vmlinux.lds.h +5 -1
index 34b7e0d2346c..f8d5455cd87f 100644
@@ -843,7 +843,11 @@
 		.debug_types	0 : { *(.debug_types) }			\
 		/* DWARF 5 */						\
 		.debug_macro	0 : { *(.debug_macro) }			\
-		.debug_addr	0 : { *(.debug_addr) }
+		.debug_addr	0 : { *(.debug_addr) }			\
+		.debug_line_str	0 : { *(.debug_line_str) }		\
+		.debug_loclists	0 : { *(.debug_loclists) }		\
+		.debug_rnglists	0 : { *(.debug_rnglists) }		\
+		.debug_str_offsets	0 : { *(.debug_str_offsets) }
 
 /* Stabs debugging sections. */
 #define STABS_DEBUG							\
lib/Kconfig.debug +18 -0
index 1850728b23e6..09146b1af20d 100644
@@ -273,6 +273,24 @@ config DEBUG_INFO_DWARF4
 	  It makes the debug information larger, but it significantly
 	  improves the success of resolving variables in gdb on optimized code.
 
+config DEBUG_INFO_DWARF5
+	bool "Generate DWARF Version 5 debuginfo"
+	depends on GCC_VERSION >= 50000 || CC_IS_CLANG
+	depends on CC_IS_GCC || $(success,$(srctree)/scripts/test_dwarf5_support.sh $(CC) $(CLANG_FLAGS))
+	depends on !DEBUG_INFO_BTF
+	help
+	  Generate DWARF v5 debug info. Requires binutils 2.35, gcc 5.0+ (gcc
+	  5.0+ accepts the -gdwarf-5 flag but only had partial support for some
+	  draft features until 7.0), and gdb 8.0+.
+
+	  Changes to the structure of debug info in Version 5 allow for around
+	  15-18% savings in resulting image and debug info section sizes as
+	  compared to DWARF Version 4. DWARF Version 5 standardizes previous
+	  extensions such as accelerators for symbol indexing and the format
+	  for fission (.dwo/.dwp) files. Users may not want to select this
+	  config if they rely on tooling that has not yet been updated to
+	  support DWARF Version 5.
+
 endchoice # "DWARF version"
 
 config DEBUG_INFO_BTF
scripts/test_dwarf5_support.sh new file +8 -0
new file mode 100755
index 000000000000..1a00484d0b2e
@@ -0,0 +1,8 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+
+# Test that assembler accepts -gdwarf-5 and .file 0 directives, which were bugs
+# in binutils < 2.35.
+# https://sourceware.org/bugzilla/show_bug.cgi?id=25612
+# https://sourceware.org/bugzilla/show_bug.cgi?id=25614
+echo '.file 0 "filename"' | $* -gdwarf-5 -Wa,-gdwarf-5 -c -x assembler -o /dev/null -
Signature · 1 line
2.30.0.365.g02bc693789-goog
#9 lore raw

Re: [PATCH v6 2/2] Kbuild: implement support for DWARF v5

Quoted 76 lines · Nick Desaulniers

DWARF v5 is the latest standard of the DWARF debug info format.

Feature detection of DWARF5 is onerous, especially given that we've removed $(AS), so we must query $(CC) for DWARF5 assembler directive support.

The DWARF version of a binary can be validated with:

$ llvm-dwarfdump vmlinux | head -n 4 | grep version
or
$ readelf --debug-dump=info vmlinux 2>/dev/null | grep Version

DWARF5 wins significantly in terms of size when mixed with compression (CONFIG_DEBUG_INFO_COMPRESSED).

363M    vmlinux.clang12.dwarf5.compressed
434M    vmlinux.clang12.dwarf4.compressed
439M    vmlinux.clang12.dwarf2.compressed
457M    vmlinux.clang12.dwarf5
536M    vmlinux.clang12.dwarf4
548M    vmlinux.clang12.dwarf2
515M    vmlinux.gcc10.2.dwarf5.compressed
599M    vmlinux.gcc10.2.dwarf4.compressed
624M    vmlinux.gcc10.2.dwarf2.compressed
630M    vmlinux.gcc10.2.dwarf5
765M    vmlinux.gcc10.2.dwarf4
809M    vmlinux.gcc10.2.dwarf2

Though the quality of debug info is harder to quantify; size is not a proxy for quality.

Jakub notes:
All [GCC] 5.1 - 6.x did was start accepting -gdwarf-5 as experimental option that enabled some small DWARF subset (initially only a few DW_LANG_* codes newly added to DWARF5 drafts). Only GCC 7 (released after DWARF 5 has been finalized) started emitting DWARF5 section headers and got most of the DWARF5 changes in...

Version check GCC so that we don't need to worry about the difference in command line args between GNU readelf and llvm-readelf/llvm-dwarfdump to validate the DWARF Version in the assembler feature detection script.

GNU as only recently gained support for specifying -gdwarf-5, so when compiling with Clang but without Clang's integrated assembler (LLVM_IAS=1 is not set), explicitly add -Wa,-gdwarf-5 to DEBUG_CFLAGS.

Disabled for now if CONFIG_DEBUG_INFO_BTF is set; pahole doesn't yet recognize the new additions to the DWARF debug info. Thanks to Sedat for the report.

---
 Makefile                          | 12 ++++++++++++
 include/asm-generic/vmlinux.lds.h |  6 +++++-
 lib/Kconfig.debug                 | 18 ++++++++++++++++++
 scripts/test_dwarf5_support.sh    |  8 ++++++++
 4 files changed, 43 insertions(+), 1 deletion(-)
 create mode 100755 scripts/test_dwarf5_support.sh
Makefile +0 -0
index 20141cd9319e..bed8b3b180b8 100644
@@ -832,8 +832,20 @@ endif
 
 dwarf-version-$(CONFIG_DEBUG_INFO_DWARF2) := 2
 dwarf-version-$(CONFIG_DEBUG_INFO_DWARF4) := 4

Makefile endif · line 844

Quoted 10 lines
Makefile +8 -0
+dwarf-version-$(CONFIG_DEBUG_INFO_DWARF5) := 5
 DEBUG_CFLAGS   += -gdwarf-$(dwarf-version-y)
 
+# If using clang without the integrated assembler, we need to explicitly tell
+# GAS that we will be feeding it DWARF v5 assembler directives. Kconfig should
+# detect whether the version of GAS supports DWARF v5.
+ifdef CONFIG_CC_IS_CLANG
+ifneq ($(LLVM_IAS),1)
+ifeq ($(dwarf-version-y),5)
+DEBUG_CFLAGS   += -Wa,-gdwarf-5

I noticed double "-g -gdwarf-5 -g -gdwarf-5" (a different issue) and that's why I looked again into the top-level Makefile.

Should this be...?

KBUILD_AFLAGS += -Wa,-gdwarf-5

- Sedat -

Quoted 70 lines
Makefile +4 -0
+endif
+endif
+endif
+
 ifdef CONFIG_DEBUG_INFO_REDUCED
 DEBUG_CFLAGS   += $(call cc-option, -femit-struct-debug-baseonly) \
                   $(call cc-option,-fno-var-tracking)
include/asm-generic/vmlinux.lds.h +5 -1
index 34b7e0d2346c..f8d5455cd87f 100644
@@ -843,7 +843,11 @@
                .debug_types    0 : { *(.debug_types) }                 \
                /* DWARF 5 */                                           \
                .debug_macro    0 : { *(.debug_macro) }                 \
-               .debug_addr     0 : { *(.debug_addr) }
+               .debug_addr     0 : { *(.debug_addr) }                  \
+               .debug_line_str 0 : { *(.debug_line_str) }              \
+               .debug_loclists 0 : { *(.debug_loclists) }              \
+               .debug_rnglists 0 : { *(.debug_rnglists) }              \
+               .debug_str_offsets      0 : { *(.debug_str_offsets) }
 
 /* Stabs debugging sections. */
 #define STABS_DEBUG                                                    \
lib/Kconfig.debug +18 -0
index 1850728b23e6..09146b1af20d 100644
@@ -273,6 +273,24 @@ config DEBUG_INFO_DWARF4
          It makes the debug information larger, but it significantly
          improves the success of resolving variables in gdb on optimized code.
 
+config DEBUG_INFO_DWARF5
+       bool "Generate DWARF Version 5 debuginfo"
+       depends on GCC_VERSION >= 50000 || CC_IS_CLANG
+       depends on CC_IS_GCC || $(success,$(srctree)/scripts/test_dwarf5_support.sh $(CC) $(CLANG_FLAGS))
+       depends on !DEBUG_INFO_BTF
+       help
+         Generate DWARF v5 debug info. Requires binutils 2.35, gcc 5.0+ (gcc
+         5.0+ accepts the -gdwarf-5 flag but only had partial support for some
+         draft features until 7.0), and gdb 8.0+.
+
+         Changes to the structure of debug info in Version 5 allow for around
+         15-18% savings in resulting image and debug info section sizes as
+         compared to DWARF Version 4. DWARF Version 5 standardizes previous
+         extensions such as accelerators for symbol indexing and the format
+         for fission (.dwo/.dwp) files. Users may not want to select this
+         config if they rely on tooling that has not yet been updated to
+         support DWARF Version 5.
+
 endchoice # "DWARF version"
 
 config DEBUG_INFO_BTF
scripts/test_dwarf5_support.sh new file +8 -1
new file mode 100755
index 000000000000..1a00484d0b2e
@@ -0,0 +1,8 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+
+# Test that assembler accepts -gdwarf-5 and .file 0 directives, which were bugs
+# in binutils < 2.35.
+# https://sourceware.org/bugzilla/show_bug.cgi?id=25612
+# https://sourceware.org/bugzilla/show_bug.cgi?id=25614
+echo '.file 0 "filename"' | $* -gdwarf-5 -Wa,-gdwarf-5 -c -x assembler -o /dev/null -
--

2.30.0.365.g02bc693789-goog

#10 lore raw

Re: [PATCH v6 2/2] Kbuild: implement support for DWARF v5

Quoted 15 lines · Sedat Dilek
Quoted 12 lines · Nick Desaulniers
Makefile +1 -0
index 20141cd9319e..bed8b3b180b8 100644
@@ -832,8 +832,20 @@ endif
 
 dwarf-version-$(CONFIG_DEBUG_INFO_DWARF2) := 2
 dwarf-version-$(CONFIG_DEBUG_INFO_DWARF4) := 4
+dwarf-version-$(CONFIG_DEBUG_INFO_DWARF5) := 5
 DEBUG_CFLAGS   += -gdwarf-$(dwarf-version-y)
 
Quoted 10 lines

Makefile endif · line 844

Quoted 7 lines
Makefile +7 -0
+# If using clang without the integrated assembler, we need to explicitly tell
+# GAS that we will be feeding it DWARF v5 assembler directives. Kconfig should
+# detect whether the version of GAS supports DWARF v5.
+ifdef CONFIG_CC_IS_CLANG
+ifneq ($(LLVM_IAS),1)
+ifeq ($(dwarf-version-y),5)
+DEBUG_CFLAGS   += -Wa,-gdwarf-5

I noticed double "-g -gdwarf-5 -g -gdwarf-5" (a different issue) and that's why I looked again into the top-level Makefile.

That's...unexpected. I don't see where that could be coming from. Can you tell me please what is the precise command line invocation of make and which source file you observed this on so that I can reproduce?

Quoted 3 lines

Should this be...?

KBUILD_AFLAGS += -Wa,-gdwarf-5

No; under the set of conditions Clang is compiling .c to .S with DWARF v5 assembler directives. GAS will choke unless told -gdwarf-5 via -Wa,-gdwarf-5 for .c source files, hence it is a C flag, not an A flag. A flags are for .S assembler sources, not .c sources.

Signature · 2 lines
Thanks,
~Nick Desaulniers
#11 lore raw

Re: [PATCH v6 2/2] Kbuild: implement support for DWARF v5

Quoted 28 lines · Nick Desaulniers
Quoted 15 lines · Sedat Dilek
Quoted 12 lines · Nick Desaulniers
Makefile +1 -0
index 20141cd9319e..bed8b3b180b8 100644
@@ -832,8 +832,20 @@ endif
 
 dwarf-version-$(CONFIG_DEBUG_INFO_DWARF2) := 2
 dwarf-version-$(CONFIG_DEBUG_INFO_DWARF4) := 4
+dwarf-version-$(CONFIG_DEBUG_INFO_DWARF5) := 5
 DEBUG_CFLAGS   += -gdwarf-$(dwarf-version-y)
 
Quoted 10 lines

Makefile endif · line 844

Quoted 7 lines
Makefile +7 -0
+# If using clang without the integrated assembler, we need to explicitly tell
+# GAS that we will be feeding it DWARF v5 assembler directives. Kconfig should
+# detect whether the version of GAS supports DWARF v5.
+ifdef CONFIG_CC_IS_CLANG
+ifneq ($(LLVM_IAS),1)
+ifeq ($(dwarf-version-y),5)
+DEBUG_CFLAGS   += -Wa,-gdwarf-5

I noticed double "-g -gdwarf-5 -g -gdwarf-5" (a different issue) and that's why I looked again into the top-level Makefile.

Quoted 5 lines

That's...unexpected. I don't see where that could be coming from. Can you tell me please what is the precise command line invocation of make and which source file you observed this on so that I can reproduce?

That's everywhere...

$ zstdgrep --color '\-g -gdwarf-5 -g -gdwarf-5'
build-log_5.11.0-rc5-8-amd64-clang12-lto.txt.zst
| wc -l
29529
Quoted 9 lines
Quoted 3 lines

Should this be...?

KBUILD_AFLAGS += -Wa,-gdwarf-5

No; under the set of conditions Clang is compiling .c to .S with DWARF v5 assembler directives. GAS will choke unless told -gdwarf-5 via -Wa,-gdwarf-5 for .c source files, hence it is a C flag, not an A flag. A flags are for .S assembler sources, not .c sources.

You are right. I mixed again C and A flags.

- Sedat -

#12 lore raw

Re: [PATCH v6 2/2] Kbuild: implement support for DWARF v5

Quoted 37 lines · Sedat Dilek
Quoted 28 lines · Nick Desaulniers
Quoted 15 lines · Sedat Dilek
Quoted 12 lines · Nick Desaulniers
Makefile +1 -0
index 20141cd9319e..bed8b3b180b8 100644
@@ -832,8 +832,20 @@ endif
 
 dwarf-version-$(CONFIG_DEBUG_INFO_DWARF2) := 2
 dwarf-version-$(CONFIG_DEBUG_INFO_DWARF4) := 4
+dwarf-version-$(CONFIG_DEBUG_INFO_DWARF5) := 5
 DEBUG_CFLAGS   += -gdwarf-$(dwarf-version-y)
 
Quoted 10 lines

Makefile endif · line 844

Quoted 7 lines
Makefile +7 -0
+# If using clang without the integrated assembler, we need to explicitly tell
+# GAS that we will be feeding it DWARF v5 assembler directives. Kconfig should
+# detect whether the version of GAS supports DWARF v5.
+ifdef CONFIG_CC_IS_CLANG
+ifneq ($(LLVM_IAS),1)
+ifeq ($(dwarf-version-y),5)
+DEBUG_CFLAGS   += -Wa,-gdwarf-5

I noticed double "-g -gdwarf-5 -g -gdwarf-5" (a different issue) and that's why I looked again into the top-level Makefile.

Quoted 5 lines

That's...unexpected. I don't see where that could be coming from. Can you tell me please what is the precise command line invocation of make and which source file you observed this on so that I can reproduce?

Quoted 6 lines

That's everywhere...

$ zstdgrep --color '\-g -gdwarf-5 -g -gdwarf-5'
build-log_5.11.0-rc5-8-amd64-clang12-lto.txt.zst
| wc -l
29529

I'm not able to reproduce.

$ make LLVM=1 -j72 V=1 2>&1 | grep dwarf
...
clang ... -g -gdwarf-5 -Wa,-gdwarf-5 ...
...
$ make LLVM=1 LLVM_IAS=1 -j72 V=1 2>&1 | grep dwarf
...
clang ... -g -gdwarf-5 ...
...

Can you tell me please what is the precise command line invocation of make and which source file you observed this on so that I can reproduce?

Signature · 2 lines
Thanks,
~Nick Desaulniers
#13 lore raw

Re: [PATCH v6 2/2] Kbuild: implement support for DWARF v5

Quoted 53 lines · Nick Desaulniers
Quoted 37 lines · Sedat Dilek
Quoted 28 lines · Nick Desaulniers
Quoted 15 lines · Sedat Dilek
Quoted 12 lines · Nick Desaulniers
Makefile +1 -0
index 20141cd9319e..bed8b3b180b8 100644
@@ -832,8 +832,20 @@ endif
 
 dwarf-version-$(CONFIG_DEBUG_INFO_DWARF2) := 2
 dwarf-version-$(CONFIG_DEBUG_INFO_DWARF4) := 4
+dwarf-version-$(CONFIG_DEBUG_INFO_DWARF5) := 5
 DEBUG_CFLAGS   += -gdwarf-$(dwarf-version-y)
 
Quoted 10 lines

Makefile endif · line 844

Quoted 7 lines
Makefile +7 -0
+# If using clang without the integrated assembler, we need to explicitly tell
+# GAS that we will be feeding it DWARF v5 assembler directives. Kconfig should
+# detect whether the version of GAS supports DWARF v5.
+ifdef CONFIG_CC_IS_CLANG
+ifneq ($(LLVM_IAS),1)
+ifeq ($(dwarf-version-y),5)
+DEBUG_CFLAGS   += -Wa,-gdwarf-5

I noticed double "-g -gdwarf-5 -g -gdwarf-5" (a different issue) and that's why I looked again into the top-level Makefile.

Quoted 5 lines

That's...unexpected. I don't see where that could be coming from. Can you tell me please what is the precise command line invocation of make and which source file you observed this on so that I can reproduce?

Quoted 6 lines

That's everywhere...

$ zstdgrep --color '\-g -gdwarf-5 -g -gdwarf-5'
build-log_5.11.0-rc5-8-amd64-clang12-lto.txt.zst
| wc -l
29529

I'm not able to reproduce.

$ make LLVM=1 -j72 V=1 2>&1 | grep dwarf
...
clang ... -g -gdwarf-5 -Wa,-gdwarf-5 ...
...
Quoted 5 lines
$ make LLVM=1 LLVM_IAS=1 -j72 V=1 2>&1 | grep dwarf
...
clang ... -g -gdwarf-5 ...
...

Hmm...

I do not see in my current build "-Wa,-gdwarf-5" is passed with v6.

$ grep '\-Wa,-gdwarf-5' build-log_5.11.0-rc5-10-amd64-clang12-lto-pgo.txt
[ empty ]

- Sedat

Quoted 6 lines

Can you tell me please what is the precise command line invocation of make and which source file you observed this on so that I can reproduce?
--
Thanks,
~Nick Desaulniers

#14 lore raw

Re: [PATCH v6 2/2] Kbuild: implement support for DWARF v5

Quoted 62 lines · Sedat Dilek
Quoted 53 lines · Nick Desaulniers
Quoted 37 lines · Sedat Dilek
Quoted 28 lines · Nick Desaulniers
Quoted 15 lines · Sedat Dilek
Quoted 12 lines · Nick Desaulniers
Makefile +1 -0
index 20141cd9319e..bed8b3b180b8 100644
@@ -832,8 +832,20 @@ endif
 
 dwarf-version-$(CONFIG_DEBUG_INFO_DWARF2) := 2
 dwarf-version-$(CONFIG_DEBUG_INFO_DWARF4) := 4
+dwarf-version-$(CONFIG_DEBUG_INFO_DWARF5) := 5
 DEBUG_CFLAGS   += -gdwarf-$(dwarf-version-y)
 
Quoted 10 lines

Makefile endif · line 844

Quoted 7 lines
Makefile +7 -0
+# If using clang without the integrated assembler, we need to explicitly tell
+# GAS that we will be feeding it DWARF v5 assembler directives. Kconfig should
+# detect whether the version of GAS supports DWARF v5.
+ifdef CONFIG_CC_IS_CLANG
+ifneq ($(LLVM_IAS),1)
+ifeq ($(dwarf-version-y),5)
+DEBUG_CFLAGS   += -Wa,-gdwarf-5

I noticed double "-g -gdwarf-5 -g -gdwarf-5" (a different issue) and that's why I looked again into the top-level Makefile.

Quoted 5 lines

That's...unexpected. I don't see where that could be coming from. Can you tell me please what is the precise command line invocation of make and which source file you observed this on so that I can reproduce?

Quoted 6 lines

That's everywhere...

$ zstdgrep --color '\-g -gdwarf-5 -g -gdwarf-5'
build-log_5.11.0-rc5-8-amd64-clang12-lto.txt.zst
| wc -l
29529

I'm not able to reproduce.

$ make LLVM=1 -j72 V=1 2>&1 | grep dwarf
...
clang ... -g -gdwarf-5 -Wa,-gdwarf-5 ...
...
Quoted 5 lines
$ make LLVM=1 LLVM_IAS=1 -j72 V=1 2>&1 | grep dwarf
...
clang ... -g -gdwarf-5 ...
...
Quoted 7 lines

Hmm...

I do not see in my current build "-Wa,-gdwarf-5" is passed with v6.

$ grep '\-Wa,-gdwarf-5' build-log_5.11.0-rc5-10-amd64-clang12-lto-pgo.txt
[ empty ]

That's the diff v5 -> v6...

[ Makefile ]

@@ -826,16 +829,23 @@ else
DEBUG_CFLAGS += -g
endif

+ifneq ($(LLVM_IAS),1)
+KBUILD_AFLAGS += -Wa,-gdwarf-2
+endif
+
dwarf-version-$(CONFIG_DEBUG_INFO_DWARF2) := 2 dwarf-version-$(CONFIG_DEBUG_INFO_DWARF4) := 4 dwarf-version-$(CONFIG_DEBUG_INFO_DWARF5) := 5
DEBUG_CFLAGS += -gdwarf-$(dwarf-version-y)
-# Binutils 2.35+ required for -gdwarf-4+ support.
-dwarf-aflag := $(call as-option,-Wa$(comma)-gdwarf-$(dwarf-version-y)) -KBUILD_AFLAGS += $(dwarf-aflag)
+
+# If using clang without the integrated assembler, we need to explicitly tell +# GAS that we will be feeding it DWARF v5 assembler directives. Kconfig should +# detect whether the version of GAS supports DWARF v5.
ifdef CONFIG_CC_IS_CLANG
ifneq ($(LLVM_IAS),1)
-DEBUG_CFLAGS += $(dwarf-aflag)
+ifeq ($(dwarf-version-y),5)
+DEBUG_CFLAGS += -Wa,-gdwarf-5
+endif
endif
endif

There is no more a dwarf-aflag / KBUILD_AFLAGS += $(dwarf-aflag) used.

- Sedat -

Quoted 12 lines

- Sedat

Quoted 6 lines

Can you tell me please what is the precise command line invocation of make and which source file you observed this on so that I can reproduce?
--
Thanks,
~Nick Desaulniers

#15 lore raw

Re: [PATCH v6 2/2] Kbuild: implement support for DWARF v5

Quoted 68 lines · Sedat Dilek
Quoted 66 lines · Sedat Dilek
Quoted 53 lines · Nick Desaulniers
Quoted 37 lines · Sedat Dilek
Quoted 28 lines · Nick Desaulniers
Quoted 15 lines · Sedat Dilek
Quoted 12 lines · Nick Desaulniers
Makefile +1 -0
index 20141cd9319e..bed8b3b180b8 100644
@@ -832,8 +832,20 @@ endif
 
 dwarf-version-$(CONFIG_DEBUG_INFO_DWARF2) := 2
 dwarf-version-$(CONFIG_DEBUG_INFO_DWARF4) := 4
+dwarf-version-$(CONFIG_DEBUG_INFO_DWARF5) := 5
 DEBUG_CFLAGS   += -gdwarf-$(dwarf-version-y)
 
Quoted 10 lines

Makefile endif · line 844

Quoted 7 lines
Makefile +7 -0
+# If using clang without the integrated assembler, we need to explicitly tell
+# GAS that we will be feeding it DWARF v5 assembler directives. Kconfig should
+# detect whether the version of GAS supports DWARF v5.
+ifdef CONFIG_CC_IS_CLANG
+ifneq ($(LLVM_IAS),1)
+ifeq ($(dwarf-version-y),5)
+DEBUG_CFLAGS   += -Wa,-gdwarf-5

I noticed double "-g -gdwarf-5 -g -gdwarf-5" (a different issue) and that's why I looked again into the top-level Makefile.

Quoted 5 lines

That's...unexpected. I don't see where that could be coming from. Can you tell me please what is the precise command line invocation of make and which source file you observed this on so that I can reproduce?

Quoted 6 lines

That's everywhere...

$ zstdgrep --color '\-g -gdwarf-5 -g -gdwarf-5'
build-log_5.11.0-rc5-8-amd64-clang12-lto.txt.zst
| wc -l
29529

I'm not able to reproduce.

$ make LLVM=1 -j72 V=1 2>&1 | grep dwarf
...
clang ... -g -gdwarf-5 -Wa,-gdwarf-5 ...
...
Quoted 5 lines
$ make LLVM=1 LLVM_IAS=1 -j72 V=1 2>&1 | grep dwarf
...
clang ... -g -gdwarf-5 ...
...

Hmm...

I do not see in my current build "-Wa,-gdwarf-5" is passed with v6.

Quoted 7 lines
Quoted 3 lines
$ grep '\-Wa,-gdwarf-5' build-log_5.11.0-rc5-10-amd64-clang12-lto-pgo.txt
[ empty ]

That's the diff v5 -> v6...

There is no more a dwarf-aflag / KBUILD_AFLAGS += $(dwarf-aflag) used.

Yep; not sure that's relevant though to duplicate flags?

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Can you tell me please what is the precise command line invocation of make and which source file you observed this on so that I can reproduce?

If you don't send me your invocation of make, I cannot help you.

Signature · 2 lines
Thanks,
~Nick Desaulniers
#16 lore raw

Re: [PATCH v6 2/2] Kbuild: implement support for DWARF v5

Quoted 78 lines · Nick Desaulniers
Quoted 68 lines · Sedat Dilek
Quoted 66 lines · Sedat Dilek
Quoted 53 lines · Nick Desaulniers
Quoted 37 lines · Sedat Dilek
Quoted 28 lines · Nick Desaulniers
Quoted 15 lines · Sedat Dilek
Quoted 12 lines · Nick Desaulniers
Makefile +1 -0
index 20141cd9319e..bed8b3b180b8 100644
@@ -832,8 +832,20 @@ endif
 
 dwarf-version-$(CONFIG_DEBUG_INFO_DWARF2) := 2
 dwarf-version-$(CONFIG_DEBUG_INFO_DWARF4) := 4
+dwarf-version-$(CONFIG_DEBUG_INFO_DWARF5) := 5
 DEBUG_CFLAGS   += -gdwarf-$(dwarf-version-y)
 
Quoted 10 lines

Makefile endif · line 844

Quoted 7 lines
Makefile +7 -0
+# If using clang without the integrated assembler, we need to explicitly tell
+# GAS that we will be feeding it DWARF v5 assembler directives. Kconfig should
+# detect whether the version of GAS supports DWARF v5.
+ifdef CONFIG_CC_IS_CLANG
+ifneq ($(LLVM_IAS),1)
+ifeq ($(dwarf-version-y),5)
+DEBUG_CFLAGS   += -Wa,-gdwarf-5

I noticed double "-g -gdwarf-5 -g -gdwarf-5" (a different issue) and that's why I looked again into the top-level Makefile.

Quoted 5 lines

That's...unexpected. I don't see where that could be coming from. Can you tell me please what is the precise command line invocation of make and which source file you observed this on so that I can reproduce?

Quoted 6 lines

That's everywhere...

$ zstdgrep --color '\-g -gdwarf-5 -g -gdwarf-5'
build-log_5.11.0-rc5-8-amd64-clang12-lto.txt.zst
| wc -l
29529

I'm not able to reproduce.

$ make LLVM=1 -j72 V=1 2>&1 | grep dwarf
...
clang ... -g -gdwarf-5 -Wa,-gdwarf-5 ...
...
Quoted 5 lines
$ make LLVM=1 LLVM_IAS=1 -j72 V=1 2>&1 | grep dwarf
...
clang ... -g -gdwarf-5 ...
...

Hmm...

I do not see in my current build "-Wa,-gdwarf-5" is passed with v6.

Quoted 7 lines
Quoted 3 lines
$ grep '\-Wa,-gdwarf-5' build-log_5.11.0-rc5-10-amd64-clang12-lto-pgo.txt
[ empty ]

That's the diff v5 -> v6...

There is no more a dwarf-aflag / KBUILD_AFLAGS += $(dwarf-aflag) used.

Quoted 8 lines

Yep; not sure that's relevant though to duplicate flags?

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Can you tell me please what is the precise command line invocation of make and which source file you observed this on so that I can reproduce?

If you don't send me your invocation of make, I cannot help you.

/usr/bin/perf_5.10 stat make V=1 -j4 LLVM=1 LLVM_IAS=1 PAHOLE=/opt/pahole/bin/pahole LOCALVERSION=-10-amd64-clang12 -lto-pgo KBUILD_VERBOSE=1 KBUILD_BUILD_HOST=iniza [email protected] KBUILD_BUILD_TIMESTAMP=2021-01-29 bindeb-pkg KDEB_PKGVERSION=5.11.0~rc5-10~bullseye+dileks1

- Sedat -

#17 lore raw

Re: [PATCH v6 2/2] Kbuild: implement support for DWARF v5

Quoted 90 lines · Sedat Dilek
Quoted 78 lines · Nick Desaulniers
Quoted 68 lines · Sedat Dilek
Quoted 66 lines · Sedat Dilek
Quoted 53 lines · Nick Desaulniers
Quoted 37 lines · Sedat Dilek
Quoted 28 lines · Nick Desaulniers
Quoted 15 lines · Sedat Dilek
Quoted 12 lines · Nick Desaulniers
Makefile +1 -0
index 20141cd9319e..bed8b3b180b8 100644
@@ -832,8 +832,20 @@ endif
 
 dwarf-version-$(CONFIG_DEBUG_INFO_DWARF2) := 2
 dwarf-version-$(CONFIG_DEBUG_INFO_DWARF4) := 4
+dwarf-version-$(CONFIG_DEBUG_INFO_DWARF5) := 5
 DEBUG_CFLAGS   += -gdwarf-$(dwarf-version-y)
 
Quoted 10 lines

Makefile endif · line 844

Quoted 7 lines
Makefile +7 -0
+# If using clang without the integrated assembler, we need to explicitly tell
+# GAS that we will be feeding it DWARF v5 assembler directives. Kconfig should
+# detect whether the version of GAS supports DWARF v5.
+ifdef CONFIG_CC_IS_CLANG
+ifneq ($(LLVM_IAS),1)
+ifeq ($(dwarf-version-y),5)
+DEBUG_CFLAGS   += -Wa,-gdwarf-5

I noticed double "-g -gdwarf-5 -g -gdwarf-5" (a different issue) and that's why I looked again into the top-level Makefile.

Quoted 5 lines

That's...unexpected. I don't see where that could be coming from. Can you tell me please what is the precise command line invocation of make and which source file you observed this on so that I can reproduce?

Quoted 6 lines

That's everywhere...

$ zstdgrep --color '\-g -gdwarf-5 -g -gdwarf-5'
build-log_5.11.0-rc5-8-amd64-clang12-lto.txt.zst
| wc -l
29529

I'm not able to reproduce.

$ make LLVM=1 -j72 V=1 2>&1 | grep dwarf
...
clang ... -g -gdwarf-5 -Wa,-gdwarf-5 ...
...
Quoted 5 lines
$ make LLVM=1 LLVM_IAS=1 -j72 V=1 2>&1 | grep dwarf
...
clang ... -g -gdwarf-5 ...
...

Hmm...

I do not see in my current build "-Wa,-gdwarf-5" is passed with v6.

Quoted 7 lines
Quoted 3 lines
$ grep '\-Wa,-gdwarf-5' build-log_5.11.0-rc5-10-amd64-clang12-lto-pgo.txt
[ empty ]

That's the diff v5 -> v6...

There is no more a dwarf-aflag / KBUILD_AFLAGS += $(dwarf-aflag) used.

Quoted 8 lines

Yep; not sure that's relevant though to duplicate flags?

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Can you tell me please what is the precise command line invocation of make and which source file you observed this on so that I can reproduce?

If you don't send me your invocation of make, I cannot help you.

Quoted 6 lines

/usr/bin/perf_5.10 stat make V=1 -j4 LLVM=1 LLVM_IAS=1 PAHOLE=/opt/pahole/bin/pahole LOCALVERSION=-10-amd64-clang12 -lto-pgo KBUILD_VERBOSE=1 KBUILD_BUILD_HOST=iniza [email protected] KBUILD_BUILD_TIMESTAMP=2021-01-29 bindeb-pkg KDEB_PKGVERSION=5.11.0~rc5-10~bullseye+dileks1

$ make LLVM=1 LLVM_IAS=1 -j72 defconfig
$ make LLVM=1 LLVM_IAS=1 -j72 menuconfig
<enable CONFIG_DEBUG_INFO and CONFIG_DEBUG_INFO_DWARF5>
$ make LLVM=1 LLVM_IAS=1 -j72 V=1 &> log.txt
$ grep '\-g -gdwarf-5 -g -gdwarf-5' log.txt | wc -l
0
$ grep '\-g -gdwarf-5' log.txt | wc -l
2517

Do have the patch applied twice, perhaps?

Is your compiler haunted, or is mine? (haha! they both are; false dichotomy; they are one in the same). Is zstdgrep haunted, or is GNU grep haunted? :P

Signature · 2 lines
Thanks,
~Nick Desaulniers
#18 lore raw

Re: [PATCH v6 2/2] Kbuild: implement support for DWARF v5

Quoted 108 lines · Nick Desaulniers
Quoted 90 lines · Sedat Dilek
Quoted 78 lines · Nick Desaulniers
Quoted 68 lines · Sedat Dilek
Quoted 66 lines · Sedat Dilek
Quoted 53 lines · Nick Desaulniers
Quoted 37 lines · Sedat Dilek
Quoted 28 lines · Nick Desaulniers
Quoted 15 lines · Sedat Dilek
Quoted 12 lines · Nick Desaulniers
Makefile +1 -0
index 20141cd9319e..bed8b3b180b8 100644
@@ -832,8 +832,20 @@ endif
 
 dwarf-version-$(CONFIG_DEBUG_INFO_DWARF2) := 2
 dwarf-version-$(CONFIG_DEBUG_INFO_DWARF4) := 4
+dwarf-version-$(CONFIG_DEBUG_INFO_DWARF5) := 5
 DEBUG_CFLAGS   += -gdwarf-$(dwarf-version-y)
 
Quoted 10 lines

Makefile endif · line 844

Quoted 7 lines
Makefile +7 -0
+# If using clang without the integrated assembler, we need to explicitly tell
+# GAS that we will be feeding it DWARF v5 assembler directives. Kconfig should
+# detect whether the version of GAS supports DWARF v5.
+ifdef CONFIG_CC_IS_CLANG
+ifneq ($(LLVM_IAS),1)
+ifeq ($(dwarf-version-y),5)
+DEBUG_CFLAGS   += -Wa,-gdwarf-5

I noticed double "-g -gdwarf-5 -g -gdwarf-5" (a different issue) and that's why I looked again into the top-level Makefile.

Quoted 5 lines

That's...unexpected. I don't see where that could be coming from. Can you tell me please what is the precise command line invocation of make and which source file you observed this on so that I can reproduce?

Quoted 6 lines

That's everywhere...

$ zstdgrep --color '\-g -gdwarf-5 -g -gdwarf-5'
build-log_5.11.0-rc5-8-amd64-clang12-lto.txt.zst
| wc -l
29529

I'm not able to reproduce.

$ make LLVM=1 -j72 V=1 2>&1 | grep dwarf
...
clang ... -g -gdwarf-5 -Wa,-gdwarf-5 ...
...
Quoted 5 lines
$ make LLVM=1 LLVM_IAS=1 -j72 V=1 2>&1 | grep dwarf
...
clang ... -g -gdwarf-5 ...
...

Hmm...

I do not see in my current build "-Wa,-gdwarf-5" is passed with v6.

Quoted 7 lines
Quoted 3 lines
$ grep '\-Wa,-gdwarf-5' build-log_5.11.0-rc5-10-amd64-clang12-lto-pgo.txt
[ empty ]

That's the diff v5 -> v6...

There is no more a dwarf-aflag / KBUILD_AFLAGS += $(dwarf-aflag) used.

Quoted 8 lines

Yep; not sure that's relevant though to duplicate flags?

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Can you tell me please what is the precise command line invocation of make and which source file you observed this on so that I can reproduce?

If you don't send me your invocation of make, I cannot help you.

Quoted 6 lines

/usr/bin/perf_5.10 stat make V=1 -j4 LLVM=1 LLVM_IAS=1 PAHOLE=/opt/pahole/bin/pahole LOCALVERSION=-10-amd64-clang12 -lto-pgo KBUILD_VERBOSE=1 KBUILD_BUILD_HOST=iniza [email protected] KBUILD_BUILD_TIMESTAMP=2021-01-29 bindeb-pkg KDEB_PKGVERSION=5.11.0~rc5-10~bullseye+dileks1

$ make LLVM=1 LLVM_IAS=1 -j72 defconfig
$ make LLVM=1 LLVM_IAS=1 -j72 menuconfig
<enable CONFIG_DEBUG_INFO and CONFIG_DEBUG_INFO_DWARF5>
$ make LLVM=1 LLVM_IAS=1 -j72 V=1 &> log.txt
$ grep '\-g -gdwarf-5 -g -gdwarf-5' log.txt | wc -l
0
$ grep '\-g -gdwarf-5' log.txt | wc -l
2517
Quoted 6 lines

Do have the patch applied twice, perhaps?

Is your compiler haunted, or is mine? (haha! they both are; false dichotomy; they are one in the same). Is zstdgrep haunted, or is GNU grep haunted? :P

Switched to my v6 local Git branch and invoked above make line I gave you. I still see that double.
Looks like I need some "undrunken" switch.

- Sedat -

#19 lore raw

Re: [PATCH v6 2/2] Kbuild: implement support for DWARF v5

Quoted 39 lines · Sedat Dilek
Quoted 36 lines · Nick Desaulniers
Quoted 18 lines · Sedat Dilek
Quoted 5 lines · Nick Desaulniers
Quoted 3 lines · Sedat Dilek
Quoted 1 line · Sedat Dilek
Quoted 9 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines · Nick Desaulniers

Can you tell me please what is the precise command line invocation of make and which source file you observed this on so that I can reproduce?

If you don't send me your invocation of make, I cannot help you.

Quoted 6 lines

/usr/bin/perf_5.10 stat make V=1 -j4 LLVM=1 LLVM_IAS=1 PAHOLE=/opt/pahole/bin/pahole LOCALVERSION=-10-amd64-clang12 -lto-pgo KBUILD_VERBOSE=1 KBUILD_BUILD_HOST=iniza [email protected] KBUILD_BUILD_TIMESTAMP=2021-01-29 bindeb-pkg KDEB_PKGVERSION=5.11.0~rc5-10~bullseye+dileks1

$ make LLVM=1 LLVM_IAS=1 -j72 defconfig
$ make LLVM=1 LLVM_IAS=1 -j72 menuconfig
<enable CONFIG_DEBUG_INFO and CONFIG_DEBUG_INFO_DWARF5>
$ make LLVM=1 LLVM_IAS=1 -j72 V=1 &> log.txt
$ grep '\-g -gdwarf-5 -g -gdwarf-5' log.txt | wc -l
0
$ grep '\-g -gdwarf-5' log.txt | wc -l
2517
Quoted 6 lines
Quoted 2 lines

Do have the patch applied twice, perhaps?

Switched to my v6 local Git branch and invoked above make line I gave you. I still see that double.
Looks like I need some "undrunken" switch.

Can you follow my steps precisely to see whether it's your .config? Perhaps there is a config that duplicates DEBUG_CFLAGS that is not set in the defconfig? If so, it's still harmless to specify the same commands twice, and likely isn't introduced by this patch set if so; so I'm not sure how much more effort is worth pursuing.

Signature · 2 lines
Thanks,
~Nick Desaulniers
#20 lore raw

Re: [PATCH v6 2/2] Kbuild: implement support for DWARF v5

Quoted 48 lines · Nick Desaulniers
Quoted 39 lines · Sedat Dilek
Quoted 36 lines · Nick Desaulniers
Quoted 18 lines · Sedat Dilek
Quoted 5 lines · Nick Desaulniers
Quoted 3 lines · Sedat Dilek
Quoted 1 line · Sedat Dilek
Quoted 9 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines · Nick Desaulniers

Can you tell me please what is the precise command line invocation of make and which source file you observed this on so that I can reproduce?

If you don't send me your invocation of make, I cannot help you.

Quoted 6 lines

/usr/bin/perf_5.10 stat make V=1 -j4 LLVM=1 LLVM_IAS=1 PAHOLE=/opt/pahole/bin/pahole LOCALVERSION=-10-amd64-clang12 -lto-pgo KBUILD_VERBOSE=1 KBUILD_BUILD_HOST=iniza [email protected] KBUILD_BUILD_TIMESTAMP=2021-01-29 bindeb-pkg KDEB_PKGVERSION=5.11.0~rc5-10~bullseye+dileks1

$ make LLVM=1 LLVM_IAS=1 -j72 defconfig
$ make LLVM=1 LLVM_IAS=1 -j72 menuconfig
<enable CONFIG_DEBUG_INFO and CONFIG_DEBUG_INFO_DWARF5>
$ make LLVM=1 LLVM_IAS=1 -j72 V=1 &> log.txt
$ grep '\-g -gdwarf-5 -g -gdwarf-5' log.txt | wc -l
0
$ grep '\-g -gdwarf-5' log.txt | wc -l
2517
Quoted 6 lines
Quoted 2 lines

Do have the patch applied twice, perhaps?

Switched to my v6 local Git branch and invoked above make line I gave you. I still see that double.
Looks like I need some "undrunken" switch.

Quoted 6 lines

Can you follow my steps precisely to see whether it's your .config? Perhaps there is a config that duplicates DEBUG_CFLAGS that is not set in the defconfig? If so, it's still harmless to specify the same commands twice, and likely isn't introduced by this patch set if so; so I'm not sure how much more effort is worth pursuing.

If I follow your steps of make I do not see it "double" (in my local v6 Git branch).

Looks like this is coming from my build-script.

I checked if I have some double dwarf(-5) patches double - Nope.

- Sedat -

#21 lore raw

Re: [PATCH v6 2/2] Kbuild: implement support for DWARF v5

Quoted 58 lines · Sedat Dilek
Quoted 48 lines · Nick Desaulniers
Quoted 39 lines · Sedat Dilek
Quoted 36 lines · Nick Desaulniers
Quoted 18 lines · Sedat Dilek
Quoted 5 lines · Nick Desaulniers
Quoted 3 lines · Sedat Dilek
Quoted 1 line · Sedat Dilek
Quoted 9 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines · Nick Desaulniers

Can you tell me please what is the precise command line invocation of make and which source file you observed this on so that I can reproduce?

If you don't send me your invocation of make, I cannot help you.

Quoted 6 lines

/usr/bin/perf_5.10 stat make V=1 -j4 LLVM=1 LLVM_IAS=1 PAHOLE=/opt/pahole/bin/pahole LOCALVERSION=-10-amd64-clang12 -lto-pgo KBUILD_VERBOSE=1 KBUILD_BUILD_HOST=iniza [email protected] KBUILD_BUILD_TIMESTAMP=2021-01-29 bindeb-pkg KDEB_PKGVERSION=5.11.0~rc5-10~bullseye+dileks1

$ make LLVM=1 LLVM_IAS=1 -j72 defconfig
$ make LLVM=1 LLVM_IAS=1 -j72 menuconfig
<enable CONFIG_DEBUG_INFO and CONFIG_DEBUG_INFO_DWARF5>
$ make LLVM=1 LLVM_IAS=1 -j72 V=1 &> log.txt
$ grep '\-g -gdwarf-5 -g -gdwarf-5' log.txt | wc -l
0
$ grep '\-g -gdwarf-5' log.txt | wc -l
2517
Quoted 6 lines
Quoted 2 lines

Do have the patch applied twice, perhaps?

Switched to my v6 local Git branch and invoked above make line I gave you. I still see that double.
Looks like I need some "undrunken" switch.

Quoted 6 lines

Can you follow my steps precisely to see whether it's your .config? Perhaps there is a config that duplicates DEBUG_CFLAGS that is not set in the defconfig? If so, it's still harmless to specify the same commands twice, and likely isn't introduced by this patch set if so; so I'm not sure how much more effort is worth pursuing.

Quoted 6 lines

If I follow your steps of make I do not see it "double" (in my local v6 Git branch).

Looks like this is coming from my build-script.

I checked if I have some double dwarf(-5) patches double - Nope.

Sorry for the late reply.

I do not know which command you input,
but this happens for deb-pkg builds for example.

Please try this patch:
https://lore.kernel.org/patchwork/patch/1374926/

--
Best Regards
Masahiro Yamada

#22 lore raw

Re: [PATCH v6 2/2] Kbuild: implement support for DWARF v5

In reply to Nick Desaulniers
Quoted 7 lines · Nick Desaulniers
Quoted 3 lines

Should this be...?

KBUILD_AFLAGS += -Wa,-gdwarf-5

No; under the set of conditions Clang is compiling .c to .S with DWARF v5 assembler directives. GAS will choke unless told -gdwarf-5 via -Wa,-gdwarf-5 for .c source files, hence it is a C flag, not an A

Wasn't that fixed in GAS?
https://sourceware.org/bugzilla/show_bug.cgi?id=27195

Jakub

#23 lore raw

Re: [PATCH v6 2/2] Kbuild: implement support for DWARF v5

Quoted 4 lines · Jakub Jelinek
Quoted 2 lines · Nick Desaulniers
Quoted 2 lines

Should this be...?

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

KBUILD_AFLAGS += -Wa,-gdwarf-5

No; under the set of conditions Clang is compiling .c to .S with DWARF v5 assembler directives. GAS will choke unless told -gdwarf-5 via -Wa,-gdwarf-5 for .c source files, hence it is a C flag, not an A

Wasn't that fixed in GAS?
https://sourceware.org/bugzilla/show_bug.cgi?id=27195

```
diff --git a/Makefile b/Makefile
index bed8b3b180b8..de616e584706 100644
--- a/Makefile
+++ b/Makefile
@@ -835,17 +835,6 @@ dwarf-version-$(CONFIG_DEBUG_INFO_DWARF4) := 4
 dwarf-version-$(CONFIG_DEBUG_INFO_DWARF5) := 5
 DEBUG_CFLAGS   += -gdwarf-$(dwarf-version-y)

-# If using clang without the integrated assembler, we need to explicitly tell
-# GAS that we will be feeding it DWARF v5 assembler directives. Kconfig should
-# detect whether the version of GAS supports DWARF v5.
-ifdef CONFIG_CC_IS_CLANG
-ifneq ($(LLVM_IAS),1)
-ifeq ($(dwarf-version-y),5)
-DEBUG_CFLAGS   += -Wa,-gdwarf-5
-endif
-endif
-endif
-
 ifdef CONFIG_DEBUG_INFO_REDUCED
 DEBUG_CFLAGS   += $(call cc-option, -femit-struct-debug-baseonly) \
                   $(call cc-option,-fno-var-tracking)
```
$ make LLVM=1 -j72 defconfig
$ ./scripts/config -e DEBUG_INFO -e DEBUG_INFO_DWARF5
$ make LLVM=1 -j72
...
/tmp/init-d50d89.s: Assembler messages:
/tmp/init-d50d89.s:10: Error: file number less than one
/tmp/init-d50d89.s:11: Error: junk at end of line, first unrecognized
character is `m'

which is https://sourceware.org/bugzilla/show_bug.cgi?id=25611.

$ as --version | head -n1
GNU assembler (GNU Binutils for Debian) 2.35.1

Maybe GAS should not need to be told -gdwarf-5 to parse these? Then we would not need to pass -Wa,-gdwarf-5 via clang with -no-integrated-as.

Signature · 2 lines
Thanks,
~Nick Desaulniers
#24 lore raw

Re: [PATCH v6 2/2] Kbuild: implement support for DWARF v5

Quoted 12 lines · Nick Desaulniers
Quoted 2 lines

Wasn't that fixed in GAS?
https://sourceware.org/bugzilla/show_bug.cgi?id=27195

$ make LLVM=1 -j72 defconfig
$ ./scripts/config -e DEBUG_INFO -e DEBUG_INFO_DWARF5
$ make LLVM=1 -j72
...
/tmp/init-d50d89.s: Assembler messages:
/tmp/init-d50d89.s:10: Error: file number less than one
/tmp/init-d50d89.s:11: Error: junk at end of line, first unrecognized
character is `m'
Quoted 8 lines

which is https://sourceware.org/bugzilla/show_bug.cgi?id=25611.

$ as --version | head -n1
GNU assembler (GNU Binutils for Debian) 2.35.1

Maybe GAS should not need to be told -gdwarf-5 to parse these? Then we would not need to pass -Wa,-gdwarf-5 via clang with -no-integrated-as.

That is what sw#27195 is about, just try current binutils 2.35, 2.36 or trunk branches.

Jakub

#25 lore raw

Re: [PATCH v6 2/2] Kbuild: implement support for DWARF v5

Quoted 19 lines · Jakub Jelinek
Quoted 17 lines · Nick Desaulniers
Quoted 2 lines

Wasn't that fixed in GAS?
https://sourceware.org/bugzilla/show_bug.cgi?id=27195

$ make LLVM=1 -j72 defconfig
$ ./scripts/config -e DEBUG_INFO -e DEBUG_INFO_DWARF5
$ make LLVM=1 -j72
...
/tmp/init-d50d89.s: Assembler messages:
/tmp/init-d50d89.s:10: Error: file number less than one
/tmp/init-d50d89.s:11: Error: junk at end of line, first unrecognized
character is `m'

which is https://sourceware.org/bugzilla/show_bug.cgi?id=25611.

$ as --version | head -n1
GNU assembler (GNU Binutils for Debian) 2.35.1
Quoted 6 lines
Quoted 3 lines

Maybe GAS should not need to be told -gdwarf-5 to parse these? Then we would not need to pass -Wa,-gdwarf-5 via clang with -no-integrated-as.

That is what sw#27195 is about, just try current binutils 2.35, 2.36 or trunk branches.

Ah, I see. Then I should update the script I add (scripts/test_dwarf5_support.sh) to feature detect that bug, since it's the latest of the bunch. Also, should update my comment to note that this requires binutils greater than 2.35.1 (which is what I have, which fails, since the backport landed in ... what?!) How was this backported to 2.35
(https://sourceware.org/bugzilla/show_bug.cgi?id=27195#c12, Jan 26 2021) when binutils-2_35_1 was tagged sept 19 2020? Or will there be a binutils 2.35.2 point release?

Signature · 2 lines
Thanks,
~Nick Desaulniers
#26 lore raw

Re: [PATCH v6 2/2] Kbuild: implement support for DWARF v5

Quoted 9 lines · Nick Desaulniers

Ah, I see. Then I should update the script I add (scripts/test_dwarf5_support.sh) to feature detect that bug, since it's the latest of the bunch. Also, should update my comment to note that this requires binutils greater than 2.35.1 (which is what I have, which fails, since the backport landed in ... what?!) How was this backported to 2.35
(https://sourceware.org/bugzilla/show_bug.cgi?id=27195#c12, Jan 26 2021) when binutils-2_35_1 was tagged sept 19 2020? Or will there be a binutils 2.35.2 point release?

AFAIK yes, soon.

Jakub

#27 lore raw

Re: [PATCH v6 2/2] Kbuild: implement support for DWARF v5

Quoted 12 lines · Jakub Jelinek
Quoted 9 lines · Nick Desaulniers

Ah, I see. Then I should update the script I add (scripts/test_dwarf5_support.sh) to feature detect that bug, since it's the latest of the bunch. Also, should update my comment to note that this requires binutils greater than 2.35.1 (which is what I have, which fails, since the backport landed in ... what?!) How was this backported to 2.35
(https://sourceware.org/bugzilla/show_bug.cgi?id=27195#c12, Jan 26 2021) when binutils-2_35_1 was tagged sept 19 2020? Or will there be a binutils 2.35.2 point release?

Quoted 1 line

AFAIK yes, soon.

Err...perhaps https://sourceware.org/bugzilla/show_bug.cgi?id=27195
was about .file 0, but it looks like .file 1 "filename" md5 0x7a0b65214090b6693bd1dc24dd248245 without -gdwarf-5. Specifically the md5 ... .

So https://sourceware.org/bugzilla/show_bug.cgi?id=25611 needs a rework perhaps?

Signature · 2 lines
Thanks,
~Nick Desaulniers
#28 lore raw

Re: [PATCH v6 2/2] Kbuild: implement support for DWARF v5

Quoted 14 lines · Nick Desaulniers
Quoted 12 lines · Jakub Jelinek
Quoted 9 lines · Nick Desaulniers

Ah, I see. Then I should update the script I add (scripts/test_dwarf5_support.sh) to feature detect that bug, since it's the latest of the bunch. Also, should update my comment to note that this requires binutils greater than 2.35.1 (which is what I have, which fails, since the backport landed in ... what?!) How was this backported to 2.35
(https://sourceware.org/bugzilla/show_bug.cgi?id=27195#c12, Jan 26 2021) when binutils-2_35_1 was tagged sept 19 2020? Or will there be a binutils 2.35.2 point release?

Quoted 8 lines
Quoted 1 line

AFAIK yes, soon.

Err...perhaps https://sourceware.org/bugzilla/show_bug.cgi?id=27195
was about .file 0, but it looks like .file 1 "filename" md5 0x7a0b65214090b6693bd1dc24dd248245 without -gdwarf-5. Specifically the md5 ... .

So https://sourceware.org/bugzilla/show_bug.cgi?id=25611 needs a rework perhaps?

$ echo '.file 1 "filename" md5 0x7a0b65214090b6693bd1dc24dd248245' |
binutils-gdb/gas/as -
{standard input}: Assembler messages:
{standard input}:1: Error: junk at end of line, first unrecognized
character is `m'
$ echo '.file 1 "filename" md5 0x7a0b65214090b6693bd1dc24dd248245' |
binutils-gdb/gas/as -gdwarf-5 -
$

https://sourceware.org/bugzilla/show_bug.cgi?id=27280

Signature · 2 lines
Thanks,
~Nick Desaulniers
#29 lore raw

Re: [PATCH v6 2/2] Kbuild: implement support for DWARF v5

In reply to Jakub Jelinek
Quoted 19 lines · Jakub Jelinek
Quoted 17 lines · Nick Desaulniers
Quoted 2 lines

Wasn't that fixed in GAS?
https://sourceware.org/bugzilla/show_bug.cgi?id=27195

$ make LLVM=1 -j72 defconfig
$ ./scripts/config -e DEBUG_INFO -e DEBUG_INFO_DWARF5
$ make LLVM=1 -j72
...
/tmp/init-d50d89.s: Assembler messages:
/tmp/init-d50d89.s:10: Error: file number less than one
/tmp/init-d50d89.s:11: Error: junk at end of line, first unrecognized
character is `m'

which is https://sourceware.org/bugzilla/show_bug.cgi?id=25611.

$ as --version | head -n1
GNU assembler (GNU Binutils for Debian) 2.35.1
Quoted 6 lines
Quoted 3 lines

Maybe GAS should not need to be told -gdwarf-5 to parse these? Then we would not need to pass -Wa,-gdwarf-5 via clang with -no-integrated-as.

That is what sw#27195 is about, just try current binutils 2.35, 2.36 or trunk branches.

Ok, yep, I can confirm. I just built ToT binutils and I no longer need to specify -Wa,-gdwarf-5 when building with clang with -no-integrated-as.

I will update scripts/test_dwarf5_support.sh to check for that and update the comments/documentation/commit messages to say binutils 2.35.2+, link to https://sourceware.org/bugzilla/show_bug.cgi?id=27195
instead, then drop hunk that was passing -Wa,-gdwarf-5.

Signature · 2 lines
Thanks,
~Nick Desaulniers
#30 lore raw

Re: [PATCH v6 2/2] Kbuild: implement support for DWARF v5

In reply to Nick Desaulniers
Quoted 97 lines · Nick Desaulniers

DWARF v5 is the latest standard of the DWARF debug info format.

Feature detection of DWARF5 is onerous, especially given that we've removed $(AS), so we must query $(CC) for DWARF5 assembler directive support.

The DWARF version of a binary can be validated with:

$ llvm-dwarfdump vmlinux | head -n 4 | grep version
or
$ readelf --debug-dump=info vmlinux 2>/dev/null | grep Version

DWARF5 wins significantly in terms of size when mixed with compression (CONFIG_DEBUG_INFO_COMPRESSED).

363M    vmlinux.clang12.dwarf5.compressed
434M    vmlinux.clang12.dwarf4.compressed
439M    vmlinux.clang12.dwarf2.compressed
457M    vmlinux.clang12.dwarf5
536M    vmlinux.clang12.dwarf4
548M    vmlinux.clang12.dwarf2
515M    vmlinux.gcc10.2.dwarf5.compressed
599M    vmlinux.gcc10.2.dwarf4.compressed
624M    vmlinux.gcc10.2.dwarf2.compressed
630M    vmlinux.gcc10.2.dwarf5
765M    vmlinux.gcc10.2.dwarf4
809M    vmlinux.gcc10.2.dwarf2

Though the quality of debug info is harder to quantify; size is not a proxy for quality.

Jakub notes:
All [GCC] 5.1 - 6.x did was start accepting -gdwarf-5 as experimental option that enabled some small DWARF subset (initially only a few DW_LANG_* codes newly added to DWARF5 drafts). Only GCC 7 (released after DWARF 5 has been finalized) started emitting DWARF5 section headers and got most of the DWARF5 changes in...

Version check GCC so that we don't need to worry about the difference in command line args between GNU readelf and llvm-readelf/llvm-dwarfdump to validate the DWARF Version in the assembler feature detection script.

GNU as only recently gained support for specifying -gdwarf-5, so when compiling with Clang but without Clang's integrated assembler (LLVM_IAS=1 is not set), explicitly add -Wa,-gdwarf-5 to DEBUG_CFLAGS.

Disabled for now if CONFIG_DEBUG_INFO_BTF is set; pahole doesn't yet recognize the new additions to the DWARF debug info. Thanks to Sedat for the report.

---

Makefile                          | 12 ++++++++++++
include/asm-generic/vmlinux.lds.h |  6 +++++-
lib/Kconfig.debug                 | 18 ++++++++++++++++++
scripts/test_dwarf5_support.sh    |  8 ++++++++
4 files changed, 43 insertions(+), 1 deletion(-)

create mode 100755 scripts/test_dwarf5_support.sh

Makefile +0 -0
index 20141cd9319e..bed8b3b180b8 100644
@@ -832,8 +832,20 @@ endif
 

dwarf-version-$(CONFIG_DEBUG_INFO_DWARF2) := 2
dwarf-version-$(CONFIG_DEBUG_INFO_DWARF4) := 4
+dwarf-version-$(CONFIG_DEBUG_INFO_DWARF5) := 5
DEBUG_CFLAGS += -gdwarf-$(dwarf-version-y)

Makefile +11 -0
+# If using clang without the integrated assembler, we need to explicitly tell
+# GAS that we will be feeding it DWARF v5 assembler directives. Kconfig should
+# detect whether the version of GAS supports DWARF v5.
+ifdef CONFIG_CC_IS_CLANG
+ifneq ($(LLVM_IAS),1)
+ifeq ($(dwarf-version-y),5)
+DEBUG_CFLAGS	+= -Wa,-gdwarf-5
+endif
+endif
+endif
+

ifdef CONFIG_DEBUG_INFO_REDUCED

DEBUG_CFLAGS	+= $(call cc-option, -femit-struct-debug-baseonly) \
		   $(call cc-option,-fno-var-tracking)
include/asm-generic/vmlinux.lds.h +0 -0
index 34b7e0d2346c..f8d5455cd87f 100644

include/asm-generic/vmlinux.lds.h line 850

Quoted 9 lines
include/asm-generic/vmlinux.lds.h +5 -1
@@ -843,7 +843,11 @@
 		.debug_types	0 : { *(.debug_types) }			\
 		/* DWARF 5 */						\
 		.debug_macro	0 : { *(.debug_macro) }			\
-		.debug_addr	0 : { *(.debug_addr) }
+		.debug_addr	0 : { *(.debug_addr) }			\
+		.debug_line_str	0 : { *(.debug_line_str) }		\
+		.debug_loclists	0 : { *(.debug_loclists) }		\
+		.debug_rnglists	0 : { *(.debug_rnglists) }		\
+		.debug_str_offsets	0 : { *(.debug_str_offsets) }

Add .debug_names for -gdwarf-5 -gpubnames

The internal linker script of GNU ld 2.36 will have it.
https://sourceware.org/pipermail/binutils/2021-January/115064.html

(Compilers don't generate .debug_sup, I added to GNU ld just for future-proof.).

Quoted 48 lines
include/asm-generic/vmlinux.lds.h +0 -0
 /* Stabs debugging sections. */
 #define STABS_DEBUG							\
lib/Kconfig.debug +18 -0
index 1850728b23e6..09146b1af20d 100644
@@ -273,6 +273,24 @@ config DEBUG_INFO_DWARF4
 	  It makes the debug information larger, but it significantly
 	  improves the success of resolving variables in gdb on optimized code.
 
+config DEBUG_INFO_DWARF5
+	bool "Generate DWARF Version 5 debuginfo"
+	depends on GCC_VERSION >= 50000 || CC_IS_CLANG
+	depends on CC_IS_GCC || $(success,$(srctree)/scripts/test_dwarf5_support.sh $(CC) $(CLANG_FLAGS))
+	depends on !DEBUG_INFO_BTF
+	help
+	  Generate DWARF v5 debug info. Requires binutils 2.35, gcc 5.0+ (gcc
+	  5.0+ accepts the -gdwarf-5 flag but only had partial support for some
+	  draft features until 7.0), and gdb 8.0+.
+
+	  Changes to the structure of debug info in Version 5 allow for around
+	  15-18% savings in resulting image and debug info section sizes as
+	  compared to DWARF Version 4. DWARF Version 5 standardizes previous
+	  extensions such as accelerators for symbol indexing and the format
+	  for fission (.dwo/.dwp) files. Users may not want to select this
+	  config if they rely on tooling that has not yet been updated to
+	  support DWARF Version 5.
+

endchoice # "DWARF version"

config DEBUG_INFO_BTF

scripts/test_dwarf5_support.sh new file +8 -0
new file mode 100755
index 000000000000..1a00484d0b2e
@@ -0,0 +1,8 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+
+# Test that assembler accepts -gdwarf-5 and .file 0 directives, which were bugs
+# in binutils < 2.35.
+# https://sourceware.org/bugzilla/show_bug.cgi?id=25612
+# https://sourceware.org/bugzilla/show_bug.cgi?id=25614
+echo '.file 0 "filename"' | $* -gdwarf-5 -Wa,-gdwarf-5 -c -x assembler -o /dev/null -
Signature · 1 line
2.30.0.365.g02bc693789-goog
#31 lore raw

Re: [PATCH v6 2/2] Kbuild: implement support for DWARF v5

Quoted 19 lines · Fangrui Song
Quoted 5 lines · Nick Desaulniers
include/asm-generic/vmlinux.lds.h +0 -0
index 34b7e0d2346c..f8d5455cd87f 100644

include/asm-generic/vmlinux.lds.h line 850

Quoted 9 lines
include/asm-generic/vmlinux.lds.h +5 -1
@@ -843,7 +843,11 @@
              .debug_types    0 : { *(.debug_types) }                 \
              /* DWARF 5 */                                           \
              .debug_macro    0 : { *(.debug_macro) }                 \
-              .debug_addr     0 : { *(.debug_addr) }
+              .debug_addr     0 : { *(.debug_addr) }                  \
+              .debug_line_str 0 : { *(.debug_line_str) }              \
+              .debug_loclists 0 : { *(.debug_loclists) }              \
+              .debug_rnglists 0 : { *(.debug_rnglists) }              \
+              .debug_str_offsets      0 : { *(.debug_str_offsets) }

Add .debug_names for -gdwarf-5 -gpubnames

Quoted 5 lines

The internal linker script of GNU ld 2.36 will have it.
https://sourceware.org/pipermail/binutils/2021-January/115064.html

(Compilers don't generate .debug_sup, I added to GNU ld just for future-proof.).

If we don't use -gpubnames, do I need to future proof the kernel's linker script? YAGNI? :-P

(Since I need to make changes anyways, ok, I will add it to be safe. Thanks for the sugguestion).

Signature · 2 lines
Thanks,
~Nick Desaulniers
#32 lore raw

Re: [PATCH v6 2/2] Kbuild: implement support for DWARF v5

In reply to Nick Desaulniers
Quoted 155 lines · Nick Desaulniers

DWARF v5 is the latest standard of the DWARF debug info format.

Feature detection of DWARF5 is onerous, especially given that we've removed $(AS), so we must query $(CC) for DWARF5 assembler directive support.

The DWARF version of a binary can be validated with:

$ llvm-dwarfdump vmlinux | head -n 4 | grep version
or
$ readelf --debug-dump=info vmlinux 2>/dev/null | grep Version

DWARF5 wins significantly in terms of size when mixed with compression (CONFIG_DEBUG_INFO_COMPRESSED).

363M    vmlinux.clang12.dwarf5.compressed
434M    vmlinux.clang12.dwarf4.compressed
439M    vmlinux.clang12.dwarf2.compressed
457M    vmlinux.clang12.dwarf5
536M    vmlinux.clang12.dwarf4
548M    vmlinux.clang12.dwarf2
515M    vmlinux.gcc10.2.dwarf5.compressed
599M    vmlinux.gcc10.2.dwarf4.compressed
624M    vmlinux.gcc10.2.dwarf2.compressed
630M    vmlinux.gcc10.2.dwarf5
765M    vmlinux.gcc10.2.dwarf4
809M    vmlinux.gcc10.2.dwarf2

Though the quality of debug info is harder to quantify; size is not a proxy for quality.

Jakub notes:
All [GCC] 5.1 - 6.x did was start accepting -gdwarf-5 as experimental option that enabled some small DWARF subset (initially only a few DW_LANG_* codes newly added to DWARF5 drafts). Only GCC 7 (released after DWARF 5 has been finalized) started emitting DWARF5 section headers and got most of the DWARF5 changes in...

Version check GCC so that we don't need to worry about the difference in command line args between GNU readelf and llvm-readelf/llvm-dwarfdump to validate the DWARF Version in the assembler feature detection script.

GNU as only recently gained support for specifying -gdwarf-5, so when compiling with Clang but without Clang's integrated assembler (LLVM_IAS=1 is not set), explicitly add -Wa,-gdwarf-5 to DEBUG_CFLAGS.

Disabled for now if CONFIG_DEBUG_INFO_BTF is set; pahole doesn't yet recognize the new additions to the DWARF debug info. Thanks to Sedat for the report.

---

Makefile                          | 12 ++++++++++++
include/asm-generic/vmlinux.lds.h |  6 +++++-
lib/Kconfig.debug                 | 18 ++++++++++++++++++
scripts/test_dwarf5_support.sh    |  8 ++++++++
4 files changed, 43 insertions(+), 1 deletion(-)

create mode 100755 scripts/test_dwarf5_support.sh

Makefile +0 -0
index 20141cd9319e..bed8b3b180b8 100644
@@ -832,8 +832,20 @@ endif
 

dwarf-version-$(CONFIG_DEBUG_INFO_DWARF2) := 2
dwarf-version-$(CONFIG_DEBUG_INFO_DWARF4) := 4
+dwarf-version-$(CONFIG_DEBUG_INFO_DWARF5) := 5
DEBUG_CFLAGS += -gdwarf-$(dwarf-version-y)

Makefile +11 -0
+# If using clang without the integrated assembler, we need to explicitly tell
+# GAS that we will be feeding it DWARF v5 assembler directives. Kconfig should
+# detect whether the version of GAS supports DWARF v5.
+ifdef CONFIG_CC_IS_CLANG
+ifneq ($(LLVM_IAS),1)
+ifeq ($(dwarf-version-y),5)
+DEBUG_CFLAGS	+= -Wa,-gdwarf-5
+endif
+endif
+endif
+

ifdef CONFIG_DEBUG_INFO_REDUCED

DEBUG_CFLAGS	+= $(call cc-option, -femit-struct-debug-baseonly) \
		   $(call cc-option,-fno-var-tracking)
include/asm-generic/vmlinux.lds.h +5 -1
index 34b7e0d2346c..f8d5455cd87f 100644
@@ -843,7 +843,11 @@
 		.debug_types	0 : { *(.debug_types) }			\
 		/* DWARF 5 */						\
 		.debug_macro	0 : { *(.debug_macro) }			\
-		.debug_addr	0 : { *(.debug_addr) }
+		.debug_addr	0 : { *(.debug_addr) }			\
+		.debug_line_str	0 : { *(.debug_line_str) }		\
+		.debug_loclists	0 : { *(.debug_loclists) }		\
+		.debug_rnglists	0 : { *(.debug_rnglists) }		\
+		.debug_str_offsets	0 : { *(.debug_str_offsets) }
 
 /* Stabs debugging sections. */
 #define STABS_DEBUG							\
lib/Kconfig.debug +18 -0
index 1850728b23e6..09146b1af20d 100644
@@ -273,6 +273,24 @@ config DEBUG_INFO_DWARF4
 	  It makes the debug information larger, but it significantly
 	  improves the success of resolving variables in gdb on optimized code.
 
+config DEBUG_INFO_DWARF5
+	bool "Generate DWARF Version 5 debuginfo"
+	depends on GCC_VERSION >= 50000 || CC_IS_CLANG
+	depends on CC_IS_GCC || $(success,$(srctree)/scripts/test_dwarf5_support.sh $(CC) $(CLANG_FLAGS))
+	depends on !DEBUG_INFO_BTF
+	help
+	  Generate DWARF v5 debug info. Requires binutils 2.35, gcc 5.0+ (gcc
+	  5.0+ accepts the -gdwarf-5 flag but only had partial support for some
+	  draft features until 7.0), and gdb 8.0+.
+
+	  Changes to the structure of debug info in Version 5 allow for around
+	  15-18% savings in resulting image and debug info section sizes as
+	  compared to DWARF Version 4. DWARF Version 5 standardizes previous
+	  extensions such as accelerators for symbol indexing and the format
+	  for fission (.dwo/.dwp) files. Users may not want to select this
+	  config if they rely on tooling that has not yet been updated to
+	  support DWARF Version 5.
+

endchoice # "DWARF version"

config DEBUG_INFO_BTF

scripts/test_dwarf5_support.sh new file +8 -0
new file mode 100755
index 000000000000..1a00484d0b2e
@@ -0,0 +1,8 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+
+# Test that assembler accepts -gdwarf-5 and .file 0 directives, which were bugs
+# in binutils < 2.35.
+# https://sourceware.org/bugzilla/show_bug.cgi?id=25612
+# https://sourceware.org/bugzilla/show_bug.cgi?id=25614
+echo '.file 0 "filename"' | $* -gdwarf-5 -Wa,-gdwarf-5 -c -x assembler -o /dev/null -
Signature · 1 line
2.30.0.365.g02bc693789-goog

Since the other thread suggested that you keep just DWARF v4 and v5 and drop DWARF v2, you'll need v7...

I suggest:

Change the -Wa,-gdwarf-2 logic to add either -Wa,-gdwarf-4 or -Wa,-gdwarf-5 and drop the CONFIG_CC_IS_CLANG ifdef. (CONFIG_CC_IS_CLANG is there because clang -Wa,-gdwarf-2 does not allow DW_AT_ranges which is not in DWARF v2).

GNU as before 2020 did not support -gdwarf-[345]
(https://sourceware.org/bugzilla/show_bug.cgi?id=25612), so you can make -Wa,-gdwarf-2 a DWARF v4 workaround for older GNU as.

#33 lore raw
In reply to Nick Desaulniers
Quoted 12 lines · Nick Desaulniers

DWARF v5 is the latest standard of the DWARF debug info format.

DWARF5 wins significantly in terms of size and especially so when mixed with compression (CONFIG_DEBUG_INFO_COMPRESSED).

Patch 1 is a cleanup that lays the ground work and isn't DWARF v5 specific.
Patch 2 implements Kconfig and Kbuild support for DWARFv5.

Thanks for v6 - I queued it up in my custom patch-series.

- Sedat -

Quoted 75 lines

Changes from v5:
* Drop previous patch 1, it has been accepted into kbuild:
https://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild.git/commit/?h=kbuild&id=3f4d8ce271c7082be75bacbcbd2048aa78ce2b44
* Trying to set -Wa,-gdwarf-4 in the earlier patch was the source of additional complexity. Drop it that part of the patch. We can revisit clang without the integrated assembler setting -Wa,-gdwarf-4 later. That is a separate problem from generally supporting DWARF v5.
* Rework the final patch for clang without the integrated assembler. -Wa,-gdwarf-5 is required for DWARF5 in that case otherwise GAS will not accept the assembler directives clang produces from C code when generating asm.

Changes from v4:
* drop set -e from script as per Nathan.
* add dependency on !CONFIG_DEBUG_INFO_BTF for DWARF v5 as per Sedat.
* Move LLVM_IAS=1 complexity from patch 2 to patch 3 as per Arvind and Masahiro. Sorry it took me a few tries to understand the point (I might still not), but it looks much cleaner this way. Sorry Nathan, I did not carry forward your previous reviews as a result, but I would appreciate if you could look again.
* Add Nathan's reviewed by tag to patch 1.
* Reword commit message for patch 3 to mention LLVM_IAS=1 and -gdwarf-5 binutils addition later, and BTF issue.
* I still happen to see a pahole related error spew for the combination of:
* LLVM=1
* LLVM_IAS=1
* CONFIG_DEBUG_INFO_DWARF4
* CONFIG_DEBUG_INFO_BTF
Though they're non-fatal to the build. I'm not sure yet why removing any one of the above prevents the warning spew. Maybe we'll need a v6.

Changes from v3:

Changes as per Arvind:
* only add -Wa,-gdwarf-5 for (LLVM=1|CC=clang)+LLVM_IAS=0 builds.
* add -gdwarf-5 to Kconfig shell script.
* only run Kconfig shell script for Clang.

Apologies to Sedat and Nathan; I appreciate previous testing/review, but I did no carry forward your Tested-by and Reviewed-by tags, as the patches have changed too much IMO.

Changes from v2:
* Drop two of the earlier patches that have been accepted already.
* Add measurements with GCC 10.2 to commit message.
* Update help text as per Arvind with help from Caroline.
* Improve case/wording between DWARF Versions as per Masahiro.

Changes from the RFC:
* split patch in 3 patch series, include Fangrui's patch, too.
* prefer DWARF vX format, as per Fangrui.
* use spaces between assignment in Makefile as per Masahiro.
* simplify setting dwarf-version-y as per Masahiro.
* indent prompt in Kconfig change as per Masahiro.
* remove explicit default in Kconfig as per Masahiro.
* add comments to test_dwarf5_support.sh.
* change echo in test_dwarf5_support.sh as per Masahiro.
* remove -u from test_dwarf5_support.sh as per Masahiro.
* add a -gdwarf-5 cc-option check to Kconfig as per Jakub.

Nick Desaulniers (2):
Kbuild: make DWARF version a choice
Kbuild: implement support for DWARF v5

 Makefile                          | 16 ++++++++++--
 include/asm-generic/vmlinux.lds.h |  6 ++++-
 lib/Kconfig.debug                 | 41 ++++++++++++++++++++++++++-----
 scripts/test_dwarf5_support.sh    |  8 ++++++
 4 files changed, 62 insertions(+), 9 deletions(-)
 create mode 100755 scripts/test_dwarf5_support.sh

--
2.30.0.365.g02bc693789-goog

#34 lore raw
In reply to Nick Desaulniers
Quoted 12 lines · Nick Desaulniers

DWARF v5 is the latest standard of the DWARF debug info format.

DWARF5 wins significantly in terms of size and especially so when mixed with compression (CONFIG_DEBUG_INFO_COMPRESSED).

Patch 1 is a cleanup that lays the ground work and isn't DWARF v5 specific.
Patch 2 implements Kconfig and Kbuild support for DWARFv5.

When you will do a v7...

Can you look also at places where we have hardcoded DWARF-2 handling...

For example:

arch/x86/purgatory/Makefile:AFLAGS_REMOVE_setup-x86_$(BITS).o += -Wa,-gdwarf-2
arch/x86/purgatory/Makefile:AFLAGS_REMOVE_entry64.o
+= -Wa,-gdwarf-2

- Sedat -

Quoted 75 lines

Changes from v5:
* Drop previous patch 1, it has been accepted into kbuild:
https://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild.git/commit/?h=kbuild&id=3f4d8ce271c7082be75bacbcbd2048aa78ce2b44
* Trying to set -Wa,-gdwarf-4 in the earlier patch was the source of additional complexity. Drop it that part of the patch. We can revisit clang without the integrated assembler setting -Wa,-gdwarf-4 later. That is a separate problem from generally supporting DWARF v5.
* Rework the final patch for clang without the integrated assembler. -Wa,-gdwarf-5 is required for DWARF5 in that case otherwise GAS will not accept the assembler directives clang produces from C code when generating asm.

Changes from v4:
* drop set -e from script as per Nathan.
* add dependency on !CONFIG_DEBUG_INFO_BTF for DWARF v5 as per Sedat.
* Move LLVM_IAS=1 complexity from patch 2 to patch 3 as per Arvind and Masahiro. Sorry it took me a few tries to understand the point (I might still not), but it looks much cleaner this way. Sorry Nathan, I did not carry forward your previous reviews as a result, but I would appreciate if you could look again.
* Add Nathan's reviewed by tag to patch 1.
* Reword commit message for patch 3 to mention LLVM_IAS=1 and -gdwarf-5 binutils addition later, and BTF issue.
* I still happen to see a pahole related error spew for the combination of:
* LLVM=1
* LLVM_IAS=1
* CONFIG_DEBUG_INFO_DWARF4
* CONFIG_DEBUG_INFO_BTF
Though they're non-fatal to the build. I'm not sure yet why removing any one of the above prevents the warning spew. Maybe we'll need a v6.

Changes from v3:

Changes as per Arvind:
* only add -Wa,-gdwarf-5 for (LLVM=1|CC=clang)+LLVM_IAS=0 builds.
* add -gdwarf-5 to Kconfig shell script.
* only run Kconfig shell script for Clang.

Apologies to Sedat and Nathan; I appreciate previous testing/review, but I did no carry forward your Tested-by and Reviewed-by tags, as the patches have changed too much IMO.

Changes from v2:
* Drop two of the earlier patches that have been accepted already.
* Add measurements with GCC 10.2 to commit message.
* Update help text as per Arvind with help from Caroline.
* Improve case/wording between DWARF Versions as per Masahiro.

Changes from the RFC:
* split patch in 3 patch series, include Fangrui's patch, too.
* prefer DWARF vX format, as per Fangrui.
* use spaces between assignment in Makefile as per Masahiro.
* simplify setting dwarf-version-y as per Masahiro.
* indent prompt in Kconfig change as per Masahiro.
* remove explicit default in Kconfig as per Masahiro.
* add comments to test_dwarf5_support.sh.
* change echo in test_dwarf5_support.sh as per Masahiro.
* remove -u from test_dwarf5_support.sh as per Masahiro.
* add a -gdwarf-5 cc-option check to Kconfig as per Jakub.

Nick Desaulniers (2):
Kbuild: make DWARF version a choice
Kbuild: implement support for DWARF v5

 Makefile                          | 16 ++++++++++--
 include/asm-generic/vmlinux.lds.h |  6 ++++-
 lib/Kconfig.debug                 | 41 ++++++++++++++++++++++++++-----
 scripts/test_dwarf5_support.sh    |  8 ++++++
 4 files changed, 62 insertions(+), 9 deletions(-)
 create mode 100755 scripts/test_dwarf5_support.sh

--
2.30.0.365.g02bc693789-goog

#35 lore raw
Quoted 11 lines · Sedat Dilek
Quoted 8 lines · Nick Desaulniers

DWARF v5 is the latest standard of the DWARF debug info format.

DWARF5 wins significantly in terms of size and especially so when mixed with compression (CONFIG_DEBUG_INFO_COMPRESSED).

Quoted 8 lines
Quoted 4 lines

Patch 1 is a cleanup that lays the ground work and isn't DWARF v5 specific.
Patch 2 implements Kconfig and Kbuild support for DWARFv5.

When you will do a v7...

Can you look also at places where we have hardcoded DWARF-2 handling...

Ah, sorry, I just saw this now, after sending v7. Can we wait to purge DWARF v2 until after we have DWARF v5?

In fact, if they are orthogonal like I suspect, why don't you send some patches and I will help you test them?

Signature · 2 lines
Thanks,
~Nick Desaulniers
#36 lore raw
Quoted 22 lines · Nick Desaulniers' via Clang Built Linux
Quoted 11 lines · Sedat Dilek
Quoted 8 lines · Nick Desaulniers

DWARF v5 is the latest standard of the DWARF debug info format.

DWARF5 wins significantly in terms of size and especially so when mixed with compression (CONFIG_DEBUG_INFO_COMPRESSED).

Quoted 8 lines
Quoted 4 lines

Patch 1 is a cleanup that lays the ground work and isn't DWARF v5 specific.
Patch 2 implements Kconfig and Kbuild support for DWARFv5.

When you will do a v7...

Can you look also at places where we have hardcoded DWARF-2 handling...

Quoted 8 lines

Ah, sorry, I just saw this now, after sending v7. Can we wait to purge DWARF v2 until after we have DWARF v5?

In fact, if they are orthogonal like I suspect, why don't you send some patches and I will help you test them?
--
Thanks,
~Nick Desaulniers

Basically the distinction is just between DWARF v2 .debug_line and DWARF v5 .debug_line .
(-gdwarf-4 adds an extra maximum_operations_per_instruction (constant
1) compared with -gdwarf-2 but that can mostly be ignored).

Refinement among -gdwarf-[234] just clarifies things and is not going to affect debugging experience in any case.
So I agree with Nick that it can be done separately.
Note: such clarification can make things a bit ugly because binutils before 2020 does not recognize -gdwarf-[345].

Signature · 1 line
宋方睿