remove init function in __debug_modinfo__ initialization to fix #29628

This commit is contained in:
Viacheslav Poturaev 2019-01-09 13:45:39 +01:00
parent 5efe9a8f11
commit 9275dd8f1c
1 changed files with 2 additions and 5 deletions

View File

@ -252,13 +252,10 @@ func findModule(target, path string) module.Version {
func ModInfoProg(info string) []byte { func ModInfoProg(info string) []byte {
// Inject a variable with the debug information as runtime/debug.modinfo, // Inject a variable with the debug information as runtime/debug.modinfo,
// but compile it in package main so that it is specific to the binary. // but compile it in package main so that it is specific to the binary.
// Populate it in an init func so that it will work with go:linkname, // No need to populate in an init func, it will still work with go:linkname,
// but use a string constant instead of the name 'string' in case
// package main shadows the built-in 'string' with some local declaration.
return []byte(fmt.Sprintf(`package main return []byte(fmt.Sprintf(`package main
import _ "unsafe" import _ "unsafe"
//go:linkname __debug_modinfo__ runtime/debug.modinfo //go:linkname __debug_modinfo__ runtime/debug.modinfo
var __debug_modinfo__ = "" var __debug_modinfo__ = %q
func init() { __debug_modinfo__ = %q }
`, string(infoStart)+info+string(infoEnd))) `, string(infoStart)+info+string(infoEnd)))
} }