This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 0d0664e3d77 libs/libbuiltin/compiler-rt: Build __gcov_fork() only with 
fork().
0d0664e3d77 is described below

commit 0d0664e3d77f4358720d8f8f646ffa7c9bcdea50
Author: Marco Casaroli <[email protected]>
AuthorDate: Wed Nov 4 18:01:26 2026 +0100

    libs/libbuiltin/compiler-rt: Build __gcov_fork() only with fork().
    
    CONFIG_COVERAGE_COMPILER_RT does not compile on a flat build.
    GCDAProfiling.c calls fork() in __gcov_fork(), and unistd.h declares
    fork() only with CONFIG_ARCH_HAVE_FORK.
    
    Instrumented code reaches __gcov_fork() only in place of a call to fork(),
    and that call does not compile where fork() is not declared.  So do as
    libgcc/gcov.c does: build __gcov_fork() only with CONFIG_ARCH_HAVE_FORK.
    Add a patch to the downloaded source, in the Make and the CMake build.
    The patch applies to LLVM 15 to 21.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <[email protected]>
---
 ...-profile-Build-__gcov_fork-only-with-fork.patch | 26 ++++++++++++++++++++++
 libs/libbuiltin/compiler-rt/CMakeLists.txt         |  3 +++
 libs/libbuiltin/compiler-rt/Make.defs              |  1 +
 3 files changed, 30 insertions(+)

diff --git 
a/libs/libbuiltin/compiler-rt/0001-compiler-rt-profile-Build-__gcov_fork-only-with-fork.patch
 
b/libs/libbuiltin/compiler-rt/0001-compiler-rt-profile-Build-__gcov_fork-only-with-fork.patch
new file mode 100644
index 00000000000..f47a3f07bec
--- /dev/null
+++ 
b/libs/libbuiltin/compiler-rt/0001-compiler-rt-profile-Build-__gcov_fork-only-with-fork.patch
@@ -0,0 +1,26 @@
+From: Marco Casaroli <[email protected]>
+Subject: [PATCH] compiler-rt/profile: Build __gcov_fork() only with fork()
+
+NuttX declares fork() only with CONFIG_ARCH_HAVE_FORK.  Instrumented code
+calls __gcov_fork() only in place of a call to fork(), so nothing needs it
+in other configurations.  The second COMPILER_RT_VISIBILITY that follows the
+block makes the first one harmless, and the hunks do not touch the line of
+the outer #if, which differs between the LLVM versions.
+
+---
+ lib/profile/GCDAProfiling.c | 2 ++
+ 1 file changed, 2 insertions(+)
+
+--- a/lib/profile/GCDAProfiling.c
++++ b/lib/profile/GCDAProfiling.c
+@@ -588,2 +588,3 @@
+ COMPILER_RT_VISIBILITY
++#ifdef CONFIG_ARCH_HAVE_FORK
+ pid_t __gcov_fork() {
+@@ -602,5 +603,6 @@
+   return pid;
+ }
+ #endif
++#endif
+ 
+ COMPILER_RT_VISIBILITY
diff --git a/libs/libbuiltin/compiler-rt/CMakeLists.txt 
b/libs/libbuiltin/compiler-rt/CMakeLists.txt
index 56fee38f82c..2ee3a0c90a2 100644
--- a/libs/libbuiltin/compiler-rt/CMakeLists.txt
+++ b/libs/libbuiltin/compiler-rt/CMakeLists.txt
@@ -41,6 +41,9 @@ if(CONFIG_LIB_COMPILER_RT)
           ""
           TEST_COMMAND
           ""
+      PATCH_COMMAND
+        patch -p1 -d ${CMAKE_CURRENT_LIST_DIR}/compiler-rt <
+        
${CMAKE_CURRENT_LIST_DIR}/0001-compiler-rt-profile-Build-__gcov_fork-only-with-fork.patch
       DOWNLOAD_NO_PROGRESS true
       TIMEOUT 100)
 
diff --git a/libs/libbuiltin/compiler-rt/Make.defs 
b/libs/libbuiltin/compiler-rt/Make.defs
index fbee147b0a0..c34eb26cb4e 100644
--- a/libs/libbuiltin/compiler-rt/Make.defs
+++ b/libs/libbuiltin/compiler-rt/Make.defs
@@ -56,6 +56,7 @@ compiler-rt-$(COMPILER_RT_VERSION).src.tar.xz:
 compiler-rt/compiler-rt: compiler-rt-$(COMPILER_RT_VERSION).src.tar.xz
        $(Q) tar -xf $<
        $(Q) mv compiler-rt-$(COMPILER_RT_VERSION).src $@
+       $(Q) patch -p1 -d $@ < 
compiler-rt/0001-compiler-rt-profile-Build-__gcov_fork-only-with-fork.patch
        $(call DELDIR, $<)
 
 compiler-rt: compiler-rt/compiler-rt

Reply via email to