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 -- Dwarf-discuss mailing list Dwarf-discuss@lists.dwarfstd.org https://lists.dwarfstd.org/mailman/listinfo/dwarf-discuss