From: David Daney <ddaney@avtrex.com>
To: Tom Quarendon <tom@quarendon.net>
Cc: gcc@gcc.gnu.org, gcc help <gcc-help@gcc.gnu.org>
Subject: Re: Exception handling tables for function generated on the fly
Date: Tue, 12 Aug 2008 17:42:00 -0000 [thread overview]
Message-ID: <48A1C606.8090109@avtrex.com> (raw)
In-Reply-To: <48A1B059.1040400@quarendon.net>
Questions like this should probably go to gcc-help@gcc.gnu.org, but...
Tom Quarendon wrote:
> I'm porting some code that does a kind of JIT to translate a user script
> into a dynamically created function for execution, but am having trouble
> porting this to GCC and the way it implementes exceptions.
>
> Lets say I've got
> int doPUT() {
> throw IOException;
> }
>
> int doGET() {
> throw IOException
> }
>
> and I want to magic up a function by writing (intel x86) instructions
> into memory that does the same as if I'd done
>
> int magic() {
> doPUT();
> doGET();
> return 0;
> }
>
You don't say how you get them into memory. Are you building a shared library and then loading it with dlopen()?
> I then want to call my magic function as in
>
> int main() {
> // magic up my function in memory containing calls to doGET and doPUT.
> try {
> // call my magic'd function
> }
> catch (IOException) {
> // Report the exception
> }
> }
>
>
> If I do this I get std::terminate called from __cxa_throw. Researching
> this it seems that I somehow need to register some exception handling
> tables to correspond to the "magic" function to enable the exception
> handler to allow the exception to propagate through.
>
> I'd welcome any pointers to where I might be able to get some
> information on this. I've looked at the C++ ABI documentation which
> helps a bit, and I've found some information on the format that the
> tables need to be in (and indeed I've looked at the assembler generated
> by the gcc compiler if I code up "magic" and compile it directly), but I
> don't yet see quite how to put it all together.
>
If you pass -funwind-tables to gcc it will generate the necessary unwinding information. If you put the code in a shared library and dlopen() it it should just work.
If you are loading the code some other way, then you may have to call some of the __register_frame* family of functions (in libgcc) passing pointers to the appropriate .eh_frame sections of the generated code.
> I imagine that GCJ has do to this ind of thing?
>
g++ as well.
David Daney
next parent reply other threads:[~2008-08-12 17:19 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <48A1B059.1040400@quarendon.net>
2008-08-12 17:42 ` David Daney [this message]
2008-08-12 17:58 ` Dave Korn
2008-08-12 18:06 ` David Daney
2008-08-12 18:08 ` David Daney
2008-08-12 18:41 ` Dave Korn
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=48A1C606.8090109@avtrex.com \
--to=ddaney@avtrex.com \
--cc=gcc-help@gcc.gnu.org \
--cc=gcc@gcc.gnu.org \
--cc=tom@quarendon.net \
/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).