apache / nuttx

Apache NuttX is a mature, real-time embedded operating system (RTOS)
https://nuttx.apache.org/
Apache License 2.0
2.83k stars 1.17k forks source link

cmake/rv-virt: lacking support for `NSH_SYMTAB` and `ALLSYMS` #11304

Open yf13 opened 11 months ago

yf13 commented 11 months ago

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:

Is this issue in current CMake system or something else?

raiden00pl commented 11 months ago

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

yf13 commented 11 months ago

@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?

raiden00pl commented 11 months ago

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: