From: John Haxby <john.haxby@oracle.com>
To: Andrew Cooper <andrew.cooper3@citrix.com>, xen-devel@lists.xen.org
Subject: Re: [PATCH 1/2] xen-detect: fix strict-aliasing compilation warning.
Date: Wed, 03 Dec 2014 15:39:14 +0000 [thread overview]
Message-ID: <547F2EA2.5030702@oracle.com> (raw)
In-Reply-To: <547CA220.9070604@citrix.com>
On 01/12/14 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 ‘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@oracle.com>
>
> 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.
Do you want me to repost the second patch (the actual bug fix one) so
that it doesn't assume the line number changes and whatnot for this one?
jch
>
> ~Andrew
>
>> ---
>> tools/misc/xen-detect.c | 21 ++++++++++-----------
>> 1 file changed, 10 insertions(+), 11 deletions(-)
>>
>> diff --git a/tools/misc/xen-detect.c b/tools/misc/xen-detect.c
>> index 787b5da..19c66d1 100644
>> --- a/tools/misc/xen-detect.c
>> +++ b/tools/misc/xen-detect.c
>> @@ -54,28 +54,27 @@ static void cpuid(uint32_t idx, uint32_t *regs, int pv_context)
>>
>> static int check_for_xen(int pv_context)
>> {
>> - uint32_t regs[4];
>> - char signature[13];
>> + union
>> + {
>> + uint32_t regs[4];
>> + char signature[17];
>> + } u;
>> uint32_t base;
>>
>> for ( base = 0x40000000; base < 0x40010000; base += 0x100 )
>> {
>> - cpuid(base, regs, pv_context);
>> -
>> - *(uint32_t *)(signature + 0) = regs[1];
>> - *(uint32_t *)(signature + 4) = regs[2];
>> - *(uint32_t *)(signature + 8) = regs[3];
>> - signature[12] = '\0';
>> + cpuid(base, u.regs, pv_context);
>> + u.signature[16] = '\0';
>>
>> - if ( !strcmp("XenVMMXenVMM", signature) && (regs[0] >= (base + 2)) )
>> + if ( !strcmp("XenVMMXenVMM", u.signature+4) && (u.regs[0] >= (base + 2)) )
>> goto found;
>> }
>>
>> return 0;
>>
>> found:
>> - cpuid(base + 1, regs, pv_context);
>> - return regs[0];
>> + cpuid(base + 1, u.regs, pv_context);
>> + return u.regs[0];
>> }
>>
>> static jmp_buf sigill_jmp;
>
>
>
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xen.org
> http://lists.xen.org/xen-devel
>
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
next prev parent reply other threads:[~2014-12-03 15:39 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-01 14:37 Two miscellenous xen-detect patches John Haxby
2014-12-01 14:37 ` [PATCH 1/2] xen-detect: fix strict-aliasing compilation warning John Haxby
2014-12-01 17:15 ` Andrew Cooper
2014-12-01 18:45 ` John Haxby
2014-12-03 15:44 ` Andrew Cooper
2014-12-03 15:39 ` John Haxby [this message]
2014-12-03 15:51 ` Andrew Cooper
2014-12-01 14:37 ` [PATCH 2/2] xen-detect: check for XEN_PV before XEN_HVM John Haxby
2014-12-03 16:00 ` Andrew Cooper
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=547F2EA2.5030702@oracle.com \
--to=john.haxby@oracle.com \
--cc=andrew.cooper3@citrix.com \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.