Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Stack alignement with pthreads



On Fri, Aug 29, 2008 at 10:14:26AM +0200, Anthony Mallet wrote:
> I think (?) it expects 16 bytes alignment, since the main starts with
>   andl      $-16, %esp

On i386 it seems to do:

/* Boundary (in *bits*) on which stack pointer should be aligned.  */
#define STACK_BOUNDARY BITS_PER_WORD

i.e. 1 byte is minimum, but:

/* Boundary (in *bits*) on which the stack pointer prefers to be
   aligned; the compiler cannot rely on having this alignment.  */
#define PREFERRED_STACK_BOUNDARY ix86_preferred_stack_boundary

so it usually aligns better. But:

/* As of July 2001, many runtimes to not align the stack properly when
   entering main.  This causes expand_main_function to forcibly align
   the stack, which results in aligned frames for functions called from
   main, though it does nothing for the alignment of main itself.  */
#define FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN \
  (ix86_preferred_stack_boundary > STACK_BOUNDARY && !TARGET_64BIT)

and this is the 16 byte alignement you see.

(Default for ix86_preferred_stack_boundary is 128, as you would guess by now).

Sounds reasonable to provide the same alignement for threads.

Martin


Home | Main Index | Thread Index | Old Index