Would like to clarify: I ran dwarfdump on "macro_test_relocatable"
On Fri, Sep 13, 2024 at 10:51 AM Lorenzo Gomez <lgo...@windhoverlabs.com> wrote: > Thanks again for all of the insight into all this. The reason we're > looking into this is because we develop a tool that extracts dwarf info > from an elf file called juicer <https://github.com/WindhoverLabs/juicer>, > which dumps it into a SQLITE db for other tools. And we want to make sure > we document all the various cases when it comes to different types of > object files(shared, object file, executable/linked, etc) so that our users > are aware of all of this. > > In any case it looks I can apply relocations with the "-r" switch in gcc > and I tried the following: > > gcc -r macro_test.o -o macro_test_relocatable > > After running dwarfdump on "macro_test.o" I get the following: > > Macro data from CU-DIE at .debug_info offset 0x0000000c: > Macro version: 5 > MacroInformationEntries count: 13, bytes length: 46 > [ 0] 0x07 DW_MACRO_import offset 0x00000000 > [ 1] 0x03 DW_MACRO_start_file line 0 file number 1 > /usr/include/stdc-predef.h > [ 2] 0x03 DW_MACRO_start_file line 31 file number 2 > /home/lgomez/projects/openc3/cosmology/juicer/src/macro_test.h > [ 3] 0x07 DW_MACRO_import offset 0x00000000 > [ 4] 0x04 DW_MACRO_end_file > [ 5] 0x05 DW_MACRO_define_strp line 1 str offset 0x00001de8 MAC1 2 > [ 6] 0x05 DW_MACRO_define_strp line 2 str offset 0x000013bd MAC2 3 > [ 7] 0x03 DW_MACRO_start_file line 3 file number 3 > <src-index-high-no-source-file-name-available> > [ 8] 0x07 DW_MACRO_import offset 0x00000000 > [ 9] 0x04 DW_MACRO_end_file > [ 10] 0x05 DW_MACRO_define_strp line 4 str offset 0x00002265 MAC3 4 > [ 11] 0x04 DW_MACRO_end_file > [ 12] 0x00 end-of-macros > > As you mentioned there is the "DW_MACRO_import", but it has an offset of > "0x00000000". Which, if I'm interpreting the DWARF5 spec correctly, means > "end of macros" for macro import units (and we still don't get the "MAC4", > "MAC5" macros). And this makes sense in that this is what > "dwarf_get_macro_import" returns when I step through code in juicer. And I > believe that dwarfdump is using libdwarf too so that makes sense. > > So is this expected behavior as well? > > Essentially an object file has to be linked in order for all macros to > show up under one debug_macro section? > > I apologize if this question sounds obvious/silly; I'm just trying to make > sure I concretely document this for our tooling that depends on this... > > Again, > > Thanks so much for your time/explanations about this. It's much > appreciated! > > > > > On Thu, Sep 12, 2024 at 5:38 PM Jakub Jelinek <ja...@redhat.com> wrote: > >> On Thu, Sep 12, 2024 at 05:10:01PM -0500, Lorenzo Gomez wrote: >> > Thanks so much for the detailed explanation. So clearly all the macros >> are >> > there as we can see from readelf. I ran it myself and can see all the >> > macros as David pointed out. And just to make sure I understand, this is >> > what I took away: >> > >> > 1. All the macros are in the file as we can see from readelf output. >> > 2. As per the DWARF5 spec it states "As described in Section 3.1.1 on >> page >> > 60, the macro information for a given compilation unit is represented in >> > the .debug_macro section of an object file." >> > Meaning that there should be only *one*.debug_macro section, not >> more >> > than 1 as gcc is structuring it. >> >> Generally, in binaries/executables there is (at most) one .debug_* >> section of >> each kind with the different additions concatenated. >> In object files, there can be many, that is something eventually linked >> into >> the output section. E.g. for comdat functions the producer could in ELF >> emit separate .debug_info contributions in the comdat of the specific >> function. >> So, IMO nothing is violated, there is no bug, that is how .debug_macro >> was meant to be used from the beginning (when what we implemented in GCC >> as a DWARF 4 extension was then with small changes standardized in DWARF >> 5). >> If you are trying to look at debug info in object files rather than >> binaries/shared libraries, you need to apply relocations, and the >> DW_MACRO_import ops >> have relocations to those corresponding .debug_macro contributions; >> .debug_info compilation unit(s) also has DW_AT_macros attribute which >> should have relocation pointing to the .debug_macro contribution where >> the macros for that compilation unit start. And each DW_AT_import there >> includes everything in the referenced contribution. >> >> Jakub >> >>
-- Dwarf-discuss mailing list Dwarf-discuss@lists.dwarfstd.org https://lists.dwarfstd.org/mailman/listinfo/dwarf-discuss