This is the mail archive of the
mailing list for the GCC project.
Re: [RFC] Dynamically aligning the stack
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: sellcey at imgtec dot com
- Cc: Jeff Law <law at redhat dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 21 Apr 2015 10:57:30 -0700
- Subject: Re: [RFC] Dynamically aligning the stack
- Authentication-results: sourceware.org; auth=none
- References: <d36dff8c-c009-4767-b6d6-bec02f7cf86d at BAMAIL02 dot ba dot imgtec dot org> <552CA316 dot 7060106 at redhat dot com> <1429029024 dot 30498 dot 147 dot camel at ubuntu-sellcey> <552D4724 dot 1090306 at redhat dot com> <CAMe9rOqK2b9qyJe3S+r79eD5QkDLvj9CQzg6nT+CoJ_s2pcO3Q at mail dot gmail dot com> <1429635164 dot 14613 dot 5 dot camel at ubuntu-sellcey>
On Tue, Apr 21, 2015 at 9:52 AM, Steve Ellcey <email@example.com> wrote:
> On Tue, 2015-04-14 at 10:08 -0700, H.J. Lu wrote:
>> We have done just that in GCC 4.4 to implement dynamic stack
>> alignment on x86 :-). Some of x86 backend changes for dynamic
>> stack alignment are x86 psABI specific. Others are historical,
>> like -mstackrealign. which was the old attempt for dynamic stack
> I am a bit confused about the history of stack alignment on x86. So I
> guess -mpreferred-stack-boundary=X came first and is not
> obsolete/depreciated. But I thought -mstackrealign=X was the current
> method of aligning the stack, but based on this comment and the patches
> you pointed me at I guess this is also obsolete (or at least deprecated)
> and that -mincoming-stack-boundary=X is the current option that should
> be used. But I am not sure how this option works.
-mpreferred-stack-boundary=X and -mincoming-stack-boundary=X
set stack alignment. -mstackrealign=X:
Realign the stack at entry. On the Intel x86, the '-mstackrealign'
option generates an alternate prologue and epilogue that realigns
the run-time stack if necessary. This supports mixing legacy codes
that keep 4-byte stack alignment with modern codes that keep
16-byte stack alignment for SSE compatibility. See also the
attribute 'force_align_arg_pointer', applicable to individual
assumes 4-byte incoming stack alignment in 32-bit. It isn't needed
in most cases since GCC has been generating 16-byte outgoing
stack alignment for ages.
> Obviously it tells GCC what assumption to make about stack alignment at
> the start of a function but how do you tell GCC what alignment you want
> for the function? Or does GCC figure that out for itself based on the
> instructions and data types it sees in the function?
# git grep "stack_alignment_needed = "
to see how middle-end and backend track stack alignment requirement.