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

cmd/go: package main fails to compile with gccgo in module mode due to //go:linkname restriction #30344

Open
bcmills opened this Issue Feb 21, 2019 · 1 comment

Comments

Projects
None yet
3 participants
@bcmills
Copy link
Member

bcmills commented Feb 21, 2019

Noticed in the course of updating misc/cgo/testshared.

    shared_test.go:680: executing go install -installsuffix=3916589616287113937 -compiler=gccgo -linkshared ./exe2 failed exit status 2:
        # testshared/exe2
        /tmp/go-build891467494/b001/_gomod_.go:3:3: error: __debug_modinfo__ is not a function; //go:linkname is only supported for functions
         //go:linkname __debug_modinfo__ runtime/debug.modinfo
           ^
~/bin$ $(go env GCCGO) --version
gccgo (Debian 8-20180218-1) 8.0.1 20180218 (experimental) [trunk revision 257787]

I believe that this restriction will cause all gccgo builds to fail in module mode.

(CC @ianlancetaylor @thanm @jayconrod)

@bcmills bcmills added the modules label Feb 21, 2019

@gopherbot gopherbot added this to the Gccgo milestone Feb 21, 2019

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

ianlancetaylor commented Feb 21, 2019

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 string. But the concept of using go:linkname with a variable can not be implemented by gccgo. The problem is that we don't know whether go:linkname is being used with a variable definition or a variable reference. The Go linker finesses this issue by marking variables that use go:linkname as "dupok", and then treating the variable as a definition. Since gccgo does not have its own linker, that avenue is not available.

@ianlancetaylor ianlancetaylor changed the title gccgo: package main fails to compile in module mode due to //go:linkname restriction cmd/go: package main fails to compile with gccgo in module mode due to //go:linkname restriction Feb 21, 2019

@ianlancetaylor ianlancetaylor modified the milestones: Gccgo, Go1.13 Feb 21, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.