C++ exception support

All about the OSDev Wiki. Discussions about the organization and general structure of articles and how to use the wiki. Request changes here if you don't know how to use the wiki.
Post Reply
torshie
Member
Member
Posts: 89
Joined: Sun Jan 11, 2009 7:41 pm

C++ exception support

Post by torshie »

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
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: C++ exception support

Post by qw »

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

Re: C++ exception support

Post by Owen »

Hobbes wrote:Maybe a little off topic, but this caught my eye:
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
User avatar
Owen
Member
Member
Posts: 1700
Joined: Fri Jun 13, 2008 3:21 pm
Location: Cambridge, United Kingdom
Contact:

Re: C++ exception support

Post by Owen »

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: Select all

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;
}
torshie
Member
Member
Posts: 89
Joined: Sun Jan 11, 2009 7:41 pm

Re: C++ exception support

Post by torshie »

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
torshie
Member
Member
Posts: 89
Joined: Sun Jan 11, 2009 7:41 pm

Re: C++ exception support

Post by torshie »

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: Select all

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.
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: C++ exception support

Post by qw »

Okay, got it. Thank you guys.
Post Reply