You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by "casaroli (via GitHub)" <gi...@apache.org> on 2026/10/19 13:15:39 UTC

[PR] build: Build a loadable module without the coverage options. [nuttx-apps]

casaroli opened a new pull request, #3886:
URL: https://github.com/apache/nuttx-apps/pull/3886

   ## Summary
   
   `CONFIG_COVERAGE_ALL` adds `-fprofile-arcs -ftest-coverage` (clang: `-fprofile-instr-generate -fcoverage-mapping`) to the compile options, and the module options `CELFFLAGS` and `CMODULEFLAGS` take them too. A loadable module of a flat or protected build then refers to `__gcov_init()`, `__gcov_merge_add()` and `__gcov_exit()`. The image has them, but the system symbol table does not export them, so no module loads. The simulator config `sim:nsh` has `CONFIG_COVERAGE_ALL`:
   
   ```
   libelf_symvalue: ERROR: SHN_UNDEF: Exported symbol "__gcov_init" not found
   nsh: hello: command not found
   ```
   
   This PR removes the coverage options from the compile options of a loadable module in `Application.mk` and `Library.mk`. The list is in `Make.defs` (`NOCOVERAGE`), and it is empty in a kernel build.
   
   ## Impact
   
   Builds with `CONFIG_COVERAGE_ALL` and loadable modules: the modules load, without coverage data. The image keeps its coverage, and the programs of a kernel build do not change.
   
   ## Testing
   
   Linux x86_64 simulator (Debian 12, gcc 12), `sim:nsh` with its own options (`CONFIG_COVERAGE_ALL`, `CONFIG_COVERAGE_TOOLCHAIN`), plus `CONFIG_ELF`, `CONFIG_EXECFUNCS_SYSTEM_SYMTAB`, `CONFIG_SIM_HOSTFS`, `CONFIG_EXAMPLES_HELLO=m` and `CONFIG_TESTING_GETPRIME=m`; modules loaded from hostfs:
   
   | | master | this PR |
   |---|---|---|
   | hello compile options | `-fprofile-arcs -ftest-coverage -fno-inline` | `-fno-inline` |
   | hello: undefined symbols | `__gcov_exit __gcov_init __gcov_merge_add puts` | `puts` |
   | run hello | `Exported symbol "__gcov_init" not found` | `Hello, World!!` |
   | run getprime | not run (the run stops at the first error); `nm` shows `U __gcov_init` | `found 1230 primes`, `Done` |
   | image: `sched_lock.c` compile | `-fprofile-arcs -ftest-coverage` | `-fprofile-arcs -ftest-coverage` |
   | image: `__gcov_init` | present | present |
   
   The test needs nuttx apache/nuttx#20807 (`get_environ_ptr` in libc.csv) to load any ELF program with the system symbol table. On arm, arm64, risc-v and x86_64 the module also links crt0, which nuttx compiles: apache/nuttx#20813 removes the options there and in the CMake build. On `qemu-armv8a:nsh` with `CONFIG_COVERAGE_ALL`, the modules load only with both PRs.
   
   `tools/checkpatch.sh -c -u -m -g` passes.
   


-- 
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-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] build: Keep coverage in a module only with CONFIG COVERAGE MINI. [nuttx-apps]

Posted by "casaroli (via GitHub)" <gi...@apache.org>.
casaroli closed pull request #3886: build: Keep coverage in a module only with CONFIG COVERAGE MINI.
URL: https://github.com/apache/nuttx-apps/pull/3886


-- 
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-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] build: Keep coverage in a module only with CONFIG COVERAGE MINI. [nuttx-apps]

Posted by "casaroli (via GitHub)" <gi...@apache.org>.
casaroli commented on code in PR #3886:
URL: https://github.com/apache/nuttx-apps/pull/3886#discussion_r4331085876


##########
Application.mk:
##########
@@ -27,15 +27,15 @@
 ifneq ($(MAINSRC),)
   ifeq ($(DYNLIB),y)
     BUILD_MODULE = y
-    MODAELFFLAGS = $(CMODULELFFLAGS)
-    MODCFLAGS = $(CMODULEFLAGS)
-    MODCXXFLAGS = $(CXXMODULEFLAGS)
+    MODAELFFLAGS = $(filter-out $(NOCOVERAGE),$(CMODULELFFLAGS))

Review Comment:
   Done in apache/nuttx#20813, without filter-out: the module options now end with the options that turn coverage off (`-fno-profile-arcs -fno-test-coverage`, clang: `-fno-profile-instr-generate -fno-coverage-mapping`), as `libs/libbuiltin` does for its own runtime. The arm and arm64 `Toolchain.defs` and the sim `Make.defs` add them to `CELFFLAGS`, `CMODULEFLAGS` and the C++ versions when a module cannot use the coverage runtime of the image, and `CMakeLists.txt` adds them to the ELF and module compile options. With apps master and `CONFIG_COVERAGE_TOOLCHAIN`, `hello` as a module now has no gcov symbol and runs; with `CONFIG_COVERAGE_MINI` it keeps its coverage. apps needs no change, so I close this PR.
   



-- 
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-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] build: Keep coverage in a module only with CONFIG COVERAGE MINI. [nuttx-apps]

Posted by "casaroli (via GitHub)" <gi...@apache.org>.
casaroli commented on code in PR #3886:
URL: https://github.com/apache/nuttx-apps/pull/3886#discussion_r4329028707


##########
Application.mk:
##########
@@ -27,15 +27,15 @@
 ifneq ($(MAINSRC),)
   ifeq ($(DYNLIB),y)
     BUILD_MODULE = y
-    MODAELFFLAGS = $(CMODULELFFLAGS)
-    MODCFLAGS = $(CMODULEFLAGS)
-    MODCXXFLAGS = $(CXXMODULEFLAGS)
+    MODAELFFLAGS = $(filter-out $(NOCOVERAGE),$(CMODULELFFLAGS))

Review Comment:
   The options come from `ARCHOPTIMIZATION` in `arch/arm/src/common/Toolchain.defs:77`, `arch/arm64/src/Toolchain.defs:142` and `boards/sim/sim/sim/scripts/Make.defs:77`, and `CELFFLAGS`, `CMODULEFLAGS` and the C++ versions copy `CFLAGS` (`arch/arm/src/common/Toolchain.defs:635-647`, `arch/arm64/src/Toolchain.defs:287-293`, `boards/sim/sim/sim/scripts/Make.defs:255,288`). I can remove the options there, in apache/nuttx#20813, with `$(filter-out $(ELF_NOCOVERAGE),$(CFLAGS))`. Then this PR is not necessary, and crt0 needs no separate filter. But 13 arm boards set `CELFFLAGS` or `CMODULEFLAGS` again from `$(CFLAGS)` in their `Make.defs` (for example `boards/arm/stm32h7/openh743i/scripts/Make.defs:42`, `boards/arm/imxrt/imxrt1170-evk/scripts/Make.defs:46`), so I must also change them, or first remove these lines, which only repeat the arch values. Is that OK for you?
   



-- 
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-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] build: Build a loadable module without the coverage options. [nuttx-apps]

Posted by "cederom (via GitHub)" <gi...@apache.org>.
cederom commented on code in PR #3886:
URL: https://github.com/apache/nuttx-apps/pull/3886#discussion_r4315992162


##########
Application.mk:
##########
@@ -27,15 +27,15 @@
 ifneq ($(MAINSRC),)
   ifeq ($(DYNLIB),y)
     BUILD_MODULE = y
-    MODAELFFLAGS = $(CMODULELFFLAGS)
-    MODCFLAGS = $(CMODULEFLAGS)
-    MODCXXFLAGS = $(CXXMODULEFLAGS)
+    MODAELFFLAGS = $(filter-out $(NOCOVERAGE),$(CMODULELFFLAGS))

Review Comment:
   +1 here to @xiaoxiang781216 :-)



-- 
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-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] build: Keep coverage in a module only with CONFIG COVERAGE MINI. [nuttx-apps]

Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #3886:
URL: https://github.com/apache/nuttx-apps/pull/3886#discussion_r4329203076


##########
Application.mk:
##########
@@ -27,15 +27,15 @@
 ifneq ($(MAINSRC),)
   ifeq ($(DYNLIB),y)
     BUILD_MODULE = y
-    MODAELFFLAGS = $(CMODULELFFLAGS)
-    MODCFLAGS = $(CMODULEFLAGS)
-    MODCXXFLAGS = $(CXXMODULEFLAGS)
+    MODAELFFLAGS = $(filter-out $(NOCOVERAGE),$(CMODULELFFLAGS))

Review Comment:
   It is better to avoid filter-out by set all flags with the correct value in Toolchain.defs



-- 
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-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] build: Build a loadable module without the coverage options. [nuttx-apps]

Posted by "casaroli (via GitHub)" <gi...@apache.org>.
casaroli commented on code in PR #3886:
URL: https://github.com/apache/nuttx-apps/pull/3886#discussion_r4319224552


##########
Application.mk:
##########
@@ -27,15 +27,15 @@
 ifneq ($(MAINSRC),)
   ifeq ($(DYNLIB),y)
     BUILD_MODULE = y
-    MODAELFFLAGS = $(CMODULELFFLAGS)
-    MODCFLAGS = $(CMODULEFLAGS)
-    MODCXXFLAGS = $(CXXMODULEFLAGS)
+    MODAELFFLAGS = $(filter-out $(NOCOVERAGE),$(CMODULELFFLAGS))

Review Comment:
   Exporting the gcov functions alone is not enough: `__gcov_init()` adds the gcov_info of a module to the list of the runtime, and it stays there after the module is unloaded, so the next dump reads freed memory.
   
   With `CONFIG_COVERAGE_MINI` (libs/libbuiltin gcov.c) I will export the functions to modules and add a hook that removes (and first dumps) the gcov_info of a module when the loader unloads it. Then modules keep their coverage options.
   
   With `CONFIG_COVERAGE_TOOLCHAIN` (sim:nsh in CI) the runtime is libgcov: there is no call to remove one gcov_info, and the `__gcov_exit()` of a module dumps the data of the whole image, marks it dumped and unlinks it. A correct fix gives each module its own libgcov, as a shared library has on Linux. Which behaviour do you need there: keep building modules without coverage with libgcov, export the functions anyway (a module that is unloaded before the dump breaks the later dumps), or is your setup one where modules are never unloaded before the dump?
   



-- 
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-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] build: Build a loadable module without the coverage options. [nuttx-apps]

Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #3886:
URL: https://github.com/apache/nuttx-apps/pull/3886#discussion_r4315950772


##########
Application.mk:
##########
@@ -27,15 +27,15 @@
 ifneq ($(MAINSRC),)
   ifeq ($(DYNLIB),y)
     BUILD_MODULE = y
-    MODAELFFLAGS = $(CMODULELFFLAGS)
-    MODCFLAGS = $(CMODULEFLAGS)
-    MODCXXFLAGS = $(CXXMODULEFLAGS)
+    MODAELFFLAGS = $(filter-out $(NOCOVERAGE),$(CMODULELFFLAGS))

Review Comment:
   but why not fix the linker error to support coverage for module too



-- 
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-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] build: Keep coverage in a module only with CONFIG COVERAGE MINI. [nuttx-apps]

Posted by "casaroli (via GitHub)" <gi...@apache.org>.
casaroli commented on code in PR #3886:
URL: https://github.com/apache/nuttx-apps/pull/3886#discussion_r4319972442


##########
Application.mk:
##########
@@ -27,15 +27,15 @@
 ifneq ($(MAINSRC),)
   ifeq ($(DYNLIB),y)
     BUILD_MODULE = y
-    MODAELFFLAGS = $(CMODULELFFLAGS)
-    MODCFLAGS = $(CMODULEFLAGS)
-    MODCXXFLAGS = $(CXXMODULEFLAGS)
+    MODAELFFLAGS = $(filter-out $(NOCOVERAGE),$(CMODULELFFLAGS))

Review Comment:
   Done for `CONFIG_COVERAGE_MINI` with GCC: modules now keep their coverage. libc.csv exports the gcov functions, and `libelf_uninit()` calls a new `__gcov_unload()`, which removes the gcov_info of the module from the list before the module memory is freed (`dlclose()`, `rmmod()`, the exit of an `exec()` program). The data of a module must be dumped while it is loaded (`gcov -d`, or `__gcov_dump()` in the module). Without the unload hook, the first dump after an unload hangs on the freed gcov_info; with it, 25 load/unload cycles and 40 `dlopen()`/`dlclose()` cycles, then a dump, pass.
   
   With libgcov and the clang runtimes, modules stay without coverage for now; the question above about libgcov stays open.
   



-- 
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-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] build: Keep coverage in a module only with CONFIG COVERAGE MINI. [nuttx-apps]

Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #3886:
URL: https://github.com/apache/nuttx-apps/pull/3886#discussion_r4327625084


##########
Application.mk:
##########
@@ -27,15 +27,15 @@
 ifneq ($(MAINSRC),)
   ifeq ($(DYNLIB),y)
     BUILD_MODULE = y
-    MODAELFFLAGS = $(CMODULELFFLAGS)
-    MODCFLAGS = $(CMODULEFLAGS)
-    MODCXXFLAGS = $(CXXMODULEFLAGS)
+    MODAELFFLAGS = $(filter-out $(NOCOVERAGE),$(CMODULELFFLAGS))

Review Comment:
   let's don't add coverage option in the first place instead patching here



-- 
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-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org