From owner-freebsd-current@FreeBSD.ORG Mon Jul 28 11:55:32 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 77DE837B408 for ; Mon, 28 Jul 2003 11:55:32 -0700 (PDT) Received: from k6.locore.ca (k6.locore.ca [198.96.117.170]) by mx1.FreeBSD.org (Postfix) with ESMTP id B2D6943F3F for ; Mon, 28 Jul 2003 11:55:31 -0700 (PDT) (envelope-from jake@locore.ca) Received: by k6.locore.ca (Postfix, from userid 1000) id 723961E00A; Mon, 28 Jul 2003 14:54:49 -0400 (EDT) Date: Mon, 28 Jul 2003 14:54:49 -0400 From: Jake Burkholder To: Jun Kuriyama , Current Message-ID: <20030728185449.GA396@locore.ca> 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 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 18:55:32 -0000 Apparently, On Mon, Jul 28, 2003 at 03:59:00AM +0200, Thomas Moestl said words to the effect of; > On Mon, 2003/07/28 at 09:30:08 +0900, Jun Kuriyama wrote: > > > > Is this caused by -oS option? > > > > ----- in making BOOTMFS in make release > > cc -c -Os -pipe -Wall -Wredundant-decls -Wnested-externs -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Winline -Wcast-qual -fformat-extensions -std=c99 -nostdinc -I- -I. -I/usr/src/sys -I/usr/src/sys/dev -I/usr/src/sys/contrib/dev/acpica -I/usr/src/sys/contrib/ipfilter -I/usr/src/sys/contrib/dev/ath -I/usr/src/sys/contrib/dev/ath/freebsd -D_KERNEL -include opt_global.h -fno-common -finline-limit=15000 -mno-align-long-strings -mpreferred-stack-boundary=2 -ffreestanding -Werror /usr/src/sys/geom/geom_dev.c > > /usr/src/sys/geom/geom_dev.c: In function `g_dev_open': > > /usr/src/sys/geom/geom_dev.c:198: warning: dereferencing type-punned pointer will break strict-aliasing rules > > [...] > > 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 > casted pointer, which violates the C99 aliasing rules. > An alternative is to type-pun via a union, which is also a bit ugly, > but explicitly allowed by C99. Patch attached (but only superficially > tested). > > - Thomas > ... Using a union sounds fine to me. Jake