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


On Tue, Jun 19, 2001 at 10:52:47AM -0700, Ian Lance Taylor wrote:
> 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.

And obviously you need to test any changes on a machine that traps on unaligned
accesses (ie, sparc or mips for example, not x86 or powerpc).

-- 
Michael Meissner, Red Hat, Inc.  (GCC group)
PMB 198, 174 Littleton Road #3, Westford, Massachusetts 01886, USA
Work:	  meissner@redhat.com		phone: +1 978-486-9304
Non-work: meissner@spectacle-pond.org	fax:   +1 978-692-4482


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