From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29714 invoked by alias); 7 Mar 2015 18:20:25 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 29695 invoked by uid 89); 7 Mar 2015 18:20:25 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Sat, 07 Mar 2015 18:20:24 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t27IKKHU023759 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 7 Mar 2015 13:20:21 -0500 Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t27IKI9r029337; Sat, 7 Mar 2015 13:20:19 -0500 Message-ID: <54FB4162.5090601@redhat.com> Date: Sat, 07 Mar 2015 18:20:00 -0000 From: Pedro Alves User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: Eli Zaretskii CC: gdb-patches@sourceware.org Subject: Re: [pushed] Fix struct sockaddr/sockaddr_in/sockaddr_un strict aliasing violations References: <1425750266-14385-1-git-send-email-palves@redhat.com> <83r3t0lmb9.fsf@gnu.org> In-Reply-To: <83r3t0lmb9.fsf@gnu.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-SW-Source: 2015-03/txt/msg00196.txt.bz2 On 03/07/2015 06:00 PM, Eli Zaretskii wrote: >> From: Pedro Alves >> 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