-
Notifications
You must be signed in to change notification settings - Fork 18k
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
cmd/go: package main fails to compile with gccgo in module mode due to //go:linkname restriction #30344
Comments
Yeah, the gccgo version of this code looks like this: func ModInfoProg(info string) []byte {
return []byte(fmt.Sprintf(`package main
import _ "unsafe"
//go:linkname __set_debug_modinfo__ runtime..z2fdebug.setmodinfo
func __set_debug_modinfo__(string)
func init() { __set_debug_modinfo__(%q) }
`, string(infoStart)+info+string(infoEnd)))
} We'll need to change cmd/go to switch based on the compiler in use. The gccgo variant is not as good because it assumes that the package does not redefine |
Change https://golang.org/cl/171768 mentions this issue: |
For linkname on variables, would it work if we always treat it as definition, but generate a weak symbol if it is not explicitly initialized, and generate a strong symbol if it is? Then the linker will choose the strong symbol if there is one, otherwise use the weak symbol, and allow duplication. It doesn't work if more than one have initialization values, but I think this is fine -- it cannot work anyway. |
Also worth noting that with gccgo we support shared linkage (runtime + std packages in libgo.so), so we can't assume that when a program is linked the linker will see the runtime package object file. |
Defining a weak symbol, intended to be a reference, means that the strong definition will not be brought in from an archive, so in the general case that approach doesn't work. I think the compiler needs to know whether the variable is intended to be a definition or a reference, but |
Change https://golang.org/cl/196237 mentions this issue: |
Fix bug in previous CL 171768 -- with Go 1.13 the proper entry point to call is runtime.setmodinfo, not runtime..z2fdebug.setmodinfo (this changed when we moved from 1.12). [ Unclear why trybots and runs of all.bash didn't catch this, but hand testing made it apparent. ] Updates #30344. Change-Id: I91f47bd0c279ad2d84875051be582818b13735b6 Reviewed-on: https://go-review.googlesource.com/c/go/+/196237 Run-TryBot: Than McIntosh <thanm@google.com> Reviewed-by: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
Noticed in the course of updating
misc/cgo/testshared
.I believe that this restriction will cause all
gccgo
builds to fail in module mode.(CC @ianlancetaylor @thanm @jayconrod)
The text was updated successfully, but these errors were encountered: