From: Peter Oberparleiter Modify kbuild to create symbolic links in the build directory which refer to the .gcda files in sysfs. Required by the gcov profiling infrastructure: the gcov tool requires all data files (x.gcda, x.gcno) to be found in the same directory. Signed-off-by: Peter Oberparleiter Cc: Sam Ravnborg Cc: Rusty Russell Signed-off-by: Andrew Morton --- Makefile | 11 ++++++----- scripts/Makefile.build | 9 ++++++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff -puN Makefile~gcov-create-links-to-gcda-files-in-build-directory Makefile --- a/Makefile~gcov-create-links-to-gcda-files-in-build-directory +++ a/Makefile @@ -319,7 +319,7 @@ LDFLAGS_MODULE = CFLAGS_KERNEL = AFLAGS_KERNEL = CFLAGS_GCOV = -fprofile-arcs -ftest-coverage - +GCOV_DATA_DIR = /sys/kernel/debug/gcov # Use LINUXINCLUDE when you must reference the include/ directory. # Needed to be compatible with the O= option @@ -341,7 +341,7 @@ KERNELVERSION = $(VERSION).$(PATCHLEVEL) export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION export ARCH SRCARCH CONFIG_SHELL HOSTCC HOSTCFLAGS CROSS_COMPILE AS LD CC export CPP AR NM STRIP OBJCOPY OBJDUMP MAKE AWK GENKSYMS PERL UTS_MACHINE -export HOSTCXX HOSTCXXFLAGS LDFLAGS_MODULE CHECK CHECKFLAGS +export HOSTCXX HOSTCXXFLAGS LDFLAGS_MODULE CHECK CHECKFLAGS GCOV_DATA_DIR export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS LDFLAGS export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE CFLAGS_GCOV @@ -1141,8 +1141,8 @@ clean: archclean $(clean-dirs) \( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \ -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \ -o -name '*.symtypes' -o -name 'modules.order' \ - -o -name '*.gcno' \) \ - -type f -print | xargs rm -f + -o -name '*.gcno' -o -name '*.gcda' \) \ + \( -type f -o -type l \) -print | xargs rm -f # mrproper - Delete all generated files, including .config # @@ -1346,7 +1346,8 @@ clean: $(clean-dirs) @find $(KBUILD_EXTMOD) $(RCS_FIND_IGNORE) \ \( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \ -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \ - -o -name '*.gcno' \) -type f -print | xargs rm -f + -o -name '*.gcno' -o -name '*.gcda' \) \ + \( -type f -o -type l \) -print | xargs rm -f help: @echo ' Building external modules.' diff -puN scripts/Makefile.build~gcov-create-links-to-gcda-files-in-build-directory scripts/Makefile.build --- a/scripts/Makefile.build~gcov-create-links-to-gcda-files-in-build-directory +++ a/scripts/Makefile.build @@ -198,6 +198,12 @@ cmd_modversions = \ fi; endif +ifdef CONFIG_GCOV_PROFILE +# Create a link to the gcov data file in /sys +cmd_gcov = ln -s -f $(GCOV_DATA_DIR)$(if \ + $(filter-out /%,$(@D)),$(objtree)/$(@D),$(@D))/$(@F:.o=.gcda) $(@D) +endif + define rule_cc_o_c $(call echo-cmd,checksrc) $(cmd_checksrc) \ $(call echo-cmd,cc_o_c) $(cmd_cc_o_c); \ @@ -205,7 +211,8 @@ define rule_cc_o_c scripts/basic/fixdep $(depfile) $@ '$(call make-cmd,cc_o_c)' > \ $(dot-target).tmp; \ rm -f $(depfile); \ - mv -f $(dot-target).tmp $(dot-target).cmd + mv -f $(dot-target).tmp $(dot-target).cmd; \ + $(cmd_gcov) endef # Built-in and composite module parts _