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


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.

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.

  -Geert



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