Skip to content

Commit 98cd6f5

Browse files
nickdesaulniersmasahir0y
authored andcommitted
Kconfig: allow explicit opt in to DWARF v5
DWARF v5 is the latest standard of the DWARF debug info format. GCC 11 will change the implicit default DWARF version, if left unspecified, to DWARF v5. Allow users of Clang and older versions of GCC that have not changed the implicit default DWARF version to DWARF v5 to opt in. This can help testing consumers of DWARF debug info in preparation of v5 becoming more widespread, as well as result in significant binary size savings of the pre-stripped vmlinux image. 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: 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. 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... 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) ... 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. 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. Most issues with clang produced assembler were fixed in binutils 2.35.1, but 2.35.2 fixed issues related to requiring the flag -Wa,-gdwarf-5 explicitly. The added shell script test checks for the latter, and is only required when using clang without its integrated assembler, though we use for clang regardless as we do not yet have a way to query the assembler from Kconfig. Disabled for now if CONFIG_DEBUG_INFO_BTF is set; pahole doesn't yet recognize the new additions to the DWARF debug info. This only modifies the DWARF version emitted by the compiler, not the assembler. The DWARF version of a binary can be validated with: $ llvm-dwarfdump <object file> | head -n 4 | grep version or $ readelf --debug-dump=info <object file> 2>/dev/null | grep Version Parts of the tree don't reuse DEBUG_CFLAGS as they should; such cleanup is left as a follow up. Link: http://www.dwarfstd.org/doc/DWARF5.pdf Link: https://bugzilla.redhat.com/show_bug.cgi?id=1922707 Reported-by: Sedat Dilek <[email protected]> Suggested-by: Arvind Sankar <[email protected]> Suggested-by: Caroline Tice <[email protected]> Suggested-by: Fangrui Song <[email protected]> Suggested-by: Jakub Jelinek <[email protected]> Suggested-by: Masahiro Yamada <[email protected]> Suggested-by: Nathan Chancellor <[email protected]> Signed-off-by: Nick Desaulniers <[email protected]> Tested-by: Sedat Dilek <[email protected]> # LLVM/Clang v12.0.0-rc1 x86-64 Signed-off-by: Masahiro Yamada <[email protected]>
1 parent a66049e commit 98cd6f5

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,7 @@ endif
832832

833833
ifndef CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT
834834
dwarf-version-$(CONFIG_DEBUG_INFO_DWARF4) := 4
835+
dwarf-version-$(CONFIG_DEBUG_INFO_DWARF5) := 5
835836
DEBUG_CFLAGS += -gdwarf-$(dwarf-version-y)
836837
endif
837838

lib/Kconfig.debug

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,24 @@ config DEBUG_INFO_DWARF4
282282
newer revisions of DWARF, you may wish to choose this or have your
283283
config select this.
284284

285+
config DEBUG_INFO_DWARF5
286+
bool "Generate DWARF Version 5 debuginfo"
287+
depends on GCC_VERSION >= 50000 || CC_IS_CLANG
288+
depends on CC_IS_GCC || $(success,$(srctree)/scripts/test_dwarf5_support.sh $(CC) $(CLANG_FLAGS))
289+
depends on !DEBUG_INFO_BTF
290+
help
291+
Generate DWARF v5 debug info. Requires binutils 2.35.2, gcc 5.0+ (gcc
292+
5.0+ accepts the -gdwarf-5 flag but only had partial support for some
293+
draft features until 7.0), and gdb 8.0+.
294+
295+
Changes to the structure of debug info in Version 5 allow for around
296+
15-18% savings in resulting image and debug info section sizes as
297+
compared to DWARF Version 4. DWARF Version 5 standardizes previous
298+
extensions such as accelerators for symbol indexing and the format
299+
for fission (.dwo/.dwp) files. Users may not want to select this
300+
config if they rely on tooling that has not yet been updated to
301+
support DWARF Version 5.
302+
285303
endchoice # "DWARF version"
286304

287305
config DEBUG_INFO_BTF

scripts/test_dwarf5_support.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
# SPDX-License-Identifier: GPL-2.0
3+
4+
# Test that the assembler doesn't need -Wa,-gdwarf-5 when presented with DWARF
5+
# v5 input, such as `.file 0` and `md5 0x00`. Should be fixed in GNU binutils
6+
# 2.35.2. https://sourceware.org/bugzilla/show_bug.cgi?id=25611
7+
echo '.file 0 "filename" md5 0x7a0b65214090b6693bd1dc24dd248245' | \
8+
$* -gdwarf-5 -Wno-unused-command-line-argument -c -x assembler -o /dev/null -

0 commit comments

Comments
 (0)