diff mbox series

UML GCOV fails to produce *.gcda files

Message ID 20190718012136.GA135592@google.com
State Superseded
Headers show
Series UML GCOV fails to produce *.gcda files | expand

Commit Message

Brendan Higgins July 18, 2019, 1:21 a.m. UTC
Following the instructions here[1], we have been trying to get gcov
support working under UML. However, despite the fact that it seems to be
configured correctly (I see it producing *.gcno files), it does not
appear to be producing *.gcda files (or *.da) files when we run the UML
kernel.

Sor far we have mostly been working with v5.2.

Running make with KBUILD_VERBOSE=1 we see that gcc is being called with
the appropriate gcov flags: -fprofile-arcs -ftest-coverage

As I mentioned above, we see that *.gcno files are being produced.

We also see that libgcov is being linked into the linux binary:

readelf -s linux | grep __gcov_init
 29312: 000000006041d070   200 FUNC    GLOBAL HIDDEN    13 __gcov_init

To ensure that __gcov_flush() is actually being called, we manually
inserted it in the kernel's init (just to see if we get some coverage
information). I copied the patch at the end of this email.

And yet we still see no *.gcda files being generated.

It looks like it has been a very long time since anyone has touched the
UML gcov code, so I have started looking into building an older version
of the kernel where it might have worked, but have not gotten any useful
results back from that yet.

We are aware that gcov has also been implemented for other architectures
under separate Kconfigs (CONFIG_GCOV_KERNEL and friends); however, we
are very keen to get gcov working with UML (where we don't have to
scrape sysfs for the *.gcda files) as we are running tests in UML and it
would be much easier to get coverage for these tests on UML as well.

Hope someone can help!

Thanks!

[1]http://user-mode-linux.sourceforge.net/old/gprof.html

Our .config can be generated by running `make ARCH=um olddefconfig` on
the following defconfig:

CONFIG_DEBUG_INFO=y
CONFIG_DEBUG_KERNEL=y
CONFIG_GCOV=y

The __gcov_flush() patch mentioned above is here:

From e021b659b51670bc0a063b6817c31d30ab809be6 Mon Sep 17 00:00:00 2001
From: Brendan Higgins <brendanhiggins@google.com>
Date: Wed, 17 Jul 2019 18:11:29 -0700
Subject: [PATCH v1] DO NOT MERGE: added __gcov_flush() to init to ensure it is
 called

---
 init/main.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Brendan Higgins July 20, 2019, 1:10 a.m. UTC | #1
On Wed, Jul 17, 2019 at 6:21 PM Brendan Higgins
<brendanhiggins@google.com> wrote:
>
> Following the instructions here[1], we have been trying to get gcov
> support working under UML. However, despite the fact that it seems to be
> configured correctly (I see it producing *.gcno files), it does not
> appear to be producing *.gcda files (or *.da) files when we run the UML
> kernel.
>
> Sor far we have mostly been working with v5.2.
>
> Running make with KBUILD_VERBOSE=1 we see that gcc is being called with
> the appropriate gcov flags: -fprofile-arcs -ftest-coverage
>
> As I mentioned above, we see that *.gcno files are being produced.
>
> We also see that libgcov is being linked into the linux binary:
>
> readelf -s linux | grep __gcov_init
>  29312: 000000006041d070   200 FUNC    GLOBAL HIDDEN    13 __gcov_init
>
> To ensure that __gcov_flush() is actually being called, we manually
> inserted it in the kernel's init (just to see if we get some coverage
> information). I copied the patch at the end of this email.
>
> And yet we still see no *.gcda files being generated.
>
> It looks like it has been a very long time since anyone has touched the
> UML gcov code, so I have started looking into building an older version
> of the kernel where it might have worked, but have not gotten any useful
> results back from that yet.

I have an update on this!

I tried building the kernel with gcc-4.9.4 when I discovered that gcov
*does* work with v5.2 of the kernel, just not gcc-7.3.0. So it seems
this may actually be an issue with gcc and not UML.

I will update when I learn more.
diff mbox series

Patch

diff --git a/init/main.c b/init/main.c
index 66a196c5e4c3c..70d7a6cb9ea0f 100644
--- a/init/main.c
+++ b/init/main.c
@@ -1080,10 +1080,14 @@  void __weak free_initmem(void)
 	free_initmem_default(POISON_FREE_INITMEM);
 }
 
+extern void __gcov_flush(void);
+
 static int __ref kernel_init(void *unused)
 {
 	int ret;
 
+	__gcov_flush();
+	printk("__gcov_flush\n");
 	kernel_init_freeable();
 	/* need to finish all async __init code before freeing the memory */
 	async_synchronize_full();