aboutsummaryrefslogtreecommitdiff
path: root/src/net/http
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2024-05-22 23:06:30 -0400
committerGopher Robot <gobot@golang.org>2024-05-29 17:58:53 +0000
commit2a7ca156b8189c68c0a29b4c66194a42c5ce3c9b (patch)
tree7ac6dc198ebad85420719774562d29b7b59c6684 /src/net/http
parent5121b45d7426687076c20ae0f4fcae1238f3ed47 (diff)
downloadgo-2a7ca156b8189c68c0a29b4c66194a42c5ce3c9b.tar.xz
all: document legacy //go:linkname for final round of modules
Add linknames for most modules with ≥50 dependents. Add linknames for a few other modules that we know are important but are below 50. Remove linknames from badlinkname.go that do not merit inclusion (very small number of dependents). We can add them back later if the need arises. Fixes #67401. (For now.) Change-Id: I1e49fec0292265256044d64b1841d366c4106002 Reviewed-on: https://go-review.googlesource.com/c/go/+/587756 Auto-Submit: Russ Cox <rsc@golang.org> TryBot-Bypass: Russ Cox <rsc@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com>
Diffstat (limited to 'src/net/http')
-rw-r--r--src/net/http/badlinkname.go28
-rw-r--r--src/net/http/request.go2
-rw-r--r--src/net/http/roundtrip.go13
-rw-r--r--src/net/http/server.go48
4 files changed, 63 insertions, 28 deletions
diff --git a/src/net/http/badlinkname.go b/src/net/http/badlinkname.go
deleted file mode 100644
index c714edf5f2..0000000000
--- a/src/net/http/badlinkname.go
+++ /dev/null
@@ -1,28 +0,0 @@
-// 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 newBufioReader
-//go:linkname newBufioWriterSize
-//go:linkname putBufioReader
-//go:linkname putBufioWriter
-
-// 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/http/request.go b/src/net/http/request.go
index ecb48a4364..456615a79a 100644
--- a/src/net/http/request.go
+++ b/src/net/http/request.go
@@ -1076,6 +1076,8 @@ func ReadRequest(b *bufio.Reader) (*Request, error) {
// but widely used packages access it using linkname.
// Notable members of the hall of shame include:
// - github.com/sagernet/sing
+// - github.com/v2fly/v2ray-core/v4
+// - github.com/v2fly/v2ray-core/v5
//
// Do not remove or change the type signature.
// See go.dev/issue/67401.
diff --git a/src/net/http/roundtrip.go b/src/net/http/roundtrip.go
index 08c270179a..6674b8419f 100644
--- a/src/net/http/roundtrip.go
+++ b/src/net/http/roundtrip.go
@@ -6,6 +6,19 @@
package http
+import _ "unsafe" // for linkname
+
+// RoundTrip should be an internal detail,
+// but widely used packages access it using linkname.
+// Notable members of the hall of shame include:
+// - github.com/erda-project/erda-infra
+//
+// Do not remove or change the type signature.
+// See go.dev/issue/67401.
+//
+//go:linkname badRoundTrip net/http.(*Transport).RoundTrip
+func badRoundTrip(*Transport, *Request) (*Response, error)
+
// RoundTrip implements the [RoundTripper] interface.
//
// For higher-level HTTP client support (such as handling of cookies
diff --git a/src/net/http/server.go b/src/net/http/server.go
index 9786a68129..e28b107e99 100644
--- a/src/net/http/server.go
+++ b/src/net/http/server.go
@@ -29,6 +29,7 @@ import (
"sync"
"sync/atomic"
"time"
+ _ "unsafe" // for linkname
"golang.org/x/net/http/httpguts"
)
@@ -837,6 +838,15 @@ func bufioWriterPool(size int) *sync.Pool {
return nil
}
+// newBufioReader should be an internal detail,
+// but widely used packages access it using linkname.
+// Notable members of the hall of shame include:
+// - github.com/gobwas/ws
+//
+// Do not remove or change the type signature.
+// See go.dev/issue/67401.
+//
+//go:linkname newBufioReader
func newBufioReader(r io.Reader) *bufio.Reader {
if v := bufioReaderPool.Get(); v != nil {
br := v.(*bufio.Reader)
@@ -848,11 +858,29 @@ func newBufioReader(r io.Reader) *bufio.Reader {
return bufio.NewReader(r)
}
+// putBufioReader should be an internal detail,
+// but widely used packages access it using linkname.
+// Notable members of the hall of shame include:
+// - github.com/gobwas/ws
+//
+// Do not remove or change the type signature.
+// See go.dev/issue/67401.
+//
+//go:linkname putBufioReader
func putBufioReader(br *bufio.Reader) {
br.Reset(nil)
bufioReaderPool.Put(br)
}
+// newBufioWriterSize should be an internal detail,
+// but widely used packages access it using linkname.
+// Notable members of the hall of shame include:
+// - github.com/gobwas/ws
+//
+// Do not remove or change the type signature.
+// See go.dev/issue/67401.
+//
+//go:linkname newBufioWriterSize
func newBufioWriterSize(w io.Writer, size int) *bufio.Writer {
pool := bufioWriterPool(size)
if pool != nil {
@@ -865,6 +893,15 @@ func newBufioWriterSize(w io.Writer, size int) *bufio.Writer {
return bufio.NewWriterSize(w, size)
}
+// putBufioWriter should be an internal detail,
+// but widely used packages access it using linkname.
+// Notable members of the hall of shame include:
+// - github.com/gobwas/ws
+//
+// Do not remove or change the type signature.
+// See go.dev/issue/67401.
+//
+//go:linkname putBufioWriter
func putBufioWriter(bw *bufio.Writer) {
bw.Reset(nil)
if pool := bufioWriterPool(bw.Available()); pool != nil {
@@ -3150,6 +3187,15 @@ type serverHandler struct {
srv *Server
}
+// ServeHTTP should be an internal detail,
+// but widely used packages access it using linkname.
+// Notable members of the hall of shame include:
+// - github.com/erda-project/erda-infra
+//
+// Do not remove or change the type signature.
+// See go.dev/issue/67401.
+//
+//go:linkname badServeHTTP net/http.serverHandler.ServeHTTP
func (sh serverHandler) ServeHTTP(rw ResponseWriter, req *Request) {
handler := sh.srv.Handler
if handler == nil {
@@ -3162,6 +3208,8 @@ func (sh serverHandler) ServeHTTP(rw ResponseWriter, req *Request) {
handler.ServeHTTP(rw, req)
}
+func badServeHTTP(serverHandler, ResponseWriter, *Request)
+
// AllowQuerySemicolons returns a handler that serves requests by converting any
// unescaped semicolons in the URL query to ampersands, and invoking the handler h.
//