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/link: linkname directive on userspace variable can override runtime variable [1.24 backport] #73092

Closed
gopherbot opened this issue Mar 28, 2025 · 3 comments
Labels
CherryPickApproved Used during the release process for point releases compiler/runtime Issues related to the Go compiler and/or runtime.
Milestone

Comments

@gopherbot
Copy link
Contributor

@cherrymui requested issue #72032 to be considered for backport to the next 1.24 minor release.

@gopherbot please backport this to previous releases. This is a regression that breaks some existing uses of linkname. Thanks.

@gopherbot gopherbot added the CherryPickCandidate Used during the release process for point releases label Mar 28, 2025
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Mar 28, 2025
@gopherbot gopherbot modified the milestones: Go1.24.2, Go1.24.3 Mar 28, 2025
@cagedmantis
Copy link
Contributor

This backport request has been approved. We should keep compatibility with previous versions.

@cagedmantis cagedmantis added the CherryPickApproved Used during the release process for point releases label Apr 2, 2025
@gopherbot gopherbot removed the CherryPickCandidate Used during the release process for point releases label Apr 2, 2025
@gopherbot
Copy link
Contributor Author

Change https://go.dev/cl/662335 mentions this issue: [release-branch.go1.24] cmd/link: choose one with larger size for duplicated BSS symbols

gopherbot pushed a commit that referenced this issue Apr 10, 2025
…licated BSS symbols

When two packages declare a variable with the same name (with
linkname at least on one side), the linker will choose one as the
actual definition of the symbol if one has content (i.e. a DATA
symbol) and the other does not (i.e. a BSS symbol). When both have
content, it is redefinition error. When neither has content,
currently the choice is sort of arbitrary (depending on symbol
loading order, etc. which are subject to change).

One use case for that is that one wants to reference a symbol
defined in another package, and the reference side just wants to
see some of the fields, so it may be declared with a smaller type.
In this case, we want to choose the one with the larger size as
the true definition. Otherwise the code accessing the larger
sized one may read/write out of bounds, corrupting the next
variable. This CL makes the linker do so.

Also include the followup fix CL 661915.

Fixes #73092.
Updates #72032.

Change-Id: I160aa9e0234702066cb8f141c186eaa89d0fcfed
Reviewed-on: https://go-review.googlesource.com/c/go/+/660696
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Than McIntosh <thanm@golang.org>
(cherry picked from commit 8f6c083)
Reviewed-on: https://go-review.googlesource.com/c/go/+/662335
Auto-Submit: Dmitri Shuralyov <dmitshur@google.com>
@gopherbot
Copy link
Contributor Author

Closed by merging CL 662335 (commit a9d9b55) to release-branch.go1.24.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CherryPickApproved Used during the release process for point releases compiler/runtime Issues related to the Go compiler and/or runtime.
Projects
None yet
Development

No branches or pull requests

2 participants