ld 2.11: unaligned memory access for unions
Ian Lance Taylor
ian@zembu.com
Tue Jun 19 10:52:00 GMT 2001
Eberhard Mattes <mattes@azu.informatik.uni-stuttgart.de> writes:
> > Ah OK I understand now. The code is deliberately casting a void *
> > pointer into a structure pointer, something which strictly speaking it
> > should not do, since GCC then (reasonably) assumes that the pointer is
> > aligned as required for the structure type.
>
> That cast invokes undefined behavior, so GCC has licence to do
> whatever it likes, including copying word by word.
What is the undefined behaviour here? Casting a void * pointer to a
struct pointer is defined. I agree that the void * pointer needs to
satisfy the alignment requirements of the struct, but I don't agree
that the void * pointer needs to satisfy any more strict alignment
requirements.
If BFD is casting a void * pointer which does not satisfy the
alignment requirements of the struct, then we need to understand why
that is happening. My reading of the code is that it should not
happen.
Ian
More information about the Binutils
mailing list