From owner-svn-src-all@freebsd.org Fri Mar 4 23:10:53 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 93F0F9DB2B2 for ; Fri, 4 Mar 2016 23:10:53 +0000 (UTC) (envelope-from pfg@FreeBSD.org) Received: from nm14-vm0.bullet.mail.bf1.yahoo.com (nm14-vm0.bullet.mail.bf1.yahoo.com [98.139.213.164]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 5478EBD6 for ; Fri, 4 Mar 2016 23:10:53 +0000 (UTC) (envelope-from pfg@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1457133046; bh=YHLhaozoPhe/D5YNkVmqx6czjmhXfZcpm/8Ega/chhA=; h=Subject:To:References:Cc:From:Date:In-Reply-To:From:Subject; b=kYucctfJM1ldHStfK8GWOdVNBXevgG4RKTshtarb8Ahsa/wBznwMzynVIWNoV1izkqK9WvKcPGJUhDYUDazGOgRju2o0HDJpj1SVU/dArs5JzFSbacAFLpk9oWY0S59IBJyUSoAadjzDSZfQhsS1kupWGkSx4U32SJEi6vgAhO0Cxif/gvW9T5o2/j/OQPoUKsbEec3MSWWETB0MlIhEzTO1PZnVkuIZb1nfkY/QSU+yB0UkNhFzWEMi1mVftOn0CRieuWHlx/PgQzpYyU0soA/W/cp3rDn3dOz6EkuzA2Y8N18/PycszE6v10DIqjyb9oCveVMlzJ+ZKYA4vzMMGA== Received: from [66.196.81.172] by nm14.bullet.mail.bf1.yahoo.com with NNFMP; 04 Mar 2016 23:10:46 -0000 Received: from [98.139.213.8] by tm18.bullet.mail.bf1.yahoo.com with NNFMP; 04 Mar 2016 23:10:46 -0000 Received: from [127.0.0.1] by smtp108.mail.bf1.yahoo.com with NNFMP; 04 Mar 2016 23:10:46 -0000 X-Yahoo-Newman-Id: 185989.19196.bm@smtp108.mail.bf1.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: 9VQkafUVM1kgpYoGSdMPyr..A5qYe5TW6XQNLbcNUEXiy8M zMG1eWOmt8SUXM8ifOOtuLj3aX7Yn_GnZRwGzExyJEqQQeUV5UkL7f6hgso8 Pcqd.ilSpz9FoCzFkJHDmhWtHmeP9NXcRwQYHqykb5vKpTPx3zqS94BNeeAS f49naYqDRWCgxwqZsOHO.A_WR08QgEBT.koID2sYTvndY2VpjsxlrHhHRvnd 4w1UusvQk7gm76YfRsoGJG72G.wDv.FkjDS4tZDU4lb9IEhyGpcK_ec0nvl2 2AJNzzHl7UHa3Oy5j1zxxPJLY4Slb64Fb4kyZHyEPfAd5BSjV3Owyxn0xlbH Dho3kWuhUIMX7ykLs5CF.YWU9vfFUUs9aYJ328D5o3LUmthuyJBn9s1G0qwZ SXz7MZmQX20z5l30LnpW3TM8OER0LhEWSZaBOU0dghkRzEej53KDjBjhYi9Y b8Neozy94zAA_e8CIvi3YL0jmZ8rZQ.iIru5_tgwj6e9c8Nu0mna2ocTgjUQ b5o.2dtLN7ZNRQdfH1._qX8XdxRlxlvxY X-Yahoo-SMTP: xcjD0guswBAZaPPIbxpWwLcp9Unf Subject: Re: svn commit: r296386 - head/lib/libc/rpc To: Jilles Tjoelker References: <201603041530.u24FUfu5021609@repo.freebsd.org> <20160304223231.GA47504@stack.nl> Cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org From: Pedro Giffuni Message-ID: <56DA1620.30800@FreeBSD.org> Date: Fri, 4 Mar 2016 18:11:28 -0500 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: <20160304223231.GA47504@stack.nl> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 04 Mar 2016 23:10:53 -0000 On 03/04/16 17:32, Jilles Tjoelker wrote: > On Fri, Mar 04, 2016 at 03:30:41PM +0000, Pedro F. Giffuni wrote: >> Author: pfg >> Date: Fri Mar 4 15:30:41 2016 >> New Revision: 296386 >> URL: https://svnweb.freebsd.org/changeset/base/296386 > >> Log: >> Work around aliasing issues detected in modern GCC. > >> Avoid casting gymnastics that lead to pointer aliasing by introducing an >> inline function as done in NetBSD (but without #if0'd WIP code). > >> Obtained from: NetBSD (CVS Rev. 1.24, 1.25) > >> Modified: >> head/lib/libc/rpc/clnt_vc.c > >> Modified: head/lib/libc/rpc/clnt_vc.c >> ============================================================================== >> --- head/lib/libc/rpc/clnt_vc.c Fri Mar 4 14:23:34 2016 (r296385) >> +++ head/lib/libc/rpc/clnt_vc.c Fri Mar 4 15:30:41 2016 (r296386) >> @@ -502,6 +502,20 @@ clnt_vc_abort(CLIENT *cl) >> { >> } >> >> +static __inline void >> +htonlp(void *dst, const void *src, uint32_t incr) >> +{ >> + /* We are aligned, so we think */ >> + *(uint32_t *)dst = htonl(*(const uint32_t *)src + incr); >> +} >> + >> +static __inline void >> +ntohlp(void *dst, const void *src) >> +{ >> + /* We are aligned, so we think */ >> + *(uint32_t *)dst = htonl(*(const uint32_t *)src); >> +} >> + >> static bool_t >> clnt_vc_control(CLIENT *cl, u_int request, void *info) >> { >> @@ -576,14 +590,12 @@ clnt_vc_control(CLIENT *cl, u_int reques >> * first element in the call structure >> * This will get the xid of the PREVIOUS call >> */ >> - *(u_int32_t *)info = >> - ntohl(*(u_int32_t *)(void *)&ct->ct_u.ct_mcalli); >> + ntohlp(info, &ct->ct_u.ct_mcalli); >> break; >> case CLSET_XID: >> /* This will set the xid of the NEXT call */ >> - *(u_int32_t *)(void *)&ct->ct_u.ct_mcalli = >> - htonl(*((u_int32_t *)info) + 1); >> /* increment by 1 as clnt_vc_call() decrements once */ >> + htonlp(&ct->ct_u.ct_mcalli, info, 1); >> break; >> case CLGET_VERS: >> /* >> @@ -592,15 +604,11 @@ clnt_vc_control(CLIENT *cl, u_int reques >> * begining of the RPC header. MUST be changed if the >> * call_struct is changed >> */ >> - *(u_int32_t *)info = >> - ntohl(*(u_int32_t *)(void *)(ct->ct_u.ct_mcallc + >> - 4 * BYTES_PER_XDR_UNIT)); >> + ntohlp(info, ct->ct_u.ct_mcallc + 4 * BYTES_PER_XDR_UNIT); >> break; >> >> case CLSET_VERS: >> - *(u_int32_t *)(void *)(ct->ct_u.ct_mcallc + >> - 4 * BYTES_PER_XDR_UNIT) = >> - htonl(*(u_int32_t *)info); >> + htonlp(ct->ct_u.ct_mcallc + 4 * BYTES_PER_XDR_UNIT, info, 0); >> break; >> >> case CLGET_PROG: >> @@ -610,15 +618,11 @@ clnt_vc_control(CLIENT *cl, u_int reques >> * begining of the RPC header. MUST be changed if the >> * call_struct is changed >> */ >> - *(u_int32_t *)info = >> - ntohl(*(u_int32_t *)(void *)(ct->ct_u.ct_mcallc + >> - 3 * BYTES_PER_XDR_UNIT)); >> + ntohlp(info, ct->ct_u.ct_mcallc + 3 * BYTES_PER_XDR_UNIT); >> break; >> >> case CLSET_PROG: >> - *(u_int32_t *)(void *)(ct->ct_u.ct_mcallc + >> - 3 * BYTES_PER_XDR_UNIT) = >> - htonl(*(u_int32_t *)info); >> + htonlp(ct->ct_u.ct_mcallc + 3 * BYTES_PER_XDR_UNIT, info, 0); >> break; >> >> default: > > This change just deceives GCC's warning logic without changing whether > there is an aliasing violation or not (I don't think there is any when > clnt_vc.c is compiled separately, since *ct does not have an effective > type in that case). > Yes, I am trying to keep some changes in sync with NetBSD. They have some #ifdef 0'd code with memsets but the code is already ugly to worry about code that apparently is not ready yet. > To avoid casts, ct_mcalli could be changed to an array (of > MCALL_MSG_SIZE / 4 elements) and used. This also avoids depending on the > unspecified value of the elements 4 to 23 of ct_mcallc after storing to > ct_mcalli. > > Note that C89 did not permit type punning via a union. NetBSD might care > but we do not. C89 compilers are unlikely to be cunning enough for this > to be a problem anyway. > Hmm.. so C89 is probably the reason the linux guys are also doing the same, or uglier, workarounds. :(. > It may be that this code is too old for this kind of change. > I am just trying to put the forks in somewhat more consistent shape, and finding surprises in the way. I will probably put the more controversial changes in phabricator over the weekend. Pedro.