]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
macro: call __gcov_dump() before _exit() w/ coverage enabled
authorFrantisek Sumsal <frantisek@sumsal.cz>
Wed, 6 Apr 2022 17:41:01 +0000 (19:41 +0200)
committerFrantisek Sumsal <frantisek@sumsal.cz>
Thu, 7 Apr 2022 08:06:44 +0000 (10:06 +0200)
_exit() skips at-exit hooks, causing lost coverage from processes
utilizing it.

Hopefully resolves systemd/systemd-centos-ci#482

meson.build
src/basic/macro.h

index 0455d89b78c8c8c682f41d5037027908661d8cdc..26f98b856c610cab4ab323715a8bf300e4e89efd 100644 (file)
@@ -47,6 +47,9 @@ fuzzer_build = want_ossfuzz or want_libfuzzer
 # More items are added later after they have been detected.
 summary({'build mode' : get_option('mode')})
 
+# GCOV doesn't define any macro when compiled with, so let's define it ourselves
+conf.set10('BUILT_WITH_COVERAGE', get_option('b_coverage'))
+
 #####################################################################
 
 # Try to install the git pre-commit hook
index 68d8b062e87330983304a1ed875014d37d65ea00..685de7344931e0fb67fa3252197aae1c86d42d28 100644 (file)
 #define _alignptr_ __attribute__((__aligned__(sizeof(void*))))
 #define _warn_unused_result_ __attribute__((__warn_unused_result__))
 
+#if defined(BUILT_WITH_COVERAGE) && BUILT_WITH_COVERAGE
+/* We need to explicitly call __gcov_dump() in places where we use _exit(), since
+ * _exit() skips at-exit hooks resulting in lost coverage */
+#  include <unistd.h>
+extern void __gcov_dump(void);
+
+_noreturn_ static inline void _coverage__exit(int status) {
+        __gcov_dump();
+        _exit(status);
+}
+#  define _exit(x) _coverage__exit(x)
+#endif
+
 #if !defined(HAS_FEATURE_MEMORY_SANITIZER)
 #  if defined(__has_feature)
 #    if __has_feature(memory_sanitizer)