-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
Module Info (runtime.modinfo) prevents binary comparison #49573
Comments
Duplicate of #46400 |
Oh nice, that would solve the problem. Thanks. Also wanted to follow-up on the related GOPATH aspect, since I looked into it further:
Removing My workaround for that is to move the contents of The second challenge is that With those pieces in place, we can run TLDR: #46400 will solve the original issue, and the proposed var version = regexp.MustCompile("(=>[^;@]*)@v[0-9][^/;]*")
func main() {
var args []string
trimpath := false
for _, arg := range os.Args[1:] {
if trimpath {
// Remove version suffixes from trimmed paths.
arg = version.ReplaceAllString(arg, "$1")
trimpath = false
} else if arg == "-trimpath" {
trimpath = true
} else if strings.HasSuffix(arg, "/_gomod_.go") {
// Omit runtime.modinfo when compiling.
continue
}
args = append(args, arg)
}
cmd := exec.Command(args[0], args[1:]...)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run()
if err != nil {
if ee, ok := err.(*exec.ExitError); ok {
os.Exit(ee.ProcessState.ExitCode())
} else {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}
}
} |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes, it also happens when I build
go version go1.17.3 darwin/amd64
from source.What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
What did you expect to see?
Expected to see the vendored build produce the same binary, with checksum 4117901733. Or at the very least, expected there to be some combination of build flags where
go mod vendor
doesn't affect the build output.What did you see instead?
The checksum changed to 2432579230. The most obvious difference comes from runtime.modinfo, where the versioned result doesn't include module hashes:
I can eliminate the discrepancy by modifying src/cmd/go/internal/load/pkg.go to skip the
modload.PackageBuildInfo()
call. And then confirmed-ldflags="-s -w"
wasn't needed, since-trimpath
is enough to make the two builds identical using the modified release.I realize the compiler isn't obligated to produce identical outputs in this situation, and that the metadata is normally useful. However, these differences make it impossible to double-check for correctness when migrating to and from vendored mode. Unfortunately, compiler bugs are probably more common than we'd like to admit, and even if the compiler is perfect, my understanding of them definitely isn't. 🙂 So I've gotten in the habit of double-checking things.
Basically, it would be nice to have an off switch. See #41895 for a similar issue. In my case, passing in
-linkshared
was not permitted. (And even if it worked, it certainly wasn't designed for this.) There are new options-buildinfo
and-buildvcs
in master, but they only control new fields being added toruntime.modinfo
in the next release. This could actually be a good opportunity to come up with a more flexible option for that, like-buildinfo=flags,vcs
and-buildinfo=none
, since those options haven't been released yet.I ran into similar difficulty when migrating from GOPATH mode to module-aware mode, and suspect that
runtime.modinfo
was a culprit there too.The text was updated successfully, but these errors were encountered: