-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/compile: wrong function location in stacktrace #26839
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
We've been getting this wrong since at least Go 1.3. gccgo gets it right. Odd. CC @griesemer |
Thanks for filing this issue @daskol and thanks for checking on it @ianlancetaylor! I think I have an idea on what the problem is just from the stacktrace and I'll hopefully work on this in the next couple of weeks when free. |
I got sometime to examine this issue this morning and as I had suspected, Given a program https://play.golang.org/p/P1jZbt4zV-m or inlined below: package main
type a int
func (_ a) do() {
panic("panic")
}
func foo() {
var x a
_ = x.do
}
func bar() {
var m a
f := m.do
f()
}
func main() {
bar()
} TL;DR:when performing a partial call on assignment of a method as a variable and after the rewrite of var f = (a)(0).do
f() will refer to the first occurance of the similar code usage i.e. line 11 and then line 6, as reported in the bug report Long wind and investigationThe above symbol name generation is well and good until we have to link symbols, in which case every similar invocation or assignment will link to the first encountered and linked symbol because Linksym go/src/cmd/compile/internal/types/sym.go Line 86 in 897e080
retrieves names by the mechanism of go/src/cmd/compile/internal/types/sym.go Lines 67 to 74 in 897e080
and this can be confirmed by tracing through the repro and on running but most importantly notice
and then also
where only the line positions vary i.e. So therefore when ssa.go is now evaluating expressions and getting addresses for these values go/src/cmd/compile/internal/gc/ssa.go Lines 1670 to 1672 in 897e080
Linksym for the first case will be invoked with name Proposed fixPerhaps also include a helper or add the complementary to methodSymSuffix called methodSymPrefix which will instead take a prefix (the caller function name) and if the prefix is non blank will ensure that the name of the symbol is
which will always disambiguate between any clashing names or generate Linkname once perhaps using the same strategy to ensure that they never clash since function names are guaranteed to be unique lest we'd have a parse error. I could kindly use some extra eyes and perhaps a partnered CL, if you please @griesemer @ianlancetaylor @randall77, or feel free to take it away since y'all more familiar with this section of code but it touches upon different parts of the compiler and linker. Thank you. |
I don't think we should generate multiple symbols = more code. We should just pick the right line to use for this generated code. Probably the line of the start of the declared function (line 7 in the OP's code) would work. @ianlancetaylor : When you say gcc gets it right, what's right here? Which line? Possibly the right answer is to declare that the |
gccgo prints
Looking at this again, the difference is that the gc toolchain is interposing an additional stack frame:
I guess that is the generated wrapper for the method value, but the line number for that is clearly meaningless. gccgo does produce an internal call frame that it doesn't print in the traceback. The line number for that internal call frame is line 7, the declaration of |
I guess there are two fixes here then.
The latter I can fix as part of fixing #28640. |
Change https://golang.org/cl/153477 mentions this issue: |
Change https://golang.org/cl/153498 mentions this issue: |
Cool, thank you @randall77 for the fixes! |
As a followon to CL 152537, modify the panic-printing traceback to also handle mid-stack inlining correctly. Also declare -fm functions (aka method functions) as wrappers, so that they get elided during traceback. This fixes part 2 of #26839. Fixes #28640 Fixes #24488 Update #26839 Change-Id: I1c535a9b87a9a1ea699621be1e6526877b696c21 Reviewed-on: https://go-review.googlesource.com/c/153477 Reviewed-by: David Chase <drchase@google.com>
Depending on the runtime version, we'll use a different callstack depth size. This change is required because golang fixed a bug[1] that reported the wrong function location in the stacktrace. Fixing this requires changing the depth of Logf depending on the runtime employed. 1. golang/go#26839
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yep.
What operating system and processor architecture are you using (
go env
)?What did you do?
https://play.golang.org/p/JefU2uAc-17
What did you expect to see?/What did you see instead?
The issue is how Golang prints location of callable objects. The snippet below descibres the issue.
It says that it calls object located at
main.go:13
. The first of all that object in other function. And the second it is the function with the reveiver. So, I expect to seemain.go:18
ormain.go:19
.The text was updated successfully, but these errors were encountered: