Dwarf 3 and 4 state that if DW_AT_accessibility is missing, the default is DW_ACCESS_private in DW_TAG_class_type and DW_ACCESS_public otherwise. Unfortunately dwarf2out.c assumes the default is DW_ACCESS_public always. Not sure if GDB (or other dwarf consumers) makes the same assumption. If not, then we can add DW_ACCESS_public DW_AT_accessibility in DW_TAG_class_type for everything that didn't have it till now and drop DW_ACCESS_private accessibility, if yes, then I'm afraid all we can do for the time being is just add DW_ACCESS_public accessibility and keep DW_ACCESS_private accessibility too.
Looking at GDB: /* Handle accessibility and virtuality of field. The default accessibility for members is public, the default accessibility for inheritance is private. */ if (die->tag != DW_TAG_inheritance) new_field->accessibility = DW_ACCESS_public; else new_field->accessibility = DW_ACCESS_private; i.e. it seems to match what GCC (wrongly) does. I'm afraid we need to live with some extra DW_AT_accessibility attributes for compatibility.
Created attachment 21346 [details] gcc46-pr45124.patch Untested fix.
Subject: Bug 45124 Author: jakub Date: Mon Sep 20 16:48:29 2010 New Revision: 164442 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=164442 Log: PR debug/45124 * dwarf2out.c (add_accessibility_attribute): Assume DW_ACCESS_private as the default for dwarf_version > 2 and DW_TAG_class_type parent. (gen_inheritance_die): Assume DW_ACCESS_public as the default for dwarf_version > 2 and parent other than DW_TAG_class_type. Modified: trunk/gcc/ChangeLog trunk/gcc/dwarf2out.c
Fixed.
DWARF3 leaves the meaning for struct/union unspecified: An inheritance entry may have a DW_AT_accessibility attribute. If no accessibility attribute is present, private access is assumed for an entry of a class and public access is assumed for an entry of an interface. DWARF4 specifies: An inheritance entry may have a DW_AT_accessibility attribute. If no accessibility attribute is present, private access is assumed for an entry of a class and public access is assumed for an entry of an interface, struct or union. DWARF2 had: An inheritance entry may have a DW_AT_accessibility attribute. If no accessibility attribute is present, private access is assumed. So I guess DWARF3 was meant like what DWARF4 says and GDB should be changed for both DWARF3 and DWARF4.