sigaltstack and cygwin

Matthew Fluet fluet@cs.cornell.edu
Fri, 1 Mar 2002 14:51:50 -0500 (EST)


> On a related note, the above restriction, and the similar one that we
> use for linux (%esp holds either the C stack pointer or frontier)
> should only be imposed on programs that install signal handlers.  I
> think that is an important optimization that we should put in.

I don't see the issue.  Or, rather, I think they are independent.  In
linux, %esp holds the C stack immediately before a C call and shortly
thereafter.  Also, %esp holds frontier at every basic block boundary that
isn't a a C call.  Otherwise, it's free to do what it wants.  In general,
blocks aren't so big with so many simultaneously live values that it makes
sense to spill %esp, but it could happen.  Now, I have stated that the
basic block transfer invariant is that frontier is in %esp and stackTop is
in %ebp.  It just happens that these are used so often, that they tend not
to be used for anything else.  I did specifically choose %esp to be in
frontier precisely because it's unlikely to be spilled -- that way, other
vars won't be in %esp and we won't need to shuffle if we need to index
with %esp (screwy x86 addressing modes don't allow %esp in index
position).  Also, if we ever made the heap grow the other way, we could
use push and pop with %esp to allocate. 

> Cygwin has no sigaltstack.  So, it seems to me that I need to change
> the x86-codegen so that %esp is reserved to hold the C stack pointer
> when targeting cygwin.  Does that seem right?  Easy?

That shouldn't be too hard.  Essentially, you or I'll need to muck with
x86-generate-tranfers.fun.  It should suffice to simply put an
x86.Directive.Assume of esp in c_stackP with reserve = true at the top of
every basic block when compiling with cygwin.  Also, change x86codegen.h
to set up whatever register conventions we want for that arch.

We'll lose some performance due to extra spilling with less registers.