mirror of
https://github.com/apache/nuttx.git
synced 2026-09-09 10:26:37 +00:00
A C++ module with a static object does not link. GCC registers each such object's destructor with __cxa_atexit(dtor, obj, &__dso_handle), and __dso_handle comes from crtbegin, which a module does not link: hello++3.cxx:119: undefined reference to `__dso_handle' It is reachable today with CONFIG_PIC, where a module is linked as an executable and the symbol has to resolve. Without it the link is relocatable, the symbol stays undefined and nothing complains until something makes it resolve. -fno-use-cxa-atexit registers the destructors with atexit() instead, which puts them in .fini_array. That is also where libelf_uninit() looks for them when the module is unloaded, so the flag that makes the link work is also the flag that makes the destructors run. The option goes wherever CXXELFFLAGS is defined, which is the architecture Toolchain.defs and the boards that reassign it. The toolchains that are not GCC or Clang are left alone: ceva, tricore, z16 and the z80 family. The CMake build sets it once, next to where the architecture elf.cmake is included. A generator expression keeps it off the C compiles, because the option is valid for C++ alone and GCC warns about it otherwise, and the compiler id gates it so that a toolchain which is neither GCC nor Clang does not see it. It cannot go in the toolchain file itself: CMake reads that file again inside try_compile, in a project that has not included the NuttX extensions, so the call is an unknown command there. Reproduced with apps/examples/elf on mps3-an547:picostest with CONFIG_PIC enabled: hello++3 fails to link before and links after. Assisted-by: Claude Opus 5 (1M context) <noreply@anthropic.com> Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com> |
||
|---|---|---|
| .. | ||
| include | ||
| src | ||
| Kconfig | ||