All of lore.kernel.org
 help / color / mirror / Atom feed
From: Masahiro Yamada <masahiroy@kernel.org>
To: Nick Desaulniers <ndesaulniers@google.com>
Cc: Michal Marek <michal.lkml@markovi.net>,
	Nathan Chancellor <nathan@kernel.org>, Tom Rix <trix@redhat.com>,
	Linux Kbuild mailing list <linux-kbuild@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	clang-built-linux <llvm@lists.linux.dev>, X86 ML <x86@kernel.org>,
	Dmitrii Bundin <dmitrii.bundin.a@gmail.com>,
	Fangrui Song <maskray@google.com>,
	Alexey Alexandrov <aalexand@google.com>,
	Bill Wendling <morbo@google.com>,
	Greg Thelen <gthelen@google.com>
Subject: Re: [PATCH v2 4/5] Makefile.debug: re-enable debug info for .S files
Date: Mon, 5 Sep 2022 16:49:09 +0900	[thread overview]
Message-ID: <CAK7LNATWDH01=ZKLnsxc0vcib1zGDbEq8jLQwhWP7HkkmSb_Mw@mail.gmail.com> (raw)
In-Reply-To: <20220831184408.2778264-5-ndesaulniers@google.com>

[-- Attachment #1: Type: text/plain, Size: 3584 bytes --]

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

[-- Attachment #2: dwarf.diff --]
[-- Type: text/x-patch, Size: 1487 bytes --]

diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index bcbe60d6c80c..37aa19f0f7b0 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -264,6 +264,7 @@ config DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT
 config DEBUG_INFO_DWARF4
 	bool "Generate DWARF Version 4 debuginfo"
 	select DEBUG_INFO
+	depends on !CC_IS_CLANG || (CC_IS_CLANG && (AS_IS_LLVM || (AS_IS_GNU && AS_VERSION >= 23500)))
 	help
 	  Generate DWARF v4 debug info. This requires gcc 4.5+ and gdb 7.0+.
 
diff --git a/scripts/Makefile.debug b/scripts/Makefile.debug
index 9f39b0130551..c5ecb882a638 100644
--- a/scripts/Makefile.debug
+++ b/scripts/Makefile.debug
@@ -3,17 +3,20 @@ DEBUG_CFLAGS	:=
 ifdef CONFIG_DEBUG_INFO_SPLIT
 DEBUG_CFLAGS	+= -gsplit-dwarf
 else
-DEBUG_CFLAGS	+= -g
+debug-flags-y	+= -g
 endif
 
-ifndef CONFIG_AS_IS_LLVM
-KBUILD_AFLAGS	+= -Wa,-gdwarf-2
-endif
+debug-flags-$(CONFIG_DEBUG_INFO_DWARF4) += -gdwarf-4
+debug-flags-$(CONFIG_DEBUG_INFO_DWARF5) += -gdwarf-5
+
+DEBUG_CFLAGS	+= $(debug-flags-y)
 
-ifndef 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)
+ifeq ($(CONFIG_CC_IS_CLANG)$(CONFIG_AS_IS_GNU),yy)
+# Clang does not pass -g or -gdwarf-* option down to GAS.
+# Add -Wa, prefix to explicitly specify the flags.
+KBUILD_AFLAGS	+= $(addprefix -Wa$(comma), $(debug-flags-y))
+else
+KBUILD_AFLAGS	+= $(debug-flags-y)
 endif
 
 ifdef CONFIG_DEBUG_INFO_REDUCED

  parent reply	other threads:[~2022-09-05  7:50 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-31 18:44 [PATCH v2 0/5] fix debug info for asm and DEBUG_INFO_SPLIT Nick Desaulniers
2022-08-31 18:44 ` [PATCH v2 1/5] x86/boot/compressed: prefer cc-option for CFLAGS additions Nick Desaulniers
2022-08-31 19:41   ` Nathan Chancellor
2022-08-31 18:44 ` [PATCH v2 2/5] Makefile.compiler: Use KBUILD_AFLAGS for as-option Nick Desaulniers
2022-08-31 19:53   ` Nathan Chancellor
2022-09-05  9:09     ` Masahiro Yamada
2022-09-06 16:08       ` Nathan Chancellor
2022-09-07  4:14         ` Masahiro Yamada
2022-09-07  3:12       ` Nick Desaulniers
2022-09-07  4:27         ` Masahiro Yamada
2022-08-31 18:44 ` [PATCH v2 3/5] Makefile.compiler: replace cc-ifversion with compiler-specific macros Nick Desaulniers
2022-08-31 18:44   ` Nick Desaulniers
2022-08-31 20:08   ` Nathan Chancellor
2022-08-31 20:08     ` Nathan Chancellor
2022-09-05  6:44   ` Masahiro Yamada
2022-09-05  6:44     ` Masahiro Yamada
2022-08-31 18:44 ` [PATCH v2 4/5] Makefile.debug: re-enable debug info for .S files Nick Desaulniers
2022-08-31 20:22   ` Nathan Chancellor
2022-09-05  7:49   ` Masahiro Yamada [this message]
2022-09-07  4:27     ` Nick Desaulniers
2022-08-31 18:44 ` [PATCH v2 5/5] Makefile.debug: set -g unconditional on CONFIG_DEBUG_INFO_SPLIT Nick Desaulniers
2022-08-31 20:23   ` Nathan Chancellor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAK7LNATWDH01=ZKLnsxc0vcib1zGDbEq8jLQwhWP7HkkmSb_Mw@mail.gmail.com' \
    --to=masahiroy@kernel.org \
    --cc=aalexand@google.com \
    --cc=dmitrii.bundin.a@gmail.com \
    --cc=gthelen@google.com \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=maskray@google.com \
    --cc=michal.lkml@markovi.net \
    --cc=morbo@google.com \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=trix@redhat.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.