diff options
| author | zuojunwei.1024 <zuojunwei.1024@bytedance.com> | 2025-08-28 17:32:09 +0800 |
|---|---|---|
| committer | Wayne Zuo <wdvxdr1123@gmail.com> | 2025-08-29 09:36:19 -0700 |
| commit | 9f6936b8da81672cebcfa7ac3d6edddf9f1a5d65 (patch) | |
| tree | cfb6da5515313f6c16e9f6c4a93def1df878bc04 /src | |
| parent | 89d41d254a758f9b5e554761c92508220f4342a5 (diff) | |
| download | go-9f6936b8da81672cebcfa7ac3d6edddf9f1a5d65.tar.xz | |
cmd/link: disallow linkname of runtime.addmoduledata
Although a comment on addmoduledata warns that it should not be
called from Go code, the linker still allow it to be accessed via
go:linkname. Using linkname on this function will cause a linker
crash when building with buildmode=plugin.
Fixes #75180
Change-Id: Ib72c367a8afaef712ca5e29b1d0a4fc98ed8f40f
Reviewed-on: https://go-review.googlesource.com/c/go/+/699655
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/cmd/link/internal/loader/loader.go | 1 | ||||
| -rw-r--r-- | src/cmd/link/link_test.go | 1 | ||||
| -rw-r--r-- | src/cmd/link/testdata/linkname/addmoduledata.go | 18 |
3 files changed, 20 insertions, 0 deletions
diff --git a/src/cmd/link/internal/loader/loader.go b/src/cmd/link/internal/loader/loader.go index a02a268880..9f3ea3e553 100644 --- a/src/cmd/link/internal/loader/loader.go +++ b/src/cmd/link/internal/loader/loader.go @@ -2440,6 +2440,7 @@ var blockedLinknames = map[string][]string{ // Others "net.newWindowsFile": {"net"}, // pushed from os "testing/synctest.testingSynctestTest": {"testing/synctest"}, // pushed from testing + "runtime.addmoduledata": {}, // disallow all package } // check if a linkname reference to symbol s from pkg is allowed diff --git a/src/cmd/link/link_test.go b/src/cmd/link/link_test.go index 2fe32600f1..a87d452ed3 100644 --- a/src/cmd/link/link_test.go +++ b/src/cmd/link/link_test.go @@ -1613,6 +1613,7 @@ func TestCheckLinkname(t *testing.T) { {"coro2.go", false}, // pull linkname of a builtin symbol is not ok {"builtin.go", false}, + {"addmoduledata.go", false}, // legacy bad linkname is ok, for now {"fastrand.go", true}, {"badlinkname.go", true}, diff --git a/src/cmd/link/testdata/linkname/addmoduledata.go b/src/cmd/link/testdata/linkname/addmoduledata.go new file mode 100644 index 0000000000..40d2b57a4a --- /dev/null +++ b/src/cmd/link/testdata/linkname/addmoduledata.go @@ -0,0 +1,18 @@ +// Copyright 2025 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Linkname runtime.addmoduledata is not allowed. + +package main + +import ( + _ "unsafe" +) + +//go:linkname addmoduledata runtime.addmoduledata +func addmoduledata() + +func main() { + addmoduledata() +} |
