Page 1 of 1
C++ exception support
Posted: Mon Jul 11, 2011 10:16 pm
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.
Re: C++ exception support
Posted: Tue Jul 12, 2011 7:16 am
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.
Re: C++ exception support
Posted: Tue Jul 12, 2011 2:41 pm
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
Re: C++ exception support
Posted: Tue Jul 12, 2011 3:39 pm
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;
}
Re: C++ exception support
Posted: Tue Jul 12, 2011 11:08 pm
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.
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
Re: C++ exception support
Posted: Tue Jul 12, 2011 11:12 pm
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.
Re: C++ exception support
Posted: Wed Jul 13, 2011 6:39 am
by qw
Okay, got it. Thank you guys.