[Dwarf-discuss] Macros after "#include" does not show up DWARF
Lorenzo Gomez
lgomez@windhoverlabs.com
Fri Sep 13 22:50:50 GMT 2024
I did find it kind of odd too that it emitted "macinfo". I got a newer
version of clang(Ubuntu clang version 14.0.0-1ubuntu1.1 ) and now it
actually emits the DWARF5 version of macros:
.debug_macro: Macro info for a single cu at macro Offset 0x00000000
Macro data from CU-DIE at .debug_info offset 0x0000000c:
Nested import level: 0
Macro version : 5
macro section offset 0x00000000
MacroInformationEntries count: 371, bytes length: 1350
[ 0] 0x03 DW_MACRO_start_file line 0 file number 0
/home/docker/juicer/src/macro_test.c
[ 1] 0x0b DW_MACRO_define_strx line 1 str offset 0x00000081 __clang__ 1
[ 2] 0x0b DW_MACRO_define_strx line 2 str offset 0x0000004c main
[ 3] 0x03 DW_MACRO_start_file line 3 file number 1
/home/docker/juicer/src/./macro_test.h
[ 4] 0x0b DW_MACRO_define_strx line 1 str offset 0x00000081 __clang__ 1
[ 5] 0x0b DW_MACRO_define_strx line 2 str offset 0x00000051 int
[ 6] 0x04 DW_MACRO_end_file
[ 7] 0x0b DW_MACRO_define_strx line 4 str offset 0x00000051 int
[ 8] 0x04 DW_MACRO_end_file
....
Makes sense. Thanks so much for the detailed explanations. You're right;
clang doesn't seem to be writing the DW_MACRO_import at all (at least
judging from the dwarfdump output).
I also learned something about libdwarf, which makes me feel silly now. I
can actually get the different macros from the different COMDAT sections
using the
int dwarf_init_b(int /*fd*/,
Dwarf_Unsigned /*access*/,
unsigned /*groupnumber*/,
Dwarf_Handler /*errhand*/,
Dwarf_Ptr /*errarg*/,
Dwarf_Debug* /*dbg*/,
Dwarf_Error* /*error*/);
function and passing the groupnumber I'm interested in. I was previously
using the "dwarf_init" function, which does not have an argument for the
group number.
Hopefully this helps someone out there if they find themselves struggling
with this.
Thanks for all your help everybody!
On Fri, Sep 13, 2024 at 3:01 PM Jakub Jelinek <jakub@redhat.com> wrote:
> On Fri, Sep 13, 2024 at 01:46:26PM -0500, Lorenzo Gomez wrote:
> > That makes sense. Interestingly enough when I run with clang
> > "clang -gdwarf-5 -fdebug-macro -g3 -c macro_test.c -o macro_test_clang.o"
> > and dwarfdump with "dwarfdump macro_test_clang.o >
> macro_test_clang_dwarf"
> >
> > yields all the macros:
> >
> >
> > compilation-unit .debug_macinfo offset 0x00000000
>
> That seems to be .debug_macinfo, i.e. the DWARF4-ish section.
> In that case, there is no other choice but to emit all the macros.
>
> > num name section-offset file-index [line] "string"
> > 0 DW_MACINFO_start_file: 0 0 [ 0] 0
> > 1 DW_MACINFO_define : 3 0 [ 1] "MAC1 2"
> > 2 DW_MACINFO_define : 12 0 [ 2] "MAC2 3"
> > 3 DW_MACINFO_start_file: 21 1 [ 3] 0
> > 4 DW_MACINFO_define : 24 1 [ 1] "MAC4"
> > 5 DW_MACINFO_define : 31 1 [ 2] "MAC5 1"
> > 6 DW_MACINFO_end_file : 40 1 [ 0] 0
> > 7 DW_MACINFO_define : 41 0 [ 4] "MAC3 4"
> > 8 DW_MACINFO_end_file : 50 0 [ 0] 0
>
> The design of .debug_macro is to decrease around 100x times the size
> of the section by a) using references to .debug_str strings instead of
> including the strings directly in the section, which allows getting rid of
> reduncanies in the macro names/values between different compilation units
> b) using the DW_MACRO_import to get rid of redundancies even in the ops
> coming from the same header as long as it defines the same macros (which
> usually is the case).
> GCC implements both, clang apparently implements just a).
> Consider say simple testcase like:
> #define DEF 2
> #include <stdio.h>
> #define ABC 1
> int i;
> With GCC that results in 400 bytes in the non-group .debug_macro
> (i.e. unsharable) and 5341 bytes in the group .debug_macro sections
> (part in stdio.h related stuff (and headers it includes), part in
> predefined macros), that is sharable by different CUs most likely.
> If the #include is commented out, it reduces to 38 bytes in the primary
> .debug_macro and 2774 bytes in group .debug_macro sections (so that maps
> the predefined macros).
> Compare to clang 3723 .debug_macro section size (unsharable) plus
> 3372 .debug_str_addr (admittedly shared with .debug_info, but otherwise
> also unsharable with other CUs) vs. with #include commented out
> 1765 .debug_macro and 1904 .debug_str_addr. Note, GCC uses more
> relocations, which makes larger *.o files but if the most important
> is debug info in linked binaries/shared libraries, by using heavily
> DW_MACRO_import you can have those 5341-2774 bytes for stdio.h usually
> just once in a binary, rather than number of CUs that include it.
>
> >
> > clang version:
> > clang version 10.0.0-4ubuntu1
>
> That seems to be fairly old.
>
> Jakub
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.dwarfstd.org/pipermail/dwarf-discuss/attachments/20240913/43ed80ca/attachment-0001.htm>
More information about the Dwarf-discuss
mailing list