This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: structure size


>>>>> "Grant" == Grant Edwards <grante@visi.com> writes:

    >> Not necessarily true.

    Grant> Perhaps it's not necissarily true, but it is in the case of
    Grant> GCC generating code for ARM and SPARC. I've tripped over it
    Grant> several times on both architectures (in my code and in
    Grant> others). If you pack a struct on those architectures using
    Grant> GCC, the resulting code will result in misaligned accesses
    Grant> if the struct members are misaligned (bus fault on SPARC
    Grant> and incorrect results on ARM7).

Try the following:

----------------------------------------------------------------------------
struct xyzzy {
    short   a;
    int     b;
} __attribute__((packed));

struct xyzzy data;

int
fred(void)
{
    data.b  = 42;
}
----------------------------------------------------------------------------

Compile with arm-elf-gcc -S. The assignment to data.b is implemented
using four separate strb instructions, as I would expect. If you try
reading data.b instead there will be four ldrb instructions plus
appropriate manipulation.

$ arm-elf-gcc --version
arm-elf-gcc (GCC) 3.2.1 (eCosCentric)
Copyright (C) 2002 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

I don't have a sparc-elf compiler handy at the moment so cannot check
that, but certainly arm-elf-gcc seems to do the right thing.

Bart

-- 
Bart Veer                       eCos Configuration Architect
http://www.ecoscentric.com/     The eCos and RedBoot experts

-- 
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss


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