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

Petr Hosek via libc-commits libc-commits at lists.llvm.org
Mon Aug 31 22:44:42 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
----------------
petrhosek wrote:

You can avoid handling signals by using [continuous instrumentation profiling](https://clang.llvm.org/docs/UsersManual.html#cmdoption-fprofile-continuous) where the profile is written to a file at the start of the program, and then `mmap`ed back into memory, the instrumentation then continuously updates the counters in the mapped file. This is the mode we use on our coverage builders (for both Fuchsia and Linux).

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


More information about the libc-commits mailing list