aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/internal
diff options
context:
space:
mode:
authorCherry Mui <cherryyz@google.com>2025-11-25 13:54:18 -0500
committerCherry Mui <cherryyz@google.com>2026-04-01 11:00:13 -0700
commit46755cb4dea406093296ead4250ff5f7091c04a2 (patch)
tree4558617545a2c0b2dc924d2f95c15655ccb74ee3 /src/cmd/internal
parent8ea160279ff6700282f254d6b74fb02f8a316abe (diff)
downloadgo-46755cb4dea406093296ead4250ff5f7091c04a2.tar.xz
cmd/compile, cmd/link: add linknamestd directive for std-only linknames
In the standard library, there are a number of linknames, for sharing symbols within the standard library. They are not supposed to be accessed externally. But currently there is no good mechanism to prevent that. In the linker we have a blocklist of linknames, which forbids linkname references other than explicitly allowed packages. The blocklist is manually maintained, requiring periodic manual update. To move away from that manually maintained blocklist, this CL introduces a new directive, linknamestd, that marks a linkname for use within the standard library only. The linker will allow references within the standard library and forbid others. For a proof of concept, runtime.coroswitch is removed from the blocklist, and replaced with linknamestd. An external reference to it is still disallowed by the linker, as tested with cmd/link.TestCheckLinkname with testdata/linkname/coro.go. Change-Id: I0d0f8746b8835d8cdcfc3ff835d22a551da5f038 Reviewed-on: https://go-review.googlesource.com/c/go/+/749942 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com>
Diffstat (limited to 'src/cmd/internal')
-rw-r--r--src/cmd/internal/goobj/objfile.go2
-rw-r--r--src/cmd/internal/obj/link.go5
-rw-r--r--src/cmd/internal/obj/objfile.go3
3 files changed, 10 insertions, 0 deletions
diff --git a/src/cmd/internal/goobj/objfile.go b/src/cmd/internal/goobj/objfile.go
index cca3c840e0..679f4357e2 100644
--- a/src/cmd/internal/goobj/objfile.go
+++ b/src/cmd/internal/goobj/objfile.go
@@ -306,6 +306,7 @@ const (
SymFlagDict
SymFlagPkgInit
SymFlagLinkname
+ SymFlagLinknameStd
SymFlagABIWrapper
SymFlagWasmExport
)
@@ -340,6 +341,7 @@ func (s *Sym) IsItab() bool { return s.Flag2()&SymFlagItab != 0 }
func (s *Sym) IsDict() bool { return s.Flag2()&SymFlagDict != 0 }
func (s *Sym) IsPkgInit() bool { return s.Flag2()&SymFlagPkgInit != 0 }
func (s *Sym) IsLinkname() bool { return s.Flag2()&SymFlagLinkname != 0 }
+func (s *Sym) IsLinknameStd() bool { return s.Flag2()&SymFlagLinknameStd != 0 }
func (s *Sym) ABIWrapper() bool { return s.Flag2()&SymFlagABIWrapper != 0 }
func (s *Sym) WasmExport() bool { return s.Flag2()&SymFlagWasmExport != 0 }
diff --git a/src/cmd/internal/obj/link.go b/src/cmd/internal/obj/link.go
index 088a7c57aa..69c9e7583b 100644
--- a/src/cmd/internal/obj/link.go
+++ b/src/cmd/internal/obj/link.go
@@ -977,6 +977,9 @@ const (
// Linkname indicates this is a go:linkname'd symbol.
AttrLinkname
+ // LinknameStd indicates this is a go:linknamestd'd symbol.
+ AttrLinknameStd
+
// attrABIBase is the value at which the ABI is encoded in
// Attribute. This must be last; all bits after this are
// assumed to be an ABI value.
@@ -1007,6 +1010,7 @@ func (a *Attribute) ABIWrapper() bool { return a.load()&AttrABIWrapper !
func (a *Attribute) IsPcdata() bool { return a.load()&AttrPcdata != 0 }
func (a *Attribute) IsPkgInit() bool { return a.load()&AttrPkgInit != 0 }
func (a *Attribute) IsLinkname() bool { return a.load()&AttrLinkname != 0 }
+func (a *Attribute) IsLinknameStd() bool { return a.load()&AttrLinknameStd != 0 }
func (a *Attribute) Set(flag Attribute, value bool) {
for {
@@ -1057,6 +1061,7 @@ var textAttrStrings = [...]struct {
{bit: AttrABIWrapper, s: "ABIWRAPPER"},
{bit: AttrPkgInit, s: "PKGINIT"},
{bit: AttrLinkname, s: "LINKNAME"},
+ {bit: AttrLinknameStd, s: "LINKNAMESTD"},
}
// String formats a for printing in as part of a TEXT prog.
diff --git a/src/cmd/internal/obj/objfile.go b/src/cmd/internal/obj/objfile.go
index ea1483de01..de5f172b11 100644
--- a/src/cmd/internal/obj/objfile.go
+++ b/src/cmd/internal/obj/objfile.go
@@ -360,6 +360,9 @@ func (w *writer) Sym(s *LSym) {
// The runtime linknames main.main.
flag2 |= goobj.SymFlagLinkname
}
+ if s.IsLinknameStd() {
+ flag2 |= goobj.SymFlagLinknameStd
+ }
if s.ABIWrapper() {
flag2 |= goobj.SymFlagABIWrapper
}