Re: [PATCH 0/7] gcov kernel support

Previous thread: [PATCH 0/2] dm-ioband: I/O bandwidth controller v1.0.0: Introduction by Ryo Tsuruta on Monday, May 19, 2008 - 4:22 am. (3 messages)

Next thread: [PATCH 2/7] kernel: introduce GCC_VERSION_LOWER macro by Peter Oberparleiter on Monday, May 19, 2008 - 4:43 am. (1 message)
To: <linux-kernel@...>
Cc: <ltp-coverage@...>, Andrew Morton <akpm@...>, Sam Ravnborg <sam@...>, Peter Oberparleiter <oberparleiter@...>
Date: Monday, May 19, 2008 - 4:42 am

This is version #2 of the gcov kernel support patch set (see further
below for an in-depth explanation). Patch base is 2.6.26-rc3.

Changes are mostly based on mailing list feedback:

* added more documentation
* moved gcov config menu to general setup
* renamed some structures and variables (removed _t, lowercase ctors)
* split mod versioning change into separate patch (3)
* split GCC_VERSION_LOWER into separate patch (2)
* split gcov core patch into two patches (5+6) for better readability
* absolute paths only used when CONFIG_GCOV_PROFILE is set
* fixed compile problem with CONFIG_MODULES=n
* fixed memory leak in gcov fs code
* more style changes

Patch overview:

[PATCH 1/7] kernel: call constructors
[PATCH 2/7] kernel: introduce GCC_VERSION_LOWER macro
[PATCH 3/7] kbuild: delay object file renaming during module versioning
[PATCH 4/7] seq_file: add function to write binary data
[PATCH 5/7] gcov: add gcov profiling infrastructure
[PATCH 6/7] kbuild: make source and include paths absolute
[PATCH 7/7] gcov: architecture specific compile flag adjustments

===

This set of patches enables the use of GCC's coverage testing tool
gcov [1] with kernel 2.6.25. Coverage data for the running kernel is
exported via debugfs in a gcov-compatible format. To get coverage
data for a specific file, simply use gcov with the -o option:

# gcov -o /sys/kernel/debug/gcov/tmp/linux-2.6.25/kernel spinlock.c

This will create source code files annotated with execution counts
in the current directory. In addition, graphical gcov front-ends such
as lcov [2] can be used to automate the process of collecting data
for the entire kernel and provide coverage overviews in HTML format.

Possible uses:

* debugging (has this line been executed at all?)
* test improvement (how do I change my test to cover these lines?)
* minimizing kernel configurations (do I need this option if the
associated code is never executed?)

Known issues:

* some architecture specific problems: the patch...

To: Peter Oberparleiter <peter.oberparleiter@...>
Cc: <linux-kernel@...>, <ltp-coverage@...>, Sam Ravnborg <sam@...>, Peter Oberparleiter <oberparleiter@...>
Date: Friday, May 23, 2008 - 4:12 am

powerpc blew up:

/opt/crosstool/gcc-4.1.0-glibc-2.3.6/powerpc64-unknown-linux-gnu/lib/gcc/powerpc64-unknown-linux-gnu/4.1.0/../../../../powerpc64-unknown-linux-gnu/bin/ld: skipping incompatible /opt/crosstool/gcc-4.1.0-glibc-2.3.6/powerpc64-unknown-linux-gnu/lib/gcc/powerpc64-unknown-linux-gnu/4.1.0/./libgcov.a when searching for -lgcov
/opt/crosstool/gcc-4.1.0-glibc-2.3.6/powerpc64-unknown-linux-gnu/lib/gcc/powerpc64-unknown-linux-gnu/4.1.0/../../../../powerpc64-unknown-linux-gnu/bin/ld: cannot find -lgcov
collect2: ld returned 1 exit status
make[2]: *** [arch/powerpc/kernel/vdso32/vdso32.so.dbg] Error 1
make[1]: *** [arch/powerpc/kernel/vdso32] Error 2

--

To: Andrew Morton <akpm@...>
Cc: Peter Oberparleiter <oberparleiter@...>, <linux-kernel@...>, <ltp-coverage@...>, Sam Ravnborg <sam@...>
Date: Tuesday, May 27, 2008 - 4:32 am

This looks like a secondary linking process. It's best to exclude the
whole directory from GCOV profiling (which should ony work for C files
anyway).

Below is an update for patch #7 of the gcov series that includes the
corresponding changes.

---

[PATCH 7/7] gcov: architecture specific compile flag adjustments

From: Peter Oberparleiter <peter.oberparleiter@de.ibm.com>

Exclude code from profiling which is not linked to the main kernel or
which is running in a context not compatible with the assumptions made
by gcc's profiling code.

Signed-off-by: Peter Oberparleiter <peter.oberparleiter@de.ibm.com>
---
arch/arm/boot/compressed/Makefile | 1 +
arch/powerpc/kernel/vdso32/Makefile | 1 +
arch/powerpc/kernel/vdso64/Makefile | 1 +
arch/ppc/boot/Makefile | 1 +
arch/ppc/boot/common/Makefile | 1 +
arch/ppc/boot/simple/Makefile | 1 +
arch/x86/boot/Makefile | 1 +
arch/x86/boot/compressed/Makefile | 1 +
arch/x86/kernel/acpi/realmode/Makefile | 1 +
9 files changed, 9 insertions(+)

Index: linux-2.6.26-rc3/arch/arm/boot/compressed/Makefile
===================================================================
--- linux-2.6.26-rc3.orig/arch/arm/boot/compressed/Makefile
+++ linux-2.6.26-rc3/arch/arm/boot/compressed/Makefile
@@ -7,6 +7,7 @@
HEAD = head.o
OBJS = misc.o
FONTC = $(srctree)/drivers/video/console/font_acorn_8x8.c
+GCOV := n

#
# Architecture dependencies
Index: linux-2.6.26-rc3/arch/x86/boot/compressed/Makefile
===================================================================
--- linux-2.6.26-rc3.orig/arch/x86/boot/compressed/Makefile
+++ linux-2.6.26-rc3/arch/x86/boot/compressed/Makefile
@@ -12,6 +12,7 @@ cflags-$(CONFIG_X86_64) := -mcmodel=smal
KBUILD_CFLAGS += $(cflags-y)
KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
+GCOV := n

KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__...

To: Andrew Morton <akpm@...>
Cc: <linux-kernel@...>, Peter Oberparleiter <oberparleiter@...>, Peter Oberparleiter <peter.oberparleiter@...>, Sam Ravnborg <sam@...>, <ltp-coverage@...>
Date: Friday, May 23, 2008 - 7:06 am

Sounds like your toolchain was built without biarch support, but you're
using it for the 32-bit parts of the kernel anyway. Which works as long
as you're not using any libraries, but now you need libgcov.a .

What does

/opt/crosstool/gcc-4.1.0-glibc-2.3.6/powerpc64-unknown-linux-gnu/bin/
powerpc64-unknown-linux-gnu-gcc -v

say? (Or whatever the correct path to that compiler is, the directory
structure is a bit unusual here it seems). There shouldn't be a
--disable-biarch there.

Or, what does

find
/opt/crosstool/gcc-4.1.0-glibc-2.3.6/powerpc64-unknown-linux-gnu/4.1.0/
-name libgcov.a

say? (It should usually find three versions: 64-bit, 32-bit, 32-bit no
float).

You *can* build with a non-biarch compiler, but then you need to point
the kernel build system at a 32-bit toolchain to use for the 32-bit
parts (via CROSS32_COMPILE).

Segher

--

To: Segher Boessenkool <segher@...>
Cc: <linux-kernel@...>, Peter Oberparleiter <oberparleiter@...>, Peter Oberparleiter <peter.oberparleiter@...>, Sam Ravnborg <sam@...>, <ltp-coverage@...>
Date: Friday, May 23, 2008 - 12:56 pm

y:/home/akpm> /opt/crosstool/gcc-4.1.0-glibc-2.3.6/powerpc64-unknown-linux-gnu/bin/powerpc64-unknown-linux-gnu-gcc -v
Using built-in specs.
Target: powerpc64-unknown-linux-gnu
Configured with: /home/axboe/crosstool-0.43/build/powerpc64-unknown-linux-gnu/gcc-4.1.0-glibc-2.3.6/gcc-4.1.0/configure --target=powerpc64-unknown-linux-gnu --host=x86_64-host_unknown-linux-gnu --prefix=/opt/crosstool/gcc-4.1.0-glibc-2.3.6/powerpc64-unknown-linux-gnu --disable-multilib --with-sysroot=/opt/crosstool/gcc-4.1.0-glibc-2.3.6/powerpc64-unknown-linux-gnu/powerpc64-unknown-linux-gnu/sys-root --with-local-prefix=/opt/crosstool/gcc-4.1.0-glibc-2.3.6/powerpc64-unknown-linux-gnu/powerpc64-unknown-linux-gnu/sys-root --disable-nls --enable-threads=posix --enable-symvers=gnu --enable-__cxa_atexit --enable-languages=c --enable-shared --enable-c99 --enable-long-long
Thread model: posix

Only a single hit:

/opt/crosstool/gcc-4.1.0-glibc-2.3.6/powerpc64-unknown-linux-gnu/lib/gcc/powerpc64-unknown-linux-gnu/4.1.0/libgcov.a

and it contains

y:/home/akpm/ppc> ar x libgcov.a
y:/home/akpm/ppc> l
total 316
-rw-r--r-- 1 akpm akpm 44192 May 23 09:53 _gcov.o
-rw-r--r-- 1 akpm akpm 8448 May 23 09:53 _gcov_execl.o
-rw-r--r-- 1 akpm akpm 8584 May 23 09:53 _gcov_execle.o
-rw-r--r-- 1 akpm akpm 8456 May 23 09:53 _gcov_execlp.o
-rw-r--r-- 1 akpm akpm 7384 May 23 09:53 _gcov_execv.o
-rw-r--r-- 1 akpm akpm 7544 May 23 09:53 _gcov_execve.o
-rw-r--r-- 1 akpm akpm 7392 May 23 09:53 _gcov_execvp.o
-rw-r--r-- 1 akpm akpm 7264 May 23 09:53 _gcov_fork.o
-rw-r--r-- 1 akpm akpm 7240 May 23 09:53 _gcov_interval_profiler.o
-rw-r--r-- 1 akpm akpm 7464 May 23 09:53 _gcov_merge_add.o
-rw-r--r-- 1 akpm akpm 8544 May 23 09:53 _gcov_merge_delta.o
-rw-r--r-- 1 akpm akpm 8488 May 23 09:53 _gcov_merge_single.o
-rw-r--r-- 1 akpm akpm 6976 May 23 09:53 _gcov_one_value_profiler.o
-rw-r--r-- 1 akpm akpm 6856 May 23 09:53 _gcov_pow2_profiler.o
-rw-r--r-- 1 akpm akpm 146492 May 23 09:52 libgcov.a
y:/home/akpm/ppc...

To: Andrew Morton <akpm@...>
Cc: <linux-kernel@...>, Peter Oberparleiter <oberparleiter@...>, Peter Oberparleiter <peter.oberparleiter@...>, Sam Ravnborg <sam@...>, <ltp-coverage@...>
Date: Friday, May 23, 2008 - 5:52 pm

That's the culprit. I believe 4.1.0 enables multilib by default on
PowerPC
compilers that target 64-bit by default (the patch for that is dated
almost
a full year before the 4.1.0 release). I have no idea why crosstool
disables this support; perhaps there were some problems with some older

You were lucky, yes. If your compiler would have been just a little
bit older it wouldn't have been able to build 32-bit at all.

Do you have a separate 32-bit PowerPC compiler? If so, just set
CROSS32_COMPILE to it; if not, you'll need a new toolchain. In
that case, it's probably worthwhile to upgrade to 4.1.2 at least...

Segher

--

To: Segher Boessenkool <segher@...>
Cc: <linux-kernel@...>, <oberparleiter@...>, <peter.oberparleiter@...>, <sam@...>, <ltp-coverage@...>
Date: Friday, May 23, 2008 - 6:23 pm

On Fri, 23 May 2008 23:52:43 +0200

Sigh. Life's too short. I'll go back to testing powerpc builds on the
powerpc box.

--

To: Peter Oberparleiter <peter.oberparleiter@...>
Cc: <linux-kernel@...>, <ltp-coverage@...>, Andrew Morton <akpm@...>, Sam Ravnborg <sam@...>, Peter Oberparleiter <oberparleiter@...>
Date: Monday, May 19, 2008 - 7:42 am

I reviewed the patches and they look good to me (except for
some minor nits, probably not worth fixing)

-Andi
--

Previous thread: [PATCH 0/2] dm-ioband: I/O bandwidth controller v1.0.0: Introduction by Ryo Tsuruta on Monday, May 19, 2008 - 4:22 am. (3 messages)

Next thread: [PATCH 2/7] kernel: introduce GCC_VERSION_LOWER macro by Peter Oberparleiter on Monday, May 19, 2008 - 4:43 am. (1 message)