401d0d9
From: Josh Stone <jistone@redhat.com>
401d0d9
Date: Fri, 21 Nov 2014 10:40:00 -0800
401d0d9
Subject: [PATCH] Kbuild: Add an option to enable GCC VTA
401d0d9
MIME-Version: 1.0
401d0d9
Content-Type: text/plain; charset=UTF-8
401d0d9
Content-Transfer-Encoding: 8bit
401d0d9
401d0d9
Due to recent codegen issues, gcc -fvar-tracking-assignments was
401d0d9
unconditionally disabled in commit 2062afb4f804a ("Fix gcc-4.9.0
401d0d9
miscompilation of load_balance() in scheduler").  However, this reduces
401d0d9
the debuginfo coverage for variable locations, especially in inline
401d0d9
functions.  VTA is certainly not perfect either in those cases, but it
401d0d9
is much better than without.  With compiler versions that have fixed the
401d0d9
codegen bugs, we would prefer to have the better details for SystemTap,
401d0d9
and surely other debuginfo consumers like perf will benefit as well.
401d0d9
401d0d9
This patch simply makes CONFIG_DEBUG_INFO_VTA an option.  I considered
401d0d9
Frank and Linus's discussion of a cc-option-like -fcompare-debug test,
401d0d9
but I'm convinced that a narrow test of an arch-specific codegen issue
401d0d9
is not really useful.  GCC has their own regression tests for this, so
401d0d9
I'd suggest GCC_COMPARE_DEBUG=-fvar-tracking-assignments-toggle is more
401d0d9
useful for kernel developers to test confidence.
401d0d9
401d0d9
In fact, I ran into a couple more issues when testing for this patch[1],
401d0d9
although neither of those had any codegen impact.
401d0d9
 [1] https://bugzilla.redhat.com/show_bug.cgi?id=1140872
401d0d9
401d0d9
With gcc-4.9.2-1.fc22, I can now build v3.18-rc5 with Fedora's i686 and
401d0d9
x86_64 configs, and this is completely clean with GCC_COMPARE_DEBUG.
401d0d9
401d0d9
Cc: Frank Ch. Eigler <fche@redhat.com>
401d0d9
Cc: Jakub Jelinek <jakub@redhat.com>
401d0d9
Cc: Josh Boyer <jwboyer@fedoraproject.org>
401d0d9
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
401d0d9
Cc: Linus Torvalds <torvalds@linux-foundation.org>
401d0d9
Cc: Andrew Morton <akpm@linux-foundation.org>
401d0d9
Cc: Markus Trippelsdorf <markus@trippelsdorf.de>
401d0d9
Cc: Michel Dänzer <michel@daenzer.net>
401d0d9
Signed-off-by: Josh Stone <jistone@redhat.com>
401d0d9
---
401d0d9
 Makefile          |  4 ++++
401d0d9
 lib/Kconfig.debug | 18 +++++++++++++++++-
401d0d9
 2 files changed, 21 insertions(+), 1 deletion(-)
401d0d9
401d0d9
diff --git a/Makefile b/Makefile
228ccc4
index 257ef5892ab7..3cc6f4477e78 100644
401d0d9
--- a/Makefile
401d0d9
+++ b/Makefile
088a50c
@@ -701,7 +701,11 @@ KBUILD_CFLAGS	+= -fomit-frame-pointer
401d0d9
 endif
401d0d9
 endif
401d0d9
 
401d0d9
+ifdef CONFIG_DEBUG_INFO_VTA
401d0d9
+KBUILD_CFLAGS   += $(call cc-option, -fvar-tracking-assignments)
401d0d9
+else
401d0d9
 KBUILD_CFLAGS   += $(call cc-option, -fno-var-tracking-assignments)
401d0d9
+endif
401d0d9
 
401d0d9
 ifdef CONFIG_DEBUG_INFO
401d0d9
 ifdef CONFIG_DEBUG_INFO_SPLIT
401d0d9
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
088a50c
index e2894b23efb6..d98afe18f704 100644
401d0d9
--- a/lib/Kconfig.debug
401d0d9
+++ b/lib/Kconfig.debug
401d0d9
@@ -165,7 +165,23 @@ config DEBUG_INFO_DWARF4
401d0d9
 	  Generate dwarf4 debug info. This requires recent versions
401d0d9
 	  of gcc and gdb. It makes the debug information larger.
401d0d9
 	  But it significantly improves the success of resolving
401d0d9
-	  variables in gdb on optimized code.
401d0d9
+	  variables in gdb on optimized code.  The gcc docs also
401d0d9
+	  recommend enabling -fvar-tracking-assignments for maximum
401d0d9
+	  benefit. (see DEBUG_INFO_VTA)
401d0d9
+
401d0d9
+config DEBUG_INFO_VTA
401d0d9
+	bool "Enable var-tracking-assignments for debuginfo"
401d0d9
+	depends on DEBUG_INFO
401d0d9
+	help
401d0d9
+	  Enable gcc -fvar-tracking-assignments for improved debug
401d0d9
+	  information on variable locations in optimized code.  Per
401d0d9
+	  gcc, DEBUG_INFO_DWARF4 is recommended for best use of VTA.
401d0d9
+
401d0d9
+	  VTA has been implicated in codegen bugs (gcc PR61801,
401d0d9
+	  PR61904), so this may deserve some caution.  One can set
401d0d9
+	  GCC_COMPARE_DEBUG=-fvar-tracking-assignments-toggle in the
401d0d9
+	  environment to automatically compile everything both ways,
401d0d9
+	  generating an error if anything differs.
401d0d9
 
6bfe640
 config GDB_SCRIPTS
6bfe640
 	bool "Provide GDB scripts for kernel debugging"