From: Sasha Levin <sashal@kernel.org>
To: oberpar@linux.ibm.com
Cc: corbet@lwn.net, skhan@linuxfoundation.org, nathan@kernel.org,
linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-doc@vger.kernel.org, Sasha Levin <sashal@kernel.org>
Subject: [PATCH 1/4] gcov: fix gcov_info_add() merge semantics for IOR counters
Date: Sat, 14 Mar 2026 10:17:46 -0400 [thread overview]
Message-ID: <20260314141749.3382679-2-sashal@kernel.org> (raw)
In-Reply-To: <20260314141749.3382679-1-sashal@kernel.org>
gcov_info_add() unconditionally uses += to merge all counter types.
This is wrong for counters that use IOR merge semantics (bitwise OR),
such as GCOV_COUNTER_IOR and GCC 14's GCOV_COUNTER_CONDS (MC/DC
condition coverage). These counters store bitsets that must be merged
with |=, not accumulated with +=.
Detect IOR merge semantics by comparing the merge function pointer
against __gcov_merge_ior, matching how GCC's own libgcov identifies
merge semantics. This fixes the pre-existing bug for GCOV_COUNTER_IOR
and also enables correct merging for MC/DC condition coverage data.
Fixes: 5f41ea0386a5 ("gcov: add support for gcc 4.7 gcov format")
Assisted-by: Claude:claude-opus-4-6
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
kernel/gcov/gcc_4_7.c | 25 ++++++++++++++++++++++---
1 file changed, 22 insertions(+), 3 deletions(-)
diff --git a/kernel/gcov/gcc_4_7.c b/kernel/gcov/gcc_4_7.c
index 8fa22ababd943..923cfb34966b2 100644
--- a/kernel/gcov/gcc_4_7.c
+++ b/kernel/gcov/gcc_4_7.c
@@ -18,6 +18,8 @@
#include <linux/mm.h>
#include "gcov.h"
+extern void __gcov_merge_ior(gcov_type *, unsigned int);
+
#if (__GNUC__ >= 15)
#define GCOV_COUNTERS 10
#elif (__GNUC__ >= 14)
@@ -187,6 +189,15 @@ static int counter_active(struct gcov_info *info, unsigned int type)
return info->merge[type] ? 1 : 0;
}
+/*
+ * Determine whether a counter uses IOR merge semantics (bitwise OR of
+ * bitsets). Used for condition coverage (MC/DC) and other IOR-based counters.
+ */
+static bool counter_is_ior(struct gcov_info *info, unsigned int type)
+{
+ return info->merge[type] == __gcov_merge_ior;
+}
+
/* Determine number of active counters. Based on gcc magic. */
static unsigned int num_counter_active(struct gcov_info *info)
{
@@ -259,9 +270,17 @@ void gcov_info_add(struct gcov_info *dst, struct gcov_info *src)
if (!counter_active(src, ct_idx))
continue;
- for (val_idx = 0; val_idx < sci_ptr->num; val_idx++)
- dci_ptr->values[val_idx] +=
- sci_ptr->values[val_idx];
+ if (counter_is_ior(src, ct_idx)) {
+ for (val_idx = 0; val_idx < sci_ptr->num;
+ val_idx++)
+ dci_ptr->values[val_idx] |=
+ sci_ptr->values[val_idx];
+ } else {
+ for (val_idx = 0; val_idx < sci_ptr->num;
+ val_idx++)
+ dci_ptr->values[val_idx] +=
+ sci_ptr->values[val_idx];
+ }
dci_ptr++;
sci_ptr++;
--
2.51.0
next prev parent reply other threads:[~2026-03-14 14:18 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-14 14:17 [PATCH 0/4] gcov: Add MC/DC condition coverage support Sasha Levin
2026-03-14 14:17 ` Sasha Levin [this message]
2026-03-14 14:17 ` [PATCH 2/4] kconfig: add CC_HAS_CONDITION_COVERAGE for MC/DC support detection Sasha Levin
2026-03-14 14:17 ` [PATCH 3/4] gcov: add MC/DC condition coverage support Sasha Levin
2026-03-14 14:17 ` [PATCH 4/4] Documentation: gcov: document " Sasha Levin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260314141749.3382679-2-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=corbet@lwn.net \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nathan@kernel.org \
--cc=oberpar@linux.ibm.com \
--cc=skhan@linuxfoundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox