diff options
author | Than McIntosh <thanm@google.com> | 2019-04-12 09:47:43 -0400 |
---|---|---|
committer | Than McIntosh <thanm@google.com> | 2019-09-18 17:41:44 +0000 |
commit | baf7d95350c9eab317efe769cf113b3611a6ccd0 (patch) | |
tree | a08ff5b6fe6926b828f65578d8c48b9fe3209997 /src/cmd/go/internal/modload/build.go | |
parent | 7987238d9cfcef5f79ccd9458e59e22d8a8b3cf2 (diff) | |
download | go-baf7d95350c9eab317efe769cf113b3611a6ccd0.tar.gz go-baf7d95350c9eab317efe769cf113b3611a6ccd0.zip |
cmd/go: use alternate debug_modinfo recipe for gccgo
Use a different recipe for capturing debug modinfo if we're compiling
with the gccgo toolchain, to avoid applying a go:linkname directive to
a variable (not supported by gccgo).
Fixes #30344.
Change-Id: I9ce3d42c3bbb809fd68b140f56f9bbe3406c351b
Reviewed-on: https://go-review.googlesource.com/c/go/+/171768
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/cmd/go/internal/modload/build.go')
-rw-r--r-- | src/cmd/go/internal/modload/build.go | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/src/cmd/go/internal/modload/build.go b/src/cmd/go/internal/modload/build.go index ff42516c80..f8dc0c84ff 100644 --- a/src/cmd/go/internal/modload/build.go +++ b/src/cmd/go/internal/modload/build.go @@ -249,16 +249,34 @@ func findModule(target, path string) module.Version { panic("unreachable") } -func ModInfoProg(info string) []byte { +func ModInfoProg(info string, isgccgo bool) []byte { // Inject a variable with the debug information as runtime.modinfo, // but compile it in package main so that it is specific to the binary. // The variable must be a literal so that it will have the correct value // before the initializer for package main runs. // - // The runtime startup code refers to the variable, which keeps it live in all binaries. - return []byte(fmt.Sprintf(`package main + // The runtime startup code refers to the variable, which keeps it live + // in all binaries. + // + // Note: we use an alternate recipe below for gccgo (based on an + // init function) due to the fact that gccgo does not support + // applying a "//go:linkname" directive to a variable. This has + // drawbacks in that other packages may want to look at the module + // info in their init functions (see issue 29628), which won't + // work for gccgo. See also issue 30344. + + if !isgccgo { + return []byte(fmt.Sprintf(`package main import _ "unsafe" //go:linkname __debug_modinfo__ runtime.modinfo var __debug_modinfo__ = %q `, string(infoStart)+info+string(infoEnd))) + } else { + 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))) + } } |