]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
meson: explicitly include coverage tweaks when built w/ --coverage
authorFrantisek Sumsal <frantisek@sumsal.cz>
Fri, 8 Apr 2022 11:20:15 +0000 (13:20 +0200)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 8 Apr 2022 15:02:30 +0000 (00:02 +0900)
To make sure we don't miss any _exit() calls let's move the
coverage-related tweaks into a separate header file and include it
explicitly on the compiler command line using -include when a coverage
build is requested.

Follow-up to c6552ad381003a23cde7c3228e7071f30465df35.

meson.build
src/basic/coverage.h [new file with mode: 0644]
src/basic/macro.h

index 69dce9c87fcaeb3a9aa3360ee0ea0fa6e421c57a..458370e83df5d42a8b9551cb11af3f32b643f2b3 100644 (file)
@@ -47,9 +47,6 @@ 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
@@ -1823,6 +1820,12 @@ export_dbus_interfaces_py = find_program('tools/dbus_exporter.py')
 
 ############################################################
 
+if get_option('b_coverage')
+        add_project_arguments('-include', 'src/basic/coverage.h', language : 'c')
+endif
+
+############################################################
+
 config_h = configure_file(
         output : 'config.h',
         configuration : conf)
@@ -4230,6 +4233,7 @@ foreach tuple : [
         ['link-boot-shared',      get_option('link-boot-shared')],
         ['fexecve'],
         ['standalone-binaries',   get_option('standalone-binaries')],
+        ['coverage',              get_option('b_coverage')],
 ]
 
         if tuple.length() >= 2
diff --git a/src/basic/coverage.h b/src/basic/coverage.h
new file mode 100644 (file)
index 0000000..3ef02cf
--- /dev/null
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#pragma once
+
+/* When built with --coverage (gcov) we need to explicitly call __gcov_dump()
+ * in places where we use _exit(), since _exit() skips at-exit hooks resulting
+ * in lost coverage.
+ *
+ * To make sure we don't miss any _exit() calls, this header file is included
+ * explicitly on the compiler command line via the -include directive (only
+ * when built with -Db_coverage=true)
+ * */
+extern void _exit(int);
+extern void __gcov_dump(void);
+
+static inline void _coverage__exit(int status) {
+        __gcov_dump();
+        _exit(status);
+}
+#define _exit(x) _coverage__exit(x)
index 685de7344931e0fb67fa3252197aae1c86d42d28..68d8b062e87330983304a1ed875014d37d65ea00 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)