diff mbox series

[v2,4/5] Makefile.debug: re-enable debug info for .S files

Message ID 20220831184408.2778264-5-ndesaulniers@google.com (mailing list archive)
State New, archived
Headers show
Series fix debug info for asm and DEBUG_INFO_SPLIT | expand

Commit Message

Nick Desaulniers Aug. 31, 2022, 6:44 p.m. UTC
Alexey reported that the fraction of unknown filename instances in
kallsyms grew from ~0.3% to ~10% recently; Bill and Greg tracked it down
to assembler defined symbols, which regressed as a result of:

commit b8a9092330da ("Kbuild: do not emit debug info for assembly with LLVM_IAS=1")

In that commit, I allude to restoring debug info for assembler defined
symbols in a follow up patch, but it seems I forgot to do so in

commit a66049e2cf0e ("Kbuild: make DWARF version a choice")

This patch does a few things:
1. Add -g to KBUILD_AFLAGS. This will instruct the compiler to instruct
   the assembler to emit debug info. But this can cause an issue for
   folks using a newer compiler but older assembler, because the
   implicit default DWARF version changed from v4 to v5 in gcc-11 and
   clang-14.
2. If the user is using CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT, use a
   version check to explicitly set -Wa,-gdwarf-<version> for the
   assembler. There's another problem with this; GAS only gained support
   for explicit DWARF versions 3-5 in the 2.36 GNU binutils release.
3. Wrap -Wa,-gdwarf-<version> in as-option call to test whether the
   assembler supports that explicit DWARF version.

Link: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=31bf18645d98b4d3d7357353be840e320649a67d
Fixes: b8a9092330da ("Kbuild: do not emit debug info for assembly with LLVM_IAS=1")
Reported-by: Alexey Alexandrov <aalexand@google.com>
Reported-by: Bill Wendling <morbo@google.com>
Reported-by: Greg Thelen <gthelen@google.com>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
---
Changes v1 -> v2:
* Use newly added compiler-specific macros, as per Bill.

 scripts/Makefile.debug | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

Comments

Nathan Chancellor Aug. 31, 2022, 8:22 p.m. UTC | #1
On Wed, Aug 31, 2022 at 11:44:07AM -0700, Nick Desaulniers wrote:
> Alexey reported that the fraction of unknown filename instances in
> kallsyms grew from ~0.3% to ~10% recently; Bill and Greg tracked it down
> to assembler defined symbols, which regressed as a result of:
> 
> commit b8a9092330da ("Kbuild: do not emit debug info for assembly with LLVM_IAS=1")
> 
> In that commit, I allude to restoring debug info for assembler defined
> symbols in a follow up patch, but it seems I forgot to do so in
> 
> commit a66049e2cf0e ("Kbuild: make DWARF version a choice")
> 
> This patch does a few things:
> 1. Add -g to KBUILD_AFLAGS. This will instruct the compiler to instruct
>    the assembler to emit debug info. But this can cause an issue for
>    folks using a newer compiler but older assembler, because the
>    implicit default DWARF version changed from v4 to v5 in gcc-11 and
>    clang-14.
> 2. If the user is using CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT, use a
>    version check to explicitly set -Wa,-gdwarf-<version> for the
>    assembler. There's another problem with this; GAS only gained support
>    for explicit DWARF versions 3-5 in the 2.36 GNU binutils release.
> 3. Wrap -Wa,-gdwarf-<version> in as-option call to test whether the
>    assembler supports that explicit DWARF version.
> 
> Link: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=31bf18645d98b4d3d7357353be840e320649a67d
> Fixes: b8a9092330da ("Kbuild: do not emit debug info for assembly with LLVM_IAS=1")
> Reported-by: Alexey Alexandrov <aalexand@google.com>
> Reported-by: Bill Wendling <morbo@google.com>
> Reported-by: Greg Thelen <gthelen@google.com>
> Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>

Reviewed-by: Nathan Chancellor <nathan@kernel.org>

> ---
> Changes v1 -> v2:
> * Use newly added compiler-specific macros, as per Bill.
> 
>  scripts/Makefile.debug | 22 ++++++++++++++++++----
>  1 file changed, 18 insertions(+), 4 deletions(-)
> 
> diff --git a/scripts/Makefile.debug b/scripts/Makefile.debug
> index 9f39b0130551..46e88f0ca998 100644
> --- a/scripts/Makefile.debug
> +++ b/scripts/Makefile.debug
> @@ -4,18 +4,32 @@ ifdef CONFIG_DEBUG_INFO_SPLIT
>  DEBUG_CFLAGS	+= -gsplit-dwarf
>  else
>  DEBUG_CFLAGS	+= -g
> +KBUILD_AFLAGS	+= -g
>  endif
>  
> -ifndef CONFIG_AS_IS_LLVM
> -KBUILD_AFLAGS	+= -Wa,-gdwarf-2
> +ifdef CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT
> +# gcc-11+, clang-14+
> +ifeq ($(call cc-min-version, 110000, 140000),y)
> +dwarf-version-y := 5
> +else
> +dwarf-version-y := 4
>  endif
> -
> -ifndef CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT
> +else # !CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT
>  dwarf-version-$(CONFIG_DEBUG_INFO_DWARF4) := 4
>  dwarf-version-$(CONFIG_DEBUG_INFO_DWARF5) := 5
>  DEBUG_CFLAGS	+= -gdwarf-$(dwarf-version-y)
>  endif
>  
> +# Binutils 2.35+ (or clang) required for -gdwarf-{4|5}.
> +# https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=31bf18645d98b4d3d7357353be840e320649a67d
> +ifneq ($(call as-option,-Wa$(comma)-gdwarf-$(dwarf-version-y)),)
> +KBUILD_AFLAGS	+= -Wa,-gdwarf-$(dwarf-version-y)
> +else
> +ifndef CONFIG_AS_IS_LLVM
> +KBUILD_AFLAGS	+= -Wa,-gdwarf-2
> +endif
> +endif
> +
>  ifdef CONFIG_DEBUG_INFO_REDUCED
>  DEBUG_CFLAGS	+= -fno-var-tracking
>  ifdef CONFIG_CC_IS_GCC
> -- 
> 2.37.2.672.g94769d06f0-goog
>
Masahiro Yamada Sept. 5, 2022, 7:49 a.m. UTC | #2
On Thu, Sep 1, 2022 at 3:44 AM Nick Desaulniers <ndesaulniers@google.com> wrote:
>
> Alexey reported that the fraction of unknown filename instances in
> kallsyms grew from ~0.3% to ~10% recently; Bill and Greg tracked it down
> to assembler defined symbols, which regressed as a result of:
>
> commit b8a9092330da ("Kbuild: do not emit debug info for assembly with LLVM_IAS=1")
>
> In that commit, I allude to restoring debug info for assembler defined
> symbols in a follow up patch, but it seems I forgot to do so in
>
> commit a66049e2cf0e ("Kbuild: make DWARF version a choice")
>
> This patch does a few things:
> 1. Add -g to KBUILD_AFLAGS. This will instruct the compiler to instruct
>    the assembler to emit debug info. But this can cause an issue for
>    folks using a newer compiler but older assembler, because the
>    implicit default DWARF version changed from v4 to v5 in gcc-11 and
>    clang-14.



What kind of bad things happen for "KBUILD_AFLAGS += -g"?


I think 'gcc -g -c -o foo.o foo.S' will invoke 'as --gdwarf-2' as the backend
if gcc is configured to work with old binutils.




> diff --git a/scripts/Makefile.debug b/scripts/Makefile.debug
> index 9f39b0130551..46e88f0ca998 100644
> --- a/scripts/Makefile.debug
> +++ b/scripts/Makefile.debug
> @@ -4,18 +4,32 @@ ifdef CONFIG_DEBUG_INFO_SPLIT
>  DEBUG_CFLAGS   += -gsplit-dwarf
>  else
>  DEBUG_CFLAGS   += -g
> +KBUILD_AFLAGS  += -g
>  endif
>
> -ifndef CONFIG_AS_IS_LLVM
> -KBUILD_AFLAGS  += -Wa,-gdwarf-2
> +ifdef CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT
> +# gcc-11+, clang-14+
> +ifeq ($(call cc-min-version, 110000, 140000),y)
> +dwarf-version-y := 5
> +else
> +dwarf-version-y := 4



If you explicitly specify the DWARF version
for CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT,
what is the point of CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT?


When CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT=y,
I believe the right thing to do is to pass only -g,
and let the tool do whatever it thinks is appropriate.






>  endif
> -
> -ifndef CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT
> +else # !CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT
>  dwarf-version-$(CONFIG_DEBUG_INFO_DWARF4) := 4
>  dwarf-version-$(CONFIG_DEBUG_INFO_DWARF5) := 5
>  DEBUG_CFLAGS   += -gdwarf-$(dwarf-version-y)
>  endif
>
> +# Binutils 2.35+ (or clang) required for -gdwarf-{4|5}.
> +# https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=31bf18645d98b4d3d7357353be840e320649a67d
> +ifneq ($(call as-option,-Wa$(comma)-gdwarf-$(dwarf-version-y)),)



When is this as-option supposed to fail?


Binutils <= 2.34 always accepts whatever -gdwarf-* option.
Surprisingly or not, it accepts -gdwarf-6, -gdwarf-7, ...

No matter what DWARF version you specify, GAS silently downgrades
it to DWARF-2.


masahiro@zoe:~/tools/binutils-2.34/bin$ ./as --version | head -n 1
GNU assembler (GNU Binutils) 2.34
masahiro@zoe:~/tools/binutils-2.34/bin$ cat /dev/null | ./as -gdwarf-5
-o /dev/null -
masahiro@zoe:~/tools/binutils-2.34/bin$ echo $?
0
masahiro@zoe:~/tools/binutils-2.34/bin$ cat /dev/null | ./as
-gdwarf-100 -o /dev/null -
masahiro@zoe:~/tools/binutils-2.34/bin$ echo $?
0




Overall, I am not convinced with this patch.



Please see the attached patch.
Is there any problem with writing this more simply?





> +KBUILD_AFLAGS  += -Wa,-gdwarf-$(dwarf-version-y)
> +else
> +ifndef CONFIG_AS_IS_LLVM
> +KBUILD_AFLAGS  += -Wa,-gdwarf-2
> +endif
> +endif
> +
>  ifdef CONFIG_DEBUG_INFO_REDUCED
>  DEBUG_CFLAGS   += -fno-var-tracking
>  ifdef CONFIG_CC_IS_GCC
> --
> 2.37.2.672.g94769d06f0-goog
>


--
Best Regards
Masahiro Yamada
Nick Desaulniers Sept. 7, 2022, 4:27 a.m. UTC | #3
On Mon, Sep 5, 2022 at 12:50 AM Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> On Thu, Sep 1, 2022 at 3:44 AM Nick Desaulniers <ndesaulniers@google.com> wrote:
> >
> > Alexey reported that the fraction of unknown filename instances in
> > kallsyms grew from ~0.3% to ~10% recently; Bill and Greg tracked it down
> > to assembler defined symbols, which regressed as a result of:
> >
> > commit b8a9092330da ("Kbuild: do not emit debug info for assembly with LLVM_IAS=1")
> >
> > In that commit, I allude to restoring debug info for assembler defined
> > symbols in a follow up patch, but it seems I forgot to do so in
> >
> > commit a66049e2cf0e ("Kbuild: make DWARF version a choice")
> >
> > This patch does a few things:
> > 1. Add -g to KBUILD_AFLAGS. This will instruct the compiler to instruct
> >    the assembler to emit debug info. But this can cause an issue for
> >    folks using a newer compiler but older assembler, because the
> >    implicit default DWARF version changed from v4 to v5 in gcc-11 and
> >    clang-14.
>
>
>
> What kind of bad things happen for "KBUILD_AFLAGS += -g"?
>
>
> I think 'gcc -g -c -o foo.o foo.S' will invoke 'as --gdwarf-2' as the backend
> if gcc is configured to work with old binutils.

That's fine for CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT I think?

What other problems were you envisioning?

>
>
>
>
> > diff --git a/scripts/Makefile.debug b/scripts/Makefile.debug
> > index 9f39b0130551..46e88f0ca998 100644
> > --- a/scripts/Makefile.debug
> > +++ b/scripts/Makefile.debug
> > @@ -4,18 +4,32 @@ ifdef CONFIG_DEBUG_INFO_SPLIT
> >  DEBUG_CFLAGS   += -gsplit-dwarf
> >  else
> >  DEBUG_CFLAGS   += -g
> > +KBUILD_AFLAGS  += -g
> >  endif
> >
> > -ifndef CONFIG_AS_IS_LLVM
> > -KBUILD_AFLAGS  += -Wa,-gdwarf-2
> > +ifdef CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT
> > +# gcc-11+, clang-14+
> > +ifeq ($(call cc-min-version, 110000, 140000),y)
> > +dwarf-version-y := 5
> > +else
> > +dwarf-version-y := 4
>
>
>
> If you explicitly specify the DWARF version
> for CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT,
> what is the point of CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT?
>
>
> When CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT=y,
> I believe the right thing to do is to pass only -g,
> and let the tool do whatever it thinks is appropriate.

Ok, sure, I will revise.

>
>
>
>
>
>
> >  endif
> > -
> > -ifndef CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT
> > +else # !CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT
> >  dwarf-version-$(CONFIG_DEBUG_INFO_DWARF4) := 4
> >  dwarf-version-$(CONFIG_DEBUG_INFO_DWARF5) := 5
> >  DEBUG_CFLAGS   += -gdwarf-$(dwarf-version-y)
> >  endif
> >
> > +# Binutils 2.35+ (or clang) required for -gdwarf-{4|5}.
> > +# https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=31bf18645d98b4d3d7357353be840e320649a67d
> > +ifneq ($(call as-option,-Wa$(comma)-gdwarf-$(dwarf-version-y)),)
>
>
>
> When is this as-option supposed to fail?
>
>
> Binutils <= 2.34 always accepts whatever -gdwarf-* option.
> Surprisingly or not, it accepts -gdwarf-6, -gdwarf-7, ...
>
> No matter what DWARF version you specify, GAS silently downgrades
> it to DWARF-2.
>
>
> masahiro@zoe:~/tools/binutils-2.34/bin$ ./as --version | head -n 1
> GNU assembler (GNU Binutils) 2.34
> masahiro@zoe:~/tools/binutils-2.34/bin$ cat /dev/null | ./as -gdwarf-5
> -o /dev/null -
> masahiro@zoe:~/tools/binutils-2.34/bin$ echo $?
> 0
> masahiro@zoe:~/tools/binutils-2.34/bin$ cat /dev/null | ./as
> -gdwarf-100 -o /dev/null -
> masahiro@zoe:~/tools/binutils-2.34/bin$ echo $?
> 0

ah, right. Maybe an explicit version check is necessary then.

>
>
>
>
> Overall, I am not convinced with this patch.
>
>
>
> Please see the attached patch.
> Is there any problem with writing this more simply?


Thanks for the inspiration, I will use that as an inspiration/base for
a new patch.
diff mbox series

Patch

diff --git a/scripts/Makefile.debug b/scripts/Makefile.debug
index 9f39b0130551..46e88f0ca998 100644
--- a/scripts/Makefile.debug
+++ b/scripts/Makefile.debug
@@ -4,18 +4,32 @@  ifdef CONFIG_DEBUG_INFO_SPLIT
 DEBUG_CFLAGS	+= -gsplit-dwarf
 else
 DEBUG_CFLAGS	+= -g
+KBUILD_AFLAGS	+= -g
 endif
 
-ifndef CONFIG_AS_IS_LLVM
-KBUILD_AFLAGS	+= -Wa,-gdwarf-2
+ifdef CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT
+# gcc-11+, clang-14+
+ifeq ($(call cc-min-version, 110000, 140000),y)
+dwarf-version-y := 5
+else
+dwarf-version-y := 4
 endif
-
-ifndef CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT
+else # !CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT
 dwarf-version-$(CONFIG_DEBUG_INFO_DWARF4) := 4
 dwarf-version-$(CONFIG_DEBUG_INFO_DWARF5) := 5
 DEBUG_CFLAGS	+= -gdwarf-$(dwarf-version-y)
 endif
 
+# Binutils 2.35+ (or clang) required for -gdwarf-{4|5}.
+# https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=31bf18645d98b4d3d7357353be840e320649a67d
+ifneq ($(call as-option,-Wa$(comma)-gdwarf-$(dwarf-version-y)),)
+KBUILD_AFLAGS	+= -Wa,-gdwarf-$(dwarf-version-y)
+else
+ifndef CONFIG_AS_IS_LLVM
+KBUILD_AFLAGS	+= -Wa,-gdwarf-2
+endif
+endif
+
 ifdef CONFIG_DEBUG_INFO_REDUCED
 DEBUG_CFLAGS	+= -fno-var-tracking
 ifdef CONFIG_CC_IS_GCC