Skip to contentSkip to conversation

gcov: Add support for checksum field

PATCH Superseded Rickard Andersson 3 participants 3 messages Dec 19, 2022 – Dec 20, 2022 Gcov based kernel profiling

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gcov: Add support for checksum field

From: Rickard x Andersson <[email protected]>

In GCC version 12.1 a checksum field was added.

---
 kernel/gcov/gcc_4_7.c | 5 +++++
 1 file changed, 5 insertions(+)
kernel/gcov/gcc_4_7.c +5 -0
index c699feda21ac..04880d8fba25 100644
@@ -85,6 +85,7 @@ struct gcov_fn_info {
  * @version: gcov version magic indicating the gcc version used for compilation
  * @next: list head for a singly-linked list
  * @stamp: uniquifying time stamp
+ * @checksum: unique object checksum
  * @filename: name of the associated gcov data file
  * @merge: merge functions (null for unused counter type)
  * @n_functions: number of instrumented functions
@@ -97,6 +98,10 @@ struct gcov_info {
 	unsigned int version;
 	struct gcov_info *next;
 	unsigned int stamp;
+ /* Since GCC 12.1 a checksum field is added. */
+#if (__GNUC__ >= 12)
+	unsigned int checksum;
+#endif
 	const char *filename;
 	void (*merge[GCOV_COUNTERS])(gcov_type *, unsigned int);
 	unsigned int n_functions;
Signature · 1 line
2.30.2
maintainer Reviewed-by Tested-by on v1 1/1
#1 lore raw
Quoted 3 lines · Rickard Andersson

From: Rickard x Andersson <[email protected]>

In GCC version 12.1 a checksum field was added.

Thanks for the patch!

In another e-mail you mentioned that this patch fixes a kernel crash during boot when using gcov-kernel with GCC 12. Please add this information to the commit message and if possible the platform on which this occurs.

Also this patch fixes a missing piece from a previous patch, so please add:

Fixes 977ef30a7d88 ("gcov: support GCC 12.1 and newer compilers")

Finally I reviewed and tested the patch and it looks good to me, so please add:

Please resend with these commit message changes. Thanks!

For the record: I wondered why my testing of the previous patch with GCC 12 didn't catch this. It turns out that this crash does not occur on architectures with 8-byte pointer alignment such as s390x where I performed my tests. Consider this pahole output on s390x without the patch:

struct gcov_info {
[...]
unsigned int stamp; /* 16 4 */
/* XXX 4 bytes hole, try to pack */
const char * filename; /* 24 8 */
[...]
}

And with the patch:

struct gcov_info {
[...]

       unsigned int       stamp;                /*    16     4 */
       unsigned int       checksum;             /*    20     4 */
       const char  *      filename;             /*    24     8 */

[...]
}

As can be seen, the offset of the filename and subsequent fields does not change because the new field fills an alignment hole. It would change (resulting in a crash during boot) if the alignment-requirement of the const char *filename field would be different.

Quoted 29 lines
---
 kernel/gcov/gcc_4_7.c | 5 +++++
 1 file changed, 5 insertions(+)
kernel/gcov/gcc_4_7.c +5 -0
index c699feda21ac..04880d8fba25 100644
@@ -85,6 +85,7 @@ struct gcov_fn_info {
  * @version: gcov version magic indicating the gcc version used for compilation
  * @next: list head for a singly-linked list
  * @stamp: uniquifying time stamp
+ * @checksum: unique object checksum
  * @filename: name of the associated gcov data file
  * @merge: merge functions (null for unused counter type)
  * @n_functions: number of instrumented functions
@@ -97,6 +98,10 @@ struct gcov_info {
 	unsigned int version;
 	struct gcov_info *next;
 	unsigned int stamp;
+ /* Since GCC 12.1 a checksum field is added. */
+#if (__GNUC__ >= 12)
+	unsigned int checksum;
+#endif
 	const char *filename;
 	void (*merge[GCOV_COUNTERS])(gcov_type *, unsigned int);
 	unsigned int n_functions;
Signature · 2 lines
Peter Oberparleiter
Linux on IBM Z Development - IBM Germany R&D
Reviewed-by
#2 lore raw
Quoted 45 lines · Peter Oberparleiter
Quoted 3 lines · Rickard Andersson

From: Rickard x Andersson <[email protected]>

In GCC version 12.1 a checksum field was added.

Thanks for the patch!

In another e-mail you mentioned that this patch fixes a kernel crash during boot when using gcov-kernel with GCC 12. Please add this information to the commit message and if possible the platform on which this occurs.

Also this patch fixes a missing piece from a previous patch, so please add:

Fixes 977ef30a7d88 ("gcov: support GCC 12.1 and newer compilers")

Finally I reviewed and tested the patch and it looks good to me, so please add:

Please resend with these commit message changes. Thanks!

For the record: I wondered why my testing of the previous patch with GCC 12 didn't catch this. It turns out that this crash does not occur on architectures with 8-byte pointer alignment such as s390x where I performed my tests. Consider this pahole output on s390x without the patch:

struct gcov_info {
[...]
unsigned int stamp; /* 16 4 */
/* XXX 4 bytes hole, try to pack */
const char * filename; /* 24 8 */
[...]
}

And with the patch:

struct gcov_info {
[...]

       unsigned int       stamp;                /*    16     4 */
       unsigned int       checksum;             /*    20     4 */
       const char  *      filename;             /*    24     8 */
Quoted 7 lines

[...]
}

As can be seen, the offset of the filename and subsequent fields does not change because the new field fills an alignment hole. It would change (resulting in a crash during boot) if the alignment-requirement of the const char *filename field would be different.

Hello.

Thank you Peter for the deep analysis and it finally explains why I didn't notice while I was working on 977ef30a7d88.

Please add my review:

Thanks,
Martin

Quoted 31 lines
Quoted 30 lines
---
 kernel/gcov/gcc_4_7.c | 5 +++++
 1 file changed, 5 insertions(+)
kernel/gcov/gcc_4_7.c +5 -0
index c699feda21ac..04880d8fba25 100644
@@ -85,6 +85,7 @@ struct gcov_fn_info {
  * @version: gcov version magic indicating the gcc version used for compilation
  * @next: list head for a singly-linked list
  * @stamp: uniquifying time stamp
+ * @checksum: unique object checksum
  * @filename: name of the associated gcov data file
  * @merge: merge functions (null for unused counter type)
  * @n_functions: number of instrumented functions
@@ -97,6 +98,10 @@ struct gcov_info {
 	unsigned int version;
 	struct gcov_info *next;
 	unsigned int stamp;
+ /* Since GCC 12.1 a checksum field is added. */
+#if (__GNUC__ >= 12)
+	unsigned int checksum;
+#endif
 	const char *filename;
 	void (*merge[GCOV_COUNTERS])(gcov_type *, unsigned int);
 	unsigned int n_functions;