]> Cypherpunks repositories - gostls13.git/commit
[release-branch.go1.23] cmd/link: permit a larger size BSS reference to a smaller...
authorCherry Mui <cherryyz@google.com>
Thu, 26 Jun 2025 19:46:31 +0000 (15:46 -0400)
committerGopher Robot <gobot@golang.org>
Fri, 27 Jun 2025 17:20:55 +0000 (10:20 -0700)
commite919b332534b520da300ecc84330dfaeede7669d
tree02c898d5f2983821f7346bcd89e263c2caefab2d
parentc46a0e690de1b964be1999d1769177f159938226
[release-branch.go1.23] cmd/link: permit a larger size BSS reference to a smaller DATA symbol

Currently, if there is a BSS reference and a DATA symbol
definition with the same name, we pick the DATA symbol, as it
contains the right content. In this case, if the BSS reference
has a larger size, we error out, because it is not safe to access
a smaller symbol as if it has a larger size.

Sometimes code declares a global variable in Go and defines it
in assembly with content. They are expected to be of the same
size. However, in ASAN mode, we insert a red zone for the variable
on the Go side, making it have a larger size, whereas the assembly
symbol is unchanged. This causes the Go reference (BSS) has a
larger size than the assembly definition (DATA). It results in an
error currently. This code is valid and safe, so we should permit
that.

We support this case by increasing the symbol size to match the
larger size (of the BSS side). The symbol content (from the DATA
side) is kept. In some sense, we merge the two symbols. When
loading symbols, it is not easy to change its size (as the object
file may be mapped read-only), so we add it to a fixup list, and
fix it up later after all Go symbols are loaded. This is a very
rare case, so the list should not be long.

We could limit this to just ASAN mode. But it seems okay to allow
this in general. As long as the symbol has the larger size, it is
safe to access it with the larger size.

Updates #74314.
Fixes #74402.

Change-Id: I3ee6e46161d8f59500e2b81befea11e563355a57
Reviewed-on: https://go-review.googlesource.com/c/go/+/684236
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: David Chase <drchase@google.com>
(cherry picked from commit 0f8ab2db177baee7b04182f5641693df3b212aa9)
Reviewed-on: https://go-review.googlesource.com/c/go/+/684456
Auto-Submit: Dmitri Shuralyov <dmitshur@google.com>
src/cmd/cgo/internal/testsanitizers/asan_test.go
src/cmd/cgo/internal/testsanitizers/cc_test.go
src/cmd/cgo/internal/testsanitizers/testdata/asan_global_asm/asm.s [new file with mode: 0644]
src/cmd/cgo/internal/testsanitizers/testdata/asan_global_asm/main.go [new file with mode: 0644]
src/cmd/cgo/internal/testsanitizers/testdata/asan_global_asm2_fail/asm.s [new file with mode: 0644]
src/cmd/cgo/internal/testsanitizers/testdata/asan_global_asm2_fail/main.go [new file with mode: 0644]
src/cmd/link/internal/loader/loader.go