pussuw commented on code in PR #6235: URL: https://github.com/apache/incubator-nuttx/pull/6235#discussion_r870691838
########## arch/risc-v/src/common/crt0.c: ########## @@ -88,6 +88,71 @@ static void sig_trampoline(void) ); } +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#if defined(__cplusplus) +extern "C" +{ +#endif + +/* Linker defined symbols to .ctors and .dtors */ + + extern void (*_sctors)(void); + extern void (*_ectors)(void); + extern void (*_sdtors)(void); + extern void (*_edtors)(void); + +#if defined(__cplusplus) +} +#endif + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +#if defined(__cplusplus) +extern "C" +{ +#endif + +/**************************************************************************** + * 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) Review Comment: This way is also fine, and a quite widely used solution for static C++ ctors/dtors is to just put them into the crt files. There is no defined / required way to do this, so this way should be enough. For the kernel build using the linker defined symbols is the simplest way to do this. Binfmt manually relocates ctors/dtors from the elf file to the binfmt structure. However, there is absolutely no reason to relocate ctors and dtors separately like binfmt does now. They are just initialized data, and data relocation does the work for us... I don't know why ctor/dtor handling was implemented in binfmt, as IMO it does not belong there. Maybe it is something needed by flat/protected ? TLS ctors/dtors is another approach, but the kernel mode does not need this. I agree it would unify the implementations for FLAT/PROTECTED, but the scope of this PR is the kernel build. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org