Closed thanm closed 4 years ago
Change https://golang.org/cl/239286 mentions this issue: [dev.link] cmd/{compile,link}: fix buglet in DWARF line table generation
Change https://golang.org/cl/239287 mentions this issue: cmd/compile: fix buglet in DWARF line table generation
I sent two CLs with possible fixes for this bug.
@aarzilli PTAL and let me know what you think.
I have submitted a fix for this bug on the dev.link branch; this fix will appear on the main branch at some point when it opens up for 1.16 development (Aug?). I'll hold the bug open until then.
Closing this bug, since the dev.link branch is now merged into master.
Change https://golang.org/cl/258422 mentions this issue: [release-branch.go1.15] cmd/{compile,link}: backport fix for issue 39757
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes.
What operating system and processor architecture are you using (
go env
)?linux/amd64 but this problem applies on other archs as well
What did you do?
Build a small program, e.g. "go build himom.go"
Then examine generated DWARF with "objdump -dl":
What did you expect to see?
Call to "runtime.morestack" has a source position (file/line) the same as the prolog of the function.
What did you see instead?
Source position is "autogenerated:1":
This can interfere with debugging and profiling.
One could argue that since this is compiler-generated code it's ok to give it an autogenerated source position (similar to things like method wrappers), but there is also a strong argument to be made that the morestack call is logically part of the function prolog (even though it is positioned in the cold code at the tail end of the function).
It also turns out that we haven't always marked this code with "autogenerated" -- in previous versions of Go it was being given the correct position. Here is the tail end of the assembly when built with 1.12:
It looks as though the problem was introduced when the main part of DWARF line table generation was moved from the linker in to the compiler. This code here:
https://go.googlesource.com/go/+/d1a186d29ce9d917dda7c66cfaee7788f88e7b9e/src/cmd/internal/obj/dwarf.go#112
generates a sequence at the end of each function to reset the state of the line table back to its default settings. This code doesn't advance the PC before applying the new file and line, however, meaning that it overwrites the file/line for the last row in the line table, which is what's causing the "autogenerated:1" to be picked up.
This could be fixed in a couple of ways: one would be to emit an end of sequence op after each function (in which case there would be no manual file/line settting needed). A second option would be to add code to manually advanced the PC past the end of the last instruction before emitting the set file/set line ops.