ld 2.11: unaligned memory access for unions
Eberhard Mattes
mattes@azu.informatik.uni-stuttgart.de
Tue Jun 19 01:40:00 GMT 2001
> 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.
> True, but that would be a lot more work. I think that the easier
> solution would be to use your xmemcpy suggestion, although instead of
> using a #define alias, an explicit reference would be better.
Actually that is what I did. But that doesn't fix the bad cast.
Wrapping memcpy() just happens to work around the problem for GCC.
> Can you try this potentional patch for me and let me know it solves
> the problem ?
I haven't tried the patch yet, but it looks good, except for unsigned
vs. size_t.
Eberhard
More information about the Binutils
mailing list