diff --git a/cpu/cortexm_common/vectors_cortexm.c b/cpu/cortexm_common/vectors_cortexm.c index 6b90b2d56db1e5d0b32a6133c3e1a934b4de87e3..d73d1553446cfb7918853045fc6f637a7b96d97a 100644 --- a/cpu/cortexm_common/vectors_cortexm.c +++ b/cpu/cortexm_common/vectors_cortexm.c @@ -52,11 +52,6 @@ extern uint32_t _eram; */ #define STACK_CANARY_WORD 0xE7FEE7FEu -/** - * @brief Required by g++ cross compiler - */ -void *__dso_handle; - /** * @brief Pre-start routine for CPU-specific settings */ diff --git a/sys/Makefile.include b/sys/Makefile.include index 45ad55c440977b882249f6bd37778e084114d044..e55f67826a43394df002d7f50cfe8ae379b57588 100644 --- a/sys/Makefile.include +++ b/sys/Makefile.include @@ -26,6 +26,9 @@ endif ifneq (,$(filter cpp11-compat,$(USEMODULE))) USEMODULE_INCLUDES += $(RIOTBASE)/sys/cpp11-compat/include + # make sure cppsupport.o is linked explicitly because __dso_handle is not + # found if it is hidden away inside a static object. + export UNDEF += $(BINDIR)cpp11-compat/cppsupport.o endif ifneq (,$(filter gnrc_slip,$(USEMODULE))) diff --git a/sys/cpp11-compat/condition_variable.cpp b/sys/cpp11-compat/condition_variable.cpp index 791270997a8306971f1c6de9f843d15126d7dd68..1f2541d13321c9c9c64d05f0abf36e064a2f859f 100644 --- a/sys/cpp11-compat/condition_variable.cpp +++ b/sys/cpp11-compat/condition_variable.cpp @@ -18,12 +18,12 @@ * @} */ -#include <cstdio> #include <stdexcept> #include <system_error> #include "irq.h" #include "sched.h" +#include "timex.h" #include "vtimer.h" #include "priority_queue.h" diff --git a/sys/cpp11-compat/cppsupport.cpp b/sys/cpp11-compat/cppsupport.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2274b7a3054b2f58de34a8d02f0875039a099251 --- /dev/null +++ b/sys/cpp11-compat/cppsupport.cpp @@ -0,0 +1,147 @@ +/* + * Copyright (C) 2015 Eistec AB + * + * This file is subject to the terms and conditions of the GNU Lesser General + * Public License v2.1. See the file LICENSE in the top level directory for more + * details. + */ + +/** + * @ingroup cpp11-compat + * @{ + * + * @file + * @brief C++ runtime support functions + * + * Tested with GCC-4.9.2 and Clang-3.6 + * + * @author Joakim Gebart <joakim.gebart@eistec.se> + */ + +#include <new> +#include <cstddef> +#include <cstdlib> + +extern "C" { +#include "panic.h" +} + +/** + * @brief DSO handle + * + * This symbol is used by dynamic shared objects to identify them, but it is + * somehow pulled in as a dependency by the compiler-generated global (static) + * constructor code. + */ +void *__dso_handle __attribute__((weak)) = NULL; + +/** + * @brief Definition of a pure virtual function + * + * Calling this function is an error. + */ +extern "C" void __cxa_pure_virtual () +{ + core_panic(123, "PURE VIRTUAL CALL"); +} + +/** + * @brief Register a function to be called by exit or when a shared library is unloaded. + * + * Not really used on an embedded system where you pull the power to shut down + * the program. + * + * This is only called by code automatically generated by the C++ compiler. + * + * @return 0 on success + * @return non-zero on failure. + */ +extern "C" int __cxa_atexit (void (*) (void *), void *, void *) +{ + /* We just pretend everything is dandy. */ + return 0; +} + +namespace __gnu_cxx { +/** + * @brief Override the G++ verbose termination handler + * + * The default implementation of __gnu_cxx::__verbose_terminate_handler comes + * with gcc and will print the name of unhandled exceptions to stderr before + * terminating the program. However, in order to get the name of the exceptions + * a large chunk of name demangling code is pulled in as well (several tens of + * kBytes!). + * + * @note Depending on the version of the compiler and what settings were used + * when building the toolchain __gnu_cxx::__verbose_terminate_handler may or may + * not be pulled in. std::abort may be used instead by default in some + * toolchains. + * + * @see http://www.webalice.it/fede.tft/cpp_on_microcontrollers_tricks/cpp_on_microcontrollers_tricks.html + */ +void __verbose_terminate_handler() +{ + core_panic(123, "UNHANDLED C++ EXCEPTION"); +} +} /* namespace __gnu_cxx */ + +/* Implementations of new and delete operators taken from public domain code + * at http://pastebin.com/7VKUuTJa (downloaded on Wed 24 Jun 2015 09:00:07 PM CEST) + * Author: Eric Agan + * The license text reads: + * > "Public domain, use however you wish. + * > "If you really need a license, consider it MIT." + */ + +/* tinynew.cpp + + Overrides operators new and delete + globally to reduce code size. + + Public domain, use however you wish. + If you really need a license, consider it MIT: + http://www.opensource.org/licenses/mit-license.php + + - Eric Agan + Elegant Invention + */ + +void* operator new(std::size_t size) { + return std::malloc(size); +} + +void* operator new[](std::size_t size) { + return std::malloc(size); +} + +void operator delete(void* ptr) noexcept { + std::free(ptr); +} + +void operator delete[](void* ptr) noexcept { + std::free(ptr); +} + +/* Optionally you can override the 'nothrow' versions as well. + This is useful if you want to catch failed allocs with your + own debug code, or keep track of heap usage for example, + rather than just eliminate exceptions. + */ + +void* operator new(std::size_t size, const std::nothrow_t&) noexcept { + return std::malloc(size); +} + +void* operator new[](std::size_t size, const std::nothrow_t&) noexcept { + return std::malloc(size); +} + +void operator delete(void* ptr, const std::nothrow_t&) noexcept { + std::free(ptr); +} + +void operator delete[](void* ptr, const std::nothrow_t&) noexcept { + std::free(ptr); +} + +/** @} */ diff --git a/sys/cpp11-compat/include/riot/chrono.hpp b/sys/cpp11-compat/include/riot/chrono.hpp index 2e53c2be8734abefd9d4ef633d5a802f5058010c..8b332e6bded69295d97647a5b0667fbe1db034f9 100644 --- a/sys/cpp11-compat/include/riot/chrono.hpp +++ b/sys/cpp11-compat/include/riot/chrono.hpp @@ -26,7 +26,6 @@ #define RIOT_CHRONO_HPP #include <chrono> -#include <cstdio> #include <algorithm> #include "time.h" diff --git a/tests/cpp11_condition_variable/Makefile b/tests/cpp11_condition_variable/Makefile index 31f4446f7181616c7c8bd702864e7ab023d45eba..8cdd04026e80052dae2bb70448c65413f141d9e0 100644 --- a/tests/cpp11_condition_variable/Makefile +++ b/tests/cpp11_condition_variable/Makefile @@ -4,22 +4,28 @@ APPLICATION = cpp11_condition_variable # If no BOARD is found in the environment, use this default: BOARD ?= native +# ROM is overflowing for these boards when using +# gcc-arm-none-eabi-4.9.3.2015q2-1trusty1 from ppa:terry.guo/gcc-arm-embedded +# (Travis is using this PPA currently, 2015-06-23) +# Debian jessie libstdc++-arm-none-eabi-newlib-4.8.3-9+4 works fine, though. +# Remove this line if Travis is upgraded to a different toolchain which does +# not pull in all C++ locale code whenever exceptions are used. +BOARD_INSUFFICIENT_RAM := stm32f0discovery spark-core nucleo-f334 + # This has to be the absolute path to the RIOT base directory: RIOTBASE ?= $(CURDIR)/../.. # Comment this out to disable code in RIOT that does safety checking # which is not needed in a production environment but helps in the # development process: -CFLAGS += -DDEVELHELP -Wno-deprecated +CFLAGS += -DDEVELHELP # Change this to 0 show compiler invocation lines by default: QUIET ?= 1 -BOARD_WHITELIST := stm32f4discovery native - # If you want to add some extra flags when compile c++ files, add these flags # to CXXEXFLAGS variable -CXXEXFLAGS += -std=c++11 -g -O0 -Wno-deprecated +CXXEXFLAGS += -std=c++11 USEMODULE += cpp11-compat USEMODULE += vtimer diff --git a/tests/cpp11_mutex/Makefile b/tests/cpp11_mutex/Makefile index e247ae456a1c40f904586b84de1958057612a32b..ff57b41fcd1b987a388762cdef819e8107df0303 100644 --- a/tests/cpp11_mutex/Makefile +++ b/tests/cpp11_mutex/Makefile @@ -4,22 +4,28 @@ APPLICATION = cpp11_mutex # If no BOARD is found in the environment, use this default: BOARD ?= native +# ROM is overflowing for these boards when using +# gcc-arm-none-eabi-4.9.3.2015q2-1trusty1 from ppa:terry.guo/gcc-arm-embedded +# (Travis is using this PPA currently, 2015-06-23) +# Debian jessie libstdc++-arm-none-eabi-newlib-4.8.3-9+4 works fine, though. +# Remove this line if Travis is upgraded to a different toolchain which does +# not pull in all C++ locale code whenever exceptions are used. +BOARD_INSUFFICIENT_RAM := stm32f0discovery spark-core nucleo-f334 + # This has to be the absolute path to the RIOT base directory: RIOTBASE ?= $(CURDIR)/../.. # Comment this out to disable code in RIOT that does safety checking # which is not needed in a production environment but helps in the # development process: -CFLAGS += -DDEVELHELP -Wno-deprecated +CFLAGS += -DDEVELHELP # Change this to 0 show compiler invocation lines by default: QUIET ?= 1 -BOARD_WHITELIST := stm32f4discovery native - # If you want to add some extra flags when compile c++ files, add these flags # to CXXEXFLAGS variable -CXXEXFLAGS += -std=c++11 -g -O0 -Wno-deprecated +CXXEXFLAGS += -std=c++11 USEMODULE += cpp11-compat USEMODULE += vtimer diff --git a/tests/cpp11_thread/Makefile b/tests/cpp11_thread/Makefile index 49afd6a6be1da23caa6512bd4a2cea9a01a56647..93bea51fdc3409832e893a2dc114ed425aa292e2 100644 --- a/tests/cpp11_thread/Makefile +++ b/tests/cpp11_thread/Makefile @@ -4,22 +4,28 @@ APPLICATION = cpp11_thread # If no BOARD is found in the environment, use this default: BOARD ?= native +# ROM is overflowing for these boards when using +# gcc-arm-none-eabi-4.9.3.2015q2-1trusty1 from ppa:terry.guo/gcc-arm-embedded +# (Travis is using this PPA currently, 2015-06-23) +# Debian jessie libstdc++-arm-none-eabi-newlib-4.8.3-9+4 works fine, though. +# Remove this line if Travis is upgraded to a different toolchain which does +# not pull in all C++ locale code whenever exceptions are used. +BOARD_INSUFFICIENT_RAM := stm32f0discovery spark-core nucleo-f334 + # This has to be the absolute path to the RIOT base directory: RIOTBASE ?= $(CURDIR)/../.. # Comment this out to disable code in RIOT that does safety checking # which is not needed in a production environment but helps in the # development process: -CFLAGS += -DDEVELHELP -Wno-deprecated +CFLAGS += -DDEVELHELP # Change this to 0 show compiler invocation lines by default: QUIET ?= 1 -BOARD_WHITELIST := stm32f4discovery native - # If you want to add some extra flags when compile c++ files, add these flags # to CXXEXFLAGS variable -CXXEXFLAGS += -std=c++11 -g -O0 -Wno-deprecated +CXXEXFLAGS += -std=c++11 USEMODULE += cpp11-compat USEMODULE += vtimer