[PATCH] gcov: use memcpy for counter value dump in convert_to_gcda

From: Bradley Morgan

Date: Tue Sep 01 2026 - 05:06:39 EST


From: Bradley Morgan <brads@xxxxxxxxxxxxxx>

The loop writing gcov_type values one by one is slow and ugly. The
values are already in memory, just copy them.

store_gcov_u64 splits each value into two words with the low part
first, which matches the gcov format on little endian. On big endian
the split is still needed, so keep the loop for BE and use memcpy for
LE.

Signed-off-by: Bradley Morgan <brads@xxxxxxxxxxxxxx>
---
kernel/gcov/gcc_4_7.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/kernel/gcov/gcc_4_7.c b/kernel/gcov/gcc_4_7.c
index 8fa22ababd94..94c240180906 100644
--- a/kernel/gcov/gcc_4_7.c
+++ b/kernel/gcov/gcc_4_7.c
@@ -422,11 +422,23 @@ size_t convert_to_gcda(char *buffer, struct gcov_info *info)
pos += store_gcov_u32(buffer, pos,
ci_ptr->num * 2 * GCOV_UNIT_SIZE);

+#ifdef __LITTLE_ENDIAN
+ /*
+ * The values are already in memory, just copy them.
+ * store_gcov_u64 splits each value into two words
+ * which matches the gcov format on LE. On BE the
+ * split is still needed so keep the loop there.
+ */
+ if (buffer)
+ memcpy(buffer + pos, ci_ptr->values,
+ ci_ptr->num * sizeof(gcov_type));
+ pos += ci_ptr->num * sizeof(gcov_type);
+#else
for (cv_idx = 0; cv_idx < ci_ptr->num; cv_idx++) {
pos += store_gcov_u64(buffer, pos,
ci_ptr->values[cv_idx]);
}
-
+#endif
ci_ptr++;
}
}
--
2.47.3