From: Pedro Alves <palves@redhat.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: gdb-patches@sourceware.org
Subject: Re: [pushed] Fix struct sockaddr/sockaddr_in/sockaddr_un strict aliasing violations
Date: Sat, 07 Mar 2015 18:20:00 -0000 [thread overview]
Message-ID: <54FB4162.5090601@redhat.com> (raw)
In-Reply-To: <83r3t0lmb9.fsf@gnu.org>
On 03/07/2015 06:00 PM, Eli Zaretskii wrote:
>> From: Pedro Alves <palves@redhat.com>
>> Date: Sat, 7 Mar 2015 17:44:26 +0000
>>
>> Building gdbserver in C++ mode shows:
>>
>> gdb/gdbserver/tracepoint.c: In function âvoid* gdb_agent_helper_thread(void*)â:
>> gdb/gdbserver/tracepoint.c:7190:47: error: cannot convert âsockaddr_un*â to âsockaddr*â for argument â2â to âint accept(int, sockaddr*, socklen_t*)â
>> fd = accept (listen_fd, &sockaddr, &tmp);
>>
>> A few places in the tree already have an explicit cast to struct
>> sockaddr *, but that's a strict aliasing violation. Instead of
>> propagating invalid code, fix this by using a union instead.
>
> Yuck! Isn't there a better way? Why do we have the original problem
> to begin with, i.e. where did the incompatible data type come from?
Those are BSD socket types, they've been this way ever since BSD
invented them. The structs are not type compatible, even though
they have some common fields that are are put at the same offsets,
by design.
See e.g.:
http://stackoverflow.com/questions/1429645/how-to-cast-sockaddr-storage-and-avoid-breaking-strict-aliasing-rules
Lots of packages fixed this around the gcc 4.4 era, but gdb managed
to never triggers the warnings. See e.g., (from a quick google search):
http://comments.gmane.org/gmane.network.inn/8891
http://pidgin.im/pipermail/commits/2010-April/016956.html
> (Does it even make sense to work around C++ restrictions while
> converting code to C++?)
It's not a C++ restriction. The old code was invalid C code.
Thanks,
Pedro Alves
next prev parent reply other threads:[~2015-03-07 18:20 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-07 17:44 Pedro Alves
2015-03-07 18:00 ` Eli Zaretskii
2015-03-07 18:20 ` Pedro Alves [this message]
2015-03-07 18:53 ` Eli Zaretskii
2015-03-09 10:45 ` Pedro Alves
2015-03-09 11:10 ` Pedro Alves
2015-03-09 11:38 ` Pedro Alves
2015-03-09 16:04 ` Eli Zaretskii
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=54FB4162.5090601@redhat.com \
--to=palves@redhat.com \
--cc=eliz@gnu.org \
--cc=gdb-patches@sourceware.org \
/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