Subject: Re: Strange C compiler code generation
To: Peter Teichmann <teich-p@Rcs1.urz.tu-dresden.de>
From: Richard Earnshaw <rearnsha@buzzard.freeserve.co.uk>
List: port-arm32
Date: 02/25/2001 00:21:24
> > Are your structures marked as packed? If not, what compilation flags are
> > being used?
>
> Hm. They are. But: Still all variables are 32 bit aligned! And: Using gcc 2.95.2
> under Linux or RiscOS I do not get this strange behaviour. Why does NetBSD
> still use egcs?
>
> One example structure looks like this:
>
> #pragma pack(1)
>
> struct test {
> int a,b;
> };
>
> #pragma pack()
#prgama pack(1) means that this structure can appear at *any* address
(that's part of the definition of a packed structure). That includes odd
addresses, so the code must be compiled as a set of byte loads and the
final word built up from the bits. I'm not sure why linux is doing
differently, but it may well be a bug if it is.
From tm.texi (in the gcc documentation):
The pack pragma specifies the maximum alignment (in bytes) of fields
within a structure, in much the same way as the @samp{__aligned__} and
@samp{__packed__} @code{__attribute__}s do. A pack value of zero resets
the behaviour to the default.
> If I now do access the content of this structure, the ints are accessed by 4
> LDRBs and 3 ORRs, which is absolutely not necessary.
>
> Is there a chance that NetBSD/arm32 will soon use gcc 2.95.2?
Possibly, but it won't change anything, since the code generated is
correct for the supplied input.
Richard.