Skip to contentSkip to conversation

gcov: Disable gcov build with GCC 10

PATCH In review Leon Romanovsky 5 participants 8 messages Sep 4, 2020 – Sep 11, 2020 Gcov based kernel profiling

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gcov: Disable gcov build with GCC 10

From: Leon Romanovsky <[email protected]>

GCOV built with GCC 10 doesn't initialize n_function variable. This produces different kernel panics as was seen by Colin in Ubuntu [1] and me in FC 32 [2].

As a workaround, let's disable GCOV build for broken GCC 10 version.

[1] https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1891288
[2] https://lore.kernel.org/lkml/[email protected]

---
As was discussed:
https://lore.kernel.org/lkml/CAHk-=whbijeSdSvx-Xcr0DPMj0BiwhJ+uiNnDSVZcr_h_kg7UA@mail.gmail.com/

---
 kernel/gcov/Kconfig | 1 +
 1 file changed, 1 insertion(+)
kernel/gcov/Kconfig +1 -0
index 3110c77230c7..bb4b680e8455 100644
@@ -4,6 +4,7 @@ menu "GCOV-based kernel profiling"
 config GCOV_KERNEL
 	bool "Enable gcov-based kernel profiling"
 	depends on DEBUG_FS
+	depends on !CC_IS_GCC || GCC_VERSION < 100000
 	select CONSTRUCTORS if !UML
 	default n
 	help

--
2.26.2

#1 lore raw
Quoted 10 lines · Leon Romanovsky

GCOV built with GCC 10 doesn't initialize n_function variable. This produces different kernel panics as was seen by Colin in Ubuntu [1] and me in FC 32 [2].

As a workaround, let's disable GCOV build for broken GCC 10 version.

[1] https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1891288
[2] https://lore.kernel.org/lkml/[email protected]

The following patch should fix the problem with gcov and GCC 10. I successfully tested it with kernel 5.9-rc4 on s390 using GCC 10.1.1 and also with GCC 9.1.1 to see that it didn't break support for previous GCC versions. In both cases there were no kernel panics and gcov worked fine.

Could you try this patch to see if it also fixes the problem in your environment?

---8<---
From: Peter Oberparleiter <[email protected]>
Subject: [PATCH] gcov: add support for GCC 10.1

Using gcov to collect coverage data for kernels compiled with GCC 10.1 causes random malfunctions and kernel crashes. This is the result of a changed GCOV_COUNTERS value in GCC 10.1 that causes a mismatch between the layout of the gcov_info structure created by GCC profiling code and the related structure used by the kernel.

Fix this by updating the in-kernel GCOV_COUNTERS value. Also re-enable config GCOV_KERNEL for use with GCC 10.

---
 kernel/gcov/Kconfig   | 1 -
 kernel/gcov/gcc_4_7.c | 4 +++-
 2 files changed, 3 insertions(+), 2 deletions(-)
kernel/gcov/Kconfig +0 -1
index bb4b680e8455..3110c77230c7 100644
@@ -4,7 +4,6 @@ menu "GCOV-based kernel profiling"
 config GCOV_KERNEL
 	bool "Enable gcov-based kernel profiling"
 	depends on DEBUG_FS
-	depends on !CC_IS_GCC || GCC_VERSION < 100000
 	select CONSTRUCTORS if !UML
 	default n
 	help
kernel/gcov/gcc_4_7.c +3 -1
index 908fdf5098c3..53c67c87f141 100644
@@ -19,7 +19,9 @@
 #include <linux/vmalloc.h>
 #include "gcov.h"
 
-#if (__GNUC__ >= 7)
+#if (__GNUC__ >= 10)
+#define GCOV_COUNTERS			8
+#elif (__GNUC__ >= 7)
 #define GCOV_COUNTERS			9
 #elif (__GNUC__ > 5) || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)
 #define GCOV_COUNTERS			10
Signature · 1 line
2.21.0
author Tested-by
#2 lore raw
Quoted 12 lines · Peter Oberparleiter
Quoted 10 lines · Leon Romanovsky

GCOV built with GCC 10 doesn't initialize n_function variable. This produces different kernel panics as was seen by Colin in Ubuntu [1] and me in FC 32 [2].

As a workaround, let's disable GCOV build for broken GCC 10 version.

[1] https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1891288
[2] https://lore.kernel.org/lkml/[email protected]

Quoted 8 lines

The following patch should fix the problem with gcov and GCC 10. I successfully tested it with kernel 5.9-rc4 on s390 using GCC 10.1.1 and also with GCC 9.1.1 to see that it didn't break support for previous GCC versions. In both cases there were no kernel panics and gcov worked fine.

Could you try this patch to see if it also fixes the problem in your environment?

It worked for me, Thanks

Quoted 52 lines

---8<---
From: Peter Oberparleiter <[email protected]>
Subject: [PATCH] gcov: add support for GCC 10.1

Using gcov to collect coverage data for kernels compiled with GCC 10.1 causes random malfunctions and kernel crashes. This is the result of a changed GCOV_COUNTERS value in GCC 10.1 that causes a mismatch between the layout of the gcov_info structure created by GCC profiling code and the related structure used by the kernel.

Fix this by updating the in-kernel GCOV_COUNTERS value. Also re-enable config GCOV_KERNEL for use with GCC 10.

---
 kernel/gcov/Kconfig   | 1 -
 kernel/gcov/gcc_4_7.c | 4 +++-
 2 files changed, 3 insertions(+), 2 deletions(-)
kernel/gcov/Kconfig +0 -1
index bb4b680e8455..3110c77230c7 100644
@@ -4,7 +4,6 @@ menu "GCOV-based kernel profiling"
 config GCOV_KERNEL
 	bool "Enable gcov-based kernel profiling"
 	depends on DEBUG_FS
-	depends on !CC_IS_GCC || GCC_VERSION < 100000
 	select CONSTRUCTORS if !UML
 	default n
 	help
kernel/gcov/gcc_4_7.c +3 -2
index 908fdf5098c3..53c67c87f141 100644
@@ -19,7 +19,9 @@
 #include <linux/vmalloc.h>
 #include "gcov.h"
 
-#if (__GNUC__ >= 7)
+#if (__GNUC__ >= 10)
+#define GCOV_COUNTERS			8
+#elif (__GNUC__ >= 7)
 #define GCOV_COUNTERS			9
 #elif (__GNUC__ > 5) || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)
 #define GCOV_COUNTERS			10
--

2.21.0

#3 lore raw
In reply to Peter Oberparleiter
Quoted 3 lines · Peter Oberparleiter

Fix this by updating the in-kernel GCOV_COUNTERS value. Also re-enable config GCOV_KERNEL for use with GCC 10.

Lovely.

Is there some way we could see this value automatically, or at least have a check for it? Right now it's that _very_ magical number that depends on a gcc version in odd and undocumented ways..

IOW - I'm assuming user space gcov infrastructure finds this number some way, and wondering if we couldn't do the same?

Or is the gcov tool itself just doing the same kind of thing, and having magic numbers?

I get the feeling that somebody who knows gcov would go "You are just doing this all completely incorrectly, you should do XYZ" when they see that GCOV_COUNTERS thing.

Maybe just a script that finds the right header file in the gcc installation and extracts it from there, if only to verify the magic number that we have?

Linus

#4 lore raw

From: Linus Torvalds

Quoted 20 lines

Sent: 10 September 2020 20:19

Quoted 3 lines · Peter Oberparleiter

Fix this by updating the in-kernel GCOV_COUNTERS value. Also re-enable config GCOV_KERNEL for use with GCC 10.

Lovely.

Is there some way we could see this value automatically, or at least have a check for it? Right now it's that _very_ magical number that depends on a gcc version in odd and undocumented ways..

IOW - I'm assuming user space gcov infrastructure finds this number some way, and wondering if we couldn't do the same?

Or is the gcov tool itself just doing the same kind of thing, and having magic numbers?

Quoted 7 lines

I get the feeling that somebody who knows gcov would go "You are just doing this all completely incorrectly, you should do XYZ" when they see that GCOV_COUNTERS thing.

Maybe just a script that finds the right header file in the gcc installation and extracts it from there, if only to verify the magic number that we have?

I was wondering what happens if files compiled with different versions of gcc get linked together?

Not too far-fetched for someone to release a .a file containing 'gconv' objects.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)

#5 lore raw
Quoted 2 lines · David Laight

I was wondering what happens if files compiled with different versions of gcc get linked together?

This is not supported by GCC. At runtime libgcov will reject all data from object files compiled with a different GCC version.

Signature · 2 lines
Peter Oberparleiter
Linux on Z Development - IBM Germany
#6 lore raw
In reply to Linus Torvalds

(Adding GCC's gcov maintainer Martin Liška)

Quoted 11 lines · Linus Torvalds
Quoted 3 lines · Peter Oberparleiter

Fix this by updating the in-kernel GCOV_COUNTERS value. Also re-enable config GCOV_KERNEL for use with GCC 10.

Lovely.

Is there some way we could see this value automatically, or at least have a check for it? Right now it's that _very_ magical number that depends on a gcc version in odd and undocumented ways..

I don't think there is, except for maybe parsing GCC debuginfo files which I would consider an extreme prereq for compiling a kernel with gcov support. Also GCOV_COUNTERS is only one part of the problem - any change to struct gcov_info could have a similar effect.

Quoted 5 lines

IOW - I'm assuming user space gcov infrastructure finds this number some way, and wondering if we couldn't do the same?

Or is the gcov tool itself just doing the same kind of thing, and having magic numbers?

Short answer: GCC compiles this number into GCC and the associated GCC library and requires that only matching versions are used. The gcov_info definition is not available outside the GCC source tree.

Longer answer:

When GCC is called to compile a program with coverage profiling support it adds inline profiling code and data to the resulting assembler output. This profiling code updates in-memory counters during program execution and calls GCC library functions (libgcov) to - among other things - register the gcov_info data and to write out the resulting data file when the program terminates. The gcov tool consumes this data file format, which is different from the in-memory gcov_info data.

The gcov kernel support emulates portions of libgcov - it receives the gcov_info struct during initial registration, and creates a gcov data file in debugfs for consumption by the gcov tool.

Quoted 3 lines

I get the feeling that somebody who knows gcov would go "You are just doing this all completely incorrectly, you should do XYZ" when they see that GCOV_COUNTERS thing.

@Martin: would you care to comment from a GCC point of view?

Quoted 3 lines

Maybe just a script that finds the right header file in the gcc installation and extracts it from there, if only to verify the magic number that we have?

The next best thing that comes to my mind would be a build-time script that checks the size of the gcov_info struct generated by GCC and compare that to the size of the kernel's gcov_info for that GCC version (by parsing assembler output). This could catch some common classes of changes to gcov_info, while not restricting usage of gcov kernel support too much when gcov_info doesn't change (as was the case e.g. between GCC 7 and 9).

The "next worst thing" would be to disable CONFIG_GCOV_KERNEL for unknown GCC versions until someone tests it and updates the associated Kconfig file. This catches all changes, but at the cost of possibly unnecessarily restricting GCC versions plus requiring regular gcov-kernel updates.

Signature · 2 lines
Peter Oberparleiter
Linux on Z Development - IBM Germany
#7 lore raw
In reply to Peter Oberparleiter
Quoted 12 lines · Peter Oberparleiter
Quoted 10 lines · Leon Romanovsky

GCOV built with GCC 10 doesn't initialize n_function variable. This produces different kernel panics as was seen by Colin in Ubuntu [1] and me in FC 32 [2].

As a workaround, let's disable GCOV build for broken GCC 10 version.

[1] https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1891288
[2] https://lore.kernel.org/lkml/[email protected]

Quoted 9 lines

The following patch should fix the problem with gcov and GCC 10. I successfully tested it with kernel 5.9-rc4 on s390 using GCC 10.1.1 and also with GCC 9.1.1 to see that it didn't break support for previous GCC versions. In both cases there were no kernel panics and gcov worked fine.

Could you try this patch to see if it also fixes the problem in your environment?

This works perfectly, tested with gcc 10.2 on linux 5.9-rc4 (tip) on an ARM64 Socionext Synquacer E-Series (Cortex A-53) system.

thanks!

Quoted 49 lines

---8<---
From: Peter Oberparleiter <[email protected]>
Subject: [PATCH] gcov: add support for GCC 10.1

Using gcov to collect coverage data for kernels compiled with GCC 10.1 causes random malfunctions and kernel crashes. This is the result of a changed GCOV_COUNTERS value in GCC 10.1 that causes a mismatch between the layout of the gcov_info structure created by GCC profiling code and the related structure used by the kernel.

Fix this by updating the in-kernel GCOV_COUNTERS value. Also re-enable config GCOV_KERNEL for use with GCC 10.

---
 kernel/gcov/Kconfig   | 1 -
 kernel/gcov/gcc_4_7.c | 4 +++-
 2 files changed, 3 insertions(+), 2 deletions(-)
kernel/gcov/Kconfig +0 -1
index bb4b680e8455..3110c77230c7 100644
@@ -4,7 +4,6 @@ menu "GCOV-based kernel profiling"
 config GCOV_KERNEL
 	bool "Enable gcov-based kernel profiling"
 	depends on DEBUG_FS
-	depends on !CC_IS_GCC || GCC_VERSION < 100000
 	select CONSTRUCTORS if !UML
 	default n
 	help
kernel/gcov/gcc_4_7.c +3 -1
index 908fdf5098c3..53c67c87f141 100644
@@ -19,7 +19,9 @@
 #include <linux/vmalloc.h>
 #include "gcov.h"
 
-#if (__GNUC__ >= 7)
+#if (__GNUC__ >= 10)
+#define GCOV_COUNTERS			8
+#elif (__GNUC__ >= 7)
 #define GCOV_COUNTERS			9
 #elif (__GNUC__ > 5) || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)
 #define GCOV_COUNTERS			10