From b8c6c850421d0d81bb5ea9c340c4fcd958937165 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Thu, 17 Sep 2020 17:37:53 +0200 Subject: Add weak `std::terminate()` implementation This allows calling it from other places later. The default implementation calls `abort()`, but making it weak allows user code to override this function (either directly, or by including a library like uclibc++ that implements `std::set_terminate()`). Note that this does not add a declaration for this function, since the standard dictates this to be in ``, but we cannot meaningfully or completely implement that header, so better leave it to be overridden by e.g. libraries like uclibc++. --- cores/arduino/abi.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'cores/arduino/abi.cpp') diff --git a/cores/arduino/abi.cpp b/cores/arduino/abi.cpp index 8d719b8..b8f76cf 100644 --- a/cores/arduino/abi.cpp +++ b/cores/arduino/abi.cpp @@ -21,6 +21,12 @@ extern "C" void __cxa_pure_virtual(void) __attribute__ ((__noreturn__)); extern "C" void __cxa_deleted_virtual(void) __attribute__ ((__noreturn__)); +namespace std { + [[gnu::weak, noreturn]] void terminate() { + abort(); + } +} + void __cxa_pure_virtual(void) { // We might want to write some diagnostics to uart in this case //std::terminate(); -- cgit v1.2.3-18-g5258 From 66d06b033c3f6eafde901418be3c089ffcc6ebfc Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Thu, 17 Sep 2020 17:40:02 +0200 Subject: Call std::terminate on pure or deleted virtual functions These are special functions that are presumably put into vtables for deleted or pure virtual functions. Previously, this would call `abort()` directly, but calling `std::terminate()` achieves the same effect, but allows user code to change the behavior (e.g. to print to serial, blink leds or whatever makes sense). --- cores/arduino/abi.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'cores/arduino/abi.cpp') diff --git a/cores/arduino/abi.cpp b/cores/arduino/abi.cpp index b8f76cf..6e1b0f8 100644 --- a/cores/arduino/abi.cpp +++ b/cores/arduino/abi.cpp @@ -28,14 +28,9 @@ namespace std { } void __cxa_pure_virtual(void) { - // We might want to write some diagnostics to uart in this case - //std::terminate(); - abort(); + std::terminate(); } void __cxa_deleted_virtual(void) { - // We might want to write some diagnostics to uart in this case - //std::terminate(); - abort(); + std::terminate(); } - -- cgit v1.2.3-18-g5258