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

Masahiro Yamada
2020-12-01T01:58:15Z

On Wed, Nov 4, 2020 at 9:54 AM Nick Desaulniers <ndesaulniers@google.com> wrote:
>
> 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
>
> Link: http://www.dwarfstd.org/doc/DWARF5.pdf
> Suggested-by: Masahiro Yamada <masahiroy@kernel.org>
> Suggested-by: Jakub Jelinek <jakub@redhat.com>
> Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
> ---
> 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
>
> diff --git a/Makefile b/Makefile
> index e23786a4c1c7..9056bac0ff85 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -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.
> diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
> index b2b3d81b1535..76ce62c77029 100644
> --- a/include/asm-generic/vmlinux.lds.h
> +++ b/include/asm-generic/vmlinux.lds.h
> @@ -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 \
> diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
> index 03c494eefabd..c5b54ba51060 100644
> --- a/lib/Kconfig.debug
> +++ b/lib/Kconfig.debug
> @@ -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