[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH 1/2] xen-detect: fix strict-aliasing compilation warning.



On 01/12/14 18:45, John Haxby wrote:

On 1 Dec 2014, at 17:15, Andrew Cooper <andrew.cooper3@xxxxxxxxxx> 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 âcheck_for_xenâ:
xen-detect.c:65:9: warning: dereferencing type-punned pointer will break
strict-aliasing rules [-Wstrict-aliasing]
ÂÂÂÂÂÂÂÂ*(uint32_t *)(signature + 0) = regs[1];
ÂÂÂÂÂÂÂÂ^

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

Why are you compiling without the CFLAGS from the Xen build system?

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ât building the whole system, I just wanted xen-detect so I pulled it out and compiled it; I usually use "-Wall -Osâ 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 â reversing the code of pv and hvm checking â 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
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.