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