huojianchaoyy opened a new pull request, #22600:
URL: https://github.com/apache/nuttx/pull/22600

   *Note: Please adhere to [Contributing 
Guidelines](https://github.com/apache/nuttx/blob/master/CONTRIBUTING.md).*
   
   ## Summary
   
   Updates to the kernel-side gcov runtime (`CONFIG_COVERAGE_MINI`) from Xiaomi 
Vela. Last of four coverage PRs; it contains the commits of #22599, and only 
the last eleven commits are new here.
   
   depends-on: apache/nuttx/pull/22599
   
   - **libs/libgcc: split coverage**: builds the coverage library for both 
kernel and user space, which fixes the `nuttx_user` link in protected builds.
   - **libs/libgcc: add gcov syscall** and **syscall: add gcov syscall**: add 
`gcov(GCOV_OP_RESET | GCOV_OP_DUMP)` so that a user-space application in a 
protected or kernel build can reset or dump the kernel's coverage data. The 
single-file dump now opens the file with `O_APPEND`, so the kernel data can go 
to the same file after the application's. The implementation comes first so 
that each commit builds; `include/sys/syscall_lookup.h` gets the 
`SYSCALL_LOOKUP()` entry, since it is not generated from syscall.csv.
   - **builtin/compiler-rt: add gcov syscall**: the same `gcov()` for the Clang 
runtime.
   - **coverage/clang: fix typo in Make.defs compiler flag**: 
`-fno-fprofile-use` -> `-fno-profile-use`. CMake already had it right.
   - **fix(gcov): prevent linked list cycle and add binary dump mode**: a 
sentinel and a duplicate insertion guard in `__gcov_init()` so that a 
constructor that runs twice cannot make the `gcov_info` list a cycle, a binary 
pack dump mode (`GCOV_PREFIX_STRIP > 0` in file mode) that tools/gcov.py 
unpacks, and skipping a file instead of aborting on an allocation failure. The 
list stays under `g_gcov_lock`.
   - **libs/libbuiltin/libgcc: skip gcov dump in panic/IRQ reboot notifier**: 
dump only on restart or power-off from task context; a dump from the assert 
path could fault and hide the original crash.
   - **libs/libbuiltin/gcov: bound path concat with strlcat**: long object 
paths overflowed the `PATH_MAX` path buffer and corrupted the coverage data.
   - **libgcc/gcov: buffer onefile-dump output to avoid 9pfs busyloop** and 
**libgcc/gcov: pre-encode hex body to one write to fix 9pfs busyloop**: write 
each file of the single-file dump in a few large writes instead of one write 
per header piece and per hex line, which took thousands of round trips on 9pfs.
   - **libbuitin: fix libcoverage name**: the CMake library was named 
`liblibcoverage.a`.
   
   ## Impact
   
   - New user API `gcov()` and syscall `SYS_gcov` with `CONFIG_COVERAGE_ALL`, 
in `<gcov.h>`.
   - The single-file dump appends to the file instead of truncating it.
   - New binary dump format when `GCOV_PREFIX_STRIP > 0` in file mode.
   - The reboot notifier no longer dumps on `SYS_HALT` or from interrupt 
context.
   - CMake: the coverage library is `libcoverage.a` instead of 
`liblibcoverage.a`.
   
   ## Testing
   
   Host: Ubuntu 22.04 (Linux 6.8, x86_64), host GCC 13.4, aarch64-none-elf-gcc 
13.4, arm-none-eabi-gcc 13.2.1, CMake 3.23 with Ninja. Base: master bec2b2a11e8.
   
   `./tools/checkpatch.sh -c -u -m -g HEAD~26..HEAD` passes.
   
   Each commit builds in these configurations (`CONFIG_COVERAGE_MINI=y`, 
`CONFIG_COVERAGE_ALL=y` unless noted):
   
   - `sim:nsh` (Make and CMake)
   - `qemu-armv8a:nsh` (CMake), `qemu-armv8a:nsh_smp` (Make), 
`qemu-armv8a:knsh` (Make)
   - `fvp-armv8r:pnsh` (Make)
   - `qemu-armv7r:pnsh` (Make, `CONFIG_COVERAGE_MINI` only, because the 
instrumented image does not fit in kflash)
   - `qemu-armv8a:nsh` without coverage (CMake)
   
   The protected and kernel builds (`qemu-armv8a:knsh`, `fvp-armv8r:pnsh`) 
generate `SYS_gcov` and its stub.
   
   Not tested: dumping to 9pfs, running the syscall from a user-space 
application, hardware.
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to