cmake/rv-virt: lacking support for `NSH_SYMTAB` and `ALLSYMS`
For the rv-virt:nsh target, make approach works well, but CMake build leads to undefined symbols for g_symtab etc. It seems that defconfig has CONFIG_ALLSYMS off and CONFIG_NSH_SYMTAB on.
Further tests show that:
- When
CONFIG_NSH_SYMTABis on andCONFIG_ALLSYMSis off, Make build works but CMake fails. - When both
CONFIG_NSH_SYMTABandCONFIG_ALLSYMSare off, CMake build works. - When both
CONFIG_NSH_SYMTABandCONFIG_ALLSYMSare on, Makefile build works out a larger binary but CMake build leads to undefinedg_symtabetc.
Is this issue in current CMake system or something else?
Configurations with CONFIG_ALLSYMS needs to call tools/mkallsyms.py (or tools/mkallsyms.sh) which is not currently supported by cmake build system. Here's how it's done with make: https://github.com/apache/nuttx/blob/4f9d0149947cc3625726127e491cc5b8f978c690/arch/risc-v/src/Makefile#L164-L171
and something similar must be ported to cmake
@raiden00pl thanks a lot. The above point explains CMake's undefined errors when CONFIG_ALLSYMS=y .
How does Makefile system work well when CONFIG_ALLSYMS=n but CONFIG_NSH_SYMTAB=y? Does it contain logic so that undefined errors don't happen?
It looks like CONFIG_NSH_SYMTAB is also not supported for cmake. We have function to generate symbol table in cmake/nuttx_add_symtab.cmake but it's not called anywhere and it's quite possible that this logic hasn't been tested by anyone before.
How does Makefile system works well when CONFIG_ALLSYMS=n but CONFIG_NSH_SYMTAB=y? Does it contain logic so that undefined errors don't happen?
CONFIG_ALLSYMS depends on g_allsyms and is used for debug purposes (%pS and %ps format strings for printf, here doc from Linux https://www.kernel.org/doc/html/v4.19/core-api/printk-formats.html#symbols-function-pointers):
https://github.com/apache/nuttx/blob/4f9d0149947cc3625726127e491cc5b8f978c690/libs/libc/stdio/lib_libvsprintf.c#L1133-L1141
CONFIG_NSH_SYMTAB depends on symbol table called CONFIG_NSH_SYMTAB_ARRAYNAME which for upstream boards is usually g_symtab.
These are two separate symbol tables, generated in a different way:
CONFIG_NSH_SYMTABtable generated byapps/tools/mksymtab.sh(or mentioned earliercmake/nuttx_add_symtab.cmake)CONFIG_ALLSYMStable generated bynuttx/tools/mkallsyms.{py|sh}