Skip to content

cmd/go: use the resolved buildmode in build IDs and build info#80312

Open
harjothkhara wants to merge 1 commit into
golang:masterfrom
harjothkhara:issue-63559-buildmode
Open

cmd/go: use the resolved buildmode in build IDs and build info#80312
harjothkhara wants to merge 1 commit into
golang:masterfrom
harjothkhara:issue-63559-buildmode

Conversation

@harjothkhara

Copy link
Copy Markdown
Contributor

When -buildmode=default is used, the link action ID hashed the
literal string "default", so building with -buildmode=default and
building with the buildmode it resolves to produced binaries that
were identical except for their build IDs. Hash the resolved
buildmode (ldBuildmode) instead, so that equivalent builds share a
build ID and cached link outputs.

Additionally, the build info stamped into binaries normalized
-buildmode=default to "exe" without accounting for platforms where
the default is PIE (android, ios, darwin, and windows without
-race), misreporting the buildmode actually given to the linker.
Record "pie" on those platforms instead.

Together these make it possible to reproduce a binary built with
-buildmode=default from its stamped build info alone.

Fixes #63559

@google-cla

google-cla Bot commented Jul 8, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@harjothkhara

harjothkhara commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

Couple scope notes:

  • Left the gccgo codegenArg asymmetry bcmills mentioned alone (explicit pie sets -fPIE, default->pie doesn't). That's why the test skips gccgo. Can file a separate issue if useful.

  • Behavior change on PIE-default platforms (darwin, windows w/o -race, android, ios): go version -m now reports pie instead of exe for default builds, and build IDs change. No doc/next in the tree right now, can add a release note when it's back.

When -buildmode=default is used, the link action ID hashed the
literal string "default", so building with -buildmode=default and
building with the buildmode it resolves to produced binaries that
were identical except for their build IDs. Hash the resolved
buildmode (ldBuildmode) instead, so that equivalent builds share a
build ID and cached link outputs.

Additionally, the build info stamped into binaries normalized
-buildmode=default to "exe" without accounting for platforms where
the default is PIE (android, ios, darwin, and windows without
-race), misreporting the buildmode actually given to the linker.
Record "pie" on those platforms instead.

Together these make it possible to reproduce a binary built with
-buildmode=default from its stamped build info alone.

Fixes golang#63559
@harjothkhara harjothkhara force-pushed the issue-63559-buildmode branch from 7762fff to 1ddf5bf Compare July 9, 2026 02:53
@gopherbot

Copy link
Copy Markdown
Contributor

This PR (HEAD: 1ddf5bf) has been imported to Gerrit for code review.

Please visit Gerrit at https://go-review.googlesource.com/c/go/+/798680.

Important tips:

  • Don't comment on this PR. All discussion takes place in Gerrit.
  • You need a Gmail or other Google account to log in to Gerrit.
  • To change your code in response to feedback:
    • Push a new commit to the branch used by your GitHub PR.
    • A new "patch set" will then appear in Gerrit.
    • Respond to each comment by marking as Done in Gerrit if implemented as suggested. You can alternatively write a reply.
    • Critical: you must click the blue Reply button near the top to publish your Gerrit responses.
    • Multiple commits in the PR will be squashed by GerritBot.
  • The title and description of the GitHub PR are used to construct the final commit message.
    • Edit these as needed via the GitHub web interface (not via Gerrit or git).
    • You should word wrap the PR description at ~76 characters unless you need longer lines (e.g., for tables or URLs).
  • See the Sending a change via GitHub and Reviews sections of the Contribution Guide as well as the FAQ for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cmd/go: value of -buildmode in buildinfo can differ from what is used in build ID

2 participants