From: Richard Biener <richard.guenther@gmail.com>
To: Indu Bhagat <indu.bhagat@oracle.com>
Cc: gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: DWARF for extern variable
Date: Tue, 24 Aug 2021 09:55:06 +0200 [thread overview]
Message-ID: <CAFiYyc2MOhSX1838Cp-P9-upr8XiyAPpM=cY=90edt5=+UB5_Q@mail.gmail.com> (raw)
In-Reply-To: <4381bb52-95f6-9256-5361-e7cf517b3582@oracle.com>
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 1
> ----------
> extern const char a[];
>
> int foo()
> {
> return a != 0;
> }
>
> Testcase 1 Behavior
> ---------------------
> - gcc-trunk has _no_ DWARF for variable a.
Use -fno-eliminate-unused-debug-symbols (the comparison is folded away
very early it seems). Then we get similar DWARF as with GCC 8.
> - 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?).
It has DW_AT_declaration.
>
> <..>
> <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>
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.
> <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
next prev parent reply other threads:[~2021-08-24 7:55 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-23 21:17 Indu Bhagat
2021-08-24 7:55 ` Richard Biener [this message]
2021-09-01 17:25 ` Indu Bhagat
2021-09-02 7:32 ` Richard Biener
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAFiYyc2MOhSX1838Cp-P9-upr8XiyAPpM=cY=90edt5=+UB5_Q@mail.gmail.com' \
--to=richard.guenther@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=indu.bhagat@oracle.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).