MainframeReboot commented on issue #12356: URL: https://github.com/apache/nuttx/issues/12356#issuecomment-2125712553
> > I have seen places where the ctor/dtor code is executed in binfmt > > Constructors and destructors should run in crti and crtN, respectively, for general Unix compatibility. crti should support __init and crtN should supporrt __fini. > > Lots more detail if you care about this: https://gcc.gnu.org/onlinedocs/gccint/Initialization.html > > As the OP mentioned, this is currently done with conditional logic in crt0. That is technically okay but will likely confuse people who are used to thinking about things in the GCC/GLIBC way. > > There is a long-open issue #1265 (and related #1263). Perhaps this is only a problem in PROTECTED mode which as a single set of ctors and dtors for the whole user-space blob. KERNEL mode uses only loadable ELF modules, each with their own ctors and dtors. > > crt0.c exists only for armv7-a, arm64, and riscv-5 all of which can support the KERNEL build. > > So crt0 with C++ ELF modules should never be used in PROTECTED mode right now or else you would get doubly constructed static classes. > > > I have seen places where the ctor/dtor code is executed in binfmt (there is a kconfig that controls this I believe, don't remember the name though) > > That is CONFIG_BINFMT_CONSTRUCTORS. I think that should be disabled in KERNEL mode to let the ELF module call its own constructors and destructors in the correct context. > > This seems awkward and prone to errors to me. I naively enabled CONFIG_BINFMT_CONSTRUCTORS as the prompt told me that it enables "C++ Static Constructor Support" so it seemed like something I should enable. I have turned this off. However, that alone did not solve the issue. I had to remove the calls `exec_ctores()` and `atexit(exec_dtors)` from `crt0.c` in order to not crash on ELF load. After doing this, helloxx starts up without issue although there still appears to be some issues with static constructors despite `CONFIG_HAVE_CXXINITIALIZE` being enabled. I am assuming this goes back crt0 not being used with C++ ELF modules. Perhaps I need the ctor/dtors calls inside my ELF files instead, I can try something like this. Regardless, I can live with NuttX kernel build that has no C++ static constructor support given everything else appears to be working flawlessly. -- 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