[PATCH 6/6] [POWERPC] make struct property's value a void *

Segher Boessenkool segher at kernel.crashing.org
Fri Apr 6 09:26:26 EST 2007


>> It would remove the millions of casts (and the need for the GCC
>> -fstrict-aliasing flag for this code).
>
> Ugh ? We don't need casts with void *, that's the whole point ... while
> we would do if we used char * ...
>
> I'm not familiar with the details of the strict-breaking-good-programs
> rules also known as strict-aliasing but isn't void * supposed to alias
> all ?

Pointers never alias anything.  It's the data accesses
that matter.  You cannot access one type as another type
and expect it to work (unless one of those types is a
character type); that's the one simple rule.

Since you cannot access something with type "void"; no,
void pointers don't "alias" anything.

Perhaps you mean that you can cast any pointer to data to
"void *" and back to the same type.

> if not, that's really stupid... But even then, I fail to see how
> this would break an aliasing rule as we aren't accessing the same 
> object
> from two different types and we aren't even writing to it.

It doesn't matter whether you write to anything; you cannot
read the same data as two different types, either.

I'll have to trust you that the current code never does
that; it's really hard to see, with all the pointer casting
going around.

>> I agree.  However when making this code more generally useful,
>> it would be good to make it more correct at the same time, since
>> it will only get harder to do so later on.
>
> I think it's perfectly correct with void * ...

There's nothing wrong with a void * /per se/.  It's that
you need to cast it again later to access your data; and
I say you cast it to all kinds of wrong types, only u8 *
would be valid.  Feel free to ignore me though, at least
the PowerPC early boot makes sure all properties are
aligned to some power of two; as long as you never happen
to find a property where an int starts somewhere else
than a multiple of four into that property you should be
fine.  And SPARC can keep on depending on the OF it runs
on aligning everything by pure luck as far as I am concerned.

Other architectures won't be so lucky, so we'll just revisit
this when support for those is added.


Segher




More information about the Linuxppc-dev mailing list