[ECOS] Main stack alignment

Jonathan Larmour jifl@eCosCentric.com
Fri May 23 02:32:00 GMT 2003


Daniel Lidsten wrote:
> Hi,
> 
> When i allocate two structures in the main loop then they will be place
> with an 8 bytes alignment in the main_stack. Why is that?
> 
> The stack is declared as:
> static cyg_uint8 cyg_libc_main_stack[
> CYGNUM_LIBC_MAIN_DEFAULT_STACK_SIZE ] in mainthread.cxx;
> 
> ...and placed in the .bss section by the linker script.
> 
> The odd thing is that if i declare my structures as static or make them
> global, then they are 2-byte aligned. How come? I want my structures to
> be 2 byte aligned even when i declare them inside main.

IIRC GCC often takes a pessimistic view of stack alignment and assumes it 
may not be well aligned and so aligns it itself.

For static/global stuff, the linker puts it at a well defined address and 
can therefore be sure of its address.

You may be able to override GCC's behaviour on the command line depending 
on your architecture.

Jifl
-- 
eCosCentric    http://www.eCosCentric.com/    The eCos and RedBoot experts
--[ "You can complain because roses have thorns, or you ]--
--[  can rejoice because thorns have roses." -Lincoln   ]-- Opinions==mine


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



More information about the Ecos-discuss mailing list