From 2a7ca156b8189c68c0a29b4c66194a42c5ce3c9b Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 22 May 2024 23:06:30 -0400 Subject: all: document legacy //go:linkname for final round of modules MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 TryBot-Bypass: Russ Cox Reviewed-by: Cherry Mui --- src/debug/buildinfo/buildinfo.go | 41 ++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) (limited to 'src/debug') diff --git a/src/debug/buildinfo/buildinfo.go b/src/debug/buildinfo/buildinfo.go index 1bfdd02a67..1dd70a9f33 100644 --- a/src/debug/buildinfo/buildinfo.go +++ b/src/debug/buildinfo/buildinfo.go @@ -25,6 +25,7 @@ import ( "io/fs" "os" "runtime/debug" + _ "unsafe" // for linkname ) // Type alias for build info. We cannot move the types here, since @@ -32,22 +33,30 @@ import ( // a much larger dependency. type BuildInfo = debug.BuildInfo -var ( - // errUnrecognizedFormat is returned when a given executable file doesn't - // appear to be in a known format, or it breaks the rules of that format, - // or when there are I/O errors reading the file. - errUnrecognizedFormat = errors.New("unrecognized file format") - - // errNotGoExe is returned when a given executable file is valid but does - // not contain Go build information. - errNotGoExe = errors.New("not a Go executable") - - // The build info blob left by the linker is identified by - // a 16-byte header, consisting of buildInfoMagic (14 bytes), - // the binary's pointer size (1 byte), - // and whether the binary is big endian (1 byte). - buildInfoMagic = []byte("\xff Go buildinf:") -) +// errUnrecognizedFormat is returned when a given executable file doesn't +// appear to be in a known format, or it breaks the rules of that format, +// or when there are I/O errors reading the file. +var errUnrecognizedFormat = errors.New("unrecognized file format") + +// errNotGoExe is returned when a given executable file is valid but does +// not contain Go build information. +// +// errNotGoExe should be an internal detail, +// but widely used packages access it using linkname. +// Notable members of the hall of shame include: +// - github.com/quay/claircore +// +// Do not remove or change the type signature. +// See go.dev/issue/67401. +// +//go:linkname errNotGoExe +var errNotGoExe = errors.New("not a Go executable") + +// The build info blob left by the linker is identified by +// a 16-byte header, consisting of buildInfoMagic (14 bytes), +// the binary's pointer size (1 byte), +// and whether the binary is big endian (1 byte). +var buildInfoMagic = []byte("\xff Go buildinf:") // ReadFile returns build information embedded in a Go binary // file at the given path. Most information is only available for binaries built -- cgit v1.3-5-g9baa