On Wed, Sep 1, 2021 at 7:25 PM Indu Bhagat <indu.bha...@oracle.com> wrote: > > On 8/24/21 12:55 AM, Richard Biener wrote: > > On Mon, Aug 23, 2021 at 11:18 PM Indu Bhagat via Gcc-patches > > <gcc-patches@gcc.gnu.org> wrote: > >> > >> Hello, > >> > >> What is the expected DWARF for extern variable in the following cases? I > >> am seeing that the DWARF generated is different with gcc8.4.1 vs gcc-trunk. > >> > >> > >> Testcase 2 > >> ---------- > >> extern const char a[]; > >> const char a[] = "testme"; > >> > >> Testcase 2 Behavior > >> -------------------- > >> - Both gcc-trunk and gcc8.4.1 generate two DW_TAG_variable DIEs (the > >> defining decl holds the reference to the non-defining decl via > >> DW_AT_specification) > >> - But gcc8.4.1 does not generate any DWARF for the type of the defining > >> decl (const char[7]) but gcc-trunk does. > >> > >> ## DWARF for testcase 2 with gcc-trunk is as follows: > >> <...> > >> <1><22>: Abbrev Number: 2 (DW_TAG_array_type) > >> <23> DW_AT_type : <0x39> > >> <27> DW_AT_sibling : <0x2d> > >> <2><2b>: Abbrev Number: 5 (DW_TAG_subrange_type) > >> <2><2c>: Abbrev Number: 0 > >> <1><2d>: Abbrev Number: 1 (DW_TAG_const_type) > >> <2e> DW_AT_type : <0x22> > >> <1><32>: Abbrev Number: 3 (DW_TAG_base_type) > >> <33> DW_AT_byte_size : 1 > >> <34> DW_AT_encoding : 6 (signed char) > >> <35> DW_AT_name : (indirect string, offset: 0x2035): char > >> <1><39>: Abbrev Number: 1 (DW_TAG_const_type) > >> <3a> DW_AT_type : <0x32> > >> <1><3e>: Abbrev Number: 6 (DW_TAG_variable) > >> <3f> DW_AT_name : a > >> <41> DW_AT_decl_file : 1 > >> <42> DW_AT_decl_line : 1 > >> <43> DW_AT_decl_column : 19 > >> <44> DW_AT_type : <0x2d> > >> <48> DW_AT_external : 1 > >> <48> DW_AT_declaration : 1 > >> <1><48>: Abbrev Number: 2 (DW_TAG_array_type) > >> <49> DW_AT_type : <0x39> > >> <4d> DW_AT_sibling : <0x58> > >> <2><51>: Abbrev Number: 7 (DW_TAG_subrange_type) > >> <52> DW_AT_type : <0x5d> > >> <56> DW_AT_upper_bound : 6 > >> <2><57>: Abbrev Number: 0 > >> <1><58>: Abbrev Number: 1 (DW_TAG_const_type) > >> <59> DW_AT_type : <0x48> > >> <1><5d>: Abbrev Number: 3 (DW_TAG_base_type) > >> <5e> DW_AT_byte_size : 8 > >> <5f> DW_AT_encoding : 7 (unsigned) > >> <60> DW_AT_name : (indirect string, offset: 0x2023): long > >> unsigned int > >> <1><64>: Abbrev Number: 8 (DW_TAG_variable) > >> <65> DW_AT_specification: <0x3e> > >> <69> DW_AT_decl_line : 2 > >> <6a> DW_AT_decl_column : 12 > >> <6b> DW_AT_type : <0x58> > > > > I suppose having both a DW_AT_specification and a DW_AT_type > > is somewhat at odds. It's likely because the definition specifies > > the size of the array while the specification does not. Not sure > > what should be best done here. > > > > Richard. > > Hmm..I thought the generated DWARF by gcc-trunk for testcase 2 is > coherent and specifies the information in alignment with the source : > DW_AT_type of the defining declaration correctly specifies the type to > be const char[7] while the DW_AT_specification pointing to the > non-defining decl (and with type const char[] with no size info). > > The DWARF generated by gcc-8.4.1, however, does seem to be missing > information though. It should have the information for the defining decl > and hence, the size info. i.e., DW_AT_type pointing to a array with > DW_TAG_subrange_type with attribute DW_AT_upper_bound = 6 like above. > Isn't it ?
Yes. > Indu > > > > >> <6f> DW_AT_location : 9 byte block: 3 0 0 0 0 0 0 0 0 > >> (DW_OP_addr: 0) > >> <1><79>: Abbrev Number: 0 > >> > >> ## DWARF for testcase 2 with gcc8.4.1 is as follows: > >> <1><21>: Abbrev Number: 2 (DW_TAG_array_type) > >> <22> DW_AT_type : <0x38> > >> <26> DW_AT_sibling : <0x2c> > >> <2><2a>: Abbrev Number: 3 (DW_TAG_subrange_type) > >> <2><2b>: Abbrev Number: 0 > >> <1><2c>: Abbrev Number: 4 (DW_TAG_const_type) > >> <2d> DW_AT_type : <0x21> > >> <1><31>: Abbrev Number: 5 (DW_TAG_base_type) > >> <32> DW_AT_byte_size : 1 > >> <33> DW_AT_encoding : 6 (signed char) > >> <34> DW_AT_name : (indirect string, offset: 0x1e04): char > >> <1><38>: Abbrev Number: 4 (DW_TAG_const_type) > >> <39> DW_AT_type : <0x31> > >> <1><3d>: Abbrev Number: 6 (DW_TAG_variable) > >> <3e> DW_AT_name : a > >> <40> DW_AT_decl_file : 1 > >> <41> DW_AT_decl_line : 1 > >> <42> DW_AT_decl_column : 19 > >> <43> DW_AT_type : <0x2c> > >> <47> DW_AT_external : 1 > >> <47> DW_AT_declaration : 1 > >> <1><47>: Abbrev Number: 5 (DW_TAG_base_type) > >> <48> DW_AT_byte_size : 8 > >> <49> DW_AT_encoding : 7 (unsigned) > >> <4a> DW_AT_name : (indirect string, offset: 0x1df2): long > >> unsigned int > >> <1><4e>: Abbrev Number: 7 (DW_TAG_variable) > >> <4f> DW_AT_specification: <0x3d> > >> <53> DW_AT_decl_line : 2 > >> <54> DW_AT_decl_column : 12 > >> <55> DW_AT_location : 9 byte block: 3 0 0 0 0 0 0 0 0 > >> (DW_OP_addr: 0) > >> <1><5f>: Abbrev Number: 0 > >> > >> Thanks > >> Indu >