OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Mar 29, 2024 2:27 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: C++ exception support
PostPosted: Mon Jul 11, 2011 10:16 pm 
Offline
Member
Member

Joined: Sun Jan 11, 2009 7:41 pm
Posts: 89
Hi, I have created wiki page http://wiki.osdev.org/C%2B%2B_Exception_Support , it's about how to add exception support for Itanium C++ ABI compiles. Currenty it's an orphaned page.
Feel free to correct any errors and make any improvements. :D


Top
 Profile  
 
 Post subject: Re: C++ exception support
PostPosted: Tue Jul 12, 2011 7:16 am 
Offline
Member
Member
User avatar

Joined: Mon Jan 26, 2009 2:48 am
Posts: 792
Maybe a little off topic, but this caught my eye:
Quote:
File scope static variable is slightly faster than function scope static variable
I wonder why that is.


Top
 Profile  
 
 Post subject: Re: C++ exception support
PostPosted: Tue Jul 12, 2011 2:41 pm 
Offline
Member
Member
User avatar

Joined: Fri Jun 13, 2008 3:21 pm
Posts: 1700
Location: Cambridge, United Kingdom
Hobbes wrote:
Maybe a little off topic, but this caught my eye:
Quote:
File scope static variable is slightly faster than function scope static variable
I wonder why that is.


File scope static is initialized at load time; function scope static is initialized at first call time with the resultant implication that there is a need to check if the variable is initialized on each call


Top
 Profile  
 
 Post subject: Re: C++ exception support
PostPosted: Tue Jul 12, 2011 3:39 pm 
Offline
Member
Member
User avatar

Joined: Fri Jun 13, 2008 3:21 pm
Posts: 1700
Location: Cambridge, United Kingdom
Your example is a trivial case involving a POD type. Try a non-POD type with a non-trivial constructor, or a non trivial initializer. For example,

Code:
struct Test { Test(); };

// Test() is not defined in this file, cannot be inlined, initialization code cannot be eliminated
static Test* getTest()
{
    static Test t;
    return &t;
}

// Also has non trivial initializer: "new int"
static int* getInteger()
{
    static int* myInt = new int;
    return myInt;
}


Top
 Profile  
 
 Post subject: Re: C++ exception support
PostPosted: Tue Jul 12, 2011 11:08 pm 
Offline
Member
Member

Joined: Sun Jan 11, 2009 7:41 pm
Posts: 89
berkus wrote:
torshie wrote:
Hi, I have created wiki page http://wiki.osdev.org/C%2B%2B_Exception_Support , it's about how to add exception support for Itanium C++ ABI compiles. Currenty it's an orphaned page.
Feel free to correct any errors and make any improvements. :D


Thanks, torshie, this looks really helpful. I thought about implementing some exception support for my IDL stubs, and native C++ support seems like a reasonable idea. libcxxrt is indeed very clean and simple, but libunwind is kinda big. I will look into ripping off only relevant parts of it into a simple package for kernel exceptions support. (LGPL is not an option, unfortunately).


Before I ported libgcc_eh, I succeeded (partially) in porting libunwind. Yes, it's kinda big, compiled binaries is about 200k, so I gave it up. I ported it in a similar way as I ported libgcc_eh. First try to compile all the source files under libunwind/src/unwind, then try to solve all the undefined references and missing headers. Delete some unnecessary funtions. The most difficult two depended headers are <elf.h> & <sys/ucontext.h>. You also need to implement a full-blown dl_iterate_phdr() and rewrite two libunwind asm files: getcontext.S & setcontext.S. All in all it's not that difficult to port libunwind. If you don't need multi-thread support, it can be done within 8 hours :D


Top
 Profile  
 
 Post subject: Re: C++ exception support
PostPosted: Tue Jul 12, 2011 11:12 pm 
Offline
Member
Member

Joined: Sun Jan 11, 2009 7:41 pm
Posts: 89
Owen wrote:
Your example is a trivial case involving a POD type. Try a non-POD type with a non-trivial constructor, or a non trivial initializer. For example,

Code:
struct Test { Test(); };

// Test() is not defined in this file, cannot be inlined, initialization code cannot be eliminated
static Test* getTest()
{
    static Test t;
    return &t;
}

// Also has non trivial initializer: "new int"
static int* getInteger()
{
    static int* myInt = new int;
    return myInt;
}


You're right, just checked the generated assembly, with trivial initializer, the generated assembly is the same. I have modified the wiki page.


Top
 Profile  
 
 Post subject: Re: C++ exception support
PostPosted: Wed Jul 13, 2011 6:39 am 
Offline
Member
Member
User avatar

Joined: Mon Jan 26, 2009 2:48 am
Posts: 792
Okay, got it. Thank you guys.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 19 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group