From owner-freebsd-current@FreeBSD.ORG Sun Jul 27 19:05:19 2003 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 8C20537B401 for ; Sun, 27 Jul 2003 19:05:19 -0700 (PDT) Received: from mail.gmx.net (mail.gmx.net [213.165.64.20]) by mx1.FreeBSD.org (Postfix) with SMTP id 4D19143F75 for ; Sun, 27 Jul 2003 19:05:18 -0700 (PDT) (envelope-from tmoestl@gmx.net) Received: (qmail 8362 invoked by uid 65534); 28 Jul 2003 02:05:17 -0000 Received: from p508E51E4.dip.t-dialin.net (EHLO galatea.local) (80.142.81.228) by mail.gmx.net (mp009) with SMTP; 28 Jul 2003 04:05:17 +0200 Received: from tmm by galatea.local with local (Exim 4.20 #1) id 19gxOJ-0000Bi-6t; Mon, 28 Jul 2003 04:05:35 +0200 Date: Mon, 28 Jul 2003 04:05:35 +0200 From: Thomas Moestl To: Jun Kuriyama , Current Message-ID: <20030728020534.GA678@crow.dom2ip.de> Mail-Followup-To: Jun Kuriyama , Current References: <7mwue3v6gf.wl@black.imgsrc.co.jp> <20030728015900.GB5628@crow.dom2ip.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20030728015900.GB5628@crow.dom2ip.de> User-Agent: Mutt/1.4.1i Sender: Thomas Moestl Subject: Re: dereferencing type-punned pointer will break strict-aliasing rules X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Jul 2003 02:05:19 -0000 On Mon, 2003/07/28 at 03:59:00 +0200, Thomas Moestl wrote: > Yes, by implying -fstrict-aliasing, so using -fno-strict-aliasing is a > workaround. The problem is caused by the i386 PCPU_GET/PCPU_SET > implementation: > > #define __PCPU_GET(name) ({ \ > __pcpu_type(name) __result; \ > \ > [...] > } else if (sizeof(__result) == 4) { \ > u_int __i; \ > __asm __volatile("movl %%fs:%1,%0" \ > : "=r" (__i) \ > : "m" (*(u_int *)(__pcpu_offset(name)))); \ > __result = *(__pcpu_type(name) *)&__i; \ > [...] > > In this case, the PCPU_GET is used to retrieve curthread, causing > sizeof(__result) to be 4, so the cast at the end of the code snippet > is from a u_int * to struct thread *, and __i is accessed through the ^^^^^^^^^^^^^^^ struct thread **, of course. > casted pointer, which violates the C99 aliasing rules. - Thomas -- Thomas Moestl http://www.tu-bs.de/~y0015675/ http://people.FreeBSD.org/~tmm/ PGP fingerprint: 1C97 A604 2BD0 E492 51D0 9C0F 1FE6 4F1D 419C 776C