public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Andrew Haley <aph@redhat.com>
To: Perry Smith <pedz@easesoftware.com>
Cc: MSX to GCC <gcc-help@gcc.gnu.org>
Subject: Re: alloca attribute?
Date: Wed, 29 Nov 2006 15:58:00 -0000	[thread overview]
Message-ID: <17773.44551.954051.164855@zebedee.pink> (raw)
In-Reply-To: <8699198A-45DC-45BD-8D19-C6497EC60D38@easesoftware.com>

Perry Smith writes:
 > On Nov 29, 2006, at 9:05 AM, Andrew Haley wrote:
 > 
 > > Perry Smith writes:
 > >> On Nov 29, 2006, at 8:24 AM, Andrew Haley wrote:
 > >>
 > >>> Perry Smith writes:
 > >> But then I hit upon this other idea (which may suck).  newStack
 > >> simply mucks with the stack and returns back to testit (the routine
 > >> that calls newStack).
 > >
 > > You're right.  It sucks.  :-)
 > >
 > >> I wish I could include some graphics but I'll try to describe it
 > >> with words.
 > >
 > > No, you've explained it perfectly well, but trust me here: it's a
 > > really bad idea.  gcc can eliminate the stack pointer to the frame
 > > pointer, as you have discovered.  gcc can also save a pointer to a
 > > local area on the stack, and that can be of indeterminate size.
 > >
 > > So gcc might do this
 > >
 > >    int a = 2;
 > >    p = &a;  // allocated on the stack
 > >    newStack();
 > >    *p = 3;
 > >    print a;
 > >
 > > And a, being on the new stack, would now be different from *p, which
 > > still points to the old stack.  It can't possibly work.
 > 
 > Ahh... I see.  It took me a while to figure out what you were saying.
 > 
 > Shoot!
 > 
 > o.k.  So if I go with the idea of newStack calling foo, will I need the
 > unwind stuff you mentioned before?  I'm somewhat terrified of
 > mucking with that but I probably need to learn how it works anyhow.

If you want to switch stacks, and you want to throw exceptions past
the switch, you'll have to create unwinder data, regardless of how you
do the stack switching.  Sorry.  If you catch all exceptions on the
other side of the stack switch so that they don't propagate past the
switch, you won't need unwinder data.

 > Is this what I need to read and understand?
 > http://www.codesourcery.com/cxx-abi/abi-eh.html
 > 
 > Or... do you have any ideas of a completely different approach somehow?

Well, I described how I thought it ought to work in a previous mail.

 > This is going to suck so bad...  all of my external entry points
 > need to move the stack.  I thought, briefly, gee, thats just the
 > five or so driver entry points.  But then there is the interrupt
 > handler, iodone, timer routines, all sorts of nasty things.

Moving the stack isn't at all unusual.  Operating systems do it all
the time.  But you've got to do it right.  Save the call-saved
registers, load fp and sp to point to the new area, and go.

Andrew.

      reply	other threads:[~2006-11-29 15:58 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-11-29  4:19 Perry Smith
2006-11-29 10:19 ` Andrew Haley
2006-11-29 14:17   ` Perry Smith
2006-11-29 14:25     ` Andrew Haley
2006-11-29 14:50       ` Perry Smith
2006-11-29 15:05         ` Andrew Haley
2006-11-29 15:30           ` Perry Smith
2006-11-29 15:58             ` Andrew Haley [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=17773.44551.954051.164855@zebedee.pink \
    --to=aph@redhat.com \
    --cc=gcc-help@gcc.gnu.org \
    --cc=pedz@easesoftware.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).