This is an automated email from the ASF dual-hosted git repository. xiaoxiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
The following commit(s) were added to refs/heads/master by this push: new 12476e1f43 RISC-V: add C++ support to crt0 12476e1f43 is described below commit 12476e1f43040ab864c24251e70aced225ee7d29 Author: Ville Juven <ville.ju...@unikie.com> AuthorDate: Fri Apr 29 09:45:08 2022 +0300 RISC-V: add C++ support to crt0 --- arch/risc-v/src/common/crt0.c | 51 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/arch/risc-v/src/common/crt0.c b/arch/risc-v/src/common/crt0.c index 0ca5815d68..9edfb5c3c1 100644 --- a/arch/risc-v/src/common/crt0.c +++ b/arch/risc-v/src/common/crt0.c @@ -88,6 +88,53 @@ static void sig_trampoline(void) ); } +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/* Linker defined symbols to .ctors and .dtors */ + +extern void (*_sctors)(void); +extern void (*_ectors)(void); +extern void (*_sdtors)(void); +extern void (*_edtors)(void); + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: exec_ctors + * + * Description: + * Call static constructors + * + ****************************************************************************/ + +static void exec_ctors(void) +{ + for (void (**ctor)(void) = &_sctors; ctor != &_ectors; ctor++) + { + (*ctor)(); + } +} + +/**************************************************************************** + * Name: exec_dtors + * + * Description: + * Call static destructors + * + ****************************************************************************/ + +static void exec_dtors(void) +{ + for (void (**dtor)(void) = &_sdtors; dtor != &_edtors; dtor++) + { + (*dtor)(); + } +} + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -124,9 +171,11 @@ void _start(int argc, char *argv[]) /* Call C++ constructors */ + exec_ctors(); + /* Setup so that C++ destructors called on task exit */ - /* REVISIT: Missing logic */ + atexit(exec_dtors); /* Call the main() entry point passing argc and argv. */