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

Nick Desaulniers
2020-12-03T23:23:23Z

On Tue, Nov 24, 2020 at 9:28 AM Arvind Sankar <nivedita@alum.mit.edu> wrote:
>
> On Tue, Nov 03, 2020 at 04:53:43PM -0800, Nick Desaulniers 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.
>
> 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.

>
> > /* 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"
> > + 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.

>
> >
> > config DEBUG_INFO_BTF
> > diff --git a/scripts/test_dwarf5_support.sh b/scripts/test_dwarf5_support.sh
> > new file mode 100755
> > index 000000000000..156ad5ec4274
> > --- /dev/null
> > +++ b/scripts/test_dwarf5_support.sh
> > @@ -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.

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.

--
Thanks,
~Nick Desaulniers