This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: ld 2.11: unaligned memory access for unions


> 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]