[libc-commits] [libc] [libc] Enabling code coverage via Linux syscalls (PR #213271)

Tapiwa Gonga via libc-commits libc-commits at lists.llvm.org
Fri Sep 4 04:02:03 PDT 2026


================
@@ -75,10 +100,31 @@ ProcessStatus invoke_in_subprocess(FunctionCaller *func, int timeout_ms) {
   }
 
   if (!pid) {
+#if defined(LIBC_ENABLE_COVERAGE) && defined(LIBC_FULL_BUILD)
+    struct sigaction sa = {};
+    sa.sa_handler = coverage_fatal_signal_handler;
+    LIBC_IMPL::sigaction(SIGABRT, &sa, nullptr);
+    LIBC_IMPL::sigaction(SIGSEGV, &sa, nullptr);
+    LIBC_IMPL::sigaction(SIGILL, &sa, nullptr);
+    LIBC_IMPL::sigaction(SIGFPE, &sa, nullptr);
+    LIBC_IMPL::sigaction(SIGBUS, &sa, nullptr);
+#elif defined(LIBC_ENABLE_COVERAGE)
+    ::signal(SIGABRT, coverage_fatal_signal_handler);
+    ::signal(SIGSEGV, coverage_fatal_signal_handler);
+    ::signal(SIGILL, coverage_fatal_signal_handler);
+    ::signal(SIGFPE, coverage_fatal_signal_handler);
+    ::signal(SIGBUS, coverage_fatal_signal_handler);
+#endif
----------------
tapiwagonga wrote:

I have updated the implementation to use Clang's continuous profiling mode (`-fprofile-continuous` with `-fprofile-instr-generate=libc_cov_%p.profraw`). In this mode, the raw profile file is created and `mmap` ed into memory upfront so runtime execution counters are synchronized directly to disk via the OS page cache as code executes. Coverage is now collected without custom signal handlers or exit hooks.



https://github.com/llvm/llvm-project/pull/213271


More information about the libc-commits mailing list