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 1
----------
extern const char a[];

int foo()
{
  return a != 0;
}

Testcase 1 Behavior
---------------------
- gcc-trunk has _no_ DWARF for variable a.
- gcc8.4.1 generates following DW_TAG_variable for extern variable a. But does not designate it as a non-defining decl (IIUC, DW_AT_specification is used for such cases?).

<..>
 <1><31>: Abbrev Number: 2 (DW_TAG_array_type)
    <32>   DW_AT_type        : <0x48>
    <36>   DW_AT_sibling     : <0x3c>
 <2><3a>: Abbrev Number: 3 (DW_TAG_subrange_type)
 <2><3b>: Abbrev Number: 0
 <1><3c>: Abbrev Number: 4 (DW_TAG_const_type)
    <3d>   DW_AT_type        : <0x31>
 <1><41>: Abbrev Number: 5 (DW_TAG_base_type)
    <42>   DW_AT_byte_size   : 1
    <43>   DW_AT_encoding    : 6        (signed char)
    <44>   DW_AT_name        : (indirect string, offset: 0x1df6): char
 <1><48>: Abbrev Number: 4 (DW_TAG_const_type)
    <49>   DW_AT_type        : <0x41>
 <1><4d>: Abbrev Number: 6 (DW_TAG_variable)
    <4e>   DW_AT_name        : a
    <50>   DW_AT_decl_file   : 1
    <51>   DW_AT_decl_line   : 1
    <52>   DW_AT_decl_column : 19
    <53>   DW_AT_type        : <0x3c>
    <57>   DW_AT_external    : 1
    <57>   DW_AT_declaration : 1
<..>

-----------------------------------------------------------

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>
<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

Reply via email to