Skip to contentSkip to conversation

Kbuild: Add an option to enable GCC VTA

PATCH RESEND In review Josh Stone 4 participants 8 messages Nov 21, 2014 – Apr 24, 2015

Subsystems (2)
lore
Share & tools
lore

Josh Stone

author
#0 lore raw

PATCH RESEND 1/1 Kbuild: Add an option to enable GCC VTA

Due to recent codegen issues, gcc -fvar-tracking-assignments was unconditionally disabled in commit 2062afb4f804a ("Fix gcc-4.9.0 miscompilation of load_balance() in scheduler"). However, this reduces the debuginfo coverage for variable locations, especially in inline functions. VTA is certainly not perfect either in those cases, but it is much better than without. With compiler versions that have fixed the codegen bugs, we would prefer to have the better details for SystemTap, and surely other debuginfo consumers like perf will benefit as well.

This patch simply makes CONFIG_DEBUG_INFO_VTA an option. I considered Frank and Linus's discussion of a cc-option-like -fcompare-debug test, but I'm convinced that a narrow test of an arch-specific codegen issue is not really useful. GCC has their own regression tests for this, so I'd suggest GCC_COMPARE_DEBUG=-fvar-tracking-assignments-toggle is more useful for kernel developers to test confidence.

In fact, I ran into a couple more issues when testing for this patch[1], although neither of those had any codegen impact.
[1] https://bugzilla.redhat.com/show_bug.cgi?id=1140872

With gcc-4.9.2-1.fc22, I can now build v3.18-rc5 with Fedora's i686 and x86_64 configs, and this is completely clean with GCC_COMPARE_DEBUG.

Cc Frank Ch. Eigler <[email protected]>
Cc Jakub Jelinek <[email protected]>
Cc Josh Boyer <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Markus Trippelsdorf <[email protected]>
Cc Michel Dänzer <[email protected]>
---
 Makefile          |  4 ++++
 lib/Kconfig.debug | 18 +++++++++++++++++-
 2 files changed, 21 insertions(+), 1 deletion(-)
Makefile +4 -0
index 00d618bbe8e7..a289efbe7e28 100644
@@ -704,7 +704,11 @@ KBUILD_CFLAGS	+= -fomit-frame-pointer
 endif
 endif
 
+ifdef CONFIG_DEBUG_INFO_VTA
+KBUILD_CFLAGS   += $(call cc-option, -fvar-tracking-assignments)
+else
 KBUILD_CFLAGS   += $(call cc-option, -fno-var-tracking-assignments)
+endif
 
 ifdef CONFIG_DEBUG_INFO
 ifdef CONFIG_DEBUG_INFO_SPLIT
lib/Kconfig.debug +17 -1
index 4e35a5d767ed..27410417de1d 100644
@@ -165,7 +165,23 @@ config DEBUG_INFO_DWARF4
 	  Generate dwarf4 debug info. This requires recent versions
 	  of gcc and gdb. It makes the debug information larger.
 	  But it significantly improves the success of resolving
-	  variables in gdb on optimized code.
+	  variables in gdb on optimized code.  The gcc docs also
+	  recommend enabling -fvar-tracking-assignments for maximum
+	  benefit. (see DEBUG_INFO_VTA)
+
+config DEBUG_INFO_VTA
+	bool "Enable var-tracking-assignments for debuginfo"
+	depends on DEBUG_INFO
+	help
+	  Enable gcc -fvar-tracking-assignments for improved debug
+	  information on variable locations in optimized code.  Per
+	  gcc, DEBUG_INFO_DWARF4 is recommended for best use of VTA.
+
+	  VTA has been implicated in codegen bugs (gcc PR61801,
+	  PR61904), so this may deserve some caution.  One can set
+	  GCC_COMPARE_DEBUG=-fvar-tracking-assignments-toggle in the
+	  environment to automatically compile everything both ways,
+	  generating an error if anything differs.
 
 config ENABLE_WARN_DEPRECATED
 	bool "Enable __deprecated logic"
Signature · 1 line
2.1.0
#1 lore raw

Dne 21.11.2014 v 19:40 Josh Stone napsal(a):

Quoted 3 lines

Due to recent codegen issues, gcc -fvar-tracking-assignments was unconditionally disabled in commit 2062afb4f804a ("Fix gcc-4.9.0 miscompilation of load_balance() in scheduler"). However, this reduces

[...]

Quoted 2 lines

With gcc-4.9.2-1.fc22, I can now build v3.18-rc5 with Fedora's i686 and x86_64 configs, and this is completely clean with GCC_COMPARE_DEBUG.

According to gcc's bug#61801, this is really fixed in 4.9.2 (commit 556537c4 in the git mirror). So how about checking for this minimal version instead of a new Kconfig option?

thanks,
Michal

author
#2 lore raw
Quoted 11 lines · Michal Marek

Dne 21.11.2014 v 19:40 Josh Stone napsal(a):

Quoted 3 lines

Due to recent codegen issues, gcc -fvar-tracking-assignments was unconditionally disabled in commit 2062afb4f804a ("Fix gcc-4.9.0 miscompilation of load_balance() in scheduler"). However, this reduces

[...]

Quoted 2 lines

With gcc-4.9.2-1.fc22, I can now build v3.18-rc5 with Fedora's i686 and x86_64 configs, and this is completely clean with GCC_COMPARE_DEBUG.

According to gcc's bug#61801, this is really fixed in 4.9.2 (commit 556537c4 in the git mirror). So how about checking for this minimal version instead of a new Kconfig option?

That's possible, if the new Kconfig option is really undesirable. But given that there's a similar DWARF4 option, which this pairs well with, I thought a VTA option was a good choice.

Besides 4.9.2 though, this particular fix has also been backported to 4.8.4, and who knows what various distro maintainers may do.

#3 lore raw

Dne 25.11.2014 v 00:46 Josh Stone napsal(a):

Quoted 13 lines · Michal Marek
Quoted 11 lines

Dne 21.11.2014 v 19:40 Josh Stone napsal(a):

Quoted 3 lines

Due to recent codegen issues, gcc -fvar-tracking-assignments was unconditionally disabled in commit 2062afb4f804a ("Fix gcc-4.9.0 miscompilation of load_balance() in scheduler"). However, this reduces

[...]

Quoted 2 lines

With gcc-4.9.2-1.fc22, I can now build v3.18-rc5 with Fedora's i686 and x86_64 configs, and this is completely clean with GCC_COMPARE_DEBUG.

According to gcc's bug#61801, this is really fixed in 4.9.2 (commit 556537c4 in the git mirror). So how about checking for this minimal version instead of a new Kconfig option?

Quoted 6 lines

That's possible, if the new Kconfig option is really undesirable. But given that there's a similar DWARF4 option, which this pairs well with, I thought a VTA option was a good choice.

Besides 4.9.2 though, this particular fix has also been backported to 4.8.4, and who knows what various distro maintainers may do.

My idea was that if we switch -fvar-tracking-assignments on with gcc 4.9.2+, then yes, some users with patched compilers will not benefit from it, but it will eventually work out of the box for "everybody." With the kconfig option, an uninformed user has no idea whether or not it is a good idea to switch it on. It should at least mention that it is safe to enable with 4.9.2+. And BTW

make KCLFAGS=-fvar-tracking-assignments

works as well, as the user-supplied flags are applied last.

Michal

#4 lore raw
Quoted 28 lines · Michal Marek

Dne 25.11.2014 v 00:46 Josh Stone napsal(a):

Quoted 13 lines · Michal Marek
Quoted 11 lines

Dne 21.11.2014 v 19:40 Josh Stone napsal(a):

Quoted 3 lines

Due to recent codegen issues, gcc -fvar-tracking-assignments was unconditionally disabled in commit 2062afb4f804a ("Fix gcc-4.9.0 miscompilation of load_balance() in scheduler"). However, this reduces

[...]

Quoted 2 lines

With gcc-4.9.2-1.fc22, I can now build v3.18-rc5 with Fedora's i686 and x86_64 configs, and this is completely clean with GCC_COMPARE_DEBUG.

According to gcc's bug#61801, this is really fixed in 4.9.2 (commit 556537c4 in the git mirror). So how about checking for this minimal version instead of a new Kconfig option?

Quoted 6 lines

That's possible, if the new Kconfig option is really undesirable. But given that there's a similar DWARF4 option, which this pairs well with, I thought a VTA option was a good choice.

Besides 4.9.2 though, this particular fix has also been backported to 4.8.4, and who knows what various distro maintainers may do.

My idea was that if we switch -fvar-tracking-assignments on with gcc 4.9.2+, then yes, some users with patched compilers will not benefit from it, but it will eventually work out of the box for "everybody." With the kconfig option, an uninformed user has no idea whether or not it is a good idea to switch it on. It should at least mention that it is safe to enable with 4.9.2+. And BTW

Quoted 3 lines

make KCLFAGS=-fvar-tracking-assignments

works as well, as the user-supplied flags are applied last.

I actually tried this after Kyle McMartin mentioned it, and thought about doing it in the Fedora kernel spec file instead of taking the patch. It's a bit less noticeable when trying to reproduce build environments though, and with it being a cc-option in the Makefile we can rely on that to filter out compilers and arches that don't support the flag.

josh

#5 lore raw

PATCH 1/1 Kbuild: Add an option to enable GCC VTA

In reply to Josh Stone

From: Josh Stone <[email protected]>

Due to isolated gcc codegen issues, gcc -fvar-tracking-assignments was unconditionally disabled in commit 2062afb4f804 ("Fix gcc-4.9.0 miscompilation of load_balance() in scheduler").

However, this reduces the debuginfo coverage for variable locations, especially in inline functions. VTA is certainly not perfect either in those cases, but it is much better than without. With compiler versions that have fixed the codegen bugs, we would prefer to have the better details for SystemTap, and surely other debuginfo consumers like perf will benefit as well.

This patch simply makes CONFIG_DEBUG_INFO_VTA an option. I considered Frank and Linus's discussion of a cc-option-like -fcompare-debug test, but I'm convinced that a narrow test of an arch-specific codegen issue is not really useful. GCC has their own regression tests for this, so I'd suggest GCC_COMPARE_DEBUG=-fvar-tracking-assignments-toggle is more useful for kernel developers to test confidence.

In fact, I ran into a couple more issues when testing for this patch[1], although neither of those had any codegen impact.
[1] https://bugzilla.redhat.com/show_bug.cgi?id=1140872

With gcc-4.9.2-1.fc22, I can now build v3.18-rc5 with Fedora's i686 and x86_64 configs, and this is completely clean with GCC_COMPARE_DEBUG.

Cc Jakub Jelinek <[email protected]>
Cc Josh Boyer <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Markus Trippelsdorf <[email protected]>
Cc Michel Dänzer <[email protected]>
---
 Makefile          |  8 ++++++--
 lib/Kconfig.debug | 21 ++++++++++++++++++++-
 2 files changed, 26 insertions(+), 3 deletions(-)
Makefile +6 -2
index 6cc5b2434224..c8e1fcfdb41a 100644
@@ -704,8 +704,6 @@ KBUILD_CFLAGS	+= -fomit-frame-pointer
 endif
 endif
 
-KBUILD_CFLAGS   += $(call cc-option, -fno-var-tracking-assignments)
-
 ifdef CONFIG_DEBUG_INFO
 ifdef CONFIG_DEBUG_INFO_SPLIT
 KBUILD_CFLAGS   += $(call cc-option, -gsplit-dwarf, -g)
@@ -718,6 +716,12 @@ ifdef CONFIG_DEBUG_INFO_DWARF4
 KBUILD_CFLAGS	+= $(call cc-option, -gdwarf-4,)
 endif
 
+ifdef CONFIG_DEBUG_INFO_VTA
+KBUILD_CFLAGS   += $(call cc-option, -fvar-tracking-assignments)
+else
+KBUILD_CFLAGS   += $(call cc-option, -fno-var-tracking-assignments)
+endif
+
 ifdef CONFIG_DEBUG_INFO_REDUCED
 KBUILD_CFLAGS 	+= $(call cc-option, -femit-struct-debug-baseonly) \
 		   $(call cc-option,-fno-var-tracking)
lib/Kconfig.debug +20 -1
index 17670573dda8..e8d072d2b402 100644
@@ -165,7 +165,26 @@ config DEBUG_INFO_DWARF4
 	  Generate dwarf4 debug info. This requires recent versions
 	  of gcc and gdb. It makes the debug information larger.
 	  But it significantly improves the success of resolving
-	  variables in gdb on optimized code.
+	  variables in gdb on optimized code.  The gcc docs also
+	  recommend enabling -fvar-tracking-assignments for maximum
+	  benefit. (see DEBUG_INFO_VTA)
+
+config DEBUG_INFO_VTA
+	bool "Enable var-tracking-assignments for debuginfo"
+	depends on DEBUG_INFO
+	help
+	  Enable gcc -fvar-tracking-assignments for improved debug
+	  information on variable locations in optimized code.	Per
+	  gcc, DEBUG_INFO_DWARF4 is recommended for best use of VTA,
+	  and allows maximal access to local variables in tracers
+	  and debuggers like perf, systemtap, kgdb, and crash.
+
+	  VTA has been implicated in codegen bugs (gcc PR61801,
+	  PR61904, both fixed in 2014-08), so this flag may be used
+	  to exclude this rare class of problem.  One can also set
+	  GCC_COMPARE_DEBUG=-fvar-tracking-assignments-toggle in the
+	  environment to automatically compile everything both ways,
+	  generating an error if anything differs.
 
 config GDB_SCRIPTS
 	bool "Provide GDB scripts for kernel debugging"
Signature · 1 line
2.1.0
#6 lore raw
Quoted 27 lines · Frank Ch. Eigler

From: Josh Stone <[email protected]>

Due to isolated gcc codegen issues, gcc -fvar-tracking-assignments was unconditionally disabled in commit 2062afb4f804 ("Fix gcc-4.9.0 miscompilation of load_balance() in scheduler").

However, this reduces the debuginfo coverage for variable locations, especially in inline functions. VTA is certainly not perfect either in those cases, but it is much better than without. With compiler versions that have fixed the codegen bugs, we would prefer to have the better details for SystemTap, and surely other debuginfo consumers like perf will benefit as well.

This patch simply makes CONFIG_DEBUG_INFO_VTA an option. I considered Frank and Linus's discussion of a cc-option-like -fcompare-debug test, but I'm convinced that a narrow test of an arch-specific codegen issue is not really useful. GCC has their own regression tests for this, so I'd suggest GCC_COMPARE_DEBUG=-fvar-tracking-assignments-toggle is more useful for kernel developers to test confidence.

In fact, I ran into a couple more issues when testing for this patch[1], although neither of those had any codegen impact.
[1] https://bugzilla.redhat.com/show_bug.cgi?id=1140872

With gcc-4.9.2-1.fc22, I can now build v3.18-rc5 with Fedora's i686 and x86_64 configs, and this is completely clean with GCC_COMPARE_DEBUG.

Quoted 9 lines
Cc Jakub Jelinek <[email protected]>
Cc Josh Boyer <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Markus Trippelsdorf <[email protected]>
Cc Michel Dänzer <[email protected]>

Frank, did you rebase this against some newer tree or something? Curious why you sent it again.

Quoted 18 lines
 Makefile          |  8 ++++++--
 lib/Kconfig.debug | 21 ++++++++++++++++++++-
 2 files changed, 26 insertions(+), 3 deletions(-)
Makefile +0 -2
index 6cc5b2434224..c8e1fcfdb41a 100644
@@ -704,8 +704,6 @@ KBUILD_CFLAGS       += -fomit-frame-pointer
 endif
 endif
 
-KBUILD_CFLAGS   += $(call cc-option, -fno-var-tracking-assignments)
-
 ifdef CONFIG_DEBUG_INFO
 ifdef CONFIG_DEBUG_INFO_SPLIT
 KBUILD_CFLAGS   += $(call cc-option, -gsplit-dwarf, -g)

Makefile ifdef CONFIG_DEBUG_INFO_DWARF4 · line 724

Quoted 9 lines
Makefile +6 -0
@@ -718,6 +716,12 @@ ifdef CONFIG_DEBUG_INFO_DWARF4
 KBUILD_CFLAGS  += $(call cc-option, -gdwarf-4,)
 endif
 
+ifdef CONFIG_DEBUG_INFO_VTA
+KBUILD_CFLAGS   += $(call cc-option, -fvar-tracking-assignments)
+else
+KBUILD_CFLAGS   += $(call cc-option, -fno-var-tracking-assignments)
+endif
+

Is there a reason you moved this hunk under the DWARF4 options instead of modifying it in-place like the original patch did?

josh

#7 lore raw

Hi, Josh -

Quoted 2 lines · Josh Boyer

[...]
Frank, did you rebase this against some newer tree or something?

Yes; the lib/Kconfig.debug part didn't apply to current git.

Quoted 1 line

Curious why you sent it again.

At least as a patch-ping; the poor-debuginfo problems are reported to affect non-fedora users too.

Quoted 9 lines

Makefile ifdef CONFIG_DEBUG_INFO_DWARF4 · line 724

Quoted 6 lines
Makefile +6 -0
+ifdef CONFIG_DEBUG_INFO_VTA
+KBUILD_CFLAGS   += $(call cc-option, -fvar-tracking-assignments)
+else
+KBUILD_CFLAGS   += $(call cc-option, -fno-var-tracking-assignments)
+endif
+

Is there a reason you moved this hunk under the DWARF4 options instead of modifying it in-place like the original patch did?

Yes, this version appears a little safer, in the sense that without CONFIG_DEBUG_INFO, neither setting of CONFIG_DEBUG_INFO_VTA would affect the CFLAGS. (In fact, Jakub advises the positive polarity -fvar-tracking-assignments is redundant with -g, and the negative polarity one only provides codegen-bug-protection in the CONFIG_DEBUG_INFO case.)

- FChE