From: Cherry Mui Date: Thu, 16 May 2024 21:19:15 +0000 (-0400) Subject: all: add push linknames to allow legacy pull linknames X-Git-Tag: go1.23rc1~294 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=41aab30bd260297ad8ddad47e98fdf8390a9a67e;p=gostls13.git all: add push linknames to allow legacy pull linknames CL 585358 adds restrictions to disallow pull-only linknames (currently off by default). Currently, there are quite some pull- only linknames in user code in the wild. In order not to break those, we add push linknames to allow them to be pulled. This CL includes linknames found in a large code corpus (thanks Matthew Dempsky and Michael Pratt for the analysis!), that are not currently linknamed. Updates #67401. Change-Id: I32f5fc0c7a6abbd7a11359a025cfa2bf458fe767 Reviewed-on: https://go-review.googlesource.com/c/go/+/586137 Reviewed-by: Russ Cox LUCI-TryBot-Result: Go LUCI --- diff --git a/src/cmd/link/link_test.go b/src/cmd/link/link_test.go index 1ce484fe61..e33494f7f1 100644 --- a/src/cmd/link/link_test.go +++ b/src/cmd/link/link_test.go @@ -1440,6 +1440,7 @@ func TestCheckLinkname(t *testing.T) { {"coro2.go", false}, // legacy bad linkname is ok, for now {"fastrand.go", true}, + {"badlinkname.go", true}, } for _, test := range tests { test := test diff --git a/src/cmd/link/testdata/linkname/badlinkname.go b/src/cmd/link/testdata/linkname/badlinkname.go new file mode 100644 index 0000000000..fb9f9c6b7d --- /dev/null +++ b/src/cmd/link/testdata/linkname/badlinkname.go @@ -0,0 +1,24 @@ +// Copyright 2024 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. + +// Existing pull linknames in the wild are allowed _for now_, +// for legacy reason. Test a function and a method. +// NOTE: this may not be allowed in the future. Don't do this! + +package main + +import ( + _ "reflect" + "unsafe" +) + +//go:linkname noescape runtime.noescape +func noescape(unsafe.Pointer) unsafe.Pointer + +//go:linkname rtype_String reflect.(*rtype).String +func rtype_String(unsafe.Pointer) string + +func main() { + println(rtype_String(noescape(nil))) +} diff --git a/src/crypto/tls/badlinkname.go b/src/crypto/tls/badlinkname.go new file mode 100644 index 0000000000..97350e42af --- /dev/null +++ b/src/crypto/tls/badlinkname.go @@ -0,0 +1,27 @@ +// Copyright 2024 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. + +package tls + +import _ "unsafe" + +// As of Go 1.22, the symbols below are found to be pulled via +// linkname in the wild. We provide a push linkname here, to +// keep them accessible with pull linknames. +// This may change in the future. Please do not depend on them +// in new code. + +//go:linkname aeadAESGCMTLS13 +//go:linkname cipherSuiteTLS13ByID +//go:linkname cipherSuitesTLS13 +//go:linkname defaultCipherSuitesTLS13 +//go:linkname defaultCipherSuitesTLS13NoAES +//go:linkname errShutdown + +// The compiler doesn't allow linknames on methods, for good reasons. +// We use this trick to push linknames of the methods. +// Do not call them in this package. + +//go:linkname badlinkname_halfConn_incSeq crypto/tls.(*halfConn).incSeq +func badlinkname_halfConn_incSeq(*halfConn) diff --git a/src/crypto/x509/badlinkname.go b/src/crypto/x509/badlinkname.go new file mode 100644 index 0000000000..c119a5f861 --- /dev/null +++ b/src/crypto/x509/badlinkname.go @@ -0,0 +1,15 @@ +// Copyright 2024 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. + +package x509 + +import _ "unsafe" + +// As of Go 1.22, the symbols below are found to be pulled via +// linkname in the wild. We provide a push linkname here, to +// keep them accessible with pull linknames. +// This may change in the future. Please do not depend on them +// in new code. + +//go:linkname systemRoots diff --git a/src/database/sql/badlinkname.go b/src/database/sql/badlinkname.go new file mode 100644 index 0000000000..a77def9fbd --- /dev/null +++ b/src/database/sql/badlinkname.go @@ -0,0 +1,16 @@ +// Copyright 2024 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. + +package sql + +import _ "unsafe" + +// As of Go 1.22, the symbols below are found to be pulled via +// linkname in the wild. We provide a push linkname here, to +// keep them accessible with pull linknames. +// This may change in the future. Please do not depend on them +// in new code. + +//go:linkname convertAssign +//go:linkname drivers diff --git a/src/go/build/badlinkname.go b/src/go/build/badlinkname.go new file mode 100644 index 0000000000..feed305f02 --- /dev/null +++ b/src/go/build/badlinkname.go @@ -0,0 +1,23 @@ +// Copyright 2024 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. + +package build + +import _ "unsafe" + +// As of Go 1.22, the symbols below are found to be pulled via +// linkname in the wild. We provide a push linkname here, to +// keep them accessible with pull linknames. +// This may change in the future. Please do not depend on them +// in new code. + +//go:linkname defaultReleaseTags +//go:linkname defaultToolTags + +// The compiler doesn't allow linknames on methods, for good reasons. +// We use this trick to push linknames of the methods. +// Do not call them in this package. + +//go:linkname badlinkname_Context_goodOSArchFile go/build.(*Context).goodOSArchFile +func badlinkname_Context_goodOSArchFile(*Context, string, map[string]bool) bool diff --git a/src/go/types/badlinkname.go b/src/go/types/badlinkname.go new file mode 100644 index 0000000000..38b6a103a9 --- /dev/null +++ b/src/go/types/badlinkname.go @@ -0,0 +1,20 @@ +// Copyright 2024 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. + +package types + +import _ "unsafe" + +// As of Go 1.22, the symbols below are found to be pulled via +// linkname in the wild. We provide a push linkname here, to +// keep them accessible with pull linknames. +// This may change in the future. Please do not depend on them +// in new code. + +// The compiler doesn't allow linknames on methods, for good reasons. +// We use this trick to push linknames of the methods. +// Do not call them in this package. + +//go:linkname badlinkname_Checker_infer go/types.(*Checker).infer +func badlinkname_Checker_infer(*Checker, positioner, []*TypeParam, []Type, *Tuple, []*operand, bool, *error_) []Type diff --git a/src/internal/cpu/badlinkname_linux_arm64.go b/src/internal/cpu/badlinkname_linux_arm64.go new file mode 100644 index 0000000000..9e2cfcef06 --- /dev/null +++ b/src/internal/cpu/badlinkname_linux_arm64.go @@ -0,0 +1,15 @@ +// Copyright 2024 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. + +package cpu + +import _ "unsafe" + +// As of Go 1.22, the symbols below are found to be pulled via +// linkname in the wild. We provide a push linkname here, to +// keep them accessible with pull linknames. +// This may change in the future. Please do not depend on them +// in new code. + +//go:linkname HWCap diff --git a/src/internal/poll/badlinkname.go b/src/internal/poll/badlinkname.go new file mode 100644 index 0000000000..67e49bb409 --- /dev/null +++ b/src/internal/poll/badlinkname.go @@ -0,0 +1,15 @@ +// Copyright 2024 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. + +package poll + +import _ "unsafe" + +// As of Go 1.22, the symbols below are found to be pulled via +// linkname in the wild. We provide a push linkname here, to +// keep them accessible with pull linknames. +// This may change in the future. Please do not depend on them +// in new code. + +//go:linkname IsPollDescriptor diff --git a/src/internal/testlog/badlinkname.go b/src/internal/testlog/badlinkname.go new file mode 100644 index 0000000000..4c5358694b --- /dev/null +++ b/src/internal/testlog/badlinkname.go @@ -0,0 +1,15 @@ +// Copyright 2024 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. + +package testlog + +import _ "unsafe" + +// As of Go 1.22, the symbols below are found to be pulled via +// linkname in the wild. We provide a push linkname here, to +// keep them accessible with pull linknames. +// This may change in the future. Please do not depend on them +// in new code. + +//go:linkname SetPanicOnExit0 diff --git a/src/math/big/badlinkname.go b/src/math/big/badlinkname.go new file mode 100644 index 0000000000..2f47d89064 --- /dev/null +++ b/src/math/big/badlinkname.go @@ -0,0 +1,21 @@ +// Copyright 2024 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. + +package big + +import _ "unsafe" + +// As of Go 1.22, the symbols below are found to be pulled via +// linkname in the wild. We provide a push linkname here, to +// keep them accessible with pull linknames. +// This may change in the future. Please do not depend on them +// in new code. + +//go:linkname addMulVVW +//go:linkname addVV +//go:linkname addVW +//go:linkname mulAddVWW +//go:linkname shlVU +//go:linkname subVV +//go:linkname subVW diff --git a/src/mime/multipart/badlinkname.go b/src/mime/multipart/badlinkname.go new file mode 100644 index 0000000000..7e3b0cc9b3 --- /dev/null +++ b/src/mime/multipart/badlinkname.go @@ -0,0 +1,15 @@ +// Copyright 2024 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. + +package multipart + +import _ "unsafe" + +// As of Go 1.22, the symbols below are found to be pulled via +// linkname in the wild. We provide a push linkname here, to +// keep them accessible with pull linknames. +// This may change in the future. Please do not depend on them +// in new code. + +//go:linkname escapeQuotes diff --git a/src/net/badlinkname.go b/src/net/badlinkname.go new file mode 100644 index 0000000000..0334e834a8 --- /dev/null +++ b/src/net/badlinkname.go @@ -0,0 +1,16 @@ +// Copyright 2024 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. + +package net + +import _ "unsafe" + +// As of Go 1.22, the symbols below are found to be pulled via +// linkname in the wild. We provide a push linkname here, to +// keep them accessible with pull linknames. +// This may change in the future. Please do not depend on them +// in new code. + +//go:linkname defaultNS +//go:linkname isDomainName diff --git a/src/net/http/badlinkname.go b/src/net/http/badlinkname.go new file mode 100644 index 0000000000..93408ecd55 --- /dev/null +++ b/src/net/http/badlinkname.go @@ -0,0 +1,36 @@ +// Copyright 2024 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. + +package http + +import _ "unsafe" + +// As of Go 1.22, the symbols below are found to be pulled via +// linkname in the wild. We provide a push linkname here, to +// keep them accessible with pull linknames. +// This may change in the future. Please do not depend on them +// in new code. + +//go:linkname cloneMultipartFileHeader +//go:linkname cloneMultipartForm +//go:linkname cloneOrMakeHeader +//go:linkname cloneTLSConfig +//go:linkname cloneURL +//go:linkname cloneURLValues +//go:linkname newBufioReader +//go:linkname newBufioWriterSize +//go:linkname parseBasicAuth +//go:linkname putBufioReader +//go:linkname putBufioWriter +//go:linkname readRequest + +// The compiler doesn't allow linknames on methods, for good reasons. +// We use this trick to push linknames of the methods. +// Do not call them in this package. + +//go:linkname badlinkname_serverHandler_ServeHTTP net/http.serverHandler.ServeHTTP +func badlinkname_serverHandler_ServeHTTP(serverHandler, ResponseWriter, *Request) + +//go:linkname badlinkname_Transport_Roundtrip net/http.(*Transport).RoundTrip +func badlinkname_Transport_Roundtrip(*Transport, *Request) (*Response, error) diff --git a/src/net/url/badlinkname.go b/src/net/url/badlinkname.go new file mode 100644 index 0000000000..536abe2fa4 --- /dev/null +++ b/src/net/url/badlinkname.go @@ -0,0 +1,20 @@ +// Copyright 2024 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. + +package url + +import _ "unsafe" + +// As of Go 1.22, the symbols below are found to be pulled via +// linkname in the wild. We provide a push linkname here, to +// keep them accessible with pull linknames. +// This may change in the future. Please do not depend on them +// in new code. + +// The compiler doesn't allow linknames on methods, for good reasons. +// We use this trick to push linknames of the methods. +// Do not call them in this package. + +//go:linkname badlinkname_URL_setPath net/url.(*URL).setPath +func badlinkname_URL_setPath(*URL, string) error diff --git a/src/reflect/badlinkname.go b/src/reflect/badlinkname.go new file mode 100644 index 0000000000..597cc831fe --- /dev/null +++ b/src/reflect/badlinkname.go @@ -0,0 +1,118 @@ +// Copyright 2024 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. + +package reflect + +import ( + "internal/abi" + _ "unsafe" +) + +// As of Go 1.22, the symbols below are found to be pulled via +// linkname in the wild. We provide a push linkname here, to +// keep them accessible with pull linknames. +// This may change in the future. Please do not depend on them +// in new code. + +//go:linkname add +//go:linkname ifaceIndir +//go:linkname mapassign +//go:linkname rtypeOff +//go:linkname toType +//go:linkname typesByString +//go:linkname valueInterface + +// The compiler doesn't allow linknames on methods, for good reasons. +// We use this trick to push linknames of the methods. +// Do not call them in this package. + +//go:linkname badlinkname_rtype_Align reflect.(*rtype).Align +func badlinkname_rtype_Align(*rtype) int + +//go:linkname badlinkname_rtype_AssignableTo reflect.(*rtype).AssignableTo +func badlinkname_rtype_AssignableTo(*rtype, Type) bool + +//go:linkname badlinkname_rtype_Bits reflect.(*rtype).Bits +func badlinkname_rtype_Bits(*rtype) int + +//go:linkname badlinkname_rtype_ChanDir reflect.(*rtype).ChanDir +func badlinkname_rtype_ChanDir(*rtype) ChanDir + +//go:linkname badlinkname_rtype_Comparable reflect.(*rtype).Comparable +func badlinkname_rtype_Comparable(*rtype) bool + +//go:linkname badlinkname_rtype_ConvertibleTo reflect.(*rtype).ConvertibleTo +func badlinkname_rtype_ConvertibleTo(*rtype, Type) bool + +//go:linkname badlinkname_rtype_Elem reflect.(*rtype).Elem +func badlinkname_rtype_Elem(*rtype) Type + +//go:linkname badlinkname_rtype_Field reflect.(*rtype).Field +func badlinkname_rtype_Field(*rtype, int) StructField + +//go:linkname badlinkname_rtype_FieldAlign reflect.(*rtype).FieldAlign +func badlinkname_rtype_FieldAlign(*rtype) int + +//go:linkname badlinkname_rtype_FieldByIndex reflect.(*rtype).FieldByIndex +func badlinkname_rtype_FieldByIndex(*rtype, []int) StructField + +//go:linkname badlinkname_rtype_FieldByName reflect.(*rtype).FieldByName +func badlinkname_rtype_FieldByName(*rtype, string) (StructField, bool) + +//go:linkname badlinkname_rtype_FieldByNameFunc reflect.(*rtype).FieldByNameFunc +func badlinkname_rtype_FieldByNameFunc(*rtype, func(string) bool) (StructField, bool) + +//go:linkname badlinkname_rtype_Implements reflect.(*rtype).Implements +func badlinkname_rtype_Implements(*rtype, Type) bool + +//go:linkname badlinkname_rtype_In reflect.(*rtype).In +func badlinkname_rtype_In(*rtype, int) Type + +//go:linkname badlinkname_rtype_IsVariadic reflect.(*rtype).IsVariadic +func badlinkname_rtype_IsVariadic(*rtype) bool + +//go:linkname badlinkname_rtype_Key reflect.(*rtype).Key +func badlinkname_rtype_Key(*rtype) Type + +//go:linkname badlinkname_rtype_Kind reflect.(*rtype).Kind +func badlinkname_rtype_Kind(*rtype) Kind + +//go:linkname badlinkname_rtype_Len reflect.(*rtype).Len +func badlinkname_rtype_Len(*rtype) int + +//go:linkname badlinkname_rtype_Method reflect.(*rtype).Method +func badlinkname_rtype_Method(*rtype, int) Method + +//go:linkname badlinkname_rtype_MethodByName reflect.(*rtype).MethodByName +func badlinkname_rtype_MethodByName(*rtype, string) (Method, bool) + +//go:linkname badlinkname_rtype_Name reflect.(*rtype).Name +func badlinkname_rtype_Name(*rtype) string + +//go:linkname badlinkname_rtype_NumField reflect.(*rtype).NumField +func badlinkname_rtype_NumField(*rtype) int + +//go:linkname badlinkname_rtype_NumIn reflect.(*rtype).NumIn +func badlinkname_rtype_NumIn(*rtype) int + +//go:linkname badlinkname_rtype_NumMethod reflect.(*rtype).NumMethod +func badlinkname_rtype_NumMethod(*rtype) int + +//go:linkname badlinkname_rtype_NumOut reflect.(*rtype).NumOut +func badlinkname_rtype_NumOut(*rtype) int + +//go:linkname badlinkname_rtype_Out reflect.(*rtype).Out +func badlinkname_rtype_Out(*rtype, int) Type + +//go:linkname badlinkname_rtype_PkgPath reflect.(*rtype).PkgPath +func badlinkname_rtype_PkgPath(*rtype) string + +//go:linkname badlinkname_rtype_Size reflect.(*rtype).Size +func badlinkname_rtype_Size(*rtype) uintptr + +//go:linkname badlinkname_rtype_String reflect.(*rtype).String +func badlinkname_rtype_String(*rtype) string + +//go:linkname badlinkname_rtype_ptrTo reflect.(*rtype).ptrTo +func badlinkname_rtype_ptrTo(*rtype) *abi.Type diff --git a/src/runtime/badlinkname.go b/src/runtime/badlinkname.go new file mode 100644 index 0000000000..291f64eb2e --- /dev/null +++ b/src/runtime/badlinkname.go @@ -0,0 +1,44 @@ +// Copyright 2024 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. + +package runtime + +import _ "unsafe" + +// As of Go 1.22, the symbols below are found to be pulled via +// linkname in the wild. We provide a push linkname here, to +// keep them accessible with pull linknames. +// This may change in the future. Please do not depend on them +// in new code. + +//go:linkname add +//go:linkname atomicwb +//go:linkname callers +//go:linkname chanbuf +//go:linkname cputicks +//go:linkname entersyscallblock +//go:linkname fastexprand +//go:linkname gopanic +//go:linkname gopark +//go:linkname goready +//go:linkname goyield +//go:linkname mapassign +//go:linkname mapassign_faststr +//go:linkname mapiterinit +//go:linkname mapiternext +//go:linkname newarray +//go:linkname nilinterhash +//go:linkname noescape +//go:linkname procPin +//go:linkname procUnpin +//go:linkname sched +//go:linkname startTheWorld +//go:linkname stopTheWorld +//go:linkname stringHash +//go:linkname traceAdvance +//go:linkname traceClockNow +//go:linkname typedmemmove +//go:linkname typedslicecopy +//go:linkname typehash +//go:linkname wakep diff --git a/src/runtime/badlinkname_linux_amd64.go b/src/runtime/badlinkname_linux_amd64.go new file mode 100644 index 0000000000..8a2dae93ca --- /dev/null +++ b/src/runtime/badlinkname_linux_amd64.go @@ -0,0 +1,15 @@ +// Copyright 2024 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. + +package runtime + +import _ "unsafe" + +// As of Go 1.22, the symbols below are found to be pulled via +// linkname in the wild. We provide a push linkname here, to +// keep them accessible with pull linknames. +// This may change in the future. Please do not depend on them +// in new code. + +//go:linkname vdsoClockgettimeSym diff --git a/src/runtime/time_nofake.go b/src/runtime/time_nofake.go index 70a2102b22..ad3d550ad8 100644 --- a/src/runtime/time_nofake.go +++ b/src/runtime/time_nofake.go @@ -19,6 +19,10 @@ func nanotime() int64 { return nanotime1() } +// overrideWrite allows write to be redirected externally, by +// linkname'ing this and set it to a write function. +// +//go:linkname overrideWrite var overrideWrite func(fd uintptr, p unsafe.Pointer, n int32) int32 // write must be nosplit on Windows (see write1) diff --git a/src/sync/badlinkname.go b/src/sync/badlinkname.go new file mode 100644 index 0000000000..8dcff6d7fc --- /dev/null +++ b/src/sync/badlinkname.go @@ -0,0 +1,15 @@ +// Copyright 2024 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. + +package sync + +import _ "unsafe" + +// As of Go 1.22, the symbols below are found to be pulled via +// linkname in the wild. We provide a push linkname here, to +// keep them accessible with pull linknames. +// This may change in the future. Please do not depend on them +// in new code. + +//go:linkname poolCleanup diff --git a/src/syscall/badlinkname_unix.go b/src/syscall/badlinkname_unix.go new file mode 100644 index 0000000000..5e9247c514 --- /dev/null +++ b/src/syscall/badlinkname_unix.go @@ -0,0 +1,18 @@ +// Copyright 2024 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. + +//go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris + +package syscall + +import _ "unsafe" + +// As of Go 1.22, the symbols below are found to be pulled via +// linkname in the wild. We provide a push linkname here, to +// keep them accessible with pull linknames. +// This may change in the future. Please do not depend on them +// in new code. + +//go:linkname getsockopt +//go:linkname setsockopt diff --git a/src/time/badlinkname.go b/src/time/badlinkname.go new file mode 100644 index 0000000000..96d2e31862 --- /dev/null +++ b/src/time/badlinkname.go @@ -0,0 +1,17 @@ +// Copyright 2024 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. + +package time + +import _ "unsafe" + +// As of Go 1.22, the symbols below are found to be pulled via +// linkname in the wild. We provide a push linkname here, to +// keep them accessible with pull linknames. +// This may change in the future. Please do not depend on them +// in new code. + +//go:linkname absClock +//go:linkname absDate +//go:linkname nextStdChunk