Skip to content

Commit 9f6936b

Browse files
committed
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 <[email protected]> Reviewed-by: Cherry Mui <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 89d41d2 commit 9f6936b

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

src/cmd/link/internal/loader/loader.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2440,6 +2440,7 @@ var blockedLinknames = map[string][]string{
24402440
// Others
24412441
"net.newWindowsFile": {"net"}, // pushed from os
24422442
"testing/synctest.testingSynctestTest": {"testing/synctest"}, // pushed from testing
2443+
"runtime.addmoduledata": {}, // disallow all package
24432444
}
24442445

24452446
// check if a linkname reference to symbol s from pkg is allowed

src/cmd/link/link_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,6 +1613,7 @@ func TestCheckLinkname(t *testing.T) {
16131613
{"coro2.go", false},
16141614
// pull linkname of a builtin symbol is not ok
16151615
{"builtin.go", false},
1616+
{"addmoduledata.go", false},
16161617
// legacy bad linkname is ok, for now
16171618
{"fastrand.go", true},
16181619
{"badlinkname.go", true},
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2025 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
// Linkname runtime.addmoduledata is not allowed.
6+
7+
package main
8+
9+
import (
10+
_ "unsafe"
11+
)
12+
13+
//go:linkname addmoduledata runtime.addmoduledata
14+
func addmoduledata()
15+
16+
func main() {
17+
addmoduledata()
18+
}

0 commit comments

Comments
 (0)