Skip to content

runtime: FileLine result is incorrect for addresses within init() functions that span files #4020

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

Closed
adonovan opened this issue Aug 29, 2012 · 10 comments
Milestone

Comments

@adonovan
Copy link
Member

Reflection over the callstack reports incorrect file/line information for init()
functions that span source files.  The filename is always that of the source file
containing the first statement of init(), and the line number is garbage, often negative.

The compiler and linker are doing the right thing; the problem is in runtime/symtab.c,
which is making the simplifying assumption that "we don't need the full generality
of the z entry history stack because there are no includes in go", i.e. every
function (Func) is associated with exactly one file.  Because init() can be spread
across files, this assumption is false.

Luckily the public interfaces are all sound, but the following changes are required:

(1) symtab.c: push each 'z' symbol on a spaghetti stack associated with the object file.
 Don't throw the previous stack away each time we encounter a new start-of-object
(z.value=1) symbol.
(2) symtab.c: to convert a composite line number (z.value) to a source line, invert the
spaghetti stack to a tree and visit it depth-first until the file containing the z.value
is found; then subtract the deltas for each file on the path via which it was found.
(3) extern.go: reflect the changes to the underlying C code.

While you're there, you may want to support 'Z' symbols (#line directives).

Attachments:

  1. bug.tar.bz2 (678 bytes)
@adonovan
Copy link
Member Author

Comment 1:

The attached tarfile contains a minimal program to reproduce the bug.  Notice the
negative line number and incorrect source file for the #1 callframe; the expected result
is a.go:16.
0       0x00424edd      /home/adonovan/src-go/google3/bug/src/b/a.go:10
1       0x00425081      /home/adonovan/src-go/google3/bug/src/b/b.go:-1
2       0x00400cd8      /home/adonovan/src-go/google3/bug/src/c.go:0
3       0x0040cec4      /home/adonovan/go/src/pkg/runtime/proc.c:234
4       0x0040cf88      /home/adonovan/go/src/pkg/runtime/proc.c:271

@robpike
Copy link
Contributor

robpike commented Aug 29, 2012

Comment 2:

Labels changed: added priority-later, removed priority-triage.

Status changed to Accepted.

@rsc
Copy link
Contributor

rsc commented Sep 12, 2012

Comment 4:

Issue #2807 has been merged into this issue.

@rsc
Copy link
Contributor

rsc commented Sep 12, 2012

Comment 5:

Issue #3689 has been merged into this issue.

@rsc
Copy link
Contributor

rsc commented Sep 12, 2012

Comment 6:

Labels changed: added go1.1.

@rsc
Copy link
Contributor

rsc commented Dec 10, 2012

Comment 7:

Labels changed: added size-l.

@rsc
Copy link
Contributor

rsc commented Mar 12, 2013

Comment 8:

Labels changed: added go1.1maybe, removed go1.1.

@gopherbot
Copy link
Contributor

@robpike
Copy link
Contributor

robpike commented May 18, 2013

Comment 10:

Labels changed: added go1.2maybe, removed go1.1maybe.

@rsc
Copy link
Contributor

rsc commented Jul 16, 2013

Comment 11:

This issue was closed by revision 5d363c6.

Status changed to Fixed.

@rsc rsc added this to the Go1.2 milestone Apr 14, 2015
@rsc rsc removed the go1.2maybe label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants