-
Notifications
You must be signed in to change notification settings - Fork 18k
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: build ID depends on the full path of Go files passed on the command line #48557
Comments
Previously: #33772. You can use |
Are you doing this with a go.mod file in the directory? @bcmills is this one for you? |
This happens regardless of go.mod or not, this specific example is not using any external packages (see caam_tool.go). The buildid is the same shown in my report (the binary diff), anyway here it is:
|
I think it;s the way the arguments are passed (list of files), building a directory/package within a module results in consistent build ids |
The presence of a go.mod or not does not change the outcome. If you are talking about modules installed with |
no, but |
With a
However the earlier The rules are not clear to me however, what's the difference between the two cases. In my mind, they should behave identically. |
We did some debugging with @abarisani and we realized it's not the output path that ends up hashed in the Build ID, but the full path of the input files, because With (I wish we were more aggressive in discouraging the use of Go files on the command line. A lot of things, from build tags to multi-file packages if a file is left out, subtly breaks.) |
It would make this debugging much easier if |
Setting |
I tried this in a quick example. Here's the cache key I'm seeing: HASH[build command-line-arguments] HASH[build command-line-arguments]: "devel go1.18-8ff94bbecb Wed Sep 22 13:48:21 2021 -0700" HASH[build command-line-arguments]: "compile\n" HASH[build command-line-arguments]: "goos linux goarch amd64\n" HASH[build command-line-arguments]: "import \"command-line-arguments\"\n" HASH[build command-line-arguments]: "omitdebug false standard false local true prefix \"_/home/jay/Code/test/a\"\n" HASH[build command-line-arguments]: "trimpath\n" HASH[build command-line-arguments]: "modinfo \"path\\tcommand-line-arguments\\n\"\n" HASH[build command-line-arguments]: "compile tdLvclvHAV-OCkdMX9DV [] []\n" HASH[build command-line-arguments]: "GOAMD64=v1\n" HASH /home/jay/Code/test/a/main.go: 55a60bb97151b2b4b680462447ce60ec34511b14fa10d77440c97b9777101566 HASH[build command-line-arguments]: "file main.go VaYLuXFRsrS2gEYkR85g\n" HASH[build command-line-arguments]: "import runtime -vV7n2SyuxUHQNgBVBri\n" HASH[build command-line-arguments]: 7b6cdecf56c1e3618c9976560d07fa292928f32ba7b821fa31d29891f8114128 The bold string above is an absolute path to the package's local prefix, which is used to resolve relative imports like:
Those are only allowed in packages specified as a list of files on the command line. I agree with @FiloSottile: I wish these weren't a thing. I can't think of a good reason for the local prefix to be part of the cache key, and it doesn't really seem like it should be a distinct field from the package directory anyway. By the time the go command computes the cache key, it should already have resolved imports, and the output ids from those imports will be part of the cache key. We do pass the local prefix to the compiler in gc.go. Not sure why the compiler needs it or if it affects the output. |
Let's try not doing that and see what breaks! 😁 |
The flag is consumed here: |
Yeah. Perhaps we can start by just not passing that flag when |
@dr2chase Does the I'd expect that cmd/go could pass in an importcfg file that just maps import strings to .a file paths. Ideally the compiler wouldn't need |
I am not sure. There's a lot going on. The fact that debugging seems to be able to find the source file (in the default case, at least) suggests that at least some absolute paths are embedded in the debugging information. E.g.:
(this in a an executable that I copied into /tmp/bar, also debugged in that directory) |
But with |
The leading Debugging in the directory where I built it, delve is kinda puzzled:
|
Change https://golang.org/cl/352810 mentions this issue: |
CL 352810 should fix this in module mode. A fix in GOPATH mode would be much more invasive and doesn't seem worth doing: as far as I can tell this isn't a regression from previous Go releases, and triggering the problematic behavior would require the combination of |
In GOPATH mode, source files may import other packages using relative (“local”) paths. In module mode, relative imports are never allowed: import paths must always be fully specified. When local imports are allowed, we pass a local-import prefix to the compiler using the '-D' flag. That could theoretically change the compiler's output, so it must be included in the cache key even when -trimpath is set. (TODO: when -trimpath is set, the local-import prefix ought to be trimmed anyway, so it still shouldn't matter.) However, when local imports are disallowed, we should not pass the local-import prefix and it should not affect cmd/go's cache key or the final build ID of any artifact. For #48557 Change-Id: I2d627d67d13e5da2cac6d411cd4e2d87e510876c Reviewed-on: https://go-review.googlesource.com/c/go/+/352810 Trust: Bryan C. Mills <bcmills@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
This is now fixed in module mode, and I do not plan to address it in GOPATH mode, so closing as “as fixed as it's going to be”. |
When failing to create reproducible builds using go1.17.1, despite our best effort in ensuring that compiler and compilation flags are identical as well as
GOROOT
, we identified that the Build ID is dependent on the output path.What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
What did you expect to see?
We do not expect the build ID to be affected by the output path when building identical code under the same compiler version and flags.
What did you see instead?
The output binaries are identical with the sole exception of the build ID:
The text was updated successfully, but these errors were encountered: