Source-Changes-D archive

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

Re: CVS commit: src/sys/arch/atari/stand/installboot



On Mon, Nov 24, 2014 at 02:36:51PM +0000, Taylor R Campbell wrote:
> 
> In the case of abcksum, if you have
> 
> uint8_t p[512];
> ...
> *((uint16_t *)p + 255) = 0;
> *((uint16_t *)p + 255) = abcksum(p);
> 
> GCC may choose to evaluate abcksum before the zero assignment, because
> no uint16_t is allowed to alias a uint8_t, so the assignment of an
> lvalue with type uint16_t can't change the value of abcksum(p).

Not sure, the accesses of p[] inside abcksum() are allowed to alias
any other memory - this includes wherever was written to by the
*((uint16_t *)xxxxxxx) = 0; regardless of any expected knowledge of
the value of xxxxxxx.

For gcc you can add "asm volatile("":::"memory);" to force it to
'forget' anything it thinks it knows about the contents of memory.

The original checksum code can be (mostly) fixed by only having
a single (uint16_t) cast.
You are then only left with problems caused if the checksum is inlined
and any earlier writes to the sector itself are still 'pending'.

	David

-- 
David Laight: david%l8s.co.uk@localhost


Home | Main Index | Thread Index | Old Index