c++: Define some support functions required by GCC#3107
c++: Define some support functions required by GCC#3107jnohlgard merged 7 commits intoRIOT-OS:masterfrom
Conversation
|
The cpp11_thread test fails on my machine for all Cortex-M0 platforms because of missing |
|
Sounds like I good idea. Moving the Regarding the Cortex-M0, I have only tested the code on the stm32f4discovery boards, hence the whitelist. I will see if I can get my hands on a Cortex-M0 take a look at the error. |
|
@josephnoir |
|
I did not actually test new and delete, I just assumed that they would not work properly without a custom implementation. Does GCC/newlib provide any fallbacks for those operators? |
|
If I recall correctly, the |
|
Regarding the problem on the Cortex-M0 I found this two threads on launchpad: one and two. It seems we need to implement an alternative atomic header if we want them on these boards. Or, maybe, they will offer support in the future ... (An atomic is only used at one point, for the reference count of the thread class. Alternatively we could use a mutex to guard the reference count and remove the dependency ...) |
|
@josephnoir If you can live with using C for the atomics we could change the reference count into an atomic_int_t and use atomic_inc and atomic_dec to modify it. |
|
It does however not solve the problem if any users try to use C++ atomics |
|
@josephnoir Thank you for your Launchpad research! After reading through the threads I think it might be possible to add implementations of One question though: Should I define the From the thread on LP it seems like the CM0 newlib or similar will provide these in the future, but currently doesn't. I will update this PR to provide simple implementations of the GCC builtin atomics. |
|
Opened #3115 for Cortex M0 support. |
|
Updated with __dso_handle defined weak. Fixes linker errors on native |
|
I can live with using an atomic implementation that works for most (or all) devices. If that is using C for atomics, so be it. However, did I understand your later comments correctly, i.e., #3115 can offer the missing atomic calls to allow the usage of the C++ atomic header (which would be much nicer fix and lead to better C++ support)? |
|
@josephnoir yes, #3115 introduces the helper functions that are necessary to support at least parts of https://gcc.gnu.org/wiki/Atomic/GCCMM/LIbrary is a not quite up to date page regarding the GCC 4.7 atomic work, it was the best I could find for describing the helper functions (see "list of library routines"). It mentions a couple of other functions in addition to the ones I implemented, but I got your example to compile using only the functions in #3115 . I did not try running it though, I don't have any board with an M0. |
|
Awesome! I can confirm that #3115 allows compiling the cpp11 tests for the samr21-xpro and the example I tested (cpp11_thread) works on the board. |
I would prefer the ifdef solution (even if it is definitely uglier), but the weak symbol is GCC dependent. |
|
I don't have any desire to use dynamic memory in any application right now and I don't have time to test it. In its current state, this PR adds the rudimentary support necessary for static constructors and virtual functions. @josephnoir OK to postpone any |
|
@gebart Yes, sounds good. (The thread implementation does use a new at the moment and works on the boards I tested ...) |
|
Rebased after #3115 was merged. |
|
@josephnoir OK to squash? |
|
Sorry, I am traveling a lot at the moment. What does the |
|
@josephnoir the |
2600287 to
c2de3c5
Compare
cppsupport.cpp contains functions which are necessary in order to use some features of the C++ language, e.g. calling static constructors or virtual functions. TODO/Not implemented yet: - Test virtual functions - Handle exceptions (stack unwinding) - Run time type identification (RTTI)
…mpat/cppsupport.cpp
- Remove BOARD_WHITELIST - Clean up CXXFLAGS - Clean up CFLAGS - Blacklist boards where the C++ library is too large on Travis
- Remove BOARD_WHITELIST - Clean up CXXFLAGS - Clean up CFLAGS - Blacklist boards where the C++ library is too large on Travis
- Remove BOARD_WHITELIST - Clean up CXXFLAGS - Clean up CFLAGS - Blacklist boards where the C++ library is too large on Travis
c2de3c5 to
f3330ab
Compare
|
rebased after the libfixmath_unittests build problems were fixed in #3470. Waiting for Travis. |
|
Travis is fine. Anyone care to ACK this? |
|
@josephnoir, @BytesGalore ping |
|
ACK |
|
I see an ACK and Travis being green. @gebart, if you wanna squash, go ahead, otherwise just hit the button! |
c++: Define some support functions required by GCC
GCC needs a definition of
void *__dso_handle = NULL;to handle global constructors. In order to use virtual functions there has to exist a definition of a fallback function when calling pure virtual functions to signal the error. This PR adds a new filecppsupport.cppinsidesys/cpp11-compatfor providing these symbols.TODO: also provide an implementation ofnewanddeletefor dynamic creation of objects.