-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/go: cgo #line directives cause non-reproducibility #36072
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
Comments
cc @bcmills Marking this as a release blocker for Go 1.14. I'd like to put in at least a partial fix before then. This should not block the beta. |
Is this new? I thought this was fixed for most systems by #13247. |
@ianlancetaylor Thanks for pointing out #13247. That didn't come up in my search. I don't think it's quite the same issue though. That one is about eliding the temporary work directory, which we're doing. This issue is about eliding the source directory. In any case, I don't think this is a new issue. Though it might be considered a bug with |
A closely related problem: generated cgo files are cached for each package, and when |
Change https://golang.org/cl/210943 mentions this issue: |
Change https://golang.org/cl/212101 mentions this issue: |
CL 210943 seems too big for 1.14 at this point. It also doesn't completely solve the problem. We should try to make linked cgo binaries completely reproducible when the host linker supports that. For linkers that don't support it, we should understand why. CL 212101 is a smaller fix that should mitigate the issue. It will pass Removed the release-blocker label after discussion with @bcmills. I'd like for this to be mitigated with CL 212101, but it isn't severe enough to block the release. |
When then go command is run with -trimpath, it will now use -fdebug-prefix-map when invoking the C compiler (if supported) to replace the source root directory with a dummy root directory. This should prevent source directories from appearing either literally or in compressed DWARF in linked binaries. Updates #36072 Change-Id: Iedd08d5e886f81e981f11248a1be4ed4f58bdd29 Reviewed-on: https://go-review.googlesource.com/c/go/+/212101 Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
When then go command is run with -trimpath, it will now use -fdebug-prefix-map when invoking the C compiler (if supported) to replace the source root directory with a dummy root directory. This should prevent source directories from appearing either literally or in compressed DWARF in linked binaries. Updates golang#36072 Change-Id: Iedd08d5e886f81e981f11248a1be4ed4f58bdd29 Reviewed-on: https://go-review.googlesource.com/c/go/+/212101 Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
Moving to Backlog. |
I think my change should fix this issue? |
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?
Build an executable that depends on one or more cgo packages using
-trimpath
.This can be reproduced by adding some cgo code to the program in
build_trimpath.txt
, the test case that covers-trimpath
.Also observe that
strings $(go env GOROOT)/pkg/darwin_amd64/os/user.a
prints file names in random temporary directories under/private/var
, indicating these paths weren't completely scrubbed from standard library packages that include cgo.Below is a longer test case. It builds a small cgo program, then lists file names in the DWARF data in the executable. The working directory should not be listed (but it is).
What did you expect to see?
When the
-trimpath
flag is used, the package root directories (including GOROOT, GOPATH roots, and module roots) should not appear in binaries produced by thego
command or in any intermediate file.What did you see instead?
.c files created by cgo include
#line
directives that point back to the original source files. These .c files are intermediate files, so with-trimpath
, they shouldn't include absolute paths. The paths should just be derived from the import path, the module path, and the version.When we compile these files, we use
-fdebug-prefix-map
to strip the temporary working directory, but we don't use that flag to remove the source directory. If#line
directives are correctly stripped, we don't need this for intermediate.c
files, but we still need it for source.c
files. Without this flag, absolute paths to the source directory end up in the DWARF data in the compiled.o
files.I don't know much about the DWARF format, but I think paths are compressed in the linked binaries we're producing.
strings
doesn't show any inappropriate source paths, butdwarf-list-files.go
in the test case above does. Also, it seems like the linker has special handling forGOROOT_FINAL
for binaries inGOROOT
, but I'm not sure how that works.The text was updated successfully, but these errors were encountered: