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

Strip stdlib paths from binaries #971

Merged
merged 2 commits into from
Nov 1, 2017

Conversation

jayconrod
Copy link
Contributor

Set GOROOT_FINAL to a constant string ('GOROOT') when
linking. Normally, the actual path to GOROOT is set in linked
binaries, which results in non-reproducible builds. GOROOT_FINAL
provides a constant replacement.

Also, added a test for common reproducibility problems.

Fixes #969

Set GOROOT_FINAL to a constant string ('GOROOT') when
linking. Normally, the actual path to GOROOT is set in linked
binaries, which results in non-reproducible builds. GOROOT_FINAL
provides a constant replacement.

Also, added a test for common reproducibility problems.

Fixes bazel-contrib#969
@jayconrod jayconrod merged commit a931a1e into bazel-contrib:master Nov 1, 2017
@jayconrod jayconrod deleted the rules-strip-goroot branch November 1, 2017 14:24
JacobOaks added a commit to JacobOaks/rules_go that referenced this pull request Jul 8, 2024
Due to golang/go#62047, Go 1.23 won't support `GOROOT_FINAL`.
This means that bazel-contrib#971 will no longer fix bazel-contrib#969,
meaning linked binaries will contain full GOROOT paths, making them non-reproducible.

Instead of using `GOROOT_FINAL`, this change sets `GOROOT` when invoking the linker,
which will cause the linker to continue to write `GOROOT` into the binary,
keeping builds consistent.

This works on Go 1.23rc1 as well.

I'm not a rules_go expert and I'm not married to this particular solution,
I just wanted to bring attention to the issue.
If there's a clever way we can set `-trimpath` when invoking the compiler,
that might be better - but we already use that flag to trim off the bazel sandbox I believe.
fmeum pushed a commit that referenced this pull request Jul 16, 2024
* Clear GOROOT when linking

Due to golang/go#62047, Go 1.23 won't support `GOROOT_FINAL`.
This means that #971 will no longer fix #969,
meaning linked binaries will contain full GOROOT paths, making them non-reproducible.

Instead of using `GOROOT_FINAL`, this change sets `GOROOT` when invoking the linker,
which will cause the linker to continue to write `GOROOT` into the binary,
keeping builds consistent.

This works on Go 1.23rc1 as well.

I'm not a rules_go expert and I'm not married to this particular solution,
I just wanted to bring attention to the issue.
If there's a clever way we can set `-trimpath` when invoking the compiler,
that might be better - but we already use that flag to trim off the bazel sandbox I believe.

* switch based on runtime.Version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants