Skip to contentSkip to conversation

Kbuild: implement support for DWARF5

PATCH In review Nick Desaulniers 8 participants 45 messages Oct 22, 2020 – Dec 11, 2020 1 message not in the archive

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Kbuild: implement support for DWARF5

DWARF5 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. Further -gdwarf-X where X is an unsupported value doesn't produce an error in $(CC). GNU as only recently gained support for specifying -gdwarf-5.

The DWARF version of a binary can be validated with:

$ llvm-dwarfdump vmlinux | head -n 5 | 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

Make CONFIG_DEBUG_INFO_DWARF4 part of a Kconfig choice to preserve forward compatibility.

---
RFC because this patch is super half baked, but I'm looking for feedback.

I would logically split this into a series of patches;
1. disable -Wa,gdwarf-2 for LLVM_IAS=1, see also
https://github.com/ClangBuiltLinux/linux/issues/716
https://github.com/ClangBuiltLinux/continuous-integration/blob/master/patches/llvm-all/linux-next/arm64/silence-dwarf2-warnings.patch
that way we can backport for improved LLVM_IAS support.
2. move CONFIG_DEBUG_INFO_DWARF4 to choice.
3. implement the rest on top.

I'm pretty sure GNU as only recently gained the ability to specify -gdwarf-4 without erroring in binutils 2.35, so that part likely needs to be fixed.

 Makefile                          | 19 ++++++++++++++++---
 include/asm-generic/vmlinux.lds.h |  6 +++++-
 lib/Kconfig.debug                 | 29 +++++++++++++++++++++++++----
 scripts/test_dwarf5_support.sh    |  4 ++++
 4 files changed, 50 insertions(+), 8 deletions(-)
 create mode 100755 scripts/test_dwarf5_support.sh
Makefile +16 -3
index e71979882e4f..0862df5b1a24 100644
@@ -828,10 +828,23 @@ else
 DEBUG_CFLAGS	+= -g
 endif
 
-KBUILD_AFLAGS	+= -Wa,-gdwarf-2
-
+DWARF_VERSION=2
 ifdef CONFIG_DEBUG_INFO_DWARF4
-DEBUG_CFLAGS	+= -gdwarf-4
+DWARF_VERSION=4
+endif
+ifdef CONFIG_DEBUG_INFO_DWARF5
+DWARF_VERSION=5
+endif
+DEBUG_CFLAGS	+= -gdwarf-$(DWARF_VERSION)
+
+ifneq ($(DWARF_VERSION)$(LLVM_IAS),21)
+KBUILD_AFLAGS	+= -Wa,-gdwarf-$(DWARF_VERSION)
+endif
+
+ifdef CONFIG_CC_IS_CLANG
+ifneq ($(LLVM_IAS),1)
+KBUILD_CFLAGS	+= -Wa,-gdwarf-$(DWARF_VERSION)
+endif
 endif
 
 ifdef CONFIG_DEBUG_INFO_REDUCED
include/asm-generic/vmlinux.lds.h +5 -1
index cd14444bf600..0382808ef9fe 100644
@@ -828,7 +828,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 +25 -4
index 537cf3c2937d..6b01f0e2dad8 100644
@@ -256,14 +256,35 @@ config DEBUG_INFO_SPLIT
 	  to know about the .dwo files and include them.
 	  Incompatible with older versions of ccache.
 
+choice
+prompt "DWARF version"
+	depends on DEBUG_INFO
+	default DEBUG_INFO_DWARF2
+	help
+	  Which version of DWARF debug info to emit.
+
+config DEBUG_INFO_DWARF2
+	bool "Generate dwarf2 debuginfo"
+	help
+	  Generate dwarf2 debug info.
+
 config DEBUG_INFO_DWARF4
 	bool "Generate dwarf4 debuginfo"
 	depends on $(cc-option,-gdwarf-4)
 	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 dwarf4 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.
+
+config DEBUG_INFO_DWARF5
+	bool "Generate dwarf5 debuginfo"
+	depends on DEBUG_INFO
+	depends on $(success,$(srctree)/scripts/test_dwarf5_support.sh $(CC) $(CLANG_FLAGS))
+	help
+	  Genereate dwarf5 debug info. Requires binutils 2.35+, gcc 5.1+, and
+	  gdb 8.0+.
+
+endchoice # "DWARF version"
 
 config DEBUG_INFO_BTF
 	bool "Generate BTF typeinfo"
scripts/test_dwarf5_support.sh new file +4 -0
new file mode 100755
index 000000000000..82c0eea45845
@@ -0,0 +1,4 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+set -eu
+echo ".file 0 \"asdf\"" | $* -Wa,-gdwarf-5 -c -x assembler -o /dev/null -
Signature · 1 line
2.29.0.rc1.297.gfa9743e501-goog
#1 lore raw
Quoted 9 lines · Nick Desaulniers' via Clang Built Linux

DWARF5 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. Further -gdwarf-X where X is an unsupported value doesn't produce an error in $(CC). GNU as only recently gained support for specifying -gdwarf-5.

The DWARF version of a binary can be validated with:

To be more correct: this is just the version number of the .debug_info section. Other sections can use different version numbers.
(For example, GNU as still does not support version 5 .debug_line)

Quoted 78 lines
$ llvm-dwarfdump vmlinux | head -n 5 | 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

Make CONFIG_DEBUG_INFO_DWARF4 part of a Kconfig choice to preserve forward compatibility.

---
RFC because this patch is super half baked, but I'm looking for feedback.

I would logically split this into a series of patches;
1. disable -Wa,gdwarf-2 for LLVM_IAS=1, see also
https://github.com/ClangBuiltLinux/linux/issues/716
https://github.com/ClangBuiltLinux/continuous-integration/blob/master/patches/llvm-all/linux-next/arm64/silence-dwarf2-warnings.patch
that way we can backport for improved LLVM_IAS support.
2. move CONFIG_DEBUG_INFO_DWARF4 to choice.
3. implement the rest on top.

I'm pretty sure GNU as only recently gained the ability to specify -gdwarf-4 without erroring in binutils 2.35, so that part likely needs to be fixed.

Makefile                          | 19 ++++++++++++++++---
include/asm-generic/vmlinux.lds.h |  6 +++++-
lib/Kconfig.debug                 | 29 +++++++++++++++++++++++++----
scripts/test_dwarf5_support.sh    |  4 ++++
4 files changed, 50 insertions(+), 8 deletions(-)

create mode 100755 scripts/test_dwarf5_support.sh

Makefile +0 -0
index e71979882e4f..0862df5b1a24 100644
@@ -828,10 +828,23 @@ else

DEBUG_CFLAGS += -g
endif

Makefile +1 -2
-KBUILD_AFLAGS	+= -Wa,-gdwarf-2
-
+DWARF_VERSION=2

ifdef CONFIG_DEBUG_INFO_DWARF4

Makefile +15 -1
-DEBUG_CFLAGS	+= -gdwarf-4
+DWARF_VERSION=4
+endif
+ifdef CONFIG_DEBUG_INFO_DWARF5
+DWARF_VERSION=5
+endif
+DEBUG_CFLAGS	+= -gdwarf-$(DWARF_VERSION)
+
+ifneq ($(DWARF_VERSION)$(LLVM_IAS),21)
+KBUILD_AFLAGS	+= -Wa,-gdwarf-$(DWARF_VERSION)
+endif
+
+ifdef CONFIG_CC_IS_CLANG
+ifneq ($(LLVM_IAS),1)
+KBUILD_CFLAGS	+= -Wa,-gdwarf-$(DWARF_VERSION)
+endif

endif

ifdef CONFIG_DEBUG_INFO_REDUCED

include/asm-generic/vmlinux.lds.h +0 -0
index cd14444bf600..0382808ef9fe 100644

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

Quoted 9 lines
include/asm-generic/vmlinux.lds.h +5 -1
@@ -828,7 +828,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) }

Consider adding .debug_names for the accelerator table.
It is the DWARF v5 version of .debug_pub{names,types} (which are mentioned a few lines above).

Quoted 11 lines
include/asm-generic/vmlinux.lds.h +0 -0
 /* Stabs debugging sections. */
 #define STABS_DEBUG							\
lib/Kconfig.debug +1 -0
index 537cf3c2937d..6b01f0e2dad8 100644
@@ -256,14 +256,35 @@ config DEBUG_INFO_SPLIT
 	  to know about the .dwo files and include them.
 	  Incompatible with older versions of ccache.
 
+choice

lib/Kconfig.debug config DEBUG_INFO_SPLIT · line 269

Quoted 10 lines
lib/Kconfig.debug +10 -0
+prompt "DWARF version"
+	depends on DEBUG_INFO
+	default DEBUG_INFO_DWARF2
+	help
+	  Which version of DWARF debug info to emit.
+
+config DEBUG_INFO_DWARF2
+	bool "Generate dwarf2 debuginfo"
+	help
+	  Generate dwarf2 debug info.

In documentation, a more official way to refer to the format is: DWARF v2. (While "DWARF5" and "DWARF v5" are acceptable, the latter is preferred) Ditto below.

Quoted 41 lines

config DEBUG_INFO_DWARF4

	bool "Generate dwarf4 debuginfo"
	depends on $(cc-option,-gdwarf-4)
	help
lib/Kconfig.debug +13 -4
-	  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 dwarf4 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.
+
+config DEBUG_INFO_DWARF5
+	bool "Generate dwarf5 debuginfo"
+	depends on DEBUG_INFO
+	depends on $(success,$(srctree)/scripts/test_dwarf5_support.sh $(CC) $(CLANG_FLAGS))
+	help
+	  Genereate dwarf5 debug info. Requires binutils 2.35+, gcc 5.1+, and
+	  gdb 8.0+.
+
+endchoice # "DWARF version"

config DEBUG_INFO_BTF
bool "Generate BTF typeinfo"

scripts/test_dwarf5_support.sh new file +4 -0
new file mode 100755
index 000000000000..82c0eea45845
@@ -0,0 +1,4 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+set -eu
+echo ".file 0 \"asdf\"" | $* -Wa,-gdwarf-5 -c -x assembler -o /dev/null -
Signature · 6 lines
2.29.0.rc1.297.gfa9743e501-goog

-- 
You received this message because you are subscribed to the Google Groups "Clang Built Linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/20201022012106.1875129-1-ndesaulniers%40google.com.
#2 lore raw
Quoted 10 lines · Fangrui Song
Quoted 8 lines · Nick Desaulniers' via Clang Built Linux

DWARF5 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. Further -gdwarf-X where X is an unsupported value doesn't produce an error in $(CC). GNU as only recently gained support for specifying -gdwarf-5.

Quoted 5 lines
Quoted 1 line

The DWARF version of a binary can be validated with:

To be more correct: this is just the version number of the .debug_info section. Other sections can use different version numbers.
(For example, GNU as still does not support version 5 .debug_line)

How do you recommend we validate that then?

Quoted 14 lines
Quoted 14 lines
$ llvm-dwarfdump vmlinux | head -n 5 | grep version
or
$ readelf --debug-dump=info vmlinux 2>/dev/null | grep Version
include/asm-generic/vmlinux.lds.h +1 -1
index cd14444bf600..0382808ef9fe 100644
@@ -828,7 +828,11 @@
              .debug_types    0 : { *(.debug_types) }                 \
              /* DWARF 5 */                                           \
              .debug_macro    0 : { *(.debug_macro) }                 \
-              .debug_addr     0 : { *(.debug_addr) }
+              .debug_addr     0 : { *(.debug_addr) }                  \
Quoted 8 lines

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

Quoted 4 lines
include/asm-generic/vmlinux.lds.h +4 -0
+              .debug_line_str 0 : { *(.debug_line_str) }              \
+              .debug_loclists 0 : { *(.debug_loclists) }              \
+              .debug_rnglists 0 : { *(.debug_rnglists) }              \
+              .debug_str_offsets 0 : { *(.debug_str_offsets) }

Consider adding .debug_names for the accelerator table.
It is the DWARF v5 version of .debug_pub{names,types} (which are mentioned a few lines above).

I hadn't seen that section produced in my limited testing. Being a fan of TDD, I kind of would like to see the linker warn on orphan section placement, then add it to the list, as I did with the above. Do you have more info on when or how .debug_pub* can be produced?

Thanks for the rest of the feedback, I'll incorporate it into v2.

Signature · 2 lines
Thanks,
~Nick Desaulniers
#3 lore raw
In reply to Nick Desaulniers

Hi Masahiro,
I plan to incorporate Fangrui's recommendation into a v2. Do you have additional thoughts on changes I should make in v2? Have you had the chance to test the patch? Should I split it into a series? What do you think about the Kconfig choice changes?

Quoted 157 lines · Nick Desaulniers

DWARF5 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. Further -gdwarf-X where X is an unsupported value doesn't produce an error in $(CC). GNU as only recently gained support for specifying -gdwarf-5.

The DWARF version of a binary can be validated with:

$ llvm-dwarfdump vmlinux | head -n 5 | 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

Make CONFIG_DEBUG_INFO_DWARF4 part of a Kconfig choice to preserve forward compatibility.

---
RFC because this patch is super half baked, but I'm looking for feedback.

I would logically split this into a series of patches;
1. disable -Wa,gdwarf-2 for LLVM_IAS=1, see also
https://github.com/ClangBuiltLinux/linux/issues/716
https://github.com/ClangBuiltLinux/continuous-integration/blob/master/patches/llvm-all/linux-next/arm64/silence-dwarf2-warnings.patch
that way we can backport for improved LLVM_IAS support.
2. move CONFIG_DEBUG_INFO_DWARF4 to choice.
3. implement the rest on top.

I'm pretty sure GNU as only recently gained the ability to specify -gdwarf-4 without erroring in binutils 2.35, so that part likely needs to be fixed.

 Makefile                          | 19 ++++++++++++++++---
 include/asm-generic/vmlinux.lds.h |  6 +++++-
 lib/Kconfig.debug                 | 29 +++++++++++++++++++++++++----
 scripts/test_dwarf5_support.sh    |  4 ++++
 4 files changed, 50 insertions(+), 8 deletions(-)
 create mode 100755 scripts/test_dwarf5_support.sh
Makefile +16 -3
index e71979882e4f..0862df5b1a24 100644
@@ -828,10 +828,23 @@ else
 DEBUG_CFLAGS   += -g
 endif
 
-KBUILD_AFLAGS  += -Wa,-gdwarf-2
-
+DWARF_VERSION=2
 ifdef CONFIG_DEBUG_INFO_DWARF4
-DEBUG_CFLAGS   += -gdwarf-4
+DWARF_VERSION=4
+endif
+ifdef CONFIG_DEBUG_INFO_DWARF5
+DWARF_VERSION=5
+endif
+DEBUG_CFLAGS   += -gdwarf-$(DWARF_VERSION)
+
+ifneq ($(DWARF_VERSION)$(LLVM_IAS),21)
+KBUILD_AFLAGS  += -Wa,-gdwarf-$(DWARF_VERSION)
+endif
+
+ifdef CONFIG_CC_IS_CLANG
+ifneq ($(LLVM_IAS),1)
+KBUILD_CFLAGS  += -Wa,-gdwarf-$(DWARF_VERSION)
+endif
 endif
 
 ifdef CONFIG_DEBUG_INFO_REDUCED
include/asm-generic/vmlinux.lds.h +5 -1
index cd14444bf600..0382808ef9fe 100644
@@ -828,7 +828,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 +25 -4
index 537cf3c2937d..6b01f0e2dad8 100644
@@ -256,14 +256,35 @@ config DEBUG_INFO_SPLIT
          to know about the .dwo files and include them.
          Incompatible with older versions of ccache.
 
+choice
+prompt "DWARF version"
+       depends on DEBUG_INFO
+       default DEBUG_INFO_DWARF2
+       help
+         Which version of DWARF debug info to emit.
+
+config DEBUG_INFO_DWARF2
+       bool "Generate dwarf2 debuginfo"
+       help
+         Generate dwarf2 debug info.
+
 config DEBUG_INFO_DWARF4
        bool "Generate dwarf4 debuginfo"
        depends on $(cc-option,-gdwarf-4)
        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 dwarf4 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.
+
+config DEBUG_INFO_DWARF5
+       bool "Generate dwarf5 debuginfo"
+       depends on DEBUG_INFO
+       depends on $(success,$(srctree)/scripts/test_dwarf5_support.sh $(CC) $(CLANG_FLAGS))
+       help
+         Genereate dwarf5 debug info. Requires binutils 2.35+, gcc 5.1+, and
+         gdb 8.0+.
+
+endchoice # "DWARF version"
 
 config DEBUG_INFO_BTF
        bool "Generate BTF typeinfo"
scripts/test_dwarf5_support.sh new file +4 -1
new file mode 100755
index 000000000000..82c0eea45845
@@ -0,0 +1,4 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+set -eu
+echo ".file 0 \"asdf\"" | $* -Wa,-gdwarf-5 -c -x assembler -o /dev/null -
--

2.29.0.rc1.297.gfa9743e501-goog

Signature · 2 lines
Thanks,
~Nick Desaulniers
#4 lore raw
In reply to Nick Desaulniers
Quoted 57 lines · Nick Desaulniers' via Clang Built Linux

DWARF5 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. Further -gdwarf-X where X is an unsupported value doesn't produce an error in $(CC). GNU as only recently gained support for specifying -gdwarf-5.

The DWARF version of a binary can be validated with:

$ llvm-dwarfdump vmlinux | head -n 5 | 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

Make CONFIG_DEBUG_INFO_DWARF4 part of a Kconfig choice to preserve forward compatibility.

---
RFC because this patch is super half baked, but I'm looking for feedback.

I would logically split this into a series of patches;
1. disable -Wa,gdwarf-2 for LLVM_IAS=1, see also
https://github.com/ClangBuiltLinux/linux/issues/716
https://github.com/ClangBuiltLinux/continuous-integration/blob/master/patches/llvm-all/linux-next/arm64/silence-dwarf2-warnings.patch
that way we can backport for improved LLVM_IAS support.
2. move CONFIG_DEBUG_INFO_DWARF4 to choice.
3. implement the rest on top.

I'm pretty sure GNU as only recently gained the ability to specify -gdwarf-4 without erroring in binutils 2.35, so that part likely needs to be fixed.

 Makefile                          | 19 ++++++++++++++++---
 include/asm-generic/vmlinux.lds.h |  6 +++++-
 lib/Kconfig.debug                 | 29 +++++++++++++++++++++++++----
 scripts/test_dwarf5_support.sh    |  4 ++++
 4 files changed, 50 insertions(+), 8 deletions(-)
 create mode 100755 scripts/test_dwarf5_support.sh
Makefile +0 -0
index e71979882e4f..0862df5b1a24 100644

Makefile else · line 831

Quoted 6 lines
Makefile +1 -2
@@ -828,10 +828,23 @@ else
 DEBUG_CFLAGS   += -g
 endif
 
-KBUILD_AFLAGS  += -Wa,-gdwarf-2
-
+DWARF_VERSION=2

This is not a shell script.
You can add spaces around '='

Makefile else · line 837

Quoted 7 lines
Makefile +5 -1
 ifdef CONFIG_DEBUG_INFO_DWARF4
-DEBUG_CFLAGS   += -gdwarf-4
+DWARF_VERSION=4
+endif
+ifdef CONFIG_DEBUG_INFO_DWARF5
+DWARF_VERSION=5
+endif

This might be a bit tricky, but you can do like this if you like:

dwarf-version-$(CONFIG_DEBUG_INFO_DWARF2) := 2
dwarf-version-$(CONFIG_DEBUG_INFO_DWARF3) := 3
dwarf-version-$(CONFIG_DEBUG_INFO_DWARF5) := 5

DEBUG_CFLAGS += -gdwarf-$(dwarf-version-y)

Quoted 35 lines
Makefile +10 -0
+DEBUG_CFLAGS   += -gdwarf-$(DWARF_VERSION)
+
+ifneq ($(DWARF_VERSION)$(LLVM_IAS),21)
+KBUILD_AFLAGS  += -Wa,-gdwarf-$(DWARF_VERSION)
+endif
+
+ifdef CONFIG_CC_IS_CLANG
+ifneq ($(LLVM_IAS),1)
+KBUILD_CFLAGS  += -Wa,-gdwarf-$(DWARF_VERSION)
+endif
 endif
 
 ifdef CONFIG_DEBUG_INFO_REDUCED
include/asm-generic/vmlinux.lds.h +5 -1
index cd14444bf600..0382808ef9fe 100644
@@ -828,7 +828,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 +0 -0
index 537cf3c2937d..6b01f0e2dad8 100644

lib/Kconfig.debug config DEBUG_INFO_SPLIT · line 260

Quoted 5 lines
lib/Kconfig.debug +2 -0
@@ -256,14 +256,35 @@ config DEBUG_INFO_SPLIT
          to know about the .dwo files and include them.
          Incompatible with older versions of ccache.
 
+choice
+prompt "DWARF version"

Indentation for 'prompt'.

lib/Kconfig.debug config DEBUG_INFO_SPLIT · line 261

Quoted 1 line
lib/Kconfig.debug +1 -0
+       depends on DEBUG_INFO

Unneeded.

This block resides inside 'if DEBUG_INFO'

lib/Kconfig.debug config DEBUG_INFO_SPLIT · line 262

Quoted 1 line
lib/Kconfig.debug +1 -0
+       default DEBUG_INFO_DWARF2

This is unneeded because the first entry
is the default.

Quoted 38 lines
lib/Kconfig.debug +21 -4
+       help
+         Which version of DWARF debug info to emit.
+
+config DEBUG_INFO_DWARF2
+       bool "Generate dwarf2 debuginfo"
+       help
+         Generate dwarf2 debug info.
+
 config DEBUG_INFO_DWARF4
        bool "Generate dwarf4 debuginfo"
        depends on $(cc-option,-gdwarf-4)
        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 dwarf4 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.
+
+config DEBUG_INFO_DWARF5
+       bool "Generate dwarf5 debuginfo"
+       depends on DEBUG_INFO
+       depends on $(success,$(srctree)/scripts/test_dwarf5_support.sh $(CC) $(CLANG_FLAGS))
+       help
+         Genereate dwarf5 debug info. Requires binutils 2.35+, gcc 5.1+, and
+         gdb 8.0+.
+
+endchoice # "DWARF version"
 
 config DEBUG_INFO_BTF
        bool "Generate BTF typeinfo"
scripts/test_dwarf5_support.sh new file +0 -0
new file mode 100755
index 000000000000..82c0eea45845

scripts/test_dwarf5_support.sh line 4

Quoted 4 lines
scripts/test_dwarf5_support.sh new file +4 -0
@@ -0,0 +1,4 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+set -eu
+echo ".file 0 \"asdf\"" | $* -Wa,-gdwarf-5 -c -x assembler -o /dev/null -

Please tell me how this script detects the dwarf-5 capability.

This script fails for GCC 10.

masahiro@grover:~/workspace/linux-kbuild$
./scripts/test_dwarf5_support.sh clang

masahiro@grover:~/workspace/linux-kbuild$ echo $?
0
masahiro@grover:~/workspace/linux-kbuild$
./scripts/test_dwarf5_support.sh gcc-10
{standard input}: Assembler messages:
{standard input}:1: Error: file number less than one
masahiro@grover:~/workspace/linux-kbuild$ echo $?
1

The manual says the fileno should be "a positive integer".

.file fileno filename

When emitting dwarf2 line number information .file assigns filenames
to the .debug_line file name table.
The fileno operand should be a unique positive integer to use as the
index of the entry in the table.
The filename operand is a C string literal.

The detail of filename indices is exposed to the user because the
filename table is shared with the
.debug_info section of the dwarf2 debugging information, and thus
the user must know the exact indices
that table entries will have.

So, I modified the script as follows:

masahiro@grover:~/workspace/linux-kbuild$ git diff
scripts/test_dwarf5_support.sh +1 -1
index 82c0eea45845..8d7213e8e51f 100755
@@ -1,4 +1,4 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0
 set -eu
-echo ".file 0 \"asdf\"" | $* -Wa,-gdwarf-5 -c -x assembler -o /dev/null -
+echo ".file 1 \"asdf\"" | $* -Wa,-gdwarf-5 -c -x assembler -o /dev/null -
masahiro@grover:~/workspace/linux-kbuild$ ./scripts/test_dwarf5_support.sh  gcc
masahiro@grover:~/workspace/linux-kbuild$ echo $?
0

But, GCC 4.9 also passes this check.

masahiro@grover:~/workspace/linux-kbuild$ ~/tools/aarch64-linaro-4.9/bin/aarch64-linux-gnu-gcc --version aarch64-linux-gnu-gcc (Linaro GCC 4.9-2016.02) 4.9.4 20151028 (prerelease) Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

masahiro@grover:~/workspace/linux-kbuild$ ./scripts/test_dwarf5_support.sh ~/tools/aarch64-linaro-4.9/bin/aarch64-linux-gnu-gcc

masahiro@grover:~/workspace/linux-kbuild$ echo $?
0

Some nit-pickings.

echo '.file 0 "asdf"'

... might look cleaner because you do not need to
use escaping inside the single-quotes.

'set -u' seems to have no effect because "$*"
is the only variable expansion in this script.

-u Treat unset variables and parameters other than
the special parameters "@" and
"*" as an error when performing parameter
expansion. If expansion is attempted
on an unset variable or parameter, the shell
prints an error message, and, if
not interactive, exits with a non-zero status.

Quoted 7 lines

--
2.29.0.rc1.297.gfa9743e501-goog

--
You received this message because you are subscribed to the Google Groups "Clang Built Linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/20201022012106.1875129-1-ndesaulniers%40google.com.

--
Best Regards

Masahiro Yamada

#5 lore raw
Quoted 13 lines · Masahiro Yamada

scripts/test_dwarf5_support.sh line 4

Quoted 7 lines
scripts/test_dwarf5_support.sh new file +4 -0
@@ -0,0 +1,4 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+set -eu
+echo ".file 0 \"asdf\"" | $* -Wa,-gdwarf-5 -c -x assembler -o /dev/null -

Please tell me how this script detects the dwarf-5 capability.

Quoted 1 line

This script fails for GCC 10.

One thing is GCC DWARF-5 support, that is whether the compiler will support -gdwarf-5 flag, and that support should be there from GCC 7 onwards.

Another separate thing is whether the assembler does support the -gdwarf-5 option (i.e. if you can compile assembler files with -Wa,-gdwarf-5) for GNU as I think that is binutils 35.1, i.e. very new); but only if you want to pass the -Wa,-gdwarf-5 only when compiling *.s and *.S files. That option is about whether the assembler will emit DWARF5 or DWARF2 .debug_line.
It is fine to compile C sources with -gdwarf-5 and use DWARF2 .debug_line for assembler files if as doesn't support it.

Yet another thing is if you can pass -Wa,-gdwarf-5 even when compiling C files. There are several bugs in that category that have been fixed only in the last few days on binutils trunk, I'd suggest just not to bother, GCC 11 will have proper test for fixed assembler and will pass -gdwarf-5 to as when compiling even C sources with -gdwarf-5. The reason is to get DWARF5 .debug_line (.debug_line is usually produced by the assembler, not compiler, from .file/.loc directives).

Jakub

#6 lore raw
Quoted 15 lines · Jakub Jelinek
Quoted 13 lines · Masahiro Yamada

scripts/test_dwarf5_support.sh line 4

Quoted 7 lines
scripts/test_dwarf5_support.sh new file +4 -0
@@ -0,0 +1,4 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+set -eu
+echo ".file 0 \"asdf\"" | $* -Wa,-gdwarf-5 -c -x assembler -o /dev/null -

Please tell me how this script detects the dwarf-5 capability.

Quoted 5 lines
Quoted 1 line

This script fails for GCC 10.

One thing is GCC DWARF-5 support, that is whether the compiler will support -gdwarf-5 flag, and that support should be there from GCC 7 onwards.

I should improve my Kconfig check; I don't actually have a test for -gdwarf-5 for the compiler. In godbolt, it looks like -gdwarf-5 produces an error from GCC up until GCC 5.1. Does (5.1 < GCC < 7) not produce DWARF5? Maybe there's a more specific test you had in mind?

Quoted 10 lines

Another separate thing is whether the assembler does support the -gdwarf-5 option (i.e. if you can compile assembler files with -Wa,-gdwarf-5) for GNU as I think that is binutils 35.1, i.e. very new); but only if you want to pass the -Wa,-gdwarf-5 only when compiling *.s and *.S files. That option is about whether the assembler will emit DWARF5 or DWARF2 .debug_line.
It is fine to compile C sources with -gdwarf-5 and use DWARF2 .debug_line for assembler files if as doesn't support it.

Quoted 5 lines

Yet another thing is if you can pass -Wa,-gdwarf-5 even when compiling C files. There are several bugs in that category that have been fixed only in the last few days on binutils trunk, I'd suggest just not to bother, GCC 11 will have proper test for fixed assembler and will pass -gdwarf-5 to as when compiling even C sources with -gdwarf-5.

Do you have links? I would prefer to do feature detection rather than version detection when possible. If the bug is so severe that we think we should scuttle support for old versions, I'm ok with that, but I want to be able to link to hard proof in a commit message so that in 6 months when I forget why we made a certain decision, we have historical record in the commit message/git blame.

Signature · 2 lines
Thanks,
~Nick Desaulniers
#7 lore raw
Quoted 10 lines · Nick Desaulniers
Quoted 5 lines
Quoted 1 line

This script fails for GCC 10.

One thing is GCC DWARF-5 support, that is whether the compiler will support -gdwarf-5 flag, and that support should be there from GCC 7 onwards.

I should improve my Kconfig check; I don't actually have a test for -gdwarf-5 for the compiler. In godbolt, it looks like -gdwarf-5 produces an error from GCC up until GCC 5.1. Does (5.1 < GCC < 7) not produce DWARF5?

No. After all, those versions also predate DWARF5.
All 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, e.g. including switching over most of the now
standardized GNU extensions from their DW_*_GNU_* codes to DWARF5 DW_*).
With GCC 5/6, you get:
echo 'int i;' | gcc -c -o /tmp/test.o -xc - -gdwarf-5; readelf -wi /tmp/test.o | grep Version:
Version: 4
while with 7+
Version: 5
instead.

Quoted 1 line

Maybe there's a more specific test you had in mind?

Guess what you want to test is what version you actually get in .debug_info if you compile with -gdwarf-5.

Quoted 9 lines
Quoted 9 lines

Another separate thing is whether the assembler does support the -gdwarf-5 option (i.e. if you can compile assembler files with -Wa,-gdwarf-5) for GNU as I think that is binutils 35.1, i.e. very new); but only if you want to pass the -Wa,-gdwarf-5 only when compiling *.s and *.S files. That option is about whether the assembler will emit DWARF5 or DWARF2 .debug_line.
It is fine to compile C sources with -gdwarf-5 and use DWARF2 .debug_line for assembler files if as doesn't support it.

Quoted 7 lines
Quoted 5 lines

Yet another thing is if you can pass -Wa,-gdwarf-5 even when compiling C files. There are several bugs in that category that have been fixed only in the last few days on binutils trunk, I'd suggest just not to bother, GCC 11 will have proper test for fixed assembler and will pass -gdwarf-5 to as when compiling even C sources with -gdwarf-5.

Do you have links? I would prefer to do feature detection rather than

The
https://gcc.gnu.org/r11-3693
https://gcc.gnu.org/r11-4338
commits contain those tests in gcc/configure.ac

Jakub

#8 lore raw
In reply to Masahiro Yamada
Quoted 4 lines · Masahiro Yamada
Quoted 1 line · Nick Desaulniers' via Clang Built Linux
Quoted 14 lines

scripts/test_dwarf5_support.sh line 4

Quoted 10 lines
scripts/test_dwarf5_support.sh new file +4 -0
new file mode 100755
index 000000000000..82c0eea45845
@@ -0,0 +1,4 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+set -eu
+echo ".file 0 \"asdf\"" | $* -Wa,-gdwarf-5 -c -x assembler -o /dev/null -

Please tell me how this script detects the dwarf-5 capability.

Ah, sorry, I should have put more context. Specifically, I wrote this patch initially back in May, but testing combinations of:
- GCC + GNU as
- Clang + GNU as
- Clang + LLVM_IAS
I hit a few snags in GNU as. I reported the issues, and they were quickly fixed. The fixes shipped in binutils 2.35 (or 2.35.1 as Jakub notes).
https://sourceware.org/bugzilla/show_bug.cgi?id=25611
https://sourceware.org/bugzilla/show_bug.cgi?id=25612
https://sourceware.org/bugzilla/show_bug.cgi?id=25614 <-- .file 0
https://sourceware.org/bugzilla/show_bug.cgi?id=25917

This script is doing feature detection of .file 0 directives (which is new in DWARF5) in the assembler and actively emitted by Clang. I'm happy to add whatever other unit tests might be interesting for detecting correct support for various features, if we find them to be required, which I'd say .file 0 certainly is.

Probably could test GCC + LLVM_IAS, too.

Hence we need to test compiler and assembler support; either may be lacking.

Quoted 1 line

This script fails for GCC 10.

What is your version of binutils? Less than 2.35 I suspect? If so, then that's expected and the script is working as intended.

Thanks for your feedback, I'll try to get a v2 out this week incorporating feedback from you, Fangrui, and Jakub.

Quoted 73 lines

masahiro@grover:~/workspace/linux-kbuild$
./scripts/test_dwarf5_support.sh clang

masahiro@grover:~/workspace/linux-kbuild$ echo $?
0
masahiro@grover:~/workspace/linux-kbuild$
./scripts/test_dwarf5_support.sh gcc-10
{standard input}: Assembler messages:
{standard input}:1: Error: file number less than one
masahiro@grover:~/workspace/linux-kbuild$ echo $?
1

The manual says the fileno should be "a positive integer".

.file fileno filename

When emitting dwarf2 line number information .file assigns filenames
to the .debug_line file name table.
The fileno operand should be a unique positive integer to use as the
index of the entry in the table.
The filename operand is a C string literal.

The detail of filename indices is exposed to the user because the
filename table is shared with the
.debug_info section of the dwarf2 debugging information, and thus
the user must know the exact indices
that table entries will have.

So, I modified the script as follows:

masahiro@grover:~/workspace/linux-kbuild$ git diff
scripts/test_dwarf5_support.sh +1 -1
index 82c0eea45845..8d7213e8e51f 100755
@@ -1,4 +1,4 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0
 set -eu
-echo ".file 0 \"asdf\"" | $* -Wa,-gdwarf-5 -c -x assembler -o /dev/null -
+echo ".file 1 \"asdf\"" | $* -Wa,-gdwarf-5 -c -x assembler -o /dev/null -



masahiro@grover:~/workspace/linux-kbuild$ ./scripts/test_dwarf5_support.sh  gcc
masahiro@grover:~/workspace/linux-kbuild$ echo $?
0

But, GCC 4.9 also passes this check.

masahiro@grover:~/workspace/linux-kbuild$ ~/tools/aarch64-linaro-4.9/bin/aarch64-linux-gnu-gcc --version aarch64-linux-gnu-gcc (Linaro GCC 4.9-2016.02) 4.9.4 20151028 (prerelease) Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

masahiro@grover:~/workspace/linux-kbuild$ ./scripts/test_dwarf5_support.sh ~/tools/aarch64-linaro-4.9/bin/aarch64-linux-gnu-gcc

masahiro@grover:~/workspace/linux-kbuild$ echo $?
0
Signature · 2 lines
Thanks,
~Nick Desaulniers
#9 lore raw

v2 cover Kbuild: DWARF v5 support

In reply to Masahiro Yamada

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

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

Patch 1 is a fixup already sent, but necessary for trying to use LLVM_IAS=1 with ToT LLVM.
https://lore.kernel.org/stable/[email protected]/

Patches 2 and 3 are cleanups that lay the ground work and aren't DWARF v5 specific. In particular, I would like to see Patch 2 sent to stable so that Android and CrOS can move to LLVM_IAS=1 ASAP.

Patch 4 implements Kconfig and Kbuild support for DWARFv5.

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.

Fangrui Song (1):
x86_64: Change .weak to SYM_FUNC_START_WEAK for arch/x86/lib/mem*_64.S

Nick Desaulniers (3):
Kbuild: do not emit debug info for assembly with LLVM_IAS=1
Kbuild: make DWARF version a choice
Kbuild: implement support for DWARF v5

 Makefile                          | 13 +++++++++----
 arch/x86/lib/memcpy_64.S          |  4 +---
 arch/x86/lib/memmove_64.S         |  4 +---
 arch/x86/lib/memset_64.S          |  4 +---
 include/asm-generic/vmlinux.lds.h |  6 +++++-
 lib/Kconfig.debug                 | 27 +++++++++++++++++++++++----
 scripts/test_dwarf5_support.sh    |  9 +++++++++
 7 files changed, 49 insertions(+), 18 deletions(-)
 create mode 100755 scripts/test_dwarf5_support.sh
Signature · 1 line
2.29.1.341.ge80a0c044ae-goog
#10 lore raw

PATCH v2 1/4 x86_64: Change .weak to SYM_FUNC_START_WEAK for arch/x86/lib/mem*_64.S

From: Fangrui Song <[email protected]>

Commit 393f203f5fd5 ("x86_64: kasan: add interceptors for memset/memmove/memcpy functions") added .weak directives to arch/x86/lib/mem*_64.S instead of changing the existing ENTRY macros to WEAK. This can lead to the assembly snippet .weak memcpy ... .globl memcpy which will produce a STB_WEAK memcpy with GNU as but STB_GLOBAL memcpy with LLVM's integrated assembler before LLVM 12. LLVM 12 (since
https://reviews.llvm.org/D90108) will error on such an overridden symbol binding.

Commit ef1e03152cb0 ("x86/asm: Make some functions local") changed ENTRY in arch/x86/lib/memcpy_64.S to SYM_FUNC_START_LOCAL, which was ineffective due to the preceding .weak directive.

Use the appropriate SYM_FUNC_START_WEAK instead.

Fixes 393f203f5fd5 ("x86_64: kasan: add interceptors for memset/memmove/memcpy functions")
Fixes ef1e03152cb0 ("x86/asm: Make some functions local")
---
 arch/x86/lib/memcpy_64.S  | 4 +---
 arch/x86/lib/memmove_64.S | 4 +---
 arch/x86/lib/memset_64.S  | 4 +---
 3 files changed, 3 insertions(+), 9 deletions(-)
arch/x86/lib/memcpy_64.S +1 -3
index 037faac46b0c..1e299ac73c86 100644
@@ -16,8 +16,6 @@
  * to a jmp to memcpy_erms which does the REP; MOVSB mem copy.
  */
 
-.weak memcpy
-
 /*
  * memcpy - Copy a memory block.
  *
@@ -30,7 +28,7 @@
  * rax original destination
  */
 SYM_FUNC_START_ALIAS(__memcpy)
-SYM_FUNC_START_LOCAL(memcpy)
+SYM_FUNC_START_WEAK(memcpy)
 	ALTERNATIVE_2 "jmp memcpy_orig", "", X86_FEATURE_REP_GOOD, \
 		      "jmp memcpy_erms", X86_FEATURE_ERMS
 
arch/x86/lib/memmove_64.S +1 -3
index 7ff00ea64e4f..41902fe8b859 100644
@@ -24,9 +24,7 @@
  * Output:
  * rax: dest
  */
-.weak memmove
-
-SYM_FUNC_START_ALIAS(memmove)
+SYM_FUNC_START_WEAK(memmove)
 SYM_FUNC_START(__memmove)
 
 	mov %rdi, %rax
arch/x86/lib/memset_64.S +1 -3
index 9ff15ee404a4..0bfd26e4ca9e 100644
@@ -6,8 +6,6 @@
 #include <asm/alternative-asm.h>
 #include <asm/export.h>
 
-.weak memset
-
 /*
  * ISO C memset - set a memory block to a byte value. This function uses fast
  * string to get better performance than the original function. The code is
@@ -19,7 +17,7 @@
  *
  * rax   original destination
  */
-SYM_FUNC_START_ALIAS(memset)
+SYM_FUNC_START_WEAK(memset)
 SYM_FUNC_START(__memset)
 	/*
 	 * Some CPUs support enhanced REP MOVSB/STOSB feature. It is recommended
Signature · 1 line
2.29.1.341.ge80a0c044ae-goog
#11 lore raw

PATCH v2 2/4 Kbuild: do not emit debug info for assembly with LLVM_IAS=1

In reply to Nick Desaulniers

Clang's integrated assembler produces the warning for assembly files:

warning: DWARF2 only supports one section per compilation unit

If -Wa,-gdwarf-* is unspecified, then debug info is not emitted. This will be re-enabled for new DWARF versions in a follow up patch.

Enables defconfig+CONFIG_DEBUG_INFO to build cleanly with LLVM=1 LLVM_IAS=1 for x86_64 and arm64.

---
 Makefile | 2 ++
 1 file changed, 2 insertions(+)
Makefile +2 -0
index f353886dbf44..75b1a3dcbf30 100644
@@ -826,7 +826,9 @@ else
 DEBUG_CFLAGS	+= -g
 endif
 
+ifndef LLVM_IAS
 KBUILD_AFLAGS	+= -Wa,-gdwarf-2
+endif
 
 ifdef CONFIG_DEBUG_INFO_DWARF4
 DEBUG_CFLAGS	+= -gdwarf-4
Signature · 1 line
2.29.1.341.ge80a0c044ae-goog
Reviewed-by on v2 2/4
#12 lore raw

Re: [PATCH v2 2/4] Kbuild: do not emit debug info for assembly with LLVM_IAS=1

Quoted 5 lines · Nick Desaulniers

Clang's integrated assembler produces the warning for assembly files:

warning: DWARF2 only supports one section per compilation unit

If -Wa,-gdwarf-* is unspecified, then debug info is not emitted. This

Is this something that should be called out somewhere? If I understand this correctly, LLVM_IAS=1 + CONFIG_DEBUG_INFO=y won't work? Maybe this should be handled in Kconfig?

Quoted 9 lines

will be re-enabled for new DWARF versions in a follow up patch.

Enables defconfig+CONFIG_DEBUG_INFO to build cleanly with LLVM=1 LLVM_IAS=1 for x86_64 and arm64.

If you happen to respin, Dmitry deserves a Reported-by tag too :)

Quoted 2 lines

Regardless of the other two comments, this is fine as is as a fix for stable to unblock Android + CrOS since we have been running something similar to it in CI:

Makefile else · line 829

Quoted 13 lines
---
 Makefile | 2 ++
 1 file changed, 2 insertions(+)
Makefile +1 -0
index f353886dbf44..75b1a3dcbf30 100644
@@ -826,7 +826,9 @@ else
 DEBUG_CFLAGS	+= -g
 endif
 
+ifndef LLVM_IAS

Nit: this should probably match the existing LLVM_IAS check

ifneq ($(LLVM_IAS),1)

Quoted 8 lines
Makefile +1 -0
 KBUILD_AFLAGS	+= -Wa,-gdwarf-2
+endif
 
 ifdef CONFIG_DEBUG_INFO_DWARF4
 DEBUG_CFLAGS	+= -gdwarf-4
Signature · 1 line
2.29.1.341.ge80a0c044ae-goog
Reviewed-by
#13 lore raw

Re: [PATCH v2 2/4] Kbuild: do not emit debug info for assembly with LLVM_IAS=1

Quoted 44 lines · Nathan Chancellor
Quoted 5 lines · Nick Desaulniers

Clang's integrated assembler produces the warning for assembly files:

warning: DWARF2 only supports one section per compilation unit

If -Wa,-gdwarf-* is unspecified, then debug info is not emitted. This

Is this something that should be called out somewhere? If I understand this correctly, LLVM_IAS=1 + CONFIG_DEBUG_INFO=y won't work? Maybe this should be handled in Kconfig?

Quoted 9 lines

will be re-enabled for new DWARF versions in a follow up patch.

Enables defconfig+CONFIG_DEBUG_INFO to build cleanly with LLVM=1 LLVM_IAS=1 for x86_64 and arm64.

If you happen to respin, Dmitry deserves a Reported-by tag too :)

Quoted 2 lines

Regardless of the other two comments, this is fine as is as a fix for stable to unblock Android + CrOS since we have been running something similar to it in CI:

Quoted 12 lines
---
 Makefile | 2 ++
 1 file changed, 2 insertions(+)
Makefile +0 -0
index f353886dbf44..75b1a3dcbf30 100644
@@ -826,7 +826,9 @@ else
 DEBUG_CFLAGS	+= -g
 endif
 
Quoted 14 lines

Makefile else · line 829

Quoted 1 line
Makefile +1 -0
+ifndef LLVM_IAS

Nit: this should probably match the existing LLVM_IAS check

ifneq ($(LLVM_IAS),1)

Quoted 8 lines
Makefile +1 -1
 KBUILD_AFLAGS	+= -Wa,-gdwarf-2
+endif
 
 ifdef CONFIG_DEBUG_INFO_DWARF4
 DEBUG_CFLAGS	+= -gdwarf-4
--

2.29.1.341.ge80a0c044ae-goog

The root cause is that DWARF v2 has no DW_AT_ranges, so it cannot represent non-contiguous address ranges. It seems that GNU as -gdwarf-3 emits DW_AT_ranges as well and emits an entry for a non-executable section. In any case, the option is of very low value, at least for LLVM.

#14 lore raw

Re: [PATCH v2 2/4] Kbuild: do not emit debug info for assembly with LLVM_IAS=1

In reply to Nathan Chancellor
Quoted 11 lines · Nathan Chancellor
Quoted 5 lines · Nick Desaulniers

Clang's integrated assembler produces the warning for assembly files:

warning: DWARF2 only supports one section per compilation unit

If -Wa,-gdwarf-* is unspecified, then debug info is not emitted. This

Is this something that should be called out somewhere? If I understand this correctly, LLVM_IAS=1 + CONFIG_DEBUG_INFO=y won't work? Maybe this should be handled in Kconfig?

Specifically, debug info will not be emitted, for assembler source files. It will still be emitted for C source files (via -gdwarf-*). -Wa,-gdwarf-* only affects assembler file sources.

Quoted 6 lines
Quoted 6 lines

will be re-enabled for new DWARF versions in a follow up patch.

Enables defconfig+CONFIG_DEBUG_INFO to build cleanly with LLVM=1 LLVM_IAS=1 for x86_64 and arm64.

Quoted 6 lines
Quoted 4 lines

If you happen to respin, Dmitry deserves a Reported-by tag too :)

Sure.

Quoted 22 lines
Quoted 3 lines

Regardless of the other two comments, this is fine as is as a fix for stable to unblock Android + CrOS since we have been running something similar to it in CI:

Quoted 12 lines
---
 Makefile | 2 ++
 1 file changed, 2 insertions(+)
Makefile +0 -0
index f353886dbf44..75b1a3dcbf30 100644
@@ -826,7 +826,9 @@ else
 DEBUG_CFLAGS += -g
 endif
 
Quoted 3 lines

Makefile else · line 829

Quoted 1 line
Makefile +1 -0
+ifndef LLVM_IAS

Nit: this should probably match the existing LLVM_IAS check

Sure, will send a v3. Going to just send this for now, as it's blocking some downstream work I'm trying to get done in Android.

Quoted 11 lines

ifneq ($(LLVM_IAS),1)

Quoted 8 lines
Makefile +1 -1
 KBUILD_AFLAGS        += -Wa,-gdwarf-2
+endif
 
 ifdef CONFIG_DEBUG_INFO_DWARF4
 DEBUG_CFLAGS += -gdwarf-4
--

2.29.1.341.ge80a0c044ae-goog

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

PATCH v3 1/1 Kbuild: do not emit debug info for assembly with LLVM_IAS=1

Clang's integrated assembler produces the warning for assembly files:

warning: DWARF2 only supports one section per compilation unit

If -Wa,-gdwarf-* is unspecified, then debug info is not emitted for assembly sources (it is still emitted for C sources). This will be re-enabled for newer DWARF versions in a follow up patch.

Enables defconfig+CONFIG_DEBUG_INFO to build cleanly with LLVM=1 LLVM_IAS=1 for x86_64 and arm64.

---
 Makefile | 2 ++
 1 file changed, 2 insertions(+)
Makefile +2 -0
index f353886dbf44..7e899d356902 100644
@@ -826,7 +826,9 @@ else
 DEBUG_CFLAGS	+= -g
 endif
 
+ifneq ($(LLVM_IAS),1)
 KBUILD_AFLAGS	+= -Wa,-gdwarf-2
+endif
 
 ifdef CONFIG_DEBUG_INFO_DWARF4
 DEBUG_CFLAGS	+= -gdwarf-4
Signature · 1 line
2.29.2.222.g5d2a92d10f8-goog
#16 lore raw

Re: [PATCH v3] Kbuild: do not emit debug info for assembly with LLVM_IAS=1

Hi Masahiro, have you had time to review v3 of this patch?

Quoted 43 lines · Nick Desaulniers

Clang's integrated assembler produces the warning for assembly files:

warning: DWARF2 only supports one section per compilation unit

If -Wa,-gdwarf-* is unspecified, then debug info is not emitted for assembly sources (it is still emitted for C sources). This will be re-enabled for newer DWARF versions in a follow up patch.

Enables defconfig+CONFIG_DEBUG_INFO to build cleanly with LLVM=1 LLVM_IAS=1 for x86_64 and arm64.

---
 Makefile | 2 ++
 1 file changed, 2 insertions(+)
Makefile +2 -1
index f353886dbf44..7e899d356902 100644
@@ -826,7 +826,9 @@ else
 DEBUG_CFLAGS   += -g
 endif
 
+ifneq ($(LLVM_IAS),1)
 KBUILD_AFLAGS  += -Wa,-gdwarf-2
+endif
 
 ifdef CONFIG_DEBUG_INFO_DWARF4
 DEBUG_CFLAGS   += -gdwarf-4
--

2.29.2.222.g5d2a92d10f8-goog

Signature · 2 lines
Thanks,
~Nick Desaulniers

A message that is not in the archive (sent off-list or not yet received): CA+SOCLJTg6U+Ddop_5O-baVR42va3vGAvMQ62o9H6rd+10aKrw@mail.gmail.com

#18 lore raw

Re: [PATCH v3] Kbuild: do not emit debug info for assembly with LLVM_IAS=1

Hi Masahiro,
I would appreciate any feedback you have on this patch.

Quoted 65 lines · Jian Cai

I also verified that with this patch Chrome OS devices booted with either GNU assembler or LLVM's integrated assembler. With this patch, IAS no longer produces extra warnings compared to GNU as on Chrome OS and would remove the last blocker of enabling IAS on it.

Quoted 58 lines · Nick Desaulniers' via Clang Built Linux

Hi Masahiro, have you had time to review v3 of this patch?

Quoted 41 lines · Nick Desaulniers

Clang's integrated assembler produces the warning for assembly files:

warning: DWARF2 only supports one section per compilation unit

If -Wa,-gdwarf-* is unspecified, then debug info is not emitted for assembly sources (it is still emitted for C sources). This will be re-enabled for newer DWARF versions in a follow up patch.

Enables defconfig+CONFIG_DEBUG_INFO to build cleanly with LLVM=1 LLVM_IAS=1 for x86_64 and arm64.

---
 Makefile | 2 ++
 1 file changed, 2 insertions(+)
Makefile +2 -1
index f353886dbf44..7e899d356902 100644
@@ -826,7 +826,9 @@ else
 DEBUG_CFLAGS   += -g
 endif
 
+ifneq ($(LLVM_IAS),1)
 KBUILD_AFLAGS  += -Wa,-gdwarf-2
+endif
 
 ifdef CONFIG_DEBUG_INFO_DWARF4
 DEBUG_CFLAGS   += -gdwarf-4
--
Quoted 2 lines

2.29.2.222.g5d2a92d10f8-goog

--
Thanks,
~Nick Desaulniers

--
You received this message because you are subscribed to the Google Groups "Clang Built Linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/CAKwvOdnxAr7UdjUiuttj%3Dbz1_voK1qUvpOvSY35qOZ60%2BE8LBA%40mail.gmail.com.

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

Re: [PATCH v3] Kbuild: do not emit debug info for assembly with LLVM_IAS=1

Quoted 4 lines · Nick Desaulniers

Hi Masahiro,
I would appreciate any feedback you have on this patch.

Applied to linux-kbuild. Thanks.

Quoted 72 lines · Jian Cai
Quoted 65 lines

I also verified that with this patch Chrome OS devices booted with either GNU assembler or LLVM's integrated assembler. With this patch, IAS no longer produces extra warnings compared to GNU as on Chrome OS and would remove the last blocker of enabling IAS on it.

Quoted 58 lines · Nick Desaulniers' via Clang Built Linux

Hi Masahiro, have you had time to review v3 of this patch?

Quoted 41 lines · Nick Desaulniers

Clang's integrated assembler produces the warning for assembly files:

warning: DWARF2 only supports one section per compilation unit

If -Wa,-gdwarf-* is unspecified, then debug info is not emitted for assembly sources (it is still emitted for C sources). This will be re-enabled for newer DWARF versions in a follow up patch.

Enables defconfig+CONFIG_DEBUG_INFO to build cleanly with LLVM=1 LLVM_IAS=1 for x86_64 and arm64.

---
 Makefile | 2 ++
 1 file changed, 2 insertions(+)
Makefile +2 -1
index f353886dbf44..7e899d356902 100644
@@ -826,7 +826,9 @@ else
 DEBUG_CFLAGS   += -g
 endif
 
+ifneq ($(LLVM_IAS),1)
 KBUILD_AFLAGS  += -Wa,-gdwarf-2
+endif
 
 ifdef CONFIG_DEBUG_INFO_DWARF4
 DEBUG_CFLAGS   += -gdwarf-4
--
Quoted 2 lines

2.29.2.222.g5d2a92d10f8-goog

--
Thanks,
~Nick Desaulniers

--
You received this message because you are subscribed to the Google Groups "Clang Built Linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/CAKwvOdnxAr7UdjUiuttj%3Dbz1_voK1qUvpOvSY35qOZ60%2BE8LBA%40mail.gmail.com.

--
Thanks,
~Nick Desaulniers

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

PATCH v2 3/4 Kbuild: make DWARF version a choice

In reply to 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          | 14 ++++++++------
 lib/Kconfig.debug | 19 +++++++++++++++----
 2 files changed, 23 insertions(+), 10 deletions(-)
Makefile +8 -6
index 75b1a3dcbf30..e23786a4c1c7 100644
@@ -826,12 +826,14 @@ else
 DEBUG_CFLAGS	+= -g
 endif
 
-ifndef LLVM_IAS
-KBUILD_AFLAGS	+= -Wa,-gdwarf-2
-endif
-
-ifdef CONFIG_DEBUG_INFO_DWARF4
-DEBUG_CFLAGS	+= -gdwarf-4
+dwarf-version-$(CONFIG_DEBUG_INFO_DWARF2) := 2
+dwarf-version-$(CONFIG_DEBUG_INFO_DWARF4) := 4
+DEBUG_CFLAGS	+= -gdwarf-$(dwarf-version-y)
+ifneq ($(dwarf-version-y)$(LLVM_IAS),21)
+# Binutils 2.35+ required for -gdwarf-4+ support.
+dwarf-aflag	:= $(call as-option,-Wa$(comma)-gdwarf-$(dwarf-version-y))
+DEBUG_CFLAGS	+= $(dwarf-aflag)
+KBUILD_AFLAGS	+= $(dwarf-aflag)
 endif
 
 ifdef CONFIG_DEBUG_INFO_REDUCED
lib/Kconfig.debug +15 -4
index 83a860126897..03c494eefabd 100644
@@ -256,14 +256,25 @@ 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 v2 debuginfo"
+	help
+	  Generate DWARF v2 debug info.
+
 config DEBUG_INFO_DWARF4
 	bool "Generate dwarf4 debuginfo"
 	depends on $(cc-option,-gdwarf-4)
 	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.29.1.341.ge80a0c044ae-goog
#21 lore raw

Re: [PATCH v2 3/4] Kbuild: make DWARF version a choice

I love your patch! Yet something to improve:

Hi Nick,

I love your patch! Yet something to improve:

[auto build test ERROR on kbuild/for-next]
[also build test ERROR on asm-generic/master linus/master v5.10-rc2 next-20201104] [cannot apply to tip/x86/core]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Nick-Desaulniers/Kbuild-DWARF-v5-support/20201104-085610
base:   https://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild.git for-next
config: ia64-randconfig-r034-20201104 (attached as .config)
compiler: ia64-linux-gcc (GCC) 9.3.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/f8b8c21feb85f4422b79a96e0b56cf4e8ff53274
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Nick-Desaulniers/Kbuild-DWARF-v5-support/20201104-085610 git checkout f8b8c21feb85f4422b79a96e0b56cf4e8ff53274
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=ia64

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

{standard input}: Assembler messages:

>> {standard input}:34: Error: file number 1 already allocated

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#22 lore raw

Re: [PATCH v2 3/4] Kbuild: make DWARF version a choice

In reply to Nick Desaulniers
Quoted 27 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          | 14 ++++++++------
 lib/Kconfig.debug | 19 +++++++++++++++----
 2 files changed, 23 insertions(+), 10 deletions(-)
Makefile +0 -6
index 75b1a3dcbf30..e23786a4c1c7 100644
@@ -826,12 +826,14 @@ else
 DEBUG_CFLAGS	+= -g
 endif
 
-ifndef LLVM_IAS
-KBUILD_AFLAGS	+= -Wa,-gdwarf-2
-endif
-
-ifdef CONFIG_DEBUG_INFO_DWARF4
-DEBUG_CFLAGS	+= -gdwarf-4

Makefile else · line 838

Quoted 10 lines
Makefile +8 -0
+dwarf-version-$(CONFIG_DEBUG_INFO_DWARF2) := 2
+dwarf-version-$(CONFIG_DEBUG_INFO_DWARF4) := 4
+DEBUG_CFLAGS	+= -gdwarf-$(dwarf-version-y)
+ifneq ($(dwarf-version-y)$(LLVM_IAS),21)
+# Binutils 2.35+ required for -gdwarf-4+ support.
+dwarf-aflag	:= $(call as-option,-Wa$(comma)-gdwarf-$(dwarf-version-y))
+DEBUG_CFLAGS	+= $(dwarf-aflag)
+KBUILD_AFLAGS	+= $(dwarf-aflag)
 endif
 

For LLVM_IAS=1, adding dwarf-aflag to DEBUG_CFLAGS should not be necessary, no? This seems to add it for dwarf-4.

The as-option check will only work on binutils 2.35.1 onwards: earlier versions will silently accept any -gdwarf-N option. Do we care? I think it'll just get dwarf-2 for assembly files even though dwarf-4 might have been configured. The earlier versions only error if the double-hyphen form --gdwarf-N is used.

More generally, do we want to force this option via -Wa or should we leave it up to the compiler driver when we can? For both Clang/IAS and gcc/binutils, passing -gdwarf-N in KBUILD_AFLAGS will allow the compiler to pass on the appropriate option to the assembler (with gcc you only get --gdwarf-2 for the assembler except on trunk though). The only case that would absolutely require -Wa is Clang without IAS, might be worth adding the ability to pass on the flag to the external assembler?

Btw, is -gsplit-dwarf at all useful for assembler files?

#23 lore raw

Re: [PATCH v2 3/4] Kbuild: make DWARF version a choice

Quoted 1 line · Arvind Sankar

Btw, is -gsplit-dwarf at all useful for assembler files?

If you invoke the assembler via the compiler, with that flag it still creates separate .o and .dwo files (via objcopy invocations as usual). Whether that is useful depends on if you have any debug info that can be split :-)

Segher

#24 lore raw

Re: [PATCH v2 3/4] Kbuild: make DWARF version a choice

Quoted 10 lines · Segher Boessenkool
Quoted 1 line · Arvind Sankar

Btw, is -gsplit-dwarf at all useful for assembler files?

If you invoke the assembler via the compiler, with that flag it still creates separate .o and .dwo files (via objcopy invocations as usual). Whether that is useful depends on if you have any debug info that can be split :-)

Segher

Right, the latter was what I was really asking :) We don't currently pass -gsplit-dwarf for assembler and I was wondering if that mattered.

Thanks.

#25 lore raw

Re: [PATCH v2 3/4] Kbuild: make DWARF version a choice

Quoted 11 lines · Arvind Sankar
Quoted 7 lines · Segher Boessenkool
Quoted 1 line · Arvind Sankar

Btw, is -gsplit-dwarf at all useful for assembler files?

If you invoke the assembler via the compiler, with that flag it still creates separate .o and .dwo files (via objcopy invocations as usual). Whether that is useful depends on if you have any debug info that can be split :-)

Right, the latter was what I was really asking :) We don't currently pass -gsplit-dwarf for assembler and I was wondering if that mattered.

If there is any debug info in the .s files, it will all end up in the .o file, not a .dwo file. That may matter aesthetically, and it can cost a few bytes of disk space, but it doesn't matter functionally (GDB will search in both places).

Segher

#26 lore raw

Re: [PATCH v2 3/4] Kbuild: make DWARF version a choice

In reply to Nick Desaulniers
Quoted 25 lines · Nick Desaulniers' via Clang Built Linux

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          | 14 ++++++++------
 lib/Kconfig.debug | 19 +++++++++++++++----
 2 files changed, 23 insertions(+), 10 deletions(-)
Makefile +0 -3
index 75b1a3dcbf30..e23786a4c1c7 100644
@@ -826,12 +826,14 @@ else
 DEBUG_CFLAGS   += -g
 endif
 
-ifndef LLVM_IAS
-KBUILD_AFLAGS  += -Wa,-gdwarf-2
-endif

Makefile else · line 835

Quoted 10 lines
Makefile +7 -3
-
-ifdef CONFIG_DEBUG_INFO_DWARF4
-DEBUG_CFLAGS   += -gdwarf-4
+dwarf-version-$(CONFIG_DEBUG_INFO_DWARF2) := 2
+dwarf-version-$(CONFIG_DEBUG_INFO_DWARF4) := 4
+DEBUG_CFLAGS   += -gdwarf-$(dwarf-version-y)
+ifneq ($(dwarf-version-y)$(LLVM_IAS),21)
+# Binutils 2.35+ required for -gdwarf-4+ support.
+dwarf-aflag    := $(call as-option,-Wa$(comma)-gdwarf-$(dwarf-version-y))
+DEBUG_CFLAGS   += $(dwarf-aflag)

This changes the behavior.

For the Dwarf-2 case,

Previously, -gdwarf-2 was passed to $(CC),
so the debug info was generated by gcc.

Now, -Wa,-gdwarf-2 is passed to $(CC).
-gdwarf-2 is handled by GNU as.
So, the source info points to /tmp/<hash>.s
instead of the original .c file.

Handling the Dwarf capability is very complicated.

Are you still working for v3?

Quoted 45 lines
Makefile +1 -0
+KBUILD_AFLAGS  += $(dwarf-aflag)
 endif
 
 ifdef CONFIG_DEBUG_INFO_REDUCED
lib/Kconfig.debug +15 -5
index 83a860126897..03c494eefabd 100644
@@ -256,14 +256,25 @@ 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 v2 debuginfo"
+       help
+         Generate DWARF v2 debug info.
+
 config DEBUG_INFO_DWARF4
        bool "Generate dwarf4 debuginfo"
        depends on $(cc-option,-gdwarf-4)
        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"
--

2.29.1.341.ge80a0c044ae-goog

--
You received this message because you are subscribed to the Google Groups "Clang Built Linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/20201104005343.4192504-4-ndesaulniers%40google.com.

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

Re: [PATCH v2 3/4] Kbuild: make DWARF version a choice

Quoted 95 lines · Masahiro Yamada
Quoted 25 lines · Nick Desaulniers' via Clang Built Linux

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          | 14 ++++++++------
 lib/Kconfig.debug | 19 +++++++++++++++----
 2 files changed, 23 insertions(+), 10 deletions(-)
Makefile +0 -3
index 75b1a3dcbf30..e23786a4c1c7 100644
@@ -826,12 +826,14 @@ else
 DEBUG_CFLAGS   += -g
 endif
 
-ifndef LLVM_IAS
-KBUILD_AFLAGS  += -Wa,-gdwarf-2
-endif

Makefile else · line 835

Quoted 10 lines
Makefile +7 -3
-
-ifdef CONFIG_DEBUG_INFO_DWARF4
-DEBUG_CFLAGS   += -gdwarf-4
+dwarf-version-$(CONFIG_DEBUG_INFO_DWARF2) := 2
+dwarf-version-$(CONFIG_DEBUG_INFO_DWARF4) := 4
+DEBUG_CFLAGS   += -gdwarf-$(dwarf-version-y)
+ifneq ($(dwarf-version-y)$(LLVM_IAS),21)
+# Binutils 2.35+ required for -gdwarf-4+ support.
+dwarf-aflag    := $(call as-option,-Wa$(comma)-gdwarf-$(dwarf-version-y))
+DEBUG_CFLAGS   += $(dwarf-aflag)

This changes the behavior.

For the Dwarf-2 case,

Previously, -gdwarf-2 was passed to $(CC),
so the debug info was generated by gcc.

Now, -Wa,-gdwarf-2 is passed to $(CC).
-gdwarf-2 is handled by GNU as.
So, the source info points to /tmp/<hash>.s
instead of the original .c file.

Handling the Dwarf capability is very complicated.

Are you still working for v3?

Quoted 36 lines
Makefile +1 -0
+KBUILD_AFLAGS  += $(dwarf-aflag)
 endif
 
 ifdef CONFIG_DEBUG_INFO_REDUCED
lib/Kconfig.debug +15 -4
index 83a860126897..03c494eefabd 100644
@@ -256,14 +256,25 @@ 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 v2 debuginfo"
+       help
+         Generate DWARF v2 debug info.
+
 config DEBUG_INFO_DWARF4
        bool "Generate dwarf4 debuginfo"
        depends on $(cc-option,-gdwarf-4)
        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"
 
Quoted 4 lines
Quoted 4 lines
lib/Kconfig.debug +0 -1
 config DEBUG_INFO_BTF
        bool "Generate BTF typeinfo"
--

2.29.1.341.ge80a0c044ae-goog

We can bump -Wa,-gdwarf-2 to -Wa,-gdwarf-3 since GNU actually emits DWARF v3 DW_AT_ranges (see
https://sourceware.org/bugzilla/show_bug.cgi?id=26850 ) This can avoid the warning: DWARF2 only supports one section per compilation unit warning for Clang.

Deleting -Wa,-gdwarf-2 also sounds good to me if people can verify their debugging experience is not regressed (I believe it is useless).

Signature · 1 line
宋方睿
#28 lore raw

Re: [PATCH v2 3/4] Kbuild: make DWARF version a choice

Quoted 97 lines · Fāng-ruì Sòng' via Clang Built Linux
Quoted 95 lines · Masahiro Yamada
Quoted 25 lines · Nick Desaulniers' via Clang Built Linux

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          | 14 ++++++++------
 lib/Kconfig.debug | 19 +++++++++++++++----
 2 files changed, 23 insertions(+), 10 deletions(-)
Makefile +0 -3
index 75b1a3dcbf30..e23786a4c1c7 100644
@@ -826,12 +826,14 @@ else
 DEBUG_CFLAGS   += -g
 endif
 
-ifndef LLVM_IAS
-KBUILD_AFLAGS  += -Wa,-gdwarf-2
-endif

Makefile else · line 835

Quoted 10 lines
Makefile +7 -3
-
-ifdef CONFIG_DEBUG_INFO_DWARF4
-DEBUG_CFLAGS   += -gdwarf-4
+dwarf-version-$(CONFIG_DEBUG_INFO_DWARF2) := 2
+dwarf-version-$(CONFIG_DEBUG_INFO_DWARF4) := 4
+DEBUG_CFLAGS   += -gdwarf-$(dwarf-version-y)
+ifneq ($(dwarf-version-y)$(LLVM_IAS),21)
+# Binutils 2.35+ required for -gdwarf-4+ support.
+dwarf-aflag    := $(call as-option,-Wa$(comma)-gdwarf-$(dwarf-version-y))
+DEBUG_CFLAGS   += $(dwarf-aflag)

This changes the behavior.

For the Dwarf-2 case,

Previously, -gdwarf-2 was passed to $(CC),
so the debug info was generated by gcc.

Now, -Wa,-gdwarf-2 is passed to $(CC).
-gdwarf-2 is handled by GNU as.
So, the source info points to /tmp/<hash>.s
instead of the original .c file.

Handling the Dwarf capability is very complicated.

Are you still working for v3?

Quoted 36 lines
Makefile +1 -0
+KBUILD_AFLAGS  += $(dwarf-aflag)
 endif
 
 ifdef CONFIG_DEBUG_INFO_REDUCED
lib/Kconfig.debug +15 -4
index 83a860126897..03c494eefabd 100644
@@ -256,14 +256,25 @@ 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 v2 debuginfo"
+       help
+         Generate DWARF v2 debug info.
+
 config DEBUG_INFO_DWARF4
        bool "Generate dwarf4 debuginfo"
        depends on $(cc-option,-gdwarf-4)
        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"
 
Quoted 11 lines
Quoted 4 lines
Quoted 4 lines
lib/Kconfig.debug +0 -1
 config DEBUG_INFO_BTF
        bool "Generate BTF typeinfo"
--

2.29.1.341.ge80a0c044ae-goog

We can bump -Wa,-gdwarf-2 to -Wa,-gdwarf-3 since GNU actually emits DWARF v3 DW_AT_ranges (see
https://sourceware.org/bugzilla/show_bug.cgi?id=26850 ) This can avoid the warning: DWARF2 only supports one section per compilation unit warning for Clang.

I am not a DWARF spec expert.

Please teach me.

In my understanding, "DWARF2 only supports one section ..." is warned only when building .S files with LLVM_IAS=1

If this is due to the limitation of DWARF v2, why is it OK to build .c files with LLVM_IAS?

Quoted 12 lines

Deleting -Wa,-gdwarf-2 also sounds good to me if people can verify their debugging experience is not regressed (I believe it is useless).

--
宋方睿

--
You received this message because you are subscribed to the Google Groups "Clang Built Linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/CAFP8O3Ki9HoqcV450fn29fBOWAbmuGAdB6USLz8pGsW4Vzf7sg%40mail.gmail.com.

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

Re: [PATCH v2 3/4] Kbuild: make DWARF version a choice

Quoted 5 lines · Masahiro Yamada
Quoted 5 lines

We can bump -Wa,-gdwarf-2 to -Wa,-gdwarf-3 since GNU actually emits DWARF v3 DW_AT_ranges (see
https://sourceware.org/bugzilla/show_bug.cgi?id=26850 ) This can avoid the warning: DWARF2 only supports one section per compilation unit warning for Clang.

That warning should be "there can be only one section with executable code per translation unit", or similar.

Quoted 1 line

I am not a DWARF spec expert.

Neither am I.

Quoted 4 lines

Please teach me.

In my understanding, "DWARF2 only supports one section ..." is warned only when building .S files with LLVM_IAS=1

.S files are simply run through the C preprocessor first, and then given to the assembler. The only difference there should be wrt debug info is you could have some macros that expand to assembler debug statements.

Quoted 2 lines

If this is due to the limitation of DWARF v2, why is it OK to build .c files with LLVM_IAS?

The compiler can of course make sure not to use certain constructs in its generated assembler code, while the assembler will have to swallow whatever the user wrote.

Segher

#30 lore raw

Re: [PATCH v2 3/4] Kbuild: make DWARF version a choice

Quoted 23 lines · Segher Boessenkool
Quoted 5 lines · Masahiro Yamada
Quoted 5 lines

We can bump -Wa,-gdwarf-2 to -Wa,-gdwarf-3 since GNU actually emits DWARF v3 DW_AT_ranges (see
https://sourceware.org/bugzilla/show_bug.cgi?id=26850 ) This can avoid the warning: DWARF2 only supports one section per compilation unit warning for Clang.

That warning should be "there can be only one section with executable code per translation unit", or similar.

Quoted 1 line

I am not a DWARF spec expert.

Neither am I.

Quoted 4 lines

Please teach me.

In my understanding, "DWARF2 only supports one section ..." is warned only when building .S files with LLVM_IAS=1

.S files are simply run through the C preprocessor first, and then given to the assembler. The only difference there should be wrt debug info is you could have some macros that expand to assembler debug statements.

Quoted 7 lines
Quoted 2 lines

If this is due to the limitation of DWARF v2, why is it OK to build .c files with LLVM_IAS?

The compiler can of course make sure not to use certain constructs in its generated assembler code, while the assembler will have to swallow whatever the user wrote.

These are all correct. You can use llvm-dwarfdump a.o to dump a .o file. It has one DW_TAG_compile_unit. If the translation unit has a single contiguous address range, the assembler can emit a pair of DW_AT_low_pc/DW_AT_high_pc (available in DWARF v2). In the case of multiple executable sections, it is not guaranteed that in the final linked image the sections will be contiguous, so the assembler has to assume there may be non-contiguous address ranges and use DW_AT_ranges.

Unfortunately DW_AT_ranges was introduced in DWARF v3 and technically not available in DWARF v2. But GNU as ignores this and emits DW_AT_ranges anyway (this is probably fine - like using a GNU extension).

If -Wa,-gdwarf-2 -> -Wa,-gdwarf-3 can eliminate the LLVM integrated assembler's warning, we should do it. If people think -Wa,-gdwarf-2 is not useful and want to delete it, I'll be happier. Whether it is necessary to use -Wa,-gdwarf-2/-Wa,-gdwarf-5? Personally I would think this is unnecessary, but I won't mind if people don't mind the additional complexity in Makefile. (I implemented the -gdwarf-5 address range stuff for the integrated assembler).

#31 lore raw

Re: [PATCH v2 3/4] Kbuild: make DWARF version a choice

In reply to Masahiro Yamada
Quoted 53 lines · Masahiro Yamada
Quoted 25 lines · Nick Desaulniers' via Clang Built Linux

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          | 14 ++++++++------
 lib/Kconfig.debug | 19 +++++++++++++++----
 2 files changed, 23 insertions(+), 10 deletions(-)
Makefile +0 -3
index 75b1a3dcbf30..e23786a4c1c7 100644
@@ -826,12 +826,14 @@ else
 DEBUG_CFLAGS   += -g
 endif
 
-ifndef LLVM_IAS
-KBUILD_AFLAGS  += -Wa,-gdwarf-2
-endif

Makefile else · line 835

Quoted 10 lines
Makefile +7 -3
-
-ifdef CONFIG_DEBUG_INFO_DWARF4
-DEBUG_CFLAGS   += -gdwarf-4
+dwarf-version-$(CONFIG_DEBUG_INFO_DWARF2) := 2
+dwarf-version-$(CONFIG_DEBUG_INFO_DWARF4) := 4
+DEBUG_CFLAGS   += -gdwarf-$(dwarf-version-y)
+ifneq ($(dwarf-version-y)$(LLVM_IAS),21)
+# Binutils 2.35+ required for -gdwarf-4+ support.
+dwarf-aflag    := $(call as-option,-Wa$(comma)-gdwarf-$(dwarf-version-y))
+DEBUG_CFLAGS   += $(dwarf-aflag)

This changes the behavior.

For the Dwarf-2 case,

Previously, -gdwarf-2 was passed to $(CC),
so the debug info was generated by gcc.

Now, -Wa,-gdwarf-2 is passed to $(CC).
-gdwarf-2 is handled by GNU as.
So, the source info points to /tmp/<hash>.s
instead of the original .c file.

Quoted 3 lines

Handling the Dwarf capability is very complicated.

Are you still working for v3?

Yes, I plan to revisit the series based on all of the feedback thus far. Lately I'm focused on enabling LLVM_IAS=1 for Android; but I would like to see this land so that the Linux kernel may provide coverage and feedback to the toolchain developers for DWARF v5 (as well as reduced binary image sizes). Maybe later this week I'll have time to revisit.

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

Re: [PATCH v2 3/4] Kbuild: make DWARF version a choice

Quoted 69 lines · Nick Desaulniers' via Clang Built Linux
Quoted 53 lines · Masahiro Yamada
Quoted 25 lines · Nick Desaulniers' via Clang Built Linux

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          | 14 ++++++++------
 lib/Kconfig.debug | 19 +++++++++++++++----
 2 files changed, 23 insertions(+), 10 deletions(-)
Makefile +0 -3
index 75b1a3dcbf30..e23786a4c1c7 100644
@@ -826,12 +826,14 @@ else
 DEBUG_CFLAGS   += -g
 endif
 
-ifndef LLVM_IAS
-KBUILD_AFLAGS  += -Wa,-gdwarf-2
-endif

Makefile else · line 835

Quoted 10 lines
Makefile +7 -3
-
-ifdef CONFIG_DEBUG_INFO_DWARF4
-DEBUG_CFLAGS   += -gdwarf-4
+dwarf-version-$(CONFIG_DEBUG_INFO_DWARF2) := 2
+dwarf-version-$(CONFIG_DEBUG_INFO_DWARF4) := 4
+DEBUG_CFLAGS   += -gdwarf-$(dwarf-version-y)
+ifneq ($(dwarf-version-y)$(LLVM_IAS),21)
+# Binutils 2.35+ required for -gdwarf-4+ support.
+dwarf-aflag    := $(call as-option,-Wa$(comma)-gdwarf-$(dwarf-version-y))
+DEBUG_CFLAGS   += $(dwarf-aflag)

This changes the behavior.

For the Dwarf-2 case,

Previously, -gdwarf-2 was passed to $(CC),
so the debug info was generated by gcc.

Now, -Wa,-gdwarf-2 is passed to $(CC).
-gdwarf-2 is handled by GNU as.
So, the source info points to /tmp/<hash>.s
instead of the original .c file.

Quoted 3 lines

Handling the Dwarf capability is very complicated.

Are you still working for v3?

Yes, I plan to revisit the series based on all of the feedback thus far. Lately I'm focused on enabling LLVM_IAS=1 for Android; but I would like to see this land so that the Linux kernel may provide coverage and feedback to the toolchain developers for DWARF v5 (as well as reduced binary image sizes). Maybe later this week I'll have time to revisit.
--
Thanks,
~Nick Desaulniers

Quoted 4 lines

--
You received this message because you are subscribed to the Google Groups "Clang Built Linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/CAKwvOdmPeOEA4dfODCKLE4A_M-SF5RBVFEf-NuiTkUTXAbh-5w%40mail.gmail.com.

In my understanding, the complexity comes from the fact we are mixing up the $(CC) capability and $(AS) capability.

They are orthogonal if I understand correctly.

When building *.c files, the .debug* sections are generated by gcc (or clang), and embedded into the intermediate *.s files. The assembler (GAS or clang's IAS) simply transforms it
into byte stream in *.o. So we do not care about the assembler capability.

When building *.S files, the .debug* sections are generated by the assembler. Here, the assembler capability is important. Unless we use binutils 2.35+ or clang IAS,
DWARF v2 is the only possible choice.

So, we need two separate choices to handle this properly, I think.

The following is the rough sketch.

# The value is 2, 3, 4, or 5 depending on the assembler in use. # Unfortunately, we cannot check this by $(cc-option, -Wa,-gdwarf-4)

# because GAS <= 2.34 accepts any -gdwarf-<N>.
# readelf --debug-dump=info and grep or something?
config AS_SUPPORTS_DWARF_VERSION
        int $(shell scripts/as_dwarf_support.sh)

choice
"DWARF version for C code debugging"

config CC_DEBUG_INFO_DWARF2

            bool "..."

config CC_DEBUG_INFO_DWARF4

            bool "..."

config CC_DEBUG_INFO_DWARF5
bool "..."
depends on GCC_VERSION >= 700000 || CC_IS_CLANG depends on AS_SUPPORTS_DWARF_VERSION >= 5
help
gcc7+ or clang supports this.
Unfortunately, we also need to check assembler capability because GAS <= 2.34 do not understand ".file 0"

endchoice

choice
"DWARF version for assembly code debugging"

config AS_DEBUG_INFO_DWARF2

            bool "..."

config AS_DEBUG_INFO_DWARF4
bool "..."
depends on AS_SUPPORTS_DWARF_VERSION >= 4

config AS_DEBUG_INFO_DWARF5
bool "..."
depends on AS_SUPPORTS_DWARF_VERSION >= 5

endchoice

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

PATCH v2 4/4 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. GNU as only recently gained support for specifying -gdwarf-5.

The DWARF version of a binary can be validated with:

$ llvm-dwarfdump vmlinux | head -n 5 | 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
---
 Makefile                          | 1 +
 include/asm-generic/vmlinux.lds.h | 6 +++++-
 lib/Kconfig.debug                 | 8 ++++++++
 scripts/test_dwarf5_support.sh    | 9 +++++++++
 4 files changed, 23 insertions(+), 1 deletion(-)
 create mode 100755 scripts/test_dwarf5_support.sh
Makefile +1 -0
index e23786a4c1c7..9056bac0ff85 100644
@@ -828,6 +828,7 @@ 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)
 ifneq ($(dwarf-version-y)$(LLVM_IAS),21)
 # Binutils 2.35+ required for -gdwarf-4+ support.
include/asm-generic/vmlinux.lds.h +5 -1
index b2b3d81b1535..76ce62c77029 100644
@@ -829,7 +829,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 +8 -0
index 03c494eefabd..c5b54ba51060 100644
@@ -274,6 +274,14 @@ 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 DWARF5 debuginfo"
+	depends on $(cc-option,-gdwarf-5)
+	depends on $(success,$(srctree)/scripts/test_dwarf5_support.sh $(CC) $(CLANG_FLAGS))
+	help
+	  Genereate dwarf5 debug info. Requires binutils 2.35+, gcc 5.1+, and
+	  gdb 8.0+.
+
 endchoice # "DWARF version"
 
 config DEBUG_INFO_BTF
scripts/test_dwarf5_support.sh new file +9 -0
new file mode 100755
index 000000000000..156ad5ec4274
@@ -0,0 +1,9 @@
+#!/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
+set -e
+echo '.file 0 "filename"' | $* -Wa,-gdwarf-5 -c -x assembler -o /dev/null -
Signature · 1 line
2.29.1.341.ge80a0c044ae-goog
#34 lore raw

Re: [PATCH v2 4/4] Kbuild: implement support for DWARF v5

Quoted 6 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. GNU as only recently gained support for specifying -gdwarf-5.

With gcc, using -gdwarf-5 even without -Wa,--gdwarf-5 results in considerably smaller debug info. gcc does not seem to generate the .file 0 directive that causes older GNU as to barf.

Should the assembler support check be restricted to CC_IS_CLANG?

Quoted 9 lines

/* Stabs debugging sections. */
#define STABS_DEBUG \

lib/Kconfig.debug +0 -0
index 03c494eefabd..c5b54ba51060 100644
@@ -274,6 +274,14 @@ config DEBUG_INFO_DWARF4
 	  It makes the debug information larger, but it significantly
 	  improves the success of resolving variables in gdb on optimized code.

lib/Kconfig.debug config DEBUG_INFO_DWARF4 · line 285

Quoted 10 lines
lib/Kconfig.debug +8 -0
 
+config DEBUG_INFO_DWARF5
+	bool "Generate DWARF5 debuginfo"
+	depends on $(cc-option,-gdwarf-5)
+	depends on $(success,$(srctree)/scripts/test_dwarf5_support.sh $(CC) $(CLANG_FLAGS))
+	help
+	  Genereate dwarf5 debug info. Requires binutils 2.35+, gcc 5.1+, and
+	  gdb 8.0+.
+
 endchoice # "DWARF version"

Perhaps this can be expanded with some description of the advantages of dwarf5 over dwarf4?

Quoted 8 lines
lib/Kconfig.debug +0 -0
 config DEBUG_INFO_BTF
scripts/test_dwarf5_support.sh new file +0 -0
new file mode 100755
index 000000000000..156ad5ec4274

scripts/test_dwarf5_support.sh line 9

Quoted 9 lines
scripts/test_dwarf5_support.sh new file +9 -0
@@ -0,0 +1,9 @@
+#!/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
+set -e
+echo '.file 0 "filename"' | $* -Wa,-gdwarf-5 -c -x assembler -o /dev/null -

This also actually needs --gdwarf-5 to really check the support for the option, but older versions should error on the .file 0 in any case.

#35 lore raw

Re: [PATCH v2 4/4] Kbuild: implement support for DWARF v5

Quoted 9 lines · Arvind Sankar
Quoted 6 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. GNU as only recently gained support for specifying -gdwarf-5.

Quoted 5 lines

With gcc, using -gdwarf-5 even without -Wa,--gdwarf-5 results in considerably smaller debug info. gcc does not seem to generate the .file 0 directive that causes older GNU as to barf.

Should the assembler support check be restricted to CC_IS_CLANG?

No, because if LLVM_IAS=1 then the assembler support need not be checked.

Quoted 11 lines
Quoted 11 lines

/* Stabs debugging sections. */
#define STABS_DEBUG \

lib/Kconfig.debug +0 -0
index 03c494eefabd..c5b54ba51060 100644
@@ -274,6 +274,14 @@ config DEBUG_INFO_DWARF4
        It makes the debug information larger, but it significantly
        improves the success of resolving variables in gdb on optimized code.
 
Quoted 12 lines

lib/Kconfig.debug config DEBUG_INFO_DWARF4 · line 285

Quoted 9 lines
lib/Kconfig.debug +8 -0
+config DEBUG_INFO_DWARF5
+     bool "Generate DWARF5 debuginfo"
+     depends on $(cc-option,-gdwarf-5)
+     depends on $(success,$(srctree)/scripts/test_dwarf5_support.sh $(CC) $(CLANG_FLAGS))
+     help
+       Genereate dwarf5 debug info. Requires binutils 2.35+, gcc 5.1+, and
+       gdb 8.0+.
+
 endchoice # "DWARF version"

Perhaps this can be expanded with some description of the advantages of dwarf5 over dwarf4?

Will do.

Quoted 13 lines
Quoted 13 lines
lib/Kconfig.debug +0 -0
 config DEBUG_INFO_BTF
scripts/test_dwarf5_support.sh new file +4 -0
new file mode 100755
index 000000000000..156ad5ec4274
@@ -0,0 +1,9 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+
+# Test that assembler accepts -gdwarf-5 and .file 0 directives, which were bugs
Quoted 8 lines

scripts/test_dwarf5_support.sh line 9

Quoted 5 lines
scripts/test_dwarf5_support.sh new file +5 -0
+# in binutils < 2.35.
+# https://sourceware.org/bugzilla/show_bug.cgi?id=25612
+# https://sourceware.org/bugzilla/show_bug.cgi?id=25614
+set -e
+echo '.file 0 "filename"' | $* -Wa,-gdwarf-5 -c -x assembler -o /dev/null -

This also actually needs --gdwarf-5 to really check the support for the option, but older versions should error on the .file 0 in any case.

Based on Jakub's feedback on the earlier thread
https://lore.kernel.org/lkml/20201104121934.GT3788@tucnak/
it sounds like the dwarf version also needs to be dumped since GCC 5 < x < 7 accepts --gdwarf-5, but did not produce DWARF Version 5 debug info.

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

Re: [PATCH v2 4/4] Kbuild: implement support for DWARF v5

Quoted 11 lines · Nick Desaulniers
Quoted 9 lines · Arvind Sankar
Quoted 6 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. GNU as only recently gained support for specifying -gdwarf-5.

Quoted 7 lines
Quoted 5 lines

With gcc, using -gdwarf-5 even without -Wa,--gdwarf-5 results in considerably smaller debug info. gcc does not seem to generate the .file 0 directive that causes older GNU as to barf.

Should the assembler support check be restricted to CC_IS_CLANG?

No, because if LLVM_IAS=1 then the assembler support need not be checked.

Also, if your version of GCC supports DWARF Version 5, but your version of GAS does not, then I'm more inclined to not allow CONFIG_DEBUG_INFO_DWARF5 to be selectable, rather than mix and match or partially support this for one but not the other. Either all tools used support DWARF 5, or you don't get to use DWARF 5.

Quoted 20 lines
Quoted 11 lines
Quoted 11 lines

config DEBUG_INFO_BTF

scripts/test_dwarf5_support.sh new file +4 -0
new file mode 100755
index 000000000000..156ad5ec4274
@@ -0,0 +1,9 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+
+# Test that assembler accepts -gdwarf-5 and .file 0 directives, which were bugs
Quoted 8 lines

scripts/test_dwarf5_support.sh line 9

Quoted 5 lines
scripts/test_dwarf5_support.sh new file +5 -0
+# in binutils < 2.35.
+# https://sourceware.org/bugzilla/show_bug.cgi?id=25612
+# https://sourceware.org/bugzilla/show_bug.cgi?id=25614
+set -e
+echo '.file 0 "filename"' | $* -Wa,-gdwarf-5 -c -x assembler -o /dev/null -

This also actually needs --gdwarf-5 to really check the support for the option, but older versions should error on the .file 0 in any case.

Quoted 5 lines

Based on Jakub's feedback on the earlier thread
https://lore.kernel.org/lkml/20201104121934.GT3788@tucnak/
it sounds like the dwarf version also needs to be dumped since GCC 5 < x < 7 accepts --gdwarf-5, but did not produce DWARF Version 5 debug info.

Sigh...llvm-readelf doesn't accept --debug-dump=info for checking the DWARF version; llvm-dwarfdump works with no args...at this point I'm tempted to just version check GCC.

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

Re: [PATCH v2 4/4] Kbuild: implement support for DWARF v5

Quoted 18 lines · Nick Desaulniers
Quoted 17 lines · Nick Desaulniers
Quoted 14 lines · Arvind Sankar
Quoted 6 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. GNU as only recently gained support for specifying -gdwarf-5.

With gcc, using -gdwarf-5 even without -Wa,--gdwarf-5 results in considerably smaller debug info. gcc does not seem to generate the .file 0 directive that causes older GNU as to barf.

Should the assembler support check be restricted to CC_IS_CLANG?

Quoted 8 lines
Quoted 1 line

No, because if LLVM_IAS=1 then the assembler support need not be checked.

Also, if your version of GCC supports DWARF Version 5, but your version of GAS does not, then I'm more inclined to not allow CONFIG_DEBUG_INFO_DWARF5 to be selectable, rather than mix and match or partially support this for one but not the other. Either all tools used support DWARF 5, or you don't get to use DWARF 5.

Why? Does this actually cause any problems?

It seems like the options for gcc can actually be very straightforward:
you just need a cc-option check, and then add -gdwarf-N to both CFLAGS and AFLAGS and you're done. Adding the -Wa flag is superfluous and carries the risk of interfering with what the compiler driver does. Just let the gcc driver handle the details.

Clang/IAS is almost as straightforward, with the only additional edge case being that for assembler files, DWARF 2 doesn't work, so the CFLAGS is the same -gdwarf-N, but AFLAGS gets -gdwarf-N only if N > 2.

The messy case is only Clang/IAS=0, which needs to check the support from the external assembler, and needs CFLAGS of -gdwarf-N and AFLAGS of -Wa,--gdwarf-N, because Clang doesn't pass that option on to an external assembler. This is why I was asking if the assembler support check can be restricted to CC_IS_CLANG: nothing but Clang/IAS=0 actually requires that check.

#38 lore raw

Re: [PATCH v2 4/4] Kbuild: implement support for DWARF v5

Quoted 41 lines · Arvind Sankar
Quoted 18 lines · Nick Desaulniers
Quoted 17 lines · Nick Desaulniers
Quoted 14 lines · Arvind Sankar
Quoted 6 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. GNU as only recently gained support for specifying -gdwarf-5.

With gcc, using -gdwarf-5 even without -Wa,--gdwarf-5 results in considerably smaller debug info. gcc does not seem to generate the .file 0 directive that causes older GNU as to barf.

Should the assembler support check be restricted to CC_IS_CLANG?

Quoted 8 lines
Quoted 1 line

No, because if LLVM_IAS=1 then the assembler support need not be checked.

Also, if your version of GCC supports DWARF Version 5, but your version of GAS does not, then I'm more inclined to not allow CONFIG_DEBUG_INFO_DWARF5 to be selectable, rather than mix and match or partially support this for one but not the other. Either all tools used support DWARF 5, or you don't get to use DWARF 5.

Why? Does this actually cause any problems?

It seems like the options for gcc can actually be very straightforward:
you just need a cc-option check, and then add -gdwarf-N to both CFLAGS and AFLAGS and you're done. Adding the -Wa flag is superfluous and carries the risk of interfering with what the compiler driver does. Just let the gcc driver handle the details.

Clang/IAS is almost as straightforward, with the only additional edge case being that for assembler files, DWARF 2 doesn't work, so the CFLAGS is the same -gdwarf-N, but AFLAGS gets -gdwarf-N only if N > 2.

Quoted 6 lines

The messy case is only Clang/IAS=0, which needs to check the support from the external assembler, and needs CFLAGS of -gdwarf-N and AFLAGS of -Wa,--gdwarf-N, because Clang doesn't pass that option on to an external assembler. This is why I was asking if the assembler support check can be restricted to CC_IS_CLANG: nothing but Clang/IAS=0 actually requires that check.

Oh, I see. Yeah, that might be a nicer approach. What should we do in the case of gcc < 7 though, where -gdwarf-5 won't produce DWARF v5? Maybe that's ok, but the intent behind the Kconfig check was to prevent the option from being selectable if the tools do not support it. Maybe it's more flexible to pass the arguments along, and hope for the best?

As a gcc-5 user, I might be surprised if I chose CONFIG_DEBUG_INFO_DWARF5 if what I got was not actually DWARF v5; it does violate the principle of least surprise. Maybe that doesn't matter though?

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

Re: [PATCH v2 4/4] Kbuild: implement support for DWARF v5

Quoted 28 lines · Nick Desaulniers
Quoted 13 lines · Arvind Sankar

Why? Does this actually cause any problems?

It seems like the options for gcc can actually be very straightforward:
you just need a cc-option check, and then add -gdwarf-N to both CFLAGS and AFLAGS and you're done. Adding the -Wa flag is superfluous and carries the risk of interfering with what the compiler driver does. Just let the gcc driver handle the details.

Clang/IAS is almost as straightforward, with the only additional edge case being that for assembler files, DWARF 2 doesn't work, so the CFLAGS is the same -gdwarf-N, but AFLAGS gets -gdwarf-N only if N > 2.

Quoted 6 lines

The messy case is only Clang/IAS=0, which needs to check the support from the external assembler, and needs CFLAGS of -gdwarf-N and AFLAGS of -Wa,--gdwarf-N, because Clang doesn't pass that option on to an external assembler. This is why I was asking if the assembler support check can be restricted to CC_IS_CLANG: nothing but Clang/IAS=0 actually requires that check.

Oh, I see. Yeah, that might be a nicer approach. What should we do in the case of gcc < 7 though, where -gdwarf-5 won't produce DWARF v5? Maybe that's ok, but the intent behind the Kconfig check was to prevent the option from being selectable if the tools do not support it. Maybe it's more flexible to pass the arguments along, and hope for the best?

Quoted 4 lines

As a gcc-5 user, I might be surprised if I chose CONFIG_DEBUG_INFO_DWARF5 if what I got was not actually DWARF v5; it does violate the principle of least surprise. Maybe that doesn't matter though?

Even the current gcc documentation still says "DWARF Version 5 is only experimental". If the user wants to try it out, I think it's fine to let them get whatever subset their tool chain produces, as long as it's not completely broken. Your latest help text does say that gcc 7+ is required, maybe add another sentence saying that gcc 5+ only has partial support for some draft DWARF 5 features?

Thanks.

#40 lore raw

Re: [PATCH v2 4/4] Kbuild: implement support for DWARF v5

In reply to Nick Desaulniers
Quoted 69 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. GNU as only recently gained support for specifying -gdwarf-5.

The DWARF version of a binary can be validated with:

$ llvm-dwarfdump vmlinux | head -n 5 | 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
---
 Makefile                          | 1 +
 include/asm-generic/vmlinux.lds.h | 6 +++++-
 lib/Kconfig.debug                 | 8 ++++++++
 scripts/test_dwarf5_support.sh    | 9 +++++++++
 4 files changed, 23 insertions(+), 1 deletion(-)
 create mode 100755 scripts/test_dwarf5_support.sh
Makefile +1 -0
index e23786a4c1c7..9056bac0ff85 100644
@@ -828,6 +828,7 @@ 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)
 ifneq ($(dwarf-version-y)$(LLVM_IAS),21)
 # Binutils 2.35+ required for -gdwarf-4+ support.
include/asm-generic/vmlinux.lds.h +5 -1
index b2b3d81b1535..76ce62c77029 100644
@@ -829,7 +829,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 +0 -0
index 03c494eefabd..c5b54ba51060 100644

lib/Kconfig.debug config DEBUG_INFO_DWARF4 · line 278

Quoted 5 lines
lib/Kconfig.debug +2 -0
@@ -274,6 +274,14 @@ 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 DWARF5 debuginfo"

The choice menu looks like follows:

(X) Generate DWARF v2 debuginfo
( ) Generate dwarf4 debuginfo
( ) Generate DWARF5 debuginfo

Upper / Lower case inconsistency.

--
Best Regards
Masahiro Yamada

#41 lore raw
In reply to Nick Desaulniers
Quoted 7 lines · Nick Desaulniers

DWARF5 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. Further -gdwarf-X where X is an unsupported value doesn't produce an error in $(CC). GNU as only recently gained support for specifying -gdwarf-5.

Do you have more details here? On godbolt.org, gcc does report an error for unsupported dwarf versions.

https://godbolt.org/z/G35798

gcc does not seem to pass the -gdwarf-* options to the assembler when compiling C source. For assembler, gcc will pass an appropriate option depending on the version of binutils it was configured with: if the assembler doesn't support dwarf-5 it can call it with --gdwarf2 for eg.

If the user is using a properly configured toolchain it doesn't look like it should be an issue to just use cc-option?

#42 lore raw
Quoted 10 lines · Arvind Sankar
Quoted 2 lines · Nick Desaulniers

Further -gdwarf-X where X is an unsupported value doesn't produce an error in $(CC).

Do you have more details here? On godbolt.org, gcc does report an error for unsupported dwarf versions.

https://godbolt.org/z/G35798

Quoted 7 lines

gcc does not seem to pass the -gdwarf-* options to the assembler when compiling C source. For assembler, gcc will pass an appropriate option depending on the version of binutils it was configured with: if the assembler doesn't support dwarf-5 it can call it with --gdwarf2 for eg.

If the user is using a properly configured toolchain it doesn't look like it should be an issue to just use cc-option?

I wrote the base patch back in May, and didn't revisit until recently. I could have sworn the cc-option silently failed for the check cc-option does, which is /dev/null input. I need to recheck that, but it doesn't hurt to simply include it for now, which I've done in a v2 I'm about to send.

Signature · 2 lines
Thanks,
~Nick Desaulniers
#43 lore raw
Quoted 16 lines · Nick Desaulniers
Quoted 15 lines · Arvind Sankar
Quoted 2 lines · Nick Desaulniers

Further -gdwarf-X where X is an unsupported value doesn't produce an error in $(CC).

Do you have more details here? On godbolt.org, gcc does report an error for unsupported dwarf versions.

https://godbolt.org/z/G35798

gcc does not seem to pass the -gdwarf-* options to the assembler when compiling C source. For assembler, gcc will pass an appropriate option depending on the version of binutils it was configured with: if the assembler doesn't support dwarf-5 it can call it with --gdwarf2 for eg.

Quoted 11 lines
Quoted 2 lines

If the user is using a properly configured toolchain it doesn't look like it should be an issue to just use cc-option?

I wrote the base patch back in May, and didn't revisit until recently. I could have sworn the cc-option silently failed for the check cc-option does, which is /dev/null input. I need to recheck that, but it doesn't hurt to simply include it for now, which I've done in a v2 I'm about to send.

Signature · 2 lines
Thanks,
~Nick Desaulniers

This is giving me deja vu about the -gz=zlib option.

Didn't Masahiro fix the cc-option issue with
4d0831e8a029 ("kconfig: unify cc-option and as-option")

The existing -Wa,-gdwarf-2 in the Makefile seems bogus, btw. GCC 4.9.0 at least appears to pass on --gdwarf2 automatically.

#44 lore raw
Quoted 30 lines · Arvind Sankar
Quoted 19 lines · Nick Desaulniers
Quoted 10 lines · Arvind Sankar
Quoted 2 lines · Nick Desaulniers

Further -gdwarf-X where X is an unsupported value doesn't produce an error in $(CC).

Do you have more details here? On godbolt.org, gcc does report an error for unsupported dwarf versions.

https://godbolt.org/z/G35798

Quoted 7 lines

gcc does not seem to pass the -gdwarf-* options to the assembler when compiling C source. For assembler, gcc will pass an appropriate option depending on the version of binutils it was configured with: if the assembler doesn't support dwarf-5 it can call it with --gdwarf2 for eg.

If the user is using a properly configured toolchain it doesn't look like it should be an issue to just use cc-option?

Quoted 8 lines

I wrote the base patch back in May, and didn't revisit until recently. I could have sworn the cc-option silently failed for the check cc-option does, which is /dev/null input. I need to recheck that, but it doesn't hurt to simply include it for now, which I've done in a v2 I'm about to send.
--
Thanks,
~Nick Desaulniers

Quoted 7 lines

This is giving me deja vu about the -gz=zlib option.

Didn't Masahiro fix the cc-option issue with
4d0831e8a029 ("kconfig: unify cc-option and as-option")

The existing -Wa,-gdwarf-2 in the Makefile seems bogus, btw. GCC 4.9.0 at least appears to pass on --gdwarf2 automatically.

It looks like we don't need -Wa,-gdwarf-2 when -gdwarf-2 is set. So I can probably drop
+DEBUG_CFLAGS += $(dwarf-aflag)
from v2. Will retest though.

Signature · 2 lines
Thanks,
~Nick Desaulniers
#45 lore raw
Quoted 37 lines · Nick Desaulniers
Quoted 35 lines · Arvind Sankar
Quoted 19 lines · Nick Desaulniers
Quoted 10 lines · Arvind Sankar
Quoted 2 lines · Nick Desaulniers

Further -gdwarf-X where X is an unsupported value doesn't produce an error in $(CC).

Do you have more details here? On godbolt.org, gcc does report an error for unsupported dwarf versions.

https://godbolt.org/z/G35798

Quoted 7 lines

gcc does not seem to pass the -gdwarf-* options to the assembler when compiling C source. For assembler, gcc will pass an appropriate option depending on the version of binutils it was configured with: if the assembler doesn't support dwarf-5 it can call it with --gdwarf2 for eg.

If the user is using a properly configured toolchain it doesn't look like it should be an issue to just use cc-option?

Quoted 8 lines

I wrote the base patch back in May, and didn't revisit until recently. I could have sworn the cc-option silently failed for the check cc-option does, which is /dev/null input. I need to recheck that, but it doesn't hurt to simply include it for now, which I've done in a v2 I'm about to send.
--
Thanks,
~Nick Desaulniers

This is giving me deja vu about the -gz=zlib option.

Didn't Masahiro fix the cc-option issue with
4d0831e8a029 ("kconfig: unify cc-option and as-option")

Quoted 7 lines
Quoted 2 lines

The existing -Wa,-gdwarf-2 in the Makefile seems bogus, btw. GCC 4.9.0 at least appears to pass on --gdwarf2 automatically.

It looks like we don't need -Wa,-gdwarf-2 when -gdwarf-2 is set. So I can probably drop
+DEBUG_CFLAGS += $(dwarf-aflag)
from v2. Will retest though.

That's needed for non LLVM_IAS=1 builds so that clang informs GAS to assembler using DWARF Version 5; otherwise every translation unit fails to assemble with an error from GAS.

Signature · 2 lines
Thanks,
~Nick Desaulniers