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: Eberhard Mattes <mattes at azu dot informatik dot uni-stuttgart dot de>
- Subject: Re: ld 2.11: unaligned memory access for unions
- From: Ian Lance Taylor <ian at zembu dot com>
- Date: 19 Jun 2001 10:52:47 -0700
- Cc: nickc at cambridge dot redhat dot com, binutils at sources dot redhat dot com
- References: <200106190840.KAA22047@azu.informatik.uni-stuttgart.de>
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