From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Cooper Subject: Re: [PATCH 1/2] xen-detect: fix strict-aliasing compilation warning. Date: Wed, 3 Dec 2014 15:44:48 +0000 Message-ID: <547F2FF0.9000201@citrix.com> References: <1417444646-20636-1-git-send-email-john.haxby@oracle.com> <1417444646-20636-2-git-send-email-john.haxby@oracle.com> <547CA220.9070604@citrix.com> <309AAB3D-A4EE-485C-BE09-AAC4192E7F27@oracle.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============6305509876595795036==" Return-path: In-Reply-To: <309AAB3D-A4EE-485C-BE09-AAC4192E7F27@oracle.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: John Haxby Cc: xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org --===============6305509876595795036== Content-Type: multipart/alternative; boundary="------------050902070405050302090504" --------------050902070405050302090504 Content-Type: text/plain; charset="utf-8" Content-Length: 1722 Content-Transfer-Encoding: quoted-printable On 01/12/14 18:45, John Haxby wrote: > >> On 1 Dec 2014, at 17:15, Andrew Cooper > > wrote: >> >> On 01/12/14 14:37, John Haxby wrote: >>> With gcc 4.8.3, compiling xen-detect gives a compilation warning if >>> you're optimising: >>> >>> $ cc -Wall -Os xen-detect.c >>> xen-detect.c: In function =E2=80=98check_for_xen=E2=80=99: >>> xen-detect.c:65:9: warning: dereferencing type-punned pointer will break >>> strict-aliasing rules [-Wstrict-aliasing] >>> *(uint32_t *)(signature + 0) =3D regs[1]; >>> ^ >>> >>> Signed-off-by: John Haxby >> > >> >> Why are you compiling without the CFLAGS from the Xen build system=3F >> >> We explicitly disable strict alias optimisations, because optimisations >> based upon the aliasing rules in C is mad. Even when you eliminate all >> the warnings, there are still subtle bugs because the compiler is free >> to assume a lot more than a programmer would typically deem reasonable. > > > I wasn=E2=80=99t building the whole system, I just wanted xen-detect so I > pulled it out and compiled it; I usually use "-Wall -Os=E2=80=9D because the > combination finds problems I might otherwise overlook. The patch > also removes three lines of code :) but you can take it or leave it as > you choose. The other patch =E2=80=94 reversing the code of pv and hvm > checking =E2=80=94 was the real problem. > > jch I feel it would be neater to fix this by using the XEN_CPUID_SIGNATURE_E{B,C,D}X constants from the API. This fixes the strict aliasing, and does away with the string handling completely. ~Andrew --------------050902070405050302090504 Content-Type: text/html; charset="utf-8" Content-Length: 9822 Content-Transfer-Encoding: quoted-printable
On 01/12/14 18:45, John Haxby wrote:

On 1 Dec 2014, at 17:15, Andrew Cooper <andrew.cooper3@citrix.com> wrote:

On 01/12/14 14:37, John Haxby wrote:
With gcc 4.8.3, compiling xen-detect gives a compilation warning if
you're optimising:

$ cc -Wall -Os xen-detect.c
xen-detect.c: In function =E2=80=98check_for_xen=E2=80=99:
xen-detect.c:65:9: warning: dereferencing type-punned pointer will break
strict-aliasing rules [-Wstrict-aliasing]
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0*(uint32_t *)(signature + 0) =3D regs[1];
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0^

Signed-off-by: John Haxby <john.haxby@oracle.com>

Why are you compiling without the CFLAGS from the Xen build system=3F

We explicitly disable strict alias optimisations, because optimisations
based upon the aliasing rules in C is mad. =C2=A0Even when you eliminate all
the warnings, there are still subtle bugs because the compiler is free
to assume a lot more than a programmer would typically deem reasonable.


I wasn=E2=80=99t building the whole system, I just wanted xen-detect so I pulled it out and compiled it; I usually use "-Wall -Os=E2=80=9D because the combination finds problems I might otherwise overlook. =C2=A0 The patch also removes three lines of code :) but you can take it or leave it as you choose. =C2=A0 The other patch =E2=80=94 reversing the code of pv and hvm checking =E2=80=94 was the real problem.

jch

I feel it would be neater to fix this by using the XEN_CPUID_SIGNATURE_E{B,C,D}X constants from the API.=C2=A0 This fixes the strict aliasing, and does away with the string handling completely.

~Andrew
--------------050902070405050302090504-- --===============6305509876595795036== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --===============6305509876595795036==--