]> Cypherpunks repositories - gostls13.git/commit
[release-branch.go1.23] cmd/link: allow linkname reference to a TEXT symbol regardles...
authorCherry Mui <cherryyz@google.com>
Wed, 21 May 2025 18:32:21 +0000 (14:32 -0400)
committerMichael Knyszek <mknyszek@google.com>
Thu, 29 May 2025 15:12:27 +0000 (08:12 -0700)
commit8eeb1340b230321dc3b797e4b9836cc5ef8f316d
tree9e0eab94bea5816a3d8e06fee0de4ff1962b8628
parent4ca7c01706ad6da07aed882528e595a39edd085b
[release-branch.go1.23] cmd/link: allow linkname reference to a TEXT symbol regardless of size

In CL 660696, we made the linker to choose the symbol of the
larger size in case there are multiple contentless declarations of
the same symbol. We also made it emit an error in the case that
there are a contentless declaration of a larger size and a
definition with content of a smaller size. In this case, we should
choose the definition with content, but the code accesses it
through the declaration of the larger size could fall into the
next symbol, potentially causing data corruption. So we disallowed
it.

There is one spcial case, though, that some code uses a linknamed
variable declaration to reference a function in assembly, in order
to take its address. The variable is often declared as uintptr.
The function symbol is the definition, which could sometimes be
shorter. This would trigger the error case above, causing existing
code failing to build.

This CL allows it as a special case. It is still not safe to
access the variable's content. But it is actually okay to just
take its address, which the existing code often do.

Updates #73617.
Fixes #73831.

Change-Id: I467381bc5f6baa16caee6752a0a824c7185422f6
Reviewed-on: https://go-review.googlesource.com/c/go/+/676636
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
(cherry picked from commit 70109eb32625487d9c774d602a4fa2422e218f1b)
Reviewed-on: https://go-review.googlesource.com/c/go/+/676958
TryBot-Bypass: Cherry Mui <cherryyz@google.com>
src/cmd/link/internal/loader/loader.go
src/cmd/link/link_test.go
src/cmd/link/testdata/linkname/textvar/asm.s [new file with mode: 0644]
src/cmd/link/testdata/linkname/textvar/main.go [new file with mode: 0644]