casaroli opened a new pull request, #21464: URL: https://github.com/apache/nuttx/pull/21464
## Summary CONFIG_COVERAGE_COMPILER_RT does not compile on a build without CONFIG_ARCH_HAVE_FORK: `compiler-rt/lib/profile/GCDAProfiling.c:591: call to undeclared function 'fork'`. `__gcov_fork()` in the downloaded source calls fork(), and since 70c2ef5911c unistd.h declares fork() only with CONFIG_ARCH_HAVE_FORK. No defconfig in the tree selects this option, so CI does not build it. This PR adds a patch to the downloaded source, for the make and the CMake build. The patch builds `__gcov_fork()` only with CONFIG_ARCH_HAVE_FORK, as libgcc/gcov.c does. Instrumented code calls `__gcov_fork()` only in place of a call to fork(), and that call does not compile where fork() is not declared. So nothing needs the function there, and fork() stays undeclared. ## Impact Only builds that download compiler-rt change (LIB_COMPILER_RT). With CONFIG_ARCH_HAVE_FORK the code is the same as before. Without it the symbol `__gcov_fork` is not there. A source tree that is already in libs/libbuiltin/compiler-rt does not get the patch: run `make distclean` for a downloaded tree, and apply the patch by hand to a local checkout. The build now needs `patch` also for compiler-rt, as for the other downloaded libraries. No documentation change: Documentation/ says nothing about this function. ## Testing mps3-an547:clang, Homebrew clang 22.1.1 and lld, COVERAGE_COMPILER_RT. Make builds with EXTRAFLAGS="-Wno-cpp -Werror" and TESTING_OSTEST off (apps ostest_main.c has a clang warning that is not related). | compiler-rt, build | master | this PR | |---|---|---| | 17.0.1 make | error at GCDAProfiling.c:591 | GCDAProfiling.o builds, no `fork` and no `__gcov_fork` in its symbols | | 17.0.1 CMake | error at GCDAProfiling.c:591 | builds and links | | 18.1.8, 19.1.7 make | not run | GCDAProfiling.o as above, then BitmapFirst error in InstrProfilingPlatformOther.c | | 20.1.8, 21.1.1 make | not run | GCDAProfiling.o as above, then BitmapFirst and xf_float errors | | 21.1.1 CMake | not run | GCDAProfiling.c.o as above, then BitmapFirst and xf_float errors | This PR does not change the BitmapFirst and xf_float errors. They are in other files. To reach the link, 17.0.1 needs more than this PR. COVERAGE_ALL fails with `undefined symbol: atexit` when LIBC_MAX_EXITFUNS is 0, which is the default of this configuration. With LIBC_MAX_EXITFUNS=1 it overflows the flash of the board by 134704 bytes. So the run test uses LIBC_MAX_EXITFUNS=1 and instruments only examples/hello with `-fprofile-arcs -ftest-coverage`: it links with `llvm_gcov_init` and without `fork`, and under QEMU `hello` runs and returns to NSH. The run did not dump the coverage data. With fork declared: the same object built with `-DCONFIG_ARCH_HAVE_FORK=1` has `T __gcov_fork` and `U fork`. This is compile only. A kernel build with clang, where CONFIG_ARCH_HAVE_FORK is really set, was not built: qemu-armv7a:knsh with this clang stops at math.h in libc. The patch applies with `patch -F0` to 15.0.7, 16.0.6, 17.0.1, 18.1.8, 19.1.7, 20.1.8, 21.1.1 and 21.1.8. The outer `#if` of the function differs between these versions, so the hunks do not touch that line. I used the macOS `patch`, not GNU patch. Arm clang was not available. The runs and builds are on f19dbe6f6d3. The branch is now rebased on ba92fb6bc82 (no change in the touched files). -- 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]
