This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


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

Re: Question about -mpreferred-stack-boundary


"Geert Bosch" <bosch@gnat.com> writes:

> On 03 Feb 2001 11:37:35 +0100, Andreas Jaeger wrote:
> 
>   Who has to align the stack for calls to a function - the caller or the
>   callee?  In other words:  Does this mean that the stack has to be
>   aligned before calling a function?  Or does it have to be aligned when
>   entering a function?
> 
> >From the description you quote it seems that the stack will stay
> properly aligned if it was aligned to start with. This is done by
> ensuring that when function A calls B, the stack-pointer will
> be a multiple of the alignment lower than it was when A was called.

I should have descripted the problem in more detail: glibc's startup
code aligns the stack to 32 bytes - and then calls a function.  Now,
if you tell me that the stack has to be aligned (e.g. to 32 bytes)
*after* the push of the return address, then glibc is wrong - but if
it has to be aligned *before* the push of the return address, we might
have a bug in GCC.

> What I would think we'd need in addition is the ability to align
> a particular stack-frame more than the alignment we assume for
> the stack (by default 4 bytes on x86). This way, one could use 
> types with stricter alignment-requirements than the stack.
> 
> In Ada for example, we have to disallow any attempt to specify an
> alignment greater than 4 bytes, as we cannot *guarantee* that all
> objects will be properly aligned. It would be great if GCC could
> recognize that a certain stack-frame contains variables with a stricter
> alignment than the stack-alignment and aligns its stack frame.
> 
> Of course, this does not help at all for variables passed by value,
> which is what one can never guarantee on i386 because of the ABI.
> To solve this problem one would always pass objects with, for example,
> a 16-byte alignment requirement by reference. Especially with upcoming
> support for SSE instructions I think that enabling higher alignments
> would be a good thing.

32-byte alignment should be done by glibc (for ia32).  Or should it be
higher?

Andreas
-- 
 Andreas Jaeger
  SuSE Labs aj@suse.de
   private aj@arthur.inka.de
    http://www.suse.de/~aj

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