Kbuild: DWARF v5 support
Subsystems (3)
v4 cover Kbuild: DWARF v5 support
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 cleanup from Masahiro and isn't DWARF v5 specific. Patch 2 is a cleanup that lays the ground work and isn't DWARF v5 specific.
Patch 3 implements Kconfig and Kbuild support for DWARFv5.
Changes from v3:
Changes as per Arvind:
* only add -Wa,-gdwarf-5 for (LLVM=1|CC=clang)+LLVM_IAS=0 builds.
* add -gdwarf-5 to Kconfig shell script.
* only run Kconfig shell script for Clang.
Apologies to Sedat and Nathan; I appreciate previous testing/review, but I did no carry forward your Tested-by and Reviewed-by tags, as the patches have changed too much IMO.
Changes from v2:
* Drop two of the earlier patches that have been accepted already.
* Add measurements with GCC 10.2 to commit message.
* Update help text as per Arvind with help from Caroline.
* Improve case/wording between DWARF Versions as per Masahiro.
Changes from the RFC:
* split patch in 3 patch series, include Fangrui's patch, too.
* prefer DWARF vX format, as per Fangrui.
* use spaces between assignment in Makefile as per Masahiro.
* simplify setting dwarf-version-y as per Masahiro.
* indent prompt in Kconfig change as per Masahiro.
* remove explicit default in Kconfig as per Masahiro.
* add comments to test_dwarf5_support.sh.
* change echo in test_dwarf5_support.sh as per Masahiro.
* remove -u from test_dwarf5_support.sh as per Masahiro.
* add a -gdwarf-5 cc-option check to Kconfig as per Jakub.
Masahiro Yamada (1):
Remove $(cc-option,-gdwarf-4) dependency from CONFIG_DEBUG_INFO_DWARF4
Nick Desaulniers (2):
Kbuild: make DWARF version a choice
Kbuild: implement support for DWARF v5
Makefile | 15 +++++++---- include/asm-generic/vmlinux.lds.h | 6 ++++- lib/Kconfig.debug | 41 +++++++++++++++++++++++++------ scripts/test_dwarf5_support.sh | 9 +++++++ 4 files changed, 58 insertions(+), 13 deletions(-) create mode 100755 scripts/test_dwarf5_support.sh
Signature · 1 line
2.30.0.284.gd98b1dd5eaa7-goog
PATCH v4 1/3 Remove $(cc-option,-gdwarf-4) dependency from CONFIG_DEBUG_INFO_DWARF4
From: Masahiro Yamada <[email protected]>
The -gdwarf-4 flag is supported by GCC 4.5+, and also by Clang.
You can see it at https://godbolt.org/z/6ed1oW
For gcc 4.5.3 pane, line 37: .value 0x4
For clang 10.0.1 pane, line 117: .short 4
Given Documentation/process/changes.rst stating GCC 4.9 is the minimal version, this cc-option is unneeded.
Note
----
CONFIG_DEBUG_INFO_DWARF4 controls the DWARF version only for C files.
As you can see in the top Makefile, -gdwarf-4 is only passed to CFLAGS.
ifdef CONFIG_DEBUG_INFO_DWARF4
DEBUG_CFLAGS += -gdwarf-4
endif
This flag is used when compiling *.c files.
On the other hand, the assembler is always given -gdwarf-2.
KBUILD_AFLAGS += -Wa,-gdwarf-2
Hence, the debug info that comes from *.S files is always DWARF v2. This is simply because GAS supported only -gdwarf-2 for a long time.
Recently, GAS gained the support for --dwarf-[3|4|5] options. [1] And, also we have Clang integrated assembler. So, the debug info for *.S files might be improved if we want.
In my understanding, the current code is intentional, not a bug.
[1] https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=31bf18645d98b4d3d7357353be840e320649a67d
--- lib/Kconfig.debug | 1 - 1 file changed, 1 deletion(-)
lib/Kconfig.debug +0 -1
@@ -258,7 +258,6 @@ config DEBUG_INFO_SPLIT 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.
Signature · 1 line
2.30.0.284.gd98b1dd5eaa7-goog
Re: [PATCH v4 1/3] Remove $(cc-option,-gdwarf-4) dependency from CONFIG_DEBUG_INFO_DWARF4
Quoted 36 lines · Nick Desaulniers
From: Masahiro Yamada <[email protected]>
The -gdwarf-4 flag is supported by GCC 4.5+, and also by Clang.
You can see it at https://godbolt.org/z/6ed1oW
For gcc 4.5.3 pane, line 37: .value
0x4
For clang 10.0.1 pane, line 117: .short 4Given
Documentation/process/changes.rststating GCC 4.9 is the minimal version, this cc-option is unneeded.Note
----
CONFIG_DEBUG_INFO_DWARF4controls the DWARF version only for C files.As you can see in the top
Makefile, -gdwarf-4 is only passed to CFLAGS.ifdef
CONFIG_DEBUG_INFO_DWARF4
DEBUG_CFLAGS+= -gdwarf-4
endifThis flag is used when compiling *.c files.
On the other hand, the assembler is always given -gdwarf-2.
KBUILD_AFLAGS+= -Wa,-gdwarf-2Hence, the debug info that comes from *.S files is always DWARF v2. This is simply because GAS supported only -gdwarf-2 for a long time.
Recently, GAS gained the support for --dwarf-[3|4|5] options. [1] And, also we have Clang integrated assembler. So, the debug info for *.S files might be improved if we want.
Quoted 6 lines
In my understanding, the current code is intentional, not a bug.
[1] https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=31bf18645d98b4d3d7357353be840e320649a67d
Signed-off-by Masahiro Yamada <[email protected]>Reviewed-by Nick Desaulniers <[email protected]>
Quoted 19 lines
--- lib/Kconfig.debug | 1 - 1 file changed, 1 deletion(-)lib/Kconfig.debug +0
-1@@ -258,7 +258,6 @@ config DEBUG_INFO_SPLIT 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.Signature · 1 line
2.30.0.284.gd98b1dd5eaa7-goog
PATCH v4 2/3 Kbuild: make DWARF version a choice
In reply to Nick DesaulniersModifies 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 | 21 ++++++++++++++++----- 2 files changed, 25 insertions(+), 10 deletions(-)
Makefile +9 -5
@@ -826,12 +826,16 @@ else DEBUG_CFLAGS += -g endif -ifneq ($(LLVM_IAS),1) -KBUILD_AFLAGS += -Wa,-gdwarf-2 +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)) +ifdef CONFIG_CC_IS_CLANG +DEBUG_CFLAGS += $(dwarf-aflag) endif - -ifdef CONFIG_DEBUG_INFO_DWARF4 -DEBUG_CFLAGS += -gdwarf-4 +KBUILD_AFLAGS += $(dwarf-aflag) endif ifdef CONFIG_DEBUG_INFO_REDUCED
lib/Kconfig.debug +16 -5
@@ -256,13 +256,24 @@ config DEBUG_INFO_SPLIT to know about the .dwo files and include them. Incompatible with older versions of ccache. +choice + prompt "DWARF version" + help + Which version of DWARF debug info to emit. + +config DEBUG_INFO_DWARF2 + bool "Generate DWARF Version 2 debuginfo" + help + Generate DWARF v2 debug info. + config DEBUG_INFO_DWARF4 - bool "Generate dwarf4 debuginfo" + bool "Generate DWARF Version 4 debuginfo" help - Generate dwarf4 debug info. This requires recent versions - of gcc and gdb. It makes the debug information larger. - But it significantly improves the success of resolving - variables in gdb on optimized code. + Generate DWARF v4 debug info. This requires gcc 4.5+ and gdb 7.0+. + It makes the debug information larger, but it significantly + improves the success of resolving variables in gdb on optimized code. + +endchoice # "DWARF version" config DEBUG_INFO_BTF bool "Generate BTF typeinfo"
Signature · 1 line
2.30.0.284.gd98b1dd5eaa7-goog
Re: [PATCH v4 2/3] Kbuild: make DWARF version a choice
Quoted 8 lines · Nick Desaulniers
Modifies
CONFIG_DEBUG_INFO_DWARF4to be a member of a choice. Adds an explicitCONFIG_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.Suggested-by Fangrui Song <[email protected]>Suggested-by Masahiro Yamada <[email protected]>Signed-off-by Nick Desaulniers <[email protected]>
Quoted 68 lines
--- Makefile | 14 +++++++++----- lib/Kconfig.debug | 21 ++++++++++++++++----- 2 files changed, 25 insertions(+), 10 deletions(-)Makefile +9
-5@@ -826,12 +826,16 @@ else DEBUG_CFLAGS += -g endif -ifneq ($(LLVM_IAS),1) -KBUILD_AFLAGS += -Wa,-gdwarf-2 +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)) +ifdef CONFIG_CC_IS_CLANG +DEBUG_CFLAGS += $(dwarf-aflag) endif - -ifdef CONFIG_DEBUG_INFO_DWARF4 -DEBUG_CFLAGS += -gdwarf-4 +KBUILD_AFLAGS += $(dwarf-aflag) endif ifdef CONFIG_DEBUG_INFO_REDUCEDlib/Kconfig.debug +16
-5@@ -256,13 +256,24 @@ config DEBUG_INFO_SPLIT to know about the .dwo files and include them. Incompatible with older versions of ccache. +choice + prompt "DWARF version" + help + Which version of DWARF debug info to emit. + +config DEBUG_INFO_DWARF2 + bool "Generate DWARF Version 2 debuginfo" + help + Generate DWARF v2 debug info. + config DEBUG_INFO_DWARF4 - bool "Generate dwarf4 debuginfo" + bool "Generate DWARF Version 4 debuginfo" help - Generate dwarf4 debug info. This requires recent versions - of gcc and gdb. It makes the debug information larger. - But it significantly improves the success of resolving - variables in gdb on optimized code. + Generate DWARF v4 debug info. This requires gcc 4.5+ and gdb 7.0+. + It makes the debug information larger, but it significantly + improves the success of resolving variables in gdb on optimized code. + +endchoice # "DWARF version" config DEBUG_INFO_BTF bool "Generate BTF typeinfo"Signature · 1 line
2.30.0.284.gd98b1dd5eaa7-goog
Re: [PATCH v4 2/3] Kbuild: make DWARF version a choice
In reply to Nick DesaulniersQuoted 23 lines · Nick Desaulniers
Modifies
CONFIG_DEBUG_INFO_DWARF4to be a member of a choice. Adds an explicitCONFIG_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.Suggested-by Fangrui Song <[email protected]>Suggested-by Masahiro Yamada <[email protected]>Signed-off-by Nick Desaulniers <[email protected]>--- Makefile | 14 +++++++++----- lib/Kconfig.debug | 21 ++++++++++++++++----- 2 files changed, 25 insertions(+), 10 deletions(-)Makefile +0
-1@@ -826,12 +826,16 @@ else DEBUG_CFLAGS += -g endif -ifneq ($(LLVM_IAS),1)
Makefile else · line 837
Quoted 10 lines
Makefile +8
-1-KBUILD_AFLAGS += -Wa,-gdwarf-2 +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)) +ifdef CONFIG_CC_IS_CLANG +DEBUG_CFLAGS += $(dwarf-aflag) endif
Why is that "ifdef CONFIG_CC_IS_CLANG"?
When I use GCC v10.2.1 DEBUG_CFLAGS are not set.
- Sedat -
Quoted 44 lines
Makefile +1
-3- -ifdef CONFIG_DEBUG_INFO_DWARF4 -DEBUG_CFLAGS += -gdwarf-4 +KBUILD_AFLAGS += $(dwarf-aflag) endif ifdef CONFIG_DEBUG_INFO_REDUCEDlib/Kconfig.debug +16
-6@@ -256,13 +256,24 @@ config DEBUG_INFO_SPLIT to know about the .dwo files and include them. Incompatible with older versions of ccache. +choice + prompt "DWARF version" + help + Which version of DWARF debug info to emit. + +config DEBUG_INFO_DWARF2 + bool "Generate DWARF Version 2 debuginfo" + help + Generate DWARF v2 debug info. + config DEBUG_INFO_DWARF4 - bool "Generate dwarf4 debuginfo" + bool "Generate DWARF Version 4 debuginfo" help - Generate dwarf4 debug info. This requires recent versions - of gcc and gdb. It makes the debug information larger. - But it significantly improves the success of resolving - variables in gdb on optimized code. + Generate DWARF v4 debug info. This requires gcc 4.5+ and gdb 7.0+. + It makes the debug information larger, but it significantly + improves the success of resolving variables in gdb on optimized code. + +endchoice # "DWARF version" config DEBUG_INFO_BTF bool "Generate BTF typeinfo" --2.30.0.284.gd98b1dd5eaa7-goog
Re: [PATCH v4 2/3] Kbuild: make DWARF version a choice
Sedat,
Thanks for testing, and congrats on https://lwn.net/Articles/839772/.
I always appreciate you taking the time to help test my work, and other Clang+Linux kernel patches!
Quoted 10 lines · Sedat Dilek
Quoted 7 lines · Nick Desaulniers
Makefile +0
-0@@ -826,12 +826,16 @@ else DEBUG_CFLAGS += -g endif
Quoted 5 lines
Makefile else · line 831
Quoted 5 lines
Makefile +3
-2-ifneq ($(LLVM_IAS),1) -KBUILD_AFLAGS += -Wa,-gdwarf-2 +dwarf-version-$(CONFIG_DEBUG_INFO_DWARF2) := 2 +dwarf-version-$(CONFIG_DEBUG_INFO_DWARF4) := 4 +DEBUG_CFLAGS += -gdwarf-$(dwarf-version-y)
^ DEBUG_CFLAGS are set for everyone (all toolchains) if CONFIG_DEBUG_INFO is defined.
Quoted 1 line
Makefile else · line 832
Quoted 1 line
Makefile +1
-0+ifneq ($(dwarf-version-y)$(LLVM_IAS),21)
^ "If not using dwarf 2 and LLVM_IAS=1", ie. CONFIG_DEBUG_INFO_DWARF5 && CONFIG_CC_IS_GCC
Quoted 3 lines
Makefile else · line 835
Quoted 3 lines
Makefile +3
-0+# Binutils 2.35+ required for -gdwarf-4+ support. +dwarf-aflag := $(call as-option,-Wa$(comma)-gdwarf-$(dwarf-version-y)) +ifdef CONFIG_CC_IS_CLANG
^ "if clang"
Quoted 4 lines
Makefile else · line 837
Quoted 2 lines
Makefile +1
-0+DEBUG_CFLAGS += $(dwarf-aflag) endifWhy is that "ifdef
CONFIG_CC_IS_CLANG"?
That's what Arvind requested on v2, IIUC:
https://lore.kernel.org/lkml/X8psgMuL4jMjP%[email protected]/
Quoted 1 line
When I use GCC v10.2.1
DEBUG_CFLAGSare not set.
You should have -gdwarf-4 (and not -Wa,-gwarf-4) set for DEBUG_CFLAGS when compiling with GCC and enabling CONFIG_DEBUG_INFO_DWARF4. Can you please confirm? (Perhaps you may have accidentally disabled CONFIG_DEBUG_INFO by rerunning make defconfig?)
Signature · 2 lines
Thanks, ~Nick Desaulniers
Re: [PATCH v4 2/3] Kbuild: make DWARF version a choice
Quoted 6 lines · Nick Desaulniers
Sedat,
Thanks for testing, and congrats on https://lwn.net/Articles/839772/.
I always appreciate you taking the time to help test my work, and other Clang+Linux kernel patches!
Hi Nick,
cool, again in the top 15 :-).
I should ask Mr. Corbet for a LWN subscription.
Quoted 20 lines · Sedat Dilek
Quoted 10 lines
Quoted 7 lines · Nick Desaulniers
Makefile +0
-0@@ -826,12 +826,16 @@ else DEBUG_CFLAGS += -g endifQuoted 5 lines
Makefile else · line 831
Quoted 5 lines
Makefile +3
-2-ifneq ($(LLVM_IAS),1) -KBUILD_AFLAGS += -Wa,-gdwarf-2 +dwarf-version-$(CONFIG_DEBUG_INFO_DWARF2) := 2 +dwarf-version-$(CONFIG_DEBUG_INFO_DWARF4) := 4 +DEBUG_CFLAGS += -gdwarf-$(dwarf-version-y)^
DEBUG_CFLAGSare set for everyone (all toolchains) ifCONFIG_DEBUG_INFOis defined.
Quoted 5 lines
Quoted 1 line
Makefile else · line 832
Quoted 1 line
Makefile +1
-0+ifneq ($(dwarf-version-y)$(LLVM_IAS),21)^ "If not using dwarf 2 and LLVM_IAS=1", ie.
CONFIG_DEBUG_INFO_DWARF5&&CONFIG_CC_IS_GCC
OK, I know DWARF v2 and LLVM_IAS=1 is broken.
Looks like DWARF v5 with GCC v10.2.1 and binutils v2.35.1 is currently (here) no good choice.
Quoted 14 lines
Quoted 3 lines
Makefile else · line 835
Quoted 3 lines
Makefile +3
-0+# Binutils 2.35+ required for -gdwarf-4+ support. +dwarf-aflag := $(call as-option,-Wa$(comma)-gdwarf-$(dwarf-version-y)) +ifdef CONFIG_CC_IS_CLANG^ "if clang"
Quoted 4 lines
Makefile else · line 837
Quoted 2 lines
Makefile +1
-0+DEBUG_CFLAGS += $(dwarf-aflag) endifWhy is that "ifdef
CONFIG_CC_IS_CLANG"?That's what Arvind requested on v2, IIUC:
https://lore.kernel.org/lkml/X8psgMuL4jMjP%[email protected]/
Quoted 7 lines
Quoted 1 line
When I use GCC v10.2.1
DEBUG_CFLAGSare not set.You should have -gdwarf-4 (and not -Wa,-gwarf-4) set for
DEBUG_CFLAGSwhen compiling with GCC and enablingCONFIG_DEBUG_INFO_DWARF4. Can you please confirm? (Perhaps you may have accidentally disabledCONFIG_DEBUG_INFOby rerunningmake defconfig?)
$ egrep 'CC_IS_|LD_IS|BTF|DWARF' config-5.11.0-rc3-5-amd64-gcc10-llvm11 | grep ^CONFIG CONFIG_CC_IS_GCC=y CONFIG_LD_IS_LLD=y CONFIG_DEBUG_INFO_DWARF4=y CONFIG_DEBUG_INFO_BTF=y CONFIG_DEBUG_INFO_BTF_MODULES=y
$ grep '\-Wa,-gdwarf-4' build-log_5.11.0-rc3-5-amd64-gcc10-llvm11.txt | wc -l 156
Re: [PATCH v4 2/3] Kbuild: make DWARF version a choice
Quoted 77 lines · Sedat Dilek
Quoted 6 lines · Nick Desaulniers
Sedat,
Thanks for testing, and congrats on https://lwn.net/Articles/839772/.
I always appreciate you taking the time to help test my work, and other Clang+Linux kernel patches!Hi Nick,
cool, again in the top 15 :-).
I should ask Mr. Corbet for a LWN subscription.
Quoted 20 lines · Sedat Dilek
Quoted 10 lines
Quoted 7 lines · Nick Desaulniers
Makefile +0
-0@@ -826,12 +826,16 @@ else DEBUG_CFLAGS += -g endifQuoted 5 lines
Makefile else · line 831
Quoted 5 lines
Makefile +3
-2-ifneq ($(LLVM_IAS),1) -KBUILD_AFLAGS += -Wa,-gdwarf-2 +dwarf-version-$(CONFIG_DEBUG_INFO_DWARF2) := 2 +dwarf-version-$(CONFIG_DEBUG_INFO_DWARF4) := 4 +DEBUG_CFLAGS += -gdwarf-$(dwarf-version-y)^
DEBUG_CFLAGSare set for everyone (all toolchains) ifCONFIG_DEBUG_INFOis defined.Quoted 5 lines
Quoted 1 line
Makefile else · line 832
Quoted 1 line
Makefile +1
-0+ifneq ($(dwarf-version-y)$(LLVM_IAS),21)^ "If not using dwarf 2 and LLVM_IAS=1", ie.
CONFIG_DEBUG_INFO_DWARF5&&CONFIG_CC_IS_GCCOK, I know DWARF v2 and LLVM_IAS=1 is broken.
Looks like DWARF v5 with GCC v10.2.1 and binutils v2.35.1 is currently (here) no good choice.
Quoted 14 lines
Quoted 3 lines
Makefile else · line 835
Quoted 3 lines
Makefile +3
-0+# Binutils 2.35+ required for -gdwarf-4+ support. +dwarf-aflag := $(call as-option,-Wa$(comma)-gdwarf-$(dwarf-version-y)) +ifdef CONFIG_CC_IS_CLANG^ "if clang"
Quoted 4 lines
Makefile else · line 837
Quoted 2 lines
Makefile +1
-0+DEBUG_CFLAGS += $(dwarf-aflag) endifWhy is that "ifdef
CONFIG_CC_IS_CLANG"?That's what Arvind requested on v2, IIUC:
https://lore.kernel.org/lkml/X8psgMuL4jMjP%[email protected]/Quoted 7 lines
Quoted 1 line
When I use GCC v10.2.1
DEBUG_CFLAGSare not set.You should have -gdwarf-4 (and not -Wa,-gwarf-4) set for
DEBUG_CFLAGSwhen compiling with GCC and enablingCONFIG_DEBUG_INFO_DWARF4. Can you please confirm? (Perhaps you may have accidentally disabledCONFIG_DEBUG_INFOby rerunningmake defconfig?)$ egrep 'CC_IS_|LD_IS|BTF|DWARF' config-5.11.0-rc3-5-amd64-gcc10-llvm11 | grep ^CONFIG CONFIG_CC_IS_GCC=y CONFIG_LD_IS_LLD=y CONFIG_DEBUG_INFO_DWARF4=y CONFIG_DEBUG_INFO_BTF=y CONFIG_DEBUG_INFO_BTF_MODULES=y
Quoted 3 lines
$ grep '\-Wa,-gdwarf-4' build-log_5.11.0-rc3-5-amd64-gcc10-llvm11.txt | wc -l 156
I wonder why I see GNU/as here (see above CONFIG_LD_IS_LLD=y)?
$ llvm-dwarfdump-11 vmlinux | head -20 | egrep
'debug_info|format|version|DW_AT_producer'
vmlinux: file format elf64-x86-64
.debug_info contents:
0x00000000: Compile Unit: length = 0x0000001e, format = DWARF32,
version = 0x0004, abbr_offset = 0x0000, addr_size = 0x08 (next unit at
0x00000022)
DW_AT_producer ("GNU AS 2.35.1")
0x00000022: Compile Unit: length = 0x0000c1d2, format = DWARF32,
version = 0x0004, abbr_offset = 0x0012, addr_size = 0x08 (next unit at
0x0000c1f8)
DW_AT_producer ("GNU C89 10.2.1 20210110 -mno-sse
-mno-mmx -mno-sse2 -mno-3dnow -mno-avx -m64 -mno-80387
-mno-fp-ret-in-387 -mpreferred-stack-boundary
=3 -mskip-rax-setup -mtune=generic -mno-red-zone -mcmodel=kernel
-mindirect-branch=thunk-extern -mindirect-branch-register
-mrecord-mcount -mfentry -march=x86-64 -g -g
dwarf-4 -O2 -std=gnu90 -fno-strict-aliasing -fno-common -fshort-wchar
-fno-PIE -falign-jumps=1 -falign-loops=1
-fno-asynchronous-unwind-tables -fno-jump-tables -fno-de
lete-null-pointer-checks -fno-allow-store-data-races
-fstack-protector-strong -fno-strict-overflow -fstack-check=no
-fconserve-stack -fcf-protection=none -fno-stack-pr
otector")Maybe, I should set all LLVM utils and linker manually, not using LLVM=1.
- Sedat -
Re: [PATCH v4 2/3] Kbuild: make DWARF version a choice
In reply to Nick DesaulniersQuoted 37 lines · Nick Desaulniers
Sedat,
Thanks for testing, and congrats on https://lwn.net/Articles/839772/.
I always appreciate you taking the time to help test my work, and other Clang+Linux kernel patches!Quoted 10 lines · Sedat Dilek
Quoted 7 lines · Nick Desaulniers
Makefile +0
-0@@ -826,12 +826,16 @@ else DEBUG_CFLAGS += -g endifQuoted 5 lines
Makefile else · line 831
Quoted 5 lines
Makefile +3
-2-ifneq ($(LLVM_IAS),1) -KBUILD_AFLAGS += -Wa,-gdwarf-2 +dwarf-version-$(CONFIG_DEBUG_INFO_DWARF2) := 2 +dwarf-version-$(CONFIG_DEBUG_INFO_DWARF4) := 4 +DEBUG_CFLAGS += -gdwarf-$(dwarf-version-y)^
DEBUG_CFLAGSare set for everyone (all toolchains) ifCONFIG_DEBUG_INFOis defined.Quoted 1 line
Makefile else · line 832
Quoted 1 line
Makefile +1
-0+ifneq ($(dwarf-version-y)$(LLVM_IAS),21)^ "If not using dwarf 2 and LLVM_IAS=1", ie.
CONFIG_DEBUG_INFO_DWARF5&&CONFIG_CC_IS_GCCQuoted 3 lines
Makefile else · line 835
Quoted 3 lines
Makefile +3
-0+# Binutils 2.35+ required for -gdwarf-4+ support. +dwarf-aflag := $(call as-option,-Wa$(comma)-gdwarf-$(dwarf-version-y)) +ifdef CONFIG_CC_IS_CLANG^ "if clang"
Quoted 7 lines
Quoted 4 lines
Makefile else · line 837
Quoted 2 lines
Makefile +1
-0+DEBUG_CFLAGS += $(dwarf-aflag) endifWhy is that "ifdef
CONFIG_CC_IS_CLANG"?That's what Arvind requested on v2, IIUC:
https://lore.kernel.org/lkml/X8psgMuL4jMjP%[email protected]/
If CONFIG_CC_IS_CLANG is set,
both -gdwarf and -Wa,-gdwarf-4 are passed to DEBUG_CFLAGS.
Is it necessary?
IIUC, -Wa,-gdwarf is meaningless
when you build *.c files.
I passed -v option to see
how gas is invoked behind the scene.
See the following results
for [1] GCC + GAS and [2] Clang + GAS cases
[1] GCC + GAS
masahiro@grover:~$ cat test.c
int main(void) { return 0; }
masahiro@grover:~$ gcc -v -gdwarf-4 -c -o test.o test.c
Using built-in specs.
COLLECT_GCC=gcc
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu
10.2.0-13ubuntu1'
--with-bugurl=file:///usr/share/doc/gcc-10/README.Bugs
--enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2
--prefix=/usr --with-gcc-major-version-only --program-suffix=-10
--program-prefix=x86_64-linux-gnu- --enable-shared
--enable-linker-build-id --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --libdir=/usr/lib
--enable-nls --enable-clocale=gnu --enable-libstdcxx-debug
--enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new
--enable-gnu-unique-object --disable-vtable-verify --enable-plugin
--enable-default-pie --with-system-zlib
--enable-libphobos-checking=release --with-target-system-zlib=auto
--enable-objc-gc=auto --enable-multiarch --disable-werror
--with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32
--enable-multilib --with-tune=generic
--enable-offload-targets=nvptx-none=/build/gcc-10-JvwpWM/gcc-10-10.2.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-10-JvwpWM/gcc-10-10.2.0/debian/tmp-gcn/usr,hsa
--without-cuda-driver --enable-checking=release
--build=x86_64-linux-gnu --host=x86_64-linux-gnu
--target=x86_64-linux-gnu
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 10.2.0 (Ubuntu 10.2.0-13ubuntu1)
COLLECT_GCC_OPTIONS='-v' '-gdwarf-4' '-c' '-o' 'test.o'
'-mtune=generic' '-march=x86-64'
/usr/lib/gcc/x86_64-linux-gnu/10/cc1 -quiet -v -imultiarch
x86_64-linux-gnu test.c -quiet -dumpbase test.c -mtune=generic
-march=x86-64 -auxbase-strip test.o -gdwarf-4 -version
-fasynchronous-unwind-tables -fstack-protector-strong -Wformat
-Wformat-security -fstack-clash-protection -fcf-protection -o
/tmp/cc4hKJeo.s
GNU C17 (Ubuntu 10.2.0-13ubuntu1) version 10.2.0 (x86_64-linux-gnu)
compiled by GNU C version 10.2.0, GMP version 6.2.0, MPFR version
4.1.0, MPC version 1.2.0-rc1, isl version isl-0.22.1-GMPGGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu" ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/10/include-fixed" ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/10/../../../../x86_64-linux-gnu/include" #include "..." search starts here:
#include <...> search starts here:
/usr/lib/gcc/x86_64-linux-gnu/10/include
/usr/local/include
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
GNU C17 (Ubuntu 10.2.0-13ubuntu1) version 10.2.0 (x86_64-linux-gnu) compiled by GNU C version 10.2.0, GMP version 6.2.0, MPFR version 4.1.0, MPC version 1.2.0-rc1, isl version isl-0.22.1-GMP
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 4831429547eb0be4fec215fca56ed5cf
COLLECT_GCC_OPTIONS='-v' '-gdwarf-4' '-c' '-o' 'test.o'
'-mtune=generic' '-march=x86-64'
as -v --64 -o test.o /tmp/cc4hKJeo.s
GNU assembler version 2.35.1 (x86_64-linux-gnu) using BFD version (GNU
Binutils for Ubuntu) 2.35.1
COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/10/:/usr/lib/gcc/x86_64-linux-gnu/10/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/10/:/usr/lib/gcc/x86_64-linux-gnu/ LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/10/:/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/10/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/10/../../../:/lib/:/usr/lib/ COLLECT_GCC_OPTIONS='-v' '-gdwarf-4' '-c' '-o' 'test.o'
'-mtune=generic' '-march=x86-64'
masahiro@grover:~$ readelf --debug-dump=info test.o Contents of the .debug_info section:
Compilation Unit @ offset 0x0:
Length: 0x4f (32-bit)
Version: 4
Abbrev Offset: 0x0
Pointer Size: 8
<0><b>: Abbrev Number: 1 (DW_TAG_compile_unit)
<c> DW_AT_producer : (indirect string, offset: 0x16): GNU C17
10.2.0 -mtune=generic -march=x86-64 -gdwarf-4
-fasynchronous-unwind-tables -fstack-protector-strong
-fstack-clash-protection -fcf-protection
<10> DW_AT_language : 12 (ANSI C99)
<11> DW_AT_name : (indirect string, offset: 0xf): test.c
<15> DW_AT_comp_dir : (indirect string, offset: 0x0): /home/masahiro
<19> DW_AT_low_pc : 0x0
<21> DW_AT_high_pc : 0xf
<29> DW_AT_stmt_list : 0x0
<1><2d>: Abbrev Number: 2 (DW_TAG_subprogram)
<2e> DW_AT_external : 1
<2e> DW_AT_name : (indirect string, offset: 0xab): main
<32> DW_AT_decl_file : 1
<33> DW_AT_decl_line : 1
<34> DW_AT_decl_column : 5
<35> DW_AT_prototyped : 1
<35> DW_AT_type : <0x4b>
<39> DW_AT_low_pc : 0x0
<41> DW_AT_high_pc : 0xf
<49> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa)
<4b> DW_AT_GNU_all_call_sites: 1
<1><4b>: Abbrev Number: 3 (DW_TAG_base_type)
<4c> DW_AT_byte_size : 4
<4d> DW_AT_encoding : 5 (signed)
<4e> DW_AT_name : int<1><52>: Abbrev Number: 0
[2] Clang + GAS
masahiro@grover:~$ clang -v -fno-integrated-as -gdwarf-4 -c -o test.o test.c Ubuntu clang version 11.0.0-2 Target: x86_64-pc-linux-gnu Thread model: posix InstalledDir: /usr/bin Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/10 Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/8 Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/9 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9 Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/10 Candidate multilib: .;@m64 Selected multilib: .;@m64 "/usr/lib/llvm-11/bin/clang" -cc1 -triple x86_64-pc-linux-gnu -S -disable-free -disable-llvm-verifier -discard-value-names -main-file-name test.c -mrelocation-model static -mframe-pointer=all -fmath-errno -fno-rounding-math -no-integrated-as -mconstructor-aliases -munwind-tables -target-cpu x86-64 -fno-split-dwarf-inlining -debug-info-kind=limited -dwarf-version=4 -debugger-tuning=gdb -v -resource-dir /usr/lib/llvm-11/lib/clang/11.0.0 -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-11/lib/clang/11.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fno-dwarf-directory-asm -fdebug-compilation-dir /home/masahiro -ferror-limit 19 -fgnuc-version=4.2.1 -fcolor-diagnostics -o /tmp/test-f43580.s -x c test.c clang -cc1 version 11.0.0 based upon LLVM 11.0.0 default target x86_64-pc-linux-gnu ignoring nonexistent directory "/include" #include "..." search starts here: #include <...> search starts here: /usr/local/include /usr/lib/llvm-11/lib/clang/11.0.0/include /usr/include/x86_64-linux-gnu /usr/include End of search list. "/usr/bin/as" --64 -o test.o /tmp/test-f43580.s masahiro@grover:~$ readelf --debug-dump=info test.o Contents of the .debug_info section:
Compilation Unit @ offset 0x0:
Length: 0x47 (32-bit)
Version: 4
Abbrev Offset: 0x0
Pointer Size: 8
<0><b>: Abbrev Number: 1 (DW_TAG_compile_unit)
<c> DW_AT_producer : (indirect string, offset: 0x0): Ubuntu
clang version 11.0.0-2
<10> DW_AT_language : 12 (ANSI C99)
<12> DW_AT_name : (indirect string, offset: 0x1e): test.c
<16> DW_AT_stmt_list : 0x0
<1a> DW_AT_comp_dir : (indirect string, offset: 0x25): /home/masahiro
<1e> DW_AT_low_pc : 0x0
<26> DW_AT_high_pc : 0xf
<1><2a>: Abbrev Number: 2 (DW_TAG_subprogram)
<2b> DW_AT_low_pc : 0x0
<33> DW_AT_high_pc : 0xf
<37> DW_AT_frame_base : 1 byte block: 56 (DW_OP_reg6 (rbp))
<39> DW_AT_name : (indirect string, offset: 0x34): main
<3d> DW_AT_decl_file : 1
<3e> DW_AT_decl_line : 1
<3f> DW_AT_prototyped : 1
<3f> DW_AT_type : <0x43>
<43> DW_AT_external : 1
<1><43>: Abbrev Number: 3 (DW_TAG_base_type)
<44> DW_AT_name : (indirect string, offset: 0x39): int
<48> DW_AT_encoding : 5 (signed)
<49> DW_AT_byte_size : 4<1><4a>: Abbrev Number: 0
In [1], "as -v --64 -o test.o /tmp/cc4hKJeo.s"
is the command that invoked gas.
There is no -gdwarf-4 option passed to gas here, but the produced object has the correct dwarf4 info.
In [2], "/usr/bin/as" --64 -o test.o /tmp/test-f43580.s
is the command that invoked gas.
Again, no -gdwarf-4 option here,
but the produced object has the correct dwarf4 info.
So, when you build *.c -> *.o,
passing -gdwarf-* is enough.
The debug info is generated in the compile stage (i.e. by cc1) and included in the intermediate /tmp/*.s file.
All gas needs to do is to transform the debug sections in the intermediate /tmp/*.s file
into the binary stream in the .o file.
GAS does it without being instructed by the explicit -Wa,-gdwarf-* option.
In my understanding, passing -Wa,-gdwarf
makes sense only when you build *.S -> *.o
This is why I think
DEBUG_CFLAGS += -gdwarf-4 (for source debug of .c files)
and
KBUILD_AFLAGS += -Wa,gdwarf-4 (for source debug of .S files)
are basically orthogonal (and they can be even controlled by separate CONFIG options).
As stated above, DEBUG_CFLAGS += -Wa,gdward-4
does not make sense.
I am not a compiler expert, but
that is what I understood from some experiments.
Please correct me if I am wrong.
Quoted 9 lines
Quoted 1 line
When I use GCC v10.2.1
DEBUG_CFLAGSare not set.You should have -gdwarf-4 (and not -Wa,-gwarf-4) set for
DEBUG_CFLAGSwhen compiling with GCC and enablingCONFIG_DEBUG_INFO_DWARF4. Can you please confirm? (Perhaps you may have accidentally disabledCONFIG_DEBUG_INFOby rerunningmake defconfig?)
--
Thanks,
~Nick Desaulniers
--
Best Regards
Masahiro Yamada
PATCH v4 3/3 Kbuild: implement support for DWARF v5
In reply to Nick DesaulniersDWARF 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 4 | grep version or $ readelf --debug-dump=info vmlinux 2>/dev/null | grep Version
DWARF5 wins significantly in terms of size when mixed with compression (CONFIG_DEBUG_INFO_COMPRESSED).
363M vmlinux.clang12.dwarf5.compressed 434M vmlinux.clang12.dwarf4.compressed 439M vmlinux.clang12.dwarf2.compressed 457M vmlinux.clang12.dwarf5 536M vmlinux.clang12.dwarf4 548M vmlinux.clang12.dwarf2
515M vmlinux.gcc10.2.dwarf5.compressed 599M vmlinux.gcc10.2.dwarf4.compressed 624M vmlinux.gcc10.2.dwarf2.compressed 630M vmlinux.gcc10.2.dwarf5 765M vmlinux.gcc10.2.dwarf4 809M vmlinux.gcc10.2.dwarf2
Though the quality of debug info is harder to quantify; size is not a proxy for quality.
Jakub notes:
All [GCC] 5.1 - 6.x did was start accepting -gdwarf-5 as experimental option that enabled some small DWARF subset (initially only a few DW_LANG_* codes newly added to DWARF5 drafts). Only GCC 7 (released after DWARF 5 has been finalized) started emitting DWARF5 section headers and got most of the DWARF5 changes in...
Version check GCC so that we don't need to worry about the difference in command line args between GNU readelf and llvm-readelf/llvm-dwarfdump to validate the DWARF Version in the assembler feature detection script.
--- Makefile | 1 + include/asm-generic/vmlinux.lds.h | 6 +++++- lib/Kconfig.debug | 17 +++++++++++++++++ scripts/test_dwarf5_support.sh | 9 +++++++++ 4 files changed, 32 insertions(+), 1 deletion(-) create mode 100755 scripts/test_dwarf5_support.sh
Makefile +1 -0
@@ -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
@@ -843,7 +843,11 @@ .debug_types 0 : { *(.debug_types) } \/* DWARF 5 */ \ .debug_macro 0 : { *(.debug_macro) } \ - .debug_addr 0 : { *(.debug_addr) } + .debug_addr 0 : { *(.debug_addr) } \ + .debug_line_str 0 : { *(.debug_line_str) } \ + .debug_loclists 0 : { *(.debug_loclists) } \ + .debug_rnglists 0 : { *(.debug_rnglists) } \ + .debug_str_offsets 0 : { *(.debug_str_offsets) }/* Stabs debugging sections. */ #define STABS_DEBUG \
lib/Kconfig.debug +17 -0
@@ -273,6 +273,23 @@ config DEBUG_INFO_DWARF4 It makes the debug information larger, but it significantly improves the success of resolving variables in gdb on optimized code. +config DEBUG_INFO_DWARF5 + bool "Generate DWARF Version 5 debuginfo" + depends on GCC_VERSION >= 50000 || CC_IS_CLANG + depends on CC_IS_GCC || $(success,$(srctree)/scripts/test_dwarf5_support.sh $(CC) $(CLANG_FLAGS)) + help + Generate DWARF v5 debug info. Requires binutils 2.35, gcc 5.0+ (gcc + 5.0+ accepts the -gdwarf-5 flag but only had partial support for some + draft features until 7.0), and gdb 8.0+. + + Changes to the structure of debug info in Version 5 allow for around + 15-18% savings in resulting image and debug info section sizes as + compared to DWARF Version 4. DWARF Version 5 standardizes previous + extensions such as accelerators for symbol indexing and the format + for fission (.dwo/.dwp) files. Users may not want to select this + config if they rely on tooling that has not yet been updated to + support DWARF Version 5. + endchoice # "DWARF version" config DEBUG_INFO_BTF
scripts/test_dwarf5_support.sh new file +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"' | $* -gdwarf-5 -Wa,-gdwarf-5 -c -x assembler -o /dev/null -
Signature · 1 line
2.30.0.284.gd98b1dd5eaa7-goog
Re: [PATCH v4 3/3] Kbuild: implement support for DWARF v5
Quoted 43 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
asonly recently gained support for specifying -gdwarf-5.The DWARF version of a binary can be validated with:
$ llvm-dwarfdump vmlinux | head -n 4 | grep version or $ readelf --debug-dump=info vmlinux 2>/dev/null | grep VersionDWARF5 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.dwarf2515M vmlinux.gcc10.2.dwarf5.compressed 599M vmlinux.gcc10.2.dwarf4.compressed 624M vmlinux.gcc10.2.dwarf2.compressed 630M vmlinux.gcc10.2.dwarf5 765M vmlinux.gcc10.2.dwarf4 809M vmlinux.gcc10.2.dwarf2Though the quality of debug info is harder to quantify; size is not a proxy for quality.
Jakub notes:
All [GCC] 5.1 - 6.x did was start accepting -gdwarf-5 as experimental option that enabled some small DWARF subset (initially only a few DW_LANG_* codes newly added to DWARF5 drafts). Only GCC 7 (released after DWARF 5 has been finalized) started emitting DWARF5 section headers and got most of the DWARF5 changes in...Version check GCC so that we don't need to worry about the difference in command line args between GNU readelf and llvm-readelf/llvm-dwarfdump to validate the DWARF Version in the assembler feature detection script.
Quoted 7 lines
Suggested-by Arvind Sankar <[email protected]>Suggested-by Jakub Jelinek <[email protected]>Suggested-by Masahiro Yamada <[email protected]>Suggested-by Fangrui Song <[email protected]>Suggested-by Caroline Tice <[email protected]>Signed-off-by Nick Desaulniers <[email protected]>
One small nit below.
Quoted 71 lines
--- Makefile | 1 + include/asm-generic/vmlinux.lds.h | 6 +++++- lib/Kconfig.debug | 17 +++++++++++++++++ scripts/test_dwarf5_support.sh | 9 +++++++++ 4 files changed, 32 insertions(+), 1 deletion(-) create mode 100755 scripts/test_dwarf5_support.shMakefile +1
-0@@ -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@@ -843,7 +843,11 @@ .debug_types 0 : { *(.debug_types) } \/* DWARF 5 */ \ .debug_macro 0 : { *(.debug_macro) } \ - .debug_addr 0 : { *(.debug_addr) } + .debug_addr 0 : { *(.debug_addr) } \ + .debug_line_str 0 : { *(.debug_line_str) } \ + .debug_loclists 0 : { *(.debug_loclists) } \ + .debug_rnglists 0 : { *(.debug_rnglists) } \ + .debug_str_offsets 0 : { *(.debug_str_offsets) }/* Stabs debugging sections. */ #define STABS_DEBUG \lib/Kconfig.debug +17
-0@@ -273,6 +273,23 @@ config DEBUG_INFO_DWARF4 It makes the debug information larger, but it significantly improves the success of resolving variables in gdb on optimized code. +config DEBUG_INFO_DWARF5 + bool "Generate DWARF Version 5 debuginfo" + depends on GCC_VERSION >= 50000 || CC_IS_CLANG + depends on CC_IS_GCC || $(success,$(srctree)/scripts/test_dwarf5_support.sh $(CC) $(CLANG_FLAGS)) + help + Generate DWARF v5 debug info. Requires binutils 2.35, gcc 5.0+ (gcc + 5.0+ accepts the -gdwarf-5 flag but only had partial support for some + draft features until 7.0), and gdb 8.0+. + + Changes to the structure of debug info in Version 5 allow for around + 15-18% savings in resulting image and debug info section sizes as + compared to DWARF Version 4. DWARF Version 5 standardizes previous + extensions such as accelerators for symbol indexing and the format + for fission (.dwo/.dwp) files. Users may not want to select this + config if they rely on tooling that has not yet been updated to + support DWARF Version 5. + endchoice # "DWARF version" config DEBUG_INFO_BTFscripts/test_dwarf5_support.sh new file +0
-0
scripts/test_dwarf5_support.sh line 8
Quoted 8 lines
scripts/test_dwarf5_support.sh new file +8
-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
This is unnecessary, clang will error without this and a script's exit code is the exit code of its last command.
Quoted 4 lines
scripts/test_dwarf5_support.sh new file +1
-0+echo '.file 0 "filename"' | $* -gdwarf-5 -Wa,-gdwarf-5 -c -x assembler -o /dev/null -Signature · 1 line
2.30.0.284.gd98b1dd5eaa7-goog