Skip to content
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

gccgo hash function name confusion #6789

Closed
mwhudson opened this issue Nov 19, 2013 · 4 comments
Closed

gccgo hash function name confusion #6789

mwhudson opened this issue Nov 19, 2013 · 4 comments

Comments

@mwhudson
Copy link
Contributor

Thanks.

What steps will reproduce the problem?
If possible, include a link to a program on play.golang.org.
1. go test -compiler gccgo labix.org/v2/mgo


What is the expected output?

Something like "ok   labix.org/v2/mgo 30.1s"

What do you see instead?

# testmain
/tmp/go-build500054689/labix.org/v2/mgo/_test/labix.org/v2/libmgo_test.a(mgo_test.o): In
function `mgo_test.cLogger$hash':
/home/mwhudson/goplay/src/labix.org/v2/mgo/suite_test.go:240: undefined reference to
`launchpad.net_gocheck.timer$hash'
collect2: error: ld returned 1 exit status
$WORK/labix.org/v2/mgo/_test/mgo.test
FAIL    labix.org/v2/mgo [build failed]



Which compiler are you using (5g, 6g, 8g, gccgo)?

gccgo

Which operating system are you using?

Linux


Which version are you using?  (run 'go version')

gccgo 4.8 and also tip as of a few days ago.


Please provide any additional information below.

Running with -work and poking around in the build dir we find:

mwhudson@narsil:goplay$ nm $WORK/labix.org/v2/mgo/_test/labix.org/v2/libmgo_test.a |
grep timer\$hash
                 U launchpad.net_gocheck.timer$hash
mwhudson@narsil:goplay$ nm $WORK/launchpad.net/libgocheck.a | grep timer\$hash
0000000000012506 t gocheck.timer$hash

This seems very like the issue fixed by https://golang.org/cl/5535051 but
apparently not quite the same.
@mwhudson
Copy link
Contributor Author

Comment 1:

Here is a smaller example:
mwhudson@narsil:mwhudson$ cd $GOPATH/src/mwhudson
mwhudson@narsil:mwhudson$ cat hashfun/hashfun.go
package hashfun
// this type must not be exported
// it must also be complex enough to get a $hash function generated
type unexported struct {
    a int
    b bool
}
// now embed this type in a struct that is exported
type Struct struct {
    unexported
}
mwhudson@narsil:mwhudson$ cat wtf/wtf_test.go
package wtf
import (
    "mwhudson/hashfun"
    "testing"
)
type l hashfun.Struct
func TestAll(t *testing.T) {
}
mwhudson@narsil:mwhudson$ go test -compiler gccgo mwhudson/wtf
# testmain
/tmp/go-build219194897/mwhudson/wtf/_test/mwhudson/libwtf.a(wtf.o): In function
`wtf.l$hash':
/home/mwhudson/goplay/src/mwhudson/wtf/wtf_test.go:11: undefined reference to
`mwhudson_hashfun.unexported$hash'
collect2: error: ld returned 1 exit status
FAIL    mwhudson/wtf [build failed]
It seems that the hash function for an unexported type is inconsistently named
(s/unexported/Exported/ and it works).  Bit confused as to why compiling wtf_test.go
needs to know this name, but don't know how this is supposed to work.

@mwhudson
Copy link
Contributor Author

Comment 2:

oh, it's because when you say "type l hashfun.Struct", gccgo generates a new version of
l$hash (that is presumably the same as hashfun.Struct$hash).  Could/should it not just
emit a reference to hashfun.Struct$hash instead?

@robpike
Copy link
Contributor

robpike commented Nov 20, 2013

Comment 3:

Labels changed: added priority-soon, gccgo, removed priority-triage.

Status changed to Accepted.

@ianlancetaylor
Copy link
Contributor

Comment 4:

Fixed on tip.
Thanks for the test case.

Status changed to Fixed.

@golang golang locked and limited conversation to collaborators Jun 25, 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