This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: ld 2.11: unaligned memory access for unions
- To: nickc at cambridge dot redhat dot com
- Subject: Re: ld 2.11: unaligned memory access for unions
- From: Eberhard Mattes <mattes at azu dot informatik dot uni-stuttgart dot de>
- Date: Tue, 19 Jun 2001 10:40:15 +0200 (MET DST)
- CC: binutils at sources dot redhat dot com
> 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