This is an automated email from the ASF dual-hosted git repository. acassis pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 344540bb619a2c98b8e9861a93ea2acdc646ff0b Author: Marco Casaroli <[email protected]> AuthorDate: Tue Oct 20 00:00:17 2026 +0200 libs/libc: Export the gcov functions to loadable modules. Code that is built with the GCC coverage options calls __gcov_init() from a constructor and __gcov_exit() from a destructor, refers to __gcov_merge_add(), and calls __gcov_fork() in place of fork(). With CONFIG_COVERAGE_MINI the image has these functions, but the system symbol table does not export them, so an instrumented module does not load: "Exported symbol "__gcov_init" not found". Declare them in gcov.h and add them to libc.csv, together with __gcov_dump() and __gcov_reset(), so that a module can also dump or reset the coverage data. The other coverage runtimes do not change: libgcov of CONFIG_COVERAGE_TOOLCHAIN keeps its functions hidden, and the clang runtimes need other functions. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]> --- include/gcov.h | 23 +++++++++++++++++++++++ libs/libc/libc.csv | 6 ++++++ 2 files changed, 29 insertions(+) diff --git a/include/gcov.h b/include/gcov.h index 46c9ed34400..e225acc5d41 100644 --- a/include/gcov.h +++ b/include/gcov.h @@ -29,8 +29,15 @@ #include <nuttx/config.h> +#include <stdint.h> #include <sys/types.h> +/**************************************************************************** + * Public Types + ****************************************************************************/ + +struct gcov_info; + /**************************************************************************** * Public Function Prototypes ****************************************************************************/ @@ -65,6 +72,22 @@ extern void __gcov_dump(void); #if defined(CONFIG_COVERAGE_MINI) && defined(CONFIG_ARCH_TOOLCHAIN_GCC) +/**************************************************************************** + * Name: __gcov_init, __gcov_merge_add, __gcov_exit, __gcov_fork + * + * Description: + * The functions that instrumented code calls. The symbol table of the + * loadable modules takes them from here. + * + ****************************************************************************/ + +void __gcov_init(FAR struct gcov_info *info); +void __gcov_merge_add(FAR uint64_t *counters, unsigned int n_counters); +void __gcov_exit(void); +#ifdef CONFIG_ARCH_HAVE_FORK +pid_t __gcov_fork(void); +#endif + /**************************************************************************** * Name: __gcov_unload * diff --git a/libs/libc/libc.csv b/libs/libc/libc.csv index 451835fdbba..17080b6a087 100644 --- a/libs/libc/libc.csv +++ b/libs/libc/libc.csv @@ -1,6 +1,12 @@ "__assert","assert.h","","void","FAR const char *","int","FAR const char *" "__cxa_atexit","stdlib.h","","int","FAR CODE void (*)(FAR void *)|FAR void *","FAR void *","FAR void *" "__errno","errno.h","defined(CONFIG_BUILD_FLAT)","FAR int *" +"__gcov_dump","gcov.h","defined(CONFIG_COVERAGE_MINI) && defined(CONFIG_ARCH_TOOLCHAIN_GCC)","void" +"__gcov_exit","gcov.h","defined(CONFIG_COVERAGE_MINI) && defined(CONFIG_ARCH_TOOLCHAIN_GCC)","void" +"__gcov_fork","gcov.h","defined(CONFIG_COVERAGE_MINI) && defined(CONFIG_ARCH_TOOLCHAIN_GCC) && defined(CONFIG_ARCH_HAVE_FORK)","pid_t" +"__gcov_init","gcov.h","defined(CONFIG_COVERAGE_MINI) && defined(CONFIG_ARCH_TOOLCHAIN_GCC)","void","FAR struct gcov_info *" +"__gcov_merge_add","gcov.h","defined(CONFIG_COVERAGE_MINI) && defined(CONFIG_ARCH_TOOLCHAIN_GCC)","void","FAR uint64_t *","unsigned int" +"__gcov_reset","gcov.h","defined(CONFIG_COVERAGE_MINI) && defined(CONFIG_ARCH_TOOLCHAIN_GCC)","void" "__stack_chk_fail","ssp/ssp.h","defined(CONFIG_STACK_CANARIES)","void","void" "_alert","debug.h","!defined(CONFIG_CPP_HAVE_VARARGS) && defined(CONFIG_DEBUG_ERROR)","void","FAR const char *","..." "_err","debug.h","!defined(CONFIG_CPP_HAVE_VARARGS) && defined(CONFIG_DEBUG_ERROR)","void","FAR const char *","..."
