Message ID | 20210113003235.716547-3-ndesaulniers@google.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Kbuild: DWARF v5 support | expand |
On Tue, Jan 12, 2021 at 04:32:34PM -0800, Nick Desaulniers wrote: > Modifies CONFIG_DEBUG_INFO_DWARF4 to be a member of a choice. Adds an > explicit CONFIG_DEBUG_INFO_DWARF2, which is the default. Does so in a > way that's forward compatible with existing configs, and makes adding > future versions more straightforward. > > Suggested-by: Fangrui Song <maskray@google.com> > Suggested-by: Masahiro Yamada <masahiroy@kernel.org> > Signed-off-by: Nick Desaulniers <ndesaulniers@google.com> Reviewed-by: Nathan Chancellor <natechancellor@gmail.com> > --- > Makefile | 14 +++++++++----- > lib/Kconfig.debug | 21 ++++++++++++++++----- > 2 files changed, 25 insertions(+), 10 deletions(-) > > diff --git a/Makefile b/Makefile > index d49c3f39ceb4..656fff17b331 100644 > --- a/Makefile > +++ b/Makefile > @@ -826,12 +826,16 @@ else > DEBUG_CFLAGS += -g > endif > > -ifneq ($(LLVM_IAS),1) > -KBUILD_AFLAGS += -Wa,-gdwarf-2 > +dwarf-version-$(CONFIG_DEBUG_INFO_DWARF2) := 2 > +dwarf-version-$(CONFIG_DEBUG_INFO_DWARF4) := 4 > +DEBUG_CFLAGS += -gdwarf-$(dwarf-version-y) > +ifneq ($(dwarf-version-y)$(LLVM_IAS),21) > +# Binutils 2.35+ required for -gdwarf-4+ support. > +dwarf-aflag := $(call as-option,-Wa$(comma)-gdwarf-$(dwarf-version-y)) > +ifdef CONFIG_CC_IS_CLANG > +DEBUG_CFLAGS += $(dwarf-aflag) > endif > - > -ifdef CONFIG_DEBUG_INFO_DWARF4 > -DEBUG_CFLAGS += -gdwarf-4 > +KBUILD_AFLAGS += $(dwarf-aflag) > endif > > ifdef CONFIG_DEBUG_INFO_REDUCED > diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug > index dd7d8d35b2a5..e80770fac4f0 100644 > --- a/lib/Kconfig.debug > +++ b/lib/Kconfig.debug > @@ -256,13 +256,24 @@ config DEBUG_INFO_SPLIT > to know about the .dwo files and include them. > Incompatible with older versions of ccache. > > +choice > + prompt "DWARF version" > + help > + Which version of DWARF debug info to emit. > + > +config DEBUG_INFO_DWARF2 > + bool "Generate DWARF Version 2 debuginfo" > + help > + Generate DWARF v2 debug info. > + > config DEBUG_INFO_DWARF4 > - bool "Generate dwarf4 debuginfo" > + bool "Generate DWARF Version 4 debuginfo" > help > - Generate dwarf4 debug info. This requires recent versions > - of gcc and gdb. It makes the debug information larger. > - But it significantly improves the success of resolving > - variables in gdb on optimized code. > + Generate DWARF v4 debug info. This requires gcc 4.5+ and gdb 7.0+. > + It makes the debug information larger, but it significantly > + improves the success of resolving variables in gdb on optimized code. > + > +endchoice # "DWARF version" > > config DEBUG_INFO_BTF > bool "Generate BTF typeinfo" > -- > 2.30.0.284.gd98b1dd5eaa7-goog >
On Wed, Jan 13, 2021 at 1:32 AM Nick Desaulniers <ndesaulniers@google.com> wrote: > > Modifies CONFIG_DEBUG_INFO_DWARF4 to be a member of a choice. Adds an > explicit CONFIG_DEBUG_INFO_DWARF2, which is the default. Does so in a > way that's forward compatible with existing configs, and makes adding > future versions more straightforward. > > Suggested-by: Fangrui Song <maskray@google.com> > Suggested-by: Masahiro Yamada <masahiroy@kernel.org> > Signed-off-by: Nick Desaulniers <ndesaulniers@google.com> > --- > Makefile | 14 +++++++++----- > lib/Kconfig.debug | 21 ++++++++++++++++----- > 2 files changed, 25 insertions(+), 10 deletions(-) > > diff --git a/Makefile b/Makefile > index d49c3f39ceb4..656fff17b331 100644 > --- a/Makefile > +++ b/Makefile > @@ -826,12 +826,16 @@ else > DEBUG_CFLAGS += -g > endif > > -ifneq ($(LLVM_IAS),1) > -KBUILD_AFLAGS += -Wa,-gdwarf-2 > +dwarf-version-$(CONFIG_DEBUG_INFO_DWARF2) := 2 > +dwarf-version-$(CONFIG_DEBUG_INFO_DWARF4) := 4 > +DEBUG_CFLAGS += -gdwarf-$(dwarf-version-y) > +ifneq ($(dwarf-version-y)$(LLVM_IAS),21) > +# Binutils 2.35+ required for -gdwarf-4+ support. > +dwarf-aflag := $(call as-option,-Wa$(comma)-gdwarf-$(dwarf-version-y)) > +ifdef CONFIG_CC_IS_CLANG > +DEBUG_CFLAGS += $(dwarf-aflag) > endif Why is that "ifdef CONFIG_CC_IS_CLANG"? When I use GCC v10.2.1 DEBUG_CFLAGS are not set. - Sedat - > - > -ifdef CONFIG_DEBUG_INFO_DWARF4 > -DEBUG_CFLAGS += -gdwarf-4 > +KBUILD_AFLAGS += $(dwarf-aflag) > endif > > ifdef CONFIG_DEBUG_INFO_REDUCED > diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug > index dd7d8d35b2a5..e80770fac4f0 100644 > --- a/lib/Kconfig.debug > +++ b/lib/Kconfig.debug > @@ -256,13 +256,24 @@ config DEBUG_INFO_SPLIT > to know about the .dwo files and include them. > Incompatible with older versions of ccache. > > +choice > + prompt "DWARF version" > + help > + Which version of DWARF debug info to emit. > + > +config DEBUG_INFO_DWARF2 > + bool "Generate DWARF Version 2 debuginfo" > + help > + Generate DWARF v2 debug info. > + > config DEBUG_INFO_DWARF4 > - bool "Generate dwarf4 debuginfo" > + bool "Generate DWARF Version 4 debuginfo" > help > - Generate dwarf4 debug info. This requires recent versions > - of gcc and gdb. It makes the debug information larger. > - But it significantly improves the success of resolving > - variables in gdb on optimized code. > + Generate DWARF v4 debug info. This requires gcc 4.5+ and gdb 7.0+. > + It makes the debug information larger, but it significantly > + improves the success of resolving variables in gdb on optimized code. > + > +endchoice # "DWARF version" > > config DEBUG_INFO_BTF > bool "Generate BTF typeinfo" > -- > 2.30.0.284.gd98b1dd5eaa7-goog >
Sedat, Thanks for testing, and congrats on https://lwn.net/Articles/839772/. I always appreciate you taking the time to help test my work, and other Clang+Linux kernel patches! On Wed, Jan 13, 2021 at 1:24 PM Sedat Dilek <sedat.dilek@gmail.com> wrote: > > On Wed, Jan 13, 2021 at 1:32 AM Nick Desaulniers > <ndesaulniers@google.com> wrote: > > > > --- a/Makefile > > +++ b/Makefile > > @@ -826,12 +826,16 @@ else > > DEBUG_CFLAGS += -g > > endif > > > > -ifneq ($(LLVM_IAS),1) > > -KBUILD_AFLAGS += -Wa,-gdwarf-2 > > +dwarf-version-$(CONFIG_DEBUG_INFO_DWARF2) := 2 > > +dwarf-version-$(CONFIG_DEBUG_INFO_DWARF4) := 4 > > +DEBUG_CFLAGS += -gdwarf-$(dwarf-version-y) ^ DEBUG_CFLAGS are set for everyone (all toolchains) if CONFIG_DEBUG_INFO is defined. > > +ifneq ($(dwarf-version-y)$(LLVM_IAS),21) ^ "If not using dwarf 2 and LLVM_IAS=1", ie. CONFIG_DEBUG_INFO_DWARF5 && CONFIG_CC_IS_GCC > > +# Binutils 2.35+ required for -gdwarf-4+ support. > > +dwarf-aflag := $(call as-option,-Wa$(comma)-gdwarf-$(dwarf-version-y)) > > +ifdef CONFIG_CC_IS_CLANG ^ "if clang" > > +DEBUG_CFLAGS += $(dwarf-aflag) > > endif > > Why is that "ifdef CONFIG_CC_IS_CLANG"? That's what Arvind requested on v2, IIUC: https://lore.kernel.org/lkml/X8psgMuL4jMjP%2FOy@rani.riverdale.lan/ > When I use GCC v10.2.1 DEBUG_CFLAGS are not set. You should have -gdwarf-4 (and not -Wa,-gwarf-4) set for DEBUG_CFLAGS when compiling with GCC and enabling CONFIG_DEBUG_INFO_DWARF4. Can you please confirm? (Perhaps you may have accidentally disabled CONFIG_DEBUG_INFO by rerunning `make defconfig`?)
On Thu, Jan 14, 2021 at 12:27 AM Nick Desaulniers <ndesaulniers@google.com> wrote: > > Sedat, > Thanks for testing, and congrats on https://lwn.net/Articles/839772/. > I always appreciate you taking the time to help test my work, and > other Clang+Linux kernel patches! > Hi Nick, cool, again in the top 15 :-). I should ask Mr. Corbet for a LWN subscription. > On Wed, Jan 13, 2021 at 1:24 PM Sedat Dilek <sedat.dilek@gmail.com> wrote: > > > > On Wed, Jan 13, 2021 at 1:32 AM Nick Desaulniers > > <ndesaulniers@google.com> wrote: > > > > > > --- a/Makefile > > > +++ b/Makefile > > > @@ -826,12 +826,16 @@ else > > > DEBUG_CFLAGS += -g > > > endif > > > > > > -ifneq ($(LLVM_IAS),1) > > > -KBUILD_AFLAGS += -Wa,-gdwarf-2 > > > +dwarf-version-$(CONFIG_DEBUG_INFO_DWARF2) := 2 > > > +dwarf-version-$(CONFIG_DEBUG_INFO_DWARF4) := 4 > > > +DEBUG_CFLAGS += -gdwarf-$(dwarf-version-y) > > ^ DEBUG_CFLAGS are set for everyone (all toolchains) if > CONFIG_DEBUG_INFO is defined. > > > > +ifneq ($(dwarf-version-y)$(LLVM_IAS),21) > > ^ "If not using dwarf 2 and LLVM_IAS=1", ie. CONFIG_DEBUG_INFO_DWARF5 > && CONFIG_CC_IS_GCC > OK, I know DWARF v2 and LLVM_IAS=1 is broken. Looks like DWARF v5 with GCC v10.2.1 and binutils v2.35.1 is currently (here) no good choice. > > > +# Binutils 2.35+ required for -gdwarf-4+ support. > > > +dwarf-aflag := $(call as-option,-Wa$(comma)-gdwarf-$(dwarf-version-y)) > > > +ifdef CONFIG_CC_IS_CLANG > > ^ "if clang" > > > > +DEBUG_CFLAGS += $(dwarf-aflag) > > > endif > > > > Why is that "ifdef CONFIG_CC_IS_CLANG"? > > That's what Arvind requested on v2, IIUC: > https://lore.kernel.org/lkml/X8psgMuL4jMjP%2FOy@rani.riverdale.lan/ > > > When I use GCC v10.2.1 DEBUG_CFLAGS are not set. > > You should have -gdwarf-4 (and not -Wa,-gwarf-4) set for DEBUG_CFLAGS > when compiling with GCC and enabling CONFIG_DEBUG_INFO_DWARF4. Can you > please confirm? (Perhaps you may have accidentally disabled > CONFIG_DEBUG_INFO by rerunning `make defconfig`?) > $ egrep 'CC_IS_|LD_IS|BTF|DWARF' config-5.11.0-rc3-5-amd64-gcc10-llvm11 | grep ^CONFIG CONFIG_CC_IS_GCC=y CONFIG_LD_IS_LLD=y CONFIG_DEBUG_INFO_DWARF4=y CONFIG_DEBUG_INFO_BTF=y CONFIG_DEBUG_INFO_BTF_MODULES=y $ grep '\-Wa,-gdwarf-4' build-log_5.11.0-rc3-5-amd64-gcc10-llvm11.txt | wc -l 156
On Thu, Jan 14, 2021 at 8:20 AM Sedat Dilek <sedat.dilek@gmail.com> wrote: > > On Thu, Jan 14, 2021 at 12:27 AM Nick Desaulniers > <ndesaulniers@google.com> wrote: > > > > Sedat, > > Thanks for testing, and congrats on https://lwn.net/Articles/839772/. > > I always appreciate you taking the time to help test my work, and > > other Clang+Linux kernel patches! > > > > Hi Nick, > > cool, again in the top 15 :-). > > I should ask Mr. Corbet for a LWN subscription. > > > On Wed, Jan 13, 2021 at 1:24 PM Sedat Dilek <sedat.dilek@gmail.com> wrote: > > > > > > On Wed, Jan 13, 2021 at 1:32 AM Nick Desaulniers > > > <ndesaulniers@google.com> wrote: > > > > > > > > --- a/Makefile > > > > +++ b/Makefile > > > > @@ -826,12 +826,16 @@ else > > > > DEBUG_CFLAGS += -g > > > > endif > > > > > > > > -ifneq ($(LLVM_IAS),1) > > > > -KBUILD_AFLAGS += -Wa,-gdwarf-2 > > > > +dwarf-version-$(CONFIG_DEBUG_INFO_DWARF2) := 2 > > > > +dwarf-version-$(CONFIG_DEBUG_INFO_DWARF4) := 4 > > > > +DEBUG_CFLAGS += -gdwarf-$(dwarf-version-y) > > > > ^ DEBUG_CFLAGS are set for everyone (all toolchains) if > > CONFIG_DEBUG_INFO is defined. > > > > > > +ifneq ($(dwarf-version-y)$(LLVM_IAS),21) > > > > ^ "If not using dwarf 2 and LLVM_IAS=1", ie. CONFIG_DEBUG_INFO_DWARF5 > > && CONFIG_CC_IS_GCC > > > > OK, I know DWARF v2 and LLVM_IAS=1 is broken. > > Looks like DWARF v5 with GCC v10.2.1 and binutils v2.35.1 is currently > (here) no good choice. > > > > > +# Binutils 2.35+ required for -gdwarf-4+ support. > > > > +dwarf-aflag := $(call as-option,-Wa$(comma)-gdwarf-$(dwarf-version-y)) > > > > +ifdef CONFIG_CC_IS_CLANG > > > > ^ "if clang" > > > > > > +DEBUG_CFLAGS += $(dwarf-aflag) > > > > endif > > > > > > Why is that "ifdef CONFIG_CC_IS_CLANG"? > > > > That's what Arvind requested on v2, IIUC: > > https://lore.kernel.org/lkml/X8psgMuL4jMjP%2FOy@rani.riverdale.lan/ > > > > > When I use GCC v10.2.1 DEBUG_CFLAGS are not set. > > > > You should have -gdwarf-4 (and not -Wa,-gwarf-4) set for DEBUG_CFLAGS > > when compiling with GCC and enabling CONFIG_DEBUG_INFO_DWARF4. Can you > > please confirm? (Perhaps you may have accidentally disabled > > CONFIG_DEBUG_INFO by rerunning `make defconfig`?) > > > > $ egrep 'CC_IS_|LD_IS|BTF|DWARF' > config-5.11.0-rc3-5-amd64-gcc10-llvm11 | grep ^CONFIG > CONFIG_CC_IS_GCC=y > CONFIG_LD_IS_LLD=y > CONFIG_DEBUG_INFO_DWARF4=y > CONFIG_DEBUG_INFO_BTF=y > CONFIG_DEBUG_INFO_BTF_MODULES=y > > $ grep '\-Wa,-gdwarf-4' build-log_5.11.0-rc3-5-amd64-gcc10-llvm11.txt > | wc -l > 156 I wonder why I see GNU/as here (see above CONFIG_LD_IS_LLD=y)? $ llvm-dwarfdump-11 vmlinux | head -20 | egrep 'debug_info|format|version|DW_AT_producer' vmlinux: file format elf64-x86-64 .debug_info contents: 0x00000000: Compile Unit: length = 0x0000001e, format = DWARF32, version = 0x0004, abbr_offset = 0x0000, addr_size = 0x08 (next unit at 0x00000022) DW_AT_producer ("GNU AS 2.35.1") 0x00000022: Compile Unit: length = 0x0000c1d2, format = DWARF32, version = 0x0004, abbr_offset = 0x0012, addr_size = 0x08 (next unit at 0x0000c1f8) DW_AT_producer ("GNU C89 10.2.1 20210110 -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -m64 -mno-80387 -mno-fp-ret-in-387 -mpreferred-stack-boundary =3 -mskip-rax-setup -mtune=generic -mno-red-zone -mcmodel=kernel -mindirect-branch=thunk-extern -mindirect-branch-register -mrecord-mcount -mfentry -march=x86-64 -g -g dwarf-4 -O2 -std=gnu90 -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE -falign-jumps=1 -falign-loops=1 -fno-asynchronous-unwind-tables -fno-jump-tables -fno-de lete-null-pointer-checks -fno-allow-store-data-races -fstack-protector-strong -fno-strict-overflow -fstack-check=no -fconserve-stack -fcf-protection=none -fno-stack-pr otector") Maybe, I should set all LLVM utils and linker manually, not using LLVM=1. - Sedat -
On Thu, Jan 14, 2021 at 8:27 AM Nick Desaulniers <ndesaulniers@google.com> wrote: > > Sedat, > Thanks for testing, and congrats on https://lwn.net/Articles/839772/. > I always appreciate you taking the time to help test my work, and > other Clang+Linux kernel patches! > > On Wed, Jan 13, 2021 at 1:24 PM Sedat Dilek <sedat.dilek@gmail.com> wrote: > > > > On Wed, Jan 13, 2021 at 1:32 AM Nick Desaulniers > > <ndesaulniers@google.com> wrote: > > > > > > --- a/Makefile > > > +++ b/Makefile > > > @@ -826,12 +826,16 @@ else > > > DEBUG_CFLAGS += -g > > > endif > > > > > > -ifneq ($(LLVM_IAS),1) > > > -KBUILD_AFLAGS += -Wa,-gdwarf-2 > > > +dwarf-version-$(CONFIG_DEBUG_INFO_DWARF2) := 2 > > > +dwarf-version-$(CONFIG_DEBUG_INFO_DWARF4) := 4 > > > +DEBUG_CFLAGS += -gdwarf-$(dwarf-version-y) > > ^ DEBUG_CFLAGS are set for everyone (all toolchains) if > CONFIG_DEBUG_INFO is defined. > > > > +ifneq ($(dwarf-version-y)$(LLVM_IAS),21) > > ^ "If not using dwarf 2 and LLVM_IAS=1", ie. CONFIG_DEBUG_INFO_DWARF5 > && CONFIG_CC_IS_GCC > > > > +# Binutils 2.35+ required for -gdwarf-4+ support. > > > +dwarf-aflag := $(call as-option,-Wa$(comma)-gdwarf-$(dwarf-version-y)) > > > +ifdef CONFIG_CC_IS_CLANG > > ^ "if clang" > > > > +DEBUG_CFLAGS += $(dwarf-aflag) > > > endif > > > > Why is that "ifdef CONFIG_CC_IS_CLANG"? > > That's what Arvind requested on v2, IIUC: > https://lore.kernel.org/lkml/X8psgMuL4jMjP%2FOy@rani.riverdale.lan/ If CONFIG_CC_IS_CLANG is set, both -gdwarf and -Wa,-gdwarf-4 are passed to DEBUG_CFLAGS. Is it necessary? IIUC, -Wa,-gdwarf is meaningless when you build *.c files. I passed -v option to see how gas is invoked behind the scene. See the following results for [1] GCC + GAS and [2] Clang + GAS cases [1] GCC + GAS masahiro@grover:~$ cat test.c int main(void) { return 0; } masahiro@grover:~$ gcc -v -gdwarf-4 -c -o test.o test.c Using built-in specs. COLLECT_GCC=gcc OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa:hsa OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu 10.2.0-13ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-10/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-10 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-10-JvwpWM/gcc-10-10.2.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-10-JvwpWM/gcc-10-10.2.0/debian/tmp-gcn/usr,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 10.2.0 (Ubuntu 10.2.0-13ubuntu1) COLLECT_GCC_OPTIONS='-v' '-gdwarf-4' '-c' '-o' 'test.o' '-mtune=generic' '-march=x86-64' /usr/lib/gcc/x86_64-linux-gnu/10/cc1 -quiet -v -imultiarch x86_64-linux-gnu test.c -quiet -dumpbase test.c -mtune=generic -march=x86-64 -auxbase-strip test.o -gdwarf-4 -version -fasynchronous-unwind-tables -fstack-protector-strong -Wformat -Wformat-security -fstack-clash-protection -fcf-protection -o /tmp/cc4hKJeo.s GNU C17 (Ubuntu 10.2.0-13ubuntu1) version 10.2.0 (x86_64-linux-gnu) compiled by GNU C version 10.2.0, GMP version 6.2.0, MPFR version 4.1.0, MPC version 1.2.0-rc1, isl version isl-0.22.1-GMP GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu" ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/10/include-fixed" ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/10/../../../../x86_64-linux-gnu/include" #include "..." search starts here: #include <...> search starts here: /usr/lib/gcc/x86_64-linux-gnu/10/include /usr/local/include /usr/include/x86_64-linux-gnu /usr/include End of search list. GNU C17 (Ubuntu 10.2.0-13ubuntu1) version 10.2.0 (x86_64-linux-gnu) compiled by GNU C version 10.2.0, GMP version 6.2.0, MPFR version 4.1.0, MPC version 1.2.0-rc1, isl version isl-0.22.1-GMP GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: 4831429547eb0be4fec215fca56ed5cf COLLECT_GCC_OPTIONS='-v' '-gdwarf-4' '-c' '-o' 'test.o' '-mtune=generic' '-march=x86-64' as -v --64 -o test.o /tmp/cc4hKJeo.s GNU assembler version 2.35.1 (x86_64-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.35.1 COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/10/:/usr/lib/gcc/x86_64-linux-gnu/10/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/10/:/usr/lib/gcc/x86_64-linux-gnu/ LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/10/:/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/10/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/10/../../../:/lib/:/usr/lib/ COLLECT_GCC_OPTIONS='-v' '-gdwarf-4' '-c' '-o' 'test.o' '-mtune=generic' '-march=x86-64' masahiro@grover:~$ readelf --debug-dump=info test.o Contents of the .debug_info section: Compilation Unit @ offset 0x0: Length: 0x4f (32-bit) Version: 4 Abbrev Offset: 0x0 Pointer Size: 8 <0><b>: Abbrev Number: 1 (DW_TAG_compile_unit) <c> DW_AT_producer : (indirect string, offset: 0x16): GNU C17 10.2.0 -mtune=generic -march=x86-64 -gdwarf-4 -fasynchronous-unwind-tables -fstack-protector-strong -fstack-clash-protection -fcf-protection <10> DW_AT_language : 12 (ANSI C99) <11> DW_AT_name : (indirect string, offset: 0xf): test.c <15> DW_AT_comp_dir : (indirect string, offset: 0x0): /home/masahiro <19> DW_AT_low_pc : 0x0 <21> DW_AT_high_pc : 0xf <29> DW_AT_stmt_list : 0x0 <1><2d>: Abbrev Number: 2 (DW_TAG_subprogram) <2e> DW_AT_external : 1 <2e> DW_AT_name : (indirect string, offset: 0xab): main <32> DW_AT_decl_file : 1 <33> DW_AT_decl_line : 1 <34> DW_AT_decl_column : 5 <35> DW_AT_prototyped : 1 <35> DW_AT_type : <0x4b> <39> DW_AT_low_pc : 0x0 <41> DW_AT_high_pc : 0xf <49> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa) <4b> DW_AT_GNU_all_call_sites: 1 <1><4b>: Abbrev Number: 3 (DW_TAG_base_type) <4c> DW_AT_byte_size : 4 <4d> DW_AT_encoding : 5 (signed) <4e> DW_AT_name : int <1><52>: Abbrev Number: 0 [2] Clang + GAS masahiro@grover:~$ clang -v -fno-integrated-as -gdwarf-4 -c -o test.o test.c Ubuntu clang version 11.0.0-2 Target: x86_64-pc-linux-gnu Thread model: posix InstalledDir: /usr/bin Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/10 Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/8 Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/9 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9 Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/10 Candidate multilib: .;@m64 Selected multilib: .;@m64 "/usr/lib/llvm-11/bin/clang" -cc1 -triple x86_64-pc-linux-gnu -S -disable-free -disable-llvm-verifier -discard-value-names -main-file-name test.c -mrelocation-model static -mframe-pointer=all -fmath-errno -fno-rounding-math -no-integrated-as -mconstructor-aliases -munwind-tables -target-cpu x86-64 -fno-split-dwarf-inlining -debug-info-kind=limited -dwarf-version=4 -debugger-tuning=gdb -v -resource-dir /usr/lib/llvm-11/lib/clang/11.0.0 -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-11/lib/clang/11.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fno-dwarf-directory-asm -fdebug-compilation-dir /home/masahiro -ferror-limit 19 -fgnuc-version=4.2.1 -fcolor-diagnostics -o /tmp/test-f43580.s -x c test.c clang -cc1 version 11.0.0 based upon LLVM 11.0.0 default target x86_64-pc-linux-gnu ignoring nonexistent directory "/include" #include "..." search starts here: #include <...> search starts here: /usr/local/include /usr/lib/llvm-11/lib/clang/11.0.0/include /usr/include/x86_64-linux-gnu /usr/include End of search list. "/usr/bin/as" --64 -o test.o /tmp/test-f43580.s masahiro@grover:~$ readelf --debug-dump=info test.o Contents of the .debug_info section: Compilation Unit @ offset 0x0: Length: 0x47 (32-bit) Version: 4 Abbrev Offset: 0x0 Pointer Size: 8 <0><b>: Abbrev Number: 1 (DW_TAG_compile_unit) <c> DW_AT_producer : (indirect string, offset: 0x0): Ubuntu clang version 11.0.0-2 <10> DW_AT_language : 12 (ANSI C99) <12> DW_AT_name : (indirect string, offset: 0x1e): test.c <16> DW_AT_stmt_list : 0x0 <1a> DW_AT_comp_dir : (indirect string, offset: 0x25): /home/masahiro <1e> DW_AT_low_pc : 0x0 <26> DW_AT_high_pc : 0xf <1><2a>: Abbrev Number: 2 (DW_TAG_subprogram) <2b> DW_AT_low_pc : 0x0 <33> DW_AT_high_pc : 0xf <37> DW_AT_frame_base : 1 byte block: 56 (DW_OP_reg6 (rbp)) <39> DW_AT_name : (indirect string, offset: 0x34): main <3d> DW_AT_decl_file : 1 <3e> DW_AT_decl_line : 1 <3f> DW_AT_prototyped : 1 <3f> DW_AT_type : <0x43> <43> DW_AT_external : 1 <1><43>: Abbrev Number: 3 (DW_TAG_base_type) <44> DW_AT_name : (indirect string, offset: 0x39): int <48> DW_AT_encoding : 5 (signed) <49> DW_AT_byte_size : 4 <1><4a>: Abbrev Number: 0 In [1], "as -v --64 -o test.o /tmp/cc4hKJeo.s" is the command that invoked gas. There is no -gdwarf-4 option passed to gas here, but the produced object has the correct dwarf4 info. In [2], "/usr/bin/as" --64 -o test.o /tmp/test-f43580.s is the command that invoked gas. Again, no -gdwarf-4 option here, but the produced object has the correct dwarf4 info. So, when you build *.c -> *.o, passing -gdwarf-* is enough. The debug info is generated in the compile stage (i.e. by cc1) and included in the intermediate /tmp/*.s file. All gas needs to do is to transform the debug sections in the intermediate /tmp/*.s file into the binary stream in the .o file. GAS does it without being instructed by the explicit -Wa,-gdwarf-* option. In my understanding, passing -Wa,-gdwarf makes sense only when you build *.S -> *.o This is why I think DEBUG_CFLAGS += -gdwarf-4 (for source debug of .c files) and KBUILD_AFLAGS += -Wa,gdwarf-4 (for source debug of .S files) are basically orthogonal (and they can be even controlled by separate CONFIG options). As stated above, DEBUG_CFLAGS += -Wa,gdward-4 does not make sense. I am not a compiler expert, but that is what I understood from some experiments. Please correct me if I am wrong. > > When I use GCC v10.2.1 DEBUG_CFLAGS are not set. > > You should have -gdwarf-4 (and not -Wa,-gwarf-4) set for DEBUG_CFLAGS > when compiling with GCC and enabling CONFIG_DEBUG_INFO_DWARF4. Can you > please confirm? (Perhaps you may have accidentally disabled > CONFIG_DEBUG_INFO by rerunning `make defconfig`?) > -- > Thanks, > ~Nick Desaulniers -- Best Regards Masahiro Yamada
diff --git a/Makefile b/Makefile index d49c3f39ceb4..656fff17b331 100644 --- a/Makefile +++ b/Makefile @@ -826,12 +826,16 @@ else DEBUG_CFLAGS += -g endif -ifneq ($(LLVM_IAS),1) -KBUILD_AFLAGS += -Wa,-gdwarf-2 +dwarf-version-$(CONFIG_DEBUG_INFO_DWARF2) := 2 +dwarf-version-$(CONFIG_DEBUG_INFO_DWARF4) := 4 +DEBUG_CFLAGS += -gdwarf-$(dwarf-version-y) +ifneq ($(dwarf-version-y)$(LLVM_IAS),21) +# Binutils 2.35+ required for -gdwarf-4+ support. +dwarf-aflag := $(call as-option,-Wa$(comma)-gdwarf-$(dwarf-version-y)) +ifdef CONFIG_CC_IS_CLANG +DEBUG_CFLAGS += $(dwarf-aflag) endif - -ifdef CONFIG_DEBUG_INFO_DWARF4 -DEBUG_CFLAGS += -gdwarf-4 +KBUILD_AFLAGS += $(dwarf-aflag) endif ifdef CONFIG_DEBUG_INFO_REDUCED diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index dd7d8d35b2a5..e80770fac4f0 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -256,13 +256,24 @@ config DEBUG_INFO_SPLIT to know about the .dwo files and include them. Incompatible with older versions of ccache. +choice + prompt "DWARF version" + help + Which version of DWARF debug info to emit. + +config DEBUG_INFO_DWARF2 + bool "Generate DWARF Version 2 debuginfo" + help + Generate DWARF v2 debug info. + config DEBUG_INFO_DWARF4 - bool "Generate dwarf4 debuginfo" + bool "Generate DWARF Version 4 debuginfo" help - Generate dwarf4 debug info. This requires recent versions - of gcc and gdb. It makes the debug information larger. - But it significantly improves the success of resolving - variables in gdb on optimized code. + Generate DWARF v4 debug info. This requires gcc 4.5+ and gdb 7.0+. + It makes the debug information larger, but it significantly + improves the success of resolving variables in gdb on optimized code. + +endchoice # "DWARF version" config DEBUG_INFO_BTF bool "Generate BTF typeinfo"
Modifies CONFIG_DEBUG_INFO_DWARF4 to be a member of a choice. Adds an explicit CONFIG_DEBUG_INFO_DWARF2, which is the default. Does so in a way that's forward compatible with existing configs, and makes adding future versions more straightforward. Suggested-by: Fangrui Song <maskray@google.com> Suggested-by: Masahiro Yamada <masahiroy@kernel.org> Signed-off-by: Nick Desaulniers <ndesaulniers@google.com> --- Makefile | 14 +++++++++----- lib/Kconfig.debug | 21 ++++++++++++++++----- 2 files changed, 25 insertions(+), 10 deletions(-)