This is the mail archive of the gcc-patches@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]
Other format: [Raw text]

Re: [RFC] Dynamically aligning the stack


On Tue, Apr 21, 2015 at 9:52 AM, Steve Ellcey <sellcey@imgtec.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
>> alignment.
>
> 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:

'-mstackrealign'
     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
     functions.

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?
>

Please do

# git grep "stack_alignment_needed = "

to see how middle-end and backend track stack alignment requirement.

-- 
H.J.


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