public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug debug/97811] New: Adding transparent_union tag when typedeffing compiles but produces no debug info for components of the union
@ 2020-11-12 11:51 peadar at arista dot com
  0 siblings, 0 replies; only message in thread
From: peadar at arista dot com @ 2020-11-12 11:51 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97811

            Bug ID: 97811
           Summary: Adding transparent_union tag when typedeffing compiles
                    but produces no debug info for components of the union
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: debug
          Assignee: unassigned at gcc dot gnu.org
          Reporter: peadar at arista dot com
  Target Milestone: ---

Created attachment 49551
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49551&action=edit
Source file for good/bad example.

This is against 
gcc (GCC) 10.2.1 20201016 (Red Hat 10.2.1-6)

But exists as far back as gcc8.4 at least.


transparent_enum's are used in glibc for example, with __SOCKADDR_ARG to allow
any type of the numerous address family's variants of sockaddr to be passed to
functions such as bind(2).

The type __SOCKADDR_ARG is declared something like this:

typedef union  {
    sockaddr * restrict __sockadddr__;
    sockaddr_in * restrict __sockadddr_in__;
    /* more sockaddr_* types ... */
} __SOCKADDR_ARG __attribute__((transparent_union));

When compiled with -g, the resulting debug information does not contain any
entries for the fields of the DIE for the (anonymous) union.

The construction looked a little odd to me - it seemed that the attribute is
being applied to the typedef, rather than the union itself, but gcc was happy
to compile it, and the type behaves as expected when passing arguments to
bind(2), for example.

By putting the attribute before the __SOCKADDR_ARG token, it actually fixes the
problem, but it seems either the debug information should be propagated to the
union, or that the compiler should complain.

The attachment is a source file transparent-union.c, and embedded a comment
that is the output of `readelf --debug-dump=info transparent-union.o`. You can
see that for UGood, there's a typedef to the union, and the union has child
DIEs for each member. For UBad, there's the typedef and the union, but no
members.

gdb is, of course, unable to print the content of the problematic union when
debugging, and other tools are equally unhappy.

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-11-12 11:51 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-12 11:51 [Bug debug/97811] New: Adding transparent_union tag when typedeffing compiles but produces no debug info for components of the union peadar at arista dot com

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