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/compile: init code or linker should verify package "fingerprint" #20486

Open
griesemer opened this issue May 24, 2017 · 1 comment
Open
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. help wanted NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@griesemer
Copy link
Contributor

Given a file lib.go:

package lib

func F() int { return 42 }

and main.go:

package main

import "./lib"

func main() { println(lib.F()) }

The following command sequence prints 42 as expected:

$ go tool compile lib.go 
$ go tool compile main.go
$ go tool link main.o
$ a.out
42

If one now changes 42 to 43 in lib.go, the following command sequence still prints 42:

$ go tool compile lib.go 
$ go tool link main.o
$ a.out
42

rather than 43. The issue is (presumably) that lib.F() got inlined and there's (apparently) no check in the linker that lib.go changed.

While not surprising to an initiated user, this is surprising to an unsuspecting user. Ideally the linker, or then the initialization code should check that a compiler package we link again (or that we initialize) is the same that we compiled against. This could be done with some fingerprint of sorts, perhaps computed on the export data only.

I suspect scenarios can be created where the linker succeeds and the program crashes (because a data type changed in lib.go and main.go wasn't recompiled).

This behavior is no different from C/C++ where we have "independent" compilation: as long as the linker finds the matching symbols, it doesn't care whether they are referring to the same entities that were implied in the source code - hence the independence.

Go should properly implement "separate" compilation: packages can be compiled separately, but correspondence to source code should be enforced.

@andybons andybons added NeedsFix The path to resolution is known, but the work has not been done. help wanted labels Apr 11, 2018
@andybons andybons added this to the Unplanned milestone Apr 11, 2018
@filewalkwithme
Copy link
Contributor

I might be wrong, but I suspect that this was fixed by 229618

If I try the steps below using go1.18.1

If one now changes 42 to 43 in lib.go, the following command sequence still prints 42:

$ go tool compile lib.go 
$ go tool link main.o
$ a.out
42

I will get this output:

go tool link main.o
/usr/local/go/pkg/tool/linux_amd64/link: fingerprint mismatch: /tmp/lib has 8849f3de946169cc, import from main expecting 1172c1a932b2160a

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jul 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. help wanted NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants