This is the mail archive of the
ecos-patches@sources.redhat.com
mailing list for the eCos project.
Re: mainthread.cxx - unaligned stack possible
- From: Gary Thomas <gary at mlbassoc dot com>
- To: Larice Robert <larice at vidisys dot de>
- Cc: Jonathan Larmour <jifl at eCosCentric dot com>,eCos patches <ecos-patches at sources dot redhat dot com>
- Date: 09 Mar 2003 10:58:13 -0700
- Subject: Re: mainthread.cxx - unaligned stack possible
- References: <200303091742.h29Hgg311926@doms.vidisys.com>
On Sun, 2003-03-09 at 10:42, Larice Robert wrote:
> > Scott Furman wrote:
> > >
> > >
> > > eCos provides the stack for main() when building with libc startup
> > > support and CYGSEM_LIBC_MAIN_STACK_FROM_SYSTEM is defined. However, the
> > > stack is declared as an array of cyg_uint8, so there is the possibility
> > > that it is unaligned.
> >
> > Hmm.. I thought the linker was meant to do this for statics/globals. Oh
> > well, let's err on the side of caution...
> >
> > > The attached trivial fix ensures that the stack
> > > is at least octlet-aligned. (Does any architecture require an alignment
> > > stricter than 8 bytes ?)
> >
> > Some can. I've checked in a slightly better version (attached).
> >
> > Jifl
>
> Hello Jonathan Larmour,
>
> obviously the linker does not what you thought.
> i've a small test case here:
>
>
But, you didn't add the "alignment magic" that Jonathan did.
Try it like this:
#define CYGBLD_ATTRIB_ALIGN(__align__) __attribute__((aligned(__align__)))
char obj0[3][5] CYGBLD_ATTRIB_ALIGN(8);
char obj1[3][5] CYGBLD_ATTRIB_ALIGN(16);
etc.
> file alignment.c :
>
> char obj0[3][5];
> char obj1[3][5];
> char obj2[3][5];
> char obj3[3][5];
>
> main() {;}
>
>
> file Makefile :
>
> prefix=/u2/larice/tools-sh-elf-v2/bin/sh-elf-
>
> all :
> $(prefix)gcc -ml -m3 -o alignment alignment.c
> $(prefix)nm alignment | grep obj
>
>
> produces the following output :
>
> 00002b37 B _obj0
> 00002b46 B _obj1
> 00002b28 B _obj2
> 00002b55 B _obj3
>
> obviously obj0 and obj3 are NOT 32 bit aligned.
>
>
> several month ago i've sent a patch to fix this for 200 or so global
> arrays occuring in the ecos source code.
> (http://sources.redhat.com/ml/ecos-patches/2002-06/msg00021.html)
> all of them 2 dimensional char arrays, which are used for
> stack purpose or for other things requiring some alignment.
>
> would you please consider to apply this patch, or something else to
> fix this ? this is a really uggly problem of ecos and would well be
> repaired in the upcomming 2.0 .
>
> Thank you,
> Robert Larice
--
------------------------------------------------------------
Gary Thomas |
MLB Associates | Consulting for the
+1 (970) 229-1963 | Embedded world
http://www.mlbassoc.com/ |
email: <gary at mlbassoc dot com> |
gpg: http://www.chez-thomas.org/gary/gpg_key.asc
------------------------------------------------------------