From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18365 invoked by alias); 12 Aug 2008 17:19:50 -0000 Received: (qmail 18348 invoked by uid 22791); 12 Aug 2008 17:19:49 -0000 X-Spam-Check-By: sourceware.org Received: from smtp1.dnsmadeeasy.com (HELO smtp1.dnsmadeeasy.com) (205.234.170.134) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 12 Aug 2008 17:19:10 +0000 Received: from smtp1.dnsmadeeasy.com (localhost [127.0.0.1]) by smtp1.dnsmadeeasy.com (Postfix) with ESMTP id A4A1C320529; Tue, 12 Aug 2008 17:19:20 +0000 (UTC) X-Authenticated-Name: js.dnsmadeeasy X-Transit-System: In case of SPAM please contact abuse@dnsmadeeasy.com Received: from avtrex.com (unknown [67.116.42.147]) by smtp1.dnsmadeeasy.com (Postfix) with ESMTP; Tue, 12 Aug 2008 17:19:20 +0000 (UTC) Received: from dl2.hq2.avtrex.com ([192.168.7.26]) by avtrex.com with Microsoft SMTPSVC(6.0.3790.1830); Tue, 12 Aug 2008 10:19:04 -0700 Message-ID: <48A1C606.8090109@avtrex.com> Date: Tue, 12 Aug 2008 17:42:00 -0000 From: David Daney User-Agent: Thunderbird 2.0.0.16 (X11/20080723) MIME-Version: 1.0 To: Tom Quarendon Cc: gcc@gcc.gnu.org, gcc help Subject: Re: Exception handling tables for function generated on the fly References: <48A1B059.1040400@quarendon.net> In-Reply-To: <48A1B059.1040400@quarendon.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2008-08/txt/msg00122.txt.bz2 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