-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/compile: miscompilation of generic code; "unreachable method called. linker bug?" fatal error at runtime #48047
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
FYI, you don't need to set |
/cc @danscales @randall77 Correctly prints "\n" when built and run with GOEXPERIMENT=unified. |
Hope it helps. I add
|
We've run into this before. This is related to shapes and dictionaries, and the aggressive "dead-method" elimination by the linker. We need to mark the actual types that are may be stored in an interface (as opposed to just the shape types) and we need to mark the methods of the interface that have definitely been called. This is more of a problem with shapes/dictionaries, since most method calls become interface calls. We are already doing those extra mark calls in stencil.go - MarkUsedIfaceMethodIndex and MarkTypeUsedInInterface.
@korzhao Thanks, that is actually a helpful observation! Our problem is that these Mark calls take a symbol which they should be attached to, and the mark calls do not apply if that symbol is also dead-code eliminated. Because methods can be eliminated by inlining, we are currently using the dictionaries as the symbol. But dictionaries can also be eliminated by inlining, so we need to rethink which symbol we attach these Mark calls to. |
Change https://golang.org/cl/349169 mentions this issue: |
Change https://golang.org/cl/357836 mentions this issue: |
The method of using references to dictionaries to hold methods live during linker deadcode elimination wasn't working very well. I implemented a new scheme in the CL below this, so this CL strips out the old method. The new method has the added benefit of having 0 runtime overhead (unlike the stuff we're ripping out here, which does have a small overhead). Update #48047 Change-Id: I68ac57119792d53c58f1480f407de6ab2bb53211 Reviewed-on: https://go-review.googlesource.com/c/go/+/357836 Trust: Keith Randall <khr@golang.org> Trust: Dan Scales <danscales@google.com> Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Dan Scales <danscales@google.com>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Using latest of
dev.typeparams
branch, viagotip download dev.typeparams
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Ran across this bug by mistake while experimenting with generics. This example results in a runtime panic linker error, because a method is unreachable. The panic seems to be triggered by using a generic type for a member instead of the intended type parameter for the member type.
In the following example,
A
generic struct'sfield
member is of typeB[T2]
instead ofT1
. WhenA
is initialized withBImpl
as the type parameter a runtime panic occurs whena.field.Work()
method is called inA.Work
. I'd expectB[T2]
to be valid, even if odd, and compile/run since it is the same type asT1
.What did you expect to see?
I'd expect the program to run successful, or emit a compile time error if this use case is not intended to be supported. This should not result in a runtime failure.
What did you see instead?
The program compiles, but fails at runtime with a linker error.
The text was updated successfully, but these errors were encountered: