Bug 410691 - gcc generates DW_TAG_Variable instead of DW_TAG_member
Summary: gcc generates DW_TAG_Variable instead of DW_TAG_member
Alias: None
Product: Fedora
Classification: Fedora
Component: gcc
Version: 9
Hardware: All
OS: Linux
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Fedora Extras Quality Assurance
Depends On:
Blocks: 173278
TreeView+ depends on / blocked
Reported: 2007-12-04 16:50 UTC by Sami Wagiaalla
Modified: 2016-06-07 22:46 UTC (History)
6 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Last Closed: 2009-07-14 15:25:46 UTC
Type: ---

Attachments (Terms of Use)

Description Sami Wagiaalla 2007-12-04 16:50:42 UTC
gcc generates DW_TAG_Variable tags for static members of classes.
Which should be DW_TAG_Member.

Dwarf3 spec page 60 point 6:

 "If the variable entry represents the defining declaration for a C++ static
 data member of a structure, class or union, the entry has a 
 DW_AT_specification attribute, whose value is a reference to the debugging 
 information entry representing the declaration of this data member. The 
 referenced entry has the tag DW_TAG_member and will be a child of some class, 
 structure or union type entry."

Comment 1 Bug Zapper 2008-05-14 04:05:08 UTC
Changing version to '9' as part of upcoming Fedora 9 GA.
More information and reason for this action is here:

Comment 2 Jakub Jelinek 2009-03-31 17:37:12 UTC
So, what exactly needs to change from current gcc output for this?

Given say:
struct S
  int i;
  static int j;

int S::j = 72;

main ()
  S s;

-	.uleb128 0x4	# (DIE (0x43) DW_TAG_variable)
+	.uleb128 0x4	# (DIE (0x43) DW_TAG_member)
 	.ascii "j\0"	# DW_AT_name
 	.byte	0x1	# DW_AT_decl_file (NN.C)
 	.byte	0x4	# DW_AT_decl_line
 	.long	.LASF3	# DW_AT_MIPS_linkage_name: "_ZN1S1jE"
 	.long	0x53	# DW_AT_type
 	.byte	0x1	# DW_AT_external
 	.byte	0x1	# DW_AT_declaration

(and corresponding:
 	.uleb128 0x4	# (abbrev code)
-	.uleb128 0x34	# (TAG: DW_TAG_variable)
+	.uleb128 0xd	# (TAG: DW_TAG_member)
in .debug_abbrev) is probably not enough, as the standard doesn't list e.g. DW_AT_external to be acceptable for DW_TAG_member.  Can DW_AT_MIPS_linkage_name be used on the DW_TAG_member?  DW_AT_declaration is allowed, I'm wondering about usual stuff like DW_AT_abstract_origin etc. though.

Comment 3 Sami Wagiaalla 2009-03-31 18:54:14 UTC
Hmm.. I cant remember why I cared about this. It seems fine as is. Changing this might actually break gdb lookup and introduce no new functionality.

Jan ?.. any thoughts ?

Comment 4 Jan Kratochvil 2009-03-31 19:27:51 UTC
I agree it does not cause any problems to current GDB.
FYI dwarf2read.c:dwarf2_add_field():
  else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable)
      /* C++ static member.  */

      /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
         is a declaration, but all versions of G++ as of this writing
         (so through at least 3.2.1) incorrectly generate
         DW_TAG_variable tags.  */

But even after the GCC change GDB still works for the Jakub's testcase.

It is a clear violation of how DWARF specifies this situation according to the Sami's citation.  So GCC should change it but it is very low-low priority.

(In reply to comment #2)
> the standard doesn't list e.g. DW_AT_external to be acceptable for
> DW_TAG_member.

Appendix A - Other attributes [...] may also appear in a given debugging entry.
[...] the list [...] cannot be considered definitive.

> Can DW_AT_MIPS_linkage_name be used on the DW_TAG_member?
> DW_AT_declaration is allowed, I'm wondering about usual stuff like
> DW_AT_abstract_origin etc. though.  

As all these attributes get inherited to DW_TAG_variable IMO GCC can keep it this way.

Comment 5 Roland McGrath 2009-03-31 19:49:14 UTC
That appendix is not normative and there are some sensical attributes for some tags that it does not list.

I think it would be correct to s/variable/member/ in the specification DIE.
The way I read the spec, everything that is common (including linkage name et al) should go on the member DIE and that is fully kosher with the variable DIE referring to it via specification.

Comment 6 Roland McGrath 2009-03-31 19:50:42 UTC
Adding Petr to the CC.  Please CC him on any questionable-DWARF sorts of things.  We can add this wrinkle to the list to eventually make sure that dwarflint both catches it and recognizes it as a known quirk for gcc < 4.4.

Comment 7 Bug Zapper 2009-06-09 23:15:08 UTC
This message is a reminder that Fedora 9 is nearing its end of life.
Approximately 30 (thirty) days from now Fedora will stop maintaining
and issuing updates for Fedora 9.  It is Fedora's policy to close all
bug reports from releases that are no longer maintained.  At that time
this bug will be closed as WONTFIX if it remains open with a Fedora 
'version' of '9'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version' 
to a later Fedora version prior to Fedora 9's end of life.

Bug Reporter: Thank you for reporting this issue and we are sorry that 
we may not be able to fix it before Fedora 9 is end of life.  If you 
would still like to see this bug fixed and are able to reproduce it 
against a later version of Fedora please change the 'version' of this 
bug to the applicable version.  If you are unable to change the version, 
please add a comment here and someone will do it for you.

Although we aim to fix as many bugs as possible during every release's 
lifetime, sometimes those efforts are overtaken by events.  Often a 
more recent Fedora release includes newer upstream software that fixes 
bugs or makes them obsolete.

The process we are following is described here: 

Comment 8 Bug Zapper 2009-07-14 15:25:46 UTC
Fedora 9 changed to end-of-life (EOL) status on 2009-07-10. Fedora 9 is 
no longer maintained, which means that it will not receive any further 
security or bug fix updates. As a result we are closing this bug.

If you can reproduce this bug against a currently maintained version of 
Fedora please feel free to reopen this bug against that version.

Thank you for reporting this bug and we are sorry it could not be fixed.

Note You need to log in before you can comment on or make changes to this bug.