This is the mail archive of the
mailing list for the GDB project.
Re: [pushed] Fix struct sockaddr/sockaddr_in/sockaddr_un strict aliasing violations
- From: Pedro Alves <palves at redhat dot com>
- To: Eli Zaretskii <eliz at gnu dot org>
- Cc: gdb-patches at sourceware dot org
- Date: Sat, 07 Mar 2015 18:20:18 +0000
- Subject: Re: [pushed] Fix struct sockaddr/sockaddr_in/sockaddr_un strict aliasing violations
- Authentication-results: sourceware.org; auth=none
- References: <1425750266-14385-1-git-send-email-palves at redhat dot com> <83r3t0lmb9 dot fsf at gnu dot org>
On 03/07/2015 06:00 PM, Eli Zaretskii wrote:
>> From: Pedro Alves <email@example.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,
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):
> (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.