On 01/12/14 18:45, John Haxby 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
|