Re: [PATCH v4 2/3] Kbuild: make DWARF version a choice

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Jan 14, 2021 at 8:27 AM Nick Desaulniers
<ndesaulniers@xxxxxxxxxx> 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@xxxxxxxxx> wrote:
> >
> > On Wed, Jan 13, 2021 at 1:32 AM Nick Desaulniers
> > <ndesaulniers@xxxxxxxxxx> 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@xxxxxxxxxxxxxxxxxx/



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




[Index of Archives]     [Linux Kernel]     [Kernel Newbies]     [x86 Platform Driver]     [Netdev]     [Linux Wireless]     [Netfilter]     [Bugtraq]     [Linux Filesystems]     [Yosemite Discussion]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Device Mapper]

  Powered by Linux