Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

fix C++ ABI stubs #95

kibergus opened this Issue Aug 14, 2012 · 2 comments


None yet
3 participants

Original arduino library has a limited C++ support, but it is done in a wrong way. And energia inherits these problems.



Introduce stubs for some internal compiler functions

int cxa_guard_acquire(guard *);
void cxa_guard_release (guard *);
void cxa_guard_abort (guard *);
void cxa_pure_virtual(void) __attribute ((noreturn));

They have folowing problems:
cxa_pure_virtual(void) must call std::terminate() or at leas abort(). But it must never return because program is already broken.
You also should add similar implementation for
void cxa_deleted_virtual(void) __attribute ((noreturn));

cxa_guard_* family must block all interrupts in cxa_guard_acquire and release them in cxa_guard_release and cxa_guard_abort because they are used for thread safe initialization of static variables. You can disable this feature with -fno-threadsafe-statics, but if you do provide it, please provide correct implementation

There is appropriate patch for avr, but I don't have enough knowledge of msp430 to port it to energia. Please adopt suggested changes.


I also suggest placing these functions in separate file called abi.h and abi.cpp because they have nothing to do with operator new.

This is really something that should directed at the mspgcc-mailing list or filed as a bug on sourceforge for mspgcc.

This is a hard question. These functions are part of libstdc++ which includes some other things, such as exception handling procedures. These are parts of C++ which nobody who understands how they work really needs on microcontrollers. So this library can't be built for embedded applications and agreement on building only a part of it would take quite a time. Until this happens you would have buggy implementation in your library waiting for a perfect solution.
I have quite a lot of things to do before trying to convince gcc people to do it.
There is another variant: uclibc++ imports part of libstdc++ including these functions. It is a lightweight variant of standard c++ library for gcc. But it requires port of uclibc++ to msp430 and inclusion of it to energia as one of the libraries. I'm not going to do it and I suspect that neither do you.

Just add abort() call to cxa_pure_virtual and define cxa_deleted_virtual the same way. Is is easy. As for cxa_guard_*, add -fno-threadsafe-statics to compiler options and remove them completely. This would produce the same behaviour as it is now, but without kludges and with smaller cleaner and faster code.

@rei-vilo rei-vilo closed this Oct 27, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment