From 46afa893ebf85e23dd820a11e6007a9adb503419 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Mon, 3 Jan 2022 18:48:51 +0100 Subject: [PATCH 001/276] crypto/rand: use fast key erasure RNG on plan9 instead of ANSI X9.31 This should be a bit faster and slicker than the very old ANSI X9.31, which relied on the system time. Uses AES instead of ChaCha because it's in the standard library. Reference: https://blog.cr.yp.to/20170723-random.html Reference: https://github.com/jedisct1/supercop/blob/master/crypto_rng/aes256/ref/rng.c Change-Id: Ib7b37a83cca29f5d346355b7cb8cfe5250086b95 Reviewed-on: https://go-review.googlesource.com/c/go/+/375215 Trust: Jason Donenfeld Reviewed-by: Filippo Valsorda Run-TryBot: Filippo Valsorda Auto-Submit: Filippo Valsorda TryBot-Result: Gopher Robot Reviewed-by: Roland Shoemaker --- src/crypto/rand/rand_plan9.go | 114 ++++++++++++++-------------------- 1 file changed, 46 insertions(+), 68 deletions(-) diff --git a/src/crypto/rand/rand_plan9.go b/src/crypto/rand/rand_plan9.go index b81d73ca803..5d0af0959e9 100644 --- a/src/crypto/rand/rand_plan9.go +++ b/src/crypto/rand/rand_plan9.go @@ -9,12 +9,10 @@ package rand import ( "crypto/aes" - "crypto/cipher" "encoding/binary" "io" "os" "sync" - "sync/atomic" "time" ) @@ -27,83 +25,63 @@ func init() { // reader is a new pseudorandom generator that seeds itself by // reading from /dev/random. The Read method on the returned // reader always returns the full amount asked for, or else it -// returns an error. The generator uses the X9.31 algorithm with -// AES-128, reseeding after every 1 MB of generated data. +// returns an error. The generator is a fast key erasure RNG. type reader struct { - mu sync.Mutex - budget int // number of bytes that can be generated - cipher cipher.Block - entropy io.Reader - entropyUsed int32 // atomic; whether entropy has been used - time, seed, dst, key [aes.BlockSize]byte + mu sync.Mutex + seeded sync.Once + seedErr error + key [32]byte } -func warnBlocked() { - println("crypto/rand: blocked for 60 seconds waiting to read random data from the kernel") -} - -func (r *reader) readEntropy(b []byte) error { - if atomic.CompareAndSwapInt32(&r.entropyUsed, 0, 1) { - // First use of randomness. Start timer to warn about - // being blocked on entropy not being available. - t := time.AfterFunc(time.Minute, warnBlocked) +func (r *reader) Read(b []byte) (n int, err error) { + r.seeded.Do(func() { + t := time.AfterFunc(time.Minute, func() { + println("crypto/rand: blocked for 60 seconds waiting to read random data from the kernel") + }) defer t.Stop() - } - var err error - if r.entropy == nil { - r.entropy, err = os.Open(randomDevice) + entropy, err := os.Open(randomDevice) if err != nil { - return err + r.seedErr = err + return } + _, r.seedErr = io.ReadFull(entropy, r.key[:]) + }) + if r.seedErr != nil { + return 0, r.seedErr } - _, err = io.ReadFull(r.entropy, b) - return err -} -func (r *reader) Read(b []byte) (n int, err error) { r.mu.Lock() - defer r.mu.Unlock() - n = len(b) - - for len(b) > 0 { - if r.budget == 0 { - err = r.readEntropy(r.seed[0:]) - if err != nil { - return n - len(b), err - } - err = r.readEntropy(r.key[0:]) - if err != nil { - return n - len(b), err - } - r.cipher, err = aes.NewCipher(r.key[0:]) - if err != nil { - return n - len(b), err - } - r.budget = 1 << 20 // reseed after generating 1MB - } - r.budget -= aes.BlockSize - - // ANSI X9.31 (== X9.17) algorithm, but using AES in place of 3DES. - // - // single block: - // t = encrypt(time) - // dst = encrypt(t^seed) - // seed = encrypt(t^dst) - ns := time.Now().UnixNano() - binary.BigEndian.PutUint64(r.time[:], uint64(ns)) - r.cipher.Encrypt(r.time[0:], r.time[0:]) - for i := 0; i < aes.BlockSize; i++ { - r.dst[i] = r.time[i] ^ r.seed[i] - } - r.cipher.Encrypt(r.dst[0:], r.dst[0:]) - for i := 0; i < aes.BlockSize; i++ { - r.seed[i] = r.time[i] ^ r.dst[i] + blockCipher, err := aes.NewCipher(r.key[:]) + if err != nil { + r.mu.Unlock() + return 0, err + } + var ( + counter uint64 + block [aes.BlockSize]byte + ) + inc := func() { + counter++ + if counter == 0 { + panic("crypto/rand counter wrapped") } - r.cipher.Encrypt(r.seed[0:], r.seed[0:]) - - m := copy(b, r.dst[0:]) - b = b[m:] + binary.LittleEndian.PutUint64(block[:], counter) } + blockCipher.Encrypt(r.key[:aes.BlockSize], block[:]) + inc() + blockCipher.Encrypt(r.key[aes.BlockSize:], block[:]) + inc() + r.mu.Unlock() + n = len(b) + for len(b) >= aes.BlockSize { + blockCipher.Encrypt(b[:aes.BlockSize], block[:]) + inc() + b = b[aes.BlockSize:] + } + if len(b) > 0 { + blockCipher.Encrypt(block[:], block[:]) + copy(b, block[:]) + } return n, nil } From ca384f76296af68b874cf9305a78ca5269c20956 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Thu, 13 Jan 2022 12:46:34 +0000 Subject: [PATCH 002/276] cmd/go: avoid rebuilding itself in TestMain MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit An extra "go build" was happening, for the sake of -tags=testgo, which would insert some extra behavior into ./internal/work. Instead, reuse the test binary as cmd/go directly, by calling the main func when a special env var is set. We still duplicate the test binary into testBin, because we need a "go" executable in that directory for $PATH. Finally, the special behavior is instead inserted via TestMain. The numbers below represent how long it takes to run zero tests, measured via: benchcmd GoTestNothing go test -run=- That is, the time it takes to run the first test is reduced by half. Note that these numbers are on a warm build cache, so if the -tags=testgo build were to be done from scratch, the speed-up would be significantly more noticeable. name old time/op new time/op delta GoTestNothing 830ms ± 2% 380ms ± 7% -54.23% (p=0.008 n=5+5) name old user-time/op new user-time/op delta GoTestNothing 1.64s ± 1% 0.82s ± 3% -50.24% (p=0.008 n=5+5) name old sys-time/op new sys-time/op delta GoTestNothing 306ms ± 7% 159ms ±28% -48.15% (p=0.008 n=5+5) name old peak-RSS-bytes new peak-RSS-bytes delta GoTestNothing 173MB ± 1% 147MB ± 1% -14.96% (p=0.008 n=5+5) Change-Id: I1f8fc71269a7b45bc5b82b7228e13f56589d44c3 Reviewed-on: https://go-review.googlesource.com/c/go/+/378294 Trust: Daniel Martí Run-TryBot: Daniel Martí TryBot-Result: Gopher Robot Reviewed-by: Bryan Mills --- src/cmd/go/export_test.go | 7 +++ src/cmd/go/go_test.go | 78 +++++++++++++++++++++++++----- src/cmd/go/internal/work/build.go | 2 +- src/cmd/go/internal/work/exec.go | 22 ++++----- src/cmd/go/internal/work/gc.go | 4 +- src/cmd/go/internal/work/testgo.go | 48 ------------------ src/cmd/go/script_test.go | 1 + 7 files changed, 89 insertions(+), 73 deletions(-) create mode 100644 src/cmd/go/export_test.go delete mode 100644 src/cmd/go/internal/work/testgo.go diff --git a/src/cmd/go/export_test.go b/src/cmd/go/export_test.go new file mode 100644 index 00000000000..155ab8c1bbe --- /dev/null +++ b/src/cmd/go/export_test.go @@ -0,0 +1,7 @@ +// Copyright 2015 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 main + +func Main() { main() } diff --git a/src/cmd/go/go_test.go b/src/cmd/go/go_test.go index 1ea347ca6e5..01356f9dd00 100644 --- a/src/cmd/go/go_test.go +++ b/src/cmd/go/go_test.go @@ -14,7 +14,6 @@ import ( "fmt" "go/format" "internal/godebug" - "internal/race" "internal/testenv" "io" "io/fs" @@ -32,7 +31,11 @@ import ( "cmd/go/internal/cache" "cmd/go/internal/cfg" "cmd/go/internal/robustio" + "cmd/go/internal/search" + "cmd/go/internal/work" "cmd/internal/sys" + + cmdgo "cmd/go" ) func init() { @@ -84,6 +87,43 @@ var testBin string // The TestMain function creates a go command for testing purposes and // deletes it after the tests have been run. func TestMain(m *testing.M) { + // When CMDGO_TEST_RUN_MAIN is set, we're reusing the test binary as cmd/go. + // Enable the special behavior needed in cmd/go/internal/work, + // run the main func exported via export_test.go, and exit. + // We set CMDGO_TEST_RUN_MAIN via os.Setenv and testScript.setup. + if os.Getenv("CMDGO_TEST_RUN_MAIN") != "" { + if v := os.Getenv("TESTGO_VERSION"); v != "" { + work.RuntimeVersion = v + } + + if testGOROOT := os.Getenv("TESTGO_GOROOT"); testGOROOT != "" { + // Disallow installs to the GOROOT from which testgo was built. + // Installs to other GOROOTs — such as one set explicitly within a test — are ok. + work.AllowInstall = func(a *work.Action) error { + if cfg.BuildN { + return nil + } + + rel := search.InDir(a.Target, testGOROOT) + if rel == "" { + return nil + } + + callerPos := "" + if _, file, line, ok := runtime.Caller(1); ok { + if shortFile := search.InDir(file, filepath.Join(testGOROOT, "src")); shortFile != "" { + file = shortFile + } + callerPos = fmt.Sprintf("%s:%d: ", file, line) + } + return fmt.Errorf("%stestgo must not write to GOROOT (installing to %s)", callerPos, filepath.Join("GOROOT", rel)) + } + } + cmdgo.Main() + os.Exit(0) + } + os.Setenv("CMDGO_TEST_RUN_MAIN", "true") + // $GO_GCFLAGS a compiler debug flag known to cmd/dist, make.bash, etc. // It is not a standard go command flag; use os.Getenv, not cfg.Getenv. if os.Getenv("GO_GCFLAGS") != "" { @@ -127,10 +167,6 @@ func TestMain(m *testing.M) { log.Fatal(err) } testGo = filepath.Join(testBin, "go"+exeSuffix) - args := []string{"build", "-tags", "testgo", "-o", testGo} - if race.Enabled { - args = append(args, "-race") - } gotool, err := testenv.GoTool() if err != nil { fmt.Fprintln(os.Stderr, "locating go tool: ", err) @@ -173,12 +209,32 @@ func TestMain(m *testing.M) { return } - buildCmd := exec.Command(gotool, args...) - buildCmd.Env = append(os.Environ(), "GOFLAGS=-mod=vendor") - out, err := buildCmd.CombinedOutput() + // Duplicate the test executable into the path at testGo, for $PATH. + // If the OS supports symlinks, use them instead of copying bytes. + testExe, err := os.Executable() if err != nil { - fmt.Fprintf(os.Stderr, "building testgo failed: %v\n%s", err, out) - os.Exit(2) + log.Fatal(err) + } + if err := os.Symlink(testExe, testGo); err != nil { + // Otherwise, copy the bytes. + src, err := os.Open(testExe) + if err != nil { + log.Fatal(err) + } + defer src.Close() + + dst, err := os.OpenFile(testGo, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0o777) + if err != nil { + log.Fatal(err) + } + + _, err = io.Copy(dst, src) + if closeErr := dst.Close(); err == nil { + err = closeErr + } + if err != nil { + log.Fatal(err) + } } cmd := exec.Command(testGo, "env", "CGO_ENABLED") @@ -193,7 +249,7 @@ func TestMain(m *testing.M) { } } - out, err = exec.Command(gotool, "env", "GOCACHE").CombinedOutput() + out, err := exec.Command(gotool, "env", "GOCACHE").CombinedOutput() if err != nil { fmt.Fprintf(os.Stderr, "could not find testing GOCACHE: %v\n%s", err, out) os.Exit(2) diff --git a/src/cmd/go/internal/work/build.go b/src/cmd/go/internal/work/build.go index 0b5848a77da..ce200ec5c20 100644 --- a/src/cmd/go/internal/work/build.go +++ b/src/cmd/go/internal/work/build.go @@ -371,7 +371,7 @@ func oneMainPkg(pkgs []*load.Package) []*load.Package { var pkgsFilter = func(pkgs []*load.Package) []*load.Package { return pkgs } -var runtimeVersion = runtime.Version() +var RuntimeVersion = runtime.Version() func runBuild(ctx context.Context, cmd *base.Command, args []string) { modload.InitWorkfile() diff --git a/src/cmd/go/internal/work/exec.go b/src/cmd/go/internal/work/exec.go index ac80f503cd8..7d3a16c5f51 100644 --- a/src/cmd/go/internal/work/exec.go +++ b/src/cmd/go/internal/work/exec.go @@ -560,7 +560,7 @@ func (b *Builder) build(ctx context.Context, a *Action) (err error) { return nil } - if err := allowInstall(a); err != nil { + if err := AllowInstall(a); err != nil { return err } @@ -1346,7 +1346,7 @@ func (b *Builder) link(ctx context.Context, a *Action) (err error) { return err } - if err := allowInstall(a); err != nil { + if err := AllowInstall(a); err != nil { return err } @@ -1527,7 +1527,7 @@ func (b *Builder) getPkgConfigFlags(p *load.Package) (cflags, ldflags []string, } func (b *Builder) installShlibname(ctx context.Context, a *Action) error { - if err := allowInstall(a); err != nil { + if err := AllowInstall(a); err != nil { return err } @@ -1581,7 +1581,7 @@ func (b *Builder) linkShared(ctx context.Context, a *Action) (err error) { } defer b.flushOutput(a) - if err := allowInstall(a); err != nil { + if err := AllowInstall(a); err != nil { return err } @@ -1652,7 +1652,7 @@ func BuildInstallFunc(b *Builder, ctx context.Context, a *Action) (err error) { if !a.buggyInstall && !b.IsCmdList { if cfg.BuildN { b.Showcmd("", "touch %s", a.Target) - } else if err := allowInstall(a); err == nil { + } else if err := AllowInstall(a); err == nil { now := time.Now() os.Chtimes(a.Target, now, now) } @@ -1666,7 +1666,7 @@ func BuildInstallFunc(b *Builder, ctx context.Context, a *Action) (err error) { a.built = a1.built return nil } - if err := allowInstall(a); err != nil { + if err := AllowInstall(a); err != nil { return err } @@ -1698,12 +1698,12 @@ func BuildInstallFunc(b *Builder, ctx context.Context, a *Action) (err error) { return b.moveOrCopyFile(a.Target, a1.built, perm, false) } -// allowInstall returns a non-nil error if this invocation of the go command is +// AllowInstall returns a non-nil error if this invocation of the go command is // allowed to install a.Target. // -// (The build of cmd/go running under its own test is forbidden from installing -// to its original GOROOT.) -var allowInstall = func(*Action) error { return nil } +// The build of cmd/go running under its own test is forbidden from installing +// to its original GOROOT. The var is exported so it can be set by TestMain. +var AllowInstall = func(*Action) error { return nil } // cleanup removes a's object dir to keep the amount of // on-disk garbage down in a large build. On an operating system @@ -1868,7 +1868,7 @@ func (b *Builder) installHeader(ctx context.Context, a *Action) error { return nil } - if err := allowInstall(a); err != nil { + if err := AllowInstall(a); err != nil { return err } diff --git a/src/cmd/go/internal/work/gc.go b/src/cmd/go/internal/work/gc.go index 40175324d26..e1e2b11dd73 100644 --- a/src/cmd/go/internal/work/gc.go +++ b/src/cmd/go/internal/work/gc.go @@ -137,8 +137,8 @@ func (gcToolchain) gc(b *Builder, a *Action, archive string, importcfg, embedcfg if p.Internal.OmitDebug || cfg.Goos == "plan9" || cfg.Goarch == "wasm" { defaultGcFlags = append(defaultGcFlags, "-dwarf=false") } - if strings.HasPrefix(runtimeVersion, "go1") && !strings.Contains(os.Args[0], "go_bootstrap") { - defaultGcFlags = append(defaultGcFlags, "-goversion", runtimeVersion) + if strings.HasPrefix(RuntimeVersion, "go1") && !strings.Contains(os.Args[0], "go_bootstrap") { + defaultGcFlags = append(defaultGcFlags, "-goversion", RuntimeVersion) } if symabis != "" { defaultGcFlags = append(defaultGcFlags, "-symabis", symabis) diff --git a/src/cmd/go/internal/work/testgo.go b/src/cmd/go/internal/work/testgo.go deleted file mode 100644 index a09b65a23c3..00000000000 --- a/src/cmd/go/internal/work/testgo.go +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2017 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. - -// This file contains extra hooks for testing the go command. - -//go:build testgo - -package work - -import ( - "cmd/go/internal/cfg" - "cmd/go/internal/search" - "fmt" - "os" - "path/filepath" - "runtime" -) - -func init() { - if v := os.Getenv("TESTGO_VERSION"); v != "" { - runtimeVersion = v - } - - if testGOROOT := os.Getenv("TESTGO_GOROOT"); testGOROOT != "" { - // Disallow installs to the GOROOT from which testgo was built. - // Installs to other GOROOTs — such as one set explicitly within a test — are ok. - allowInstall = func(a *Action) error { - if cfg.BuildN { - return nil - } - - rel := search.InDir(a.Target, testGOROOT) - if rel == "" { - return nil - } - - callerPos := "" - if _, file, line, ok := runtime.Caller(1); ok { - if shortFile := search.InDir(file, filepath.Join(testGOROOT, "src")); shortFile != "" { - file = shortFile - } - callerPos = fmt.Sprintf("%s:%d: ", file, line) - } - return fmt.Errorf("%stestgo must not write to GOROOT (installing to %s)", callerPos, filepath.Join("GOROOT", rel)) - } - } -} diff --git a/src/cmd/go/script_test.go b/src/cmd/go/script_test.go index 55a88e0e0b0..eff22135257 100644 --- a/src/cmd/go/script_test.go +++ b/src/cmd/go/script_test.go @@ -188,6 +188,7 @@ func (ts *testScript) setup() { "goversion=" + goVersion(ts), ":=" + string(os.PathListSeparator), "/=" + string(os.PathSeparator), + "CMDGO_TEST_RUN_MAIN=true", } if !testenv.HasExternalNetwork() { ts.env = append(ts.env, "TESTGONETWORK=panic", "TESTGOVCS=panic") From 1e122e3894bd12407b0043ab25c2a5f665b3f6e5 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 4 Mar 2022 10:03:32 -0800 Subject: [PATCH 003/276] syscall: remove TestRlimit It's more trouble than it's worth. New code should be using x/sys/unix anyhow. Fixes #40564 Fixes #51479 Change-Id: I1c0e13f494380c1565e98359f088af9f52790b79 Reviewed-on: https://go-review.googlesource.com/c/go/+/390020 Trust: Ian Lance Taylor Run-TryBot: Ian Lance Taylor Reviewed-by: Bryan Mills TryBot-Result: Gopher Robot --- src/syscall/syscall_unix_test.go | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/src/syscall/syscall_unix_test.go b/src/syscall/syscall_unix_test.go index 1ef2634fa17..317c0c1f345 100644 --- a/src/syscall/syscall_unix_test.go +++ b/src/syscall/syscall_unix_test.go @@ -326,33 +326,6 @@ func TestUnixRightsRoundtrip(t *testing.T) { } } -func TestRlimit(t *testing.T) { - var rlimit, zero syscall.Rlimit - if err := syscall.Getrlimit(syscall.RLIMIT_CPU, &rlimit); err != nil { - t.Fatalf("Getrlimit: save failed: %v", err) - } - if zero == rlimit { - t.Fatalf("Getrlimit: save failed: got zero value %#v", rlimit) - } - set := rlimit - set.Cur = set.Max - 1 - if err := syscall.Setrlimit(syscall.RLIMIT_CPU, &set); err != nil { - t.Fatalf("Setrlimit: set failed: %#v %v", set, err) - } - var get syscall.Rlimit - if err := syscall.Getrlimit(syscall.RLIMIT_CPU, &get); err != nil { - t.Fatalf("Getrlimit: get failed: %v", err) - } - set = rlimit - set.Cur = set.Max - 1 - if set != get { - t.Fatalf("Rlimit: change failed: wanted %#v got %#v", set, get) - } - if err := syscall.Setrlimit(syscall.RLIMIT_CPU, &rlimit); err != nil { - t.Fatalf("Setrlimit: restore failed: %#v %v", rlimit, err) - } -} - func TestSeekFailure(t *testing.T) { _, err := syscall.Seek(-1, 0, io.SeekStart) if err == nil { From 797e8890463671b96fb0af8ed151101950d76999 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Wed, 2 Mar 2022 20:16:55 -0800 Subject: [PATCH 004/276] doc/go1.19: mention use of EDNS(0) For #51153 Change-Id: I4374c63498b62ba7a08f146eebd034cbd50623f6 Reviewed-on: https://go-review.googlesource.com/c/go/+/389634 Trust: Ian Lance Taylor Run-TryBot: Ian Lance Taylor TryBot-Result: Gopher Robot Reviewed-by: Emmanuel Odeke --- doc/go1.19.html | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/doc/go1.19.html b/doc/go1.19.html index a68c27ecc84..c71d5e760b4 100644 --- a/doc/go1.19.html +++ b/doc/go1.19.html @@ -59,3 +59,18 @@

Minor changes to the library

TODO: complete this section

+
net
+
+

+ The pure Go resolver will now use EDNS(0) to include a suggested + maximum reply packet length, permitting reply packets to contain + up to 1232 bytes (the previous maximum was 512). + In the unlikely event that this causes problems with a local DNS + resolver, setting the environment variable + GODEBUG=netdns=cgo to use the cgo-based resolver + should work. + Please report any such problems on the + issue tracker. +

+
+
From 7d7b9bbc7a37d3b83936a8caea08e0be7240a125 Mon Sep 17 00:00:00 2001 From: Lynn Boger Date: Thu, 3 Mar 2022 07:28:44 -0600 Subject: [PATCH 005/276] crypto/sha512: fix stack size for previous change In a recent change CL 388654 a function was updated so it no longer needed stack space, but the TEXT statement was not updated to reflect that change. This corrects that problem. Change-Id: I9e60cebddae620788b1097ab7b39c47b323d1f62 Reviewed-on: https://go-review.googlesource.com/c/go/+/389674 Run-TryBot: Lynn Boger TryBot-Result: Gopher Robot Trust: Lynn Boger Reviewed-by: Paul Murphy --- src/crypto/sha512/sha512block_ppc64x.s | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/crypto/sha512/sha512block_ppc64x.s b/src/crypto/sha512/sha512block_ppc64x.s index 955900b7145..968183dde96 100644 --- a/src/crypto/sha512/sha512block_ppc64x.s +++ b/src/crypto/sha512/sha512block_ppc64x.s @@ -292,7 +292,7 @@ GLOBL ·kcon(SB), RODATA, $1312 VADDUDM s1, xj, xj // func block(dig *digest, p []byte) -TEXT ·block(SB),0,$128-32 +TEXT ·block(SB),0,$0-32 MOVD dig+0(FP), CTX MOVD p_base+8(FP), INP MOVD p_len+16(FP), LEN From 2b8aa2b734721487bb718ee5fb6080f51b57efd9 Mon Sep 17 00:00:00 2001 From: Roland Shoemaker Date: Mon, 28 Feb 2022 05:42:11 -0800 Subject: [PATCH 006/276] internal/fuzz: handle Inf/NaN float values Fixes #51258 Change-Id: I3c8b785ac912d66e1a6e2179625e6903032b8330 Reviewed-on: https://go-review.googlesource.com/c/go/+/388354 Reviewed-by: Bryan Mills Trust: Roland Shoemaker Run-TryBot: Roland Shoemaker Auto-Submit: Roland Shoemaker TryBot-Result: Gopher Robot --- src/internal/fuzz/encoding.go | 115 ++++++++++++++++++++++------- src/internal/fuzz/encoding_test.go | 14 ++++ 2 files changed, 104 insertions(+), 25 deletions(-) diff --git a/src/internal/fuzz/encoding.go b/src/internal/fuzz/encoding.go index 2bfa02b8c06..fe070eca349 100644 --- a/src/internal/fuzz/encoding.go +++ b/src/internal/fuzz/encoding.go @@ -10,6 +10,7 @@ import ( "go/ast" "go/parser" "go/token" + "math" "strconv" ) @@ -27,8 +28,20 @@ func marshalCorpusFile(vals ...any) []byte { // instead of changing to byte and rune respectively. for _, val := range vals { switch t := val.(type) { - case int, int8, int16, int64, uint, uint16, uint32, uint64, float32, float64, bool: + case int, int8, int16, int64, uint, uint16, uint32, uint64, bool: fmt.Fprintf(b, "%T(%v)\n", t, t) + case float32: + if math.IsNaN(float64(t)) && math.Float32bits(t) != math.Float32bits(float32(math.NaN())) { + fmt.Fprintf(b, "math.Float32frombits(%v)\n", math.Float32bits(t)) + } else { + fmt.Fprintf(b, "%T(%v)\n", t, t) + } + case float64: + if math.IsNaN(t) && math.Float64bits(t) != math.Float64bits(math.NaN()) { + fmt.Fprintf(b, "math.Float64frombits(%v)\n", math.Float64bits(t)) + } else { + fmt.Fprintf(b, "%T(%v)\n", t, t) + } case string: fmt.Fprintf(b, "string(%q)\n", t) case rune: // int32 @@ -105,44 +118,78 @@ func parseCorpusValue(line []byte) (any, error) { return []byte(s), nil } - idType, ok := call.Fun.(*ast.Ident) - if !ok { - return nil, fmt.Errorf("expected []byte or primitive type") - } - if idType.Name == "bool" { - id, ok := arg.(*ast.Ident) + var idType *ast.Ident + if selector, ok := call.Fun.(*ast.SelectorExpr); ok { + xIdent, ok := selector.X.(*ast.Ident) + if !ok || xIdent.Name != "math" { + return nil, fmt.Errorf("invalid selector type") + } + switch selector.Sel.Name { + case "Float64frombits": + idType = &ast.Ident{Name: "float64-bits"} + case "Float32frombits": + idType = &ast.Ident{Name: "float32-bits"} + default: + return nil, fmt.Errorf("invalid selector type") + } + } else { + idType, ok = call.Fun.(*ast.Ident) if !ok { - return nil, fmt.Errorf("malformed bool") + return nil, fmt.Errorf("expected []byte or primitive type") } - if id.Name == "true" { - return true, nil - } else if id.Name == "false" { - return false, nil - } else { - return nil, fmt.Errorf("true or false required for type bool") + if idType.Name == "bool" { + id, ok := arg.(*ast.Ident) + if !ok { + return nil, fmt.Errorf("malformed bool") + } + if id.Name == "true" { + return true, nil + } else if id.Name == "false" { + return false, nil + } else { + return nil, fmt.Errorf("true or false required for type bool") + } } } + var ( val string kind token.Token ) if op, ok := arg.(*ast.UnaryExpr); ok { - // Special case for negative numbers. - lit, ok := op.X.(*ast.BasicLit) - if !ok || (lit.Kind != token.INT && lit.Kind != token.FLOAT) { + switch lit := op.X.(type) { + case *ast.BasicLit: + if op.Op != token.SUB { + return nil, fmt.Errorf("unsupported operation on int/float: %v", op.Op) + } + // Special case for negative numbers. + val = op.Op.String() + lit.Value // e.g. "-" + "124" + kind = lit.Kind + case *ast.Ident: + if lit.Name != "Inf" { + return nil, fmt.Errorf("expected operation on int or float type") + } + if op.Op == token.SUB { + val = "-Inf" + } else { + val = "+Inf" + } + kind = token.FLOAT + default: return nil, fmt.Errorf("expected operation on int or float type") } - if op.Op != token.SUB { - return nil, fmt.Errorf("unsupported operation on int: %v", op.Op) - } - val = op.Op.String() + lit.Value // e.g. "-" + "124" - kind = lit.Kind } else { - lit, ok := arg.(*ast.BasicLit) - if !ok { + switch lit := arg.(type) { + case *ast.BasicLit: + val, kind = lit.Value, lit.Kind + case *ast.Ident: + if lit.Name != "NaN" { + return nil, fmt.Errorf("literal value required for primitive type") + } + val, kind = "NaN", token.FLOAT + default: return nil, fmt.Errorf("literal value required for primitive type") } - val, kind = lit.Value, lit.Kind } switch typ := idType.Name; typ { @@ -191,6 +238,24 @@ func parseCorpusValue(line []byte) (any, error) { return nil, fmt.Errorf("float or integer literal required for float64 type") } return strconv.ParseFloat(val, 64) + case "float32-bits": + if kind != token.INT { + return nil, fmt.Errorf("integer literal required for math.Float32frombits type") + } + bits, err := parseUint(val, "uint32") + if err != nil { + return nil, err + } + return math.Float32frombits(bits.(uint32)), nil + case "float64-bits": + if kind != token.FLOAT && kind != token.INT { + return nil, fmt.Errorf("integer literal required for math.Float64frombits type") + } + bits, err := parseUint(val, "uint64") + if err != nil { + return nil, err + } + return math.Float64frombits(bits.(uint64)), nil default: return nil, fmt.Errorf("expected []byte or primitive type") } diff --git a/src/internal/fuzz/encoding_test.go b/src/internal/fuzz/encoding_test.go index b429d429c67..4b55892acda 100644 --- a/src/internal/fuzz/encoding_test.go +++ b/src/internal/fuzz/encoding_test.go @@ -103,6 +103,20 @@ float64(-12.5) float32(2.5)`, ok: true, }, + { + in: `go test fuzz v1 +float32(-0) +float64(-0) +float32(+Inf) +float32(-Inf) +float32(NaN) +float64(+Inf) +float64(-Inf) +float64(NaN) +math.Float64frombits(9221120237041090560) +math.Float32frombits(2143289343)`, + ok: true, + }, } for _, test := range tests { t.Run(test.in, func(t *testing.T) { From e79c39f004769fc55e60c2fb052155486295d533 Mon Sep 17 00:00:00 2001 From: Iskander Sharipov Date: Wed, 17 Nov 2021 17:46:22 +0300 Subject: [PATCH 007/276] encoding/xml: improve the test coverage, fix minor bugs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Improve the test coverage of encoding/xml package by adding the test cases for the execution paths that were not covered before. Since it reveals a couple of issues, fix them as well while we're at it. As I used an `strings.EqualFold` instead of adding one more `strings.ToLower`, our fix to `autoClose()` tends to run faster as well as a result. name old time/op new time/op delta HTMLAutoClose-8 5.93µs ± 2% 5.75µs ± 3% -3.16% (p=0.000 n=10+10) name old alloc/op new alloc/op delta HTMLAutoClose-8 2.60kB ± 0% 2.58kB ± 0% -0.46% (p=0.000 n=10+10) name old allocs/op new allocs/op delta HTMLAutoClose-8 72.0 ± 0% 67.0 ± 0% -6.94% (p=0.000 n=10+10) The overall `encoding/xml` test coverage increase is `88.1% -> 89.9%`; although it may look insignificant, this CL covers some important corner cases, like `autoClose()` functionality (that was not tested at all). Fixes #49635 Fixes #49636 Change-Id: I50b2769896c197eb285672313b7148f4fe8bdb38 Reviewed-on: https://go-review.googlesource.com/c/go/+/364734 Trust: Bryan Mills Reviewed-by: Daniel Martí Trust: Daniel Martí Run-TryBot: Daniel Martí TryBot-Result: Gopher Robot --- src/encoding/xml/xml.go | 10 +-- src/encoding/xml/xml_test.go | 165 +++++++++++++++++++++++++++++++++++ 2 files changed, 168 insertions(+), 7 deletions(-) diff --git a/src/encoding/xml/xml.go b/src/encoding/xml/xml.go index 8a0a9c253ad..ef51252dcbb 100644 --- a/src/encoding/xml/xml.go +++ b/src/encoding/xml/xml.go @@ -10,9 +10,6 @@ package xml // Annotated XML spec: https://www.xml.com/axml/testaxml.htm // XML name spaces: https://www.w3.org/TR/REC-xml-names/ -// TODO(rsc): -// Test error handling. - import ( "bufio" "bytes" @@ -499,7 +496,7 @@ func (d *Decoder) popElement(t *EndElement) bool { return false case s.name.Space != name.Space: d.err = d.syntaxError("element <" + s.name.Local + "> in space " + s.name.Space + - "closed by in space " + name.Space) + " closed by in space " + name.Space) return false } @@ -523,12 +520,11 @@ func (d *Decoder) autoClose(t Token) (Token, bool) { if d.stk == nil || d.stk.kind != stkStart { return nil, false } - name := strings.ToLower(d.stk.name.Local) for _, s := range d.AutoClose { - if strings.ToLower(s) == name { + if strings.EqualFold(s, d.stk.name.Local) { // This one should be auto closed if t doesn't close it. et, ok := t.(EndElement) - if !ok || et.Name.Local != name { + if !ok || !strings.EqualFold(et.Name.Local, d.stk.name.Local) { return EndElement{d.stk.name}, true } break diff --git a/src/encoding/xml/xml_test.go b/src/encoding/xml/xml_test.go index 19152dbdb68..ab1dbf849bf 100644 --- a/src/encoding/xml/xml_test.go +++ b/src/encoding/xml/xml_test.go @@ -673,6 +673,19 @@ func TestCopyTokenStartElement(t *testing.T) { } } +func TestCopyTokenComment(t *testing.T) { + data := []byte("") + var tok1 Token = Comment(data) + tok2 := CopyToken(tok1) + if !reflect.DeepEqual(tok1, tok2) { + t.Error("CopyToken(Comment) != Comment") + } + data[1] = 'o' + if reflect.DeepEqual(tok1, tok2) { + t.Error("CopyToken(Comment) uses same buffer.") + } +} + func TestSyntaxErrorLineNum(t *testing.T) { testInput := "

Foo

\n\n

Bar\n" d := NewDecoder(strings.NewReader(testInput)) @@ -1060,3 +1073,155 @@ func TestRoundTrip(t *testing.T) { t.Run(name, func(t *testing.T) { testRoundTrip(t, input) }) } } + +func TestParseErrors(t *testing.T) { + withDefaultHeader := func(s string) string { + return `` + s + } + tests := []struct { + src string + err string + }{ + {withDefaultHeader(``), `unexpected end element `}, + {withDefaultHeader(``), `element in space x closed by in space y`}, + {withDefaultHeader(``), `expected target name after `), `invalid sequence `), `invalid sequence `), `invalid `, `unsupported version "1.1"; only version 1.0 is supported`}, + + // Cases below are for "no errors". + {withDefaultHeader(``), ``}, + {withDefaultHeader(``), ``}, + } + + for _, test := range tests { + d := NewDecoder(strings.NewReader(test.src)) + var err error + for { + _, err = d.Token() + if err != nil { + break + } + } + if test.err == "" { + if err != io.EOF { + t.Errorf("parse %s: have %q error, expected none", test.src, err) + } + continue + } + if err == nil || err == io.EOF { + t.Errorf("parse %s: have no error, expected a non-nil error", test.src) + continue + } + if !strings.Contains(err.Error(), test.err) { + t.Errorf("parse %s: can't find %q error sudbstring\nerror: %q", test.src, test.err, err) + continue + } + } +} + +const testInputHTMLAutoClose = ` +
+

+

+

+
+

+

+
abc

` + +func BenchmarkHTMLAutoClose(b *testing.B) { + b.RunParallel(func(p *testing.PB) { + for p.Next() { + d := NewDecoder(strings.NewReader(testInputHTMLAutoClose)) + d.Strict = false + d.AutoClose = HTMLAutoClose + d.Entity = HTMLEntity + for { + _, err := d.Token() + if err != nil { + if err == io.EOF { + break + } + b.Fatalf("unexpected error: %v", err) + } + } + } + }) +} + +func TestHTMLAutoClose(t *testing.T) { + wantTokens := []Token{ + ProcInst{"xml", []byte(`version="1.0" encoding="UTF-8"`)}, + CharData("\n"), + StartElement{Name{"", "br"}, []Attr{}}, + EndElement{Name{"", "br"}}, + CharData("\n"), + StartElement{Name{"", "br"}, []Attr{}}, + EndElement{Name{"", "br"}}, + StartElement{Name{"", "br"}, []Attr{}}, + EndElement{Name{"", "br"}}, + CharData("\n"), + StartElement{Name{"", "br"}, []Attr{}}, + EndElement{Name{"", "br"}}, + StartElement{Name{"", "br"}, []Attr{}}, + EndElement{Name{"", "br"}}, + CharData("\n"), + StartElement{Name{"", "br"}, []Attr{}}, + EndElement{Name{"", "br"}}, + CharData("\n"), + StartElement{Name{"", "BR"}, []Attr{}}, + EndElement{Name{"", "BR"}}, + CharData("\n"), + StartElement{Name{"", "BR"}, []Attr{}}, + EndElement{Name{"", "BR"}}, + StartElement{Name{"", "BR"}, []Attr{}}, + EndElement{Name{"", "BR"}}, + CharData("\n"), + StartElement{Name{"", "Br"}, []Attr{}}, + EndElement{Name{"", "Br"}}, + CharData("\n"), + StartElement{Name{"", "BR"}, []Attr{}}, + EndElement{Name{"", "BR"}}, + StartElement{Name{"", "span"}, []Attr{{Name: Name{"", "id"}, Value: "test"}}}, + CharData("abc"), + EndElement{Name{"", "span"}}, + StartElement{Name{"", "br"}, []Attr{}}, + EndElement{Name{"", "br"}}, + StartElement{Name{"", "br"}, []Attr{}}, + EndElement{Name{"", "br"}}, + } + + d := NewDecoder(strings.NewReader(testInputHTMLAutoClose)) + d.Strict = false + d.AutoClose = HTMLAutoClose + d.Entity = HTMLEntity + var haveTokens []Token + for { + tok, err := d.Token() + if err != nil { + if err == io.EOF { + break + } + t.Fatalf("unexpected error: %v", err) + } + haveTokens = append(haveTokens, CopyToken(tok)) + } + if len(haveTokens) != len(wantTokens) { + t.Errorf("tokens count mismatch: have %d, want %d", len(haveTokens), len(wantTokens)) + } + for i, want := range wantTokens { + if i >= len(haveTokens) { + t.Errorf("token[%d] expected %#v, have no token", i, want) + } else { + have := haveTokens[i] + if !reflect.DeepEqual(have, want) { + t.Errorf("token[%d] mismatch:\nhave: %#v\nwant: %#v", i, have, want) + } + } + } +} From bf97c99b62fe7d6652cc8c807dbc91998d488a01 Mon Sep 17 00:00:00 2001 From: uji Date: Sat, 26 Feb 2022 13:58:54 +0000 Subject: [PATCH 008/276] cmd/go: clarify error from 'go install' when arguments have mismatched versions and paths Fixes #51196. Change-Id: I0ee4d8234f11e4f3b71b81546518647e07fafd7d GitHub-Last-Rev: 8fd1a77adff982dd00385c5b25a4e0cdf3e2e220 GitHub-Pull-Request: golang/go#51373 Reviewed-on: https://go-review.googlesource.com/c/go/+/388154 Trust: Dmitri Shuralyov Reviewed-by: Bryan Mills Run-TryBot: Bryan Mills TryBot-Result: Gopher Robot Trust: Than McIntosh Reviewed-by: Than McIntosh --- src/cmd/go/internal/load/pkg.go | 2 +- src/cmd/go/testdata/script/mod_install_pkg_version.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cmd/go/internal/load/pkg.go b/src/cmd/go/internal/load/pkg.go index d68f43a7c98..fdc00f95dca 100644 --- a/src/cmd/go/internal/load/pkg.go +++ b/src/cmd/go/internal/load/pkg.go @@ -3001,7 +3001,7 @@ func PackagesAndErrorsOutsideModule(ctx context.Context, opts PackageOpts, args patterns := make([]string, len(args)) for i, arg := range args { if !strings.HasSuffix(arg, "@"+version) { - return nil, fmt.Errorf("%s: all arguments must have the same version (@%s)", arg, version) + return nil, fmt.Errorf("%s: all arguments must refer to packages in the same module at the same version (@%s)", arg, version) } p := arg[:len(arg)-len(version)-1] switch { diff --git a/src/cmd/go/testdata/script/mod_install_pkg_version.txt b/src/cmd/go/testdata/script/mod_install_pkg_version.txt index 14153b8e9ec..e3f59fc1528 100644 --- a/src/cmd/go/testdata/script/mod_install_pkg_version.txt +++ b/src/cmd/go/testdata/script/mod_install_pkg_version.txt @@ -106,7 +106,7 @@ stdout '^example.com/cmd v1.0.0$' env GO111MODULE=auto ! go install example.com/cmd/a@v1.0.0 example.com/cmd/b@latest -stderr '^go: example.com/cmd/b@latest: all arguments must have the same version \(@v1.0.0\)$' +stderr '^go: example.com/cmd/b@latest: all arguments must refer to packages in the same module at the same version \(@v1.0.0\)$' # 'go install pkg@version' should report an error if the arguments are in From 55a60cadc3f5d01f76ac9435da2ed941e194a29b Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Fri, 4 Mar 2022 09:49:32 +0100 Subject: [PATCH 009/276] syscall: use dup3 in forkAndExecInChild on OpenBSD Use dup3(oldfd, newfd, O_CLOEXEC) to atomically duplicate the file descriptor and mark is as close-on-exec instead of dup2 & fcntl. The dup3 system call first appeared in OpenBSD 5.7. Change-Id: Ic06c2c7089dcdbd931ee24e5e8c316879d81474e Reviewed-on: https://go-review.googlesource.com/c/go/+/389974 Trust: Tobias Klauser Run-TryBot: Tobias Klauser Reviewed-by: Ian Lance Taylor --- src/syscall/exec_bsd.go | 26 ++++++++++++-------------- src/syscall/exec_libc2.go | 23 +++++++++++++++++++---- src/syscall/syscall_darwin.go | 2 ++ src/syscall/syscall_openbsd.go | 1 + src/syscall/syscall_openbsd_libc.go | 2 ++ src/syscall/syscall_openbsd_mips64.go | 2 +- src/syscall/zsyscall_openbsd_386.go | 14 ++++++++++++++ src/syscall/zsyscall_openbsd_386.s | 2 ++ src/syscall/zsyscall_openbsd_amd64.go | 14 ++++++++++++++ src/syscall/zsyscall_openbsd_amd64.s | 2 ++ src/syscall/zsyscall_openbsd_arm.go | 14 ++++++++++++++ src/syscall/zsyscall_openbsd_arm.s | 2 ++ src/syscall/zsyscall_openbsd_arm64.go | 14 ++++++++++++++ src/syscall/zsyscall_openbsd_arm64.s | 2 ++ 14 files changed, 101 insertions(+), 19 deletions(-) diff --git a/src/syscall/exec_bsd.go b/src/syscall/exec_bsd.go index 148f5a91aa0..530b48cb707 100644 --- a/src/syscall/exec_bsd.go +++ b/src/syscall/exec_bsd.go @@ -181,18 +181,17 @@ func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr // Pass 1: look for fd[i] < i and move those up above len(fd) // so that pass 2 won't stomp on an fd it needs later. if pipe < nextfd { - switch runtime.GOOS { - case "netbsd": + if runtime.GOOS == "netbsd" || (runtime.GOOS == "openbsd" && runtime.GOARCH == "mips64") { _, _, err1 = RawSyscall(_SYS_DUP3, uintptr(pipe), uintptr(nextfd), O_CLOEXEC) - if err1 != 0 { - goto childerror - } - default: + } else { _, _, err1 = RawSyscall(SYS_DUP2, uintptr(pipe), uintptr(nextfd), 0) if err1 != 0 { goto childerror } - RawSyscall(SYS_FCNTL, uintptr(nextfd), F_SETFD, FD_CLOEXEC) + _, _, err1 = RawSyscall(SYS_FCNTL, uintptr(nextfd), F_SETFD, FD_CLOEXEC) + } + if err1 != 0 { + goto childerror } pipe = nextfd nextfd++ @@ -202,18 +201,17 @@ func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr if nextfd == pipe { // don't stomp on pipe nextfd++ } - switch runtime.GOOS { - case "netbsd": + if runtime.GOOS == "netbsd" || (runtime.GOOS == "openbsd" && runtime.GOARCH == "mips64") { _, _, err1 = RawSyscall(_SYS_DUP3, uintptr(fd[i]), uintptr(nextfd), O_CLOEXEC) - if err1 != 0 { - goto childerror - } - default: + } else { _, _, err1 = RawSyscall(SYS_DUP2, uintptr(fd[i]), uintptr(nextfd), 0) if err1 != 0 { goto childerror } - RawSyscall(SYS_FCNTL, uintptr(nextfd), F_SETFD, FD_CLOEXEC) + _, _, err1 = RawSyscall(SYS_FCNTL, uintptr(nextfd), F_SETFD, FD_CLOEXEC) + } + if err1 != 0 { + goto childerror } fd[i] = nextfd nextfd++ diff --git a/src/syscall/exec_libc2.go b/src/syscall/exec_libc2.go index b05f053bbf3..91a39ba1b8f 100644 --- a/src/syscall/exec_libc2.go +++ b/src/syscall/exec_libc2.go @@ -8,6 +8,7 @@ package syscall import ( "internal/abi" + "runtime" "unsafe" ) @@ -180,11 +181,18 @@ func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr // Pass 1: look for fd[i] < i and move those up above len(fd) // so that pass 2 won't stomp on an fd it needs later. if pipe < nextfd { - _, _, err1 = rawSyscall(abi.FuncPCABI0(libc_dup2_trampoline), uintptr(pipe), uintptr(nextfd), 0) + if runtime.GOOS == "openbsd" { + _, _, err1 = rawSyscall(dupTrampoline, uintptr(pipe), uintptr(nextfd), O_CLOEXEC) + } else { + _, _, err1 = rawSyscall(dupTrampoline, uintptr(pipe), uintptr(nextfd), 0) + if err1 != 0 { + goto childerror + } + _, _, err1 = rawSyscall(abi.FuncPCABI0(libc_fcntl_trampoline), uintptr(nextfd), F_SETFD, FD_CLOEXEC) + } if err1 != 0 { goto childerror } - rawSyscall(abi.FuncPCABI0(libc_fcntl_trampoline), uintptr(nextfd), F_SETFD, FD_CLOEXEC) pipe = nextfd nextfd++ } @@ -193,11 +201,18 @@ func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr if nextfd == pipe { // don't stomp on pipe nextfd++ } - _, _, err1 = rawSyscall(abi.FuncPCABI0(libc_dup2_trampoline), uintptr(fd[i]), uintptr(nextfd), 0) + if runtime.GOOS == "openbsd" { + _, _, err1 = rawSyscall(dupTrampoline, uintptr(fd[i]), uintptr(nextfd), O_CLOEXEC) + } else { + _, _, err1 = rawSyscall(dupTrampoline, uintptr(fd[i]), uintptr(nextfd), 0) + if err1 != 0 { + goto childerror + } + _, _, err1 = rawSyscall(abi.FuncPCABI0(libc_fcntl_trampoline), uintptr(nextfd), F_SETFD, FD_CLOEXEC) + } if err1 != 0 { goto childerror } - rawSyscall(abi.FuncPCABI0(libc_fcntl_trampoline), uintptr(nextfd), F_SETFD, FD_CLOEXEC) fd[i] = nextfd nextfd++ } diff --git a/src/syscall/syscall_darwin.go b/src/syscall/syscall_darwin.go index 902d6e77e11..87fb5c2f62d 100644 --- a/src/syscall/syscall_darwin.go +++ b/src/syscall/syscall_darwin.go @@ -17,6 +17,8 @@ import ( "unsafe" ) +var dupTrampoline = abi.FuncPCABI0(libc_dup2_trampoline) + type SockaddrDatalink struct { Len uint8 Family uint8 diff --git a/src/syscall/syscall_openbsd.go b/src/syscall/syscall_openbsd.go index fa939ec5c88..30a95316e85 100644 --- a/src/syscall/syscall_openbsd.go +++ b/src/syscall/syscall_openbsd.go @@ -136,6 +136,7 @@ func Getfsstat(buf []Statfs_t, flags int) (n int, err error) { //sys Close(fd int) (err error) //sys Dup(fd int) (nfd int, err error) //sys Dup2(from int, to int) (err error) +//sys dup3(from int, to int, flags int) (err error) //sys Fchdir(fd int) (err error) //sys Fchflags(fd int, flags int) (err error) //sys Fchmod(fd int, mode uint32) (err error) diff --git a/src/syscall/syscall_openbsd_libc.go b/src/syscall/syscall_openbsd_libc.go index 15b68fd0fcf..516d02975c5 100644 --- a/src/syscall/syscall_openbsd_libc.go +++ b/src/syscall/syscall_openbsd_libc.go @@ -10,6 +10,8 @@ import ( "internal/abi" ) +var dupTrampoline = abi.FuncPCABI0(libc_dup3_trampoline) + func init() { execveOpenBSD = execve } diff --git a/src/syscall/syscall_openbsd_mips64.go b/src/syscall/syscall_openbsd_mips64.go index e8ae2e9911b..4508ad99b49 100644 --- a/src/syscall/syscall_openbsd_mips64.go +++ b/src/syscall/syscall_openbsd_mips64.go @@ -4,7 +4,7 @@ package syscall -const _SYS_DUP3 = 0 +const _SYS_DUP3 = SYS_DUP3 func setTimespec(sec, nsec int64) Timespec { return Timespec{Sec: sec, Nsec: nsec} diff --git a/src/syscall/zsyscall_openbsd_386.go b/src/syscall/zsyscall_openbsd_386.go index 5f95d7a9c6d..2dcc4b2739d 100644 --- a/src/syscall/zsyscall_openbsd_386.go +++ b/src/syscall/zsyscall_openbsd_386.go @@ -551,6 +551,20 @@ func libc_dup2_trampoline() // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func dup3(from int, to int, flags int) (err error) { + _, _, e1 := syscall(abi.FuncPCABI0(libc_dup3_trampoline), uintptr(from), uintptr(to), uintptr(flags)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +func libc_dup3_trampoline() + +//go:cgo_import_dynamic libc_dup3 dup3 "libc.so" + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func Fchdir(fd int) (err error) { _, _, e1 := syscall(abi.FuncPCABI0(libc_fchdir_trampoline), uintptr(fd), 0, 0) if e1 != 0 { diff --git a/src/syscall/zsyscall_openbsd_386.s b/src/syscall/zsyscall_openbsd_386.s index d47a4f480d9..e2c58625bb3 100644 --- a/src/syscall/zsyscall_openbsd_386.s +++ b/src/syscall/zsyscall_openbsd_386.s @@ -69,6 +69,8 @@ TEXT ·libc_dup_trampoline(SB),NOSPLIT,$0-0 JMP libc_dup(SB) TEXT ·libc_dup2_trampoline(SB),NOSPLIT,$0-0 JMP libc_dup2(SB) +TEXT ·libc_dup3_trampoline(SB),NOSPLIT,$0-0 + JMP libc_dup3(SB) TEXT ·libc_fchdir_trampoline(SB),NOSPLIT,$0-0 JMP libc_fchdir(SB) TEXT ·libc_fchflags_trampoline(SB),NOSPLIT,$0-0 diff --git a/src/syscall/zsyscall_openbsd_amd64.go b/src/syscall/zsyscall_openbsd_amd64.go index 189bf887e62..8d4cb9c1e1c 100644 --- a/src/syscall/zsyscall_openbsd_amd64.go +++ b/src/syscall/zsyscall_openbsd_amd64.go @@ -551,6 +551,20 @@ func libc_dup2_trampoline() // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func dup3(from int, to int, flags int) (err error) { + _, _, e1 := syscall(abi.FuncPCABI0(libc_dup3_trampoline), uintptr(from), uintptr(to), uintptr(flags)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +func libc_dup3_trampoline() + +//go:cgo_import_dynamic libc_dup3 dup3 "libc.so" + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func Fchdir(fd int) (err error) { _, _, e1 := syscall(abi.FuncPCABI0(libc_fchdir_trampoline), uintptr(fd), 0, 0) if e1 != 0 { diff --git a/src/syscall/zsyscall_openbsd_amd64.s b/src/syscall/zsyscall_openbsd_amd64.s index e5c5dde930b..964c9ed9e12 100644 --- a/src/syscall/zsyscall_openbsd_amd64.s +++ b/src/syscall/zsyscall_openbsd_amd64.s @@ -69,6 +69,8 @@ TEXT ·libc_dup_trampoline(SB),NOSPLIT,$0-0 JMP libc_dup(SB) TEXT ·libc_dup2_trampoline(SB),NOSPLIT,$0-0 JMP libc_dup2(SB) +TEXT ·libc_dup3_trampoline(SB),NOSPLIT,$0-0 + JMP libc_dup3(SB) TEXT ·libc_fchdir_trampoline(SB),NOSPLIT,$0-0 JMP libc_fchdir(SB) TEXT ·libc_fchflags_trampoline(SB),NOSPLIT,$0-0 diff --git a/src/syscall/zsyscall_openbsd_arm.go b/src/syscall/zsyscall_openbsd_arm.go index c7513a3ac9a..d45bc02fbd3 100644 --- a/src/syscall/zsyscall_openbsd_arm.go +++ b/src/syscall/zsyscall_openbsd_arm.go @@ -551,6 +551,20 @@ func libc_dup2_trampoline() // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func dup3(from int, to int, flags int) (err error) { + _, _, e1 := syscall(abi.FuncPCABI0(libc_dup3_trampoline), uintptr(from), uintptr(to), uintptr(flags)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +func libc_dup3_trampoline() + +//go:cgo_import_dynamic libc_dup3 dup3 "libc.so" + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func Fchdir(fd int) (err error) { _, _, e1 := syscall(abi.FuncPCABI0(libc_fchdir_trampoline), uintptr(fd), 0, 0) if e1 != 0 { diff --git a/src/syscall/zsyscall_openbsd_arm.s b/src/syscall/zsyscall_openbsd_arm.s index d33f3aa3e05..5975780edb2 100644 --- a/src/syscall/zsyscall_openbsd_arm.s +++ b/src/syscall/zsyscall_openbsd_arm.s @@ -69,6 +69,8 @@ TEXT ·libc_dup_trampoline(SB),NOSPLIT,$0-0 JMP libc_dup(SB) TEXT ·libc_dup2_trampoline(SB),NOSPLIT,$0-0 JMP libc_dup2(SB) +TEXT ·libc_dup3_trampoline(SB),NOSPLIT,$0-0 + JMP libc_dup3(SB) TEXT ·libc_fchdir_trampoline(SB),NOSPLIT,$0-0 JMP libc_fchdir(SB) TEXT ·libc_fchflags_trampoline(SB),NOSPLIT,$0-0 diff --git a/src/syscall/zsyscall_openbsd_arm64.go b/src/syscall/zsyscall_openbsd_arm64.go index 293b7036002..e060b092fe3 100644 --- a/src/syscall/zsyscall_openbsd_arm64.go +++ b/src/syscall/zsyscall_openbsd_arm64.go @@ -551,6 +551,20 @@ func libc_dup2_trampoline() // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func dup3(from int, to int, flags int) (err error) { + _, _, e1 := syscall(abi.FuncPCABI0(libc_dup3_trampoline), uintptr(from), uintptr(to), uintptr(flags)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +func libc_dup3_trampoline() + +//go:cgo_import_dynamic libc_dup3 dup3 "libc.so" + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func Fchdir(fd int) (err error) { _, _, e1 := syscall(abi.FuncPCABI0(libc_fchdir_trampoline), uintptr(fd), 0, 0) if e1 != 0 { diff --git a/src/syscall/zsyscall_openbsd_arm64.s b/src/syscall/zsyscall_openbsd_arm64.s index 37778b1db54..2c4a0b0faf5 100644 --- a/src/syscall/zsyscall_openbsd_arm64.s +++ b/src/syscall/zsyscall_openbsd_arm64.s @@ -69,6 +69,8 @@ TEXT ·libc_dup_trampoline(SB),NOSPLIT,$0-0 JMP libc_dup(SB) TEXT ·libc_dup2_trampoline(SB),NOSPLIT,$0-0 JMP libc_dup2(SB) +TEXT ·libc_dup3_trampoline(SB),NOSPLIT,$0-0 + JMP libc_dup3(SB) TEXT ·libc_fchdir_trampoline(SB),NOSPLIT,$0-0 JMP libc_fchdir(SB) TEXT ·libc_fchflags_trampoline(SB),NOSPLIT,$0-0 From 2981fc7f1676ca79e487ba3c1df06e5e60723483 Mon Sep 17 00:00:00 2001 From: Dan Kortschak Date: Tue, 21 Dec 2021 21:49:50 +1030 Subject: [PATCH 010/276] math: don't use integer division that truncates to zero Change-Id: I7389da0c3a63fea3be5c820f2ce0d0168a95ab4c Reviewed-on: https://go-review.googlesource.com/c/go/+/373377 Trust: Emmanuel Odeke Run-TryBot: Emmanuel Odeke TryBot-Result: Gopher Robot Reviewed-by: Ian Lance Taylor --- src/math/all_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/math/all_test.go b/src/math/all_test.go index c11d8232331..8d5e0ad4391 100644 --- a/src/math/all_test.go +++ b/src/math/all_test.go @@ -1631,8 +1631,8 @@ var vfpowSC = [][2]float64{ {-1, Inf(-1)}, {-1, Inf(1)}, {-1, NaN()}, - {-1 / 2, Inf(-1)}, - {-1 / 2, Inf(1)}, + {-0.5, Inf(-1)}, + {-0.5, Inf(1)}, {Copysign(0, -1), Inf(-1)}, {Copysign(0, -1), -Pi}, {Copysign(0, -1), -0.5}, @@ -1652,8 +1652,8 @@ var vfpowSC = [][2]float64{ {0, Inf(1)}, {0, NaN()}, - {1 / 2, Inf(-1)}, - {1 / 2, Inf(1)}, + {0.5, Inf(-1)}, + {0.5, Inf(1)}, {1, Inf(-1)}, {1, Inf(1)}, {1, NaN()}, @@ -1681,8 +1681,8 @@ var vfpowSC = [][2]float64{ {2, float64(1 << 32)}, {2, -float64(1 << 32)}, {-2, float64(1<<32 + 1)}, - {1 / 2, float64(1 << 45)}, - {1 / 2, -float64(1 << 45)}, + {0.5, float64(1 << 45)}, + {0.5, -float64(1 << 45)}, {Nextafter(1, 2), float64(1 << 63)}, {Nextafter(1, -2), float64(1 << 63)}, {Nextafter(-1, 2), float64(1 << 63)}, From 45f45444b307cea7c8330b100b30382e642e010f Mon Sep 17 00:00:00 2001 From: Adam Shannon Date: Wed, 2 Mar 2022 15:05:39 -0800 Subject: [PATCH 011/276] fmt: clarify right-padded strings use spaces Fixes #51419 Change-Id: I0a32f41a6e6e01481ad58c7dddb57ec7085d77af Reviewed-on: https://go-review.googlesource.com/c/go/+/389434 Reviewed-by: Rob Pike Trust: Ian Lance Taylor --- src/fmt/doc.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/fmt/doc.go b/src/fmt/doc.go index c584cc9465e..4a095557344 100644 --- a/src/fmt/doc.go +++ b/src/fmt/doc.go @@ -124,7 +124,8 @@ ' ' (space) leave a space for elided sign in numbers (% d); put spaces between bytes printing strings or slices in hex (% x, % X) 0 pad with leading zeros rather than spaces; - for numbers, this moves the padding after the sign + for numbers, this moves the padding after the sign; + ignored for strings, byte slices and byte arrays Flags are ignored by verbs that do not expect them. For example there is no alternate decimal format, so %#d and %d From da2773fe3e2f6106634673a38dc3a6eb875fe7d8 Mon Sep 17 00:00:00 2001 From: Dan Kortschak Date: Sat, 5 Mar 2022 19:21:15 +1030 Subject: [PATCH 012/276] all: fix some typos MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I7dfae0fc91c2d70873ec7ec920be7c0a4888153a Reviewed-on: https://go-review.googlesource.com/c/go/+/390175 Reviewed-by: Ian Lance Taylor Reviewed-by: Daniel Martí Trust: Daniel Martí --- src/compress/bzip2/huffman.go | 2 +- src/crypto/tls/conn.go | 2 +- src/crypto/x509/parser.go | 2 +- src/debug/dwarf/entry.go | 2 +- src/html/template/escape.go | 4 ++-- src/index/suffixarray/sais.go | 2 +- src/index/suffixarray/sais2.go | 2 +- src/math/big/nat.go | 2 +- src/net/lookup.go | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/compress/bzip2/huffman.go b/src/compress/bzip2/huffman.go index 36ae9540093..447fc4d8510 100644 --- a/src/compress/bzip2/huffman.go +++ b/src/compress/bzip2/huffman.go @@ -182,7 +182,7 @@ func buildHuffmanNode(t *huffmanTree, codes []huffmanCode, level uint32) (nodeIn // If this function was called recursively then we know that // len(codes) >= 2 because, otherwise, we would have hit the - // "leaf node" case, below, and not recursed. + // "leaf node" case, below, and not recurred. // // However, for the initial call it's possible that len(codes) // is zero or one. Both cases are invalid because a zero length diff --git a/src/crypto/tls/conn.go b/src/crypto/tls/conn.go index 28ab0637820..fba36d30100 100644 --- a/src/crypto/tls/conn.go +++ b/src/crypto/tls/conn.go @@ -758,7 +758,7 @@ func (c *Conn) readRecordOrCCS(expectChangeCipherSpec bool) error { return nil } -// retryReadRecord recurses into readRecordOrCCS to drop a non-advancing record, like +// retryReadRecord recurs into readRecordOrCCS to drop a non-advancing record, like // a warning alert, empty application_data, or a change_cipher_spec in TLS 1.3. func (c *Conn) retryReadRecord(expectChangeCipherSpec bool) error { c.retryCount++ diff --git a/src/crypto/x509/parser.go b/src/crypto/x509/parser.go index a32a973c68e..bb60cea7c96 100644 --- a/src/crypto/x509/parser.go +++ b/src/crypto/x509/parser.go @@ -855,7 +855,7 @@ func parseCertificate(der []byte) (*Certificate, error) { } // we ignore the presence of negative serial numbers because // of their prevalence, despite them being invalid - // TODO(rolandshoemaker): revist this decision, there are currently + // TODO(rolandshoemaker): revisit this decision, there are currently // only 10 trusted certificates with negative serial numbers // according to censys.io. cert.SerialNumber = serial diff --git a/src/debug/dwarf/entry.go b/src/debug/dwarf/entry.go index cbdc838a12b..3bc6a5454e3 100644 --- a/src/debug/dwarf/entry.go +++ b/src/debug/dwarf/entry.go @@ -1122,7 +1122,7 @@ func (d *Data) dwarf2Ranges(u *unit, base uint64, ranges int64, ret [][2]uint64) return ret, nil } -// dwarf5Ranges interpets a debug_rnglists sequence, see DWARFv5 section +// dwarf5Ranges interprets a debug_rnglists sequence, see DWARFv5 section // 2.17.3 (page 53). func (d *Data) dwarf5Ranges(u *unit, cu *Entry, base uint64, ranges int64, ret [][2]uint64) ([][2]uint64, error) { var addrBase int64 diff --git a/src/html/template/escape.go b/src/html/template/escape.go index 2b11526f52b..2b4027348ae 100644 --- a/src/html/template/escape.go +++ b/src/html/template/escape.go @@ -44,7 +44,7 @@ func escapeTemplate(tmpl *Template, node parse.Node, name string) error { } // evalArgs formats the list of arguments into a string. It is equivalent to -// fmt.Sprint(args...), except that it deferences all pointers. +// fmt.Sprint(args...), except that it dereferences all pointers. func evalArgs(args ...any) string { // Optimization for simple common case of a single string argument. if len(args) == 1 { @@ -690,7 +690,7 @@ func (e *escaper) escapeTemplateBody(c context, t *template.Template) (context, return c.eq(c1) } // We need to assume an output context so that recursive template calls - // take the fast path out of escapeTree instead of infinitely recursing. + // take the fast path out of escapeTree instead of infinitely recurring. // Naively assuming that the input context is the same as the output // works >90% of the time. e.output[t.Name()] = c diff --git a/src/index/suffixarray/sais.go b/src/index/suffixarray/sais.go index b4496d29882..74c52356171 100644 --- a/src/index/suffixarray/sais.go +++ b/src/index/suffixarray/sais.go @@ -656,7 +656,7 @@ func recurse_32(sa, oldTmp []int32, numLMS, maxID int) { dst, saTmp, text := sa[:numLMS], sa[numLMS:len(sa)-numLMS], sa[len(sa)-numLMS:] // Set up temporary space for recursive call. - // We must pass sais_32 a tmp buffer wiith at least maxID entries. + // We must pass sais_32 a tmp buffer with at least maxID entries. // // The subproblem is guaranteed to have length at most len(sa)/2, // so that sa can hold both the subproblem and its suffix array. diff --git a/src/index/suffixarray/sais2.go b/src/index/suffixarray/sais2.go index f1247028c6c..32b89728011 100644 --- a/src/index/suffixarray/sais2.go +++ b/src/index/suffixarray/sais2.go @@ -1194,7 +1194,7 @@ func recurse_64(sa, oldTmp []int64, numLMS, maxID int) { dst, saTmp, text := sa[:numLMS], sa[numLMS:len(sa)-numLMS], sa[len(sa)-numLMS:] // Set up temporary space for recursive call. - // We must pass sais_64 a tmp buffer wiith at least maxID entries. + // We must pass sais_64 a tmp buffer with at least maxID entries. // // The subproblem is guaranteed to have length at most len(sa)/2, // so that sa can hold both the subproblem and its suffix array. diff --git a/src/math/big/nat.go b/src/math/big/nat.go index 140c619c8ca..512b2c229fb 100644 --- a/src/math/big/nat.go +++ b/src/math/big/nat.go @@ -341,7 +341,7 @@ func karatsuba(z, x, y nat) { karatsuba(p, xd, yd) // save original z2:z0 - // (ok to use upper half of z since we're done recursing) + // (ok to use upper half of z since we're done recurring) r := z[n*4:] copy(r, z[:n*2]) diff --git a/src/net/lookup.go b/src/net/lookup.go index c7b8dc69059..6fa90f354d4 100644 --- a/src/net/lookup.go +++ b/src/net/lookup.go @@ -286,7 +286,7 @@ func withUnexpiredValuesPreserved(lookupCtx context.Context) context.Context { // It returns a slice of that host's IPv4 and IPv6 addresses. func (r *Resolver) lookupIPAddr(ctx context.Context, network, host string) ([]IPAddr, error) { // Make sure that no matter what we do later, host=="" is rejected. - // parseIP, for example, does accept empty strings. + // parseIPZone, for example, does accept empty strings. if host == "" { return nil, &DNSError{Err: errNoSuchHost.Error(), Name: host, IsNotFound: true} } From 7c292ddf1f883698b3a0bab7004368cff62a04a5 Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Sun, 6 Mar 2022 20:11:21 -0800 Subject: [PATCH 013/276] cmd/compile: fix reentrancy issue in unified IR function body reading We shouldn't need to read in function bodies for new functions found during inlining, but something is expecting them to still be read in. We should fix that code to not depend on them being read in, but in the mean time reading them in anyway is at least correct, albeit less efficient in time and space. Fixes #49536. Updates #50552. Change-Id: I949ef45e7be09406e5a8149e251d78e015aca5fa Reviewed-on: https://go-review.googlesource.com/c/go/+/390335 Run-TryBot: Matthew Dempsky Trust: Matthew Dempsky Reviewed-by: Cuong Manh Le TryBot-Result: Gopher Robot --- src/cmd/compile/internal/noder/reader.go | 14 ++++---- src/cmd/compile/internal/noder/unified.go | 40 +++++++++++++---------- test/run.go | 1 - test/typeparam/issue49536.dir/a.go | 12 +++++++ test/typeparam/issue49536.dir/b.go | 9 +++++ test/typeparam/issue49536.go | 7 ++++ 6 files changed, 58 insertions(+), 25 deletions(-) create mode 100644 test/typeparam/issue49536.dir/a.go create mode 100644 test/typeparam/issue49536.dir/b.go create mode 100644 test/typeparam/issue49536.go diff --git a/src/cmd/compile/internal/noder/reader.go b/src/cmd/compile/internal/noder/reader.go index 2b1636588e6..3207e3f85bd 100644 --- a/src/cmd/compile/internal/noder/reader.go +++ b/src/cmd/compile/internal/noder/reader.go @@ -930,11 +930,6 @@ var bodyReader = map[*ir.Func]pkgReaderIndex{} // constructed. var todoBodies []*ir.Func -// todoBodiesDone signals that we constructed all function in todoBodies. -// This is necessary to prevent reader.addBody adds thing to todoBodies -// when nested inlining happens. -var todoBodiesDone = false - func (r *reader) addBody(fn *ir.Func) { pri := pkgReaderIndex{r.p, r.Reloc(pkgbits.RelocBody), r.dict} bodyReader[fn] = pri @@ -945,7 +940,7 @@ func (r *reader) addBody(fn *ir.Func) { return } - if r.curfn == nil && !todoBodiesDone { + if r.curfn == nil { todoBodies = append(todoBodies, fn) return } @@ -1974,6 +1969,13 @@ func InlineCall(call *ir.CallExpr, fn *ir.Func, inlIndex int) *ir.InlinedCallExp r.curfn.Body = r.stmts() r.curfn.Endlineno = r.pos() + // TODO(mdempsky): This shouldn't be necessary. Inlining might + // read in new function/method declarations, which could + // potentially be recursively inlined themselves; but we shouldn't + // need to read in the non-inlined bodies for the declarations + // themselves. But currently it's an easy fix to #50552. + readBodies(typecheck.Target) + deadcode.Func(r.curfn) // Replace any "return" statements within the function body. diff --git a/src/cmd/compile/internal/noder/unified.go b/src/cmd/compile/internal/noder/unified.go index ac82f2df03a..ca01c0da95b 100644 --- a/src/cmd/compile/internal/noder/unified.go +++ b/src/cmd/compile/internal/noder/unified.go @@ -116,6 +116,28 @@ func unified(noders []*noder) { } } + readBodies(target) + + // Check that nothing snuck past typechecking. + for _, n := range target.Decls { + if n.Typecheck() == 0 { + base.FatalfAt(n.Pos(), "missed typecheck: %v", n) + } + + // For functions, check that at least their first statement (if + // any) was typechecked too. + if fn, ok := n.(*ir.Func); ok && len(fn.Body) != 0 { + if stmt := fn.Body[0]; stmt.Typecheck() == 0 { + base.FatalfAt(stmt.Pos(), "missed typecheck: %v", stmt) + } + } + } + + base.ExitIfErrors() // just in case +} + +// readBodies reads in bodies for any +func readBodies(target *ir.Package) { // Don't use range--bodyIdx can add closures to todoBodies. for len(todoBodies) > 0 { // The order we expand bodies doesn't matter, so pop from the end @@ -134,24 +156,6 @@ func unified(noders []*noder) { } } todoBodies = nil - todoBodiesDone = true - - // Check that nothing snuck past typechecking. - for _, n := range target.Decls { - if n.Typecheck() == 0 { - base.FatalfAt(n.Pos(), "missed typecheck: %v", n) - } - - // For functions, check that at least their first statement (if - // any) was typechecked too. - if fn, ok := n.(*ir.Func); ok && len(fn.Body) != 0 { - if stmt := fn.Body[0]; stmt.Typecheck() == 0 { - base.FatalfAt(stmt.Pos(), "missed typecheck: %v", stmt) - } - } - } - - base.ExitIfErrors() // just in case } // writePkgStub type checks the given parsed source files, diff --git a/test/run.go b/test/run.go index fcd5d4875b2..e22efe49e5e 100644 --- a/test/run.go +++ b/test/run.go @@ -2043,7 +2043,6 @@ var unifiedFailures = setOf( "typeparam/typeswitch2.go", // duplicate case failure due to stenciling "typeparam/typeswitch3.go", // duplicate case failure due to stenciling "typeparam/typeswitch4.go", // duplicate case failure due to stenciling - "typeparam/issue50552.go", // gives missing method for instantiated type ) func setOf(keys ...string) map[string]bool { diff --git a/test/typeparam/issue49536.dir/a.go b/test/typeparam/issue49536.dir/a.go new file mode 100644 index 00000000000..a95ad60812c --- /dev/null +++ b/test/typeparam/issue49536.dir/a.go @@ -0,0 +1,12 @@ +// Copyright 2022 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 a + +func F() interface{} { return new(T[int]) } + +type T[P any] int + +func (x *T[P]) One() int { return x.Two() } +func (x *T[P]) Two() int { return 0 } diff --git a/test/typeparam/issue49536.dir/b.go b/test/typeparam/issue49536.dir/b.go new file mode 100644 index 00000000000..b08a77b9de1 --- /dev/null +++ b/test/typeparam/issue49536.dir/b.go @@ -0,0 +1,9 @@ +// Copyright 2022 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 b + +import "./a" + +var _ = a.F() diff --git a/test/typeparam/issue49536.go b/test/typeparam/issue49536.go new file mode 100644 index 00000000000..8bb5c3e2139 --- /dev/null +++ b/test/typeparam/issue49536.go @@ -0,0 +1,7 @@ +// compiledir + +// Copyright 2022 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 ignored From 82a65299050cb1146583c72350f841684256bb3c Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Sun, 6 Mar 2022 19:52:08 -0800 Subject: [PATCH 014/276] cmd/compile: remove unneeded type alias code in unified IR Before #46477, the Go generics proposal allowed `type T = U` where `U` was an uninstantiated generic type. However, we decided not to allow that, and go/types and types2 have already been updated to disallow it. This CL just removes the analogous code from unified IR. Change-Id: I0fe6d1754c96790b498c1d5185b948333646d7de Reviewed-on: https://go-review.googlesource.com/c/go/+/390315 Trust: Matthew Dempsky Run-TryBot: Matthew Dempsky TryBot-Result: Gopher Robot Reviewed-by: Cuong Manh Le --- src/cmd/compile/internal/noder/writer.go | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/src/cmd/compile/internal/noder/writer.go b/src/cmd/compile/internal/noder/writer.go index 59e9409b97d..59bce0730d4 100644 --- a/src/cmd/compile/internal/noder/writer.go +++ b/src/cmd/compile/internal/noder/writer.go @@ -284,10 +284,7 @@ func (pw *pkgWriter) typIdx(typ types2.Type, dict *writerDict) typeInfo { } case *types2.Named: - // Type aliases can refer to uninstantiated generic types, so we - // might see len(TParams) != 0 && len(TArgs) == 0 here. - // TODO(mdempsky): Revisit after #46477 is resolved. - assert(typ.TypeParams().Len() == typ.TypeArgs().Len() || typ.TypeArgs().Len() == 0) + assert(typ.TypeParams().Len() == typ.TypeArgs().Len()) // TODO(mdempsky): Why do we need to loop here? orig := typ @@ -1630,15 +1627,6 @@ func (w *writer) pkgDecl(decl syntax.Decl) { break } - // Skip aliases to uninstantiated generic types. - // TODO(mdempsky): Revisit after #46477 is resolved. - if name.IsAlias() { - named, ok := name.Type().(*types2.Named) - if ok && named.TypeParams().Len() != 0 && named.TypeArgs().Len() == 0 { - break - } - } - w.Code(declOther) w.pkgObjs(decl.Name) From 8893175c3b5267f1eb70c518b5de6f03037c4d03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Sun, 6 Mar 2022 11:26:11 +0000 Subject: [PATCH 015/276] flag: make tests silent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A few of the tests were printing garbage to stderr, since FlagSet's default Output is os.Stderr: $ go test flag provided but not defined: -x invalid value "1" for flag -v: test error Usage of test: flag needs an argument: -b Usage of test: -b usage PASS ok flag 0.008s Add the remaining SetOutput(io.Discard) method calls. Note that TestUserDefinedFunc was a tricky one. Even with the added SetOutput calls, the last part of the test would still print usage text to stderr. It took me a while to figure out the problem was copying FlagSet. I've filed go.dev/issue/51507 to record this particular sharp edge, and the test code now avoids making FlagSet copies to avoid the bug. Change-Id: I323f24091b98386312aa72df3eb890af6625628d Reviewed-on: https://go-review.googlesource.com/c/go/+/390234 Trust: Daniel Martí Run-TryBot: Daniel Martí TryBot-Result: Gopher Robot Reviewed-by: Ian Lance Taylor --- src/flag/export_test.go | 6 +++++- src/flag/flag_test.go | 9 ++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/flag/export_test.go b/src/flag/export_test.go index 838cfaf6a4c..9ef93ed6c5b 100644 --- a/src/flag/export_test.go +++ b/src/flag/export_test.go @@ -4,7 +4,10 @@ package flag -import "os" +import ( + "io" + "os" +) // Additional routines compiled into the package only during testing. @@ -15,6 +18,7 @@ var DefaultUsage = Usage // exit the program. func ResetForTesting(usage func()) { CommandLine = NewFlagSet(os.Args[0], ContinueOnError) + CommandLine.SetOutput(io.Discard) CommandLine.Usage = commandLineUsage Usage = usage } diff --git a/src/flag/flag_test.go b/src/flag/flag_test.go index 5835fcf22cd..d5c443d3c66 100644 --- a/src/flag/flag_test.go +++ b/src/flag/flag_test.go @@ -246,6 +246,7 @@ func (f *flagVar) Set(value string) error { func TestUserDefined(t *testing.T) { var flags FlagSet flags.Init("test", ContinueOnError) + flags.SetOutput(io.Discard) var v flagVar flags.Var(&v, "v", "usage") if err := flags.Parse([]string{"-v", "1", "-v", "2", "-v=3"}); err != nil { @@ -261,8 +262,8 @@ func TestUserDefined(t *testing.T) { } func TestUserDefinedFunc(t *testing.T) { - var flags FlagSet - flags.Init("test", ContinueOnError) + flags := NewFlagSet("test", ContinueOnError) + flags.SetOutput(io.Discard) var ss []string flags.Func("v", "usage", func(s string) error { ss = append(ss, s) @@ -286,7 +287,8 @@ func TestUserDefinedFunc(t *testing.T) { t.Errorf("usage string not included: %q", usage) } // test Func error - flags = *NewFlagSet("test", ContinueOnError) + flags = NewFlagSet("test", ContinueOnError) + flags.SetOutput(io.Discard) flags.Func("v", "usage", func(s string) error { return fmt.Errorf("test error") }) @@ -335,6 +337,7 @@ func (b *boolFlagVar) IsBoolFlag() bool { func TestUserDefinedBool(t *testing.T) { var flags FlagSet flags.Init("test", ContinueOnError) + flags.SetOutput(io.Discard) var b boolFlagVar var err error flags.Var(&b, "b", "usage") From 0e2f1abf5b764a4a3928a2f4f050144063c46a93 Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Sun, 6 Mar 2022 23:47:27 -0800 Subject: [PATCH 016/276] cmd/compile: represent derived types with ir.DynamicType in unified IR This CL switches unified IR to using ir.DynamicType for derived types. This has an immediate effect of fixing compilation of generic code that when fully stenciled results in statically invalid type assertions. This does require updating typecheck to expect ODYNAMICTYPE in type switches, but this is straightforward to implement. For now, we still statically resolve the runtime type (or itab) pointer. However, a subsequent CL will allow reading these pointers from the runtime dictionary. Change-Id: I1666678fcc588bc9cb8b97871bd02b9059848e6d Reviewed-on: https://go-review.googlesource.com/c/go/+/390336 Trust: Matthew Dempsky Run-TryBot: Matthew Dempsky TryBot-Result: Gopher Robot Reviewed-by: Cuong Manh Le --- src/cmd/compile/internal/noder/reader.go | 89 +++++++++++++++---- src/cmd/compile/internal/noder/writer.go | 45 +++++++++- .../compile/internal/reflectdata/reflect.go | 9 +- src/cmd/compile/internal/typecheck/stmt.go | 5 +- src/internal/pkgbits/sync.go | 1 + src/internal/pkgbits/syncmarker_string.go | 61 ++++++------- test/run.go | 5 -- 7 files changed, 155 insertions(+), 60 deletions(-) diff --git a/src/cmd/compile/internal/noder/reader.go b/src/cmd/compile/internal/noder/reader.go index 3207e3f85bd..5191dbe1778 100644 --- a/src/cmd/compile/internal/noder/reader.go +++ b/src/cmd/compile/internal/noder/reader.go @@ -1407,25 +1407,22 @@ func (r *reader) switchStmt(label *types.Sym) ir.Node { init := r.stmt() var tag ir.Node + var ident *ir.Ident + var iface *types.Type if r.Bool() { pos := r.pos() - var ident *ir.Ident if r.Bool() { pos := r.pos() sym := typecheck.Lookup(r.String()) ident = ir.NewIdent(pos, sym) } x := r.expr() + iface = x.Type() tag = ir.NewTypeSwitchGuard(pos, ident, x) } else { tag = r.expr() } - tswitch, ok := tag.(*ir.TypeSwitchGuard) - if ok && tswitch.Tag == nil { - tswitch = nil - } - clauses := make([]*ir.CaseClause, r.Len()) for i := range clauses { if i > 0 { @@ -1434,18 +1431,30 @@ func (r *reader) switchStmt(label *types.Sym) ir.Node { r.openScope() pos := r.pos() - cases := r.exprList() + var cases []ir.Node + if iface != nil { + cases = make([]ir.Node, r.Len()) + if len(cases) == 0 { + cases = nil // TODO(mdempsky): Unclear if this matters. + } + for i := range cases { + cases[i] = r.exprType(iface, true) + } + } else { + cases = r.exprList() + } clause := ir.NewCaseStmt(pos, cases, nil) - if tswitch != nil { + + if ident != nil { pos := r.pos() typ := r.typ() - name := ir.NewNameAt(pos, tswitch.Tag.Sym()) + name := ir.NewNameAt(pos, ident.Sym()) setType(name, typ) r.addLocal(name, ir.PAUTO) clause.Var = name - name.Defn = tswitch + name.Defn = tag } clause.Body = r.stmts() @@ -1529,10 +1538,7 @@ func (r *reader) expr() (res ir.Node) { return typecheck.Callee(r.obj()) case exprType: - // TODO(mdempsky): ir.TypeNode should probably return a typecheck'd node. - n := ir.TypeNode(r.typ()) - n.SetTypecheck(1) - return n + return r.exprType(nil, false) case exprConst: pos := r.pos() @@ -1552,6 +1558,15 @@ func (r *reader) expr() (res ir.Node) { x := r.expr() pos := r.pos() _, sym := r.selector() + + // Method expression with derived receiver type. + if x.Op() == ir.ODYNAMICTYPE { + // TODO(mdempsky): Handle with runtime dictionary lookup. + n := ir.TypeNode(x.Type()) + n.SetTypecheck(1) + x = n + } + n := typecheck.Expr(ir.NewSelectorExpr(pos, ir.OXDOT, x, sym)).(*ir.SelectorExpr) if n.Op() == ir.OMETHVALUE { wrapper := methodValueWrapper{ @@ -1588,8 +1603,12 @@ func (r *reader) expr() (res ir.Node) { case exprAssert: x := r.expr() pos := r.pos() - typ := r.expr().(ir.Ntype) - return typecheck.Expr(ir.NewTypeAssertExpr(pos, x, typ)) + typ := r.exprType(x.Type(), false) + + if typ, ok := typ.(*ir.DynamicType); ok && typ.Op() == ir.ODYNAMICTYPE { + return typed(typ.Type(), ir.NewDynamicTypeAssertExpr(pos, ir.ODYNAMICDOTTYPE, x, typ.X)) + } + return typecheck.Expr(ir.NewTypeAssertExpr(pos, x, typ.(ir.Ntype))) case exprUnaryOp: op := r.op() @@ -1734,6 +1753,44 @@ func (r *reader) exprs() []ir.Node { return nodes } +func (r *reader) exprType(iface *types.Type, nilOK bool) ir.Node { + if iface != nil { + base.Assertf(iface.IsInterface(), "%L must be an interface type", iface) + } + + r.Sync(pkgbits.SyncExprType) + + if nilOK && r.Bool() { + return typecheck.Expr(types.BuiltinPkg.Lookup("nil").Def.(*ir.NilExpr)) + } + + pos := r.pos() + info := r.typInfo() + typ := r.p.typIdx(info, r.dict, true) + + if info.derived { + // TODO(mdempsky): Handle with runtime dictionary lookup. + + var lsym *obj.LSym + + // For assertions from non-empty interfaces to non-interfaces, + // we need the ITab instead. + if iface != nil && !iface.IsEmptyInterface() && !typ.IsInterface() { + lsym = reflectdata.ITabLsym(typ, iface) + } else { + lsym = reflectdata.TypeLinksym(typ) + } + + ptr := typecheck.Expr(typecheck.NodAddr(ir.NewLinksymExpr(pos, lsym, types.Types[types.TUINT8]))) + return typed(typ, ir.NewDynamicType(pos, ptr)) + } + + // TODO(mdempsky): ir.TypeNode should probably return a typecheck'd node. + n := ir.TypeNode(typ) + n.SetTypecheck(1) + return n +} + func (r *reader) op() ir.Op { r.Sync(pkgbits.SyncOp) return ir.Op(r.Len()) diff --git a/src/cmd/compile/internal/noder/writer.go b/src/cmd/compile/internal/noder/writer.go index 59bce0730d4..821fae59e0b 100644 --- a/src/cmd/compile/internal/noder/writer.go +++ b/src/cmd/compile/internal/noder/writer.go @@ -1073,7 +1073,12 @@ func (w *writer) switchStmt(stmt *syntax.SwitchStmt) { w.pos(stmt) w.stmt(stmt.Init) + var iface types2.Type if guard, ok := stmt.Tag.(*syntax.TypeSwitchGuard); w.Bool(ok) { + tv, ok := w.p.info.Types[guard.X] + assert(ok && tv.IsValue()) + iface = tv.Type + w.pos(guard) if tag := guard.Lhs; w.Bool(tag != nil) { w.pos(tag) @@ -1092,7 +1097,16 @@ func (w *writer) switchStmt(stmt *syntax.SwitchStmt) { w.openScope(clause.Pos()) w.pos(clause) - w.exprList(clause.Cases) + + if iface != nil { + cases := unpackListExpr(clause.Cases) + w.Len(len(cases)) + for _, cas := range cases { + w.exprType(iface, cas, true) + } + } else { + w.exprList(clause.Cases) + } if obj, ok := w.p.info.Implicits[clause]; ok { // TODO(mdempsky): These pos details are quirkish, but also @@ -1152,13 +1166,13 @@ func (w *writer) expr(expr syntax.Expr) { if tv.IsType() { w.Code(exprType) - w.typ(tv.Type) + w.exprType(nil, expr, false) return } if tv.Value != nil { w.Code(exprConst) - w.pos(expr.Pos()) + w.pos(expr) w.typ(tv.Type) w.Value(tv.Value) @@ -1232,10 +1246,13 @@ func (w *writer) expr(expr syntax.Expr) { } case *syntax.AssertExpr: + tv, ok := w.p.info.Types[expr.X] + assert(ok && tv.IsValue()) + w.Code(exprAssert) w.expr(expr.X) w.pos(expr) - w.expr(expr.Type) + w.exprType(tv.Type, expr.Type, false) case *syntax.Operation: if expr.Y == nil { @@ -1370,6 +1387,26 @@ func (w *writer) exprs(exprs []syntax.Expr) { } } +func (w *writer) exprType(iface types2.Type, typ syntax.Expr, nilOK bool) { + if iface != nil { + _, ok := iface.Underlying().(*types2.Interface) + base.Assertf(ok, "%v must be an interface type", iface) + } + + tv, ok := w.p.info.Types[typ] + assert(ok) + + w.Sync(pkgbits.SyncExprType) + + if nilOK && w.Bool(tv.IsNil()) { + return + } + + assert(tv.IsType()) + w.pos(typ) + w.typ(tv.Type) +} + func (w *writer) op(op ir.Op) { // TODO(mdempsky): Remove in favor of explicit codes? Would make // export data more stable against internal refactorings, but low diff --git a/src/cmd/compile/internal/reflectdata/reflect.go b/src/cmd/compile/internal/reflectdata/reflect.go index ec217be4c35..896bbf660ea 100644 --- a/src/cmd/compile/internal/reflectdata/reflect.go +++ b/src/cmd/compile/internal/reflectdata/reflect.go @@ -1819,16 +1819,17 @@ func methodWrapper(rcvr *types.Type, method *types.Field, forItab bool) *obj.LSy newnam := ir.MethodSym(rcvr, method.Sym) lsym := newnam.Linksym() - if newnam.Siggen() { - return lsym - } - newnam.SetSiggen(true) // Unified IR creates its own wrappers. if base.Debug.Unified != 0 { return lsym } + if newnam.Siggen() { + return lsym + } + newnam.SetSiggen(true) + methodrcvr := method.Type.Recv().Type // For generic methods, we need to generate the wrapper even if the receiver // types are identical, because we want to add the dictionary. diff --git a/src/cmd/compile/internal/typecheck/stmt.go b/src/cmd/compile/internal/typecheck/stmt.go index 9a02c1752ca..f2660075073 100644 --- a/src/cmd/compile/internal/typecheck/stmt.go +++ b/src/cmd/compile/internal/typecheck/stmt.go @@ -615,6 +615,9 @@ func tcSwitchType(n *ir.SwitchStmt) { } continue } + if n1.Op() == ir.ODYNAMICTYPE { + continue + } if n1.Op() != ir.OTYPE { base.ErrorfAt(ncase.Pos(), "%L is not a type", n1) continue @@ -640,7 +643,7 @@ func tcSwitchType(n *ir.SwitchStmt) { // Assign the clause variable's type. vt := t if len(ls) == 1 { - if ls[0].Op() == ir.OTYPE { + if ls[0].Op() == ir.OTYPE || ls[0].Op() == ir.ODYNAMICTYPE { vt = ls[0].Type() } else if !ir.IsNil(ls[0]) { // Invalid single-type case; diff --git a/src/internal/pkgbits/sync.go b/src/internal/pkgbits/sync.go index b2c9139ce67..6eae306b223 100644 --- a/src/internal/pkgbits/sync.go +++ b/src/internal/pkgbits/sync.go @@ -92,6 +92,7 @@ const ( SyncExprList SyncExprs SyncExpr + SyncExprType SyncOp SyncFuncLit SyncCompLit diff --git a/src/internal/pkgbits/syncmarker_string.go b/src/internal/pkgbits/syncmarker_string.go index 91154a001d2..39db9eddad2 100644 --- a/src/internal/pkgbits/syncmarker_string.go +++ b/src/internal/pkgbits/syncmarker_string.go @@ -44,39 +44,40 @@ func _() { _ = x[SyncExprList-34] _ = x[SyncExprs-35] _ = x[SyncExpr-36] - _ = x[SyncOp-37] - _ = x[SyncFuncLit-38] - _ = x[SyncCompLit-39] - _ = x[SyncDecl-40] - _ = x[SyncFuncBody-41] - _ = x[SyncOpenScope-42] - _ = x[SyncCloseScope-43] - _ = x[SyncCloseAnotherScope-44] - _ = x[SyncDeclNames-45] - _ = x[SyncDeclName-46] - _ = x[SyncStmts-47] - _ = x[SyncBlockStmt-48] - _ = x[SyncIfStmt-49] - _ = x[SyncForStmt-50] - _ = x[SyncSwitchStmt-51] - _ = x[SyncRangeStmt-52] - _ = x[SyncCaseClause-53] - _ = x[SyncCommClause-54] - _ = x[SyncSelectStmt-55] - _ = x[SyncDecls-56] - _ = x[SyncLabeledStmt-57] - _ = x[SyncUseObjLocal-58] - _ = x[SyncAddLocal-59] - _ = x[SyncLinkname-60] - _ = x[SyncStmt1-61] - _ = x[SyncStmtsEnd-62] - _ = x[SyncLabel-63] - _ = x[SyncOptLabel-64] + _ = x[SyncExprType-37] + _ = x[SyncOp-38] + _ = x[SyncFuncLit-39] + _ = x[SyncCompLit-40] + _ = x[SyncDecl-41] + _ = x[SyncFuncBody-42] + _ = x[SyncOpenScope-43] + _ = x[SyncCloseScope-44] + _ = x[SyncCloseAnotherScope-45] + _ = x[SyncDeclNames-46] + _ = x[SyncDeclName-47] + _ = x[SyncStmts-48] + _ = x[SyncBlockStmt-49] + _ = x[SyncIfStmt-50] + _ = x[SyncForStmt-51] + _ = x[SyncSwitchStmt-52] + _ = x[SyncRangeStmt-53] + _ = x[SyncCaseClause-54] + _ = x[SyncCommClause-55] + _ = x[SyncSelectStmt-56] + _ = x[SyncDecls-57] + _ = x[SyncLabeledStmt-58] + _ = x[SyncUseObjLocal-59] + _ = x[SyncAddLocal-60] + _ = x[SyncLinkname-61] + _ = x[SyncStmt1-62] + _ = x[SyncStmtsEnd-63] + _ = x[SyncLabel-64] + _ = x[SyncOptLabel-65] } -const _SyncMarker_name = "EOFBoolInt64Uint64StringValueValRelocsRelocUseRelocPublicPosPosBaseObjectObject1PkgPkgDefMethodTypeTypeIdxTypeParamNamesSignatureParamsParamCodeObjSymLocalIdentSelectorPrivateFuncExtVarExtTypeExtPragmaExprListExprsExprOpFuncLitCompLitDeclFuncBodyOpenScopeCloseScopeCloseAnotherScopeDeclNamesDeclNameStmtsBlockStmtIfStmtForStmtSwitchStmtRangeStmtCaseClauseCommClauseSelectStmtDeclsLabeledStmtUseObjLocalAddLocalLinknameStmt1StmtsEndLabelOptLabel" +const _SyncMarker_name = "EOFBoolInt64Uint64StringValueValRelocsRelocUseRelocPublicPosPosBaseObjectObject1PkgPkgDefMethodTypeTypeIdxTypeParamNamesSignatureParamsParamCodeObjSymLocalIdentSelectorPrivateFuncExtVarExtTypeExtPragmaExprListExprsExprAssertTypeOpFuncLitCompLitDeclFuncBodyOpenScopeCloseScopeCloseAnotherScopeDeclNamesDeclNameStmtsBlockStmtIfStmtForStmtSwitchStmtRangeStmtCaseClauseCommClauseSelectStmtDeclsLabeledStmtUseObjLocalAddLocalLinknameStmt1StmtsEndLabelOptLabel" -var _SyncMarker_index = [...]uint16{0, 3, 7, 12, 18, 24, 29, 32, 38, 43, 51, 57, 60, 67, 73, 80, 83, 89, 95, 99, 106, 120, 129, 135, 140, 147, 150, 160, 168, 175, 182, 188, 195, 201, 209, 214, 218, 220, 227, 234, 238, 246, 255, 265, 282, 291, 299, 304, 313, 319, 326, 336, 345, 355, 365, 375, 380, 391, 402, 410, 418, 423, 431, 436, 444} +var _SyncMarker_index = [...]uint16{0, 3, 7, 12, 18, 24, 29, 32, 38, 43, 51, 57, 60, 67, 73, 80, 83, 89, 95, 99, 106, 120, 129, 135, 140, 147, 150, 160, 168, 175, 182, 188, 195, 201, 209, 214, 218, 228, 230, 237, 244, 248, 256, 265, 275, 292, 301, 309, 314, 323, 329, 336, 346, 355, 365, 375, 385, 390, 401, 412, 420, 428, 433, 441, 446, 454} func (i SyncMarker) String() string { i -= 1 diff --git a/test/run.go b/test/run.go index e22efe49e5e..6339095d954 100644 --- a/test/run.go +++ b/test/run.go @@ -2038,11 +2038,6 @@ var unifiedFailures = setOf( "fixedbugs/issue42058b.go", // unified IR doesn't report channel element too large "fixedbugs/issue49767.go", // unified IR doesn't report channel element too large "fixedbugs/issue49814.go", // unified IR doesn't report array type too large - "typeparam/issue50002.go", // pure stenciling leads to a static type assertion error - "typeparam/typeswitch1.go", // duplicate case failure due to stenciling - "typeparam/typeswitch2.go", // duplicate case failure due to stenciling - "typeparam/typeswitch3.go", // duplicate case failure due to stenciling - "typeparam/typeswitch4.go", // duplicate case failure due to stenciling ) func setOf(keys ...string) map[string]bool { From d168c4f29682e032a14bb8f5ca23af08a6834635 Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Mon, 7 Mar 2022 02:27:35 -0800 Subject: [PATCH 017/276] test: additional generic type switch test coverage None of the current generic type switch test cases exercise type switches where the instantiated case is an interface type. Change-Id: I9272fa61b8dde1fe1a3702d524d4f40253ef19b2 Reviewed-on: https://go-review.googlesource.com/c/go/+/390354 Trust: Matthew Dempsky Run-TryBot: Matthew Dempsky TryBot-Result: Gopher Robot Reviewed-by: Cuong Manh Le --- test/typeparam/typeswitch1.go | 2 ++ test/typeparam/typeswitch1.out | 2 ++ test/typeparam/typeswitch2.go | 14 ++++++++------ test/typeparam/typeswitch2.out | 6 ++++-- test/typeparam/typeswitch3.go | 8 ++++++++ test/typeparam/typeswitch3.out | 3 +++ test/typeparam/typeswitch4.go | 8 ++++++++ test/typeparam/typeswitch4.out | 3 +++ 8 files changed, 38 insertions(+), 8 deletions(-) diff --git a/test/typeparam/typeswitch1.go b/test/typeparam/typeswitch1.go index e971779982e..a0468d378fb 100644 --- a/test/typeparam/typeswitch1.go +++ b/test/typeparam/typeswitch1.go @@ -28,4 +28,6 @@ func main() { f[float64](int8(9)) f[int32](int32(7)) f[int](int32(7)) + f[any](int(10)) + f[interface{ M() }](int(11)) } diff --git a/test/typeparam/typeswitch1.out b/test/typeparam/typeswitch1.out index dc5dfdb7611..6b8a33c3457 100644 --- a/test/typeparam/typeswitch1.out +++ b/test/typeparam/typeswitch1.out @@ -5,3 +5,5 @@ struct{T,T} other T int32/int16 +T +int diff --git a/test/typeparam/typeswitch2.go b/test/typeparam/typeswitch2.go index b2496fd1c4a..286002a8302 100644 --- a/test/typeparam/typeswitch2.go +++ b/test/typeparam/typeswitch2.go @@ -6,20 +6,20 @@ package main -import "reflect" +import "fmt" func f[T any](i interface{}) { switch x := i.(type) { case T: - println("T", x) + fmt.Println("T", x) case int: - println("int", x) + fmt.Println("int", x) case int32, int16: - println("int32/int16", reflect.ValueOf(x).Int()) + fmt.Println("int32/int16", x) case struct{ a, b T }: - println("struct{T,T}", x.a, x.b) + fmt.Println("struct{T,T}", x.a, x.b) default: - println("other", reflect.ValueOf(x).Int()) + fmt.Println("other", x) } } func main() { @@ -30,4 +30,6 @@ func main() { f[float64](int8(9)) f[int32](int32(7)) f[int](int32(7)) + f[any](int(10)) + f[interface{ M() }](int(11)) } diff --git a/test/typeparam/typeswitch2.out b/test/typeparam/typeswitch2.out index 85b54e38aeb..6d4df54124c 100644 --- a/test/typeparam/typeswitch2.out +++ b/test/typeparam/typeswitch2.out @@ -1,7 +1,9 @@ -T +6.000000e+000 +T 6 int 7 int32/int16 8 -struct{T,T} +1.000000e+000 +2.000000e+000 +struct{T,T} 1 2 other 9 T 7 int32/int16 7 +T 10 +int 11 diff --git a/test/typeparam/typeswitch3.go b/test/typeparam/typeswitch3.go index 83d81f37d03..b84fdd02eaa 100644 --- a/test/typeparam/typeswitch3.go +++ b/test/typeparam/typeswitch3.go @@ -7,6 +7,10 @@ package main type I interface{ foo() int } +type J interface { + I + bar() +} type myint int @@ -19,6 +23,7 @@ func (x myfloat) foo() int { return int(x) } type myint32 int32 func (x myint32) foo() int { return int(x) } +func (x myint32) bar() {} func f[T I](i I) { switch x := i.(type) { @@ -37,4 +42,7 @@ func main() { f[myint32](myint32(8)) f[myint32](myfloat(7)) f[myint](myint32(9)) + f[I](myint(10)) + f[J](myint(11)) + f[J](myint32(12)) } diff --git a/test/typeparam/typeswitch3.out b/test/typeparam/typeswitch3.out index ed59987e6d9..05ed5331973 100644 --- a/test/typeparam/typeswitch3.out +++ b/test/typeparam/typeswitch3.out @@ -4,3 +4,6 @@ other 8 T 8 other 7 other 9 +T 10 +myint 11 +T 12 diff --git a/test/typeparam/typeswitch4.go b/test/typeparam/typeswitch4.go index 43a6fc12fc1..3fdf5527202 100644 --- a/test/typeparam/typeswitch4.go +++ b/test/typeparam/typeswitch4.go @@ -7,6 +7,10 @@ package main type I interface{ foo() int } +type J interface { + I + bar() +} type myint int @@ -19,6 +23,7 @@ func (x myfloat) foo() int { return int(x) } type myint32 int32 func (x myint32) foo() int { return int(x) } +func (x myint32) bar() {} func f[T I](i I) { switch x := i.(type) { @@ -35,4 +40,7 @@ func main() { f[myint32](myint32(9)) f[myint](myint32(10)) f[myint](myfloat(42)) + f[I](myint(10)) + f[J](myint(11)) + f[J](myint32(12)) } diff --git a/test/typeparam/typeswitch4.out b/test/typeparam/typeswitch4.out index d6121d077c0..b98f0743c2e 100644 --- a/test/typeparam/typeswitch4.out +++ b/test/typeparam/typeswitch4.out @@ -4,3 +4,6 @@ T/myint32 8 T/myint32 9 T/myint32 10 other 42 +T/myint32 10 +other 11 +T/myint32 12 From ac3ba9790762113bbc4ce1e8068654ce9579d3d6 Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Mon, 7 Mar 2022 03:35:14 -0800 Subject: [PATCH 018/276] cmd/compile: add itabs to unified IR dictionaries This CL changes unified IR to include itabs in its serialized dictionary format. Change-Id: I334c972dc1bc19293f955bb23cfb66844da7adec Reviewed-on: https://go-review.googlesource.com/c/go/+/390355 Trust: Matthew Dempsky Run-TryBot: Matthew Dempsky TryBot-Result: Gopher Robot Reviewed-by: Cuong Manh Le --- src/cmd/compile/internal/noder/reader.go | 68 +++++++++++++++--------- src/cmd/compile/internal/noder/writer.go | 55 +++++++++++++++++-- 2 files changed, 93 insertions(+), 30 deletions(-) diff --git a/src/cmd/compile/internal/noder/reader.go b/src/cmd/compile/internal/noder/reader.go index 5191dbe1778..2b8134a02c5 100644 --- a/src/cmd/compile/internal/noder/reader.go +++ b/src/cmd/compile/internal/noder/reader.go @@ -147,6 +147,13 @@ type readerDict struct { funcs []objInfo funcsObj []ir.Node + + itabs []itabInfo2 +} + +type itabInfo2 struct { + typ *types.Type + lsym *obj.LSym } func setType(n ir.Node, typ *types.Type) { @@ -745,6 +752,22 @@ func (pr *pkgReader) objDictIdx(sym *types.Sym, idx int, implicits, explicits [] dict.funcs[i] = objInfo{idx: objIdx, explicits: targs} } + dict.itabs = make([]itabInfo2, r.Len()) + for i := range dict.itabs { + typ := pr.typIdx(typeInfo{idx: r.Len(), derived: true}, &dict, true) + ifaceInfo := r.typInfo() + + var lsym *obj.LSym + if typ.IsInterface() { + lsym = reflectdata.TypeLinksym(typ) + } else { + iface := pr.typIdx(ifaceInfo, &dict, true) + lsym = reflectdata.ITabLsym(typ, iface) + } + + dict.itabs[i] = itabInfo2{typ: typ, lsym: lsym} + } + return &dict } @@ -1438,7 +1461,7 @@ func (r *reader) switchStmt(label *types.Sym) ir.Node { cases = nil // TODO(mdempsky): Unclear if this matters. } for i := range cases { - cases[i] = r.exprType(iface, true) + cases[i] = r.exprType(true) } } else { cases = r.exprList() @@ -1538,7 +1561,7 @@ func (r *reader) expr() (res ir.Node) { return typecheck.Callee(r.obj()) case exprType: - return r.exprType(nil, false) + return r.exprType(false) case exprConst: pos := r.pos() @@ -1603,7 +1626,7 @@ func (r *reader) expr() (res ir.Node) { case exprAssert: x := r.expr() pos := r.pos() - typ := r.exprType(x.Type(), false) + typ := r.exprType(false) if typ, ok := typ.(*ir.DynamicType); ok && typ.Op() == ir.ODYNAMICTYPE { return typed(typ.Type(), ir.NewDynamicTypeAssertExpr(pos, ir.ODYNAMICDOTTYPE, x, typ.X)) @@ -1753,11 +1776,7 @@ func (r *reader) exprs() []ir.Node { return nodes } -func (r *reader) exprType(iface *types.Type, nilOK bool) ir.Node { - if iface != nil { - base.Assertf(iface.IsInterface(), "%L must be an interface type", iface) - } - +func (r *reader) exprType(nilOK bool) ir.Node { r.Sync(pkgbits.SyncExprType) if nilOK && r.Bool() { @@ -1765,30 +1784,29 @@ func (r *reader) exprType(iface *types.Type, nilOK bool) ir.Node { } pos := r.pos() - info := r.typInfo() - typ := r.p.typIdx(info, r.dict, true) - if info.derived { - // TODO(mdempsky): Handle with runtime dictionary lookup. + var typ *types.Type + var lsym *obj.LSym - var lsym *obj.LSym + if r.Bool() { + itab := r.dict.itabs[r.Len()] + typ, lsym = itab.typ, itab.lsym + } else { + info := r.typInfo() + typ = r.p.typIdx(info, r.dict, true) - // For assertions from non-empty interfaces to non-interfaces, - // we need the ITab instead. - if iface != nil && !iface.IsEmptyInterface() && !typ.IsInterface() { - lsym = reflectdata.ITabLsym(typ, iface) - } else { - lsym = reflectdata.TypeLinksym(typ) + if !info.derived { + // TODO(mdempsky): ir.TypeNode should probably return a typecheck'd node. + n := ir.TypeNode(typ) + n.SetTypecheck(1) + return n } - ptr := typecheck.Expr(typecheck.NodAddr(ir.NewLinksymExpr(pos, lsym, types.Types[types.TUINT8]))) - return typed(typ, ir.NewDynamicType(pos, ptr)) + lsym = reflectdata.TypeLinksym(typ) } - // TODO(mdempsky): ir.TypeNode should probably return a typecheck'd node. - n := ir.TypeNode(typ) - n.SetTypecheck(1) - return n + ptr := typecheck.Expr(typecheck.NodAddr(ir.NewLinksymExpr(pos, lsym, types.Types[types.TUINT8]))) + return typed(typ, ir.NewDynamicType(pos, ptr)) } func (r *reader) op() ir.Op { diff --git a/src/cmd/compile/internal/noder/writer.go b/src/cmd/compile/internal/noder/writer.go index 821fae59e0b..c5c346b7842 100644 --- a/src/cmd/compile/internal/noder/writer.go +++ b/src/cmd/compile/internal/noder/writer.go @@ -103,6 +103,10 @@ type writerDict struct { // instantiated with derived types (i.e., that require // sub-dictionaries when called at run time). funcs []objInfo + + // itabs lists itabs that are needed for dynamic type assertions + // (including type switches). + itabs []itabInfo } type derivedInfo struct { @@ -120,6 +124,11 @@ type objInfo struct { explicits []typeInfo // info for the type arguments } +type itabInfo struct { + typIdx int // always a derived type index + iface typeInfo // always a non-empty interface type +} + func (info objInfo) anyDerived() bool { for _, explicit := range info.explicits { if explicit.derived { @@ -633,6 +642,13 @@ func (w *writer) objDict(obj types2.Object, dict *writerDict) { } } + nitabs := len(dict.itabs) + w.Len(nitabs) + for _, itab := range dict.itabs { + w.Len(itab.typIdx) + w.typInfo(itab.iface) + } + assert(len(dict.derived) == nderived) assert(len(dict.funcs) == nfuncs) } @@ -1388,10 +1404,7 @@ func (w *writer) exprs(exprs []syntax.Expr) { } func (w *writer) exprType(iface types2.Type, typ syntax.Expr, nilOK bool) { - if iface != nil { - _, ok := iface.Underlying().(*types2.Interface) - base.Assertf(ok, "%v must be an interface type", iface) - } + base.Assertf(iface == nil || isInterface(iface), "%v must be nil or an interface type", iface) tv, ok := w.p.info.Types[typ] assert(ok) @@ -1403,8 +1416,40 @@ func (w *writer) exprType(iface types2.Type, typ syntax.Expr, nilOK bool) { } assert(tv.IsType()) + info := w.p.typIdx(tv.Type, w.dict) + w.pos(typ) - w.typ(tv.Type) + + if w.Bool(info.derived && iface != nil && !iface.Underlying().(*types2.Interface).Empty()) { + ifaceInfo := w.p.typIdx(iface, w.dict) + + idx := -1 + for i, itab := range w.dict.itabs { + if itab.typIdx == info.idx && itab.iface == ifaceInfo { + idx = i + } + } + if idx < 0 { + idx = len(w.dict.itabs) + w.dict.itabs = append(w.dict.itabs, itabInfo{typIdx: info.idx, iface: ifaceInfo}) + } + w.Len(idx) + return + } + + w.typInfo(info) +} + +func isInterface(typ types2.Type) bool { + if _, ok := typ.(*types2.TypeParam); ok { + // typ is a type parameter and may be instantiated as either a + // concrete or interface type, so the writer can't depend on + // knowing this. + base.Fatalf("%v is a type parameter", typ) + } + + _, ok := typ.Underlying().(*types2.Interface) + return ok } func (w *writer) op(op ir.Op) { From d1820f748f8d63da8ef602e53d1db224f072be8f Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Mon, 7 Mar 2022 05:43:40 -0800 Subject: [PATCH 019/276] test: add test case for #51521 The test case is already working with unified IR, so add it to make sure we don't regress while finishing unified IR's support for dictionaries. Updates #51521. Change-Id: Ib7c8bf9612d30cd552e8e631fd0d487dcb177f14 Reviewed-on: https://go-review.googlesource.com/c/go/+/390356 Trust: Matthew Dempsky Run-TryBot: Matthew Dempsky TryBot-Result: Gopher Robot Reviewed-by: Cuong Manh Le --- test/run.go | 3 ++- test/typeparam/issue51521.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 test/typeparam/issue51521.go diff --git a/test/run.go b/test/run.go index 6339095d954..869911a4265 100644 --- a/test/run.go +++ b/test/run.go @@ -1999,7 +1999,8 @@ var types2Failures32Bit = setOf( ) var g3Failures = setOf( - "typeparam/nested.go", // -G=3 doesn't support function-local types with generics + "typeparam/nested.go", // -G=3 doesn't support function-local types with generics + "typeparam/issue51521.go", // -G=3 produces bad panic message and link error ) // In all of these cases, -G=0 reports reasonable errors, but either -G=0 or types2 diff --git a/test/typeparam/issue51521.go b/test/typeparam/issue51521.go new file mode 100644 index 00000000000..5eb4e35c185 --- /dev/null +++ b/test/typeparam/issue51521.go @@ -0,0 +1,30 @@ +// run + +// Copyright 2022 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 main + +import ( + "fmt" + "strings" +) + +type I interface{ M() } + +func F[P I](p P) { defer catch(); p.M() } +func G[T any]() { defer catch(); interface{ M() T }.M(nil) } + +func main() { + F[I](nil) + G[int]() +} + +func catch() { + err := recover() + if err, ok := err.(error); ok && strings.Contains(err.Error(), "nil pointer dereference") { + return + } + fmt.Println("FAIL", err) +} From 63bd6f68e6cbb237b46a99775103758afaee370a Mon Sep 17 00:00:00 2001 From: Roland Shoemaker Date: Sat, 5 Mar 2022 08:47:33 -0800 Subject: [PATCH 020/276] internal/fuzz: fix TestUnmarshalMarshal on MIPS Previous value used in the float32 roundtrip used float32(math.NaN())-1 which caused the quiet/signal bit to flip, which seemed to break the test on MIPS platforms. Instead switch to using float32(math.NaN())+1, which preserves the bit and makes the test happy. Possibly related to #37455 Fixes #51258 Change-Id: Ia85c649e89a5d02027c0ec197f0ff318aa819c19 Reviewed-on: https://go-review.googlesource.com/c/go/+/390214 Trust: Dmitri Shuralyov Reviewed-by: Bryan Mills Trust: Roland Shoemaker Run-TryBot: Roland Shoemaker TryBot-Result: Gopher Robot --- src/internal/fuzz/encoding_test.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/internal/fuzz/encoding_test.go b/src/internal/fuzz/encoding_test.go index 4b55892acda..3a614f5bd2a 100644 --- a/src/internal/fuzz/encoding_test.go +++ b/src/internal/fuzz/encoding_test.go @@ -104,6 +104,12 @@ float32(2.5)`, ok: true, }, { + // The two IEEE 754 bit patterns used for the math.Float{64,32}frombits + // encodings are non-math.NAN quiet-NaN values. Since they are not equal + // to math.NaN(), they should be re-encoded to their bit patterns. They + // are, respectively: + // * math.Float64bits(math.NaN())+1 + // * math.Float32bits(float32(math.NaN()))+1 in: `go test fuzz v1 float32(-0) float64(-0) @@ -113,8 +119,8 @@ float32(NaN) float64(+Inf) float64(-Inf) float64(NaN) -math.Float64frombits(9221120237041090560) -math.Float32frombits(2143289343)`, +math.Float64frombits(9221120237041090562) +math.Float32frombits(2143289345)`, ok: true, }, } From cc9d3f548a0265124766dfdb45e77cf05579219d Mon Sep 17 00:00:00 2001 From: Michael Pratt Date: Fri, 4 Mar 2022 11:17:43 -0500 Subject: [PATCH 021/276] runtime: print goid when throwing in gentraceback This makes it easier to figure out where the crash is occurring. Change-Id: Ie1f78a360367090dcd61c61b2a55c34f3e2ff2eb Reviewed-on: https://go-review.googlesource.com/c/go/+/390034 Trust: David Chase Reviewed-by: David Chase Trust: Michael Pratt Run-TryBot: Michael Pratt TryBot-Result: Gopher Robot Reviewed-by: Cherry Mui --- src/runtime/crash_test.go | 2 +- src/runtime/traceback.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/runtime/crash_test.go b/src/runtime/crash_test.go index 9b9ab4f3e1b..d8cabcdda28 100644 --- a/src/runtime/crash_test.go +++ b/src/runtime/crash_test.go @@ -665,7 +665,7 @@ retry: func TestBadTraceback(t *testing.T) { output := runTestProg(t, "testprog", "BadTraceback") for _, want := range []string{ - "runtime: unexpected return pc", + "unexpected return pc", "called from 0xbad", "00000bad", // Smashed LR in hex dump " Date: Mon, 7 Mar 2022 08:54:28 -0800 Subject: [PATCH 022/276] cmd/compile: remove duplicate const logic from typecheck Now that we always use types2 to validate user source code, we can remove the constSet logic from typecheck for detecting duplicate expression switch cases and duplicate map literal keys. This logic is redundant with types2, and currently causes unified IR to report inappropriate duplicate constant errors that only appear after type substitution. Updates #42758. Change-Id: I51ee2c5106eec9abf40eba2480dc52603c68ba21 Reviewed-on: https://go-review.googlesource.com/c/go/+/390474 Trust: Matthew Dempsky Run-TryBot: Matthew Dempsky TryBot-Result: Gopher Robot Reviewed-by: Robert Griesemer --- src/cmd/compile/internal/noder/reader.go | 6 -- src/cmd/compile/internal/typecheck/const.go | 89 --------------------- src/cmd/compile/internal/typecheck/expr.go | 2 - src/cmd/compile/internal/typecheck/stmt.go | 11 --- test/typeparam/issue42758.go | 19 +++++ 5 files changed, 19 insertions(+), 108 deletions(-) create mode 100644 test/typeparam/issue42758.go diff --git a/src/cmd/compile/internal/noder/reader.go b/src/cmd/compile/internal/noder/reader.go index 2b8134a02c5..004630236d6 100644 --- a/src/cmd/compile/internal/noder/reader.go +++ b/src/cmd/compile/internal/noder/reader.go @@ -26,12 +26,6 @@ import ( "cmd/internal/src" ) -// TODO(mdempsky): Suppress duplicate type/const errors that can arise -// during typecheck due to naive type substitution (e.g., see #42758). -// I anticipate these will be handled as a consequence of adding -// dictionaries support, so it's probably not important to focus on -// this until after that's done. - type pkgReader struct { pkgbits.PkgDecoder diff --git a/src/cmd/compile/internal/typecheck/const.go b/src/cmd/compile/internal/typecheck/const.go index fbe7c02c498..3be3b8059f7 100644 --- a/src/cmd/compile/internal/typecheck/const.go +++ b/src/cmd/compile/internal/typecheck/const.go @@ -16,7 +16,6 @@ import ( "cmd/compile/internal/base" "cmd/compile/internal/ir" "cmd/compile/internal/types" - "cmd/internal/src" ) func roundFloat(v constant.Value, sz int64) constant.Value { @@ -773,94 +772,6 @@ func anyCallOrChan(n ir.Node) bool { }) } -// A constSet represents a set of Go constant expressions. -type constSet struct { - m map[constSetKey]src.XPos -} - -type constSetKey struct { - typ *types.Type - val interface{} -} - -// add adds constant expression n to s. If a constant expression of -// equal value and identical type has already been added, then add -// reports an error about the duplicate value. -// -// pos provides position information for where expression n occurred -// (in case n does not have its own position information). what and -// where are used in the error message. -// -// n must not be an untyped constant. -func (s *constSet) add(pos src.XPos, n ir.Node, what, where string) { - if conv := n; conv.Op() == ir.OCONVIFACE { - conv := conv.(*ir.ConvExpr) - if conv.Implicit() { - n = conv.X - } - } - - if !ir.IsConstNode(n) || n.Type() == nil { - return - } - if n.Type().IsUntyped() { - base.Fatalf("%v is untyped", n) - } - - // Consts are only duplicates if they have the same value and - // identical types. - // - // In general, we have to use types.Identical to test type - // identity, because == gives false negatives for anonymous - // types and the byte/uint8 and rune/int32 builtin type - // aliases. However, this is not a problem here, because - // constant expressions are always untyped or have a named - // type, and we explicitly handle the builtin type aliases - // below. - // - // This approach may need to be revisited though if we fix - // #21866 by treating all type aliases like byte/uint8 and - // rune/int32. - - typ := n.Type() - switch typ { - case types.ByteType: - typ = types.Types[types.TUINT8] - case types.RuneType: - typ = types.Types[types.TINT32] - } - k := constSetKey{typ, ir.ConstValue(n)} - - if ir.HasUniquePos(n) { - pos = n.Pos() - } - - if s.m == nil { - s.m = make(map[constSetKey]src.XPos) - } - - if prevPos, isDup := s.m[k]; isDup { - base.ErrorfAt(pos, "duplicate %s %s in %s\n\tprevious %s at %v", - what, nodeAndVal(n), where, - what, base.FmtPos(prevPos)) - } else { - s.m[k] = pos - } -} - -// nodeAndVal reports both an expression and its constant value, if -// the latter is non-obvious. -// -// TODO(mdempsky): This could probably be a fmt.go flag. -func nodeAndVal(n ir.Node) string { - show := fmt.Sprint(n) - val := ir.ConstValue(n) - if s := fmt.Sprintf("%#v", val); show != s { - show += " (value " + s + ")" - } - return show -} - // evalunsafe evaluates a package unsafe operation and returns the result. func evalunsafe(n ir.Node) int64 { switch n.Op() { diff --git a/src/cmd/compile/internal/typecheck/expr.go b/src/cmd/compile/internal/typecheck/expr.go index 0fe8f916965..e2b95b27c6a 100644 --- a/src/cmd/compile/internal/typecheck/expr.go +++ b/src/cmd/compile/internal/typecheck/expr.go @@ -245,7 +245,6 @@ func tcCompLit(n *ir.CompLitExpr) (res ir.Node) { n.Len = length case types.TMAP: - var cs constSet for i3, l := range n.List { ir.SetPos(l) if l.Op() != ir.OKEY { @@ -259,7 +258,6 @@ func tcCompLit(n *ir.CompLitExpr) (res ir.Node) { r = pushtype(r, t.Key()) r = Expr(r) l.Key = AssignConv(r, t.Key(), "map key") - cs.add(base.Pos, l.Key, "key", "map literal") r = l.Value r = pushtype(r, t.Elem()) diff --git a/src/cmd/compile/internal/typecheck/stmt.go b/src/cmd/compile/internal/typecheck/stmt.go index f2660075073..b2fba315e75 100644 --- a/src/cmd/compile/internal/typecheck/stmt.go +++ b/src/cmd/compile/internal/typecheck/stmt.go @@ -519,7 +519,6 @@ func tcSwitchExpr(n *ir.SwitchStmt) { } var defCase ir.Node - var cs constSet for _, ncase := range n.Cases { ls := ncase.List if len(ls) == 0 { // default: @@ -554,16 +553,6 @@ func tcSwitchExpr(n *ir.SwitchStmt) { } } } - - // Don't check for duplicate bools. Although the spec allows it, - // (1) the compiler hasn't checked it in the past, so compatibility mandates it, and - // (2) it would disallow useful things like - // case GOARCH == "arm" && GOARM == "5": - // case GOARCH == "arm": - // which would both evaluate to false for non-ARM compiles. - if !n1.Type().IsBoolean() { - cs.add(ncase.Pos(), n1, "case", "switch") - } } Stmts(ncase.Body) diff --git a/test/typeparam/issue42758.go b/test/typeparam/issue42758.go new file mode 100644 index 00000000000..25fb85ffb6d --- /dev/null +++ b/test/typeparam/issue42758.go @@ -0,0 +1,19 @@ +// run + +// Copyright 2022 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 main + +func F[T, U int]() interface{} { + switch interface{}(nil) { + case int(0), T(0), U(0): + } + + return map[interface{}]int{int(0): 0, T(0): 0, U(0): 0} +} + +func main() { + F[int, int]() +} From 7dc6c5ec34ca6780e8eac1760116ff69d0c27d7a Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Fri, 4 Mar 2022 15:07:17 -0800 Subject: [PATCH 023/276] go/types, types2: correctly include comparable in type set intersection The comparable bit was handled incorrectly. This CL establishes a clear invariant for a type set's terms and its comparable bit and correctly uses the bit when computing term intersections. Relevant changes: - Introduce a new function intersectTermLists that does the correct intersection computation. Minor: - Moved the comparable bit after terms in _TypeSet to make it clearer that they belong together. - Simplify and clarify _TypeSet.IsAll predicate. - Remove the IsTypeSet predicate which was only used for error reporting in union.go, and use the existing predicates instead. - Rename/introduce local variables in computeInterfaceTypeSet for consistency and to avoid confusion. - Update some tests whose output has changed because the comparable bit is now only set if we have have the set of all types. For instance, for interface{comparable; int} the type set doesn't set the comparable bit because the intersection of comparable and int is just int; etc. - Add many more comments to make the code clearer. Fixes #51472. Change-Id: I8a5661eb1693a41a17ce5f70d7e10774301f38ab Reviewed-on: https://go-review.googlesource.com/c/go/+/390025 Trust: Robert Griesemer Run-TryBot: Robert Griesemer Reviewed-by: Robert Findley TryBot-Result: Gopher Robot --- .../types2/testdata/fixedbugs/issue41124.go2 | 10 +-- .../types2/testdata/fixedbugs/issue51472.go2 | 54 ++++++++++++ src/cmd/compile/internal/types2/typeset.go | 87 +++++++++++++------ .../compile/internal/types2/typeset_test.go | 10 +-- src/cmd/compile/internal/types2/union.go | 18 ++-- src/cmd/compile/internal/types2/universe.go | 2 +- .../types/testdata/fixedbugs/issue41124.go2 | 10 +-- .../types/testdata/fixedbugs/issue51472.go2 | 54 ++++++++++++ src/go/types/typeset.go | 85 ++++++++++++------ src/go/types/typeset_test.go | 10 +-- src/go/types/union.go | 18 ++-- src/go/types/universe.go | 2 +- 12 files changed, 268 insertions(+), 92 deletions(-) create mode 100644 src/cmd/compile/internal/types2/testdata/fixedbugs/issue51472.go2 create mode 100644 src/go/types/testdata/fixedbugs/issue51472.go2 diff --git a/src/cmd/compile/internal/types2/testdata/fixedbugs/issue41124.go2 b/src/cmd/compile/internal/types2/testdata/fixedbugs/issue41124.go2 index 7f55ba85a6b..4550dd732c1 100644 --- a/src/cmd/compile/internal/types2/testdata/fixedbugs/issue41124.go2 +++ b/src/cmd/compile/internal/types2/testdata/fixedbugs/issue41124.go2 @@ -47,7 +47,7 @@ type _ struct{ } type _ struct{ - I3 // ERROR interface is .* comparable + I3 // ERROR interface contains type constraints } // General composite types. @@ -59,19 +59,19 @@ type ( _ []I1 // ERROR interface is .* comparable _ []I2 // ERROR interface contains type constraints - _ *I3 // ERROR interface is .* comparable + _ *I3 // ERROR interface contains type constraints _ map[I1 /* ERROR interface is .* comparable */ ]I2 // ERROR interface contains type constraints - _ chan I3 // ERROR interface is .* comparable + _ chan I3 // ERROR interface contains type constraints _ func(I1 /* ERROR interface is .* comparable */ ) _ func() I2 // ERROR interface contains type constraints ) // Other cases. -var _ = [...]I3 /* ERROR interface is .* comparable */ {} +var _ = [...]I3 /* ERROR interface contains type constraints */ {} func _(x interface{}) { - _ = x.(I3 /* ERROR interface is .* comparable */ ) + _ = x.(I3 /* ERROR interface contains type constraints */ ) } type T1[_ any] struct{} diff --git a/src/cmd/compile/internal/types2/testdata/fixedbugs/issue51472.go2 b/src/cmd/compile/internal/types2/testdata/fixedbugs/issue51472.go2 new file mode 100644 index 00000000000..f19d906d973 --- /dev/null +++ b/src/cmd/compile/internal/types2/testdata/fixedbugs/issue51472.go2 @@ -0,0 +1,54 @@ +// Copyright 2022 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 p + +func _[T comparable](x T) { + _ = x == x +} + +func _[T interface{interface{comparable}}](x T) { + _ = x == x +} + +func _[T interface{comparable; interface{comparable}}](x T) { + _ = x == x +} + +func _[T interface{comparable; ~int}](x T) { + _ = x == x +} + +func _[T interface{comparable; ~[]byte}](x T) { + _ = x /* ERROR cannot compare */ == x +} + +// TODO(gri) The error message here should be better. See issue #51525. +func _[T interface{comparable; ~int; ~string}](x T) { + _ = x /* ERROR cannot compare */ == x +} + +// TODO(gri) The error message here should be better. See issue #51525. +func _[T interface{~int; ~string}](x T) { + _ = x /* ERROR cannot compare */ == x +} + +func _[T interface{comparable; interface{~int}; interface{int|float64}}](x T) { + _ = x == x +} + +func _[T interface{interface{comparable; ~int}; interface{~float64; comparable; m()}}](x T) { + _ = x /* ERROR cannot compare */ == x +} + +// test case from issue + +func f[T interface{comparable; []byte|string}](x T) { + _ = x == x +} + +func _(s []byte) { + f( /* ERROR \[\]byte does not implement interface{comparable; \[\]byte\|string} */ s) + _ = f[[ /* ERROR does not implement */ ]byte] +} diff --git a/src/cmd/compile/internal/types2/typeset.go b/src/cmd/compile/internal/types2/typeset.go index 65ae04819e7..8df89494352 100644 --- a/src/cmd/compile/internal/types2/typeset.go +++ b/src/cmd/compile/internal/types2/typeset.go @@ -15,20 +15,25 @@ import ( // API // A _TypeSet represents the type set of an interface. +// Because of existing language restrictions, methods can be "factored out" +// from the terms. The actual type set is the intersection of the type set +// implied by the methods and the type set described by the terms and the +// comparable bit. To test whether a type is included in a type set +// ("implements" relation), the type must implement all methods _and_ be +// an element of the type set described by the terms and the comparable bit. +// If the term list describes the set of all types and comparable is true, +// only comparable types are meant; in all other cases comparable is false. type _TypeSet struct { - comparable bool // if set, the interface is or embeds comparable - // TODO(gri) consider using a set for the methods for faster lookup - methods []*Func // all methods of the interface; sorted by unique ID - terms termlist // type terms of the type set + methods []*Func // all methods of the interface; sorted by unique ID + terms termlist // type terms of the type set + comparable bool // invariant: !comparable || terms.isAll() } // IsEmpty reports whether type set s is the empty set. func (s *_TypeSet) IsEmpty() bool { return s.terms.isEmpty() } // IsAll reports whether type set s is the set of all types (corresponding to the empty interface). -func (s *_TypeSet) IsAll() bool { - return !s.comparable && len(s.methods) == 0 && s.terms.isAll() -} +func (s *_TypeSet) IsAll() bool { return s.IsMethodSet() && len(s.methods) == 0 } // IsMethodSet reports whether the interface t is fully described by its method set. func (s *_TypeSet) IsMethodSet() bool { return !s.comparable && s.terms.isAll() } @@ -43,13 +48,6 @@ func (s *_TypeSet) IsComparable(seen map[Type]bool) bool { }) } -// TODO(gri) IsTypeSet is not a great name for this predicate. Find a better one. - -// IsTypeSet reports whether the type set s is represented by a finite set of underlying types. -func (s *_TypeSet) IsTypeSet() bool { - return !s.comparable && len(s.methods) == 0 -} - // NumMethods returns the number of methods available. func (s *_TypeSet) NumMethods() int { return len(s.methods) } @@ -215,12 +213,12 @@ func computeInterfaceTypeSet(check *Checker, pos syntax.Pos, ityp *Interface) *_ var todo []*Func var seen objset - var methods []*Func + var allMethods []*Func mpos := make(map[*Func]syntax.Pos) // method specification or method embedding position, for good error messages addMethod := func(pos syntax.Pos, m *Func, explicit bool) { switch other := seen.insert(m); { case other == nil: - methods = append(methods, m) + allMethods = append(allMethods, m) mpos[m] = pos case explicit: if check == nil { @@ -259,7 +257,8 @@ func computeInterfaceTypeSet(check *Checker, pos syntax.Pos, ityp *Interface) *_ } // collect embedded elements - var allTerms = allTermlist + allTerms := allTermlist + allComparable := false for i, typ := range ityp.embeddeds { // The embedding position is nil for imported interfaces // and also for interface copies after substitution (but @@ -268,6 +267,7 @@ func computeInterfaceTypeSet(check *Checker, pos syntax.Pos, ityp *Interface) *_ if ityp.embedPos != nil { pos = (*ityp.embedPos)[i] } + var comparable bool var terms termlist switch u := under(typ).(type) { case *Interface: @@ -279,9 +279,7 @@ func computeInterfaceTypeSet(check *Checker, pos syntax.Pos, ityp *Interface) *_ check.versionErrorf(pos, "go1.18", "embedding constraint interface %s", typ) continue } - if tset.comparable { - ityp.tset.comparable = true - } + comparable = tset.comparable for _, m := range tset.methods { addMethod(pos, m, false) // use embedding position pos rather than m.pos } @@ -295,6 +293,8 @@ func computeInterfaceTypeSet(check *Checker, pos syntax.Pos, ityp *Interface) *_ if tset == &invalidTypeSet { continue // ignore invalid unions } + assert(!tset.comparable) + assert(len(tset.methods) == 0) terms = tset.terms default: if u == Typ[Invalid] { @@ -306,11 +306,11 @@ func computeInterfaceTypeSet(check *Checker, pos syntax.Pos, ityp *Interface) *_ } terms = termlist{{false, typ}} } - // The type set of an interface is the intersection - // of the type sets of all its elements. - // Intersection cannot produce longer termlists and - // thus cannot overflow. - allTerms = allTerms.intersect(terms) + + // The type set of an interface is the intersection of the type sets of all its elements. + // Due to language restrictions, only embedded interfaces can add methods, they are handled + // separately. Here we only need to intersect the term lists and comparable bits. + allTerms, allComparable = intersectTermLists(allTerms, allComparable, terms, comparable) } ityp.embedPos = nil // not needed anymore (errors have been reported) @@ -323,15 +323,46 @@ func computeInterfaceTypeSet(check *Checker, pos syntax.Pos, ityp *Interface) *_ } } - if methods != nil { - sortMethods(methods) - ityp.tset.methods = methods + ityp.tset.comparable = allComparable + if len(allMethods) != 0 { + sortMethods(allMethods) + ityp.tset.methods = allMethods } ityp.tset.terms = allTerms return ityp.tset } +// TODO(gri) The intersectTermLists function belongs to the termlist implementation. +// The comparable type set may also be best represented as a term (using +// a special type). + +// intersectTermLists computes the intersection of two term lists and respective comparable bits. +// xcomp, ycomp are valid only if xterms.isAll() and yterms.isAll() respectively. +func intersectTermLists(xterms termlist, xcomp bool, yterms termlist, ycomp bool) (termlist, bool) { + terms := xterms.intersect(yterms) + // If one of xterms or yterms is marked as comparable, + // the result must only include comparable types. + comp := xcomp || ycomp + if comp && !terms.isAll() { + // only keep comparable terms + i := 0 + for _, t := range terms { + assert(t.typ != nil) + if Comparable(t.typ) { + terms[i] = t + i++ + } + } + terms = terms[:i] + if !terms.isAll() { + comp = false + } + } + assert(!comp || terms.isAll()) // comparable invariant + return terms, comp +} + func sortMethods(list []*Func) { sort.Sort(byUniqueMethodName(list)) } diff --git a/src/cmd/compile/internal/types2/typeset_test.go b/src/cmd/compile/internal/types2/typeset_test.go index 7f7cc06db97..68e5d8ad62c 100644 --- a/src/cmd/compile/internal/types2/typeset_test.go +++ b/src/cmd/compile/internal/types2/typeset_test.go @@ -25,9 +25,9 @@ func TestTypeSetString(t *testing.T) { "{int; string}": "∅", "{comparable}": "{comparable}", - "{comparable; int}": "{comparable; int}", - "{~int; comparable}": "{comparable; ~int}", - "{int|string; comparable}": "{comparable; int ∪ string}", + "{comparable; int}": "{int}", + "{~int; comparable}": "{~int}", + "{int|string; comparable}": "{int ∪ string}", "{comparable; int; string}": "∅", "{m()}": "{func (p.T).m()}", @@ -37,8 +37,8 @@ func TestTypeSetString(t *testing.T) { "{m1(); comparable; m2() int }": "{comparable; func (p.T).m1(); func (p.T).m2() int}", "{comparable; error}": "{comparable; func (error).Error() string}", - "{m(); comparable; int|float32|string}": "{comparable; func (p.T).m(); int ∪ float32 ∪ string}", - "{m1(); int; m2(); comparable }": "{comparable; func (p.T).m1(); func (p.T).m2(); int}", + "{m(); comparable; int|float32|string}": "{func (p.T).m(); int ∪ float32 ∪ string}", + "{m1(); int; m2(); comparable }": "{func (p.T).m1(); func (p.T).m2(); int}", "{E}; type E interface{}": "𝓤", "{E}; type E interface{int;string}": "∅", diff --git a/src/cmd/compile/internal/types2/union.go b/src/cmd/compile/internal/types2/union.go index 3c0df04ccdc..e317b9cced4 100644 --- a/src/cmd/compile/internal/types2/union.go +++ b/src/cmd/compile/internal/types2/union.go @@ -100,25 +100,27 @@ func parseUnion(check *Checker, uexpr syntax.Expr) Type { if !Identical(u, t.typ) { check.errorf(tlist[i], "invalid use of ~ (underlying type of %s is %s)", t.typ, u) - continue // don't report another error for t + continue } } // Stand-alone embedded interfaces are ok and are handled by the single-type case // in the beginning. Embedded interfaces with tilde are excluded above. If we reach - // here, we must have at least two terms in the union. - if f != nil && !f.typeSet().IsTypeSet() { + // here, we must have at least two terms in the syntactic term list (but not necessarily + // in the term list of the union's type set). + if f != nil { + tset := f.typeSet() switch { - case f.typeSet().NumMethods() != 0: + case tset.NumMethods() != 0: check.errorf(tlist[i], "cannot use %s in union (%s contains methods)", t, t) + continue case t.typ == universeComparable.Type(): check.error(tlist[i], "cannot use comparable in union") - case f.typeSet().comparable: + continue + case tset.comparable: check.errorf(tlist[i], "cannot use %s in union (%s embeds comparable)", t, t) - default: - panic("not a type set but no methods and not comparable") + continue } - continue // don't report another error for t } // Report overlapping (non-disjoint) terms such as diff --git a/src/cmd/compile/internal/types2/universe.go b/src/cmd/compile/internal/types2/universe.go index 6ee5dbdca35..11c81863a98 100644 --- a/src/cmd/compile/internal/types2/universe.go +++ b/src/cmd/compile/internal/types2/universe.go @@ -111,7 +111,7 @@ func defPredeclaredTypes() { typ := NewNamed(obj, nil, nil) // interface{} // marked as comparable - ityp := &Interface{obj: obj, complete: true, tset: &_TypeSet{true, nil, allTermlist}} + ityp := &Interface{obj: obj, complete: true, tset: &_TypeSet{nil, allTermlist, true}} typ.SetUnderlying(ityp) def(obj) diff --git a/src/go/types/testdata/fixedbugs/issue41124.go2 b/src/go/types/testdata/fixedbugs/issue41124.go2 index 7f55ba85a6b..4550dd732c1 100644 --- a/src/go/types/testdata/fixedbugs/issue41124.go2 +++ b/src/go/types/testdata/fixedbugs/issue41124.go2 @@ -47,7 +47,7 @@ type _ struct{ } type _ struct{ - I3 // ERROR interface is .* comparable + I3 // ERROR interface contains type constraints } // General composite types. @@ -59,19 +59,19 @@ type ( _ []I1 // ERROR interface is .* comparable _ []I2 // ERROR interface contains type constraints - _ *I3 // ERROR interface is .* comparable + _ *I3 // ERROR interface contains type constraints _ map[I1 /* ERROR interface is .* comparable */ ]I2 // ERROR interface contains type constraints - _ chan I3 // ERROR interface is .* comparable + _ chan I3 // ERROR interface contains type constraints _ func(I1 /* ERROR interface is .* comparable */ ) _ func() I2 // ERROR interface contains type constraints ) // Other cases. -var _ = [...]I3 /* ERROR interface is .* comparable */ {} +var _ = [...]I3 /* ERROR interface contains type constraints */ {} func _(x interface{}) { - _ = x.(I3 /* ERROR interface is .* comparable */ ) + _ = x.(I3 /* ERROR interface contains type constraints */ ) } type T1[_ any] struct{} diff --git a/src/go/types/testdata/fixedbugs/issue51472.go2 b/src/go/types/testdata/fixedbugs/issue51472.go2 new file mode 100644 index 00000000000..31267708290 --- /dev/null +++ b/src/go/types/testdata/fixedbugs/issue51472.go2 @@ -0,0 +1,54 @@ +// Copyright 2022 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 p + +func _[T comparable](x T) { + _ = x == x +} + +func _[T interface{interface{comparable}}](x T) { + _ = x == x +} + +func _[T interface{comparable; interface{comparable}}](x T) { + _ = x == x +} + +func _[T interface{comparable; ~int}](x T) { + _ = x == x +} + +func _[T interface{comparable; ~[]byte}](x T) { + _ = x /* ERROR cannot compare */ == x +} + +// TODO(gri) The error message here should be better. See issue #51525. +func _[T interface{comparable; ~int; ~string}](x T) { + _ = x /* ERROR cannot compare */ == x +} + +// TODO(gri) The error message here should be better. See issue #51525. +func _[T interface{~int; ~string}](x T) { + _ = x /* ERROR cannot compare */ == x +} + +func _[T interface{comparable; interface{~int}; interface{int|float64}}](x T) { + _ = x == x +} + +func _[T interface{interface{comparable; ~int}; interface{~float64; comparable; m()}}](x T) { + _ = x /* ERROR cannot compare */ == x +} + +// test case from issue + +func f[T interface{comparable; []byte|string}](x T) { + _ = x == x +} + +func _(s []byte) { + f /* ERROR \[\]byte does not implement interface{comparable; \[\]byte\|string} */ (s) + _ = f[[ /* ERROR does not implement */ ]byte] +} diff --git a/src/go/types/typeset.go b/src/go/types/typeset.go index 4c3f018cfef..6603383ea3c 100644 --- a/src/go/types/typeset.go +++ b/src/go/types/typeset.go @@ -15,18 +15,25 @@ import ( // API // A _TypeSet represents the type set of an interface. +// Because of existing language restrictions, methods can be "factored out" +// from the terms. The actual type set is the intersection of the type set +// implied by the methods and the type set described by the terms and the +// comparable bit. To test whether a type is included in a type set +// ("implements" relation), the type must implement all methods _and_ be +// an element of the type set described by the terms and the comparable bit. +// If the term list describes the set of all types and comparable is true, +// only comparable types are meant; in all other cases comparable is false. type _TypeSet struct { - comparable bool // if set, the interface is or embeds comparable - // TODO(gri) consider using a set for the methods for faster lookup - methods []*Func // all methods of the interface; sorted by unique ID - terms termlist // type terms of the type set + methods []*Func // all methods of the interface; sorted by unique ID + terms termlist // type terms of the type set + comparable bool // invariant: !comparable || terms.isAll() } // IsEmpty reports whether type set s is the empty set. func (s *_TypeSet) IsEmpty() bool { return s.terms.isEmpty() } // IsAll reports whether type set s is the set of all types (corresponding to the empty interface). -func (s *_TypeSet) IsAll() bool { return !s.comparable && len(s.methods) == 0 && s.terms.isAll() } +func (s *_TypeSet) IsAll() bool { return s.IsMethodSet() && len(s.methods) == 0 } // IsMethodSet reports whether the interface t is fully described by its method set. func (s *_TypeSet) IsMethodSet() bool { return !s.comparable && s.terms.isAll() } @@ -41,13 +48,6 @@ func (s *_TypeSet) IsComparable(seen map[Type]bool) bool { }) } -// TODO(gri) IsTypeSet is not a great name for this predicate. Find a better one. - -// IsTypeSet reports whether the type set s is represented by a finite set of underlying types. -func (s *_TypeSet) IsTypeSet() bool { - return !s.comparable && len(s.methods) == 0 -} - // NumMethods returns the number of methods available. func (s *_TypeSet) NumMethods() int { return len(s.methods) } @@ -217,12 +217,12 @@ func computeInterfaceTypeSet(check *Checker, pos token.Pos, ityp *Interface) *_T var todo []*Func var seen objset - var methods []*Func + var allMethods []*Func mpos := make(map[*Func]token.Pos) // method specification or method embedding position, for good error messages addMethod := func(pos token.Pos, m *Func, explicit bool) { switch other := seen.insert(m); { case other == nil: - methods = append(methods, m) + allMethods = append(allMethods, m) mpos[m] = pos case explicit: if check == nil { @@ -257,7 +257,8 @@ func computeInterfaceTypeSet(check *Checker, pos token.Pos, ityp *Interface) *_T } // collect embedded elements - var allTerms = allTermlist + allTerms := allTermlist + allComparable := false for i, typ := range ityp.embeddeds { // The embedding position is nil for imported interfaces // and also for interface copies after substitution (but @@ -266,6 +267,7 @@ func computeInterfaceTypeSet(check *Checker, pos token.Pos, ityp *Interface) *_T if ityp.embedPos != nil { pos = (*ityp.embedPos)[i] } + var comparable bool var terms termlist switch u := under(typ).(type) { case *Interface: @@ -277,9 +279,7 @@ func computeInterfaceTypeSet(check *Checker, pos token.Pos, ityp *Interface) *_T check.errorf(atPos(pos), _UnsupportedFeature, "embedding constraint interface %s requires go1.18 or later", typ) continue } - if tset.comparable { - ityp.tset.comparable = true - } + comparable = tset.comparable for _, m := range tset.methods { addMethod(pos, m, false) // use embedding position pos rather than m.pos } @@ -293,6 +293,8 @@ func computeInterfaceTypeSet(check *Checker, pos token.Pos, ityp *Interface) *_T if tset == &invalidTypeSet { continue // ignore invalid unions } + assert(!tset.comparable) + assert(len(tset.methods) == 0) terms = tset.terms default: if u == Typ[Invalid] { @@ -304,11 +306,11 @@ func computeInterfaceTypeSet(check *Checker, pos token.Pos, ityp *Interface) *_T } terms = termlist{{false, typ}} } - // The type set of an interface is the intersection - // of the type sets of all its elements. - // Intersection cannot produce longer termlists and - // thus cannot overflow. - allTerms = allTerms.intersect(terms) + + // The type set of an interface is the intersection of the type sets of all its elements. + // Due to language restrictions, only embedded interfaces can add methods, they are handled + // separately. Here we only need to intersect the term lists and comparable bits. + allTerms, allComparable = intersectTermLists(allTerms, allComparable, terms, comparable) } ityp.embedPos = nil // not needed anymore (errors have been reported) @@ -321,15 +323,46 @@ func computeInterfaceTypeSet(check *Checker, pos token.Pos, ityp *Interface) *_T } } - if methods != nil { - sort.Sort(byUniqueMethodName(methods)) - ityp.tset.methods = methods + ityp.tset.comparable = allComparable + if len(allMethods) != 0 { + sortMethods(allMethods) + ityp.tset.methods = allMethods } ityp.tset.terms = allTerms return ityp.tset } +// TODO(gri) The intersectTermLists function belongs to the termlist implementation. +// The comparable type set may also be best represented as a term (using +// a special type). + +// intersectTermLists computes the intersection of two term lists and respective comparable bits. +// xcomp, ycomp are valid only if xterms.isAll() and yterms.isAll() respectively. +func intersectTermLists(xterms termlist, xcomp bool, yterms termlist, ycomp bool) (termlist, bool) { + terms := xterms.intersect(yterms) + // If one of xterms or yterms is marked as comparable, + // the result must only include comparable types. + comp := xcomp || ycomp + if comp && !terms.isAll() { + // only keep comparable terms + i := 0 + for _, t := range terms { + assert(t.typ != nil) + if Comparable(t.typ) { + terms[i] = t + i++ + } + } + terms = terms[:i] + if !terms.isAll() { + comp = false + } + } + assert(!comp || terms.isAll()) // comparable invariant + return terms, comp +} + func sortMethods(list []*Func) { sort.Sort(byUniqueMethodName(list)) } diff --git a/src/go/types/typeset_test.go b/src/go/types/typeset_test.go index 1c0eeceb8c3..2bbe6113760 100644 --- a/src/go/types/typeset_test.go +++ b/src/go/types/typeset_test.go @@ -26,9 +26,9 @@ func TestTypeSetString(t *testing.T) { "{int; string}": "∅", "{comparable}": "{comparable}", - "{comparable; int}": "{comparable; int}", - "{~int; comparable}": "{comparable; ~int}", - "{int|string; comparable}": "{comparable; int ∪ string}", + "{comparable; int}": "{int}", + "{~int; comparable}": "{~int}", + "{int|string; comparable}": "{int ∪ string}", "{comparable; int; string}": "∅", "{m()}": "{func (p.T).m()}", @@ -38,8 +38,8 @@ func TestTypeSetString(t *testing.T) { "{m1(); comparable; m2() int }": "{comparable; func (p.T).m1(); func (p.T).m2() int}", "{comparable; error}": "{comparable; func (error).Error() string}", - "{m(); comparable; int|float32|string}": "{comparable; func (p.T).m(); int ∪ float32 ∪ string}", - "{m1(); int; m2(); comparable }": "{comparable; func (p.T).m1(); func (p.T).m2(); int}", + "{m(); comparable; int|float32|string}": "{func (p.T).m(); int ∪ float32 ∪ string}", + "{m1(); int; m2(); comparable }": "{func (p.T).m1(); func (p.T).m2(); int}", "{E}; type E interface{}": "𝓤", "{E}; type E interface{int;string}": "∅", diff --git a/src/go/types/union.go b/src/go/types/union.go index 9c59279447f..8397d65af01 100644 --- a/src/go/types/union.go +++ b/src/go/types/union.go @@ -103,25 +103,27 @@ func parseUnion(check *Checker, uexpr ast.Expr) Type { if !Identical(u, t.typ) { check.errorf(tlist[i], _InvalidUnion, "invalid use of ~ (underlying type of %s is %s)", t.typ, u) - continue // don't report another error for t + continue } } // Stand-alone embedded interfaces are ok and are handled by the single-type case // in the beginning. Embedded interfaces with tilde are excluded above. If we reach - // here, we must have at least two terms in the union. - if f != nil && !f.typeSet().IsTypeSet() { + // here, we must have at least two terms in the syntactic term list (but not necessarily + // in the term list of the union's type set). + if f != nil { + tset := f.typeSet() switch { - case f.typeSet().NumMethods() != 0: + case tset.NumMethods() != 0: check.errorf(tlist[i], _InvalidUnion, "cannot use %s in union (%s contains methods)", t, t) + continue case t.typ == universeComparable.Type(): check.error(tlist[i], _InvalidUnion, "cannot use comparable in union") - case f.typeSet().comparable: + continue + case tset.comparable: check.errorf(tlist[i], _InvalidUnion, "cannot use %s in union (%s embeds comparable)", t, t) - default: - panic("not a type set but no methods and not comparable") + continue } - continue // don't report another error for t } // Report overlapping (non-disjoint) terms such as diff --git a/src/go/types/universe.go b/src/go/types/universe.go index 34216346789..303ada4e57b 100644 --- a/src/go/types/universe.go +++ b/src/go/types/universe.go @@ -112,7 +112,7 @@ func defPredeclaredTypes() { typ := NewNamed(obj, nil, nil) // interface{} // marked as comparable - ityp := &Interface{obj: obj, complete: true, tset: &_TypeSet{true, nil, allTermlist}} + ityp := &Interface{obj: obj, complete: true, tset: &_TypeSet{nil, allTermlist, true}} typ.SetUnderlying(ityp) def(obj) From 114d5deac2f513a7397ab4c2ee8d2d567a901266 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Sun, 6 Mar 2022 15:44:42 -0800 Subject: [PATCH 024/276] go/types, types2: don't crash in selectors referring to the type being declared In Checker.typInternal, the SelectorExpr case was the only case that didn't either set or pass along the incoming def *Named type. Handle this by passing it along to Checker.selector and report a cycle if one is detected. Fixes #51509. Change-Id: I6c2d46835f225aeb4cb25fe0ae55f6180cef038b Reviewed-on: https://go-review.googlesource.com/c/go/+/390314 Trust: Robert Griesemer Reviewed-by: Robert Findley --- src/cmd/compile/internal/types2/call.go | 8 +++++++- src/cmd/compile/internal/types2/expr.go | 2 +- .../internal/types2/testdata/fixedbugs/issue51509.go | 7 +++++++ src/cmd/compile/internal/types2/typexpr.go | 2 +- src/go/types/call.go | 8 +++++++- src/go/types/expr.go | 2 +- src/go/types/testdata/fixedbugs/issue51509.go | 7 +++++++ src/go/types/typexpr.go | 2 +- 8 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 src/cmd/compile/internal/types2/testdata/fixedbugs/issue51509.go create mode 100644 src/go/types/testdata/fixedbugs/issue51509.go diff --git a/src/cmd/compile/internal/types2/call.go b/src/cmd/compile/internal/types2/call.go index d12ee49adbc..6cc30a7015c 100644 --- a/src/cmd/compile/internal/types2/call.go +++ b/src/cmd/compile/internal/types2/call.go @@ -423,7 +423,7 @@ var cgoPrefixes = [...]string{ "_Cmacro_", // function to evaluate the expanded expression } -func (check *Checker) selector(x *operand, e *syntax.SelectorExpr) { +func (check *Checker) selector(x *operand, e *syntax.SelectorExpr, def *Named) { // these must be declared before the "goto Error" statements var ( obj Object @@ -526,6 +526,12 @@ func (check *Checker) selector(x *operand, e *syntax.SelectorExpr) { check.exprOrType(x, e.X, false) switch x.mode { + case typexpr: + // don't crash for "type T T.x" (was issue #51509) + if def != nil && x.typ == def { + check.cycleError([]Object{def.obj}) + goto Error + } case builtin: check.errorf(e.Pos(), "cannot select on %s", x) goto Error diff --git a/src/cmd/compile/internal/types2/expr.go b/src/cmd/compile/internal/types2/expr.go index c587c40f80f..861a83472da 100644 --- a/src/cmd/compile/internal/types2/expr.go +++ b/src/cmd/compile/internal/types2/expr.go @@ -1556,7 +1556,7 @@ func (check *Checker) exprInternal(x *operand, e syntax.Expr, hint Type) exprKin return kind case *syntax.SelectorExpr: - check.selector(x, e) + check.selector(x, e, nil) case *syntax.IndexExpr: if check.indexExpr(x, e) { diff --git a/src/cmd/compile/internal/types2/testdata/fixedbugs/issue51509.go b/src/cmd/compile/internal/types2/testdata/fixedbugs/issue51509.go new file mode 100644 index 00000000000..5ae47176d07 --- /dev/null +++ b/src/cmd/compile/internal/types2/testdata/fixedbugs/issue51509.go @@ -0,0 +1,7 @@ +// Copyright 2022 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 p + +type T /* ERROR illegal cycle */ T.x diff --git a/src/cmd/compile/internal/types2/typexpr.go b/src/cmd/compile/internal/types2/typexpr.go index 2847aa76c09..b9bc992a82f 100644 --- a/src/cmd/compile/internal/types2/typexpr.go +++ b/src/cmd/compile/internal/types2/typexpr.go @@ -256,7 +256,7 @@ func (check *Checker) typInternal(e0 syntax.Expr, def *Named) (T Type) { case *syntax.SelectorExpr: var x operand - check.selector(&x, e) + check.selector(&x, e, def) switch x.mode { case typexpr: diff --git a/src/go/types/call.go b/src/go/types/call.go index 854528ddfa7..5d1f60d4326 100644 --- a/src/go/types/call.go +++ b/src/go/types/call.go @@ -429,7 +429,7 @@ var cgoPrefixes = [...]string{ "_Cmacro_", // function to evaluate the expanded expression } -func (check *Checker) selector(x *operand, e *ast.SelectorExpr) { +func (check *Checker) selector(x *operand, e *ast.SelectorExpr, def *Named) { // these must be declared before the "goto Error" statements var ( obj Object @@ -528,6 +528,12 @@ func (check *Checker) selector(x *operand, e *ast.SelectorExpr) { check.exprOrType(x, e.X, false) switch x.mode { + case typexpr: + // don't crash for "type T T.x" (was issue #51509) + if def != nil && x.typ == def { + check.cycleError([]Object{def.obj}) + goto Error + } case builtin: // types2 uses the position of '.' for the error check.errorf(e.Sel, _UncalledBuiltin, "cannot select on %s", x) diff --git a/src/go/types/expr.go b/src/go/types/expr.go index 9241c243f21..68b0789d650 100644 --- a/src/go/types/expr.go +++ b/src/go/types/expr.go @@ -1533,7 +1533,7 @@ func (check *Checker) exprInternal(x *operand, e ast.Expr, hint Type) exprKind { return kind case *ast.SelectorExpr: - check.selector(x, e) + check.selector(x, e, nil) case *ast.IndexExpr, *ast.IndexListExpr: ix := typeparams.UnpackIndexExpr(e) diff --git a/src/go/types/testdata/fixedbugs/issue51509.go b/src/go/types/testdata/fixedbugs/issue51509.go new file mode 100644 index 00000000000..5ae47176d07 --- /dev/null +++ b/src/go/types/testdata/fixedbugs/issue51509.go @@ -0,0 +1,7 @@ +// Copyright 2022 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 p + +type T /* ERROR illegal cycle */ T.x diff --git a/src/go/types/typexpr.go b/src/go/types/typexpr.go index 724c40963fd..838febc087b 100644 --- a/src/go/types/typexpr.go +++ b/src/go/types/typexpr.go @@ -254,7 +254,7 @@ func (check *Checker) typInternal(e0 ast.Expr, def *Named) (T Type) { case *ast.SelectorExpr: var x operand - check.selector(&x, e) + check.selector(&x, e, def) switch x.mode { case typexpr: From 43b09c096a33b8a3cd3477546c445e2c41efcfdf Mon Sep 17 00:00:00 2001 From: Robert Findley Date: Fri, 4 Mar 2022 18:52:49 -0500 Subject: [PATCH 025/276] go/types, types2: record all type instances, even duplicates Due to instance de-duplication, we were failing to record some type instances in types.Info.Instances. Fix this by moving the instance recording out of the resolver. Fixes #51494 Change-Id: Iddd8989307d95886eedb321efa4ab98cd2b3573a Reviewed-on: https://go-review.googlesource.com/c/go/+/390041 Trust: Robert Findley Run-TryBot: Robert Findley Reviewed-by: Robert Griesemer TryBot-Result: Gopher Robot --- src/cmd/compile/internal/types2/api_test.go | 275 +++++++++++--------- src/cmd/compile/internal/types2/typexpr.go | 5 +- src/go/types/api_test.go | 243 +++++++++-------- src/go/types/typexpr.go | 5 +- 4 files changed, 286 insertions(+), 242 deletions(-) diff --git a/src/cmd/compile/internal/types2/api_test.go b/src/cmd/compile/internal/types2/api_test.go index 5c38c59c803..5bb551798ee 100644 --- a/src/cmd/compile/internal/types2/api_test.go +++ b/src/cmd/compile/internal/types2/api_test.go @@ -12,6 +12,7 @@ import ( "internal/testenv" "reflect" "regexp" + "sort" "strings" "testing" @@ -403,69 +404,61 @@ func TestTypesInfo(t *testing.T) { } func TestInstanceInfo(t *testing.T) { - var tests = []struct { - src string + const lib = `package lib + +func F[P any](P) {} + +type T[P any] []P +` + + type testInst struct { name string targs []string typ string + } + + var tests = []struct { + src string + instances []testInst // recorded instances in source order }{ {`package p0; func f[T any](T) {}; func _() { f(42) }`, - `f`, - []string{`int`}, - `func(int)`, + []testInst{{`f`, []string{`int`}, `func(int)`}}, }, {`package p1; func f[T any](T) T { panic(0) }; func _() { f('@') }`, - `f`, - []string{`rune`}, - `func(rune) rune`, + []testInst{{`f`, []string{`rune`}, `func(rune) rune`}}, }, {`package p2; func f[T any](...T) T { panic(0) }; func _() { f(0i) }`, - `f`, - []string{`complex128`}, - `func(...complex128) complex128`, + []testInst{{`f`, []string{`complex128`}, `func(...complex128) complex128`}}, }, {`package p3; func f[A, B, C any](A, *B, []C) {}; func _() { f(1.2, new(string), []byte{}) }`, - `f`, - []string{`float64`, `string`, `byte`}, - `func(float64, *string, []byte)`, + []testInst{{`f`, []string{`float64`, `string`, `byte`}, `func(float64, *string, []byte)`}}, }, {`package p4; func f[A, B any](A, *B, ...[]B) {}; func _() { f(1.2, new(byte)) }`, - `f`, - []string{`float64`, `byte`}, - `func(float64, *byte, ...[]byte)`, + []testInst{{`f`, []string{`float64`, `byte`}, `func(float64, *byte, ...[]byte)`}}, }, - // we don't know how to translate these but we can type-check them {`package q0; type T struct{}; func (T) m[P any](P) {}; func _(x T) { x.m(42) }`, - `m`, - []string{`int`}, - `func(int)`, + []testInst{{`m`, []string{`int`}, `func(int)`}}, }, {`package q1; type T struct{}; func (T) m[P any](P) P { panic(0) }; func _(x T) { x.m(42) }`, - `m`, - []string{`int`}, - `func(int) int`, + []testInst{{`m`, []string{`int`}, `func(int) int`}}, }, {`package q2; type T struct{}; func (T) m[P any](...P) P { panic(0) }; func _(x T) { x.m(42) }`, - `m`, - []string{`int`}, - `func(...int) int`, + []testInst{{`m`, []string{`int`}, `func(...int) int`}}, }, {`package q3; type T struct{}; func (T) m[A, B, C any](A, *B, []C) {}; func _(x T) { x.m(1.2, new(string), []byte{}) }`, - `m`, - []string{`float64`, `string`, `byte`}, - `func(float64, *string, []byte)`, + []testInst{{`m`, []string{`float64`, `string`, `byte`}, `func(float64, *string, []byte)`}}, }, {`package q4; type T struct{}; func (T) m[A, B any](A, *B, ...[]B) {}; func _(x T) { x.m(1.2, new(byte)) }`, - `m`, - []string{`float64`, `byte`}, - `func(float64, *byte, ...[]byte)`, + []testInst{{`m`, []string{`float64`, `byte`}, `func(float64, *byte, ...[]byte)`}}, }, - {`package r0; type T[P any] struct{}; func (_ T[P]) m[Q any](Q) {}; func _[P any](x T[P]) { x.m(42) }`, - `m`, - []string{`int`}, - `func(int)`, + {`package r0; type T[P1 any] struct{}; func (_ T[P2]) m[Q any](Q) {}; func _[P3 any](x T[P3]) { x.m(42) }`, + []testInst{ + {`T`, []string{`P2`}, `struct{}`}, + {`T`, []string{`P3`}, `struct{}`}, + {`m`, []string{`int`}, `func(int)`}, + }, }, // TODO(gri) record method type parameters in syntax.FuncType so we can check this // {`package r1; type T interface{ m[P any](P) }; func _(x T) { x.m(4.2) }`, @@ -475,98 +468,112 @@ func TestInstanceInfo(t *testing.T) { // }, {`package s1; func f[T any, P interface{*T}](x T) {}; func _(x string) { f(x) }`, - `f`, - []string{`string`, `*string`}, - `func(x string)`, + []testInst{{`f`, []string{`string`, `*string`}, `func(x string)`}}, }, {`package s2; func f[T any, P interface{*T}](x []T) {}; func _(x []int) { f(x) }`, - `f`, - []string{`int`, `*int`}, - `func(x []int)`, + []testInst{{`f`, []string{`int`, `*int`}, `func(x []int)`}}, }, {`package s3; type C[T any] interface{chan<- T}; func f[T any, P C[T]](x []T) {}; func _(x []int) { f(x) }`, - `f`, - []string{`int`, `chan<- int`}, - `func(x []int)`, + []testInst{ + {`C`, []string{`T`}, `interface{chan<- T}`}, + {`f`, []string{`int`, `chan<- int`}, `func(x []int)`}, + }, }, {`package s4; type C[T any] interface{chan<- T}; func f[T any, P C[T], Q C[[]*P]](x []T) {}; func _(x []int) { f(x) }`, - `f`, - []string{`int`, `chan<- int`, `chan<- []*chan<- int`}, - `func(x []int)`, + []testInst{ + {`C`, []string{`T`}, `interface{chan<- T}`}, + {`C`, []string{`[]*P`}, `interface{chan<- []*P}`}, + {`f`, []string{`int`, `chan<- int`, `chan<- []*chan<- int`}, `func(x []int)`}, + }, }, {`package t1; func f[T any, P interface{*T}]() T { panic(0) }; func _() { _ = f[string] }`, - `f`, - []string{`string`, `*string`}, - `func() string`, + []testInst{{`f`, []string{`string`, `*string`}, `func() string`}}, }, {`package t2; func f[T any, P interface{*T}]() T { panic(0) }; func _() { _ = (f[string]) }`, - `f`, - []string{`string`, `*string`}, - `func() string`, + []testInst{{`f`, []string{`string`, `*string`}, `func() string`}}, }, {`package t3; type C[T any] interface{chan<- T}; func f[T any, P C[T], Q C[[]*P]]() []T { return nil }; func _() { _ = f[int] }`, - `f`, - []string{`int`, `chan<- int`, `chan<- []*chan<- int`}, - `func() []int`, + []testInst{ + {`C`, []string{`T`}, `interface{chan<- T}`}, + {`C`, []string{`[]*P`}, `interface{chan<- []*P}`}, + {`f`, []string{`int`, `chan<- int`, `chan<- []*chan<- int`}, `func() []int`}, + }, }, {`package t4; type C[T any] interface{chan<- T}; func f[T any, P C[T], Q C[[]*P]]() []T { return nil }; func _() { _ = (f[int]) }`, - `f`, - []string{`int`, `chan<- int`, `chan<- []*chan<- int`}, - `func() []int`, + []testInst{ + {`C`, []string{`T`}, `interface{chan<- T}`}, + {`C`, []string{`[]*P`}, `interface{chan<- []*P}`}, + {`f`, []string{`int`, `chan<- int`, `chan<- []*chan<- int`}, `func() []int`}, + }, }, - {`package i0; import "lib"; func _() { lib.F(42) }`, - `F`, - []string{`int`}, - `func(int)`, + []testInst{{`F`, []string{`int`}, `func(int)`}}, + }, + + {`package duplfunc0; func f[T any](T) {}; func _() { f(42); f("foo"); f[int](3) }`, + []testInst{ + {`f`, []string{`int`}, `func(int)`}, + {`f`, []string{`string`}, `func(string)`}, + {`f`, []string{`int`}, `func(int)`}, + }, + }, + {`package duplfunc1; import "lib"; func _() { lib.F(42); lib.F("foo"); lib.F(3) }`, + []testInst{ + {`F`, []string{`int`}, `func(int)`}, + {`F`, []string{`string`}, `func(string)`}, + {`F`, []string{`int`}, `func(int)`}, + }, }, {`package type0; type T[P interface{~int}] struct{ x P }; var _ T[int]`, - `T`, - []string{`int`}, - `struct{x int}`, + []testInst{{`T`, []string{`int`}, `struct{x int}`}}, }, {`package type1; type T[P interface{~int}] struct{ x P }; var _ (T[int])`, - `T`, - []string{`int`}, - `struct{x int}`, + []testInst{{`T`, []string{`int`}, `struct{x int}`}}, }, {`package type2; type T[P interface{~int}] struct{ x P }; var _ T[(int)]`, - `T`, - []string{`int`}, - `struct{x int}`, + []testInst{{`T`, []string{`int`}, `struct{x int}`}}, }, {`package type3; type T[P1 interface{~[]P2}, P2 any] struct{ x P1; y P2 }; var _ T[[]int, int]`, - `T`, - []string{`[]int`, `int`}, - `struct{x []int; y int}`, + []testInst{{`T`, []string{`[]int`, `int`}, `struct{x []int; y int}`}}, }, {`package type4; import "lib"; var _ lib.T[int]`, - `T`, - []string{`int`}, - `[]int`, + []testInst{{`T`, []string{`int`}, `[]int`}}, + }, + + {`package dupltype0; type T[P interface{~int}] struct{ x P }; var x T[int]; var y T[int]`, + []testInst{ + {`T`, []string{`int`}, `struct{x int}`}, + {`T`, []string{`int`}, `struct{x int}`}, + }, + }, + {`package dupltype1; type T[P ~int] struct{ x P }; func (r *T[Q]) add(z T[Q]) { r.x += z.x }`, + []testInst{ + {`T`, []string{`Q`}, `struct{x Q}`}, + {`T`, []string{`Q`}, `struct{x Q}`}, + }, + }, + {`package dupltype1; import "lib"; var x lib.T[int]; var y lib.T[int]; var z lib.T[string]`, + []testInst{ + {`T`, []string{`int`}, `[]int`}, + {`T`, []string{`int`}, `[]int`}, + {`T`, []string{`string`}, `[]string`}, + }, }, } for _, test := range tests { - const lib = `package lib - -func F[P any](P) {} - -type T[P any] []P -` - imports := make(testImporter) conf := Config{Importer: imports} - instances := make(map[*syntax.Name]Instance) - uses := make(map[*syntax.Name]Object) + instMap := make(map[*syntax.Name]Instance) + useMap := make(map[*syntax.Name]Object) makePkg := func(src string) *Package { f, err := parseSrc("p.go", src) if err != nil { t.Fatal(err) } - pkg, err := conf.Check("", []*syntax.File{f}, &Info{Instances: instances, Uses: uses}) + pkg, err := conf.Check("", []*syntax.File{f}, &Info{Instances: instMap, Uses: useMap}) if err != nil { t.Fatal(err) } @@ -576,58 +583,70 @@ type T[P any] []P makePkg(lib) pkg := makePkg(test.src) - // look for instance information - var targs []Type - var typ Type - for ident, inst := range instances { - if syntax.String(ident) == test.name { - for i := 0; i < inst.TypeArgs.Len(); i++ { - targs = append(targs, inst.TypeArgs.At(i)) + t.Run(pkg.Name(), func(t *testing.T) { + // Sort instances in source order for stability. + instances := sortedInstances(instMap) + if got, want := len(instances), len(test.instances); got != want { + t.Fatalf("got %d instances, want %d", got, want) + } + + // Pairwise compare with the expected instances. + for ii, inst := range instances { + var targs []Type + for i := 0; i < inst.Inst.TypeArgs.Len(); i++ { + targs = append(targs, inst.Inst.TypeArgs.At(i)) + } + typ := inst.Inst.Type + + testInst := test.instances[ii] + if got := inst.Name.Value; got != testInst.name { + t.Fatalf("got name %s, want %s", got, testInst.name) + } + + if len(targs) != len(testInst.targs) { + t.Fatalf("got %d type arguments; want %d", len(targs), len(testInst.targs)) + } + for i, targ := range targs { + if got := targ.String(); got != testInst.targs[i] { + t.Errorf("type argument %d: got %s; want %s", i, got, testInst.targs[i]) + } + } + if got := typ.Underlying().String(); got != testInst.typ { + t.Errorf("package %s: got %s; want %s", pkg.Name(), got, testInst.typ) } - typ = inst.Type - // Check that we can find the corresponding parameterized type. - ptype := uses[ident].Type() + // Verify the invariant that re-instantiating the corresponding generic + // type with TypeArgs results in an identical instance. + ptype := useMap[inst.Name].Type() lister, _ := ptype.(interface{ TypeParams() *TypeParamList }) if lister == nil || lister.TypeParams().Len() == 0 { - t.Errorf("package %s: info.Types[%v] = %v, want parameterized type", pkg.Name(), ident, ptype) - continue + t.Fatalf("info.Types[%v] = %v, want parameterized type", inst.Name, ptype) } - - // Verify the invariant that re-instantiating the generic type with - // TypeArgs results in an equivalent type. inst2, err := Instantiate(nil, ptype, targs, true) if err != nil { t.Errorf("Instantiate(%v, %v) failed: %v", ptype, targs, err) } - if !Identical(inst.Type, inst2) { - t.Errorf("%v and %v are not identical", inst.Type, inst2) + if !Identical(inst.Inst.Type, inst2) { + t.Errorf("%v and %v are not identical", inst.Inst.Type, inst2) } - break } - } - if targs == nil { - t.Errorf("package %s: no instance information found for %s", pkg.Name(), test.name) - continue - } + }) + } +} - // check that type arguments are correct - if len(targs) != len(test.targs) { - t.Errorf("package %s: got %d type arguments; want %d", pkg.Name(), len(targs), len(test.targs)) - continue - } - for i, targ := range targs { - if got := targ.String(); got != test.targs[i] { - t.Errorf("package %s, %d. type argument: got %s; want %s", pkg.Name(), i, got, test.targs[i]) - continue - } - } +type recordedInstance struct { + Name *syntax.Name + Inst Instance +} - // check that the types match - if got := typ.Underlying().String(); got != test.typ { - t.Errorf("package %s: got %s; want %s", pkg.Name(), got, test.typ) - } +func sortedInstances(m map[*syntax.Name]Instance) (instances []recordedInstance) { + for id, inst := range m { + instances = append(instances, recordedInstance{id, inst}) } + sort.Slice(instances, func(i, j int) bool { + return instances[i].Name.Pos().Cmp(instances[j].Name.Pos()) < 0 + }) + return instances } func TestDefsInfo(t *testing.T) { diff --git a/src/cmd/compile/internal/types2/typexpr.go b/src/cmd/compile/internal/types2/typexpr.go index b9bc992a82f..89c1f7b3a08 100644 --- a/src/cmd/compile/internal/types2/typexpr.go +++ b/src/cmd/compile/internal/types2/typexpr.go @@ -455,17 +455,15 @@ func (check *Checker) instantiatedType(x syntax.Expr, xlist []syntax.Expr, def * inst.resolver = func(ctxt *Context, n *Named) (*TypeParamList, Type, *methodList) { tparams := orig.TypeParams().list() - inferred := targs if len(targs) < len(tparams) { // If inference fails, len(inferred) will be 0, and inst.underlying will // be set to Typ[Invalid] in expandNamed. - inferred = check.infer(x.Pos(), tparams, targs, nil, nil) + inferred := check.infer(x.Pos(), tparams, targs, nil, nil) if len(inferred) > len(targs) { inst.targs = newTypeList(inferred) } } - check.recordInstance(x, inferred, inst) return expandNamed(ctxt, n, x.Pos()) } @@ -475,6 +473,7 @@ func (check *Checker) instantiatedType(x syntax.Expr, xlist []syntax.Expr, def * // and so it must be resolved during type-checking so that we can report // errors. inst.resolve(ctxt) + check.recordInstance(x, inst.TypeArgs().list(), inst) // Since check is non-nil, we can still mutate inst. Unpinning the resolver // frees some memory. inst.resolver = nil diff --git a/src/go/types/api_test.go b/src/go/types/api_test.go index 4c732dd58e7..4014201769e 100644 --- a/src/go/types/api_test.go +++ b/src/go/types/api_test.go @@ -16,6 +16,7 @@ import ( "internal/testenv" "reflect" "regexp" + "sort" "strings" "testing" @@ -434,131 +435,146 @@ func TestTypesInfo(t *testing.T) { } func TestInstanceInfo(t *testing.T) { - var tests = []struct { - src string + const lib = `package lib + +func F[P any](P) {} + +type T[P any] []P +` + + type testInst struct { name string targs []string typ string + } + + var tests = []struct { + src string + instances []testInst // recorded instances in source order }{ {`package p0; func f[T any](T) {}; func _() { f(42) }`, - `f`, - []string{`int`}, - `func(int)`, + []testInst{{`f`, []string{`int`}, `func(int)`}}, }, {`package p1; func f[T any](T) T { panic(0) }; func _() { f('@') }`, - `f`, - []string{`rune`}, - `func(rune) rune`, + []testInst{{`f`, []string{`rune`}, `func(rune) rune`}}, }, {`package p2; func f[T any](...T) T { panic(0) }; func _() { f(0i) }`, - `f`, - []string{`complex128`}, - `func(...complex128) complex128`, + []testInst{{`f`, []string{`complex128`}, `func(...complex128) complex128`}}, }, {`package p3; func f[A, B, C any](A, *B, []C) {}; func _() { f(1.2, new(string), []byte{}) }`, - `f`, - []string{`float64`, `string`, `byte`}, - `func(float64, *string, []byte)`, + []testInst{{`f`, []string{`float64`, `string`, `byte`}, `func(float64, *string, []byte)`}}, }, {`package p4; func f[A, B any](A, *B, ...[]B) {}; func _() { f(1.2, new(byte)) }`, - `f`, - []string{`float64`, `byte`}, - `func(float64, *byte, ...[]byte)`, + []testInst{{`f`, []string{`float64`, `byte`}, `func(float64, *byte, ...[]byte)`}}, }, {`package s1; func f[T any, P interface{*T}](x T) {}; func _(x string) { f(x) }`, - `f`, - []string{`string`, `*string`}, - `func(x string)`, + []testInst{{`f`, []string{`string`, `*string`}, `func(x string)`}}, }, {`package s2; func f[T any, P interface{*T}](x []T) {}; func _(x []int) { f(x) }`, - `f`, - []string{`int`, `*int`}, - `func(x []int)`, + []testInst{{`f`, []string{`int`, `*int`}, `func(x []int)`}}, }, {`package s3; type C[T any] interface{chan<- T}; func f[T any, P C[T]](x []T) {}; func _(x []int) { f(x) }`, - `f`, - []string{`int`, `chan<- int`}, - `func(x []int)`, + []testInst{ + {`C`, []string{`T`}, `interface{chan<- T}`}, + {`f`, []string{`int`, `chan<- int`}, `func(x []int)`}, + }, }, {`package s4; type C[T any] interface{chan<- T}; func f[T any, P C[T], Q C[[]*P]](x []T) {}; func _(x []int) { f(x) }`, - `f`, - []string{`int`, `chan<- int`, `chan<- []*chan<- int`}, - `func(x []int)`, + []testInst{ + {`C`, []string{`T`}, `interface{chan<- T}`}, + {`C`, []string{`[]*P`}, `interface{chan<- []*P}`}, + {`f`, []string{`int`, `chan<- int`, `chan<- []*chan<- int`}, `func(x []int)`}, + }, }, {`package t1; func f[T any, P interface{*T}]() T { panic(0) }; func _() { _ = f[string] }`, - `f`, - []string{`string`, `*string`}, - `func() string`, + []testInst{{`f`, []string{`string`, `*string`}, `func() string`}}, }, {`package t2; func f[T any, P interface{*T}]() T { panic(0) }; func _() { _ = (f[string]) }`, - `f`, - []string{`string`, `*string`}, - `func() string`, + []testInst{{`f`, []string{`string`, `*string`}, `func() string`}}, }, {`package t3; type C[T any] interface{chan<- T}; func f[T any, P C[T], Q C[[]*P]]() []T { return nil }; func _() { _ = f[int] }`, - `f`, - []string{`int`, `chan<- int`, `chan<- []*chan<- int`}, - `func() []int`, + []testInst{ + {`C`, []string{`T`}, `interface{chan<- T}`}, + {`C`, []string{`[]*P`}, `interface{chan<- []*P}`}, + {`f`, []string{`int`, `chan<- int`, `chan<- []*chan<- int`}, `func() []int`}, + }, }, {`package t4; type C[T any] interface{chan<- T}; func f[T any, P C[T], Q C[[]*P]]() []T { return nil }; func _() { _ = (f[int]) }`, - `f`, - []string{`int`, `chan<- int`, `chan<- []*chan<- int`}, - `func() []int`, + []testInst{ + {`C`, []string{`T`}, `interface{chan<- T}`}, + {`C`, []string{`[]*P`}, `interface{chan<- []*P}`}, + {`f`, []string{`int`, `chan<- int`, `chan<- []*chan<- int`}, `func() []int`}, + }, }, - {`package i0; import "lib"; func _() { lib.F(42) }`, - `F`, - []string{`int`}, - `func(int)`, + []testInst{{`F`, []string{`int`}, `func(int)`}}, + }, + + {`package duplfunc0; func f[T any](T) {}; func _() { f(42); f("foo"); f[int](3) }`, + []testInst{ + {`f`, []string{`int`}, `func(int)`}, + {`f`, []string{`string`}, `func(string)`}, + {`f`, []string{`int`}, `func(int)`}, + }, + }, + {`package duplfunc1; import "lib"; func _() { lib.F(42); lib.F("foo"); lib.F(3) }`, + []testInst{ + {`F`, []string{`int`}, `func(int)`}, + {`F`, []string{`string`}, `func(string)`}, + {`F`, []string{`int`}, `func(int)`}, + }, }, {`package type0; type T[P interface{~int}] struct{ x P }; var _ T[int]`, - `T`, - []string{`int`}, - `struct{x int}`, + []testInst{{`T`, []string{`int`}, `struct{x int}`}}, }, {`package type1; type T[P interface{~int}] struct{ x P }; var _ (T[int])`, - `T`, - []string{`int`}, - `struct{x int}`, + []testInst{{`T`, []string{`int`}, `struct{x int}`}}, }, {`package type2; type T[P interface{~int}] struct{ x P }; var _ T[(int)]`, - `T`, - []string{`int`}, - `struct{x int}`, + []testInst{{`T`, []string{`int`}, `struct{x int}`}}, }, {`package type3; type T[P1 interface{~[]P2}, P2 any] struct{ x P1; y P2 }; var _ T[[]int, int]`, - `T`, - []string{`[]int`, `int`}, - `struct{x []int; y int}`, + []testInst{{`T`, []string{`[]int`, `int`}, `struct{x []int; y int}`}}, }, {`package type4; import "lib"; var _ lib.T[int]`, - `T`, - []string{`int`}, - `[]int`, + []testInst{{`T`, []string{`int`}, `[]int`}}, + }, + + {`package dupltype0; type T[P interface{~int}] struct{ x P }; var x T[int]; var y T[int]`, + []testInst{ + {`T`, []string{`int`}, `struct{x int}`}, + {`T`, []string{`int`}, `struct{x int}`}, + }, + }, + {`package dupltype1; type T[P ~int] struct{ x P }; func (r *T[Q]) add(z T[Q]) { r.x += z.x }`, + []testInst{ + {`T`, []string{`Q`}, `struct{x Q}`}, + {`T`, []string{`Q`}, `struct{x Q}`}, + }, + }, + {`package dupltype1; import "lib"; var x lib.T[int]; var y lib.T[int]; var z lib.T[string]`, + []testInst{ + {`T`, []string{`int`}, `[]int`}, + {`T`, []string{`int`}, `[]int`}, + {`T`, []string{`string`}, `[]string`}, + }, }, } for _, test := range tests { - const lib = `package lib - -func F[P any](P) {} - -type T[P any] []P -` - imports := make(testImporter) conf := Config{Importer: imports} - instances := make(map[*ast.Ident]Instance) - uses := make(map[*ast.Ident]Object) + instMap := make(map[*ast.Ident]Instance) + useMap := make(map[*ast.Ident]Object) makePkg := func(src string) *Package { f, err := parser.ParseFile(fset, "p.go", src, 0) if err != nil { t.Fatal(err) } - pkg, err := conf.Check("", fset, []*ast.File{f}, &Info{Instances: instances, Uses: uses}) + pkg, err := conf.Check("", fset, []*ast.File{f}, &Info{Instances: instMap, Uses: useMap}) if err != nil { t.Fatal(err) } @@ -568,58 +584,69 @@ type T[P any] []P makePkg(lib) pkg := makePkg(test.src) - // look for instance information - var targs []Type - var typ Type - for ident, inst := range instances { - if ExprString(ident) == test.name { - for i := 0; i < inst.TypeArgs.Len(); i++ { - targs = append(targs, inst.TypeArgs.At(i)) + t.Run(pkg.Name(), func(t *testing.T) { + // Sort instances in source order for stability. + instances := sortedInstances(instMap) + if got, want := len(instances), len(test.instances); got != want { + t.Fatalf("got %d instances, want %d", got, want) + } + + // Pairwise compare with the expected instances. + for ii, inst := range instances { + var targs []Type + for i := 0; i < inst.Inst.TypeArgs.Len(); i++ { + targs = append(targs, inst.Inst.TypeArgs.At(i)) + } + typ := inst.Inst.Type + + testInst := test.instances[ii] + if got := inst.Ident.Name; got != testInst.name { + t.Fatalf("got name %s, want %s", got, testInst.name) + } + if len(targs) != len(testInst.targs) { + t.Fatalf("got %d type arguments; want %d", len(targs), len(testInst.targs)) + } + for i, targ := range targs { + if got := targ.String(); got != testInst.targs[i] { + t.Errorf("type argument %d: got %s; want %s", i, got, testInst.targs[i]) + } + } + if got := typ.Underlying().String(); got != testInst.typ { + t.Errorf("package %s: got %s; want %s", pkg.Name(), got, testInst.typ) } - typ = inst.Type - // Check that we can find the corresponding parameterized type. - ptype := uses[ident].Type() + // Verify the invariant that re-instantiating the corresponding generic + // type with TypeArgs results in an identical instance. + ptype := useMap[inst.Ident].Type() lister, _ := ptype.(interface{ TypeParams() *TypeParamList }) if lister == nil || lister.TypeParams().Len() == 0 { - t.Errorf("package %s: info.Types[%v] = %v, want parameterized type", pkg.Name(), ident, ptype) - continue + t.Fatalf("info.Types[%v] = %v, want parameterized type", inst.Ident, ptype) } - - // Verify the invariant that re-instantiating the generic type with - // TypeArgs results in an equivalent type. inst2, err := Instantiate(nil, ptype, targs, true) if err != nil { t.Errorf("Instantiate(%v, %v) failed: %v", ptype, targs, err) } - if !Identical(inst.Type, inst2) { - t.Errorf("%v and %v are not identical", inst.Type, inst2) + if !Identical(inst.Inst.Type, inst2) { + t.Errorf("%v and %v are not identical", inst.Inst.Type, inst2) } - break } - } - if targs == nil { - t.Errorf("package %s: no instance information found for %s", pkg.Name(), test.name) - continue - } + }) + } +} - // check that type arguments are correct - if len(targs) != len(test.targs) { - t.Errorf("package %s: got %d type arguments; want %d", pkg.Name(), len(targs), len(test.targs)) - continue - } - for i, targ := range targs { - if got := targ.String(); got != test.targs[i] { - t.Errorf("package %s, %d. type argument: got %s; want %s", pkg.Name(), i, got, test.targs[i]) - continue - } - } +type recordedInstance struct { + Ident *ast.Ident + Inst Instance +} - // check that the types match - if got := typ.Underlying().String(); got != test.typ { - t.Errorf("package %s: got %s; want %s", pkg.Name(), got, test.typ) - } +func sortedInstances(m map[*ast.Ident]Instance) (instances []recordedInstance) { + for id, inst := range m { + instances = append(instances, recordedInstance{id, inst}) } + sort.Slice(instances, func(i, j int) bool { + return instances[i].Ident.Pos() < instances[j].Ident.Pos() + }) + return instances } func TestDefsInfo(t *testing.T) { diff --git a/src/go/types/typexpr.go b/src/go/types/typexpr.go index 838febc087b..373ade04eb5 100644 --- a/src/go/types/typexpr.go +++ b/src/go/types/typexpr.go @@ -440,17 +440,15 @@ func (check *Checker) instantiatedType(ix *typeparams.IndexExpr, def *Named) (re inst.resolver = func(ctxt *Context, n *Named) (*TypeParamList, Type, *methodList) { tparams := orig.TypeParams().list() - inferred := targs if len(targs) < len(tparams) { // If inference fails, len(inferred) will be 0, and inst.underlying will // be set to Typ[Invalid] in expandNamed. - inferred = check.infer(ix.Orig, tparams, targs, nil, nil) + inferred := check.infer(ix.Orig, tparams, targs, nil, nil) if len(inferred) > len(targs) { inst.targs = newTypeList(inferred) } } - check.recordInstance(ix.Orig, inferred, inst) return expandNamed(ctxt, n, pos) } @@ -463,6 +461,7 @@ func (check *Checker) instantiatedType(ix *typeparams.IndexExpr, def *Named) (re // Since check is non-nil, we can still mutate inst. Unpinning the resolver // frees some memory. inst.resolver = nil + check.recordInstance(ix.Orig, inst.TypeArgs().list(), inst) if check.validateTArgLen(pos, inst.tparams.Len(), inst.targs.Len()) { if i, err := check.verify(pos, inst.tparams.list(), inst.targs.list()); err != nil { From 20dd9a42fb80ed4919d79bfb4644c16ab9e09e72 Mon Sep 17 00:00:00 2001 From: Robert Findley Date: Fri, 4 Mar 2022 14:39:43 -0500 Subject: [PATCH 026/276] go/types: document that predicates are undefined on generic types Fixes #50887 Change-Id: I451d66b067badcfb7cf2e2756ea2b062366ac9d4 Reviewed-on: https://go-review.googlesource.com/c/go/+/390039 Trust: Robert Findley Run-TryBot: Robert Findley Reviewed-by: Robert Griesemer TryBot-Result: Gopher Robot --- src/cmd/compile/internal/types2/api.go | 22 ++++++++++++++++++---- src/go/types/api.go | 22 ++++++++++++++++++---- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/cmd/compile/internal/types2/api.go b/src/cmd/compile/internal/types2/api.go index 6230c58401a..584f613a642 100644 --- a/src/cmd/compile/internal/types2/api.go +++ b/src/cmd/compile/internal/types2/api.go @@ -421,8 +421,11 @@ func (conf *Config) Check(path string, files []*syntax.File, info *Info) (*Packa } // AssertableTo reports whether a value of type V can be asserted to have type T. -// The behavior of AssertableTo is undefined if V is a generalized interface; i.e., -// an interface that may only be used as a type constraint in Go code. +// +// The behavior of AssertableTo is undefined in two cases: +// - if V is a generalized interface; i.e., an interface that may only be used +// as a type constraint in Go code +// - if T is an uninstantiated generic type func AssertableTo(V *Interface, T Type) bool { // Checker.newAssertableTo suppresses errors for invalid types, so we need special // handling here. @@ -432,20 +435,31 @@ func AssertableTo(V *Interface, T Type) bool { return (*Checker)(nil).newAssertableTo(V, T) == nil } -// AssignableTo reports whether a value of type V is assignable to a variable of type T. +// AssignableTo reports whether a value of type V is assignable to a variable +// of type T. +// +// The behavior of AssignableTo is undefined if V or T is an uninstantiated +// generic type. func AssignableTo(V, T Type) bool { x := operand{mode: value, typ: V} ok, _ := x.assignableTo(nil, T, nil) // check not needed for non-constant x return ok } -// ConvertibleTo reports whether a value of type V is convertible to a value of type T. +// ConvertibleTo reports whether a value of type V is convertible to a value of +// type T. +// +// The behavior of ConvertibleTo is undefined if V or T is an uninstantiated +// generic type. func ConvertibleTo(V, T Type) bool { x := operand{mode: value, typ: V} return x.convertibleTo(nil, T, nil) // check not needed for non-constant x } // Implements reports whether type V implements interface T. +// +// The behavior of Implements is undefined if V is an uninstantiated generic +// type. func Implements(V Type, T *Interface) bool { if T.Empty() { // All types (even Typ[Invalid]) implement the empty interface. diff --git a/src/go/types/api.go b/src/go/types/api.go index 828461477b9..86a03eba31f 100644 --- a/src/go/types/api.go +++ b/src/go/types/api.go @@ -417,8 +417,11 @@ func (conf *Config) Check(path string, fset *token.FileSet, files []*ast.File, i } // AssertableTo reports whether a value of type V can be asserted to have type T. -// The behavior of AssertableTo is undefined if V is a generalized interface; i.e., -// an interface that may only be used as a type constraint in Go code. +// +// The behavior of AssertableTo is undefined in two cases: +// - if V is a generalized interface; i.e., an interface that may only be used +// as a type constraint in Go code +// - if T is an uninstantiated generic type func AssertableTo(V *Interface, T Type) bool { // Checker.newAssertableTo suppresses errors for invalid types, so we need special // handling here. @@ -428,20 +431,31 @@ func AssertableTo(V *Interface, T Type) bool { return (*Checker)(nil).newAssertableTo(V, T) == nil } -// AssignableTo reports whether a value of type V is assignable to a variable of type T. +// AssignableTo reports whether a value of type V is assignable to a variable +// of type T. +// +// The behavior of AssignableTo is undefined if V or T is an uninstantiated +// generic type. func AssignableTo(V, T Type) bool { x := operand{mode: value, typ: V} ok, _ := x.assignableTo(nil, T, nil) // check not needed for non-constant x return ok } -// ConvertibleTo reports whether a value of type V is convertible to a value of type T. +// ConvertibleTo reports whether a value of type V is convertible to a value of +// type T. +// +// The behavior of ConvertibleTo is undefined if V or T is an uninstantiated +// generic type. func ConvertibleTo(V, T Type) bool { x := operand{mode: value, typ: V} return x.convertibleTo(nil, T, nil) // check not needed for non-constant x } // Implements reports whether type V implements interface T. +// +// The behavior of Implements is undefined if V is an uninstantiated generic +// type. func Implements(V Type, T *Interface) bool { if T.Empty() { // All types (even Typ[Invalid]) implement the empty interface. From 28fab5ef21d8aef72634f9c251fbeb4039dababa Mon Sep 17 00:00:00 2001 From: Robert Findley Date: Thu, 24 Feb 2022 14:18:24 -0500 Subject: [PATCH 027/276] go/types, types2: disable inference for type instances Inference for type instances has dependencies on type-checking order that can lead to subtle bugs. As explained in #51527, disable it for 1.18. Fixes #51527 Change-Id: I42795bad30ce53abecfc5a4914599ae5a2041a9e Reviewed-on: https://go-review.googlesource.com/c/go/+/387934 Trust: Robert Findley Run-TryBot: Robert Findley Reviewed-by: Robert Griesemer TryBot-Result: Gopher Robot --- .../types2/testdata/check/typeinference.go2 | 24 ++++++++++--------- .../types2/testdata/fixedbugs/issue49541.go2 | 7 +++--- .../types2/testdata/fixedbugs/issue50929.go2 | 6 ++--- .../types2/testdata/fixedbugs/issue51232.go2 | 11 +++++---- .../types2/testdata/fixedbugs/issue51233.go2 | 10 ++++---- .../types2/testdata/fixedbugs/issue51339.go2 | 4 +++- src/cmd/compile/internal/types2/typexpr.go | 15 ++++++++---- src/go/types/errorcodes.go | 5 ---- src/go/types/testdata/check/typeinference.go2 | 24 ++++++++++--------- .../types/testdata/fixedbugs/issue49541.go2 | 7 +++--- .../types/testdata/fixedbugs/issue50929.go2 | 6 ++--- .../types/testdata/fixedbugs/issue51232.go2 | 11 +++++---- .../types/testdata/fixedbugs/issue51233.go2 | 10 ++++---- .../types/testdata/fixedbugs/issue51339.go2 | 4 +++- src/go/types/typexpr.go | 13 ++++++---- test/typeparam/issue51232.go | 12 +++++----- test/typeparam/issue51233.go | 16 +++++++++---- 17 files changed, 106 insertions(+), 79 deletions(-) diff --git a/src/cmd/compile/internal/types2/testdata/check/typeinference.go2 b/src/cmd/compile/internal/types2/testdata/check/typeinference.go2 index 3d3380da9c0..28f3e286b7a 100644 --- a/src/cmd/compile/internal/types2/testdata/check/typeinference.go2 +++ b/src/cmd/compile/internal/types2/testdata/check/typeinference.go2 @@ -4,22 +4,24 @@ package typeInference +// As of issue #51527, type-type inference has been disabled. + // basic inference type Tb[P ~*Q, Q any] int func _() { - var x Tb[*int] + var x Tb /* ERROR got 1 arguments */ [*int] var y Tb[*int, int] - x = y + x = y /* ERROR cannot use y .* in assignment */ _ = x } // recursive inference type Tr[A any, B *C, C *D, D *A] int func _() { - var x Tr[string] + var x Tr /* ERROR got 1 arguments */ [string] var y Tr[string, ***string, **string, *string] var z Tr[int, ***int, **int, *int] - x = y + x = y /* ERROR cannot use y .* in assignment */ x = z // ERROR cannot use z .* as Tr _ = x } @@ -31,17 +33,17 @@ type To2[A any, B [][]A] int type To3[A any, B [3]*A] int type To4[A any, B any, C struct{a A; b B}] int func _() { - var _ To0[int] - var _ To1[int] - var _ To2[int] - var _ To3[int] - var _ To4[int, string] + var _ To0 /* ERROR got 1 arguments */ [int] + var _ To1 /* ERROR got 1 arguments */ [int] + var _ To2 /* ERROR got 1 arguments */ [int] + var _ To3 /* ERROR got 1 arguments */ [int] + var _ To4 /* ERROR got 2 arguments */ [int, string] } // failed inference type Tf0[A, B any] int type Tf1[A any, B ~struct{a A; c C}, C any] int func _() { - var _ Tf0 /* ERROR cannot infer B */ /* ERROR got 1 arguments but 2 type parameters */ [int] - var _ Tf1 /* ERROR cannot infer B */ /* ERROR got 1 arguments but 3 type parameters */ [int] + var _ Tf0 /* ERROR got 1 arguments but 2 type parameters */ [int] + var _ Tf1 /* ERROR got 1 arguments but 3 type parameters */ [int] } diff --git a/src/cmd/compile/internal/types2/testdata/fixedbugs/issue49541.go2 b/src/cmd/compile/internal/types2/testdata/fixedbugs/issue49541.go2 index b7bf12a1860..c8499c1b61d 100644 --- a/src/cmd/compile/internal/types2/testdata/fixedbugs/issue49541.go2 +++ b/src/cmd/compile/internal/types2/testdata/fixedbugs/issue49541.go2 @@ -10,9 +10,10 @@ type S[A, B any] struct { func (S[A, B]) m() {} -// TODO(gri) We should only report one error below. See issue #50588. +// TODO(gri): with type-type inference enabled we should only report one error +// below. See issue #50588. -func _[A any](s S /* ERROR cannot infer B */ /* ERROR got 1 arguments but 2 type parameters */ [A]) { +func _[A any](s S /* ERROR got 1 arguments but 2 type parameters */ [A]) { // we should see no follow-on errors below s.f = 1 s.m() @@ -21,7 +22,7 @@ func _[A any](s S /* ERROR cannot infer B */ /* ERROR got 1 arguments but 2 type // another test case from the issue func _() { - X(Interface[*F /* ERROR cannot infer B */ /* ERROR got 1 arguments but 2 type parameters */ [string]](Impl{})) + X(Interface[*F /* ERROR got 1 arguments but 2 type parameters */ [string]](Impl{})) } func X[Q Qer](fs Interface[Q]) { diff --git a/src/cmd/compile/internal/types2/testdata/fixedbugs/issue50929.go2 b/src/cmd/compile/internal/types2/testdata/fixedbugs/issue50929.go2 index 941dbaa3c11..3629ecf1045 100644 --- a/src/cmd/compile/internal/types2/testdata/fixedbugs/issue50929.go2 +++ b/src/cmd/compile/internal/types2/testdata/fixedbugs/issue50929.go2 @@ -16,7 +16,7 @@ func G[A, B any](F[A, B]) { func _() { // TODO(gri) only report one error below (issue #50932) - var x F /* ERROR cannot infer B */ /* ERROR got 1 arguments but 2 type parameters */ [int] + var x F /* ERROR got 1 arguments but 2 type parameters */ [int] G(x /* ERROR does not match */) } @@ -46,9 +46,9 @@ func NSG[G any](c RSC[G]) { fmt.Println(c) } -func MMD[Rc RC /* ERROR cannot infer RG */ /* ERROR got 1 arguments */ [RG], RG any, G any]() M /* ERROR got 2 arguments */ /* ERROR Rc does not match */ [Rc, RG] { +func MMD[Rc RC /* ERROR got 1 arguments */ [RG], RG any, G any]() M /* ERROR got 2 arguments */ [Rc, RG] { - var nFn NFn /* ERROR got 2 arguments */ /* ERROR Rc does not match */ [Rc, RG] + var nFn NFn /* ERROR got 2 arguments */ [Rc, RG] var empty Rc switch any(empty).(type) { diff --git a/src/cmd/compile/internal/types2/testdata/fixedbugs/issue51232.go2 b/src/cmd/compile/internal/types2/testdata/fixedbugs/issue51232.go2 index 6e575a376d1..3fa6a05732a 100644 --- a/src/cmd/compile/internal/types2/testdata/fixedbugs/issue51232.go2 +++ b/src/cmd/compile/internal/types2/testdata/fixedbugs/issue51232.go2 @@ -11,19 +11,20 @@ type RC[RG any] interface { type Fn[RCT RC[RG], RG any] func(RCT) type F[RCT RC[RG], RG any] interface { - Fn() Fn[RCT] + Fn() Fn /* ERROR got 1 arguments */ [RCT] } type concreteF[RCT RC[RG], RG any] struct { - makeFn func() Fn[RCT] + makeFn func() Fn /* ERROR got 1 arguments */ [RCT] } -func (c *concreteF[RCT, RG]) Fn() Fn[RCT] { +func (c *concreteF[RCT, RG]) Fn() Fn /* ERROR got 1 arguments */ [RCT] { return c.makeFn() } -func NewConcrete[RCT RC[RG], RG any](Rc RCT) F[RCT] { - return &concreteF[RCT]{ +func NewConcrete[RCT RC[RG], RG any](Rc RCT) F /* ERROR got 1 arguments */ [RCT] { + // TODO(rfindley): eliminate the duplicate error below. + return & /* ERROR cannot use .* as F\[RCT\] */ concreteF /* ERROR got 1 arguments */ [RCT]{ makeFn: nil, } } diff --git a/src/cmd/compile/internal/types2/testdata/fixedbugs/issue51233.go2 b/src/cmd/compile/internal/types2/testdata/fixedbugs/issue51233.go2 index 5c8393d039c..9c15028c91d 100644 --- a/src/cmd/compile/internal/types2/testdata/fixedbugs/issue51233.go2 +++ b/src/cmd/compile/internal/types2/testdata/fixedbugs/issue51233.go2 @@ -4,22 +4,24 @@ package p +// As of issue #51527, type-type inference has been disabled. + type RC[RG any] interface { ~[]RG } type Fn[RCT RC[RG], RG any] func(RCT) -type FFn[RCT RC[RG], RG any] func() Fn[RCT] +type FFn[RCT RC[RG], RG any] func() Fn /* ERROR got 1 arguments */ [RCT] type F[RCT RC[RG], RG any] interface { - Fn() Fn[RCT] + Fn() Fn /* ERROR got 1 arguments */ [RCT] } type concreteF[RCT RC[RG], RG any] struct { - makeFn FFn[RCT] + makeFn FFn /* ERROR got 1 arguments */ [RCT] } -func (c *concreteF[RCT, RG]) Fn() Fn[RCT] { +func (c *concreteF[RCT, RG]) Fn() Fn /* ERROR got 1 arguments */ [RCT] { return c.makeFn() } diff --git a/src/cmd/compile/internal/types2/testdata/fixedbugs/issue51339.go2 b/src/cmd/compile/internal/types2/testdata/fixedbugs/issue51339.go2 index 40706ec493d..84e551d9ad6 100644 --- a/src/cmd/compile/internal/types2/testdata/fixedbugs/issue51339.go2 +++ b/src/cmd/compile/internal/types2/testdata/fixedbugs/issue51339.go2 @@ -10,7 +10,9 @@ package p type T[P any, B *P] struct{} func (T /* ERROR cannot use generic type */ ) m0() {} -func (T /* ERROR got 1 type parameter, but receiver base type declares 2 */ [_]) m1() {} + +// TODO(rfindley): eliminate the duplicate errors here. +func (T /* ERROR got 1 type parameter, but receiver base type declares 2 */ /* ERROR got 1 arguments but 2 type parameters */ [_]) m1() {} func (T[_, _]) m2() {} // TODO(gri) this error is unfortunate (issue #51343) func (T /* ERROR got 3 arguments but 2 type parameters */ [_, _, _]) m3() {} diff --git a/src/cmd/compile/internal/types2/typexpr.go b/src/cmd/compile/internal/types2/typexpr.go index 89c1f7b3a08..a9ce55bd1e5 100644 --- a/src/cmd/compile/internal/types2/typexpr.go +++ b/src/cmd/compile/internal/types2/typexpr.go @@ -430,10 +430,14 @@ func (check *Checker) instantiatedType(x syntax.Expr, xlist []syntax.Expr, def * // evaluate arguments targs := check.typeList(xlist) if targs == nil { - def.setUnderlying(Typ[Invalid]) // avoid later errors due to lazy instantiation + def.setUnderlying(Typ[Invalid]) // avoid errors later due to lazy instantiation return Typ[Invalid] } + // enableTypeTypeInference controls whether to infer missing type arguments + // using constraint type inference. See issue #51527. + const enableTypeTypeInference = false + // create the instance ctxt := check.bestContext(nil) h := ctxt.instanceHash(orig, targs) @@ -453,14 +457,15 @@ func (check *Checker) instantiatedType(x syntax.Expr, xlist []syntax.Expr, def * def.setUnderlying(inst) inst.resolver = func(ctxt *Context, n *Named) (*TypeParamList, Type, *methodList) { - tparams := orig.TypeParams().list() + tparams := n.orig.TypeParams().list() - if len(targs) < len(tparams) { + targs := n.targs.list() + if enableTypeTypeInference && len(targs) < len(tparams) { // If inference fails, len(inferred) will be 0, and inst.underlying will // be set to Typ[Invalid] in expandNamed. inferred := check.infer(x.Pos(), tparams, targs, nil, nil) if len(inferred) > len(targs) { - inst.targs = newTypeList(inferred) + n.targs = newTypeList(inferred) } } @@ -473,10 +478,10 @@ func (check *Checker) instantiatedType(x syntax.Expr, xlist []syntax.Expr, def * // and so it must be resolved during type-checking so that we can report // errors. inst.resolve(ctxt) - check.recordInstance(x, inst.TypeArgs().list(), inst) // Since check is non-nil, we can still mutate inst. Unpinning the resolver // frees some memory. inst.resolver = nil + check.recordInstance(x, inst.TypeArgs().list(), inst) if check.validateTArgLen(x.Pos(), inst.tparams.Len(), inst.targs.Len()) { if i, err := check.verify(x.Pos(), inst.tparams.list(), inst.targs.list()); err != nil { diff --git a/src/go/types/errorcodes.go b/src/go/types/errorcodes.go index a7514b317a0..64cf24c96a1 100644 --- a/src/go/types/errorcodes.go +++ b/src/go/types/errorcodes.go @@ -1339,11 +1339,6 @@ const ( // func _() { // f() // } - // - // Example: - // type N[P, Q any] struct{} - // - // var _ N[int] _CannotInferTypeArgs // _InvalidTypeArg occurs when a type argument does not satisfy its diff --git a/src/go/types/testdata/check/typeinference.go2 b/src/go/types/testdata/check/typeinference.go2 index 3d3380da9c0..28f3e286b7a 100644 --- a/src/go/types/testdata/check/typeinference.go2 +++ b/src/go/types/testdata/check/typeinference.go2 @@ -4,22 +4,24 @@ package typeInference +// As of issue #51527, type-type inference has been disabled. + // basic inference type Tb[P ~*Q, Q any] int func _() { - var x Tb[*int] + var x Tb /* ERROR got 1 arguments */ [*int] var y Tb[*int, int] - x = y + x = y /* ERROR cannot use y .* in assignment */ _ = x } // recursive inference type Tr[A any, B *C, C *D, D *A] int func _() { - var x Tr[string] + var x Tr /* ERROR got 1 arguments */ [string] var y Tr[string, ***string, **string, *string] var z Tr[int, ***int, **int, *int] - x = y + x = y /* ERROR cannot use y .* in assignment */ x = z // ERROR cannot use z .* as Tr _ = x } @@ -31,17 +33,17 @@ type To2[A any, B [][]A] int type To3[A any, B [3]*A] int type To4[A any, B any, C struct{a A; b B}] int func _() { - var _ To0[int] - var _ To1[int] - var _ To2[int] - var _ To3[int] - var _ To4[int, string] + var _ To0 /* ERROR got 1 arguments */ [int] + var _ To1 /* ERROR got 1 arguments */ [int] + var _ To2 /* ERROR got 1 arguments */ [int] + var _ To3 /* ERROR got 1 arguments */ [int] + var _ To4 /* ERROR got 2 arguments */ [int, string] } // failed inference type Tf0[A, B any] int type Tf1[A any, B ~struct{a A; c C}, C any] int func _() { - var _ Tf0 /* ERROR cannot infer B */ /* ERROR got 1 arguments but 2 type parameters */ [int] - var _ Tf1 /* ERROR cannot infer B */ /* ERROR got 1 arguments but 3 type parameters */ [int] + var _ Tf0 /* ERROR got 1 arguments but 2 type parameters */ [int] + var _ Tf1 /* ERROR got 1 arguments but 3 type parameters */ [int] } diff --git a/src/go/types/testdata/fixedbugs/issue49541.go2 b/src/go/types/testdata/fixedbugs/issue49541.go2 index b7bf12a1860..c8499c1b61d 100644 --- a/src/go/types/testdata/fixedbugs/issue49541.go2 +++ b/src/go/types/testdata/fixedbugs/issue49541.go2 @@ -10,9 +10,10 @@ type S[A, B any] struct { func (S[A, B]) m() {} -// TODO(gri) We should only report one error below. See issue #50588. +// TODO(gri): with type-type inference enabled we should only report one error +// below. See issue #50588. -func _[A any](s S /* ERROR cannot infer B */ /* ERROR got 1 arguments but 2 type parameters */ [A]) { +func _[A any](s S /* ERROR got 1 arguments but 2 type parameters */ [A]) { // we should see no follow-on errors below s.f = 1 s.m() @@ -21,7 +22,7 @@ func _[A any](s S /* ERROR cannot infer B */ /* ERROR got 1 arguments but 2 type // another test case from the issue func _() { - X(Interface[*F /* ERROR cannot infer B */ /* ERROR got 1 arguments but 2 type parameters */ [string]](Impl{})) + X(Interface[*F /* ERROR got 1 arguments but 2 type parameters */ [string]](Impl{})) } func X[Q Qer](fs Interface[Q]) { diff --git a/src/go/types/testdata/fixedbugs/issue50929.go2 b/src/go/types/testdata/fixedbugs/issue50929.go2 index 941dbaa3c11..3629ecf1045 100644 --- a/src/go/types/testdata/fixedbugs/issue50929.go2 +++ b/src/go/types/testdata/fixedbugs/issue50929.go2 @@ -16,7 +16,7 @@ func G[A, B any](F[A, B]) { func _() { // TODO(gri) only report one error below (issue #50932) - var x F /* ERROR cannot infer B */ /* ERROR got 1 arguments but 2 type parameters */ [int] + var x F /* ERROR got 1 arguments but 2 type parameters */ [int] G(x /* ERROR does not match */) } @@ -46,9 +46,9 @@ func NSG[G any](c RSC[G]) { fmt.Println(c) } -func MMD[Rc RC /* ERROR cannot infer RG */ /* ERROR got 1 arguments */ [RG], RG any, G any]() M /* ERROR got 2 arguments */ /* ERROR Rc does not match */ [Rc, RG] { +func MMD[Rc RC /* ERROR got 1 arguments */ [RG], RG any, G any]() M /* ERROR got 2 arguments */ [Rc, RG] { - var nFn NFn /* ERROR got 2 arguments */ /* ERROR Rc does not match */ [Rc, RG] + var nFn NFn /* ERROR got 2 arguments */ [Rc, RG] var empty Rc switch any(empty).(type) { diff --git a/src/go/types/testdata/fixedbugs/issue51232.go2 b/src/go/types/testdata/fixedbugs/issue51232.go2 index 6e575a376d1..3fa6a05732a 100644 --- a/src/go/types/testdata/fixedbugs/issue51232.go2 +++ b/src/go/types/testdata/fixedbugs/issue51232.go2 @@ -11,19 +11,20 @@ type RC[RG any] interface { type Fn[RCT RC[RG], RG any] func(RCT) type F[RCT RC[RG], RG any] interface { - Fn() Fn[RCT] + Fn() Fn /* ERROR got 1 arguments */ [RCT] } type concreteF[RCT RC[RG], RG any] struct { - makeFn func() Fn[RCT] + makeFn func() Fn /* ERROR got 1 arguments */ [RCT] } -func (c *concreteF[RCT, RG]) Fn() Fn[RCT] { +func (c *concreteF[RCT, RG]) Fn() Fn /* ERROR got 1 arguments */ [RCT] { return c.makeFn() } -func NewConcrete[RCT RC[RG], RG any](Rc RCT) F[RCT] { - return &concreteF[RCT]{ +func NewConcrete[RCT RC[RG], RG any](Rc RCT) F /* ERROR got 1 arguments */ [RCT] { + // TODO(rfindley): eliminate the duplicate error below. + return & /* ERROR cannot use .* as F\[RCT\] */ concreteF /* ERROR got 1 arguments */ [RCT]{ makeFn: nil, } } diff --git a/src/go/types/testdata/fixedbugs/issue51233.go2 b/src/go/types/testdata/fixedbugs/issue51233.go2 index 5c8393d039c..9c15028c91d 100644 --- a/src/go/types/testdata/fixedbugs/issue51233.go2 +++ b/src/go/types/testdata/fixedbugs/issue51233.go2 @@ -4,22 +4,24 @@ package p +// As of issue #51527, type-type inference has been disabled. + type RC[RG any] interface { ~[]RG } type Fn[RCT RC[RG], RG any] func(RCT) -type FFn[RCT RC[RG], RG any] func() Fn[RCT] +type FFn[RCT RC[RG], RG any] func() Fn /* ERROR got 1 arguments */ [RCT] type F[RCT RC[RG], RG any] interface { - Fn() Fn[RCT] + Fn() Fn /* ERROR got 1 arguments */ [RCT] } type concreteF[RCT RC[RG], RG any] struct { - makeFn FFn[RCT] + makeFn FFn /* ERROR got 1 arguments */ [RCT] } -func (c *concreteF[RCT, RG]) Fn() Fn[RCT] { +func (c *concreteF[RCT, RG]) Fn() Fn /* ERROR got 1 arguments */ [RCT] { return c.makeFn() } diff --git a/src/go/types/testdata/fixedbugs/issue51339.go2 b/src/go/types/testdata/fixedbugs/issue51339.go2 index 6803c44d761..38f86109e36 100644 --- a/src/go/types/testdata/fixedbugs/issue51339.go2 +++ b/src/go/types/testdata/fixedbugs/issue51339.go2 @@ -10,7 +10,9 @@ package p type T[P any, B *P] struct{} func (T /* ERROR cannot use generic type */ ) m0() {} -func (/* ERROR got 1 type parameter, but receiver base type declares 2 */ T[_]) m1() {} + +// TODO(rfindley): eliminate the duplicate errors here. +func (/* ERROR got 1 type parameter, but receiver base type declares 2 */ T /* ERROR got 1 arguments but 2 type parameters */ [_]) m1() {} func (T[_, _]) m2() {} // TODO(gri) this error is unfortunate (issue #51343) func (T /* ERROR got 3 arguments but 2 type parameters */ [_, _, _]) m3() {} diff --git a/src/go/types/typexpr.go b/src/go/types/typexpr.go index 373ade04eb5..14735c37091 100644 --- a/src/go/types/typexpr.go +++ b/src/go/types/typexpr.go @@ -415,10 +415,14 @@ func (check *Checker) instantiatedType(ix *typeparams.IndexExpr, def *Named) (re // evaluate arguments targs := check.typeList(ix.Indices) if targs == nil { - def.setUnderlying(Typ[Invalid]) // avoid later errors due to lazy instantiation + def.setUnderlying(Typ[Invalid]) // avoid errors later due to lazy instantiation return Typ[Invalid] } + // enableTypeTypeInference controls whether to infer missing type arguments + // using constraint type inference. See issue #51527. + const enableTypeTypeInference = false + // create the instance ctxt := check.bestContext(nil) h := ctxt.instanceHash(orig, targs) @@ -438,14 +442,15 @@ func (check *Checker) instantiatedType(ix *typeparams.IndexExpr, def *Named) (re def.setUnderlying(inst) inst.resolver = func(ctxt *Context, n *Named) (*TypeParamList, Type, *methodList) { - tparams := orig.TypeParams().list() + tparams := n.orig.TypeParams().list() - if len(targs) < len(tparams) { + targs := n.targs.list() + if enableTypeTypeInference && len(targs) < len(tparams) { // If inference fails, len(inferred) will be 0, and inst.underlying will // be set to Typ[Invalid] in expandNamed. inferred := check.infer(ix.Orig, tparams, targs, nil, nil) if len(inferred) > len(targs) { - inst.targs = newTypeList(inferred) + n.targs = newTypeList(inferred) } } diff --git a/test/typeparam/issue51232.go b/test/typeparam/issue51232.go index 44d114d2351..0d25e1863d7 100644 --- a/test/typeparam/issue51232.go +++ b/test/typeparam/issue51232.go @@ -1,4 +1,4 @@ -// compile +// errorcheck // Copyright 2022 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style @@ -13,19 +13,19 @@ type RC[RG any] interface { type Fn[RCT RC[RG], RG any] func(RCT) type F[RCT RC[RG], RG any] interface { - Fn() Fn[RCT] + Fn() Fn[RCT] // ERROR "got 1 arguments" } type concreteF[RCT RC[RG], RG any] struct { - makeFn func() Fn[RCT] + makeFn func() Fn[RCT] // ERROR "got 1 arguments" } -func (c *concreteF[RCT, RG]) Fn() Fn[RCT] { +func (c *concreteF[RCT, RG]) Fn() Fn[RCT] { // ERROR "got 1 arguments" return c.makeFn() } -func NewConcrete[RCT RC[RG], RG any](Rc RCT) F[RCT] { - return &concreteF[RCT]{ +func NewConcrete[RCT RC[RG], RG any](Rc RCT) F[RCT] { // ERROR "got 1 arguments" + return &concreteF[RCT]{ // ERROR "cannot use" "got 1 arguments" makeFn: nil, } } diff --git a/test/typeparam/issue51233.go b/test/typeparam/issue51233.go index 9411f2e6b5b..96a25ddb9c3 100644 --- a/test/typeparam/issue51233.go +++ b/test/typeparam/issue51233.go @@ -1,22 +1,28 @@ -// compile +// errorcheck // Copyright 2022 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 p +// As of issue #51527, type-type inference has been disabled. + type RC[RG any] interface { ~[]RG } + type Fn[RCT RC[RG], RG any] func(RCT) -type FFn[RCT RC[RG], RG any] func() Fn[RCT] + +type FFn[RCT RC[RG], RG any] func() Fn[RCT] // ERROR "got 1 arguments" + type F[RCT RC[RG], RG any] interface { - Fn() Fn[RCT] + Fn() Fn[RCT] // ERROR "got 1 arguments" } + type concreteF[RCT RC[RG], RG any] struct { - makeFn FFn[RCT] + makeFn FFn[RCT] // ERROR "got 1 arguments" } -func (c *concreteF[RCT, RG]) Fn() Fn[RCT] { +func (c *concreteF[RCT, RG]) Fn() Fn[RCT] { // ERROR "got 1 arguments" return c.makeFn() } From 38174b3a3514629b84dcd76878b2f536b189dd7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Sun, 6 Mar 2022 20:31:33 +0000 Subject: [PATCH 028/276] go/build: use static maps rather than an init func MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit go/build is one of the packages that contributes the most towards cmd/go's init cost, which adds up to any call to the tool. One piece of low-hanging fruit is knownOS and knownArch, maps which are filled via an init func from a space-separated list. Using GODEBUG=inittrace=1, we can get three samples: init go/build @0.36 ms, 0.024 ms clock, 6568 bytes, 74 allocs init go/build @0.33 ms, 0.025 ms clock, 6888 bytes, 76 allocs init go/build @0.36 ms, 0.025 ms clock, 6728 bytes, 75 allocs After using a static map instead, we see an improvement: init go/build @0.33 ms, 0.018 ms clock, 5096 bytes, 69 allocs init go/build @0.36 ms, 0.021 ms clock, 5096 bytes, 69 allocs init go/build @0.33 ms, 0.019 ms clock, 5096 bytes, 69 allocs The speedup isn't huge, but it helps, and also reduces allocs. One can also imagine that the compiler may get better with static, read-only maps in the future, whereas the init func will likely always have a linear cost and extra allocations. Change-Id: I430212bad03d25358d2cc7b1eab4536ad88d05a8 Reviewed-on: https://go-review.googlesource.com/c/go/+/390274 Run-TryBot: Daniel Martí Trust: Daniel Martí TryBot-Result: Gopher Robot Reviewed-by: Ian Lance Taylor --- src/go/build/build.go | 12 ---------- src/go/build/syslist.go | 49 ++++++++++++++++++++++++++++++++++++++--- 2 files changed, 46 insertions(+), 15 deletions(-) diff --git a/src/go/build/build.go b/src/go/build/build.go index dce0304ba48..baf76e6b7ff 100644 --- a/src/go/build/build.go +++ b/src/go/build/build.go @@ -1965,18 +1965,6 @@ func (ctxt *Context) goodOSArchFile(name string, allTags map[string]bool) bool { return true } -var knownOS = make(map[string]bool) -var knownArch = make(map[string]bool) - -func init() { - for _, v := range strings.Fields(goosList) { - knownOS[v] = true - } - for _, v := range strings.Fields(goarchList) { - knownArch[v] = true - } -} - // ToolDir is the directory containing build tools. var ToolDir = getToolDir() diff --git a/src/go/build/syslist.go b/src/go/build/syslist.go index 0f6e3369253..6b62b63042b 100644 --- a/src/go/build/syslist.go +++ b/src/go/build/syslist.go @@ -4,8 +4,51 @@ package build -// List of past, present, and future known GOOS and GOARCH values. +// Past, present, and future known GOOS and GOARCH values. // Do not remove from this list, as these are used for go/build filename matching. -const goosList = "aix android darwin dragonfly freebsd hurd illumos ios js linux nacl netbsd openbsd plan9 solaris windows zos " -const goarchList = "386 amd64 amd64p32 arm armbe arm64 arm64be loong64 mips mipsle mips64 mips64le mips64p32 mips64p32le ppc ppc64 ppc64le riscv riscv64 s390 s390x sparc sparc64 wasm " +var knownOS = map[string]bool{ + "aix": true, + "android": true, + "darwin": true, + "dragonfly": true, + "freebsd": true, + "hurd": true, + "illumos": true, + "ios": true, + "js": true, + "linux": true, + "nacl": true, + "netbsd": true, + "openbsd": true, + "plan9": true, + "solaris": true, + "windows": true, + "zos": true, +} +var knownArch = map[string]bool{ + "386": true, + "amd64": true, + "amd64p32": true, + "arm": true, + "armbe": true, + "arm64": true, + "arm64be": true, + "loong64": true, + "mips": true, + "mipsle": true, + "mips64": true, + "mips64le": true, + "mips64p32": true, + "mips64p32le": true, + "ppc": true, + "ppc64": true, + "ppc64le": true, + "riscv": true, + "riscv64": true, + "s390": true, + "s390x": true, + "sparc": true, + "sparc64": true, + "wasm": true, +} From 3bb90a278a09c889fe936b2c5053116e48312ba2 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Sun, 13 Feb 2022 21:27:58 -0800 Subject: [PATCH 029/276] spec: clarifications based on feedback This change includes several smaller changes based on feedback received so far. These changes were reviewed at CL 385536. The only additional change here is to the current date in the subtitle. Change-Id: I653eb4a143e3b86c5357a2fd3b19168419c9f432 Reviewed-on: https://go-review.googlesource.com/c/go/+/390634 Trust: Robert Griesemer Run-TryBot: Robert Griesemer TryBot-Result: Gopher Robot Reviewed-by: Ian Lance Taylor --- doc/go_spec.html | 82 ++++++++++++++++++++++-------------------------- 1 file changed, 38 insertions(+), 44 deletions(-) diff --git a/doc/go_spec.html b/doc/go_spec.html index 6c6f982854a..e8061f94b92 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,6 +1,6 @@ @@ -987,7 +987,7 @@

Slice types

-A new, initialized slice value for a given element type T is +A new, initialized slice value for a given element type T may be made using the built-in function make, which takes a slice type @@ -1422,7 +1422,7 @@

General interfaces

~int } -// An interface representing all types with underlying type int which implement the String method. +// An interface representing all types with underlying type int that implement the String method. interface { ~int String() string @@ -1455,32 +1455,32 @@

General interfaces

-// The Floats interface represents all floating-point types
+// The Float interface represents all floating-point types
 // (including any named types whose underlying types are
 // either float32 or float64).
-type Floats interface {
+type Float interface {
 	~float32 | ~float64
 }
 

-In a union, a term cannot be a type parameter, and the type sets of all +In a union, a term cannot be a type parameter, and the type sets of all non-interface terms must be pairwise disjoint (the pairwise intersection of the type sets must be empty). Given a type parameter P:

 interface {
-	P                 // illegal: the term P is a type parameter
-	int | P           // illegal: the term P is a type parameter
-	~int | MyInt      // illegal: the type sets for ~int and MyInt are not disjoint (~int includes MyInt)
-	float32 | Floats  // overlapping type sets but Floats is an interface
+	P                // illegal: P is a type parameter
+	int | P          // illegal: P is a type parameter
+	~int | MyInt     // illegal: the type sets for ~int and MyInt are not disjoint (~int includes MyInt)
+	float32 | Float  // overlapping type sets but Float is an interface
 }
 

Implementation restriction: -A union with more than one term cannot contain the +A union (with more than one term) cannot contain the predeclared identifier comparable or interfaces that specify methods, or embed comparable or interfaces that specify methods. @@ -1494,12 +1494,12 @@

General interfaces

-var x Floats                     // illegal: Floats is not a basic interface
+var x Float                     // illegal: Float is not a basic interface
 
-var x interface{} = Floats(nil)  // illegal
+var x interface{} = Float(nil)  // illegal
 
 type Floatish struct {
-	f Floats                 // illegal
+	f Float                 // illegal
 }
 
@@ -1545,7 +1545,7 @@

Implementing an interface

-A value x of type T implements an interface if T +A value of type T implements an interface if T implements the interface.

@@ -1701,10 +1701,9 @@

Underlying types

is one of the predeclared boolean, numeric, or string types, or a type literal, the corresponding underlying type is T itself. Otherwise, T's underlying type is the underlying type of the -type to which T refers in its type -declaration. The underlying type of a type parameter is the -underlying type of its type constraint, which -is always an interface. +type to which T refers in its declaration. +For a type parameter that is the underlying type of its +type constraint, which is always an interface.

@@ -1755,7 +1754,7 @@ 

Core types

-All other interfaces don't have a core type. +No other interfaces have a core type.

@@ -1795,7 +1794,7 @@

Core types

-Examples of interfaces whithout core types: +Examples of interfaces without core types:

@@ -1973,21 +1972,21 @@ 

Type identity

Assignability

-A value x is assignable to a variable of type T +A value x of type V is assignable to a variable of type T ("x is assignable to T") if one of the following conditions applies:

  • -x's type is identical to T. +V and T are identical.
  • -x's type V and T have identical +V and T have identical underlying types and at least one of V or T is not a named type.
  • -x's type V and T are channel types with +V and T are channel types with identical element types, V is a bidirectional channel, and at least one of V or T is not a named type.
  • @@ -2220,13 +2219,13 @@

    Declarations and scope

  • The scope of an identifier denoting a method receiver, function parameter, or result variable is the function body.
  • -
  • The scope of an identifier denoting a type parameter of a generic function +
  • The scope of an identifier denoting a type parameter of a function or declared by a method receiver is the function body and all parameter lists of the function.
  • -
  • The scope of an identifier denoting a type parameter of a generic type - begins after the name of the generic type and ends at the end +
  • The scope of an identifier denoting a type parameter of a type + begins after the name of the type and ends at the end of the TypeSpec.
  • The scope of a constant or variable identifier declared @@ -2512,7 +2511,7 @@

    Type definitions

    type TreeNode struct { left, right *TreeNode - value *Comparable + value any } type Block interface { @@ -2584,15 +2583,10 @@

    Type definitions

    next *List[T] value T } - -type Tree[T constraints.Ordered] struct { - left, right *Tree[T] - value T -}

-The given type cannot be a type parameter in a type definition. +In a type definition the given type cannot be a type parameter.

@@ -2604,8 +2598,8 @@ 

Type definitions

-A generic type may also have methods associated with it. In this case, -the method receivers must declare the same number of type parameters as +A generic type may also have methods associated with it. +In this case, the method receivers must declare the same number of type parameters as present in the generic type definition.

@@ -2899,12 +2893,12 @@

Function declarations

If the function declaration specifies type parameters, the function name denotes a generic function. -Generic functions must be instantiated when they -are used. +A generic function must be instantiated before it can be +called or used as a value.

-func min[T constraints.Ordered](x, y T) T {
+func min[T ~int|~float64](x, y T) T {
 	if x < y {
 		return x
 	}
@@ -2963,7 +2957,7 @@ 

Method declarations

-Given defined type Point, the declarations +Given defined type Point the declarations

@@ -3758,7 +3752,7 @@ 

Index expressions

-If a is not a map: +If a is neither a map nor a type parameter:

  • the index x must be an untyped constant or its @@ -4298,7 +4292,7 @@

    Instantiations

    -func min[T constraints.Ordered](x, y T) T { … }
    +func min[T ~int|~float64](x, y T) T { … }
     
     f := min                   // illegal: min must be instantiated when used without being called
     minInt := min[int]         // minInt has type func(x, y int) int
    @@ -4550,7 +4544,7 @@ 

    Function argument type inference

    -func min[T constraints.Ordered](x, y T) T
    +func min[T ~int|~float64](x, y T) T
     
     var x int
     min(x, 2.0)    // T is int, inferred from typed argument x; 2.0 is assignable to int
    
    From 079a027d27a9eed18c99c0c6a6e2fc70f9dd07b7 Mon Sep 17 00:00:00 2001
    From: Jorropo 
    Date: Mon, 7 Mar 2022 12:56:01 +0000
    Subject: [PATCH 030/276] io: add WriterTo to MultiReader
    MIME-Version: 1.0
    Content-Type: text/plain; charset=UTF-8
    Content-Transfer-Encoding: 8bit
    
    This patch allows to zerocopy using MultiReader.
    This is done by MultiReader implementing WriterTo.
    
    Each sub reader is copied using usual io copy helper and thus use
    WriterTo or ReadFrom with reflection.
    
    There is a special case for when a subreader is a MultiReader.
    Instead of using copyBuffer which would call multiReader.WriteTo,
    multiReader.writeToWithBuffer is used instead, the difference
    is that the temporary copy buffer is passed along, saving
    allocations for nested MultiReaders.
    
    The workflow looks like this:
    - multiReader.WriteTo (allocates 32k buffer)
      - multiReader.writeToWithBuffer
        - for each subReader:
          - is instance of multiReader ?
            - yes, call multiReader.writeToWithBuffer
            - no, call copyBuffer(writer, currentReader, buffer)
              - does currentReader implements WriterTo ?
               - yes, use use currentReader.WriteTo
               - no, does writer implement ReadFrom ?
                 - yes, use writer.ReadFrom
                 - no, copy using Read / Write with buffer
    
    This can be improved by lazy allocating the 32k buffer.
    For example a MultiReader of such types:
      MultiReader(
        bytes.Reader, // WriterTo-able
        bytes.Reader, // WriterTo-able
        bytes.Reader, // WriterTo-able
      )
    
    Doesn't need any allocation, all copy can be done using bytes.Reader's
    internal data slice. However currently we still allocate a 32k buffer
    for nothing.
    
    This optimisation has been omitted for a future patch because of high
    complexity costs for a non obvious performance cost (it needs a benchmark).
    This patch at least is on par with the previous MultiReader.Read
    workflow allocation wise.
    
    Fixes #50842
    
    Change-Id: Ib070c8f36337d9dd86090df8a703c5df97a773ae
    GitHub-Last-Rev: 8ebe60ceacec6bd52b63d9bdc05cd5b4ada57a6e
    GitHub-Pull-Request: golang/go#51502
    Reviewed-on: https://go-review.googlesource.com/c/go/+/390215
    Run-TryBot: Ian Lance Taylor 
    TryBot-Result: Gopher Robot 
    Reviewed-by: Ian Lance Taylor 
    Reviewed-by: Daniel Martí 
    Trust: Daniel Martí 
    ---
     src/io/multi.go      | 25 +++++++++++++++++++++++++
     src/io/multi_test.go | 25 +++++++++++++++++++++++++
     2 files changed, 50 insertions(+)
    
    diff --git a/src/io/multi.go b/src/io/multi.go
    index 24ee71e4ca6..909b7e45233 100644
    --- a/src/io/multi.go
    +++ b/src/io/multi.go
    @@ -41,6 +41,31 @@ func (mr *multiReader) Read(p []byte) (n int, err error) {
     	return 0, EOF
     }
     
    +func (mr *multiReader) WriteTo(w Writer) (sum int64, err error) {
    +	return mr.writeToWithBuffer(w, make([]byte, 1024 * 32))
    +}
    +
    +func (mr *multiReader) writeToWithBuffer(w Writer, buf []byte) (sum int64, err error) {
    +	for i, r := range mr.readers {
    +		var n int64
    +		if subMr, ok := r.(*multiReader); ok { // reuse buffer with nested multiReaders
    +			n, err = subMr.writeToWithBuffer(w, buf)
    +		} else {
    +			n, err = copyBuffer(w, r, buf)
    +		}
    +		sum += n
    +		if err != nil {
    +			mr.readers = mr.readers[i:] // permit resume / retry after error
    +			return sum, err
    +		}
    +		mr.readers[i] = nil // permit early GC
    +	}
    +	mr.readers = nil
    +	return sum, nil
    +}
    +
    +var _ WriterTo = (*multiReader)(nil)
    +
     // MultiReader returns a Reader that's the logical concatenation of
     // the provided input readers. They're read sequentially. Once all
     // inputs have returned EOF, Read will return EOF.  If any of the readers
    diff --git a/src/io/multi_test.go b/src/io/multi_test.go
    index e877e54571c..679312c23b0 100644
    --- a/src/io/multi_test.go
    +++ b/src/io/multi_test.go
    @@ -63,6 +63,31 @@ func TestMultiReader(t *testing.T) {
     	})
     }
     
    +func TestMultiReaderAsWriterTo(t *testing.T) {
    +	mr := MultiReader(
    +		strings.NewReader("foo "),
    +		MultiReader( // Tickle the buffer reusing codepath
    +			strings.NewReader(""),
    +			strings.NewReader("bar"),
    +		),
    +	)
    +	mrAsWriterTo, ok := mr.(WriterTo)
    +	if !ok {
    +		t.Fatalf("expected cast to WriterTo to succeed")
    +	}
    +	sink := &strings.Builder{}
    +	n, err := mrAsWriterTo.WriteTo(sink)
    +	if err != nil {
    +		t.Fatalf("expected no error; got %v", err)
    +	}
    +	if n != 7 {
    +		t.Errorf("expected read 7 bytes; got %d", n)
    +	}
    +	if result := sink.String(); result != "foo bar" {
    +		t.Errorf(`expected "foo bar"; got %q`, result)
    +	}
    +}
    +
     func TestMultiWriter(t *testing.T) {
     	sink := new(bytes.Buffer)
     	// Hide bytes.Buffer's WriteString method:
    
    From d9d55724bd8ff10d8de5c13fd77122a37ac73719 Mon Sep 17 00:00:00 2001
    From: "Paul E. Murphy" 
    Date: Thu, 3 Mar 2022 15:41:57 -0600
    Subject: [PATCH 031/276] internal/cpu: set PPC64.IsPOWER8
    
    This should always be true, but use the HWCAP2 bit anyways.
    
    Change-Id: Ib164cf05b4c9f0c509f41b7eb339ef32fb63e384
    Reviewed-on: https://go-review.googlesource.com/c/go/+/389894
    Trust: Paul Murphy 
    Run-TryBot: Paul Murphy 
    TryBot-Result: Gopher Robot 
    Reviewed-by: Cherry Mui 
    ---
     src/internal/cpu/cpu_ppc64x_linux.go | 2 ++
     1 file changed, 2 insertions(+)
    
    diff --git a/src/internal/cpu/cpu_ppc64x_linux.go b/src/internal/cpu/cpu_ppc64x_linux.go
    index 7999656f01f..0fe86678433 100644
    --- a/src/internal/cpu/cpu_ppc64x_linux.go
    +++ b/src/internal/cpu/cpu_ppc64x_linux.go
    @@ -15,6 +15,7 @@ var HWCap2 uint
     // HWCAP bits. These are exposed by Linux.
     const (
     	// ISA Level
    +	hwcap2_ARCH_2_07 = 0x80000000
     	hwcap2_ARCH_3_00 = 0x00800000
     
     	// CPU features
    @@ -23,6 +24,7 @@ const (
     )
     
     func osinit() {
    +	PPC64.IsPOWER8 = isSet(HWCap2, hwcap2_ARCH_2_07)
     	PPC64.IsPOWER9 = isSet(HWCap2, hwcap2_ARCH_3_00)
     	PPC64.HasDARN = isSet(HWCap2, hwcap2_DARN)
     	PPC64.HasSCV = isSet(HWCap2, hwcap2_SCV)
    
    From 0043c1efbb53e72cbd1b41c32812ca3c78d8e169 Mon Sep 17 00:00:00 2001
    From: Dmitri Shuralyov 
    Date: Tue, 8 Mar 2022 00:08:49 +0000
    Subject: [PATCH 032/276] fmt: use tabs for indentation
    
    Replace 24 spaces added in CL 389434 with 3 tabs,
    so the new line is indented like other lines around it.
    
    Updates #51419.
    
    Change-Id: Ic3e50023a01f233c52dda53c36de2c461222d95c
    Reviewed-on: https://go-review.googlesource.com/c/go/+/390674
    Trust: Dmitri Shuralyov 
    Run-TryBot: Dmitri Shuralyov 
    Auto-Submit: Dmitri Shuralyov 
    TryBot-Result: Gopher Robot 
    Reviewed-by: Adam Shannon 
    Reviewed-by: Ian Lance Taylor 
    ---
     src/fmt/doc.go | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)
    
    diff --git a/src/fmt/doc.go b/src/fmt/doc.go
    index 4a095557344..a7bd02b627f 100644
    --- a/src/fmt/doc.go
    +++ b/src/fmt/doc.go
    @@ -125,7 +125,7 @@
     			put spaces between bytes printing strings or slices in hex (% x, % X)
     		0	pad with leading zeros rather than spaces;
     			for numbers, this moves the padding after the sign;
    -                        ignored for strings, byte slices and byte arrays
    +			ignored for strings, byte slices and byte arrays
     
     	Flags are ignored by verbs that do not expect them.
     	For example there is no alternate decimal format, so %#d and %d
    
    From 31be6285a879af94c7283e6599e3f9b64266bc1a Mon Sep 17 00:00:00 2001
    From: eric fang 
    Date: Tue, 18 Jan 2022 08:49:56 +0000
    Subject: [PATCH 033/276] cmd/internal/obj/arm64: optimize stacksplit prologue
     for small stack
    
    When framesize <= objabi.StackSmall, 128B, the stacksplit prologue is:
      MOVD	16(g), R16
      MOVD	SP, R17
      CMP	R16, R17
      BLS	morestack_label
    
    The second instruction is not necessary, we can compare R16 with SP
    directly, so the sequence becomes:
      MOVD	16(g), R16
      CMP	R16, SP
      BLS	morestack_label
    
    This CL removes this instruction.
    
    Change-Id: I0567ac52e9be124880957271951e1186da203612
    Reviewed-on: https://go-review.googlesource.com/c/go/+/379076
    Trust: Eric Fang 
    Run-TryBot: Eric Fang 
    TryBot-Result: Gopher Robot 
    Reviewed-by: Eric Fang 
    Reviewed-by: Cherry Mui 
    ---
     src/cmd/internal/obj/arm64/obj7.go | 12 ++----------
     1 file changed, 2 insertions(+), 10 deletions(-)
    
    diff --git a/src/cmd/internal/obj/arm64/obj7.go b/src/cmd/internal/obj/arm64/obj7.go
    index e9eb786cb24..2bbc7e37b0b 100644
    --- a/src/cmd/internal/obj/arm64/obj7.go
    +++ b/src/cmd/internal/obj/arm64/obj7.go
    @@ -165,21 +165,13 @@ func (c *ctxt7) stacksplit(p *obj.Prog, framesize int32) *obj.Prog {
     	q := (*obj.Prog)(nil)
     	if framesize <= objabi.StackSmall {
     		// small stack: SP < stackguard
    -		//	MOV	SP, RT2
    -		//	CMP	stackguard, RT2
    -		p = obj.Appendp(p, c.newprog)
    -
    -		p.As = AMOVD
    -		p.From.Type = obj.TYPE_REG
    -		p.From.Reg = REGSP
    -		p.To.Type = obj.TYPE_REG
    -		p.To.Reg = REGRT2
    +		//	CMP	stackguard, SP
     
     		p = obj.Appendp(p, c.newprog)
     		p.As = ACMP
     		p.From.Type = obj.TYPE_REG
     		p.From.Reg = REGRT1
    -		p.Reg = REGRT2
    +		p.Reg = REGSP
     	} else if framesize <= objabi.StackBig {
     		// large stack: SP-framesize < stackguard-StackSmall
     		//	SUB	$(framesize-StackSmall), SP, RT2
    
    From 6e63be7b69aab25ac66029e7dfec47303d3b7505 Mon Sep 17 00:00:00 2001
    From: Robert Griesemer 
    Date: Mon, 7 Mar 2022 14:48:28 -0800
    Subject: [PATCH 034/276] spec: document that type inference doesn't apply to
     generic types
    
    Type inference for types was always a "nice to have" feature.
    Given the under-appreciated complexity of making it work in all
    cases, and the fact that we don't have a good understanding of
    how it might affect readability of generic code, require explicit
    type arguments for generic types.
    
    This matches the current implementation.
    
    Change-Id: Ie7ff6293d3fbea92ddc54c46285a4cabece7fe01
    Reviewed-on: https://go-review.googlesource.com/c/go/+/390577
    Trust: Robert Griesemer 
    Run-TryBot: Robert Griesemer 
    TryBot-Result: Gopher Robot 
    Reviewed-by: Ian Lance Taylor 
    Reviewed-by: Robert Findley 
    ---
     doc/go_spec.html | 61 +++++++++++++++++++++++-------------------------
     1 file changed, 29 insertions(+), 32 deletions(-)
    
    diff --git a/doc/go_spec.html b/doc/go_spec.html
    index e8061f94b92..6278b8252de 100644
    --- a/doc/go_spec.html
    +++ b/doc/go_spec.html
    @@ -11,11 +11,6 @@ 

    Earlier version

    The Go Programming Language Specification.

    - -

    -[For reviewers: Sections where we know of missing prose are marked like this. The markers will be removed before the release.] -

    -

    Introduction

    @@ -4230,7 +4225,7 @@

    Instantiations

    A generic function or type is instantiated by substituting type arguments for the type parameters. -Instantiation proceeds in two phases: +Instantiation proceeds in two steps:

      @@ -4262,31 +4257,12 @@

      Instantiations

    -Type arguments may be provided explicitly, or they may be partially or completely -inferred. -A partially provided type argument list cannot be empty; there must be at least the -first argument. -

    - -
    -type T[P1 ~int, P2 ~[]P1] struct{ … }
    -
    -T[]            // illegal: at least the first type argument must be present, even if it could be inferred
    -T[int]         // argument for P1 explicitly provided, argument for P2 inferred
    -T[int, []int]  // both arguments explicitly provided
    -
    - -

    -A partial type argument list specifies a prefix of the full list of type arguments, leaving -the remaining arguments to be inferred. Loosely speaking, type arguments may be omitted from -"right to left". -

    - -

    -Generic types, and generic functions that are not called, -require a type argument list for instantiation; if the list is partial, all +For a generic function, type arguments may be provided explicitly, or they +may be partially or completely inferred. +A generic function that is is not called requires a +type argument list for instantiation; if the list is partial, all remaining type arguments must be inferrable. -Calls to generic functions may provide a (possibly partial) type +A generic function that is called may provide a (possibly partial) type argument list, or may omit it entirely if the omitted type arguments are inferrable from the ordinary (non-type) function arguments.

    @@ -4294,17 +4270,38 @@

    Instantiations

     func min[T ~int|~float64](x, y T) T { … }
     
    -f := min                   // illegal: min must be instantiated when used without being called
    +f := min                   // illegal: min must be instantiated with type arguments when used without being called
     minInt := min[int]         // minInt has type func(x, y int) int
     a := minInt(2, 3)          // a has value 2 of type int
     b := min[float64](2.0, 3)  // b has value 2.0 of type float64
     c := min(b, -1)            // c has value -1.0 of type float64
     
    +

    +A partial type argument list cannot be empty; at least the first argument must be present. +The list is a prefix of the full list of type arguments, leaving the remaining arguments +to be inferred. Loosely speaking, type arguments may be omitted from "right to left". +

    + +
    +func apply[S ~[]E, E any](s S, f(E) E) S { … }
    +
    +f0 := apply[]                  // illegal: type argument list cannot be empty
    +f1 := apply[[]int]             // type argument for S explicitly provided, type argument for E inferred
    +f2 := apply[[]string, string]  // both type arguments explicitly provided
    +
    +var bytes []byte
    +r := apply(bytes, func(byte) byte { … })  // both type arguments inferred from the function arguments
    +
    + +

    +For a generic type, all type arguments must always be provided explicitly. +

    +

    Type inference

    -Missing type arguments may be inferred by a series of steps, described below. +Missing function type arguments may be inferred by a series of steps, described below. Each step attempts to use known information to infer additional type arguments. Type inference stops as soon as all type arguments are known. After type inference is complete, it is still necessary to substitute all type arguments From 0b76afc75ca687fcd9a1a8e0b19670fb8f37fecb Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Tue, 22 Feb 2022 17:07:49 -0500 Subject: [PATCH 035/276] crypto/rand: simplify Prime to use only rejection sampling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The old code picks a random number n and then tests n, n+2, n+4, up to n+(1<<20) for primality before giving up and picking a new n. (The chance of finishing the loop and picking a new n is infinitesimally small.) This approach, called “incremental search” in the Handbook of Applied Cryptography, section 4.51, demands fewer bits from the random source and amortizes some of the cost of the small-prime division checks across the incremented values. This commit deletes the n+2, n+4, ... checks, instead picking a series of random n and stopping at the first one that is probably prime. This approach is called “rejection sampling.” Reasons to make this change, in decreasing order of importance: 1. Rejection sampling is simpler, and simpler is more clearly correct. 2. The main benefit of incremental search was performance, and that is less important than before. Incremental search required fewer random bits and was able to amortize the checks for small primes across the entire sequence. However, both random bit generation and primality checks have gotten faster much quicker than typical primes have gotten longer, so the benefits are not as important today. Also, random prime generation is not typically on the critical path. Negating any lingering concerns about performance, rejection sampling no slower in practice than the incremental search, perhaps because the incremental search was using a somewhat inefficient test to eliminate multiples of small primes; ProbablyPrime does it better. name old time/op new time/op delta Prime/MathRand 69.3ms ±23% 68.0ms ±37% ~ (p=0.531 n=20+19) Prime/CryptoRand 69.2ms ±27% 63.8ms ±36% ~ (p=0.076 n=20+20) (Here, Prime/MathRand is the current Prime benchmark, and Prime/CryptoRand is an adaptation to use crypto/rand.Reader instead of math/rand's non-cryptographic randomness source, just in case the quality of the bits affects the outcome. If anything, rejection sampling is even better with cryptographically random bits, but really the two are statistically indistinguishable over 20 runs.) 3. Incremental search has a clear bias when generating small primes: a prime is more likely to be returned the larger the gap between it and the next smaller prime. Although the bias is negligible in practice for cryptographically large primes, people can measure the bias for smaller prime sizes, and we have received such reports extrapolating the bias to larger sizes and claiming a security bug (which, to be clear, does not exist). However, given that rejection sampling is simpler, more clearly correct and at least no slower than incremental search, the bias is indefensible. 4. Incremental search has a timing leak. If you can tell the incremental search ran 10 times, then you know that p is such that there are no primes in the range [p-20, p). To be clear, there are other timing leaks in our current primality testing, so there's no definitive benefit to eliminating this one, but there's also no reason to keep it around. (See https://bugs.chromium.org/p/boringssl/issues/detail?id=238 for all the work that would be needed to make RSA key generation constant-time, which is definitely not something we have planned for Go crypto.) 5. Rejection sampling moves from matching OpenSSL to matching BoringSSL. As a general rule BoringSSL is the better role model. (Everyone started out using incremental search; BoringSSL switched to rejection sampling in 2019, as part of the constant-time work linked above.) Change-Id: Ie67e572a967c12d8728c752045c7e38f21804f8e Reviewed-on: https://go-review.googlesource.com/c/go/+/387554 Trust: Russ Cox Run-TryBot: Russ Cox Reviewed-by: Peter Weinberger Reviewed-by: Filippo Valsorda TryBot-Result: Gopher Robot Auto-Submit: Russ Cox --- src/crypto/rand/util.go | 61 +++++------------------------------------ 1 file changed, 7 insertions(+), 54 deletions(-) diff --git a/src/crypto/rand/util.go b/src/crypto/rand/util.go index 4dd17112034..0f143a38302 100644 --- a/src/crypto/rand/util.go +++ b/src/crypto/rand/util.go @@ -10,28 +10,11 @@ import ( "math/big" ) -// smallPrimes is a list of small, prime numbers that allows us to rapidly -// exclude some fraction of composite candidates when searching for a random -// prime. This list is truncated at the point where smallPrimesProduct exceeds -// a uint64. It does not include two because we ensure that the candidates are -// odd by construction. -var smallPrimes = []uint8{ - 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, -} - -// smallPrimesProduct is the product of the values in smallPrimes and allows us -// to reduce a candidate prime by this number and then determine whether it's -// coprime to all the elements of smallPrimes without further big.Int -// operations. -var smallPrimesProduct = new(big.Int).SetUint64(16294579238595022365) - -// Prime returns a number, p, of the given size, such that p is prime -// with high probability. +// Prime returns a number of the given bit length that is prime with high probability. // Prime will return error for any error returned by rand.Read or if bits < 2. -func Prime(rand io.Reader, bits int) (p *big.Int, err error) { +func Prime(rand io.Reader, bits int) (*big.Int, error) { if bits < 2 { - err = errors.New("crypto/rand: prime size must be at least 2-bit") - return + return nil, errors.New("crypto/rand: prime size must be at least 2-bit") } b := uint(bits % 8) @@ -40,13 +23,10 @@ func Prime(rand io.Reader, bits int) (p *big.Int, err error) { } bytes := make([]byte, (bits+7)/8) - p = new(big.Int) - - bigMod := new(big.Int) + p := new(big.Int) for { - _, err = io.ReadFull(rand, bytes) - if err != nil { + if _, err := io.ReadFull(rand, bytes); err != nil { return nil, err } @@ -69,35 +49,8 @@ func Prime(rand io.Reader, bits int) (p *big.Int, err error) { bytes[len(bytes)-1] |= 1 p.SetBytes(bytes) - - // Calculate the value mod the product of smallPrimes. If it's - // a multiple of any of these primes we add two until it isn't. - // The probability of overflowing is minimal and can be ignored - // because we still perform Miller-Rabin tests on the result. - bigMod.Mod(p, smallPrimesProduct) - mod := bigMod.Uint64() - - NextDelta: - for delta := uint64(0); delta < 1<<20; delta += 2 { - m := mod + delta - for _, prime := range smallPrimes { - if m%uint64(prime) == 0 && (bits > 6 || m != uint64(prime)) { - continue NextDelta - } - } - - if delta > 0 { - bigMod.SetUint64(delta) - p.Add(p, bigMod) - } - break - } - - // There is a tiny possibility that, by adding delta, we caused - // the number to be one bit too long. Thus we check BitLen - // here. - if p.ProbablyPrime(20) && p.BitLen() == bits { - return + if p.ProbablyPrime(20) { + return p, nil } } } From 7fd9564fcd3715a2aaf2bf4df1096f71ff40ef15 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Tue, 22 Feb 2022 14:43:41 -0500 Subject: [PATCH 036/276] cmd/compile: allow fieldtrack of unexported fields The fieldtrack support is experimental and used mainly inside Google, where we have included this change for years. No reason not to make it in the public copy. Change-Id: I5233e4e775ccce60a17098c007aed8c82a0425d7 Reviewed-on: https://go-review.googlesource.com/c/go/+/387355 Trust: Russ Cox Run-TryBot: Russ Cox TryBot-Result: Gopher Robot Reviewed-by: Ian Lance Taylor --- src/cmd/compile/internal/walk/expr.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/cmd/compile/internal/walk/expr.go b/src/cmd/compile/internal/walk/expr.go index e5bf6cf0b5e..43201dbd3d4 100644 --- a/src/cmd/compile/internal/walk/expr.go +++ b/src/cmd/compile/internal/walk/expr.go @@ -1012,9 +1012,6 @@ func usefield(n *ir.SelectorExpr) { if outer.Sym() == nil { base.Errorf("tracked field must be in named struct type") } - if !types.IsExported(field.Sym.Name) { - base.Errorf("tracked field must be exported (upper case)") - } sym := reflectdata.TrackSym(outer, field) if ir.CurFunc.FieldTrack == nil { From 3c42ebf3e2dccbe228b78ca2e157010a7d3c5b9d Mon Sep 17 00:00:00 2001 From: Joel Sing Date: Fri, 21 Jan 2022 18:34:03 +1100 Subject: [PATCH 037/276] internal/bytealg: optimise memequal on riscv64 Implement memequal using loops that process 32 bytes, 16 bytes, 4 bytes or 1 byte depending on size and alignment. For comparisons that are less than 32 bytes the overhead of checking and adjusting alignment usually exceeds the overhead of reading and processing 4 bytes at a time. Updates #50615 name old time/op new time/op delta Equal/0-4 38.3ns _ 0% 43.1ns _ 0% +12.54% (p=0.000 n=3+3) Equal/1-4 77.7ns _ 0% 90.3ns _ 0% +16.27% (p=0.000 n=3+3) Equal/6-4 116ns _ 0% 121ns _ 0% +3.85% (p=0.002 n=3+3) Equal/9-4 137ns _ 0% 126ns _ 0% -7.98% (p=0.000 n=3+3) Equal/15-4 179ns _ 0% 170ns _ 0% -4.77% (p=0.001 n=3+3) Equal/16-4 186ns _ 0% 159ns _ 0% -14.65% (p=0.000 n=3+3) Equal/20-4 215ns _ 0% 178ns _ 0% -17.18% (p=0.000 n=3+3) Equal/32-4 298ns _ 0% 101ns _ 0% -66.22% (p=0.000 n=3+3) Equal/4K-4 28.9_s _ 0% 2.2_s _ 0% -92.56% (p=0.000 n=3+3) Equal/4M-4 29.6ms _ 0% 2.2ms _ 0% -92.72% (p=0.000 n=3+3) Equal/64M-4 758ms _75% 35ms _ 0% ~ (p=0.127 n=3+3) CompareBytesEqual-4 226ns _ 0% 131ns _ 0% -41.76% (p=0.000 n=3+3) name old speed new speed delta Equal/1-4 12.9MB/s _ 0% 11.1MB/s _ 0% -13.98% (p=0.000 n=3+3) Equal/6-4 51.7MB/s _ 0% 49.8MB/s _ 0% -3.72% (p=0.002 n=3+3) Equal/9-4 65.7MB/s _ 0% 71.4MB/s _ 0% +8.67% (p=0.000 n=3+3) Equal/15-4 83.8MB/s _ 0% 88.0MB/s _ 0% +5.02% (p=0.001 n=3+3) Equal/16-4 85.9MB/s _ 0% 100.6MB/s _ 0% +17.19% (p=0.000 n=3+3) Equal/20-4 93.2MB/s _ 0% 112.6MB/s _ 0% +20.74% (p=0.000 n=3+3) Equal/32-4 107MB/s _ 0% 317MB/s _ 0% +195.97% (p=0.000 n=3+3) Equal/4K-4 142MB/s _ 0% 1902MB/s _ 0% +1243.76% (p=0.000 n=3+3) Equal/4M-4 142MB/s _ 0% 1946MB/s _ 0% +1274.22% (p=0.000 n=3+3) Equal/64M-4 111MB/s _55% 1941MB/s _ 0% +1641.21% (p=0.000 n=3+3) Change-Id: I9af7e82de3c4c5af8813772ed139230900c03b92 Reviewed-on: https://go-review.googlesource.com/c/go/+/380075 Trust: Joel Sing Trust: mzh Reviewed-by: mzh Run-TryBot: Joel Sing TryBot-Result: Gopher Robot Reviewed-by: Cherry Mui --- src/internal/bytealg/equal_riscv64.s | 144 +++++++++++++++++++++------ 1 file changed, 111 insertions(+), 33 deletions(-) diff --git a/src/internal/bytealg/equal_riscv64.s b/src/internal/bytealg/equal_riscv64.s index 22cb4fa97d8..959a996f81e 100644 --- a/src/internal/bytealg/equal_riscv64.s +++ b/src/internal/bytealg/equal_riscv64.s @@ -9,41 +9,119 @@ // func memequal(a, b unsafe.Pointer, size uintptr) bool TEXT runtime·memequal(SB),NOSPLIT|NOFRAME,$0-25 - MOV a+0(FP), A1 - MOV b+8(FP), A2 - BEQ A1, A2, eq - MOV size+16(FP), A3 - ADD A1, A3, A4 -loop: - BEQ A1, A4, eq - - MOVBU (A1), A6 - ADD $1, A1 - MOVBU (A2), A7 - ADD $1, A2 - BEQ A6, A7, loop - - MOVB ZERO, ret+24(FP) - RET -eq: - MOV $1, A1 - MOVB A1, ret+24(FP) - RET + MOV a+0(FP), X5 + MOV b+8(FP), X6 + MOV size+16(FP), X7 + MOV $ret+24(FP), X19 + JMP memequal<>(SB) // func memequal_varlen(a, b unsafe.Pointer) bool -TEXT runtime·memequal_varlen(SB),NOSPLIT,$40-17 - MOV a+0(FP), A1 - MOV b+8(FP), A2 - BEQ A1, A2, eq - MOV 8(CTXT), A3 // compiler stores size at offset 8 in the closure - MOV A1, 8(X2) - MOV A2, 16(X2) - MOV A3, 24(X2) - CALL runtime·memequal(SB) - MOVBU 32(X2), A1 - MOVB A1, ret+16(FP) +TEXT runtime·memequal_varlen(SB),NOSPLIT|NOFRAME,$0-17 + MOV a+0(FP), X5 + MOV b+8(FP), X6 + MOV 8(CTXT), X7 // compiler stores size at offset 8 in the closure + MOV $ret+16(FP), X19 + JMP memequal<>(SB) + +// On entry X5 and X6 contain pointers, X7 contains length. +// X19 contains address for return value. +TEXT memequal<>(SB),NOSPLIT|NOFRAME,$0 + BEQ X5, X6, eq + + MOV $32, X8 + BLT X7, X8, loop4_check + + // Check alignment - if alignment differs we have to do one byte at a time. + AND $3, X5, X9 + AND $3, X6, X10 + BNE X9, X10, loop4_check + BEQZ X9, loop32_check + + // Check one byte at a time until we reach 8 byte alignment. + SUB X9, X7, X7 +align: + ADD $-1, X9 + MOVBU 0(X5), X10 + MOVBU 0(X6), X11 + BNE X10, X11, not_eq + ADD $1, X5 + ADD $1, X6 + BNEZ X9, align + +loop32_check: + MOV $32, X9 + BLT X7, X9, loop16_check +loop32: + MOV 0(X5), X10 + MOV 0(X6), X11 + MOV 8(X5), X12 + MOV 8(X6), X13 + BNE X10, X11, not_eq + BNE X12, X13, not_eq + MOV 16(X5), X14 + MOV 16(X6), X15 + MOV 24(X5), X16 + MOV 24(X6), X17 + BNE X14, X15, not_eq + BNE X16, X17, not_eq + ADD $32, X5 + ADD $32, X6 + ADD $-32, X7 + BGE X7, X9, loop32 + BEQZ X7, eq + +loop16_check: + MOV $16, X8 + BLT X7, X8, loop4_check +loop16: + MOV 0(X5), X10 + MOV 0(X6), X11 + MOV 8(X5), X12 + MOV 8(X6), X13 + BNE X10, X11, not_eq + BNE X12, X13, not_eq + ADD $16, X5 + ADD $16, X6 + ADD $-16, X7 + BGE X7, X8, loop16 + BEQZ X7, eq + +loop4_check: + MOV $4, X8 + BLT X7, X8, loop1 +loop4: + MOVBU 0(X5), X10 + MOVBU 0(X6), X11 + MOVBU 1(X5), X12 + MOVBU 1(X6), X13 + BNE X10, X11, not_eq + BNE X12, X13, not_eq + MOVBU 2(X5), X14 + MOVBU 2(X6), X15 + MOVBU 3(X5), X16 + MOVBU 3(X6), X17 + BNE X14, X15, not_eq + BNE X16, X17, not_eq + ADD $4, X5 + ADD $4, X6 + ADD $-4, X7 + BGE X7, X8, loop4 + +loop1: + BEQZ X7, eq + MOVBU 0(X5), X10 + MOVBU 0(X6), X11 + BNE X10, X11, not_eq + ADD $1, X5 + ADD $1, X6 + ADD $-1, X7 + JMP loop1 + +not_eq: + MOV $0, X5 + MOVB X5, (X19) RET eq: - MOV $1, A1 - MOVB A1, ret+16(FP) + MOV $1, X5 + MOVB X5, (X19) RET From 291bda80e551289e0b8ed3209782ccb2a98a124b Mon Sep 17 00:00:00 2001 From: Joel Sing Date: Fri, 21 Jan 2022 19:48:26 +1100 Subject: [PATCH 038/276] internal/bytealg: optimise compare on riscv64 Implement compare using loops that process 32 bytes, 16 bytes, 4 bytes or 1 byte depending on size and alignment. For comparisons that are less than 32 bytes the overhead of checking and adjusting alignment usually exceeds the overhead of reading and processing 4 bytes at a time. Updates #50615 name old time/op new time/op delta BytesCompare/1-4 68.4ns _ 1% 61.0ns _ 0% -10.78% (p=0.001 n=3+3) BytesCompare/2-4 82.9ns _ 0% 71.0ns _ 1% -14.31% (p=0.000 n=3+3) BytesCompare/4-4 107ns _ 0% 70ns _ 0% -34.96% (p=0.000 n=3+3) BytesCompare/8-4 156ns _ 0% 90ns _ 0% -42.36% (p=0.000 n=3+3) BytesCompare/16-4 267ns _11% 130ns _ 0% -51.10% (p=0.011 n=3+3) BytesCompare/32-4 446ns _ 0% 74ns _ 0% -83.31% (p=0.000 n=3+3) BytesCompare/64-4 840ns _ 2% 91ns _ 0% -89.17% (p=0.000 n=3+3) BytesCompare/128-4 1.60_s _ 0% 0.13_s _ 0% -92.18% (p=0.000 n=3+3) BytesCompare/256-4 3.15_s _ 0% 0.19_s _ 0% -93.91% (p=0.000 n=3+3) BytesCompare/512-4 6.25_s _ 0% 0.33_s _ 0% -94.80% (p=0.000 n=3+3) BytesCompare/1024-4 12.5_s _ 0% 0.6_s _ 0% -95.23% (p=0.000 n=3+3) BytesCompare/2048-4 24.8_s _ 0% 1.1_s _ 0% -95.46% (p=0.000 n=3+3) CompareBytesEqual-4 225ns _ 0% 131ns _ 0% -41.69% (p=0.000 n=3+3) CompareBytesToNil-4 45.3ns _ 7% 46.7ns _ 0% ~ (p=0.452 n=3+3) CompareBytesEmpty-4 41.0ns _ 1% 40.6ns _ 0% ~ (p=0.071 n=3+3) CompareBytesIdentical-4 48.9ns _ 0% 41.3ns _ 1% -15.58% (p=0.000 n=3+3) CompareBytesSameLength-4 127ns _ 0% 77ns _ 0% -39.48% (p=0.000 n=3+3) CompareBytesDifferentLength-4 136ns _12% 78ns _ 0% -42.65% (p=0.018 n=3+3) CompareBytesBigUnaligned-4 14.9ms _ 1% 7.3ms _ 1% -50.95% (p=0.000 n=3+3) CompareBytesBig-4 14.9ms _ 1% 2.7ms _ 8% -82.10% (p=0.000 n=3+3) CompareBytesBigIdentical-4 52.5ns _ 0% 44.9ns _ 0% -14.53% (p=0.000 n=3+3) name old speed new speed delta CompareBytesBigUnaligned-4 70.5MB/s _ 1% 143.8MB/s _ 1% +103.87% (p=0.000 n=3+3) CompareBytesBig-4 70.3MB/s _ 1% 393.8MB/s _ 8% +460.43% (p=0.003 n=3+3) CompareBytesBigIdentical-4 20.0TB/s _ 0% 23.4TB/s _ 0% +17.00% (p=0.000 n=3+3) Change-Id: Ie18712a9009d425c75e1ab49d5a673d84e73a1eb Reviewed-on: https://go-review.googlesource.com/c/go/+/380076 Trust: Joel Sing Trust: mzh Reviewed-by: Cherry Mui --- src/internal/bytealg/compare_generic.go | 2 +- src/internal/bytealg/compare_native.go | 2 +- src/internal/bytealg/compare_riscv64.s | 185 ++++++++++++++++++++++++ 3 files changed, 187 insertions(+), 2 deletions(-) create mode 100644 src/internal/bytealg/compare_riscv64.s diff --git a/src/internal/bytealg/compare_generic.go b/src/internal/bytealg/compare_generic.go index eaea168f2de..c5853f503f0 100644 --- a/src/internal/bytealg/compare_generic.go +++ b/src/internal/bytealg/compare_generic.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build !386 && !amd64 && !s390x && !arm && !arm64 && !ppc64 && !ppc64le && !mips && !mipsle && !wasm && !mips64 && !mips64le +//go:build !386 && !amd64 && !s390x && !arm && !arm64 && !ppc64 && !ppc64le && !mips && !mipsle && !wasm && !mips64 && !mips64le && !riscv64 package bytealg diff --git a/src/internal/bytealg/compare_native.go b/src/internal/bytealg/compare_native.go index 21ff8fe786d..ad0fcd7660a 100644 --- a/src/internal/bytealg/compare_native.go +++ b/src/internal/bytealg/compare_native.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build 386 || amd64 || s390x || arm || arm64 || ppc64 || ppc64le || mips || mipsle || wasm || mips64 || mips64le +//go:build 386 || amd64 || s390x || arm || arm64 || ppc64 || ppc64le || mips || mipsle || wasm || mips64 || mips64le || riscv64 package bytealg diff --git a/src/internal/bytealg/compare_riscv64.s b/src/internal/bytealg/compare_riscv64.s new file mode 100644 index 00000000000..0dc62515a17 --- /dev/null +++ b/src/internal/bytealg/compare_riscv64.s @@ -0,0 +1,185 @@ +// Copyright 2022 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. + +#include "go_asm.h" +#include "textflag.h" + +TEXT ·Compare(SB),NOSPLIT|NOFRAME,$0-56 + MOV a_base+0(FP), X5 + MOV a_len+8(FP), X6 + MOV b_base+24(FP), X7 + MOV b_len+32(FP), X8 + MOV $ret+48(FP), X9 + JMP compare<>(SB) + +TEXT runtime·cmpstring(SB),NOSPLIT|NOFRAME,$0-40 + MOV a_base+0(FP), X5 + MOV a_len+8(FP), X6 + MOV b_base+16(FP), X7 + MOV b_len+24(FP), X8 + MOV $ret+32(FP), X9 + JMP compare<>(SB) + +// On entry: +// X5 points to start of a +// X6 length of a +// X7 points to start of b +// X8 length of b +// X9 points to the address to store the return value (-1/0/1) +TEXT compare<>(SB),NOSPLIT|NOFRAME,$0 + BEQ X5, X7, cmp_len + + MOV X6, X10 + BGE X8, X10, use_a_len // X10 = min(len(a), len(b)) + MOV X8, X10 +use_a_len: + BEQZ X10, cmp_len + + MOV $32, X11 + BLT X10, X11, loop4_check + + // Check alignment - if alignment differs we have to do one byte at a time. + AND $3, X5, X12 + AND $3, X7, X13 + BNE X12, X13, loop4_check + BEQZ X12, loop32_check + + // Check one byte at a time until we reach 8 byte alignment. + SUB X12, X10, X10 +align: + ADD $-1, X12 + MOVBU 0(X5), X13 + MOVBU 0(X7), X14 + BNE X13, X14, cmp + ADD $1, X5 + ADD $1, X7 + BNEZ X12, align + +loop32_check: + MOV $32, X12 + BLT X10, X12, loop16_check +loop32: + MOV 0(X5), X15 + MOV 0(X7), X16 + MOV 8(X5), X17 + MOV 8(X7), X18 + BEQ X15, X16, loop32a + JMP cmp8a +loop32a: + BEQ X17, X18, loop32b + JMP cmp8b +loop32b: + MOV 16(X5), X15 + MOV 16(X7), X16 + MOV 24(X5), X17 + MOV 24(X7), X18 + BEQ X15, X16, loop32c + JMP cmp8a +loop32c: + BEQ X17, X18, loop32d + JMP cmp8b +loop32d: + ADD $32, X5 + ADD $32, X7 + ADD $-32, X10 + BGE X10, X12, loop32 + BEQZ X10, cmp_len + +loop16_check: + MOV $16, X11 + BLT X10, X11, loop4_check +loop16: + MOV 0(X5), X15 + MOV 0(X7), X16 + MOV 8(X5), X17 + MOV 8(X7), X18 + BEQ X15, X16, loop16a + JMP cmp8a +loop16a: + BEQ X17, X18, loop16b + JMP cmp8b +loop16b: + ADD $16, X5 + ADD $16, X7 + ADD $-16, X10 + BGE X10, X11, loop16 + BEQZ X10, cmp_len + +loop4_check: + MOV $4, X11 + BLT X10, X11, loop1 +loop4: + MOVBU 0(X5), X13 + MOVBU 0(X7), X14 + MOVBU 1(X5), X15 + MOVBU 1(X7), X16 + BEQ X13, X14, loop4a + SLTU X14, X13, X10 + SLTU X13, X14, X11 + JMP cmp_ret +loop4a: + BEQ X15, X16, loop4b + SLTU X16, X15, X10 + SLTU X15, X16, X11 + JMP cmp_ret +loop4b: + MOVBU 2(X5), X21 + MOVBU 2(X7), X22 + MOVBU 3(X5), X23 + MOVBU 3(X7), X24 + BEQ X21, X22, loop4c + SLTU X22, X21, X10 + SLTU X21, X22, X11 + JMP cmp_ret +loop4c: + BEQ X23, X24, loop4d + SLTU X24, X23, X10 + SLTU X23, X24, X11 + JMP cmp_ret +loop4d: + ADD $4, X5 + ADD $4, X7 + ADD $-4, X10 + BGE X10, X11, loop4 + +loop1: + BEQZ X10, cmp_len + MOVBU 0(X5), X13 + MOVBU 0(X7), X14 + BNE X13, X14, cmp + ADD $1, X5 + ADD $1, X7 + ADD $-1, X10 + JMP loop1 + + // Compare 8 bytes of memory in X15/X16 that are known to differ. +cmp8a: + MOV $0xff, X19 +cmp8a_loop: + AND X15, X19, X13 + AND X16, X19, X14 + BNE X13, X14, cmp + SLLI $8, X19 + JMP cmp8a_loop + + // Compare 8 bytes of memory in X17/X18 that are known to differ. +cmp8b: + MOV $0xff, X19 +cmp8b_loop: + AND X17, X19, X13 + AND X18, X19, X14 + BNE X13, X14, cmp + SLLI $8, X19 + JMP cmp8b_loop + +cmp_len: + MOV X6, X13 + MOV X8, X14 +cmp: + SLTU X14, X13, X10 + SLTU X13, X14, X11 +cmp_ret: + SUB X10, X11, X12 + MOV X12, (X9) + RET From d3070a767bc0ddfdca1f84e2018de1c906b817ca Mon Sep 17 00:00:00 2001 From: thepudds Date: Tue, 8 Mar 2022 14:51:27 +0000 Subject: [PATCH 039/276] cmd/compile/internal/types2: more consistently print "check go.mod" if language version < 1.18 If you attempt to instantiate a generic type or func and run 'go build' with a language version < 1.18 in the 'go' directive inside the go.mod file, cmd/compile emits a friendly message that includes the suggestion to 'check go.mod': type instantiation requires go1.18 or later (-lang was set to go1.17; check go.mod) However, if the code instead only declares a generic type or func without instantiating, cmd/compile currently emits a less friendly message: type parameters require go1.18 or later With this CL, the error in that situation becomes: type parameter requires go1.18 or later (-lang was set to go1.17; check go.mod) Within cmd/compile/internal/types2, it already calls check.versionErrorf in a dozen or so places, including three existing calls to check.versionErrorf within typeset.go (e.g., for embedding a constraint interface). This CL adds two more calls to check.versionErrorf, replacing calls to check.softErrorf. Both check.versionErrorf and check.softErrorf call check.err(at, , true) after massaging the string message. Fixes #51531 Change-Id: If54e179f5952b97701d1dfde4abb08101de07811 GitHub-Last-Rev: b0b7c1346f3a92f70e6cd5ff9ef047f441b09895 GitHub-Pull-Request: golang/go#51536 Reviewed-on: https://go-review.googlesource.com/c/go/+/390578 Reviewed-by: Robert Griesemer Trust: Robert Findley --- src/cmd/compile/internal/types2/resolver.go | 4 ++-- .../types2/testdata/fixedbugs/issue47818.go2 | 6 +++--- test/fixedbugs/issue51531.go | 13 +++++++++++++ 3 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 test/fixedbugs/issue51531.go diff --git a/src/cmd/compile/internal/types2/resolver.go b/src/cmd/compile/internal/types2/resolver.go index 05755f8cfd4..61963cb0437 100644 --- a/src/cmd/compile/internal/types2/resolver.go +++ b/src/cmd/compile/internal/types2/resolver.go @@ -413,7 +413,7 @@ func (check *Checker) collectObjects() { case *syntax.TypeDecl: if len(s.TParamList) != 0 && !check.allowVersion(pkg, 1, 18) { - check.softErrorf(s.TParamList[0], "type parameters require go1.18 or later") + check.versionErrorf(s.TParamList[0], "go1.18", "type parameter") } obj := NewTypeName(s.Name.Pos(), pkg, s.Name.Value, nil) check.declarePkgObj(s.Name, obj, &declInfo{file: fileScope, tdecl: s}) @@ -458,7 +458,7 @@ func (check *Checker) collectObjects() { check.recordDef(s.Name, obj) } if len(s.TParamList) != 0 && !check.allowVersion(pkg, 1, 18) && !hasTParamError { - check.softErrorf(s.TParamList[0], "type parameters require go1.18 or later") + check.versionErrorf(s.TParamList[0], "go1.18", "type parameter") } info := &declInfo{file: fileScope, fdecl: s} // Methods are not package-level objects but we still track them in the diff --git a/src/cmd/compile/internal/types2/testdata/fixedbugs/issue47818.go2 b/src/cmd/compile/internal/types2/testdata/fixedbugs/issue47818.go2 index 546de1ce313..6069f1f97b4 100644 --- a/src/cmd/compile/internal/types2/testdata/fixedbugs/issue47818.go2 +++ b/src/cmd/compile/internal/types2/testdata/fixedbugs/issue47818.go2 @@ -8,13 +8,13 @@ package go1_17 -type T[P /* ERROR type parameters require go1\.18 or later */ any /* ERROR undeclared name: any \(requires version go1\.18 or later\) */ ] struct{} +type T[P /* ERROR type parameter requires go1\.18 or later */ any /* ERROR undeclared name: any \(requires version go1\.18 or later\) */ ] struct{} // for init (and main, but we're not in package main) we should only get one error func init[P /* ERROR func init must have no type parameters */ any /* ERROR undeclared name: any \(requires version go1\.18 or later\) */ ]() {} -func main[P /* ERROR type parameters require go1\.18 or later */ any /* ERROR undeclared name: any \(requires version go1\.18 or later\) */ ]() {} +func main[P /* ERROR type parameter requires go1\.18 or later */ any /* ERROR undeclared name: any \(requires version go1\.18 or later\) */ ]() {} -func f[P /* ERROR type parameters require go1\.18 or later */ any /* ERROR undeclared name: any \(requires version go1\.18 or later\) */ ](x P) { +func f[P /* ERROR type parameter requires go1\.18 or later */ any /* ERROR undeclared name: any \(requires version go1\.18 or later\) */ ](x P) { var _ T[ /* ERROR type instantiation requires go1\.18 or later */ int] var _ (T[ /* ERROR type instantiation requires go1\.18 or later */ int]) _ = T[ /* ERROR type instantiation requires go1\.18 or later */ int]{} diff --git a/test/fixedbugs/issue51531.go b/test/fixedbugs/issue51531.go new file mode 100644 index 00000000000..a296bbc776f --- /dev/null +++ b/test/fixedbugs/issue51531.go @@ -0,0 +1,13 @@ +// errorcheck -lang=go1.17 + +// Copyright 2021 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 p + +type empty interface{} + +type Foo[T empty] int // ERROR "type parameter requires go1\.18 or later \(-lang was set to go1\.17; check go.mod\)" + +func Bar[T empty]() {} // ERROR "type parameter requires go1\.18 or later \(-lang was set to go1\.17; check go.mod\)" From 7419bb3ebb8ea2b9b3745cdcbaf747e4dffc52ae Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Mon, 7 Mar 2022 11:26:18 -0500 Subject: [PATCH 040/276] internal/fuzz: fix encoding for out-of-range ints and runes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also switch float64 NaN encoding to use hexadecimal, and accept hexadecimal encoding for all other integer types too. (That gives us the flexibility to change the encodings in either direction in the future without breaking earlier Go versions.) Out-of-range runes encoded using "%q" were previously replaced with the Unicode replacement charecter, losing their values. Out-of-range ints and uints on 32-bit platforms were previously rejected. Now they are wrapped instead: an “interesting” case with a large int or uint found on a 64-bit platform likely remains interesting on a 32-bit platform, even if the specific values differ. To verify the above changes, I have made TestMarshalUnmarshal accept (and check for) arbitrary differences between input and output, and added tests cases that include values in valid but non-canonical encodings. I have also added round-trip fuzz tests in the opposite direction for most of the types affected by this change, verifying that a marshaled value unmarshals to the same bitwise value. Updates #51258 Updates #51526 Fixes #51528 Change-Id: I7727a9d0582d81be0d954529545678a4374e88ed Reviewed-on: https://go-review.googlesource.com/c/go/+/390424 Trust: Bryan Mills Run-TryBot: Bryan Mills Reviewed-by: Roland Shoemaker TryBot-Result: Gopher Robot --- src/internal/fuzz/encoding.go | 84 +++++++-- src/internal/fuzz/encoding_test.go | 272 +++++++++++++++++++++++++---- 2 files changed, 311 insertions(+), 45 deletions(-) diff --git a/src/internal/fuzz/encoding.go b/src/internal/fuzz/encoding.go index fe070eca349..c95d9e088bb 100644 --- a/src/internal/fuzz/encoding.go +++ b/src/internal/fuzz/encoding.go @@ -12,6 +12,7 @@ import ( "go/token" "math" "strconv" + "unicode/utf8" ) // encVersion1 will be the first line of a file with version 1 encoding. @@ -32,21 +33,60 @@ func marshalCorpusFile(vals ...any) []byte { fmt.Fprintf(b, "%T(%v)\n", t, t) case float32: if math.IsNaN(float64(t)) && math.Float32bits(t) != math.Float32bits(float32(math.NaN())) { - fmt.Fprintf(b, "math.Float32frombits(%v)\n", math.Float32bits(t)) + // We encode unusual NaNs as hex values, because that is how users are + // likely to encounter them in literature about floating-point encoding. + // This allows us to reproduce fuzz failures that depend on the specific + // NaN representation (for float32 there are about 2^24 possibilities!), + // not just the fact that the value is *a* NaN. + // + // Note that the specific value of float32(math.NaN()) can vary based on + // whether the architecture represents signaling NaNs using a low bit + // (as is common) or a high bit (as commonly implemented on MIPS + // hardware before around 2012). We believe that the increase in clarity + // from identifying "NaN" with math.NaN() is worth the slight ambiguity + // from a platform-dependent value. + fmt.Fprintf(b, "math.Float32frombits(0x%x)\n", math.Float32bits(t)) } else { + // We encode all other values — including the NaN value that is + // bitwise-identical to float32(math.Nan()) — using the default + // formatting, which is equivalent to strconv.FormatFloat with format + // 'g' and can be parsed by strconv.ParseFloat. + // + // For an ordinary floating-point number this format includes + // sufficiently many digits to reconstruct the exact value. For positive + // or negative infinity it is the string "+Inf" or "-Inf". For positive + // or negative zero it is "0" or "-0". For NaN, it is the string "NaN". fmt.Fprintf(b, "%T(%v)\n", t, t) } case float64: if math.IsNaN(t) && math.Float64bits(t) != math.Float64bits(math.NaN()) { - fmt.Fprintf(b, "math.Float64frombits(%v)\n", math.Float64bits(t)) + fmt.Fprintf(b, "math.Float64frombits(0x%x)\n", math.Float64bits(t)) } else { fmt.Fprintf(b, "%T(%v)\n", t, t) } case string: fmt.Fprintf(b, "string(%q)\n", t) case rune: // int32 - fmt.Fprintf(b, "rune(%q)\n", t) + // Although rune and int32 are represented by the same type, only a subset + // of valid int32 values can be expressed as rune literals. Notably, + // negative numbers, surrogate halves, and values above unicode.MaxRune + // have no quoted representation. + // + // fmt with "%q" (and the corresponding functions in the strconv package) + // would quote out-of-range values to the Unicode replacement character + // instead of the original value (see https://go.dev/issue/51526), so + // they must be treated as int32 instead. + // + // We arbitrarily draw the line at UTF-8 validity, which biases toward the + // "rune" interpretation. (However, we accept either format as input.) + if utf8.ValidRune(t) { + fmt.Fprintf(b, "rune(%q)\n", t) + } else { + fmt.Fprintf(b, "int32(%v)\n", t) + } case byte: // uint8 + // For bytes, we arbitrarily prefer the character interpretation. + // (Every byte has a valid character encoding.) fmt.Fprintf(b, "byte(%q)\n", t) case []byte: // []uint8 fmt.Fprintf(b, "[]byte(%q)\n", t) @@ -199,6 +239,14 @@ func parseCorpusValue(line []byte) (any, error) { } return strconv.Unquote(val) case "byte", "rune": + if kind == token.INT { + switch typ { + case "rune": + return parseInt(val, typ) + case "byte": + return parseUint(val, typ) + } + } if kind != token.CHAR { return nil, fmt.Errorf("character literal required for byte/rune types") } @@ -265,18 +313,24 @@ func parseCorpusValue(line []byte) (any, error) { func parseInt(val, typ string) (any, error) { switch typ { case "int": - return strconv.Atoi(val) + // The int type may be either 32 or 64 bits. If 32, the fuzz tests in the + // corpus may include 64-bit values produced by fuzzing runs on 64-bit + // architectures. When running those tests, we implicitly wrap the values to + // fit in a regular int. (The test case is still “interesting”, even if the + // specific values of its inputs are platform-dependent.) + i, err := strconv.ParseInt(val, 0, 64) + return int(i), err case "int8": - i, err := strconv.ParseInt(val, 10, 8) + i, err := strconv.ParseInt(val, 0, 8) return int8(i), err case "int16": - i, err := strconv.ParseInt(val, 10, 16) + i, err := strconv.ParseInt(val, 0, 16) return int16(i), err - case "int32": - i, err := strconv.ParseInt(val, 10, 32) + case "int32", "rune": + i, err := strconv.ParseInt(val, 0, 32) return int32(i), err case "int64": - return strconv.ParseInt(val, 10, 64) + return strconv.ParseInt(val, 0, 64) default: panic("unreachable") } @@ -286,19 +340,19 @@ func parseInt(val, typ string) (any, error) { func parseUint(val, typ string) (any, error) { switch typ { case "uint": - i, err := strconv.ParseUint(val, 10, 0) + i, err := strconv.ParseUint(val, 0, 64) return uint(i), err - case "uint8": - i, err := strconv.ParseUint(val, 10, 8) + case "uint8", "byte": + i, err := strconv.ParseUint(val, 0, 8) return uint8(i), err case "uint16": - i, err := strconv.ParseUint(val, 10, 16) + i, err := strconv.ParseUint(val, 0, 16) return uint16(i), err case "uint32": - i, err := strconv.ParseUint(val, 10, 32) + i, err := strconv.ParseUint(val, 0, 32) return uint32(i), err case "uint64": - return strconv.ParseUint(val, 10, 64) + return strconv.ParseUint(val, 0, 64) default: panic("unreachable") } diff --git a/src/internal/fuzz/encoding_test.go b/src/internal/fuzz/encoding_test.go index 3a614f5bd2a..8e3800eb77f 100644 --- a/src/internal/fuzz/encoding_test.go +++ b/src/internal/fuzz/encoding_test.go @@ -5,85 +5,104 @@ package fuzz import ( + "math" "strconv" - "strings" "testing" + "unicode" ) func TestUnmarshalMarshal(t *testing.T) { var tests = []struct { - in string - ok bool + desc string + in string + reject bool + want string // if different from in }{ { - in: "int(1234)", - ok: false, // missing version + desc: "missing version", + in: "int(1234)", + reject: true, }, { + desc: "malformed string", in: `go test fuzz v1 string("a"bcad")`, - ok: false, // malformed + reject: true, }, { + desc: "empty value", in: `go test fuzz v1 int()`, - ok: false, // empty value + reject: true, }, { + desc: "negative uint", in: `go test fuzz v1 uint(-32)`, - ok: false, // invalid negative uint + reject: true, }, { + desc: "int8 too large", in: `go test fuzz v1 int8(1234456)`, - ok: false, // int8 too large + reject: true, }, { + desc: "multiplication in int value", in: `go test fuzz v1 int(20*5)`, - ok: false, // expression in int value + reject: true, }, { + desc: "double negation", in: `go test fuzz v1 int(--5)`, - ok: false, // expression in int value + reject: true, }, { + desc: "malformed bool", in: `go test fuzz v1 bool(0)`, - ok: false, // malformed bool + reject: true, }, { + desc: "malformed byte", in: `go test fuzz v1 byte('aa)`, - ok: false, // malformed byte + reject: true, }, { + desc: "byte out of range", in: `go test fuzz v1 byte('☃')`, - ok: false, // byte out of range + reject: true, }, { + desc: "extra newline", in: `go test fuzz v1 -string("has final newline") +string("has extra newline") `, - ok: true, // has final newline + want: `go test fuzz v1 +string("has extra newline")`, }, { + desc: "trailing spaces", in: `go test fuzz v1 string("extra") []byte("spacing") `, - ok: true, // extra spaces in the final newline + want: `go test fuzz v1 +string("extra") +[]byte("spacing")`, }, { + desc: "float types", in: `go test fuzz v1 float64(0) float32(0)`, - ok: true, // will be an integer literal since there is no decimal }, { + desc: "various types", in: `go test fuzz v1 int(-23) int8(-2) @@ -101,9 +120,9 @@ bool(true) string("hello\\xbd\\xb2=\\xbc ⌘") float64(-12.5) float32(2.5)`, - ok: true, }, { + desc: "float edge cases", // The two IEEE 754 bit patterns used for the math.Float{64,32}frombits // encodings are non-math.NAN quiet-NaN values. Since they are not equal // to math.NaN(), they should be re-encoded to their bit patterns. They @@ -119,21 +138,94 @@ float32(NaN) float64(+Inf) float64(-Inf) float64(NaN) +math.Float64frombits(0x7ff8000000000002) +math.Float32frombits(0x7fc00001)`, + }, + { + desc: "int variations", + // Although we arbitrarily choose default integer bases (0 or 16), we may + // want to change those arbitrary choices in the future and should not + // break the parser. Verify that integers in the opposite bases still + // parse correctly. + in: `go test fuzz v1 +int(0x0) +int32(0x41) +int64(0xfffffffff) +uint32(0xcafef00d) +uint64(0xffffffffffffffff) +uint8(0b0000000) +byte(0x0) +byte('\000') +byte('\u0000') +byte('\'') math.Float64frombits(9221120237041090562) math.Float32frombits(2143289345)`, - ok: true, + want: `go test fuzz v1 +int(0) +rune('A') +int64(68719476735) +uint32(3405705229) +uint64(18446744073709551615) +byte('\x00') +byte('\x00') +byte('\x00') +byte('\x00') +byte('\'') +math.Float64frombits(0x7ff8000000000002) +math.Float32frombits(0x7fc00001)`, + }, + { + desc: "rune validation", + in: `go test fuzz v1 +rune(0) +rune(0x41) +rune(-1) +rune(0xfffd) +rune(0xd800) +rune(0x10ffff) +rune(0x110000) +`, + want: `go test fuzz v1 +rune('\x00') +rune('A') +int32(-1) +rune('�') +int32(55296) +rune('\U0010ffff') +int32(1114112)`, + }, + { + desc: "int overflow", + in: `go test fuzz v1 +int(0x7fffffffffffffff) +uint(0xffffffffffffffff)`, + want: func() string { + switch strconv.IntSize { + case 32: + return `go test fuzz v1 +int(-1) +uint(4294967295)` + case 64: + return `go test fuzz v1 +int(9223372036854775807) +uint(18446744073709551615)` + default: + panic("unreachable") + } + }(), }, } for _, test := range tests { - t.Run(test.in, func(t *testing.T) { + t.Run(test.desc, func(t *testing.T) { vals, err := unmarshalCorpusFile([]byte(test.in)) - if test.ok && err != nil { - t.Fatalf("unmarshal unexpected error: %v", err) - } else if !test.ok && err == nil { - t.Fatalf("unmarshal unexpected success") + if test.reject { + if err == nil { + t.Fatalf("unmarshal unexpected success") + } + return } - if !test.ok { - return // skip the rest of the test + if err != nil { + t.Fatalf("unmarshal unexpected error: %v", err) } newB := marshalCorpusFile(vals...) if err != nil { @@ -142,9 +234,15 @@ math.Float32frombits(2143289345)`, if newB[len(newB)-1] != '\n' { t.Error("didn't write final newline to corpus file") } - before, after := strings.TrimSpace(test.in), strings.TrimSpace(string(newB)) - if before != after { - t.Errorf("values changed after unmarshal then marshal\nbefore: %q\nafter: %q", before, after) + + want := test.want + if want == "" { + want = test.in + } + want += "\n" + got := string(newB) + if got != want { + t.Errorf("unexpected marshaled value\ngot:\n%s\nwant:\n%s", got, want) } }) } @@ -190,3 +288,117 @@ func BenchmarkUnmarshalCorpusFile(b *testing.B) { }) } } + +func TestByteRoundTrip(t *testing.T) { + for x := 0; x < 256; x++ { + b1 := byte(x) + buf := marshalCorpusFile(b1) + vs, err := unmarshalCorpusFile(buf) + if err != nil { + t.Fatal(err) + } + b2 := vs[0].(byte) + if b2 != b1 { + t.Fatalf("unmarshaled %v, want %v:\n%s", b2, b1, buf) + } + } +} + +func TestInt8RoundTrip(t *testing.T) { + for x := -128; x < 128; x++ { + i1 := int8(x) + buf := marshalCorpusFile(i1) + vs, err := unmarshalCorpusFile(buf) + if err != nil { + t.Fatal(err) + } + i2 := vs[0].(int8) + if i2 != i1 { + t.Fatalf("unmarshaled %v, want %v:\n%s", i2, i1, buf) + } + } +} + +func FuzzFloat64RoundTrip(f *testing.F) { + f.Add(math.Float64bits(0)) + f.Add(math.Float64bits(math.Copysign(0, -1))) + f.Add(math.Float64bits(math.MaxFloat64)) + f.Add(math.Float64bits(math.SmallestNonzeroFloat64)) + f.Add(math.Float64bits(math.NaN())) + f.Add(uint64(0x7FF0000000000001)) // signaling NaN + f.Add(math.Float64bits(math.Inf(1))) + f.Add(math.Float64bits(math.Inf(-1))) + + f.Fuzz(func(t *testing.T, u1 uint64) { + x1 := math.Float64frombits(u1) + + b := marshalCorpusFile(x1) + t.Logf("marshaled math.Float64frombits(0x%x):\n%s", u1, b) + + xs, err := unmarshalCorpusFile(b) + if err != nil { + t.Fatal(err) + } + if len(xs) != 1 { + t.Fatalf("unmarshaled %d values", len(xs)) + } + x2 := xs[0].(float64) + u2 := math.Float64bits(x2) + if u2 != u1 { + t.Errorf("unmarshaled %v (bits 0x%x)", x2, u2) + } + }) +} + +func FuzzRuneRoundTrip(f *testing.F) { + f.Add(rune(-1)) + f.Add(rune(0xd800)) + f.Add(rune(0xdfff)) + f.Add(rune(unicode.ReplacementChar)) + f.Add(rune(unicode.MaxASCII)) + f.Add(rune(unicode.MaxLatin1)) + f.Add(rune(unicode.MaxRune)) + f.Add(rune(unicode.MaxRune + 1)) + f.Add(rune(-0x80000000)) + f.Add(rune(0x7fffffff)) + + f.Fuzz(func(t *testing.T, r1 rune) { + b := marshalCorpusFile(r1) + t.Logf("marshaled rune(0x%x):\n%s", r1, b) + + rs, err := unmarshalCorpusFile(b) + if err != nil { + t.Fatal(err) + } + if len(rs) != 1 { + t.Fatalf("unmarshaled %d values", len(rs)) + } + r2 := rs[0].(rune) + if r2 != r1 { + t.Errorf("unmarshaled rune(0x%x)", r2) + } + }) +} + +func FuzzStringRoundTrip(f *testing.F) { + f.Add("") + f.Add("\x00") + f.Add(string([]rune{unicode.ReplacementChar})) + + f.Fuzz(func(t *testing.T, s1 string) { + b := marshalCorpusFile(s1) + t.Logf("marshaled %q:\n%s", s1, b) + + rs, err := unmarshalCorpusFile(b) + if err != nil { + t.Fatal(err) + } + if len(rs) != 1 { + t.Fatalf("unmarshaled %d values", len(rs)) + } + s2 := rs[0].(string) + if s2 != s1 { + t.Errorf("unmarshaled %q", s2) + } + }) +} From e030833880b4ed20a7c153e6e58190c5649284ac Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Fri, 4 Mar 2022 17:17:56 -0500 Subject: [PATCH 041/276] cmd/compile/internal/syntax: don't try to parse files in GOROOT/.git This test was failing locally in my clone of the go repo due to a Git branch ending in ".go", which the test found and was attempting to parse as a file. It's fragile to try to parse .go files in GOROOT/.git, and wasteful to scan GOROOT/pkg and other non-source directories; instead, let's only parse the directories we actually expect to contain source files. (I was running the test for #51461.) Change-Id: I5d4e31ec2bcd9b4b6840ec32ad9b12bf44f349a5 Reviewed-on: https://go-review.googlesource.com/c/go/+/390023 Trust: Bryan Mills Run-TryBot: Bryan Mills TryBot-Result: Gopher Robot Reviewed-by: Robert Griesemer --- src/cmd/compile/internal/syntax/parser_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cmd/compile/internal/syntax/parser_test.go b/src/cmd/compile/internal/syntax/parser_test.go index e258a17c38e..ecb21e070b0 100644 --- a/src/cmd/compile/internal/syntax/parser_test.go +++ b/src/cmd/compile/internal/syntax/parser_test.go @@ -78,7 +78,8 @@ func TestStdLib(t *testing.T) { go func() { defer close(results) for _, dir := range []string{ - runtime.GOROOT(), + filepath.Join(runtime.GOROOT(), "src"), + filepath.Join(runtime.GOROOT(), "misc"), } { walkDirs(t, dir, func(filename string) { if skipRx != nil && skipRx.MatchString(filename) { From de8ddd97accb417450db014d1f45723515cb5d80 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Tue, 8 Mar 2022 11:13:37 +0100 Subject: [PATCH 042/276] syscall: add Pipe2 on solaris and use it for forkExecPipe Other platforms already define Pipe2, so add it for solaris as well. Change-Id: If0d2dfc9a3613479fb4611a673a20a4aa0af0b2b Reviewed-on: https://go-review.googlesource.com/c/go/+/390714 Trust: Tobias Klauser Run-TryBot: Tobias Klauser Trust: Matt Layher TryBot-Result: Gopher Robot Reviewed-by: Ian Lance Taylor --- src/syscall/forkpipe.go | 2 +- src/syscall/forkpipe2.go | 2 +- src/syscall/syscall_solaris.go | 15 +++++++++++++++ src/syscall/zsyscall_solaris_amd64.go | 13 +++++++++++++ 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/syscall/forkpipe.go b/src/syscall/forkpipe.go index 6f7d29ce67a..5082abc41cf 100644 --- a/src/syscall/forkpipe.go +++ b/src/syscall/forkpipe.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build aix || darwin || solaris +//go:build aix || darwin package syscall diff --git a/src/syscall/forkpipe2.go b/src/syscall/forkpipe2.go index 312244c0d8a..6ab1391c127 100644 --- a/src/syscall/forkpipe2.go +++ b/src/syscall/forkpipe2.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build dragonfly || freebsd || netbsd || openbsd +//go:build dragonfly || freebsd || netbsd || openbsd || solaris package syscall diff --git a/src/syscall/syscall_solaris.go b/src/syscall/syscall_solaris.go index f44a9e25ac9..3c50343d845 100644 --- a/src/syscall/syscall_solaris.go +++ b/src/syscall/syscall_solaris.go @@ -63,6 +63,21 @@ func Pipe(p []int) (err error) { return } +//sysnb pipe2(p *[2]_C_int, flags int) (err error) + +func Pipe2(p []int, flags int) error { + if len(p) != 2 { + return EINVAL + } + var pp [2]_C_int + err := pipe2(&pp, flags) + if err == nil { + p[0] = int(pp[0]) + p[1] = int(pp[1]) + } + return err +} + func (sa *SockaddrInet4) sockaddr() (unsafe.Pointer, _Socklen, error) { if sa.Port < 0 || sa.Port > 0xFFFF { return nil, 0, EINVAL diff --git a/src/syscall/zsyscall_solaris_amd64.go b/src/syscall/zsyscall_solaris_amd64.go index 2d8cdfd280b..dad05800273 100644 --- a/src/syscall/zsyscall_solaris_amd64.go +++ b/src/syscall/zsyscall_solaris_amd64.go @@ -7,6 +7,7 @@ package syscall import "unsafe" +//go:cgo_import_dynamic libc_pipe2 pipe2 "libc.so" //go:cgo_import_dynamic libc_Getcwd getcwd "libc.so" //go:cgo_import_dynamic libc_getgroups getgroups "libc.so" //go:cgo_import_dynamic libc_setgroups setgroups "libc.so" @@ -91,6 +92,7 @@ import "unsafe" //go:cgo_import_dynamic libc_getexecname getexecname "libc.so" //go:cgo_import_dynamic libc_utimensat utimensat "libc.so" +//go:linkname libc_pipe2 libc_pipe2 //go:linkname libc_Getcwd libc_Getcwd //go:linkname libc_getgroups libc_getgroups //go:linkname libc_setgroups libc_setgroups @@ -178,6 +180,7 @@ import "unsafe" type libcFunc uintptr var ( + libc_pipe2, libc_Getcwd, libc_getgroups, libc_setgroups, @@ -265,6 +268,16 @@ var ( // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func pipe2(p *[2]_C_int, flags int) (err error) { + _, _, e1 := rawSysvicall6(uintptr(unsafe.Pointer(&libc_pipe2)), 2, uintptr(unsafe.Pointer(p)), uintptr(flags), 0, 0, 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func Getcwd(buf []byte) (n int, err error) { var _p0 *byte if len(buf) > 0 { From 085ef537c4a2c57d373e72f4a110d9fae9a287be Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Tue, 8 Mar 2022 14:54:53 +0100 Subject: [PATCH 043/276] os, internal/syscall/unix: consolidate Pipe implementations All platforms with the pipe2 syscall now provide syscall.Pipe2. Use it to implement os.Pipe. This also allows to drop the illumos-specific wrapper in internal/sys/unix. Change-Id: Ieb712a1498e86a389bad261e4e97c61c11d4bdd0 Reviewed-on: https://go-review.googlesource.com/c/go/+/390715 Trust: Tobias Klauser Run-TryBot: Tobias Klauser Trust: Matt Layher TryBot-Result: Gopher Robot Reviewed-by: Ian Lance Taylor --- src/internal/syscall/unix/pipe2_illumos.go | 34 ---------------------- src/os/pipe2_illumos.go | 25 ---------------- src/os/{pipe2_bsd.go => pipe2_unix.go} | 4 +-- src/os/pipe_linux.go | 20 ------------- src/os/{pipe_bsd.go => pipe_unix.go} | 2 +- 5 files changed, 3 insertions(+), 82 deletions(-) delete mode 100644 src/internal/syscall/unix/pipe2_illumos.go delete mode 100644 src/os/pipe2_illumos.go rename src/os/{pipe2_bsd.go => pipe2_unix.go} (81%) delete mode 100644 src/os/pipe_linux.go rename src/os/{pipe_bsd.go => pipe_unix.go} (91%) diff --git a/src/internal/syscall/unix/pipe2_illumos.go b/src/internal/syscall/unix/pipe2_illumos.go deleted file mode 100644 index c6280f85e58..00000000000 --- a/src/internal/syscall/unix/pipe2_illumos.go +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2020 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 illumos - -package unix - -import ( - "syscall" - "unsafe" -) - -//go:cgo_import_dynamic libc_pipe2 pipe2 "libc.so" - -//go:linkname procpipe2 libc_pipe2 - -var procpipe2 uintptr - -type _C_int int32 - -func Pipe2(p []int, flags int) error { - if len(p) != 2 { - return syscall.EINVAL - } - var pp [2]_C_int - _, _, errno := syscall6(uintptr(unsafe.Pointer(&procpipe2)), 2, uintptr(unsafe.Pointer(&pp)), uintptr(flags), 0, 0, 0, 0) - if errno != 0 { - return errno - } - p[0] = int(pp[0]) - p[1] = int(pp[1]) - return nil -} diff --git a/src/os/pipe2_illumos.go b/src/os/pipe2_illumos.go deleted file mode 100644 index 354b35cc462..00000000000 --- a/src/os/pipe2_illumos.go +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2020 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 illumos - -package os - -import ( - "internal/syscall/unix" - "syscall" -) - -// Pipe returns a connected pair of Files; reads from r return bytes written to w. -// It returns the files and an error, if any. -func Pipe() (r *File, w *File, err error) { - var p [2]int - - e := unix.Pipe2(p[0:], syscall.O_CLOEXEC) - if e != nil { - return nil, nil, NewSyscallError("pipe", e) - } - - return newFile(uintptr(p[0]), "|0", kindPipe), newFile(uintptr(p[1]), "|1", kindPipe), nil -} diff --git a/src/os/pipe2_bsd.go b/src/os/pipe2_unix.go similarity index 81% rename from src/os/pipe2_bsd.go rename to src/os/pipe2_unix.go index 7eb1350d025..1e2e8ccb67c 100644 --- a/src/os/pipe2_bsd.go +++ b/src/os/pipe2_unix.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build dragonfly || freebsd || netbsd || openbsd +//go:build dragonfly || freebsd || linux || netbsd || openbsd || solaris package os @@ -15,7 +15,7 @@ func Pipe() (r *File, w *File, err error) { e := syscall.Pipe2(p[0:], syscall.O_CLOEXEC) if e != nil { - return nil, nil, NewSyscallError("pipe", e) + return nil, nil, NewSyscallError("pipe2", e) } return newFile(uintptr(p[0]), "|0", kindPipe), newFile(uintptr(p[1]), "|1", kindPipe), nil diff --git a/src/os/pipe_linux.go b/src/os/pipe_linux.go deleted file mode 100644 index 52f4e21e7c6..00000000000 --- a/src/os/pipe_linux.go +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2013 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 os - -import "syscall" - -// Pipe returns a connected pair of Files; reads from r return bytes written to w. -// It returns the files and an error, if any. -func Pipe() (r *File, w *File, err error) { - var p [2]int - - e := syscall.Pipe2(p[0:], syscall.O_CLOEXEC) - if e != nil { - return nil, nil, NewSyscallError("pipe2", e) - } - - return newFile(uintptr(p[0]), "|0", kindPipe), newFile(uintptr(p[1]), "|1", kindPipe), nil -} diff --git a/src/os/pipe_bsd.go b/src/os/pipe_unix.go similarity index 91% rename from src/os/pipe_bsd.go rename to src/os/pipe_unix.go index 554d62111a5..710f77670e2 100644 --- a/src/os/pipe_bsd.go +++ b/src/os/pipe_unix.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build aix || darwin || (js && wasm) || (solaris && !illumos) +//go:build aix || darwin || (js && wasm) package os From c3c74777bc5dcd351af6dc4811011241efe07d21 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Tue, 8 Mar 2022 14:55:26 +0100 Subject: [PATCH 044/276] runtime, syscall: implement syscall.Pipe using syscall.Pipe2 on solaris All other platforms providing the pipe2 syscall already implement it that way. Do so as well on solaris, which allows to drop runtime.syscall_pipe and its dependencies as well. Change-Id: Icf04777f21d1804da74325d173fefdc87caa42eb Reviewed-on: https://go-review.googlesource.com/c/go/+/390716 Trust: Tobias Klauser Run-TryBot: Tobias Klauser Trust: Matt Layher TryBot-Result: Gopher Robot Reviewed-by: Ian Lance Taylor --- src/runtime/os3_solaris.go | 3 --- src/runtime/sys_solaris_amd64.s | 12 ------------ src/runtime/syscall_solaris.go | 18 ------------------ src/syscall/asm_solaris_amd64.s | 3 --- src/syscall/syscall_solaris.go | 14 +------------- 5 files changed, 1 insertion(+), 49 deletions(-) diff --git a/src/runtime/os3_solaris.go b/src/runtime/os3_solaris.go index 5aee04d5a8d..f465a3aa3f5 100644 --- a/src/runtime/os3_solaris.go +++ b/src/runtime/os3_solaris.go @@ -47,7 +47,6 @@ import ( //go:cgo_import_dynamic libc_sysconf sysconf "libc.so" //go:cgo_import_dynamic libc_usleep usleep "libc.so" //go:cgo_import_dynamic libc_write write "libc.so" -//go:cgo_import_dynamic libc_pipe pipe "libc.so" //go:cgo_import_dynamic libc_pipe2 pipe2 "libc.so" //go:linkname libc____errno libc____errno @@ -83,7 +82,6 @@ import ( //go:linkname libc_sysconf libc_sysconf //go:linkname libc_usleep libc_usleep //go:linkname libc_write libc_write -//go:linkname libc_pipe libc_pipe //go:linkname libc_pipe2 libc_pipe2 var ( @@ -120,7 +118,6 @@ var ( libc_sysconf, libc_usleep, libc_write, - libc_pipe, libc_pipe2 libcFunc ) diff --git a/src/runtime/sys_solaris_amd64.s b/src/runtime/sys_solaris_amd64.s index 05fd187517e..24d2d61df08 100644 --- a/src/runtime/sys_solaris_amd64.s +++ b/src/runtime/sys_solaris_amd64.s @@ -29,18 +29,6 @@ TEXT runtime·miniterrno(SB),NOSPLIT,$0 MOVQ AX, (m_mOS+mOS_perrno)(BX) RET -// pipe(3c) wrapper that returns fds in AX, DX. -// NOT USING GO CALLING CONVENTION. -TEXT runtime·pipe1(SB),NOSPLIT,$0 - SUBQ $16, SP // 8 bytes will do, but stack has to be 16-byte aligned - MOVQ SP, DI - LEAQ libc_pipe(SB), AX - CALL AX - MOVL 0(SP), AX - MOVL 4(SP), DX - ADDQ $16, SP - RET - // Call a library function with SysV calling conventions. // The called function can take a maximum of 6 INTEGER class arguments, // see diff --git a/src/runtime/syscall_solaris.go b/src/runtime/syscall_solaris.go index e270e271c0a..79775711aea 100644 --- a/src/runtime/syscall_solaris.go +++ b/src/runtime/syscall_solaris.go @@ -25,11 +25,6 @@ var ( libc_wait4 libcFunc ) -//go:linkname pipe1x runtime.pipe1 -var pipe1x libcFunc // name to take addr of pipe1 - -func pipe1() // declared for vet; do NOT call - // Many of these are exported via linkname to assembly in the syscall // package. @@ -196,19 +191,6 @@ func syscall_ioctl(fd, req, arg uintptr) (err uintptr) { return call.err } -//go:linkname syscall_pipe -func syscall_pipe() (r, w, err uintptr) { - call := libcall{ - fn: uintptr(unsafe.Pointer(&pipe1x)), - n: 0, - args: uintptr(unsafe.Pointer(&pipe1x)), // it's unused but must be non-nil, otherwise crashes - } - entersyscallblock() - asmcgocall(unsafe.Pointer(&asmsysvicall6x), unsafe.Pointer(&call)) - exitsyscall() - return call.r1, call.r2, call.err -} - // This is syscall.RawSyscall, it exists to satisfy some build dependency, // but it doesn't work. // diff --git a/src/syscall/asm_solaris_amd64.s b/src/syscall/asm_solaris_amd64.s index c61e04a42fa..3672d3667fa 100644 --- a/src/syscall/asm_solaris_amd64.s +++ b/src/syscall/asm_solaris_amd64.s @@ -48,9 +48,6 @@ TEXT ·getpid(SB),NOSPLIT,$0 TEXT ·ioctl(SB),NOSPLIT,$0 JMP runtime·syscall_ioctl(SB) -TEXT ·pipe(SB),NOSPLIT,$0 - JMP runtime·syscall_pipe(SB) - TEXT ·RawSyscall(SB),NOSPLIT,$0 JMP runtime·syscall_rawsyscall(SB) diff --git a/src/syscall/syscall_solaris.go b/src/syscall/syscall_solaris.go index 3c50343d845..d01070b2ec5 100644 --- a/src/syscall/syscall_solaris.go +++ b/src/syscall/syscall_solaris.go @@ -47,20 +47,8 @@ func direntNamlen(buf []byte) (uint64, bool) { return reclen - uint64(unsafe.Offsetof(Dirent{}.Name)), true } -func pipe() (r uintptr, w uintptr, err uintptr) - func Pipe(p []int) (err error) { - if len(p) != 2 { - return EINVAL - } - r0, w0, e1 := pipe() - if e1 != 0 { - err = Errno(e1) - } - if err == nil { - p[0], p[1] = int(r0), int(w0) - } - return + return Pipe2(p, 0) } //sysnb pipe2(p *[2]_C_int, flags int) (err error) From bd77d6e24048e5a8b7b07d2d0b7cf552d21905f5 Mon Sep 17 00:00:00 2001 From: Rhys Hiltner Date: Tue, 8 Feb 2022 14:51:41 -0800 Subject: [PATCH 045/276] runtime/pprof: check if PC is reused for inlining When describing call stacks that include inlined function calls, the runtime uses "fake" PCs to represent the frames that inlining removed. Those PCs correspond to real NOP instructions that the compiler inserts for this purpose. Describing the call stack in a protobuf-formatted profile requires the runtime/pprof package to collapse any sequences of fake call sites back into single PCs, removing the NOPs but retaining their line info. But because the NOP instructions are part of the function, they can appear as leaf nodes in a CPU profile. That results in an address that should sometimes be ignored (when it appears as a call site) and that sometimes should be present in the profile (when it is observed consuming CPU time). When processing a PC address, consider it first as a fake PC to add to the current inlining deck, and then as a previously-seen (real) PC. Fixes #50996 Change-Id: I80802369978bd7ac9969839ecfc9995ea4f84ab4 Reviewed-on: https://go-review.googlesource.com/c/go/+/384239 Reviewed-by: Cherry Mui Reviewed-by: Michael Pratt --- src/runtime/pprof/proto.go | 50 +++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/src/runtime/pprof/proto.go b/src/runtime/pprof/proto.go index 073a076802d..215bd0bf96c 100644 --- a/src/runtime/pprof/proto.go +++ b/src/runtime/pprof/proto.go @@ -244,6 +244,10 @@ type locInfo struct { // to represent inlined functions // https://github.com/golang/go/blob/d6f2f833c93a41ec1c68e49804b8387a06b131c5/src/runtime/traceback.go#L347-L368 pcs []uintptr + + // results of allFrames call for this PC + frames []runtime.Frame + symbolizeResult symbolizeFlag } // newProfileBuilder returns a new profileBuilder. @@ -399,6 +403,24 @@ func (b *profileBuilder) appendLocsForStack(locs []uint64, stk []uintptr) (newLo for len(stk) > 0 { addr := stk[0] if l, ok := b.locs[addr]; ok { + // When generating code for an inlined function, the compiler adds + // NOP instructions to the outermost function as a placeholder for + // each layer of inlining. When the runtime generates tracebacks for + // stacks that include inlined functions, it uses the addresses of + // those NOPs as "fake" PCs on the stack as if they were regular + // function call sites. But if a profiling signal arrives while the + // CPU is executing one of those NOPs, its PC will show up as a leaf + // in the profile with its own Location entry. So, always check + // whether addr is a "fake" PC in the context of the current call + // stack by trying to add it to the inlining deck before assuming + // that the deck is complete. + if len(b.deck.pcs) > 0 { + if added := b.deck.tryAdd(addr, l.frames, l.symbolizeResult); added { + stk = stk[1:] + continue + } + } + // first record the location if there is any pending accumulated info. if id := b.emitLocation(); id > 0 { locs = append(locs, id) @@ -451,6 +473,27 @@ func (b *profileBuilder) appendLocsForStack(locs []uint64, stk []uintptr) (newLo return locs } +// Here's an example of how Go 1.17 writes out inlined functions, compiled for +// linux/amd64. The disassembly of main.main shows two levels of inlining: main +// calls b, b calls a, a does some work. +// +// inline.go:9 0x4553ec 90 NOPL // func main() { b(v) } +// inline.go:6 0x4553ed 90 NOPL // func b(v *int) { a(v) } +// inline.go:5 0x4553ee 48c7002a000000 MOVQ $0x2a, 0(AX) // func a(v *int) { *v = 42 } +// +// If a profiling signal arrives while executing the MOVQ at 0x4553ee (for line +// 5), the runtime will report the stack as the MOVQ frame being called by the +// NOPL at 0x4553ed (for line 6) being called by the NOPL at 0x4553ec (for line +// 9). +// +// The role of pcDeck is to collapse those three frames back into a single +// location at 0x4553ee, with file/line/function symbolization info representing +// the three layers of calls. It does that via sequential calls to pcDeck.tryAdd +// starting with the leaf-most address. The fourth call to pcDeck.tryAdd will be +// for the caller of main.main. Because main.main was not inlined in its caller, +// the deck will reject the addition, and the fourth PC on the stack will get +// its own location. + // pcDeck is a helper to detect a sequence of inlined functions from // a stack trace returned by the runtime. // @@ -535,7 +578,12 @@ func (b *profileBuilder) emitLocation() uint64 { newFuncs := make([]newFunc, 0, 8) id := uint64(len(b.locs)) + 1 - b.locs[addr] = locInfo{id: id, pcs: append([]uintptr{}, b.deck.pcs...)} + b.locs[addr] = locInfo{ + id: id, + pcs: append([]uintptr{}, b.deck.pcs...), + symbolizeResult: b.deck.symbolizeResult, + frames: append([]runtime.Frame{}, b.deck.frames...), + } start := b.pb.startMessage() b.pb.uint64Opt(tagLocation_ID, id) From 67f1a436b9c4055e02d9d031c6c2e9d6c9456bf0 Mon Sep 17 00:00:00 2001 From: Michael Pratt Date: Mon, 13 Dec 2021 17:32:07 -0500 Subject: [PATCH 046/276] cmd/dist: log CPU model when testing Knowing whether test failures are correlated with specific CPU models on has proven useful on several issues. Log it for prior to testing so it is always available. internal/sysinfo provides the CPU model, but it is not available in the bootstrap toolchain, so we can't access this in cmd/dist. Instead use a separate binary which cmd/dist will only build once testing begins. The addition of new data to the beginning of cmd/dist output will break x/build/cmd/coordinator's banner parsing, leaving extra lines in the log output, though information will not be lost. https://golang.org/cl/372538 fixes up the coordinator and should be submitted and deployed before this CL is submitted. This is a redo of CL 371474. It switches back to the original approach of using a separate binary, as the bootstap toolchain won't allow cmd/dist to import internal packages. For #46272. For #49209. For #50146. Change-Id: I906bbda987902a2120c5183290a4e89a2440de58 Reviewed-on: https://go-review.googlesource.com/c/go/+/378589 Reviewed-by: Austin Clements Trust: Michael Pratt Run-TryBot: Michael Pratt TryBot-Result: Gopher Robot --- src/cmd/dist/test.go | 25 +++++++++++++++++++++++++ src/cmd/internal/metadata/main.go | 19 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 src/cmd/internal/metadata/main.go diff --git a/src/cmd/dist/test.go b/src/cmd/dist/test.go index ab30089881d..cd3c26ab3a3 100644 --- a/src/cmd/dist/test.go +++ b/src/cmd/dist/test.go @@ -218,6 +218,15 @@ func (t *tester) run() { } } + if err := t.maybeLogMetadata(); err != nil { + t.failed = true + if t.keepGoing { + log.Printf("Failed logging metadata: %v", err) + } else { + fatalf("Failed logging metadata: %v", err) + } + } + for _, dt := range t.tests { if !t.shouldRunTest(dt.name) { t.partial = true @@ -268,6 +277,22 @@ func (t *tester) shouldRunTest(name string) bool { return false } +func (t *tester) maybeLogMetadata() error { + if t.compileOnly { + // We need to run a subprocess to log metadata. Don't do that + // on compile-only runs. + return nil + } + t.out("Test execution environment.") + // Helper binary to print system metadata (CPU model, etc). This is a + // separate binary from dist so it need not build with the bootstrap + // toolchain. + // + // TODO(prattmic): If we split dist bootstrap and dist test then this + // could be simplified to directly use internal/sysinfo here. + return t.dirCmd(filepath.Join(goroot, "src/cmd/internal/metadata"), "go", []string{"run", "."}).Run() +} + // short returns a -short flag value to use with 'go test' // or a test binary for tests intended to run in short mode. // It returns "true", unless the environment variable diff --git a/src/cmd/internal/metadata/main.go b/src/cmd/internal/metadata/main.go new file mode 100644 index 00000000000..2df048fad62 --- /dev/null +++ b/src/cmd/internal/metadata/main.go @@ -0,0 +1,19 @@ +// Copyright 2022 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. + +// Metadata prints basic system metadata to include in test logs. This is +// separate from cmd/dist so it does not need to build with the bootstrap +// toolchain. +package main + +import ( + "fmt" + "internal/sysinfo" + "runtime" +) + +func main() { + fmt.Printf("# GOARCH: %s\n", runtime.GOARCH) + fmt.Printf("# CPU: %s\n", sysinfo.CPU.Name()) +} From dbbe4cca5d7069482983316694334bdf2fe6a7ec Mon Sep 17 00:00:00 2001 From: Michael Pratt Date: Mon, 13 Dec 2021 17:34:16 -0500 Subject: [PATCH 047/276] cmd/dist: log OS version when testing As a follow-up to https://golang.org/cl/371474, add the OS version to the metadata printed for each test. This is a redo of CL 371475. This version updates go.mod and conforms to the changes made in the parent commit. Fixes #50146. Change-Id: Iba5541cc8dd2c85c1fa3a215e30c8c3f9b6aaaab Reviewed-on: https://go-review.googlesource.com/c/go/+/378590 Reviewed-by: Austin Clements Trust: Michael Pratt Run-TryBot: Michael Pratt TryBot-Result: Gopher Robot --- src/cmd/go.mod | 2 +- src/cmd/internal/metadata/main.go | 8 ++++++ src/cmd/internal/osinfo/doc.go | 6 +++++ src/cmd/internal/osinfo/os_js.go | 21 ++++++++++++++++ src/cmd/internal/osinfo/os_plan9.go | 21 ++++++++++++++++ src/cmd/internal/osinfo/os_unix.go | 36 +++++++++++++++++++++++++++ src/cmd/internal/osinfo/os_windows.go | 19 ++++++++++++++ 7 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 src/cmd/internal/osinfo/doc.go create mode 100644 src/cmd/internal/osinfo/os_js.go create mode 100644 src/cmd/internal/osinfo/os_plan9.go create mode 100644 src/cmd/internal/osinfo/os_unix.go create mode 100644 src/cmd/internal/osinfo/os_windows.go diff --git a/src/cmd/go.mod b/src/cmd/go.mod index 48fc888f949..fd54a886309 100644 --- a/src/cmd/go.mod +++ b/src/cmd/go.mod @@ -7,6 +7,7 @@ require ( golang.org/x/arch v0.0.0-20210923205945-b76863e36670 golang.org/x/mod v0.6.0-dev.0.20211102181907-3a5865c02020 golang.org/x/sync v0.0.0-20210220032951-036812b2e83c + golang.org/x/sys v0.0.0-20211205182925-97ca703d548d golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 golang.org/x/tools v0.1.9-0.20220124164225-97de9ec46646 ) @@ -14,6 +15,5 @@ require ( require ( github.com/ianlancetaylor/demangle v0.0.0-20210905161508-09a460cdf81d // indirect golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 // indirect - golang.org/x/sys v0.0.0-20211205182925-97ca703d548d // indirect golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect ) diff --git a/src/cmd/internal/metadata/main.go b/src/cmd/internal/metadata/main.go index 2df048fad62..157226e8901 100644 --- a/src/cmd/internal/metadata/main.go +++ b/src/cmd/internal/metadata/main.go @@ -8,6 +8,7 @@ package main import ( + "cmd/internal/osinfo" "fmt" "internal/sysinfo" "runtime" @@ -16,4 +17,11 @@ import ( func main() { fmt.Printf("# GOARCH: %s\n", runtime.GOARCH) fmt.Printf("# CPU: %s\n", sysinfo.CPU.Name()) + + fmt.Printf("# GOOS: %s\n", runtime.GOOS) + ver, err := osinfo.Version() + if err != nil { + ver = fmt.Sprintf("UNKNOWN: error determining OS version: %v", err) + } + fmt.Printf("# OS Version: %s\n", ver) } diff --git a/src/cmd/internal/osinfo/doc.go b/src/cmd/internal/osinfo/doc.go new file mode 100644 index 00000000000..1b5469d53a1 --- /dev/null +++ b/src/cmd/internal/osinfo/doc.go @@ -0,0 +1,6 @@ +// Copyright 2022 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 osinfo provides OS metadata. +package osinfo diff --git a/src/cmd/internal/osinfo/os_js.go b/src/cmd/internal/osinfo/os_js.go new file mode 100644 index 00000000000..882580d6527 --- /dev/null +++ b/src/cmd/internal/osinfo/os_js.go @@ -0,0 +1,21 @@ +// Copyright 2022 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 js + +package osinfo + +import ( + "fmt" +) + +// Version returns the OS version name/number. +func Version() (string, error) { + // Version detection on wasm varies depending on the underlying runtime + // (browser, node, etc), nor is there a standard via something like + // WASI (see https://go.dev/issue/31105). We could attempt multiple + // combinations, but for now we leave this unimplemented for + // simplicity. + return "", fmt.Errorf("unimplemented") +} diff --git a/src/cmd/internal/osinfo/os_plan9.go b/src/cmd/internal/osinfo/os_plan9.go new file mode 100644 index 00000000000..e0225a93a27 --- /dev/null +++ b/src/cmd/internal/osinfo/os_plan9.go @@ -0,0 +1,21 @@ +// Copyright 2022 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 plan9 + +package osinfo + +import ( + "os" +) + +// Version returns the OS version name/number. +func Version() (string, error) { + b, err := os.ReadFile("/dev/osversion") + if err != nil { + return "", err + } + + return string(b), nil +} diff --git a/src/cmd/internal/osinfo/os_unix.go b/src/cmd/internal/osinfo/os_unix.go new file mode 100644 index 00000000000..fab9e08f829 --- /dev/null +++ b/src/cmd/internal/osinfo/os_unix.go @@ -0,0 +1,36 @@ +// Copyright 2022 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 osinfo + +import ( + "bytes" + + "golang.org/x/sys/unix" +) + +func utsString(b []byte) string { + i := bytes.IndexByte(b, 0) + if i == -1 { + return string(b) + } + return string(b[:i]) +} + +// Version returns the OS version name/number. +func Version() (string, error) { + var uts unix.Utsname + if err := unix.Uname(&uts); err != nil { + return "", err + } + + sysname := utsString(uts.Sysname[:]) + release := utsString(uts.Release[:]) + version := utsString(uts.Version[:]) + machine := utsString(uts.Machine[:]) + + return sysname + " " + release + " " + version + " " + machine, nil +} diff --git a/src/cmd/internal/osinfo/os_windows.go b/src/cmd/internal/osinfo/os_windows.go new file mode 100644 index 00000000000..8ffe4f3f6d8 --- /dev/null +++ b/src/cmd/internal/osinfo/os_windows.go @@ -0,0 +1,19 @@ +// Copyright 2022 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 windows + +package osinfo + +import ( + "fmt" + + "golang.org/x/sys/windows" +) + +// Version returns the OS version name/number. +func Version() (string, error) { + major, minor, patch := windows.RtlGetNtVersionNumbers() + return fmt.Sprintf("%d.%d.%d", major, minor, patch), nil +} From 4469557974a95b1f4bc1c700aee6779a0f15d22e Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Tue, 8 Feb 2022 15:24:33 -0500 Subject: [PATCH 048/276] net/http/pprof: skip TestDeltaProfile on all arm and arm64 architectures Given that we have seen failures with the same failure mode on both openbsd/arm and android/arm64, it seems likely that the underlying bug affects at least all ARM-based architectures. It appears that either these architectures are not able to sample at the frequency expected by the test, or the samples are for some reason being dropped. For #50218 Change-Id: I42a6c8ecda57448f8068e8facb42a4a2cecbbb37 Reviewed-on: https://go-review.googlesource.com/c/go/+/383997 Trust: Bryan Mills Run-TryBot: Bryan Mills TryBot-Result: Gopher Robot Reviewed-by: Cherry Mui --- src/net/http/pprof/pprof_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/net/http/pprof/pprof_test.go b/src/net/http/pprof/pprof_test.go index 1a4d653a62d..f82ad45bf6f 100644 --- a/src/net/http/pprof/pprof_test.go +++ b/src/net/http/pprof/pprof_test.go @@ -153,7 +153,7 @@ func mutexHog(duration time.Duration, hogger func(mu1, mu2 *sync.Mutex, start ti } func TestDeltaProfile(t *testing.T) { - if runtime.GOOS == "openbsd" && runtime.GOARCH == "arm" { + if strings.HasPrefix(runtime.GOARCH, "arm") { testenv.SkipFlaky(t, 50218) } From 0add0647d80f8ec794042b4608275830372fe298 Mon Sep 17 00:00:00 2001 From: Robert Findley Date: Tue, 8 Mar 2022 16:43:47 -0500 Subject: [PATCH 049/276] go/printer: don't print unnecesary commas for func type param lists Type parameter lists are not ambiguous for function declarations in the way that they are ambiguous for type declarations. Avoid printing an extra comma to disambiguate. Fixes #51548 Change-Id: I8ca2b21e271982013653b9e220f92ee74f577ba2 Reviewed-on: https://go-review.googlesource.com/c/go/+/390914 Trust: Robert Findley Run-TryBot: Robert Findley Reviewed-by: Robert Griesemer TryBot-Result: Gopher Robot --- src/go/printer/nodes.go | 24 +++++++++++++++-------- src/go/printer/testdata/generics.golden | 26 +++++++++++++++++++++++++ src/go/printer/testdata/generics.input | 25 ++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 8 deletions(-) diff --git a/src/go/printer/nodes.go b/src/go/printer/nodes.go index f2170dbc4f3..9a09d58eb2c 100644 --- a/src/go/printer/nodes.go +++ b/src/go/printer/nodes.go @@ -319,9 +319,17 @@ func (p *printer) exprList(prev0 token.Pos, list []ast.Expr, depth int, mode exp } } -func (p *printer) parameters(fields *ast.FieldList, isTypeParam bool) { +type paramMode int + +const ( + funcParam paramMode = iota + funcTParam + typeTParam +) + +func (p *printer) parameters(fields *ast.FieldList, mode paramMode) { openTok, closeTok := token.LPAREN, token.RPAREN - if isTypeParam { + if mode != funcParam { openTok, closeTok = token.LBRACK, token.RBRACK } p.print(fields.Opening, openTok) @@ -373,7 +381,7 @@ func (p *printer) parameters(fields *ast.FieldList, isTypeParam bool) { if closing := p.lineFor(fields.Closing); 0 < prevLine && prevLine < closing { p.print(token.COMMA) p.linebreak(closing, 0, ignore, true) - } else if isTypeParam && fields.NumFields() == 1 { + } else if mode == typeTParam && fields.NumFields() == 1 { // Otherwise, if we are in a type parameter list that could be confused // with the constant array length expression [P*C], print a comma so that // parsing is unambiguous. @@ -411,10 +419,10 @@ func isTypeLit(x ast.Expr) bool { func (p *printer) signature(sig *ast.FuncType) { if sig.TypeParams != nil { - p.parameters(sig.TypeParams, true) + p.parameters(sig.TypeParams, funcTParam) } if sig.Params != nil { - p.parameters(sig.Params, false) + p.parameters(sig.Params, funcParam) } else { p.print(token.LPAREN, token.RPAREN) } @@ -428,7 +436,7 @@ func (p *printer) signature(sig *ast.FuncType) { p.expr(stripParensAlways(res.List[0].Type)) return } - p.parameters(res, false) + p.parameters(res, funcParam) } } @@ -1639,7 +1647,7 @@ func (p *printer) spec(spec ast.Spec, n int, doIndent bool) { p.setComment(s.Doc) p.expr(s.Name) if s.TypeParams != nil { - p.parameters(s.TypeParams, true) + p.parameters(s.TypeParams, typeTParam) } if n == 1 { p.print(blank) @@ -1829,7 +1837,7 @@ func (p *printer) funcDecl(d *ast.FuncDecl) { // FUNC is emitted). startCol := p.out.Column - len("func ") if d.Recv != nil { - p.parameters(d.Recv, false) // method: print receiver + p.parameters(d.Recv, funcParam) // method: print receiver p.print(blank) } p.expr(d.Name) diff --git a/src/go/printer/testdata/generics.golden b/src/go/printer/testdata/generics.golden index 4fac2c9c580..c3a7df83725 100644 --- a/src/go/printer/testdata/generics.golden +++ b/src/go/printer/testdata/generics.golden @@ -64,3 +64,29 @@ type _ [P*T - T]struct{} type _[ P *T, ] struct{} + +// equivalent test cases for potentially ambiguous type parameter lists, except +// for function declarations there is no ambiguity (issue #51548) +func _[P *T]() {} +func _[P *T, _ any]() {} +func _[P *T]() {} +func _[P *T, _ any]() {} +func _[P T]() {} +func _[P T, _ any]() {} + +func _[P *struct{}]() {} +func _[P *struct{}]() {} +func _[P []int]() {} + +func _[P T]() {} +func _[P T]() {} +func _[P **T]() {} +func _[P *T]() {} +func _[P *T]() {} +func _[P **T]() {} +func _[P *T]() {} + +func _[ + P *T, +]() { +} diff --git a/src/go/printer/testdata/generics.input b/src/go/printer/testdata/generics.input index fde9d32ef04..66e1554f7ff 100644 --- a/src/go/printer/testdata/generics.input +++ b/src/go/printer/testdata/generics.input @@ -61,3 +61,28 @@ type _ [P * T - T]struct{} type _[ P *T, ] struct{} + +// equivalent test cases for potentially ambiguous type parameter lists, except +// for function declarations there is no ambiguity (issue #51548) +func _[P *T,]() {} +func _[P *T, _ any]() {} +func _[P (*T),]() {} +func _[P (*T), _ any]() {} +func _[P (T),]() {} +func _[P (T), _ any]() {} + +func _[P *struct{}] () {} +func _[P (*struct{})] () {} +func _[P ([]int)] () {} + +func _ [P(T)]() {} +func _ [P((T))]() {} +func _ [P * *T]() {} +func _ [P * T]() {} +func _ [P(*T)]() {} +func _ [P(**T)]() {} +func _ [P * T]() {} + +func _[ + P *T, +]() {} From 20d333b6f48545cd9900a39fb10f390584d4ba2c Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Tue, 8 Mar 2022 13:32:34 -0800 Subject: [PATCH 050/276] cmd/go: for gccgo expect one fewer file in TestScript/list_swigcxx One of the files in CompileGoFiles is actually _cgo_import.go, but that file is only generated for gc, not for gccgo. Change-Id: I87bb55552e1409cc57da8f35a32b37ce4a3df60c Reviewed-on: https://go-review.googlesource.com/c/go/+/390895 Trust: Ian Lance Taylor Run-TryBot: Ian Lance Taylor TryBot-Result: Gopher Robot Reviewed-by: Bryan Mills --- src/cmd/go/testdata/script/list_swigcxx.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cmd/go/testdata/script/list_swigcxx.txt b/src/cmd/go/testdata/script/list_swigcxx.txt index d4227a80e8e..4220487a286 100644 --- a/src/cmd/go/testdata/script/list_swigcxx.txt +++ b/src/cmd/go/testdata/script/list_swigcxx.txt @@ -6,7 +6,7 @@ # CompiledGoFiles should contain 4 files: # a.go -# a.swigcxx.go +# _cgo_import.go [gc only] # _cgo_gotypes.go # a.cgo1.go # @@ -16,7 +16,8 @@ go list -f '{{.CompiledGoFiles}}' -compiled=true example/swig stdout a\.go -stdout -count=3 $GOCACHE +[gc] stdout -count=3 $GOCACHE +[gccgo] stdout -count=2 $GOCACHE -- go.mod -- module example From 1045faa38c660b8a0ac3fbf5b0a01dde26a3cf75 Mon Sep 17 00:00:00 2001 From: Meng Zhuo Date: Tue, 19 Oct 2021 10:22:20 +0800 Subject: [PATCH 051/276] cmd/compile/internal: add ABI register information for riscv64 This CL adds the defines for ABI registers on riscv64. Updates #40724 Change-Id: I53a89d88b6feb1a88cf7008b8484d444791e8a55 Reviewed-on: https://go-review.googlesource.com/c/go/+/356519 Trust: mzh Run-TryBot: mzh Reviewed-by: Joel Sing Reviewed-by: Cherry Mui TryBot-Result: Gopher Robot --- src/cmd/compile/abi-internal.md | 51 +++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/src/cmd/compile/abi-internal.md b/src/cmd/compile/abi-internal.md index 53eaa84d545..72232bd1516 100644 --- a/src/cmd/compile/abi-internal.md +++ b/src/cmd/compile/abi-internal.md @@ -730,6 +730,57 @@ The floating point status and control register (FPSCR) is initialized to 0 by the kernel at startup of the Go program and not changed by the Go generated code. +### riscv64 architecture + +The riscv64 architecture uses X10 – X17, X8, X9, X18 – X23 for integer arguments +and results. + +It uses F10 – F17, F8, F9, F18 – F23 for floating-point arguments and results. + +Special-purpose registers used within Go generated code and Go +assembly code are as follows: + +| Register | Call meaning | Return meaning | Body meaning | +| --- | --- | --- | --- | +| X0 | Zero value | Same | Same | +| X1 | Link register | Link register | Scratch | +| X2 | Stack pointer | Same | Same | +| X3 | Global pointer | Same | Used by dynamic linker | +| X4 | TLS (thread pointer) | TLS | Scratch | +| X24,X25 | Scratch | Scratch | Used by duffcopy, duffzero | +| X26 | Closure context pointer | Scratch | Scratch | +| X27 | Current goroutine | Same | Same | +| X31 | Scratch | Scratch | Scratch | + +*Rationale*: These register meanings are compatible with Go’s +stack-based calling convention. Context register X20 will change to X26, +duffcopy, duffzero register will change to X24, X25 before this register ABI been adopted. +X10 – X17, X8, X9, X18 – X23, is the same order as A0 – A7, S0 – S7 in platform ABI. +F10 – F17, F8, F9, F18 – F23, is the same order as FA0 – FA7, FS0 – FS7 in platform ABI. +X8 – X23, F8 – F15 are used for compressed instruction (RVC) which will benefit code size in the future. + +#### Stack layout + +The stack pointer, X2, grows down and is aligned to 8 bytes. + +A function's stack frame, after the frame is created, is laid out as +follows: + + +------------------------------+ + | ... locals ... | + | ... outgoing arguments ... | + | return PC | ← X2 points to + +------------------------------+ ↓ lower addresses + +The "return PC" is loaded to the link register, X1, as part of the +riscv64 `CALL` operation. + +#### Flags + +The riscv64 has Zicsr extension for control and status register (CSR) and +treated as scratch register. +All bits in CSR are system flags and are not modified by Go. + ## Future directions ### Spill path improvements From c6d9b38dd82fea8775f1dff9a4a70a017463035d Mon Sep 17 00:00:00 2001 From: eric fang Date: Tue, 18 Jan 2022 02:52:08 +0000 Subject: [PATCH 052/276] cmd/internal/obj/arm64: optimize function prologue/epilogue with STP/LDP In function prologue and epilogue, we save and restore FP and LR registers, and adjust RSP. The current instruction sequence is as follow. For frame size <= 240B, prologue: MOVD.W R30, -offset(RSP) MOVD R29, -8(RSP) epilogue: MOVD -8(RSP), R29 MOVD.P offset(RSP), R30 For frame size > 240B, prologue: SUB $offset, RSP, R27 MOVD R30, (R27) MOVD R27, RSP MOVD R29, -8(RSP) epilogue: MOVD -8(RSP), R29 MOVD (RSP), R30 ADD $offset, RSP Each sequence uses two load or store instructions, actually we can load or store two registers with one LDP or STP instruction. This CL changes the sequences as follow. For frame size <= 496B, prologue: STP (R29, R30), -(offset+8)(RSP) SUB $offset, RSP, RSP epilogue: LDP -8(RSP), (R29, R30) ADD $offset, RSP, RSP For frame size > 496B, prologue: SUB $offset, RSP, R20 STP (R29, R30), -8(R20) MOVD R20, RSP epilogue: LDP -8(RSP), (R29, R30) ADD $offset, RSP, RSP Change-Id: Ia58af85fc81cce9b7c393dc38df43bffb203baad Reviewed-on: https://go-review.googlesource.com/c/go/+/379075 Reviewed-by: Cherry Mui Trust: Eric Fang Run-TryBot: Eric Fang --- src/cmd/internal/obj/arm64/obj7.go | 188 +++++++++++++++-------------- 1 file changed, 100 insertions(+), 88 deletions(-) diff --git a/src/cmd/internal/obj/arm64/obj7.go b/src/cmd/internal/obj/arm64/obj7.go index 2bbc7e37b0b..43f7b16d6e2 100644 --- a/src/cmd/internal/obj/arm64/obj7.go +++ b/src/cmd/internal/obj/arm64/obj7.go @@ -622,92 +622,124 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) { var prologueEnd *obj.Prog aoffset := c.autosize - if aoffset > 0xF0 { - aoffset = 0xF0 + if aoffset > 0x1f0 { + // LDP offset variant range is -512 to 504, SP should be 16-byte aligned, + // so the maximum aoffset value is 496. + aoffset = 0x1f0 } // Frame is non-empty. Make sure to save link register, even if // it is a leaf function, so that traceback works. q = p if c.autosize > aoffset { - // Frame size is too large for a MOVD.W instruction. - // Store link register before decrementing SP, so if a signal comes - // during the execution of the function prologue, the traceback - // code will not see a half-updated stack frame. - // This sequence is not async preemptible, as if we open a frame - // at the current SP, it will clobber the saved LR. - q = c.ctxt.StartUnsafePoint(q, c.newprog) + // Frame size is too large for a STP instruction. Store the frame pointer + // register and link register before decrementing SP, so if a signal comes + // during the execution of the function prologue, the traceback code will + // not see a half-updated stack frame. - q = obj.Appendp(q, c.newprog) - q.Pos = p.Pos - q.As = ASUB - q.From.Type = obj.TYPE_CONST - q.From.Offset = int64(c.autosize) - q.Reg = REGSP - q.To.Type = obj.TYPE_REG - q.To.Reg = REGTMP + // SUB $autosize, RSP, R20 + q1 = obj.Appendp(q, c.newprog) + q1.Pos = p.Pos + q1.As = ASUB + q1.From.Type = obj.TYPE_CONST + q1.From.Offset = int64(c.autosize) + q1.Reg = REGSP + q1.To.Type = obj.TYPE_REG + q1.To.Reg = REG_R20 - prologueEnd = q + prologueEnd = q1 - q = obj.Appendp(q, c.newprog) - q.Pos = p.Pos - q.As = AMOVD - q.From.Type = obj.TYPE_REG - q.From.Reg = REGLINK - q.To.Type = obj.TYPE_MEM - q.To.Reg = REGTMP + // STP (R29, R30), -8(R20) + q1 = obj.Appendp(q1, c.newprog) + q1.Pos = p.Pos + q1.As = ASTP + q1.From.Type = obj.TYPE_REGREG + q1.From.Reg = REGFP + q1.From.Offset = REGLINK + q1.To.Type = obj.TYPE_MEM + q1.To.Reg = REG_R20 + q1.To.Offset = -8 - q1 = obj.Appendp(q, c.newprog) + // This is not async preemptible, as if we open a frame + // at the current SP, it will clobber the saved LR. + q1 = c.ctxt.StartUnsafePoint(q1, c.newprog) + + // MOVD R20, RSP + q1 = obj.Appendp(q1, c.newprog) q1.Pos = p.Pos q1.As = AMOVD q1.From.Type = obj.TYPE_REG - q1.From.Reg = REGTMP + q1.From.Reg = REG_R20 q1.To.Type = obj.TYPE_REG q1.To.Reg = REGSP q1.Spadj = c.autosize + q1 = c.ctxt.EndUnsafePoint(q1, c.newprog, -1) + if buildcfg.GOOS == "ios" { // iOS does not support SA_ONSTACK. We will run the signal handler // on the G stack. If we write below SP, it may be clobbered by - // the signal handler. So we save LR after decrementing SP. + // the signal handler. So we save FP and LR after decrementing SP. + // STP (R29, R30), -8(RSP) q1 = obj.Appendp(q1, c.newprog) q1.Pos = p.Pos - q1.As = AMOVD - q1.From.Type = obj.TYPE_REG - q1.From.Reg = REGLINK + q1.As = ASTP + q1.From.Type = obj.TYPE_REGREG + q1.From.Reg = REGFP + q1.From.Offset = REGLINK q1.To.Type = obj.TYPE_MEM q1.To.Reg = REGSP + q1.To.Offset = -8 } - - q1 = c.ctxt.EndUnsafePoint(q1, c.newprog, -1) } else { - // small frame, update SP and save LR in a single MOVD.W instruction + // small frame, save FP and LR with one STP instruction, then update SP. + // Store first, so if a signal comes during the execution of the function + // prologue, the traceback code will not see a half-updated stack frame. + // STP (R29, R30), -aoffset-8(RSP) q1 = obj.Appendp(q, c.newprog) - q1.As = AMOVD + q1.As = ASTP q1.Pos = p.Pos - q1.From.Type = obj.TYPE_REG - q1.From.Reg = REGLINK + q1.From.Type = obj.TYPE_REGREG + q1.From.Reg = REGFP + q1.From.Offset = REGLINK q1.To.Type = obj.TYPE_MEM - q1.Scond = C_XPRE - q1.To.Offset = int64(-aoffset) + q1.To.Offset = int64(-aoffset - 8) q1.To.Reg = REGSP - q1.Spadj = aoffset prologueEnd = q1 + + q1 = c.ctxt.StartUnsafePoint(q1, c.newprog) + // This instruction is not async preemptible, see the above comment. + // SUB $aoffset, RSP, RSP + q1 = obj.Appendp(q1, c.newprog) + q1.Pos = p.Pos + q1.As = ASUB + q1.From.Type = obj.TYPE_CONST + q1.From.Offset = int64(aoffset) + q1.Reg = REGSP + q1.To.Type = obj.TYPE_REG + q1.To.Reg = REGSP + q1.Spadj = aoffset + + q1 = c.ctxt.EndUnsafePoint(q1, c.newprog, -1) + + if buildcfg.GOOS == "ios" { + // See the above comment. + // STP (R29, R30), -8(RSP) + q1 = obj.Appendp(q1, c.newprog) + q1.As = ASTP + q1.Pos = p.Pos + q1.From.Type = obj.TYPE_REGREG + q1.From.Reg = REGFP + q1.From.Offset = REGLINK + q1.To.Type = obj.TYPE_MEM + q1.To.Offset = int64(-8) + q1.To.Reg = REGSP + } } prologueEnd.Pos = prologueEnd.Pos.WithXlogue(src.PosPrologueEnd) - // Frame pointer. - q1 = obj.Appendp(q1, c.newprog) - q1.Pos = p.Pos - q1.As = AMOVD - q1.From.Type = obj.TYPE_REG - q1.From.Reg = REGFP - q1.To.Type = obj.TYPE_MEM - q1.To.Reg = REGSP - q1.To.Offset = -8 - q1 = obj.Appendp(q1, c.newprog) q1.Pos = p.Pos q1.As = ASUB @@ -850,48 +882,28 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) { p.To.Reg = REGFP } } else { - /* want write-back pre-indexed SP+autosize -> SP, loading REGLINK*/ - - // Frame pointer. - p.As = AMOVD + aoffset := c.autosize + // LDP -8(RSP), (R29, R30) + p.As = ALDP p.From.Type = obj.TYPE_MEM - p.From.Reg = REGSP p.From.Offset = -8 - p.To.Type = obj.TYPE_REG + p.From.Reg = REGSP + p.To.Type = obj.TYPE_REGREG p.To.Reg = REGFP - p = obj.Appendp(p, c.newprog) - - aoffset := c.autosize + p.To.Offset = REGLINK - if aoffset <= 0xF0 { - p.As = AMOVD - p.From.Type = obj.TYPE_MEM - p.Scond = C_XPOST - p.From.Offset = int64(aoffset) - p.From.Reg = REGSP - p.To.Type = obj.TYPE_REG - p.To.Reg = REGLINK - p.Spadj = -aoffset - } else { - p.As = AMOVD - p.From.Type = obj.TYPE_MEM - p.From.Offset = 0 - p.From.Reg = REGSP - p.To.Type = obj.TYPE_REG - p.To.Reg = REGLINK - - q = newprog() - q.As = AADD - q.From.Type = obj.TYPE_CONST - q.From.Offset = int64(aoffset) - q.To.Type = obj.TYPE_REG - q.To.Reg = REGSP - q.Link = p.Link - q.Spadj = int32(-q.From.Offset) - q.Pos = p.Pos - p.Link = q - p = q - } + // ADD $aoffset, RSP, RSP + q = newprog() + q.As = AADD + q.From.Type = obj.TYPE_CONST + q.From.Offset = int64(aoffset) + q.To.Type = obj.TYPE_REG + q.To.Reg = REGSP + q.Spadj = -aoffset + q.Pos = p.Pos + q.Link = p.Link + p.Link = q + p = q } // If enabled, this code emits 'MOV PC, R27' before every 'MOV LR, PC', From 7160e3252991d9462ee3a155b5504c564a6cffe5 Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Tue, 8 Mar 2022 14:59:32 -0800 Subject: [PATCH 053/276] cmd/compile: mark instantiated generic functions as DUPOK Unified IR wasn't marking instantiated generic functions as DUPOK, even though they can appear in multiple compilation units, which evidently interfered with cmd/link's dead code elimination logic. Manually confirmed to fix the issue, but non-trivial to test within $GOROOT/test currently, because it's only reproducible when cmd/compile is invoked with -p. @rsc is currently investigating updating test/run.go appropriately, after which I'll revisit writing a test case. Fixes #51519. Change-Id: I74a79ed0ca15b25b826e419714af5ceb6e567012 Reviewed-on: https://go-review.googlesource.com/c/go/+/390956 Trust: Matthew Dempsky Run-TryBot: Matthew Dempsky TryBot-Result: Gopher Robot Reviewed-by: Cherry Mui --- src/cmd/compile/internal/noder/reader.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/cmd/compile/internal/noder/reader.go b/src/cmd/compile/internal/noder/reader.go index 004630236d6..73e4ddbbedc 100644 --- a/src/cmd/compile/internal/noder/reader.go +++ b/src/cmd/compile/internal/noder/reader.go @@ -644,6 +644,10 @@ func (pr *pkgReader) objIdx(idx int, implicits, explicits []*types.Type) ir.Node name.Func = ir.NewFunc(r.pos()) name.Func.Nname = name + if r.hasTypeParams() { + name.Func.SetDupok(true) + } + rext.funcExt(name) return name @@ -790,6 +794,10 @@ func (r *reader) method(rext *reader) *types.Field { name.Func = ir.NewFunc(r.pos()) name.Func.Nname = name + if r.hasTypeParams() { + name.Func.SetDupok(true) + } + rext.funcExt(name) meth := types.NewField(name.Func.Pos(), sym, typ) From 0d33a9967540fe06f5ce7b14790e9be8da576936 Mon Sep 17 00:00:00 2001 From: Rhys Hiltner Date: Wed, 9 Mar 2022 07:56:04 -0800 Subject: [PATCH 054/276] runtime/pprof: fix pcDeck's frame indexing When building the inlining deck, correctly identify which is the last frame in the deck. Otherwise, when some forms of inlining cause a PC to expand to multiple frames, the length of the deck's two slices will diverge. Fixes #51567 Change-Id: I24e7ba32cb16b167f4307178b3f03c29e5362c4b Reviewed-on: https://go-review.googlesource.com/c/go/+/391134 Reviewed-by: Michael Pratt Trust: Than McIntosh --- src/runtime/pprof/proto.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime/pprof/proto.go b/src/runtime/pprof/proto.go index 215bd0bf96c..68dac42d200 100644 --- a/src/runtime/pprof/proto.go +++ b/src/runtime/pprof/proto.go @@ -530,7 +530,7 @@ func (d *pcDeck) reset() { // since the stack trace is already fully expanded) and the symbolizeResult // to the deck. If it fails the caller needs to flush the deck and retry. func (d *pcDeck) tryAdd(pc uintptr, frames []runtime.Frame, symbolizeResult symbolizeFlag) (success bool) { - if existing := len(d.pcs); existing > 0 { + if existing := len(d.frames); existing > 0 { // 'd.frames' are all expanded from one 'pc' and represent all // inlined functions so we check only the last one. newFrame := frames[0] From 7026eeb8cfdc5801adddaaa678fb6495a998db0e Mon Sep 17 00:00:00 2001 From: Mark Pulford Date: Sun, 27 Feb 2022 23:22:22 +1030 Subject: [PATCH 055/276] cmd/go: fix buildvcs when using older git versions Git versions before v2.10.0 do not support --no-show-signature. Using "-c" allows Git to ignore the configuration option if it does not exist. Fixes #51253 Change-Id: I2b1adaca0eb18ae31f2e1119e354ce515b00cfc2 Reviewed-on: https://go-review.googlesource.com/c/go/+/388194 Trust: Dmitri Shuralyov Run-TryBot: Dmitri Shuralyov TryBot-Result: Gopher Robot Reviewed-by: Bryan Mills --- src/cmd/go/internal/vcs/vcs.go | 2 +- src/cmd/go/testdata/script/version_buildvcs_git.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cmd/go/internal/vcs/vcs.go b/src/cmd/go/internal/vcs/vcs.go index fd521b2eb15..2acabf7aafb 100644 --- a/src/cmd/go/internal/vcs/vcs.go +++ b/src/cmd/go/internal/vcs/vcs.go @@ -312,7 +312,7 @@ func gitStatus(vcsGit *Cmd, rootDir string) (Status, error) { // uncommitted files and skip tagging revision / committime. var rev string var commitTime time.Time - out, err = vcsGit.runOutputVerboseOnly(rootDir, "show -s --no-show-signature --format=%H:%ct") + out, err = vcsGit.runOutputVerboseOnly(rootDir, "-c log.showsignature=false show -s --format=%H:%ct") if err != nil && !uncommitted { return Status{}, err } else if err == nil { diff --git a/src/cmd/go/testdata/script/version_buildvcs_git.txt b/src/cmd/go/testdata/script/version_buildvcs_git.txt index 86d1de06df4..44706870e22 100644 --- a/src/cmd/go/testdata/script/version_buildvcs_git.txt +++ b/src/cmd/go/testdata/script/version_buildvcs_git.txt @@ -111,7 +111,7 @@ rm $GOBIN/d$GOEXE go list -x ./... stdout -count=3 '^example.com' stderr -count=1 '^git status' -stderr -count=1 '^git show' +stderr -count=1 '^git -c log.showsignature=false show' -- $WORK/fakebin/git -- #!/bin/sh From b8248fab897da9bee2211a98df1656883ccecd6d Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Wed, 9 Mar 2022 10:01:24 -0800 Subject: [PATCH 056/276] go/types, types2: disable field accesses through type parameters This is a feature that is not understood well enough and may have subtle repercussions impacting future changes. Disable for Go 1.18. The actual change is trivial: disable a branch through a flag. The remaining changes are adjustments to tests. Fixes #51576. Change-Id: Ib77b038b846711a808315a8889b3904e72367bce Reviewed-on: https://go-review.googlesource.com/c/go/+/391135 Trust: Robert Griesemer Run-TryBot: Robert Griesemer Reviewed-by: Robert Findley TryBot-Result: Gopher Robot --- src/cmd/compile/internal/types2/lookup.go | 3 +- .../types2/testdata/fixedbugs/issue50417.go2 | 24 +++++++----- .../types2/testdata/fixedbugs/issue50782.go2 | 13 +++++-- src/go/types/lookup.go | 3 +- .../types/testdata/fixedbugs/issue50417.go2 | 24 +++++++----- .../types/testdata/fixedbugs/issue50782.go2 | 13 +++++-- test/typeparam/absdiff2.go | 32 +++++++++++----- test/typeparam/absdiffimp2.dir/a.go | 32 +++++++++++----- test/typeparam/issue50417.go | 6 +++ test/typeparam/issue50417b.go | 8 ++++ test/typeparam/issue50690a.go | 37 +++++++++++++------ test/typeparam/issue50690b.go | 26 +++++++++---- test/typeparam/issue50690c.go | 30 +++++++++++---- 13 files changed, 177 insertions(+), 74 deletions(-) diff --git a/src/cmd/compile/internal/types2/lookup.go b/src/cmd/compile/internal/types2/lookup.go index 0a2d2a57902..08328772260 100644 --- a/src/cmd/compile/internal/types2/lookup.go +++ b/src/cmd/compile/internal/types2/lookup.go @@ -70,7 +70,8 @@ func LookupFieldOrMethod(T Type, addressable bool, pkg *Package, name string) (o // see if there is a matching field (but not a method, those need to be declared // explicitly in the constraint). If the constraint is a named pointer type (see // above), we are ok here because only fields are accepted as results. - if obj == nil && isTypeParam(T) { + const enableTParamFieldLookup = false // see issue #51576 + if enableTParamFieldLookup && obj == nil && isTypeParam(T) { if t := coreType(T); t != nil { obj, index, indirect = lookupFieldOrMethod(t, addressable, pkg, name, false) if _, ok := obj.(*Var); !ok { diff --git a/src/cmd/compile/internal/types2/testdata/fixedbugs/issue50417.go2 b/src/cmd/compile/internal/types2/testdata/fixedbugs/issue50417.go2 index 50487fa2ffe..2caef1b9863 100644 --- a/src/cmd/compile/internal/types2/testdata/fixedbugs/issue50417.go2 +++ b/src/cmd/compile/internal/types2/testdata/fixedbugs/issue50417.go2 @@ -2,6 +2,10 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// Field accesses through type parameters are disabled +// until we have a more thorough understanding of the +// implications on the spec. See issue #51576. + package p type Sf struct { @@ -9,13 +13,13 @@ type Sf struct { } func f0[P Sf](p P) { - _ = p.f - p.f = 0 + _ = p.f // ERROR p\.f undefined + p.f /* ERROR p\.f undefined */ = 0 } func f0t[P ~struct{f int}](p P) { - _ = p.f - p.f = 0 + _ = p.f // ERROR p\.f undefined + p.f /* ERROR p\.f undefined */ = 0 } var _ = f0[Sf] @@ -25,8 +29,8 @@ var _ = f0[Sm /* ERROR does not implement */ ] var _ = f0t[Sm /* ERROR does not implement */ ] func f1[P interface{ Sf; m() }](p P) { - _ = p.f - p.f = 0 + _ = p.f // ERROR p\.f undefined + p.f /* ERROR p\.f undefined */ = 0 p.m() } @@ -44,8 +48,8 @@ type Sfm struct { func (Sfm) m() {} func f2[P interface{ Sfm; m() }](p P) { - _ = p.f - p.f = 0 + _ = p.f // ERROR p\.f undefined + p.f /* ERROR p\.f undefined */ = 0 p.m() } @@ -56,8 +60,8 @@ var _ = f2[Sfm] type PSfm *Sfm func f3[P interface{ PSfm }](p P) { - _ = p.f - p.f = 0 + _ = p.f // ERROR p\.f undefined + p.f /* ERROR p\.f undefined */ = 0 p.m /* ERROR type P has no field or method m */ () } diff --git a/src/cmd/compile/internal/types2/testdata/fixedbugs/issue50782.go2 b/src/cmd/compile/internal/types2/testdata/fixedbugs/issue50782.go2 index 8f41b841630..fd1ab11b8cf 100644 --- a/src/cmd/compile/internal/types2/testdata/fixedbugs/issue50782.go2 +++ b/src/cmd/compile/internal/types2/testdata/fixedbugs/issue50782.go2 @@ -2,6 +2,10 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// Field accesses through type parameters are disabled +// until we have a more thorough understanding of the +// implications on the spec. See issue #51576. + package p // The first example from the issue. @@ -18,9 +22,12 @@ type numericAbs[T Numeric] interface { // AbsDifference computes the absolute value of the difference of // a and b, where the absolute value is determined by the Abs method. func absDifference[T numericAbs[T /* ERROR T does not implement Numeric */]](a, b T) T { - // TODO: the error below should probably be positioned on the '-'. - d := a /* ERROR "invalid operation: operator - not defined" */ .Value - b.Value - return d.Abs() + // Field accesses are not permitted for now. Keep an error so + // we can find and fix this code once the situation changes. + return a.Value // ERROR a\.Value undefined + // TODO: The error below should probably be positioned on the '-'. + // d := a /* ERROR "invalid operation: operator - not defined" */ .Value - b.Value + // return d.Abs() } // The second example from the issue. diff --git a/src/go/types/lookup.go b/src/go/types/lookup.go index 501c230357b..335fada7b76 100644 --- a/src/go/types/lookup.go +++ b/src/go/types/lookup.go @@ -70,7 +70,8 @@ func LookupFieldOrMethod(T Type, addressable bool, pkg *Package, name string) (o // see if there is a matching field (but not a method, those need to be declared // explicitly in the constraint). If the constraint is a named pointer type (see // above), we are ok here because only fields are accepted as results. - if obj == nil && isTypeParam(T) { + const enableTParamFieldLookup = false // see issue #51576 + if enableTParamFieldLookup && obj == nil && isTypeParam(T) { if t := coreType(T); t != nil { obj, index, indirect = lookupFieldOrMethod(t, addressable, pkg, name, false) if _, ok := obj.(*Var); !ok { diff --git a/src/go/types/testdata/fixedbugs/issue50417.go2 b/src/go/types/testdata/fixedbugs/issue50417.go2 index 50487fa2ffe..2caef1b9863 100644 --- a/src/go/types/testdata/fixedbugs/issue50417.go2 +++ b/src/go/types/testdata/fixedbugs/issue50417.go2 @@ -2,6 +2,10 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// Field accesses through type parameters are disabled +// until we have a more thorough understanding of the +// implications on the spec. See issue #51576. + package p type Sf struct { @@ -9,13 +13,13 @@ type Sf struct { } func f0[P Sf](p P) { - _ = p.f - p.f = 0 + _ = p.f // ERROR p\.f undefined + p.f /* ERROR p\.f undefined */ = 0 } func f0t[P ~struct{f int}](p P) { - _ = p.f - p.f = 0 + _ = p.f // ERROR p\.f undefined + p.f /* ERROR p\.f undefined */ = 0 } var _ = f0[Sf] @@ -25,8 +29,8 @@ var _ = f0[Sm /* ERROR does not implement */ ] var _ = f0t[Sm /* ERROR does not implement */ ] func f1[P interface{ Sf; m() }](p P) { - _ = p.f - p.f = 0 + _ = p.f // ERROR p\.f undefined + p.f /* ERROR p\.f undefined */ = 0 p.m() } @@ -44,8 +48,8 @@ type Sfm struct { func (Sfm) m() {} func f2[P interface{ Sfm; m() }](p P) { - _ = p.f - p.f = 0 + _ = p.f // ERROR p\.f undefined + p.f /* ERROR p\.f undefined */ = 0 p.m() } @@ -56,8 +60,8 @@ var _ = f2[Sfm] type PSfm *Sfm func f3[P interface{ PSfm }](p P) { - _ = p.f - p.f = 0 + _ = p.f // ERROR p\.f undefined + p.f /* ERROR p\.f undefined */ = 0 p.m /* ERROR type P has no field or method m */ () } diff --git a/src/go/types/testdata/fixedbugs/issue50782.go2 b/src/go/types/testdata/fixedbugs/issue50782.go2 index 8f41b841630..fd1ab11b8cf 100644 --- a/src/go/types/testdata/fixedbugs/issue50782.go2 +++ b/src/go/types/testdata/fixedbugs/issue50782.go2 @@ -2,6 +2,10 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// Field accesses through type parameters are disabled +// until we have a more thorough understanding of the +// implications on the spec. See issue #51576. + package p // The first example from the issue. @@ -18,9 +22,12 @@ type numericAbs[T Numeric] interface { // AbsDifference computes the absolute value of the difference of // a and b, where the absolute value is determined by the Abs method. func absDifference[T numericAbs[T /* ERROR T does not implement Numeric */]](a, b T) T { - // TODO: the error below should probably be positioned on the '-'. - d := a /* ERROR "invalid operation: operator - not defined" */ .Value - b.Value - return d.Abs() + // Field accesses are not permitted for now. Keep an error so + // we can find and fix this code once the situation changes. + return a.Value // ERROR a\.Value undefined + // TODO: The error below should probably be positioned on the '-'. + // d := a /* ERROR "invalid operation: operator - not defined" */ .Value - b.Value + // return d.Abs() } // The second example from the issue. diff --git a/test/typeparam/absdiff2.go b/test/typeparam/absdiff2.go index f3e058d4685..87a1ec6de1a 100644 --- a/test/typeparam/absdiff2.go +++ b/test/typeparam/absdiff2.go @@ -23,15 +23,16 @@ type Numeric interface { // numericAbs matches a struct containing a numeric type that has an Abs method. type numericAbs[T Numeric] interface { - ~struct{ Value T } + ~struct{ Value_ T } Abs() T + Value() T } // absDifference computes the absolute value of the difference of // a and b, where the absolute value is determined by the Abs method. func absDifference[T Numeric, U numericAbs[T]](a, b U) T { - d := a.Value - b.Value - dt := U{Value: d} + d := a.Value() - b.Value() + dt := U{Value_: d} return dt.Abs() } @@ -50,20 +51,29 @@ type Complex interface { // orderedAbs is a helper type that defines an Abs method for // a struct containing an ordered numeric type. type orderedAbs[T orderedNumeric] struct { - Value T + Value_ T } func (a orderedAbs[T]) Abs() T { - if a.Value < 0 { - return -a.Value + if a.Value_ < 0 { + return -a.Value_ } - return a.Value + return a.Value_ +} + +// Field accesses through type parameters are disabled +// until we have a more thorough understanding of the +// implications on the spec. See issue #51576. +// Use accessor method instead. + +func (a orderedAbs[T]) Value() T { + return a.Value_ } // complexAbs is a helper type that defines an Abs method for // a struct containing a complex type. type complexAbs[T Complex] struct { - Value T + Value_ T } func realimag(x any) (re, im float64) { @@ -82,13 +92,17 @@ func realimag(x any) (re, im float64) { func (a complexAbs[T]) Abs() T { // TODO use direct conversion instead of realimag once #50937 is fixed - r, i := realimag(a.Value) + r, i := realimag(a.Value_) // r := float64(real(a.Value)) // i := float64(imag(a.Value)) d := math.Sqrt(r*r + i*i) return T(complex(d, 0)) } +func (a complexAbs[T]) Value() T { + return a.Value_ +} + // OrderedAbsDifference returns the absolute value of the difference // between a and b, where a and b are of an ordered type. func OrderedAbsDifference[T orderedNumeric](a, b T) T { diff --git a/test/typeparam/absdiffimp2.dir/a.go b/test/typeparam/absdiffimp2.dir/a.go index 43493e1430d..dc64f2dcbed 100644 --- a/test/typeparam/absdiffimp2.dir/a.go +++ b/test/typeparam/absdiffimp2.dir/a.go @@ -17,15 +17,16 @@ type Numeric interface { // numericAbs matches a struct containing a numeric type that has an Abs method. type numericAbs[T Numeric] interface { - ~struct{ Value T } + ~struct{ Value_ T } Abs() T + Value() T } // absDifference computes the absolute value of the difference of // a and b, where the absolute value is determined by the Abs method. func absDifference[T Numeric, U numericAbs[T]](a, b U) T { - d := a.Value - b.Value - dt := U{Value: d} + d := a.Value() - b.Value() + dt := U{Value_: d} return dt.Abs() } @@ -44,20 +45,29 @@ type Complex interface { // orderedAbs is a helper type that defines an Abs method for // a struct containing an ordered numeric type. type orderedAbs[T orderedNumeric] struct { - Value T + Value_ T } func (a orderedAbs[T]) Abs() T { - if a.Value < 0 { - return -a.Value + if a.Value_ < 0 { + return -a.Value_ } - return a.Value + return a.Value_ +} + +// Field accesses through type parameters are disabled +// until we have a more thorough understanding of the +// implications on the spec. See issue #51576. +// Use accessor method instead. + +func (a orderedAbs[T]) Value() T { + return a.Value_ } // complexAbs is a helper type that defines an Abs method for // a struct containing a complex type. type complexAbs[T Complex] struct { - Value T + Value_ T } func realimag(x any) (re, im float64) { @@ -76,13 +86,17 @@ func realimag(x any) (re, im float64) { func (a complexAbs[T]) Abs() T { // TODO use direct conversion instead of realimag once #50937 is fixed - r, i := realimag(a.Value) + r, i := realimag(a.Value_) // r := float64(real(a.Value)) // i := float64(imag(a.Value)) d := math.Sqrt(r*r + i*i) return T(complex(d, 0)) } +func (a complexAbs[T]) Value() T { + return a.Value_ +} + // OrderedAbsDifference returns the absolute value of the difference // between a and b, where a and b are of an ordered type. func OrderedAbsDifference[T orderedNumeric](a, b T) T { diff --git a/test/typeparam/issue50417.go b/test/typeparam/issue50417.go index 3d5f2f25380..b32e270bdfc 100644 --- a/test/typeparam/issue50417.go +++ b/test/typeparam/issue50417.go @@ -8,6 +8,11 @@ package main func main() {} +// Field accesses through type parameters are disabled +// until we have a more thorough understanding of the +// implications on the spec. See issue #51576. + +/* type Sf struct { f int } @@ -138,3 +143,4 @@ func f8[P Int4](p P) { } var _ = f8[*Sf] +*/ diff --git a/test/typeparam/issue50417b.go b/test/typeparam/issue50417b.go index 8c13a4ee36a..1c803b09bdf 100644 --- a/test/typeparam/issue50417b.go +++ b/test/typeparam/issue50417b.go @@ -6,6 +6,13 @@ package main +func main() {} + +// Field accesses through type parameters are disabled +// until we have a more thorough understanding of the +// implications on the spec. See issue #51576. + +/* import "fmt" type MyStruct struct { @@ -48,3 +55,4 @@ func main() { panic(fmt.Sprintf("got %d, want %d", got, want)) } } +*/ diff --git a/test/typeparam/issue50690a.go b/test/typeparam/issue50690a.go index 35e8c20e072..6691af0a073 100644 --- a/test/typeparam/issue50690a.go +++ b/test/typeparam/issue50690a.go @@ -29,34 +29,47 @@ func Sum[T Numeric](args ...T) T { // Ledger is an identifiable, financial record. type Ledger[T ~string, K Numeric] struct { - // ID identifies the ledger. - ID T + ID_ T // Amounts is a list of monies associated with this ledger. - Amounts []K + Amounts_ []K // SumFn is a function that can be used to sum the amounts // in this ledger. - SumFn func(...K) K + SumFn_ func(...K) K } +// Field accesses through type parameters are disabled +// until we have a more thorough understanding of the +// implications on the spec. See issue #51576. +// Use accessor methods instead. + +func (l Ledger[T, _]) ID() T { return l.ID_ } +func (l Ledger[_, K]) Amounts() []K { return l.Amounts_ } +func (l Ledger[_, K]) SumFn() func(...K) K { return l.SumFn_ } + func PrintLedger[ T ~string, K Numeric, - L ~struct { - ID T - Amounts []K - SumFn func(...K) K + L interface { + ~struct { + ID_ T + Amounts_ []K + SumFn_ func(...K) K + } + ID() T + Amounts() []K + SumFn() func(...K) K }, ](l L) { - fmt.Printf("%s has a sum of %v\n", l.ID, l.SumFn(l.Amounts...)) + fmt.Printf("%s has a sum of %v\n", l.ID(), l.SumFn()(l.Amounts()...)) } func main() { PrintLedger(Ledger[string, int]{ - ID: "fake", - Amounts: []int{1, 2, 3}, - SumFn: Sum[int], + ID_: "fake", + Amounts_: []int{1, 2, 3}, + SumFn_: Sum[int], }) } diff --git a/test/typeparam/issue50690b.go b/test/typeparam/issue50690b.go index 13e725ae0a7..09c84e089df 100644 --- a/test/typeparam/issue50690b.go +++ b/test/typeparam/issue50690b.go @@ -18,24 +18,34 @@ func Print[T ~string](s T) { fmt.Println(s) } -func PrintWithPrinter[T ~string, S ~struct { - ID T - PrintFn func(T) +func PrintWithPrinter[T ~string, S interface { + ~struct { + ID T + PrintFn_ func(T) + } + PrintFn() func(T) }](message T, obj S) { - obj.PrintFn(message) + obj.PrintFn()(message) } type PrintShop[T ~string] struct { - ID T - PrintFn func(T) + ID T + PrintFn_ func(T) } +// Field accesses through type parameters are disabled +// until we have a more thorough understanding of the +// implications on the spec. See issue #51576. +// Use accessor method instead. + +func (s PrintShop[T]) PrintFn() func(T) { return s.PrintFn_ } + func main() { PrintWithPrinter( "Hello, world.", PrintShop[string]{ - ID: "fake", - PrintFn: Print[string], + ID: "fake", + PrintFn_: Print[string], }, ) } diff --git a/test/typeparam/issue50690c.go b/test/typeparam/issue50690c.go index 75e772cccd5..2db1487ecb1 100644 --- a/test/typeparam/issue50690c.go +++ b/test/typeparam/issue50690c.go @@ -18,19 +18,33 @@ func Print[T ~string](s T) { fmt.Println(s) } -func PrintWithPrinter[T ~string, S struct { - ID T - PrintFn func(T) +func PrintWithPrinter[T ~string, S interface { + ~struct { + ID T + PrintFn_ func(T) + } + PrintFn() func(T) }](message T, obj S) { - obj.PrintFn(message) + obj.PrintFn()(message) } func main() { PrintWithPrinter( "Hello, world.", - struct { - ID string - PrintFn func(string) - }{ID: "fake", PrintFn: Print[string]}, + StructWithPrinter{ID: "fake", PrintFn_: Print[string]}, ) } + +type StructWithPrinter struct { + ID string + PrintFn_ func(string) +} + +// Field accesses through type parameters are disabled +// until we have a more thorough understanding of the +// implications on the spec. See issue #51576. +// Use accessor method instead. + +func (s StructWithPrinter) PrintFn() func(string) { + return s.PrintFn_ +} From a987aaf5f7a5f64215ff75ac93a2c1b39967a8c9 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Tue, 8 Mar 2022 18:16:35 -0500 Subject: [PATCH 057/276] cmd/compile: require -p flag MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The -p flag specifies the import path of the package being compiled. This CL makes it required when invoking the compiler and adjusts tests that invoke the compiler directly to conform to this new requirement. The go command already passes the flag, so it is unmodified in this CL. It is expected that any other Go build systems also already pass -p, or else they will need to arrange to do so before updating to Go 1.19. Of particular note, Bazel already does for rules with an importpath= attribute, which includes all Gazelle-generated rules. There is more cleanup possible now in cmd/compile, cmd/link, and other consumers of Go object files, but that is left to future CLs. Additional historical background follows but can be ignored. Long ago, before the go command, or modules, or any kind of versioning, symbols in Go archive files were named using just the package name, so that for example func F in math/rand and func F in crypto/rand would both be the object file symbol 'rand.F'. This led to collisions even in small source trees, which made certain packages unusable in the presence of other packages and generally was a problem for Go's goal of scaling to very large source trees. Fixing this problem required changing from package names to import paths in symbol names, which was mostly straightforward. One wrinkle, though, is that the compiler did not know the import path of the package being compiled; it only knew the package name. At the time, there was no go command, just Makefiles that people had invoking 6g (now “go tool compile”) and then copying the resulting object file to an importable location. That is, everyone had a custom build setup for Go, because there was no standard one. So it was not particularly attractive to change how the compiler was invoked, since that would break approximately every Go user at the time. Instead, we arranged for the compiler to emit, and other tools reading object files to recognize, a special import path (the empty string, it turned out) denoting “the import path of this object file”. This worked well enough at the time and maintained complete command-line compatibility with existing Go usage. The changes implementing this transition can be found by searching the Git history for “package global name space”, which is what they eliminated. In particular, CL 190076 (a6736fa4), CL 186263 (758f2bc5), CL 193080 (1cecac81), CL 194053 (19126320), and CL 194071 (531e6b77) did the bulk of this transformation in January 2010. Later, in September 2011, we added the -p flag to the compiler for diagnostic purposes. The problem was that it was easy to create import cycles, especially in tests, and these could not be diagnosed until link time. You'd really want the compiler to diagnose these, for example if the compilation of package sort noticed it was importing a package that itself imported "sort". But the compilation of package sort didn't know its own import path, and so it could not tell whether it had found itself as a transitive dependency. Adding the -p flag solved this problem, and its use was optional, since the linker would still diagnose the import cycle in builds that had not updated to start passing -p. This was CL 4972057 (1e480cd1). There was still no go command at this point, but when we introduced the go command we made it pass -p, which it has for many years at this point. Over time, parts of the compiler began to depend on the presence of the -p flag for various reasonable purposes. For example: In CL 6497074 (041fc8bf; Oct 2012), the race detector used -p to detect packages that should not have race annotations, such as runtime/race and sync/atomic. In CL 13367052 (7276c02b; Sep 2013), a bug fix used -p to detect the compilation of package reflect. In CL 30539 (8aadcc55; Oct 2016), the compiler started using -p to identify package math, to be able to intrinsify calls to Sqrt inside that package. In CL 61019 (9daee931; Sep 2017), CL 71430 (2c1d2e06; Oct 2017), and later related CLs, the compiler started using the -p value when creating various DWARF debugging information. In CL 174657 (cc5eaf93; May 2019), the compiler started writing symbols without the magic empty string whenever -p was used, to reduce the amount of work required in the linker. In CL 179861 (dde7c770; Jun 2019), the compiler made the second argument to //go:linkname optional when -p is used, because in that case the compiler can derive an appropriate default. There are more examples. Today it is impossible to compile the Go standard library without using -p, and DWARF debug information is incomplete without using -p. All known Go build systems pass -p. In particular, the go command does, which is what nearly all Go developers invoke to build Go code. And Bazel does, for go_library rules that set the importpath attribute, which is all rules generated by Gazelle. Gccgo has an equivalent of -p and has required its use in order to disambiguate packages with the same name but different import paths since 2010. On top of all this, various parts of code generation for generics are made more complicated by needing to cope with the case where -p is not specified, even though it's essentially always specified. In summary, the current state is: - Use of the -p flag with cmd/compile is required for building the standard library, and for complete DWARF information, and to enable certain linker speedups. - The go command and Bazel, which we expect account for just about 100% of Go builds, both invoke cmd/compile with -p. - The code in cmd/compile to support builds without -p is complex and has become more complex with generics, but it is almost always dead code and therefore not worth maintaining. - Gccgo already requires its equivalent of -p in any build where two packages have the same name. All this supports the change in this CL, which makes -p required and adjusts tests that invoke cmd/compile to add -p appropriately. Future CLs will be able to remove all the code dealing with the possibility of -p not having been specified. Change-Id: I6b95b9d4cffe59c7bac82eb273ef6c4a67bb0e43 Reviewed-on: https://go-review.googlesource.com/c/go/+/391014 Trust: Russ Cox Run-TryBot: Russ Cox TryBot-Result: Gopher Robot Reviewed-by: Matthew Dempsky --- src/cmd/compile/internal/base/flag.go | 4 ++ .../internal/importer/gcimporter_test.go | 2 +- .../compile/internal/logopt/logopt_test.go | 6 +- .../compile/internal/test/fixedbugs_test.go | 2 +- src/cmd/compile/internal/test/lang_test.go | 2 +- .../internal/test/reproduciblebuilds_test.go | 4 +- src/cmd/internal/archive/archive_test.go | 4 +- src/cmd/internal/obj/objfile_test.go | 2 +- src/cmd/link/link_test.go | 14 ++-- src/cmd/objdump/objdump_test.go | 2 +- src/cmd/pack/pack_test.go | 16 ++--- src/go/internal/gcimporter/gcimporter_test.go | 2 +- src/internal/abi/abi_test.go | 2 +- test/const7.go | 2 +- test/fixedbugs/bug302.go | 4 +- test/fixedbugs/bug369.go | 6 +- test/fixedbugs/issue11771.go | 2 +- test/fixedbugs/issue21317.go | 2 +- test/fixedbugs/issue22660.go | 2 +- test/fixedbugs/issue22662b.go | 2 +- test/fixedbugs/issue26411.go | 2 +- test/fixedbugs/issue30908.go | 3 +- test/fixedbugs/issue9355.go | 2 +- test/interface/embed1.dir/embed0.go | 5 +- test/linkmain_run.go | 8 +-- test/linkname2.go | 21 ------ test/linkobj.go | 14 ++-- test/run.go | 69 +++++++++---------- test/sinit_run.go | 2 +- 29 files changed, 94 insertions(+), 114 deletions(-) delete mode 100644 test/linkname2.go diff --git a/src/cmd/compile/internal/base/flag.go b/src/cmd/compile/internal/base/flag.go index 6377091ce0b..0b04f62e1c1 100644 --- a/src/cmd/compile/internal/base/flag.go +++ b/src/cmd/compile/internal/base/flag.go @@ -201,6 +201,10 @@ func ParseFlags() { Exit(2) } + if *Flag.LowerP == "" { + log.Fatalf("-p is required") + } + if Flag.LowerO == "" { p := flag.Arg(0) if i := strings.LastIndex(p, "/"); i >= 0 { diff --git a/src/cmd/compile/internal/importer/gcimporter_test.go b/src/cmd/compile/internal/importer/gcimporter_test.go index 5d80db244b9..cc804aabbc5 100644 --- a/src/cmd/compile/internal/importer/gcimporter_test.go +++ b/src/cmd/compile/internal/importer/gcimporter_test.go @@ -38,7 +38,7 @@ func compile(t *testing.T, dirname, filename, outdirname string) string { } basename := filepath.Base(filename) outname := filepath.Join(outdirname, basename[:len(basename)-2]+"o") - cmd := exec.Command(testenv.GoToolPath(t), "tool", "compile", "-o", outname, filename) + cmd := exec.Command(testenv.GoToolPath(t), "tool", "compile", "-p=p", "-o", outname, filename) cmd.Dir = dirname out, err := cmd.CombinedOutput() if err != nil { diff --git a/src/cmd/compile/internal/logopt/logopt_test.go b/src/cmd/compile/internal/logopt/logopt_test.go index 902cbc8091f..8d07a49cc0f 100644 --- a/src/cmd/compile/internal/logopt/logopt_test.go +++ b/src/cmd/compile/internal/logopt/logopt_test.go @@ -226,7 +226,7 @@ func s15a8(x *[15]int64) [15]int64 { } func testLogOpt(t *testing.T, flag, src, outfile string) (string, error) { - run := []string{testenv.GoToolPath(t), "tool", "compile", flag, "-o", outfile, src} + run := []string{testenv.GoToolPath(t), "tool", "compile", "-p=p", flag, "-o", outfile, src} t.Log(run) cmd := exec.Command(run[0], run[1:]...) out, err := cmd.CombinedOutput() @@ -236,7 +236,7 @@ func testLogOpt(t *testing.T, flag, src, outfile string) (string, error) { func testLogOptDir(t *testing.T, dir, flag, src, outfile string) (string, error) { // Notice the specified import path "x" - run := []string{testenv.GoToolPath(t), "tool", "compile", "-p", "x", flag, "-o", outfile, src} + run := []string{testenv.GoToolPath(t), "tool", "compile", "-p=x", flag, "-o", outfile, src} t.Log(run) cmd := exec.Command(run[0], run[1:]...) cmd.Dir = dir @@ -247,7 +247,7 @@ func testLogOptDir(t *testing.T, dir, flag, src, outfile string) (string, error) func testCopy(t *testing.T, dir, goarch, goos, src, outfile string) (string, error) { // Notice the specified import path "x" - run := []string{testenv.GoToolPath(t), "tool", "compile", "-p", "x", "-json=0,file://log/opt", "-o", outfile, src} + run := []string{testenv.GoToolPath(t), "tool", "compile", "-p=x", "-json=0,file://log/opt", "-o", outfile, src} t.Log(run) cmd := exec.Command(run[0], run[1:]...) cmd.Dir = dir diff --git a/src/cmd/compile/internal/test/fixedbugs_test.go b/src/cmd/compile/internal/test/fixedbugs_test.go index 376b45edfcf..cd0d5fc3536 100644 --- a/src/cmd/compile/internal/test/fixedbugs_test.go +++ b/src/cmd/compile/internal/test/fixedbugs_test.go @@ -72,7 +72,7 @@ func TestIssue16214(t *testing.T) { t.Fatalf("could not write file: %v", err) } - cmd := exec.Command(testenv.GoToolPath(t), "tool", "compile", "-S", "-o", filepath.Join(dir, "out.o"), src) + cmd := exec.Command(testenv.GoToolPath(t), "tool", "compile", "-p=main", "-S", "-o", filepath.Join(dir, "out.o"), src) out, err := cmd.CombinedOutput() if err != nil { t.Fatalf("go tool compile: %v\n%s", err, out) diff --git a/src/cmd/compile/internal/test/lang_test.go b/src/cmd/compile/internal/test/lang_test.go index 67c15512922..66ab8401c68 100644 --- a/src/cmd/compile/internal/test/lang_test.go +++ b/src/cmd/compile/internal/test/lang_test.go @@ -56,7 +56,7 @@ func TestInvalidLang(t *testing.T) { } func testLang(t *testing.T, lang, src, outfile string) error { - run := []string{testenv.GoToolPath(t), "tool", "compile", "-lang", lang, "-o", outfile, src} + run := []string{testenv.GoToolPath(t), "tool", "compile", "-p=p", "-lang", lang, "-o", outfile, src} t.Log(run) out, err := exec.Command(run[0], run[1:]...).CombinedOutput() t.Logf("%s", out) diff --git a/src/cmd/compile/internal/test/reproduciblebuilds_test.go b/src/cmd/compile/internal/test/reproduciblebuilds_test.go index 4d84f9cdeff..0a1a5e9b994 100644 --- a/src/cmd/compile/internal/test/reproduciblebuilds_test.go +++ b/src/cmd/compile/internal/test/reproduciblebuilds_test.go @@ -41,7 +41,7 @@ func TestReproducibleBuilds(t *testing.T) { for i := 0; i < iters; i++ { // Note: use -c 2 to expose any nondeterminism which is the result // of the runtime scheduler. - out, err := exec.Command(testenv.GoToolPath(t), "tool", "compile", "-c", "2", "-o", tmp.Name(), filepath.Join("testdata", "reproducible", test)).CombinedOutput() + out, err := exec.Command(testenv.GoToolPath(t), "tool", "compile", "-p=p", "-c", "2", "-o", tmp.Name(), filepath.Join("testdata", "reproducible", test)).CombinedOutput() if err != nil { t.Fatalf("failed to compile: %v\n%s", err, out) } @@ -89,7 +89,7 @@ func TestIssue38068(t *testing.T) { s := &scenarios[i] s.libpath = filepath.Join(tmpdir, s.tag+".a") // Note: use of "-p" required in order for DWARF to be generated. - cmd := exec.Command(testenv.GoToolPath(t), "tool", "compile", "-trimpath", "-p=issue38068", "-buildid=", s.args, "-o", s.libpath, src) + cmd := exec.Command(testenv.GoToolPath(t), "tool", "compile", "-p=issue38068", "-buildid=", s.args, "-o", s.libpath, src) out, err := cmd.CombinedOutput() if err != nil { t.Fatalf("%v: %v:\n%s", cmd.Args, err, out) diff --git a/src/cmd/internal/archive/archive_test.go b/src/cmd/internal/archive/archive_test.go index c284a9cf0dc..9573495dec1 100644 --- a/src/cmd/internal/archive/archive_test.go +++ b/src/cmd/internal/archive/archive_test.go @@ -109,11 +109,11 @@ func buildGoobj() error { go1src := filepath.Join("testdata", "go1.go") go2src := filepath.Join("testdata", "go2.go") - out, err := exec.Command(gotool, "tool", "compile", "-o", go1obj, go1src).CombinedOutput() + out, err := exec.Command(gotool, "tool", "compile", "-p=p", "-o", go1obj, go1src).CombinedOutput() if err != nil { return fmt.Errorf("go tool compile -o %s %s: %v\n%s", go1obj, go1src, err, out) } - out, err = exec.Command(gotool, "tool", "compile", "-o", go2obj, go2src).CombinedOutput() + out, err = exec.Command(gotool, "tool", "compile", "-p=p", "-o", go2obj, go2src).CombinedOutput() if err != nil { return fmt.Errorf("go tool compile -o %s %s: %v\n%s", go2obj, go2src, err, out) } diff --git a/src/cmd/internal/obj/objfile_test.go b/src/cmd/internal/obj/objfile_test.go index 146627b62b9..f5a4016eec3 100644 --- a/src/cmd/internal/obj/objfile_test.go +++ b/src/cmd/internal/obj/objfile_test.go @@ -111,7 +111,7 @@ func TestSymbolTooLarge(t *testing.T) { // Issue 42054 t.Fatalf("failed to write source file: %v\n", err) } obj := filepath.Join(tmpdir, "p.o") - cmd := exec.Command(testenv.GoToolPath(t), "tool", "compile", "-o", obj, src) + cmd := exec.Command(testenv.GoToolPath(t), "tool", "compile", "-p=p", "-o", obj, src) out, err := cmd.CombinedOutput() if err == nil { t.Fatalf("did not fail\noutput: %s", out) diff --git a/src/cmd/link/link_test.go b/src/cmd/link/link_test.go index ad7658bb257..0492feaf0d6 100644 --- a/src/cmd/link/link_test.go +++ b/src/cmd/link/link_test.go @@ -55,7 +55,7 @@ func main() {} t.Fatalf("failed to write main.go: %v\n", err) } - cmd := exec.Command(testenv.GoToolPath(t), "tool", "compile", "main.go") + cmd := exec.Command(testenv.GoToolPath(t), "tool", "compile", "-p=main", "main.go") cmd.Dir = tmpdir out, err := cmd.CombinedOutput() if err != nil { @@ -100,7 +100,7 @@ func TestIssue28429(t *testing.T) { // Compile a main package. write("main.go", "package main; func main() {}") - runGo("tool", "compile", "-p", "main", "main.go") + runGo("tool", "compile", "-p=main", "main.go") runGo("tool", "pack", "c", "main.a", "main.o") // Add an extra section with a short, non-.o name. @@ -236,7 +236,7 @@ void foo() { // Compile, assemble and pack the Go and C code. runGo("tool", "asm", "-gensymabis", "-o", "symabis", "x.s") - runGo("tool", "compile", "-symabis", "symabis", "-p", "main", "-o", "x1.o", "main.go") + runGo("tool", "compile", "-symabis", "symabis", "-p=main", "-o", "x1.o", "main.go") runGo("tool", "asm", "-o", "x2.o", "x.s") run(cc, append(cflags, "-c", "-o", "x3.o", "x.c")...) runGo("tool", "pack", "c", "x.a", "x1.o", "x2.o", "x3.o") @@ -431,7 +431,7 @@ func TestIssue34788Android386TLSSequence(t *testing.T) { } obj := filepath.Join(tmpdir, "blah.o") - cmd := exec.Command(testenv.GoToolPath(t), "tool", "compile", "-o", obj, src) + cmd := exec.Command(testenv.GoToolPath(t), "tool", "compile", "-p=blah", "-o", obj, src) cmd.Env = append(os.Environ(), "GOARCH=386", "GOOS=android") if out, err := cmd.CombinedOutput(); err != nil { t.Fatalf("failed to compile blah.go: %v, output: %s\n", err, out) @@ -765,13 +765,13 @@ func TestIndexMismatch(t *testing.T) { exe := filepath.Join(tmpdir, "main.exe") // Build a program with main package importing package a. - cmd := exec.Command(testenv.GoToolPath(t), "tool", "compile", "-o", aObj, aSrc) + cmd := exec.Command(testenv.GoToolPath(t), "tool", "compile", "-p=a", "-o", aObj, aSrc) t.Log(cmd) out, err := cmd.CombinedOutput() if err != nil { t.Fatalf("compiling a.go failed: %v\n%s", err, out) } - cmd = exec.Command(testenv.GoToolPath(t), "tool", "compile", "-I", tmpdir, "-o", mObj, mSrc) + cmd = exec.Command(testenv.GoToolPath(t), "tool", "compile", "-p=main", "-I", tmpdir, "-o", mObj, mSrc) t.Log(cmd) out, err = cmd.CombinedOutput() if err != nil { @@ -786,7 +786,7 @@ func TestIndexMismatch(t *testing.T) { // Now, overwrite a.o with the object of b.go. This should // result in an index mismatch. - cmd = exec.Command(testenv.GoToolPath(t), "tool", "compile", "-o", aObj, bSrc) + cmd = exec.Command(testenv.GoToolPath(t), "tool", "compile", "-p=a", "-o", aObj, bSrc) t.Log(cmd) out, err = cmd.CombinedOutput() if err != nil { diff --git a/src/cmd/objdump/objdump_test.go b/src/cmd/objdump/objdump_test.go index ff431610308..313cc7a8093 100644 --- a/src/cmd/objdump/objdump_test.go +++ b/src/cmd/objdump/objdump_test.go @@ -267,7 +267,7 @@ func TestDisasmGoobj(t *testing.T) { mustHaveDisasm(t) hello := filepath.Join(tmp, "hello.o") - args := []string{"tool", "compile", "-o", hello} + args := []string{"tool", "compile", "-p=main", "-o", hello} args = append(args, "testdata/fmthello.go") out, err := exec.Command(testenv.GoToolPath(t), args...).CombinedOutput() if err != nil { diff --git a/src/cmd/pack/pack_test.go b/src/cmd/pack/pack_test.go index 81e78f53e28..6eec1f50ef6 100644 --- a/src/cmd/pack/pack_test.go +++ b/src/cmd/pack/pack_test.go @@ -179,7 +179,7 @@ func TestHello(t *testing.T) { goBin := testenv.GoToolPath(t) run(goBin, "build", "cmd/pack") // writes pack binary to dir - run(goBin, "tool", "compile", "hello.go") + run(goBin, "tool", "compile", "-p=main", "hello.go") run("./pack", "grc", "hello.a", "hello.o") run(goBin, "tool", "link", "-o", "a.out", "hello.a") out := run("./a.out") @@ -246,9 +246,9 @@ func TestLargeDefs(t *testing.T) { goBin := testenv.GoToolPath(t) run(goBin, "build", "cmd/pack") // writes pack binary to dir - run(goBin, "tool", "compile", "large.go") + run(goBin, "tool", "compile", "-p=large", "large.go") run("./pack", "grc", "large.a", "large.o") - run(goBin, "tool", "compile", "-I", ".", "main.go") + run(goBin, "tool", "compile", "-p=main", "-I", ".", "main.go") run(goBin, "tool", "link", "-L", ".", "-o", "a.out", "main.o") out := run("./a.out") if out != "ok\n" { @@ -281,9 +281,9 @@ func TestIssue21703(t *testing.T) { goBin := testenv.GoToolPath(t) run(goBin, "build", "cmd/pack") // writes pack binary to dir - run(goBin, "tool", "compile", "a.go") + run(goBin, "tool", "compile", "-p=a", "a.go") run("./pack", "c", "a.a", "a.o") - run(goBin, "tool", "compile", "-I", ".", "b.go") + run(goBin, "tool", "compile", "-p=b", "-I", ".", "b.go") } // Test the "c" command can "see through" the archive generated by the compiler. @@ -305,7 +305,7 @@ func TestCreateWithCompilerObj(t *testing.T) { goBin := testenv.GoToolPath(t) run(goBin, "build", "cmd/pack") // writes pack binary to dir - run(goBin, "tool", "compile", "-pack", "-o", "p.a", "p.go") + run(goBin, "tool", "compile", "-pack", "-p=p", "-o", "p.a", "p.go") run("./pack", "c", "packed.a", "p.a") fi, err := os.Stat(filepath.Join(dir, "p.a")) if err != nil { @@ -323,7 +323,7 @@ func TestCreateWithCompilerObj(t *testing.T) { } // Test -linkobj flag as well. - run(goBin, "tool", "compile", "-linkobj", "p2.a", "-o", "p.x", "p.go") + run(goBin, "tool", "compile", "-p=p", "-linkobj", "p2.a", "-o", "p.x", "p.go") run("./pack", "c", "packed2.a", "p2.a") fi, err = os.Stat(filepath.Join(dir, "p2.a")) if err != nil { @@ -369,7 +369,7 @@ func TestRWithNonexistentFile(t *testing.T) { goBin := testenv.GoToolPath(t) run(goBin, "build", "cmd/pack") // writes pack binary to dir - run(goBin, "tool", "compile", "-o", "p.o", "p.go") + run(goBin, "tool", "compile", "-p=p", "-o", "p.o", "p.go") run("./pack", "r", "p.a", "p.o") // should succeed } diff --git a/src/go/internal/gcimporter/gcimporter_test.go b/src/go/internal/gcimporter/gcimporter_test.go index c9c5946d9fb..51511ea620f 100644 --- a/src/go/internal/gcimporter/gcimporter_test.go +++ b/src/go/internal/gcimporter/gcimporter_test.go @@ -45,7 +45,7 @@ func compile(t *testing.T, dirname, filename, outdirname string) string { } basename := filepath.Base(filename) outname := filepath.Join(outdirname, basename[:len(basename)-2]+"o") - cmd := exec.Command(testenv.GoToolPath(t), "tool", "compile", "-o", outname, filename) + cmd := exec.Command(testenv.GoToolPath(t), "tool", "compile", "-p=p", "-o", outname, filename) cmd.Dir = dirname out, err := cmd.CombinedOutput() if err != nil { diff --git a/src/internal/abi/abi_test.go b/src/internal/abi/abi_test.go index 5a3b6b616d3..51d26f69aec 100644 --- a/src/internal/abi/abi_test.go +++ b/src/internal/abi/abi_test.go @@ -50,7 +50,7 @@ func TestFuncPCCompileError(t *testing.T) { } // compile go code. - cmd = exec.Command(testenv.GoToolPath(t), "tool", "compile", "-symabis", symabi, "-o", obj, goSrc) + cmd = exec.Command(testenv.GoToolPath(t), "tool", "compile", "-p=p", "-symabis", symabi, "-o", obj, goSrc) out, err = cmd.CombinedOutput() if err == nil { t.Fatalf("go tool compile did not fail") diff --git a/test/const7.go b/test/const7.go index e6256712781..6acd7fde3a0 100644 --- a/test/const7.go +++ b/test/const7.go @@ -37,7 +37,7 @@ func testProg(dir, name string, length int, ok bool) { log.Fatal(err) } - cmd := exec.Command("go", "tool", "compile", filename) + cmd := exec.Command("go", "tool", "compile", "-p=p", filename) cmd.Dir = dir output, err := cmd.CombinedOutput() diff --git a/test/fixedbugs/bug302.go b/test/fixedbugs/bug302.go index a2ab661277a..b3b958c3aa9 100644 --- a/test/fixedbugs/bug302.go +++ b/test/fixedbugs/bug302.go @@ -28,9 +28,9 @@ func main() { } defer os.RemoveAll(tmpDir) - run("go", "tool", "compile", filepath.Join(fb, "bug302.dir", "p.go")) + run("go", "tool", "compile", "-p=p", filepath.Join(fb, "bug302.dir", "p.go")) run("go", "tool", "pack", "grc", "pp.a", "p.o") - run("go", "tool", "compile", "-I", ".", filepath.Join(fb, "bug302.dir", "main.go")) + run("go", "tool", "compile", "-p=main", "-I", ".", filepath.Join(fb, "bug302.dir", "main.go")) } func run(cmd string, args ...string) { diff --git a/test/fixedbugs/bug369.go b/test/fixedbugs/bug369.go index 83f638d0463..8e50678c899 100644 --- a/test/fixedbugs/bug369.go +++ b/test/fixedbugs/bug369.go @@ -29,9 +29,9 @@ func main() { return filepath.Join(tmpDir, name) } - run("go", "tool", "compile", "-N", "-o", tmp("slow.o"), "pkg.go") - run("go", "tool", "compile", "-o", tmp("fast.o"), "pkg.go") - run("go", "tool", "compile", "-D", tmpDir, "-o", tmp("main.o"), "main.go") + run("go", "tool", "compile", "-p=pkg", "-N", "-o", tmp("slow.o"), "pkg.go") + run("go", "tool", "compile", "-p=pkg", "-o", tmp("fast.o"), "pkg.go") + run("go", "tool", "compile", "-p=main", "-D", tmpDir, "-o", tmp("main.o"), "main.go") run("go", "tool", "link", "-o", tmp("a.exe"), tmp("main.o")) run(tmp("a.exe")) } diff --git a/test/fixedbugs/issue11771.go b/test/fixedbugs/issue11771.go index c95dd6ba396..e5bed186bbd 100644 --- a/test/fixedbugs/issue11771.go +++ b/test/fixedbugs/issue11771.go @@ -52,7 +52,7 @@ func x() { log.Fatal(err) } - cmd := exec.Command("go", "tool", "compile", "x.go") + cmd := exec.Command("go", "tool", "compile", "-p=p", "x.go") cmd.Dir = dir output, err := cmd.CombinedOutput() if err == nil { diff --git a/test/fixedbugs/issue21317.go b/test/fixedbugs/issue21317.go index 32b660c1639..fe51ef1738a 100644 --- a/test/fixedbugs/issue21317.go +++ b/test/fixedbugs/issue21317.go @@ -38,7 +38,7 @@ func main() { defer os.RemoveAll(f.Name()) // compile and test output - cmd := exec.Command("go", "tool", "compile", f.Name()) + cmd := exec.Command("go", "tool", "compile", "-p=main", f.Name()) out, err := cmd.CombinedOutput() if err == nil { log.Fatalf("expected cmd/compile to fail") diff --git a/test/fixedbugs/issue22660.go b/test/fixedbugs/issue22660.go index 9ce9c4d732e..7f542c51534 100644 --- a/test/fixedbugs/issue22660.go +++ b/test/fixedbugs/issue22660.go @@ -35,7 +35,7 @@ func main() { log.Fatal(err) } - out, err := exec.Command("go", "tool", "compile", fmt.Sprintf("-trimpath=%s", path), f.Name()).CombinedOutput() + out, err := exec.Command("go", "tool", "compile", "-p=p", fmt.Sprintf("-trimpath=%s", path), f.Name()).CombinedOutput() if err == nil { log.Fatalf("expected compiling %s to fail", f.Name()) } diff --git a/test/fixedbugs/issue22662b.go b/test/fixedbugs/issue22662b.go index 8da17679be0..df4f28429c7 100644 --- a/test/fixedbugs/issue22662b.go +++ b/test/fixedbugs/issue22662b.go @@ -48,7 +48,7 @@ func main() { log.Fatal(err) } - out, err := exec.Command("go", "tool", "compile", f.Name()).CombinedOutput() + out, err := exec.Command("go", "tool", "compile", "-p=p", f.Name()).CombinedOutput() if err == nil { log.Fatalf("expected compiling\n---\n%s\n---\nto fail", test.src) } diff --git a/test/fixedbugs/issue26411.go b/test/fixedbugs/issue26411.go index 5f40bf25229..eb17960c476 100644 --- a/test/fixedbugs/issue26411.go +++ b/test/fixedbugs/issue26411.go @@ -75,7 +75,7 @@ bar : log.Printf("#%d: failed to create file %s", i, filename) continue } - output, _ := exec.Command("go", "tool", "compile", filename).CombinedOutput() + output, _ := exec.Command("go", "tool", "compile", "-p=p", filename).CombinedOutput() // remove each matching error from the output for _, err := range test.errors { diff --git a/test/fixedbugs/issue30908.go b/test/fixedbugs/issue30908.go index 60fbd11457f..27f070ececc 100644 --- a/test/fixedbugs/issue30908.go +++ b/test/fixedbugs/issue30908.go @@ -1,9 +1,10 @@ -// rundir -P -ldflags -strictdups=2 -w=0 +// rundir -ldflags -strictdups=2 -w=0 // Copyright 2019 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 !nacl && !js // +build !nacl,!js package ignored diff --git a/test/fixedbugs/issue9355.go b/test/fixedbugs/issue9355.go index 319a2a90df9..31376153ac7 100644 --- a/test/fixedbugs/issue9355.go +++ b/test/fixedbugs/issue9355.go @@ -27,7 +27,7 @@ func main() { } f.Close() - out := run("go", "tool", "compile", "-o", f.Name(), "-S", "a.go") + out := run("go", "tool", "compile", "-p=p", "-o", f.Name(), "-S", "a.go") os.Remove(f.Name()) // 6g/8g print the offset as dec, but 5g/9g print the offset as hex. diff --git a/test/interface/embed1.dir/embed0.go b/test/interface/embed1.dir/embed0.go index 728bec74e87..4aed391b634 100644 --- a/test/interface/embed1.dir/embed0.go +++ b/test/interface/embed1.dir/embed0.go @@ -7,10 +7,11 @@ package p type T int + func (t T) m() {} -type I interface { m() } -type J interface { I } +type I interface{ m() } +type J interface{ I } func main() { var i I diff --git a/test/linkmain_run.go b/test/linkmain_run.go index 077f7ee9175..6bc82dfafcd 100644 --- a/test/linkmain_run.go +++ b/test/linkmain_run.go @@ -62,14 +62,14 @@ func main() { } // helloworld.go is package main - run("go tool compile -o", tmp("linkmain.o"), "helloworld.go") - run("go tool compile -pack -o", tmp("linkmain.a"), "helloworld.go") + run("go tool compile -p=main -o", tmp("linkmain.o"), "helloworld.go") + run("go tool compile -p=main -pack -o", tmp("linkmain.a"), "helloworld.go") run("go tool link -o", tmp("linkmain.exe"), tmp("linkmain.o")) run("go tool link -o", tmp("linkmain.exe"), tmp("linkmain.a")) // linkmain.go is not - run("go tool compile -o", tmp("linkmain1.o"), "linkmain.go") - run("go tool compile -pack -o", tmp("linkmain1.a"), "linkmain.go") + run("go tool compile -p=notmain -o", tmp("linkmain1.o"), "linkmain.go") + run("go tool compile -p=notmain -pack -o", tmp("linkmain1.a"), "linkmain.go") runFail("go tool link -o", tmp("linkmain.exe"), tmp("linkmain1.o")) runFail("go tool link -o", tmp("linkmain.exe"), tmp("linkmain1.a")) cleanup() diff --git a/test/linkname2.go b/test/linkname2.go deleted file mode 100644 index 5eb250f9c4b..00000000000 --- a/test/linkname2.go +++ /dev/null @@ -1,21 +0,0 @@ -// errorcheck - -// Copyright 2020 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. - -// Tests that errors are reported for misuse of linkname. -package p - -import _ "unsafe" - -type t int - -var x, y int - -//go:linkname x ok - -// ERROR "//go:linkname requires linkname argument or -p compiler flag" - -//line linkname2.go:18 -//go:linkname y diff --git a/test/linkobj.go b/test/linkobj.go index 4c9bd24568b..023996aa309 100644 --- a/test/linkobj.go +++ b/test/linkobj.go @@ -37,28 +37,28 @@ func main() { writeFile("p1.go", ` package p1 - + func F() { println("hello from p1") } `) writeFile("p2.go", ` package p2 - + import "./p1" func F() { p1.F() println("hello from p2") } - + func main() {} `) writeFile("p3.go", ` package main import "./p2" - + func main() { p2.F() println("hello from main") @@ -76,9 +76,9 @@ func main() { } // inlining is disabled to make sure that the link objects contain needed code. - run("go", "tool", "compile", pkg, "-D", ".", "-I", ".", "-l", "-o", "p1."+o, "-linkobj", "p1.lo", "p1.go") - run("go", "tool", "compile", pkg, "-D", ".", "-I", ".", "-l", "-o", "p2."+o, "-linkobj", "p2.lo", "p2.go") - run("go", "tool", "compile", pkg, "-D", ".", "-I", ".", "-l", "-o", "p3."+o, "-linkobj", "p3.lo", "p3.go") + run("go", "tool", "compile", "-p=p1", pkg, "-D", ".", "-I", ".", "-l", "-o", "p1."+o, "-linkobj", "p1.lo", "p1.go") + run("go", "tool", "compile", "-p=p2", pkg, "-D", ".", "-I", ".", "-l", "-o", "p2."+o, "-linkobj", "p2.lo", "p2.go") + run("go", "tool", "compile", "-p=main", pkg, "-D", ".", "-I", ".", "-l", "-o", "p3."+o, "-linkobj", "p3.lo", "p3.go") cp("p1."+o, "p1.oo") cp("p2."+o, "p2.oo") diff --git a/test/run.go b/test/run.go index 869911a4265..e5dd0e443c8 100644 --- a/test/run.go +++ b/test/run.go @@ -184,7 +184,7 @@ func main() { resCount[status]++ dt := fmt.Sprintf("%.3fs", test.dt.Seconds()) if status == "FAIL" { - fmt.Printf("# go run run.go %s\n%s\nFAIL\t%s\t%s\n", + fmt.Printf("# go run run.go -- %s\n%s\nFAIL\t%s\t%s\n", path.Join(test.dir, test.gofile), errStr, test.goFileName(), dt) continue @@ -254,7 +254,7 @@ func goFiles(dir string) []string { type runCmd func(...string) ([]byte, error) func compileFile(runcmd runCmd, longname string, flags []string) (out []byte, err error) { - cmd := []string{goTool(), "tool", "compile", "-e"} + cmd := []string{goTool(), "tool", "compile", "-e", "-p=p"} cmd = append(cmd, flags...) if *linkshared { cmd = append(cmd, "-dynlink", "-installsuffix=dynlink") @@ -263,8 +263,11 @@ func compileFile(runcmd runCmd, longname string, flags []string) (out []byte, er return runcmd(cmd...) } -func compileInDir(runcmd runCmd, dir string, flags []string, localImports bool, names ...string) (out []byte, err error) { - cmd := []string{goTool(), "tool", "compile", "-e"} +func compileInDir(runcmd runCmd, dir string, flags []string, localImports bool, pkgname string, names ...string) (out []byte, err error) { + if pkgname != "main" { + pkgname = strings.TrimSuffix(names[0], ".go") + } + cmd := []string{goTool(), "tool", "compile", "-e", "-p=" + pkgname} if localImports { // Set relative path for local imports and import search path to current dir. cmd = append(cmd, "-D", ".", "-I", ".") @@ -415,28 +418,33 @@ func getPackageNameFromSource(fn string) (string, error) { return pkgname[1], nil } +type goDirPkg struct { + name string + files []string +} + // If singlefilepkgs is set, each file is considered a separate package // even if the package names are the same. -func goDirPackages(longdir string, singlefilepkgs bool) ([][]string, error) { +func goDirPackages(longdir string, singlefilepkgs bool) ([]*goDirPkg, error) { files, err := goDirFiles(longdir) if err != nil { return nil, err } - var pkgs [][]string - m := make(map[string]int) + var pkgs []*goDirPkg + m := make(map[string]*goDirPkg) for _, file := range files { name := file.Name() pkgname, err := getPackageNameFromSource(filepath.Join(longdir, name)) if err != nil { log.Fatal(err) } - i, ok := m[pkgname] + p, ok := m[pkgname] if singlefilepkgs || !ok { - i = len(pkgs) - pkgs = append(pkgs, nil) - m[pkgname] = i + p = &goDirPkg{name: pkgname} + pkgs = append(pkgs, p) + m[pkgname] = p } - pkgs[i] = append(pkgs[i], name) + p.files = append(p.files, name) } return pkgs, nil } @@ -607,7 +615,6 @@ func (t *test) run() { wantError := false wantAuto := false singlefilepkgs := false - setpkgpaths := false localImports := true f, err := splitQuoted(action) if err != nil { @@ -652,8 +659,6 @@ func (t *test) run() { wantError = false case "-s": singlefilepkgs = true - case "-P": - setpkgpaths = true case "-n": // Do not set relative path for local imports to current dir, // e.g. do not pass -D . -I . to the compiler. @@ -843,7 +848,7 @@ func (t *test) run() { // Fail if wantError is true and compilation was successful and vice versa. // Match errors produced by gc against errors in comments. // TODO(gri) remove need for -C (disable printing of columns in error messages) - cmdline := []string{goTool(), "tool", "compile", "-d=panic", "-C", "-e", "-o", "a.o"} + cmdline := []string{goTool(), "tool", "compile", "-p=p", "-d=panic", "-C", "-e", "-o", "a.o"} // No need to add -dynlink even if linkshared if we're just checking for errors... cmdline = append(cmdline, flags...) cmdline = append(cmdline, long) @@ -880,8 +885,8 @@ func (t *test) run() { t.err = err return } - for _, gofiles := range pkgs { - _, t.err = compileInDir(runcmd, longdir, flags, localImports, gofiles...) + for _, pkg := range pkgs { + _, t.err = compileInDir(runcmd, longdir, flags, localImports, pkg.name, pkg.files...) if t.err != nil { return } @@ -904,8 +909,8 @@ func (t *test) run() { // Preceding pkg must return an error from compileInDir. errPkg-- } - for i, gofiles := range pkgs { - out, err := compileInDir(runcmd, longdir, flags, localImports, gofiles...) + for i, pkg := range pkgs { + out, err := compileInDir(runcmd, longdir, flags, localImports, pkg.name, pkg.files...) if i == errPkg { if wantError && err == nil { t.err = fmt.Errorf("compilation succeeded unexpectedly\n%s", out) @@ -919,7 +924,7 @@ func (t *test) run() { return } var fullshort []string - for _, name := range gofiles { + for _, name := range pkg.files { fullshort = append(fullshort, filepath.Join(longdir, name), name) } t.err = t.errorCheck(string(out), wantAuto, fullshort...) @@ -953,18 +958,8 @@ func (t *test) run() { } } - for i, gofiles := range pkgs { - pflags := []string{} - pflags = append(pflags, flags...) - if setpkgpaths { - fp := filepath.Join(longdir, gofiles[0]) - pkgname, err := getPackageNameFromSource(fp) - if err != nil { - log.Fatal(err) - } - pflags = append(pflags, "-p", pkgname) - } - _, err := compileInDir(runcmd, longdir, pflags, localImports, gofiles...) + for i, pkg := range pkgs { + _, err := compileInDir(runcmd, longdir, flags, localImports, pkg.name, pkg.files...) // Allow this package compilation fail based on conditions below; // its errors were checked in previous case. if err != nil && !(wantError && action == "errorcheckandrundir" && i == len(pkgs)-2) { @@ -972,7 +967,7 @@ func (t *test) run() { return } if i == len(pkgs)-1 { - err = linkFile(runcmd, gofiles[0], ldflags) + err = linkFile(runcmd, pkg.files[0], ldflags) if err != nil { t.err = err return @@ -1071,7 +1066,7 @@ func (t *test) run() { } } var objs []string - cmd := []string{goTool(), "tool", "compile", "-e", "-D", ".", "-I", ".", "-o", "go.o"} + cmd := []string{goTool(), "tool", "compile", "-p=main", "-e", "-D", ".", "-I", ".", "-o", "go.o"} if len(asms) > 0 { cmd = append(cmd, "-asmhdr", "go_asm.h", "-symabis", "symabis") } @@ -1156,7 +1151,7 @@ func (t *test) run() { // Because we run lots of trivial test programs, // the time adds up. pkg := filepath.Join(t.tempDir, "pkg.a") - if _, err := runcmd(goTool(), "tool", "compile", "-o", pkg, t.goFileName()); err != nil { + if _, err := runcmd(goTool(), "tool", "compile", "-p=main", "-o", pkg, t.goFileName()); err != nil { t.err = err return } @@ -1238,7 +1233,7 @@ func (t *test) run() { t.err = fmt.Errorf("write tempfile:%s", err) return } - cmdline := []string{goTool(), "tool", "compile", "-d=panic", "-e", "-o", "a.o"} + cmdline := []string{goTool(), "tool", "compile", "-p=p", "-d=panic", "-e", "-o", "a.o"} cmdline = append(cmdline, flags...) cmdline = append(cmdline, tfile) out, err = runcmd(cmdline...) diff --git a/test/sinit_run.go b/test/sinit_run.go index dcaf3383312..e01502bd56d 100644 --- a/test/sinit_run.go +++ b/test/sinit_run.go @@ -25,7 +25,7 @@ func main() { } f.Close() - cmd := exec.Command("go", "tool", "compile", "-o", f.Name(), "-S", "sinit.go") + cmd := exec.Command("go", "tool", "compile", "-p=sinit", "-o", f.Name(), "-S", "sinit.go") out, err := cmd.CombinedOutput() os.Remove(f.Name()) if err != nil { From e189b5e06d4831025758c0b152838fa1a0375525 Mon Sep 17 00:00:00 2001 From: Robert Findley Date: Wed, 9 Mar 2022 11:35:10 -0500 Subject: [PATCH 058/276] go/types, types2: clarify documentation with respect to generic types Address several areas where documentation was inaccurate or unclear regarding generic types. Also prefer the use of the word 'generic' over 'parameterized', and add additional documentation for the use of SetConstraint. For #49593 Change-Id: Iccac60d1b3e2c45a57a3d03b3c10984293af57dd Reviewed-on: https://go-review.googlesource.com/c/go/+/391154 Trust: Robert Findley Run-TryBot: Robert Findley Reviewed-by: Robert Griesemer TryBot-Result: Gopher Robot --- src/cmd/compile/internal/types2/api.go | 6 +++--- src/cmd/compile/internal/types2/instantiate.go | 8 ++++---- src/cmd/compile/internal/types2/named.go | 12 ++++++++---- src/cmd/compile/internal/types2/typeparam.go | 9 ++++++--- src/go/types/api.go | 6 +++--- src/go/types/eval.go | 4 ++-- src/go/types/instantiate.go | 8 ++++---- src/go/types/named.go | 12 ++++++++---- src/go/types/typeparam.go | 9 ++++++--- 9 files changed, 44 insertions(+), 30 deletions(-) diff --git a/src/cmd/compile/internal/types2/api.go b/src/cmd/compile/internal/types2/api.go index 584f613a642..d864c96fb61 100644 --- a/src/cmd/compile/internal/types2/api.go +++ b/src/cmd/compile/internal/types2/api.go @@ -204,12 +204,12 @@ type Info struct { // qualified identifiers are collected in the Uses map. Types map[syntax.Expr]TypeAndValue - // Instances maps identifiers denoting parameterized types or functions to - // their type arguments and instantiated type. + // Instances maps identifiers denoting generic types or functions to their + // type arguments and instantiated type. // // For example, Instances will map the identifier for 'T' in the type // instantiation T[int, string] to the type arguments [int, string] and - // resulting instantiated *Named type. Given a parameterized function + // resulting instantiated *Named type. Given a generic function // func F[A any](A), Instances will map the identifier for 'F' in the call // expression F(int(1)) to the inferred type arguments [int], and resulting // instantiated *Signature. diff --git a/src/cmd/compile/internal/types2/instantiate.go b/src/cmd/compile/internal/types2/instantiate.go index c2653a38344..9eced489dcf 100644 --- a/src/cmd/compile/internal/types2/instantiate.go +++ b/src/cmd/compile/internal/types2/instantiate.go @@ -15,10 +15,10 @@ import ( // Instantiate instantiates the type orig with the given type arguments targs. // orig must be a *Named or a *Signature type. If there is no error, the -// resulting Type is a new, instantiated (not parameterized) type of the same -// kind (either a *Named or a *Signature). Methods attached to a *Named type -// are also instantiated, and associated with a new *Func that has the same -// position as the original method, but nil function scope. +// resulting Type is an instantiated type of the same kind (either a *Named or +// a *Signature). Methods attached to a *Named type are also instantiated, and +// associated with a new *Func that has the same position as the original +// method, but nil function scope. // // If ctxt is non-nil, it may be used to de-duplicate the instance against // previous instances with the same identity. As a special case, generic diff --git a/src/cmd/compile/internal/types2/named.go b/src/cmd/compile/internal/types2/named.go index 5c6a1cf5d80..daf8fdc9861 100644 --- a/src/cmd/compile/internal/types2/named.go +++ b/src/cmd/compile/internal/types2/named.go @@ -98,10 +98,10 @@ func (t *Named) cleanup() { } // Obj returns the type name for the declaration defining the named type t. For -// instantiated types, this is the type name of the base type. +// instantiated types, this is same as the type name of the origin type. func (t *Named) Obj() *TypeName { return t.orig.obj } // for non-instances this is the same as t.obj -// Origin returns the parameterized type from which the named type t is +// Origin returns the generic type from which the named type t is // instantiated. If t is not an instantiated type, the result is t. func (t *Named) Origin() *Named { return t.orig } @@ -109,7 +109,7 @@ func (t *Named) Origin() *Named { return t.orig } // between parameterized instantiated and non-instantiated types. // TypeParams returns the type parameters of the named type t, or nil. -// The result is non-nil for an (originally) parameterized type even if it is instantiated. +// The result is non-nil for an (originally) generic type even if it is instantiated. func (t *Named) TypeParams() *TypeParamList { return t.resolve(nil).tparams } // SetTypeParams sets the type parameters of the named type t. @@ -122,7 +122,11 @@ func (t *Named) SetTypeParams(tparams []*TypeParam) { // TypeArgs returns the type arguments used to instantiate the named type t. func (t *Named) TypeArgs() *TypeList { return t.targs } -// NumMethods returns the number of explicit methods whose receiver is named type t. +// NumMethods returns the number of explicit methods defined for t. +// +// For an ordinary or instantiated type t, the receiver base type of these +// methods will be the named type t. For an uninstantiated generic type t, each +// method receiver will be instantiated with its receiver type parameters. func (t *Named) NumMethods() int { return t.resolve(nil).methods.Len() } // Method returns the i'th method of named type t for 0 <= i < t.NumMethods(). diff --git a/src/cmd/compile/internal/types2/typeparam.go b/src/cmd/compile/internal/types2/typeparam.go index 9ed3369ff42..2e9a2adae67 100644 --- a/src/cmd/compile/internal/types2/typeparam.go +++ b/src/cmd/compile/internal/types2/typeparam.go @@ -31,7 +31,8 @@ func (t *TypeParam) Obj() *TypeName { return t.obj } // or Signature type by calling SetTypeParams. Setting a type parameter on more // than one type will result in a panic. // -// The constraint argument can be nil, and set later via SetConstraint. +// The constraint argument can be nil, and set later via SetConstraint. If the +// constraint is non-nil, it must be fully defined. func NewTypeParam(obj *TypeName, constraint Type) *TypeParam { return (*Checker)(nil).newTypeParam(obj, constraint) } @@ -71,8 +72,10 @@ func (t *TypeParam) Constraint() Type { // SetConstraint sets the type constraint for t. // -// SetConstraint should not be called concurrently, but once SetConstraint -// returns the receiver t is safe for concurrent use. +// It must be called by users of NewTypeParam after the bound's underlying is +// fully defined, and before using the type parameter in any way other than to +// form other types. Once SetConstraint returns the receiver, t is safe for +// concurrent use. func (t *TypeParam) SetConstraint(bound Type) { if bound == nil { panic("nil constraint") diff --git a/src/go/types/api.go b/src/go/types/api.go index 86a03eba31f..f2dcd104d85 100644 --- a/src/go/types/api.go +++ b/src/go/types/api.go @@ -199,12 +199,12 @@ type Info struct { // qualified identifiers are collected in the Uses map. Types map[ast.Expr]TypeAndValue - // Instances maps identifiers denoting parameterized types or functions to - // their type arguments and instantiated type. + // Instances maps identifiers denoting generic types or functions to their + // type arguments and instantiated type. // // For example, Instances will map the identifier for 'T' in the type // instantiation T[int, string] to the type arguments [int, string] and - // resulting instantiated *Named type. Given a parameterized function + // resulting instantiated *Named type. Given a generic function // func F[A any](A), Instances will map the identifier for 'F' in the call // expression F(int(1)) to the inferred type arguments [int], and resulting // instantiated *Signature. diff --git a/src/go/types/eval.go b/src/go/types/eval.go index c8bb005eb6d..5700cbf79c7 100644 --- a/src/go/types/eval.go +++ b/src/go/types/eval.go @@ -37,8 +37,8 @@ func Eval(fset *token.FileSet, pkg *Package, pos token.Pos, expr string) (_ Type // CheckExpr type checks the expression expr as if it had appeared at position // pos of package pkg. Type information about the expression is recorded in -// info. The expression may be an uninstantiated parameterized function or -// type. +// info. The expression may be an identifier denoting an uninstantiated generic +// function or type. // // If pkg == nil, the Universe scope is used and the provided // position pos is ignored. If pkg != nil, and pos is invalid, diff --git a/src/go/types/instantiate.go b/src/go/types/instantiate.go index 4b8e3d46612..a4817466573 100644 --- a/src/go/types/instantiate.go +++ b/src/go/types/instantiate.go @@ -15,10 +15,10 @@ import ( // Instantiate instantiates the type orig with the given type arguments targs. // orig must be a *Named or a *Signature type. If there is no error, the -// resulting Type is a new, instantiated (not parameterized) type of the same -// kind (either a *Named or a *Signature). Methods attached to a *Named type -// are also instantiated, and associated with a new *Func that has the same -// position as the original method, but nil function scope. +// resulting Type is an instantiated type of the same kind (either a *Named or +// a *Signature). Methods attached to a *Named type are also instantiated, and +// associated with a new *Func that has the same position as the original +// method, but nil function scope. // // If ctxt is non-nil, it may be used to de-duplicate the instance against // previous instances with the same identity. As a special case, generic diff --git a/src/go/types/named.go b/src/go/types/named.go index 5b84e0653b9..876f7e8551f 100644 --- a/src/go/types/named.go +++ b/src/go/types/named.go @@ -98,12 +98,12 @@ func (t *Named) cleanup() { } // Obj returns the type name for the declaration defining the named type t. For -// instantiated types, this is the type name of the base type. +// instantiated types, this is same as the type name of the origin type. func (t *Named) Obj() *TypeName { return t.orig.obj // for non-instances this is the same as t.obj } -// Origin returns the parameterized type from which the named type t is +// Origin returns the generic type from which the named type t is // instantiated. If t is not an instantiated type, the result is t. func (t *Named) Origin() *Named { return t.orig } @@ -111,7 +111,7 @@ func (t *Named) Origin() *Named { return t.orig } // between parameterized instantiated and non-instantiated types. // TypeParams returns the type parameters of the named type t, or nil. -// The result is non-nil for an (originally) parameterized type even if it is instantiated. +// The result is non-nil for an (originally) generic type even if it is instantiated. func (t *Named) TypeParams() *TypeParamList { return t.resolve(nil).tparams } // SetTypeParams sets the type parameters of the named type t. @@ -124,7 +124,11 @@ func (t *Named) SetTypeParams(tparams []*TypeParam) { // TypeArgs returns the type arguments used to instantiate the named type t. func (t *Named) TypeArgs() *TypeList { return t.targs } -// NumMethods returns the number of explicit methods whose receiver is named type t. +// NumMethods returns the number of explicit methods defined for t. +// +// For an ordinary or instantiated type t, the receiver base type of these +// methods will be the named type t. For an uninstantiated generic type t, each +// method receiver will be instantiated with its receiver type parameters. func (t *Named) NumMethods() int { return t.resolve(nil).methods.Len() } // Method returns the i'th method of named type t for 0 <= i < t.NumMethods(). diff --git a/src/go/types/typeparam.go b/src/go/types/typeparam.go index 778c687d430..40d96ac9470 100644 --- a/src/go/types/typeparam.go +++ b/src/go/types/typeparam.go @@ -30,7 +30,8 @@ type TypeParam struct { // or Signature type by calling SetTypeParams. Setting a type parameter on more // than one type will result in a panic. // -// The constraint argument can be nil, and set later via SetConstraint. +// The constraint argument can be nil, and set later via SetConstraint. If the +// constraint is non-nil, it must be fully defined. func NewTypeParam(obj *TypeName, constraint Type) *TypeParam { return (*Checker)(nil).newTypeParam(obj, constraint) } @@ -73,8 +74,10 @@ func (t *TypeParam) Constraint() Type { // SetConstraint sets the type constraint for t. // -// SetConstraint should not be called concurrently, but once SetConstraint -// returns the receiver t is safe for concurrent use. +// It must be called by users of NewTypeParam after the bound's underlying is +// fully defined, and before using the type parameter in any way other than to +// form other types. Once SetConstraint returns the receiver, t is safe for +// concurrent use. func (t *TypeParam) SetConstraint(bound Type) { if bound == nil { panic("nil constraint") From 3a5e3d8173df547d8360a609097fc80f01182db1 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Wed, 9 Mar 2022 14:27:25 -0800 Subject: [PATCH 059/276] go/types, types2: pointer base types cannot be type constraints Pointer types may appear in expressions *P and we don't know if we have an indirection (P is a pointer value) or a pointer type (P is a type) until we type-check P. Don't forget to check that a type P must be an ordinary (not a constraint) type in this special case. Fixes #51578. Change-Id: If782cc6dd2a602a498574c78c99e40c3b72274a5 Reviewed-on: https://go-review.googlesource.com/c/go/+/391275 Trust: Robert Griesemer Run-TryBot: Robert Griesemer Reviewed-by: Robert Findley TryBot-Result: Gopher Robot --- src/cmd/compile/internal/types2/expr.go | 1 + .../types2/testdata/fixedbugs/issue51578.go2 | 17 +++++++++++++++++ src/cmd/compile/internal/types2/typexpr.go | 10 +++++++--- src/go/types/expr.go | 1 + src/go/types/testdata/fixedbugs/issue51578.go2 | 17 +++++++++++++++++ src/go/types/typexpr.go | 10 +++++++--- 6 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 src/cmd/compile/internal/types2/testdata/fixedbugs/issue51578.go2 create mode 100644 src/go/types/testdata/fixedbugs/issue51578.go2 diff --git a/src/cmd/compile/internal/types2/expr.go b/src/cmd/compile/internal/types2/expr.go index 861a83472da..05cf1d0b33d 100644 --- a/src/cmd/compile/internal/types2/expr.go +++ b/src/cmd/compile/internal/types2/expr.go @@ -1642,6 +1642,7 @@ func (check *Checker) exprInternal(x *operand, e syntax.Expr, hint Type) exprKin case invalid: goto Error case typexpr: + check.validVarType(e.X, x.typ) x.typ = &Pointer{base: x.typ} default: var base Type diff --git a/src/cmd/compile/internal/types2/testdata/fixedbugs/issue51578.go2 b/src/cmd/compile/internal/types2/testdata/fixedbugs/issue51578.go2 new file mode 100644 index 00000000000..5c204bae209 --- /dev/null +++ b/src/cmd/compile/internal/types2/testdata/fixedbugs/issue51578.go2 @@ -0,0 +1,17 @@ +// Copyright 2022 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 p + +var _ = (*interface /* ERROR interface contains type constraints */ {int})(nil) + +// abbreviated test case from issue + +type TypeSet interface{ int | string } + +func _() { + f((*TypeSet /* ERROR interface contains type constraints */)(nil)) +} + +func f(any) {} \ No newline at end of file diff --git a/src/cmd/compile/internal/types2/typexpr.go b/src/cmd/compile/internal/types2/typexpr.go index a9ce55bd1e5..7e30562e972 100644 --- a/src/cmd/compile/internal/types2/typexpr.go +++ b/src/cmd/compile/internal/types2/typexpr.go @@ -147,10 +147,16 @@ func (check *Checker) typ(e syntax.Expr) Type { // constraint interface. func (check *Checker) varType(e syntax.Expr) Type { typ := check.definedType(e, nil) + check.validVarType(e, typ) + return typ +} +// validVarType reports an error if typ is a constraint interface. +// The expression e is used for error reporting, if any. +func (check *Checker) validVarType(e syntax.Expr, typ Type) { // If we have a type parameter there's nothing to do. if isTypeParam(typ) { - return typ + return } // We don't want to call under() or complete interfaces while we are in @@ -169,8 +175,6 @@ func (check *Checker) varType(e syntax.Expr) Type { } } }) - - return typ } // definedType is like typ but also accepts a type name def. diff --git a/src/go/types/expr.go b/src/go/types/expr.go index 68b0789d650..e24bd60dc39 100644 --- a/src/go/types/expr.go +++ b/src/go/types/expr.go @@ -1588,6 +1588,7 @@ func (check *Checker) exprInternal(x *operand, e ast.Expr, hint Type) exprKind { case invalid: goto Error case typexpr: + check.validVarType(e.X, x.typ) x.typ = &Pointer{base: x.typ} default: var base Type diff --git a/src/go/types/testdata/fixedbugs/issue51578.go2 b/src/go/types/testdata/fixedbugs/issue51578.go2 new file mode 100644 index 00000000000..5c204bae209 --- /dev/null +++ b/src/go/types/testdata/fixedbugs/issue51578.go2 @@ -0,0 +1,17 @@ +// Copyright 2022 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 p + +var _ = (*interface /* ERROR interface contains type constraints */ {int})(nil) + +// abbreviated test case from issue + +type TypeSet interface{ int | string } + +func _() { + f((*TypeSet /* ERROR interface contains type constraints */)(nil)) +} + +func f(any) {} \ No newline at end of file diff --git a/src/go/types/typexpr.go b/src/go/types/typexpr.go index 14735c37091..5bb2d8f8112 100644 --- a/src/go/types/typexpr.go +++ b/src/go/types/typexpr.go @@ -144,10 +144,16 @@ func (check *Checker) typ(e ast.Expr) Type { // constraint interface. func (check *Checker) varType(e ast.Expr) Type { typ := check.definedType(e, nil) + check.validVarType(e, typ) + return typ +} +// validVarType reports an error if typ is a constraint interface. +// The expression e is used for error reporting, if any. +func (check *Checker) validVarType(e ast.Expr, typ Type) { // If we have a type parameter there's nothing to do. if isTypeParam(typ) { - return typ + return } // We don't want to call under() or complete interfaces while we are in @@ -165,8 +171,6 @@ func (check *Checker) varType(e ast.Expr) Type { } } }) - - return typ } // definedType is like typ but also accepts a type name def. From 9faef5a6540f56af0129610db8a55b443229075f Mon Sep 17 00:00:00 2001 From: Meng Zhuo Date: Fri, 22 Oct 2021 14:36:06 +0800 Subject: [PATCH 060/276] cmd/compile,bytealg: change context register on riscv64 The register ABI will use X8-X23 (CL 356519), this CL changes context register from X20(S4) to X26(S10) to meet the prerequisite. Update #40724 Change-Id: I93d51d22fe7b3ea5ceffe96dff93e3af60fbe7f6 Reviewed-on: https://go-review.googlesource.com/c/go/+/357974 Trust: mzh Run-TryBot: mzh Reviewed-by: Joel Sing Reviewed-by: Cherry Mui TryBot-Result: Gopher Robot --- src/cmd/compile/internal/riscv64/ssa.go | 2 +- src/cmd/compile/internal/ssa/gen/RISCV64Ops.go | 4 ++-- src/cmd/compile/internal/ssa/opGen.go | 4 ++-- src/cmd/internal/obj/riscv/cpu.go | 6 +++--- src/internal/bytealg/equal_riscv64.s | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/cmd/compile/internal/riscv64/ssa.go b/src/cmd/compile/internal/riscv64/ssa.go index 1359b6a0c38..fc52e9427d6 100644 --- a/src/cmd/compile/internal/riscv64/ssa.go +++ b/src/cmd/compile/internal/riscv64/ssa.go @@ -648,7 +648,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) { } case ssa.OpRISCV64LoweredGetClosurePtr: - // Closure pointer is S4 (riscv.REG_CTXT). + // Closure pointer is S10 (riscv.REG_CTXT). ssagen.CheckLoweredGetClosurePtr(v) case ssa.OpRISCV64LoweredGetCallerSP: diff --git a/src/cmd/compile/internal/ssa/gen/RISCV64Ops.go b/src/cmd/compile/internal/ssa/gen/RISCV64Ops.go index 076919773b4..09a8bb38c9a 100644 --- a/src/cmd/compile/internal/ssa/gen/RISCV64Ops.go +++ b/src/cmd/compile/internal/ssa/gen/RISCV64Ops.go @@ -26,7 +26,7 @@ import ( const ( riscv64REG_G = 27 - riscv64REG_CTXT = 20 + riscv64REG_CTXT = 26 riscv64REG_LR = 1 riscv64REG_SP = 2 riscv64REG_GP = 3 @@ -115,7 +115,7 @@ func init() { panic("Too many RISCV64 registers") } - regCtxt := regNamed["X20"] + regCtxt := regNamed["X26"] callerSave := gpMask | fpMask | regNamed["g"] var ( diff --git a/src/cmd/compile/internal/ssa/opGen.go b/src/cmd/compile/internal/ssa/opGen.go index 81fe5d4c23c..6f0eb450148 100644 --- a/src/cmd/compile/internal/ssa/opGen.go +++ b/src/cmd/compile/internal/ssa/opGen.go @@ -28898,7 +28898,7 @@ var opcodeTable = [...]opInfo{ call: true, reg: regInfo{ inputs: []inputInfo{ - {1, 524288}, // X20 + {1, 33554432}, // X26 {0, 1006632946}, // SP X5 X6 X7 X8 X9 X10 X11 X12 X13 X14 X15 X16 X17 X18 X19 X20 X21 X22 X23 X24 X25 X26 X28 X29 X30 }, clobbers: 9223372035781033968, // X5 X6 X7 X8 X9 X10 X11 X12 X13 X14 X15 X16 X17 X18 X19 X20 X21 X22 X23 X24 X25 X26 g X28 X29 X30 F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 F13 F14 F15 F16 F17 F18 F19 F20 F21 F22 F23 F24 F25 F26 F27 F28 F29 F30 F31 @@ -29189,7 +29189,7 @@ var opcodeTable = [...]opInfo{ argLen: 0, reg: regInfo{ outputs: []outputInfo{ - {0, 524288}, // X20 + {0, 33554432}, // X26 }, }, }, diff --git a/src/cmd/internal/obj/riscv/cpu.go b/src/cmd/internal/obj/riscv/cpu.go index d9434e74158..8c2daf6e5bd 100644 --- a/src/cmd/internal/obj/riscv/cpu.go +++ b/src/cmd/internal/obj/riscv/cpu.go @@ -125,13 +125,13 @@ const ( REG_A7 = REG_X17 REG_S2 = REG_X18 REG_S3 = REG_X19 - REG_S4 = REG_X20 // aka REG_CTXT + REG_S4 = REG_X20 REG_S5 = REG_X21 REG_S6 = REG_X22 REG_S7 = REG_X23 REG_S8 = REG_X24 REG_S9 = REG_X25 - REG_S10 = REG_X26 + REG_S10 = REG_X26 // aka REG_CTXT REG_S11 = REG_X27 // aka REG_G REG_T3 = REG_X28 REG_T4 = REG_X29 @@ -139,8 +139,8 @@ const ( REG_T6 = REG_X31 // aka REG_TMP // Go runtime register names. + REG_CTXT = REG_S10 // Context for closures. REG_G = REG_S11 // G pointer. - REG_CTXT = REG_S4 // Context for closures. REG_LR = REG_RA // Link register. REG_TMP = REG_T6 // Reserved for assembler use. diff --git a/src/internal/bytealg/equal_riscv64.s b/src/internal/bytealg/equal_riscv64.s index 959a996f81e..5dd13beb555 100644 --- a/src/internal/bytealg/equal_riscv64.s +++ b/src/internal/bytealg/equal_riscv64.s @@ -5,7 +5,7 @@ #include "go_asm.h" #include "textflag.h" -#define CTXT S4 +#define CTXT S10 // func memequal(a, b unsafe.Pointer, size uintptr) bool TEXT runtime·memequal(SB),NOSPLIT|NOFRAME,$0-25 From 604140d93111f89911e17cb147dcf6a02d2700d0 Mon Sep 17 00:00:00 2001 From: Carl Johnson Date: Fri, 4 Mar 2022 14:49:52 +0000 Subject: [PATCH 061/276] net/url: add JoinPath, URL.JoinPath Builds on CL 332209. Fixes #47005 Change-Id: I82708dede05d79a196ca63f5a4e7cb5ac9a041ea GitHub-Last-Rev: 51b735066eef74f5e67c3e8899c58f44c0383c61 GitHub-Pull-Request: golang/go#50383 Reviewed-on: https://go-review.googlesource.com/c/go/+/374654 Reviewed-by: Russ Cox Auto-Submit: Russ Cox Trust: Ian Lance Taylor Reviewed-by: Damien Neil Run-TryBot: Ian Lance Taylor TryBot-Result: Gopher Robot --- api/next.txt | 2 ++ src/net/url/url.go | 23 +++++++++++++++++ src/net/url/url_test.go | 56 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+) diff --git a/api/next.txt b/api/next.txt index 23fd98a9bac..148cbffbfeb 100644 --- a/api/next.txt +++ b/api/next.txt @@ -3,3 +3,5 @@ pkg encoding/binary, type AppendByteOrder interface, AppendUint16([]uint8, uint1 pkg encoding/binary, type AppendByteOrder interface, AppendUint32([]uint8, uint32) []uint8 pkg encoding/binary, type AppendByteOrder interface, AppendUint64([]uint8, uint64) []uint8 pkg encoding/binary, type AppendByteOrder interface, String() string +pkg net/url, func JoinPath(string, ...string) (string, error) +pkg net/url, method (*URL) JoinPath(...string) *URL diff --git a/src/net/url/url.go b/src/net/url/url.go index f31aa08b592..1571bf728ba 100644 --- a/src/net/url/url.go +++ b/src/net/url/url.go @@ -13,6 +13,7 @@ package url import ( "errors" "fmt" + "path" "sort" "strconv" "strings" @@ -1176,6 +1177,17 @@ func (u *URL) UnmarshalBinary(text []byte) error { return nil } +// JoinPath returns a new URL with the provided path elements joined to +// any existing path and the resulting path cleaned of any ./ or ../ elements. +func (u *URL) JoinPath(elem ...string) *URL { + url := *u + if len(elem) > 0 { + elem = append([]string{u.Path}, elem...) + url.setPath(path.Join(elem...)) + } + return &url +} + // validUserinfo reports whether s is a valid userinfo string per RFC 3986 // Section 3.2.1: // userinfo = *( unreserved / pct-encoded / sub-delims / ":" ) @@ -1216,3 +1228,14 @@ func stringContainsCTLByte(s string) bool { } return false } + +// JoinPath returns a URL string with the provided path elements joined to +// the existing path of base and the resulting path cleaned of any ./ or ../ elements. +func JoinPath(base string, elem ...string) (result string, err error) { + url, err := Parse(base) + if err != nil { + return + } + result = url.JoinPath(elem...).String() + return +} diff --git a/src/net/url/url_test.go b/src/net/url/url_test.go index 664757b832a..84dba45c3c1 100644 --- a/src/net/url/url_test.go +++ b/src/net/url/url_test.go @@ -2062,3 +2062,59 @@ func BenchmarkPathUnescape(b *testing.B) { }) } } + +func TestJoinPath(t *testing.T) { + tests := []struct { + base string + elem []string + out string + }{ + { + base: "https://go.googlesource.com", + elem: []string{"go"}, + out: "https://go.googlesource.com/go", + }, + { + base: "https://go.googlesource.com/a/b/c", + elem: []string{"../../../go"}, + out: "https://go.googlesource.com/go", + }, + { + base: "https://go.googlesource.com/", + elem: []string{"./go"}, + out: "https://go.googlesource.com/go", + }, + { + base: "https://go.googlesource.com//", + elem: []string{"/go"}, + out: "https://go.googlesource.com/go", + }, + { + base: "https://go.googlesource.com//", + elem: []string{"/go", "a", "b", "c"}, + out: "https://go.googlesource.com/go/a/b/c", + }, + { + base: "http://[fe80::1%en0]:8080/", + elem: []string{"/go"}, + }, + } + for _, tt := range tests { + wantErr := "nil" + if tt.out == "" { + wantErr = "non-nil error" + } + if out, err := JoinPath(tt.base, tt.elem...); out != tt.out || (err == nil) != (tt.out != "") { + t.Errorf("JoinPath(%q, %q) = %q, %v, want %q, %v", tt.base, tt.elem, out, err, tt.out, wantErr) + } + var out string + u, err := Parse(tt.base) + if err == nil { + u = u.JoinPath(tt.elem...) + out = u.String() + } + if out != tt.out || (err == nil) != (tt.out != "") { + t.Errorf("Parse(%q).JoinPath(%q) = %q, %v, want %q, %v", tt.base, tt.elem, out, err, tt.out, wantErr) + } + } +} From 46f352de2dc80657664431ebb04f89a2fad579c5 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Mon, 7 Mar 2022 21:49:26 -0800 Subject: [PATCH 062/276] spec: remove notion of specific types Specific types were introduced to explain rules for operands of type parameter type. Specific types are really an implementation mechanism to represent (possibly infinite) type sets in the machine; they are not needed in the specification. A specific type is either standing for a single named or unnamed type, or it is the underlying (unnamed) type of an infinite set of types. Each rule that applies to a type T of the set of specific types must also apply to all types T' in the type set for which T is a representative of. Thus, in the spec we can simply refer to the type set directly, infinite or not. Rather then excluding operands with empty type sets in each instance, leave unspecified what happens when such an operand is used. Instead give an implementation some leeway with an implementation restriction. (The implementation restriction also needs to be formulated for types, such as in conversions, which technically are not "operands". Left for another CL.) Minor: Remove the two uses of the word "concrete" to refer to non- interface types; instead just say "non-interface type" for clarity. Change-Id: I67ac89a640c995369c9d421a03820a0c0435835a Reviewed-on: https://go-review.googlesource.com/c/go/+/390694 Trust: Robert Griesemer Reviewed-by: Ian Lance Taylor --- doc/go_spec.html | 138 +++++++++++++---------------------------------- 1 file changed, 38 insertions(+), 100 deletions(-) diff --git a/doc/go_spec.html b/doc/go_spec.html index 6278b8252de..000b0c5e670 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,6 +1,6 @@ @@ -761,7 +761,7 @@

    Variables

    new call or composite literal, or the type of an element of a structured variable. Variables of interface type also have a distinct dynamic type, -which is the concrete type of the value assigned to the variable at run time +which is the (non-interface) type of the value assigned to the variable at run time (unless the value is the predeclared identifier nil, which has no type). The dynamic type may vary during execution but values stored in interface @@ -1799,70 +1799,6 @@

    Core types

    interface{ <-chan int | chan<- int } // directional channels have different directions
    -

    Specific types

    - -

    -[The definition of specific types is not quite correct yet.] -

    - -

    -An interface specification that contains type elements -defines a (possibly empty) set of specific types. -Loosely speaking, these are the types T that appear in the -interface definition in terms of the form T, ~T, -or in unions of such terms. -

    - -

    -More precisely, for a given interface, the set of specific types corresponds to -the set 𝑅 of representative types of the interface, if 𝑅 is non-empty and finite. -Otherwise, if 𝑅 is empty or infinite, the interface has no specific types. -

    - -

    -For a given interface, type element or type term, the set 𝑅 of representative types is defined as follows: -

    - -
      -
    • For an interface with no type elements, 𝑅 is the (infinite) set of all types. -
    • - -
    • For an interface with type elements, - 𝑅 is the intersection of the representative types of its type elements. -
    • - -
    • For a non-interface type term T or a term of the form ~T, - 𝑅 is the set consisting of the type T. -
    • - -
    • For a union of terms - t1|t2|…|tn, - 𝑅 is the union of the representative types of the terms. -
    • -
    - -

    -An interface may have specific types even if its type set -is empty. -

    - -

    -Examples of interfaces with their specific types: -

    - -
    -interface{}                    // no specific types
    -interface{ int }               // int
    -interface{ ~string }           // string
    -interface{ int|~string }       // int, string
    -interface{ Celsius|Kelvin }    // Celsius, Kelvin
    -interface{ float64|any }       // no specific types (union is all types)
    -interface{ int; m() }          // int (but type set is empty because int has no method m)
    -interface{ ~int; m() }         // int (but type set is infinite because many integer types have a method m)
    -interface{ int; any }          // int
    -interface{ int; string }       // no specific types (intersection is empty)
    -
    -

    Type identity

    @@ -2002,25 +1938,24 @@

    Assignability

-Additionally, if x's type V or T are type parameters -with specific types, x +Additionally, if x's type V or T are type parameters, x is assignable to a variable of type T if one of the following conditions applies:

  • x is the predeclared identifier nil, T is -a type parameter, and x is assignable to each specific type of -T. +a type parameter, and x is assignable to each type in +T's type set.
  • V is not a named type, T is -a type parameter, and x is assignable to each specific type of -T. +a type parameter, and x is assignable to each type in +T's type set.
  • V is a type parameter and T is not a named type, -and values of each specific type of V are assignable +and values of each type in V's type set are assignable to T.
@@ -2055,9 +1990,9 @@

Representability

-If T is a type parameter with specific types, +If T is a type parameter, x is representable by a value of type T if x is representable -by a value of each specific type of T. +by a value of each type in T's type set.

@@ -2705,7 +2640,7 @@ 

Type constraints

The predeclared interface type comparable -denotes the set of all concrete (non-interface) types that are +denotes the set of all non-interface types that are comparable. Specifically, a type T implements comparable if:

@@ -3037,6 +2972,14 @@

Operands

operand only on the left-hand side of an assignment.

+

+Implementation restriction: A compiler need not report an error if an operand's +type is a type parameter with an empty +type set. Functions with such type parameters +cannot be instantiated; any attempt will lead +to an error at the instantiation site. +

+

Qualified identifiers

@@ -3819,20 +3762,19 @@

Index expressions

For a of type parameter type P:

    -
  • P must have specific types.
  • The index expression a[x] must be valid for values - of all specific types of P.
  • -
  • The element types of all specific types of P must be identical. + of all types in P's type set.
  • +
  • The element types of all types in P's type set must be identical. In this context, the element type of a string type is byte.
  • -
  • If there is a map type among the specific types of P, - all specific types must be map types, and the respective key types +
  • If there is a map type in the type set of P, + all types in that type set must be map types, and the respective key types must be all identical.
  • a[x] is the array, slice, or string element at index x, or the map element with key x of the type argument that P is instantiated with, and the type of a[x] is the type of the (identical) element types.
  • -
  • a[x] may not be assigned to if the specific types of P - include string types. +
  • a[x] may not be assigned to if P's type set + includes string types.

@@ -4728,6 +4670,10 @@

Operators

to the type of the other operand.

+

+[The rules for shifts need adjustments for type parameters. Issue #51182.] +

+

The right operand in a shift expression must have integer type or be an untyped constant representable by a @@ -4832,9 +4778,8 @@

Arithmetic operators

-Excluding shifts, if the operand type is a type parameter, -it must have specific types, and the operator must -apply to each specific type. +If the operand type is a type parameter, +the operator must apply to each type in that type set. The operands are represented as values of the type argument that the type parameter is instantiated with, and the operation is computed with the precision of that type argument. For example, given the function: @@ -4857,11 +4802,6 @@

Arithmetic operators

respectively, depending on the type argument for F.

-

-For shifts, the core type of both operands must be -an integer. -

-

Integer operators

@@ -5374,23 +5314,23 @@

Conversions

Additionally, if T or x's type V are type -parameters with specific types, x +parameters, x can also be converted to type T if one of the following conditions applies:

  • Both V and T are type parameters and a value of each -specific type of V can be converted to each specific type -of T. +type in V's type set can be converted to each type in T's +type set.
  • Only V is a type parameter and a value of each -specific type of V can be converted to T. +type in V's type set can be converted to T.
  • Only T is a type parameter and x can be converted to each -specific type of T. +type in T's type set.
@@ -7085,9 +7025,8 @@

Length and capacity

If the argument type is a type parameter P, -P must have specific types, and the call len(e) (or cap(e) respectively) must be valid for -each specific type of P. +each type in P's type set. The result is the length (or capacity, respectively) of the argument whose type corresponds to the type argument with which P was instantiated. @@ -7309,8 +7248,7 @@

Deletion of map elements

If the type of m is a type parameter, -it must have specific types, all specific types -must be maps, and they must all have identical key types. +all types in that type set must be maps, and they must all have identical key types.

From 6fb07317e5e7997a1e44ccb6984229c77dc186a3 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Tue, 8 Mar 2022 13:11:04 -0800 Subject: [PATCH 063/276] spec: more adjustments/corrections - Change section title from "Type parameters lists" to "Type parameter declarations" as the enclosing section is about declarations. - Correct section on parsing ambiguity in type parameter lists. - Rephrase paragraphs on type parameters for method receivers and adjust examples. - Remove duplicate prose in section on function argument type inference. - Clarified "after substitution" column in Instantiations section. Change-Id: Id76be9804ad96a3f1221e5c4942552dde015dfcb Reviewed-on: https://go-review.googlesource.com/c/go/+/390994 Trust: Robert Griesemer Reviewed-by: Ian Lance Taylor --- doc/go_spec.html | 92 +++++++++++++++++++++++++----------------------- 1 file changed, 47 insertions(+), 45 deletions(-) diff --git a/doc/go_spec.html b/doc/go_spec.html index 000b0c5e670..cfbb17e3bba 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -807,7 +807,7 @@

Types

The language predeclares certain type names. Others are introduced with type declarations -or type parameter lists. +or type parameter lists. Composite types—array, struct, pointer, function, interface, slice, map, and channel types—may be constructed using type literals. @@ -1459,7 +1459,7 @@

General interfaces

-In a union, a term cannot be a type parameter, and the type sets of all +In a union, a term cannot be a type parameter, and the type sets of all non-interface terms must be pairwise disjoint (the pairwise intersection of the type sets must be empty). Given a type parameter P:

@@ -1769,7 +1769,7 @@

Core types

By definition, a core type is never a defined type, -type parameter, or +type parameter, or interface type.

@@ -1965,7 +1965,7 @@

Representability

A constant x is representable by a value of type T, -where T is not a type parameter, +where T is not a type parameter, if one of the following conditions applies:

@@ -2105,6 +2105,7 @@

Declarations and scope

A declaration binds a non-blank identifier to a constant, type, +type parameter, variable, function, label, or @@ -2502,7 +2503,7 @@

Type definitions

-If the type definition specifies type parameters, +If the type definition specifies type parameters, the type name denotes a generic type. Generic types must be instantiated when they are used. @@ -2538,7 +2539,7 @@

Type definitions

func (l *List[T]) Len() int { … } -

Type parameter lists

+

Type parameter declarations

A type parameter list declares the type parameters of a generic function or type declaration. @@ -2577,22 +2578,22 @@

Type parameter lists

A parsing ambiguity arises when the type parameter list for a generic type -declares a single type parameter with a type constraint of the form *C -or (C) where C is not a (possibly parenthesized) -type literal: +declares a single type parameter P with a constraint C +such that the text P C forms a valid expression:

 type T[P *C] …
 type T[P (C)] …
+type T[P *C|Q] …
+…
 

-In these rare cases, the type parameter declaration is indistinguishable from -the expressions P*C or P(C) and the type declaration -is parsed as an array type declaration. -To resolve the ambiguity, embed the constraint in an interface or use a trailing -comma: +In these rare cases, the type parameter list is indistinguishable from an +expression and the type declaration is parsed as an array type declaration. +To resolve the ambiguity, embed the constraint in an +interface or use a trailing comma:

@@ -2606,6 +2607,11 @@ 

Type parameter lists

with a generic type.

+ +

Type constraints

@@ -2625,10 +2631,10 @@

Type constraints

-[T *P]                             // = [T interface{*P}]
-[T ~int]                           // = [T interface{~int}]
-[T int|string]                     // = [T interface{int|string}]
-type Constraint ~int               // illegal: ~int is not inside a type parameter list
+[T []P]                      // = [T interface{[]P}]
+[T ~int]                     // = [T interface{~int}]
+[T int|string]               // = [T interface{int|string}]
+type Constraint ~int         // illegal: ~int is not inside a type parameter list
 
-

Earlier version

- -

-For the pre-Go1.18 specification without generics support see -The Go Programming Language Specification. -

-

Introduction

-This is a reference manual for the Go programming language. For -more information and other documents, see golang.org. +This is the reference manual for the Go programming language. +The pre-Go1.18 version, without generics, can be found +here. +For more information and other documents, see golang.org.

@@ -4668,10 +4663,6 @@

Operators

to the type of the other operand.

-

-[The rules for shifts need adjustments for type parameters. Issue #51182.] -

-

The right operand in a shift expression must have integer type or be an untyped constant representable by a @@ -7257,10 +7248,6 @@

Deletion of map elements

Manipulating complex numbers

-

-[We don't support generic arguments for these built-ins for Go 1.18.] -

-

Three functions assemble and disassemble complex numbers. The built-in function complex constructs a complex @@ -7323,6 +7310,10 @@

Manipulating complex numbers

_ = imag(3 << s) // illegal: 3 assumes complex type, cannot shift
+

+Arguments of type parameter type are not permitted. +

+

Handling panics

Two built-in functions, panic and recover, From fe75fe3c7ae99713ed4e452ea8a4fcb589517dd9 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Thu, 10 Mar 2022 17:40:01 -0800 Subject: [PATCH 079/276] spec: various minor clarifications - Allow for a type parameter as length/capacity to make. - Be slightly more precise in prose for append. - Add a couple of links. Change-Id: Ib97e528bab1ab55d271beeeb53d9bb7a07047b9b Reviewed-on: https://go-review.googlesource.com/c/go/+/391754 Trust: Robert Griesemer Reviewed-by: Ian Lance Taylor --- doc/go_spec.html | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/doc/go_spec.html b/doc/go_spec.html index 9b37e0ded08..ad12fcfaa99 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -7116,8 +7116,9 @@

Making slices, maps and channels

-Each of the size arguments n and m must be of integer type -or an untyped constant. +Each of the size arguments n and m must be of integer type, +have a type set containing only integer types, +or be an untyped constant. A constant size argument must be non-negative and representable by a value of type int; if it is an untyped constant it is given type int. If both n and m are provided and are constant, then @@ -7154,9 +7155,9 @@

Appending to and copying slices

The variadic function append appends zero or more values x to a slice s -and returns the resulting slice. +and returns the resulting slice of the same type as s. The core type of s must be a slice -of the form []E. +of type []E. The values x are passed to a parameter of type ...E and the respective parameter passing rules apply. @@ -7166,7 +7167,7 @@

Appending to and copying slices

-append(s S, x ...E) S  // E is the element type of the core type of S
+append(s S, x ...E) S  // core type of S is []E
 

@@ -7922,11 +7923,17 @@

Package unsafe

func Slice(ptr *ArbitraryType, len IntegerType) []ArbitraryType + +

A Pointer is a pointer type but a Pointer value may not be dereferenced. -Any pointer or value of underlying type uintptr can be converted to -a type of underlying type Pointer and vice versa. +Any pointer or value of underlying type uintptr can be +converted to a type of underlying type Pointer and vice versa. The effect of converting between Pointer and uintptr is implementation-defined.

@@ -7973,7 +7980,8 @@

Package unsafe

A (variable of) type T has variable size if T -is a type parameter, or if it is an array or struct type containing elements +is a type parameter, or if it is an +array or struct type containing elements or fields of variable size. Otherwise the size is constant. Calls to Alignof, Offsetof, and Sizeof are compile-time constant expressions of From c1f22134f22158ebeebf450357f711eb22fab202 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Thu, 10 Mar 2022 09:28:09 +0100 Subject: [PATCH 080/276] runtime/pprof, syscall: report MaxRSS on all unix platforms All unix platforms currently supported by Go provide the getrusage syscall. On aix and solaris the Getrusage syscall wrapper is not available yet, so add and use it to report MaxRSS in memory profiles. Change-Id: Ie880a3058171031fd2e12ccf9adfb85ce18858b1 Reviewed-on: https://go-review.googlesource.com/c/go/+/391434 Trust: Tobias Klauser Run-TryBot: Tobias Klauser TryBot-Result: Gopher Robot Reviewed-by: Michael Pratt Trust: Michael Pratt Reviewed-by: Ian Lance Taylor --- src/runtime/pprof/pprof_norusage.go | 2 +- src/runtime/pprof/pprof_rusage.go | 6 ++++-- src/runtime/pprof/rusage_test.go | 2 +- src/syscall/syscall_aix.go | 1 + src/syscall/syscall_solaris.go | 1 + src/syscall/zsyscall_aix_ppc64.go | 13 +++++++++++++ src/syscall/zsyscall_solaris_amd64.go | 13 +++++++++++++ 7 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/runtime/pprof/pprof_norusage.go b/src/runtime/pprof/pprof_norusage.go index cbc5176cfa0..3d6052519c4 100644 --- a/src/runtime/pprof/pprof_norusage.go +++ b/src/runtime/pprof/pprof_norusage.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build !darwin && !linux +//go:build !aix && !darwin && !dragonfly && !freebsd && !linux && !netbsd && !openbsd && !solaris package pprof diff --git a/src/runtime/pprof/pprof_rusage.go b/src/runtime/pprof/pprof_rusage.go index 46263fedd96..7df81eca23c 100644 --- a/src/runtime/pprof/pprof_rusage.go +++ b/src/runtime/pprof/pprof_rusage.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build darwin || linux +//go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris package pprof @@ -17,10 +17,12 @@ import ( func addMaxRSS(w io.Writer) { var rssToBytes uintptr switch runtime.GOOS { - case "linux", "android": + case "aix", "android", "dragonfly", "freebsd", "linux", "netbsd", "openbsd": rssToBytes = 1024 case "darwin", "ios": rssToBytes = 1 + case "illumos", "solaris": + rssToBytes = uintptr(syscall.Getpagesize()) default: panic("unsupported OS") } diff --git a/src/runtime/pprof/rusage_test.go b/src/runtime/pprof/rusage_test.go index b0d651e0ebb..f274d0caa3a 100644 --- a/src/runtime/pprof/rusage_test.go +++ b/src/runtime/pprof/rusage_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build darwin || freebsd || linux || netbsd || openbsd +//go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris package pprof diff --git a/src/syscall/syscall_aix.go b/src/syscall/syscall_aix.go index 739c55f1793..acc19b4db32 100644 --- a/src/syscall/syscall_aix.go +++ b/src/syscall/syscall_aix.go @@ -594,6 +594,7 @@ func PtraceDetach(pid int) (err error) { return ptrace64(PT_DETACH, int64(pid), //sys Getppid() (ppid int) //sys Getpriority(which int, who int) (n int, err error) //sysnb Getrlimit(which int, lim *Rlimit) (err error) +//sysnb Getrusage(who int, rusage *Rusage) (err error) //sysnb Getuid() (uid int) //sys Kill(pid int, signum Signal) (err error) //sys Lchown(path string, uid int, gid int) (err error) diff --git a/src/syscall/syscall_solaris.go b/src/syscall/syscall_solaris.go index d01070b2ec5..38c82a11e85 100644 --- a/src/syscall/syscall_solaris.go +++ b/src/syscall/syscall_solaris.go @@ -421,6 +421,7 @@ func sendmsgN(fd int, p, oob []byte, ptr unsafe.Pointer, salen _Socklen, flags i //sys Getppid() (ppid int) //sys Getpriority(which int, who int) (n int, err error) //sysnb Getrlimit(which int, lim *Rlimit) (err error) +//sysnb Getrusage(who int, rusage *Rusage) (err error) //sysnb Gettimeofday(tv *Timeval) (err error) //sysnb Getuid() (uid int) //sys Kill(pid int, signum Signal) (err error) diff --git a/src/syscall/zsyscall_aix_ppc64.go b/src/syscall/zsyscall_aix_ppc64.go index 94f1b4371c5..2a3411374f5 100644 --- a/src/syscall/zsyscall_aix_ppc64.go +++ b/src/syscall/zsyscall_aix_ppc64.go @@ -62,6 +62,7 @@ import "unsafe" //go:cgo_import_dynamic libc_Getppid getppid "libc.a/shr_64.o" //go:cgo_import_dynamic libc_Getpriority getpriority "libc.a/shr_64.o" //go:cgo_import_dynamic libc_Getrlimit getrlimit "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_Getrusage getrusage "libc.a/shr_64.o" //go:cgo_import_dynamic libc_Getuid getuid "libc.a/shr_64.o" //go:cgo_import_dynamic libc_Kill kill "libc.a/shr_64.o" //go:cgo_import_dynamic libc_Lchown lchown "libc.a/shr_64.o" @@ -154,6 +155,7 @@ import "unsafe" //go:linkname libc_Getppid libc_Getppid //go:linkname libc_Getpriority libc_Getpriority //go:linkname libc_Getrlimit libc_Getrlimit +//go:linkname libc_Getrusage libc_Getrusage //go:linkname libc_Getuid libc_Getuid //go:linkname libc_Kill libc_Kill //go:linkname libc_Lchown libc_Lchown @@ -249,6 +251,7 @@ var ( libc_Getppid, libc_Getpriority, libc_Getrlimit, + libc_Getrusage, libc_Getuid, libc_Kill, libc_Lchown, @@ -925,6 +928,16 @@ func Getrlimit(which int, lim *Rlimit) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func Getrusage(who int, rusage *Rusage) (err error) { + _, _, e1 := rawSyscall6(uintptr(unsafe.Pointer(&libc_Getrusage)), 2, uintptr(who), uintptr(unsafe.Pointer(rusage)), 0, 0, 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func Getuid() (uid int) { r0, _, _ := rawSyscall6(uintptr(unsafe.Pointer(&libc_Getuid)), 0, 0, 0, 0, 0, 0, 0) uid = int(r0) diff --git a/src/syscall/zsyscall_solaris_amd64.go b/src/syscall/zsyscall_solaris_amd64.go index dad05800273..7b012bf9bb8 100644 --- a/src/syscall/zsyscall_solaris_amd64.go +++ b/src/syscall/zsyscall_solaris_amd64.go @@ -35,6 +35,7 @@ import "unsafe" //go:cgo_import_dynamic libc_Getppid getppid "libc.so" //go:cgo_import_dynamic libc_Getpriority getpriority "libc.so" //go:cgo_import_dynamic libc_Getrlimit getrlimit "libc.so" +//go:cgo_import_dynamic libc_Getrusage getrusage "libc.so" //go:cgo_import_dynamic libc_Gettimeofday gettimeofday "libc.so" //go:cgo_import_dynamic libc_Getuid getuid "libc.so" //go:cgo_import_dynamic libc_Kill kill "libc.so" @@ -120,6 +121,7 @@ import "unsafe" //go:linkname libc_Getppid libc_Getppid //go:linkname libc_Getpriority libc_Getpriority //go:linkname libc_Getrlimit libc_Getrlimit +//go:linkname libc_Getrusage libc_Getrusage //go:linkname libc_Gettimeofday libc_Gettimeofday //go:linkname libc_Getuid libc_Getuid //go:linkname libc_Kill libc_Kill @@ -208,6 +210,7 @@ var ( libc_Getppid, libc_Getpriority, libc_Getrlimit, + libc_Getrusage, libc_Gettimeofday, libc_Getuid, libc_Kill, @@ -580,6 +583,16 @@ func Getrlimit(which int, lim *Rlimit) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func Getrusage(who int, rusage *Rusage) (err error) { + _, _, e1 := rawSysvicall6(uintptr(unsafe.Pointer(&libc_Getrusage)), 2, uintptr(who), uintptr(unsafe.Pointer(rusage)), 0, 0, 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func Gettimeofday(tv *Timeval) (err error) { _, _, e1 := rawSysvicall6(uintptr(unsafe.Pointer(&libc_Gettimeofday)), 1, uintptr(unsafe.Pointer(tv)), 0, 0, 0, 0, 0) if e1 != 0 { From 7b1ba972dc5687f6746b2299b047f44e38bc6686 Mon Sep 17 00:00:00 2001 From: "Paul E. Murphy" Date: Mon, 25 Oct 2021 16:51:55 -0500 Subject: [PATCH 081/276] cmd/asm: add support for bdnz/bdz extended mnemonics on PPC64 Support BDNZ and BDZ mnemonics, they are commonly used POWER instructions. The raw BC mnemonic is not easy to read. Likewise, cleanup code surrounding these changes. Change-Id: I72f1dad5013f7856bd0dd320bfb17b5a9f3c69ee Reviewed-on: https://go-review.googlesource.com/c/go/+/390696 Reviewed-by: Lynn Boger Trust: Paul Murphy Run-TryBot: Paul Murphy TryBot-Result: Gopher Robot --- src/cmd/asm/internal/arch/ppc64.go | 2 +- src/cmd/asm/internal/asm/testdata/ppc64.s | 30 ++++++++++++++--------- src/cmd/internal/obj/ppc64/a.out.go | 11 ++++++--- src/cmd/internal/obj/ppc64/anames.go | 2 ++ src/cmd/internal/obj/ppc64/asm9.go | 24 ++++++++++++------ 5 files changed, 44 insertions(+), 25 deletions(-) diff --git a/src/cmd/asm/internal/arch/ppc64.go b/src/cmd/asm/internal/arch/ppc64.go index 3139665ba55..616e189b1a8 100644 --- a/src/cmd/asm/internal/arch/ppc64.go +++ b/src/cmd/asm/internal/arch/ppc64.go @@ -15,7 +15,7 @@ import ( func jumpPPC64(word string) bool { switch word { - case "BC", "BCL", "BEQ", "BGE", "BGT", "BL", "BLE", "BLT", "BNE", "BR", "BVC", "BVS", "CALL", "JMP": + case "BC", "BCL", "BEQ", "BGE", "BGT", "BL", "BLE", "BLT", "BNE", "BR", "BVC", "BVS", "BDNZ", "BDZ", "CALL", "JMP": return true } return false diff --git a/src/cmd/asm/internal/asm/testdata/ppc64.s b/src/cmd/asm/internal/asm/testdata/ppc64.s index c140fd025a6..5452668791d 100644 --- a/src/cmd/asm/internal/asm/testdata/ppc64.s +++ b/src/cmd/asm/internal/asm/testdata/ppc64.s @@ -751,17 +751,23 @@ TEXT asmtest(SB),DUPOK|NOSPLIT,$0 MOVD XER, R3 // 7c6102a6 MOVFL CR3, CR1 // 4c8c0000 - MOVW CR0, R1 // 7c380026 - MOVW CR7, R1 // 7c301026 - MOVW CR, R1 // 7c200026 - - MOVW R1, CR // 7c2ff120 - MOVFL R1, CR // 7c2ff120 - MOVW R1, CR2 // 7c320120 - MOVFL R1, CR2 // 7c320120 - MOVFL R1, $255 // 7c2ff120 - MOVFL R1, $1 // 7c301120 - MOVFL R1, $128 // 7c380120 - MOVFL R1, $3 // 7c203120 + MOVW CR0, R1 // 7c380026 + MOVW CR7, R1 // 7c301026 + MOVW CR, R1 // 7c200026 + + MOVW R1, CR // 7c2ff120 + MOVFL R1, CR // 7c2ff120 + MOVW R1, CR2 // 7c320120 + MOVFL R1, CR2 // 7c320120 + MOVFL R1, $255 // 7c2ff120 + MOVFL R1, $1 // 7c301120 + MOVFL R1, $128 // 7c380120 + MOVFL R1, $3 // 7c203120 + + // Verify supported bdnz/bdz encodings. + BC 16,0,0(PC) // BC $16,R0,0(PC) // 42000000 + BDNZ 0(PC) // 42000000 + BDZ 0(PC) // 42400000 + BC 18,0,0(PC) // BC $18,R0,0(PC) // 42400000 RET diff --git a/src/cmd/internal/obj/ppc64/a.out.go b/src/cmd/internal/obj/ppc64/a.out.go index 1e74e64a29f..25081efcee8 100644 --- a/src/cmd/internal/obj/ppc64/a.out.go +++ b/src/cmd/internal/obj/ppc64/a.out.go @@ -362,13 +362,14 @@ const ( BI_LT = 0 BI_GT = 1 BI_EQ = 2 - BI_OVF = 3 + BI_FU = 3 ) // Common values for the BO field. const ( BO_BCTR = 16 // decrement ctr, branch on ctr != 0 + BO_NOTBCTR = 18 // decrement ctr, branch on ctr == 0 BO_BCR = 12 // branch on cr value BO_BCRBCTR = 8 // decrement ctr, branch on ctr != 0 and cr value BO_NOTBCR = 4 // branch on not cr value @@ -480,9 +481,11 @@ const ( ABGT ABLE // not GT = L/E/U ABLT - ABNE // not EQ = L/G/U - ABVC // Unordered-clear - ABVS // Unordered-set + ABNE // not EQ = L/G/U + ABVC // Branch if float not unordered (also branch on not summary overflow) + ABVS // Branch if float unordered (also branch on summary overflow) + ABDNZ // Decrement CTR, and branch if CTR != 0 + ABDZ // Decrement CTR, and branch if CTR == 0 ACMP ACMPU ACMPEQB diff --git a/src/cmd/internal/obj/ppc64/anames.go b/src/cmd/internal/obj/ppc64/anames.go index 0da73ca91ed..7521a92ab4d 100644 --- a/src/cmd/internal/obj/ppc64/anames.go +++ b/src/cmd/internal/obj/ppc64/anames.go @@ -42,6 +42,8 @@ var Anames = []string{ "BNE", "BVC", "BVS", + "BDNZ", + "BDZ", "CMP", "CMPU", "CMPEQB", diff --git a/src/cmd/internal/obj/ppc64/asm9.go b/src/cmd/internal/obj/ppc64/asm9.go index 70ce9050b69..50c9b37f02f 100644 --- a/src/cmd/internal/obj/ppc64/asm9.go +++ b/src/cmd/internal/obj/ppc64/asm9.go @@ -305,6 +305,7 @@ var optab = []Optab{ {as: ABC, a1: C_SCON, a2: C_REG, a6: C_LR, type_: 18, size: 4}, {as: ABC, a1: C_SCON, a2: C_REG, a6: C_CTR, type_: 18, size: 4}, {as: ABC, a6: C_ZOREG, type_: 15, size: 8}, + {as: ABDNZ, a6: C_SBRA, type_: 16, size: 4}, {as: ASYNC, type_: 46, size: 4}, {as: AWORD, a1: C_LCON, type_: 40, size: 4}, {as: ADWORD, a1: C_64CON, type_: 31, size: 8}, @@ -1778,6 +1779,9 @@ func buildop(ctxt *obj.Link) { case ABC: opset(ABCL, r0) + case ABDNZ: + opset(ABDZ, r0) + case AEXTSB: /* op Rs, Ra */ opset(AEXTSBCC, r0) @@ -4875,21 +4879,25 @@ func (c *ctxt9) opirr(a obj.As) uint32 { return OPVCC(16, 0, 0, 0) | 1 case ABEQ: - return AOP_RRR(16<<26, 12, 2, 0) + return AOP_RRR(16<<26, BO_BCR, BI_EQ, 0) case ABGE: - return AOP_RRR(16<<26, 4, 0, 0) + return AOP_RRR(16<<26, BO_NOTBCR, BI_LT, 0) case ABGT: - return AOP_RRR(16<<26, 12, 1, 0) + return AOP_RRR(16<<26, BO_BCR, BI_GT, 0) case ABLE: - return AOP_RRR(16<<26, 4, 1, 0) + return AOP_RRR(16<<26, BO_NOTBCR, BI_GT, 0) case ABLT: - return AOP_RRR(16<<26, 12, 0, 0) + return AOP_RRR(16<<26, BO_BCR, BI_LT, 0) case ABNE: - return AOP_RRR(16<<26, 4, 2, 0) + return AOP_RRR(16<<26, BO_NOTBCR, BI_EQ, 0) case ABVC: - return AOP_RRR(16<<26, 4, 3, 0) // apparently unordered-clear + return AOP_RRR(16<<26, BO_NOTBCR, BI_FU, 0) case ABVS: - return AOP_RRR(16<<26, 12, 3, 0) // apparently unordered-set + return AOP_RRR(16<<26, BO_BCR, BI_FU, 0) + case ABDZ: + return AOP_RRR(16<<26, BO_NOTBCTR, 0, 0) + case ABDNZ: + return AOP_RRR(16<<26, BO_BCTR, 0, 0) case ACMP: return OPVCC(11, 0, 0, 0) | 1<<21 /* L=1 */ From baf61e4a67789e20f019507287a324cca06bed42 Mon Sep 17 00:00:00 2001 From: eh-steve Date: Fri, 11 Mar 2022 21:14:27 +0000 Subject: [PATCH 082/276] encoding/hex: implement Decode with a lookup table MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implement hex decode using a 256 byte lookup table instead of branching logic. In happy flow, uses 3x 64 byte (or 5x 32 byte) cache lines. name old time/op new time/op delta Decode/256-64 223ns ± 3% 135ns ± 2% -39.64% (p=0.000 n=8+8) Decode/1024-64 872ns ± 2% 512ns ± 2% -41.25% (p=0.000 n=8+8) Decode/4096-64 3.43µs ± 1% 2.01µs ± 2% -41.31% (p=0.001 n=7+7) Decode/16384-64 13.9µs ± 1% 8.0µs ± 1% -42.69% (p=0.000 n=8+7) name old speed new speed delta Decode/256-64 1.15GB/s ± 3% 1.90GB/s ± 2% +65.66% (p=0.000 n=8+8) Decode/1024-64 1.17GB/s ± 2% 2.00GB/s ± 2% +70.22% (p=0.000 n=8+8) Decode/4096-64 1.20GB/s ± 1% 2.04GB/s ± 2% +70.39% (p=0.001 n=7+7) Decode/16384-64 1.18GB/s ± 1% 2.06GB/s ± 1% +74.49% (p=0.000 n=8+7) Also reduces amd64 object size by 766 bytes, despite the extra RODATA due to removal of `fromHexChar()` and duplicated inlined versions of it and simplification of `Decode()`. Change-Id: I0988c7a30562ec154eff11db6e27954e0ce2b611 GitHub-Last-Rev: 64818018afc83ab07ec128a46aaea6a16f11400e GitHub-Pull-Request: golang/go#51432 Reviewed-on: https://go-review.googlesource.com/c/go/+/390037 Reviewed-by: Ian Lance Taylor Reviewed-by: Daniel Martí Trust: Daniel Martí Run-TryBot: Daniel Martí TryBot-Result: Gopher Robot --- src/encoding/hex/hex.go | 55 ++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/src/encoding/hex/hex.go b/src/encoding/hex/hex.go index fbba78ffd21..375f5831709 100644 --- a/src/encoding/hex/hex.go +++ b/src/encoding/hex/hex.go @@ -12,7 +12,26 @@ import ( "strings" ) -const hextable = "0123456789abcdef" +const ( + hextable = "0123456789abcdef" + reverseHexTable = "" + + "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" + + "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" + + "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" + + "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\xff\xff\xff\xff\xff\xff" + + "\xff\x0a\x0b\x0c\x0d\x0e\x0f\xff\xff\xff\xff\xff\xff\xff\xff\xff" + + "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" + + "\xff\x0a\x0b\x0c\x0d\x0e\x0f\xff\xff\xff\xff\xff\xff\xff\xff\xff" + + "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" + + "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" + + "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" + + "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" + + "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" + + "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" + + "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" + + "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" + + "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" +) // EncodedLen returns the length of an encoding of n source bytes. // Specifically, it returns n * 2. @@ -58,13 +77,16 @@ func DecodedLen(x int) int { return x / 2 } func Decode(dst, src []byte) (int, error) { i, j := 0, 1 for ; j < len(src); j += 2 { - a, ok := fromHexChar(src[j-1]) - if !ok { - return i, InvalidByteError(src[j-1]) + p := src[j-1] + q := src[j] + + a := reverseHexTable[p] + b := reverseHexTable[q] + if a > 0x0f { + return i, InvalidByteError(p) } - b, ok := fromHexChar(src[j]) - if !ok { - return i, InvalidByteError(src[j]) + if b > 0x0f { + return i, InvalidByteError(q) } dst[i] = (a << 4) | b i++ @@ -72,7 +94,7 @@ func Decode(dst, src []byte) (int, error) { if len(src)%2 == 1 { // Check for invalid char before reporting bad length, // since the invalid char (if present) is an earlier problem. - if _, ok := fromHexChar(src[j-1]); !ok { + if reverseHexTable[src[j-1]] > 0x0f { return i, InvalidByteError(src[j-1]) } return i, ErrLength @@ -80,20 +102,6 @@ func Decode(dst, src []byte) (int, error) { return i, nil } -// fromHexChar converts a hex character into its value and a success flag. -func fromHexChar(c byte) (byte, bool) { - switch { - case '0' <= c && c <= '9': - return c - '0', true - case 'a' <= c && c <= 'f': - return c - 'a' + 10, true - case 'A' <= c && c <= 'F': - return c - 'A' + 10, true - } - - return 0, false -} - // EncodeToString returns the hexadecimal encoding of src. func EncodeToString(src []byte) string { dst := make([]byte, EncodedLen(len(src))) @@ -185,7 +193,8 @@ func (d *decoder) Read(p []byte) (n int, err error) { numRead, d.err = d.r.Read(d.arr[numCopy:]) d.in = d.arr[:numCopy+numRead] if d.err == io.EOF && len(d.in)%2 != 0 { - if _, ok := fromHexChar(d.in[len(d.in)-1]); !ok { + + if a := reverseHexTable[d.in[len(d.in)-1]]; a > 0x0f { d.err = InvalidByteError(d.in[len(d.in)-1]) } else { d.err = io.ErrUnexpectedEOF From 842d37ee5f86f12aa096b750adbd2debd9129fcb Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 11 Mar 2022 18:29:37 -0800 Subject: [PATCH 083/276] syscall: add race annotations to Pread and Pwrite Fixes #51618 Change-Id: Ife894d8c313dce8c4929f40fa0ac90a069f77a89 Reviewed-on: https://go-review.googlesource.com/c/go/+/391954 Trust: Ian Lance Taylor Run-TryBot: Ian Lance Taylor TryBot-Result: Gopher Robot Reviewed-by: Keith Randall --- src/runtime/race/testdata/mop_test.go | 14 +++++++++- src/syscall/syscall_aix.go | 4 +-- src/syscall/syscall_darwin.go | 4 +-- src/syscall/syscall_dragonfly.go | 4 +-- src/syscall/syscall_freebsd.go | 4 +-- src/syscall/syscall_linux_386.go | 4 +-- src/syscall/syscall_linux_amd64.go | 4 +-- src/syscall/syscall_linux_arm.go | 4 +-- src/syscall/syscall_linux_arm64.go | 4 +-- src/syscall/syscall_linux_mips64x.go | 4 +-- src/syscall/syscall_linux_mipsx.go | 4 +-- src/syscall/syscall_linux_ppc64x.go | 4 +-- src/syscall/syscall_linux_riscv64.go | 4 +-- src/syscall/syscall_linux_s390x.go | 4 +-- src/syscall/syscall_netbsd.go | 4 +-- src/syscall/syscall_openbsd.go | 4 +-- src/syscall/syscall_solaris.go | 4 +-- src/syscall/syscall_unix.go | 36 ++++++++++++++++++++++++++ src/syscall/zsyscall_aix_ppc64.go | 20 +++++++------- src/syscall/zsyscall_darwin_amd64.go | 4 +-- src/syscall/zsyscall_darwin_arm64.go | 4 +-- src/syscall/zsyscall_freebsd_386.go | 4 +-- src/syscall/zsyscall_freebsd_amd64.go | 4 +-- src/syscall/zsyscall_freebsd_arm.go | 4 +-- src/syscall/zsyscall_freebsd_arm64.go | 4 +-- src/syscall/zsyscall_linux_386.go | 4 +-- src/syscall/zsyscall_linux_amd64.go | 4 +-- src/syscall/zsyscall_linux_arm.go | 4 +-- src/syscall/zsyscall_linux_arm64.go | 4 +-- src/syscall/zsyscall_linux_mips.go | 4 +-- src/syscall/zsyscall_linux_mips64.go | 4 +-- src/syscall/zsyscall_linux_mips64le.go | 4 +-- src/syscall/zsyscall_linux_mipsle.go | 4 +-- src/syscall/zsyscall_linux_ppc64.go | 4 +-- src/syscall/zsyscall_linux_ppc64le.go | 4 +-- src/syscall/zsyscall_linux_riscv64.go | 4 +-- src/syscall/zsyscall_linux_s390x.go | 4 +-- src/syscall/zsyscall_netbsd_386.go | 4 +-- src/syscall/zsyscall_netbsd_amd64.go | 4 +-- src/syscall/zsyscall_netbsd_arm.go | 4 +-- src/syscall/zsyscall_netbsd_arm64.go | 4 +-- src/syscall/zsyscall_openbsd_386.go | 4 +-- src/syscall/zsyscall_openbsd_amd64.go | 4 +-- src/syscall/zsyscall_openbsd_arm.go | 4 +-- src/syscall/zsyscall_openbsd_arm64.go | 4 +-- src/syscall/zsyscall_openbsd_mips64.go | 4 +-- src/syscall/zsyscall_solaris_amd64.go | 20 +++++++------- 47 files changed, 155 insertions(+), 107 deletions(-) diff --git a/src/runtime/race/testdata/mop_test.go b/src/runtime/race/testdata/mop_test.go index 2d093739dfb..d05a443f62a 100644 --- a/src/runtime/race/testdata/mop_test.go +++ b/src/runtime/race/testdata/mop_test.go @@ -1896,6 +1896,14 @@ func TestRaceNestedStruct(t *testing.T) { } func TestRaceIssue5567(t *testing.T) { + testRaceRead(t, false) +} + +func TestRaceIssue51618(t *testing.T) { + testRaceRead(t, true) +} + +func testRaceRead(t *testing.T, pread bool) { defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(4)) in := make(chan []byte) res := make(chan error) @@ -1914,7 +1922,11 @@ func TestRaceIssue5567(t *testing.T) { var n, total int b := make([]byte, 17) // the race is on b buffer for err == nil { - n, err = f.Read(b) + if pread { + n, err = f.ReadAt(b, int64(total)) + } else { + n, err = f.Read(b) + } total += n if n > 0 { in <- b[:n] diff --git a/src/syscall/syscall_aix.go b/src/syscall/syscall_aix.go index acc19b4db32..a2f8c784389 100644 --- a/src/syscall/syscall_aix.go +++ b/src/syscall/syscall_aix.go @@ -604,8 +604,8 @@ func PtraceDetach(pid int) (err error) { return ptrace64(PT_DETACH, int64(pid), //sys Mkdirat(dirfd int, path string, mode uint32) (err error) //sys Mknodat(dirfd int, path string, mode uint32, dev int) (err error) //sys Open(path string, mode int, perm uint32) (fd int, err error) -//sys Pread(fd int, p []byte, offset int64) (n int, err error) -//sys Pwrite(fd int, p []byte, offset int64) (n int, err error) +//sys pread(fd int, p []byte, offset int64) (n int, err error) +//sys pwrite(fd int, p []byte, offset int64) (n int, err error) //sys read(fd int, p []byte) (n int, err error) //sys Reboot(how int) (err error) //sys Rename(from string, to string) (err error) diff --git a/src/syscall/syscall_darwin.go b/src/syscall/syscall_darwin.go index 87fb5c2f62d..2e5387a6d9b 100644 --- a/src/syscall/syscall_darwin.go +++ b/src/syscall/syscall_darwin.go @@ -170,8 +170,8 @@ func Kill(pid int, signum Signal) (err error) { return kill(pid, int(signum), 1) //sys Munlockall() (err error) //sys Open(path string, mode int, perm uint32) (fd int, err error) //sys Pathconf(path string, name int) (val int, err error) -//sys Pread(fd int, p []byte, offset int64) (n int, err error) -//sys Pwrite(fd int, p []byte, offset int64) (n int, err error) +//sys pread(fd int, p []byte, offset int64) (n int, err error) +//sys pwrite(fd int, p []byte, offset int64) (n int, err error) //sys read(fd int, p []byte) (n int, err error) //sys readdir_r(dir uintptr, entry *Dirent, result **Dirent) (res Errno) //sys Readlink(path string, buf []byte) (n int, err error) diff --git a/src/syscall/syscall_dragonfly.go b/src/syscall/syscall_dragonfly.go index f3c0f545214..d8edca99614 100644 --- a/src/syscall/syscall_dragonfly.go +++ b/src/syscall/syscall_dragonfly.go @@ -122,12 +122,12 @@ func Pipe2(p []int, flags int) (err error) { } //sys extpread(fd int, p []byte, flags int, offset int64) (n int, err error) -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { return extpread(fd, p, 0, offset) } //sys extpwrite(fd int, p []byte, flags int, offset int64) (n int, err error) -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { return extpwrite(fd, p, 0, offset) } diff --git a/src/syscall/syscall_freebsd.go b/src/syscall/syscall_freebsd.go index ecb9ec825aa..8494b21e5b7 100644 --- a/src/syscall/syscall_freebsd.go +++ b/src/syscall/syscall_freebsd.go @@ -469,8 +469,8 @@ func convertFromDirents11(buf []byte, old []byte) int { //sys Nanosleep(time *Timespec, leftover *Timespec) (err error) //sys Open(path string, mode int, perm uint32) (fd int, err error) //sys Pathconf(path string, name int) (val int, err error) -//sys Pread(fd int, p []byte, offset int64) (n int, err error) -//sys Pwrite(fd int, p []byte, offset int64) (n int, err error) +//sys pread(fd int, p []byte, offset int64) (n int, err error) +//sys pwrite(fd int, p []byte, offset int64) (n int, err error) //sys read(fd int, p []byte) (n int, err error) //sys Readlink(path string, buf []byte) (n int, err error) //sys Rename(from string, to string) (err error) diff --git a/src/syscall/syscall_linux_386.go b/src/syscall/syscall_linux_386.go index ef0f53468a1..fc7df8496eb 100644 --- a/src/syscall/syscall_linux_386.go +++ b/src/syscall/syscall_linux_386.go @@ -32,8 +32,8 @@ func setTimeval(sec, usec int64) Timeval { //sys Ioperm(from int, num int, on int) (err error) //sys Iopl(level int) (err error) //sys Pause() (err error) -//sys Pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64 -//sys Pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64 +//sys pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64 +//sys pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64 //sys Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error) //sys sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) = SYS_SENDFILE64 //sys Setfsgid(gid int) (err error) = SYS_SETFSGID32 diff --git a/src/syscall/syscall_linux_amd64.go b/src/syscall/syscall_linux_amd64.go index ea5229e8a0a..0bcc664d32a 100644 --- a/src/syscall/syscall_linux_amd64.go +++ b/src/syscall/syscall_linux_amd64.go @@ -22,8 +22,8 @@ const _SYS_setgroups = SYS_SETGROUPS //sys Iopl(level int) (err error) //sys Listen(s int, n int) (err error) //sys Pause() (err error) -//sys Pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64 -//sys Pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64 +//sys pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64 +//sys pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64 //sys Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error) //sys Seek(fd int, offset int64, whence int) (off int64, err error) = SYS_LSEEK //sys Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error) diff --git a/src/syscall/syscall_linux_arm.go b/src/syscall/syscall_linux_arm.go index f00149a1d4a..9db702729f8 100644 --- a/src/syscall/syscall_linux_arm.go +++ b/src/syscall/syscall_linux_arm.go @@ -72,8 +72,8 @@ func Seek(fd int, offset int64, whence int) (newoffset int64, err error) { //sys Utime(path string, buf *Utimbuf) (err error) //sys utimes(path string, times *[2]Timeval) (err error) -//sys Pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64 -//sys Pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64 +//sys pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64 +//sys pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64 //sys Truncate(path string, length int64) (err error) = SYS_TRUNCATE64 //sys Ftruncate(fd int, length int64) (err error) = SYS_FTRUNCATE64 diff --git a/src/syscall/syscall_linux_arm64.go b/src/syscall/syscall_linux_arm64.go index 9ed20f43ed5..ef935f3a63e 100644 --- a/src/syscall/syscall_linux_arm64.go +++ b/src/syscall/syscall_linux_arm64.go @@ -28,8 +28,8 @@ func EpollCreate(size int) (fd int, err error) { //sysnb getrlimit(resource int, rlim *Rlimit) (err error) //sysnb Getuid() (uid int) //sys Listen(s int, n int) (err error) -//sys Pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64 -//sys Pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64 +//sys pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64 +//sys pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64 //sys Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error) //sys Seek(fd int, offset int64, whence int) (off int64, err error) = SYS_LSEEK //sys sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) diff --git a/src/syscall/syscall_linux_mips64x.go b/src/syscall/syscall_linux_mips64x.go index b56b8f06b68..258eb97b7ed 100644 --- a/src/syscall/syscall_linux_mips64x.go +++ b/src/syscall/syscall_linux_mips64x.go @@ -23,8 +23,8 @@ const _SYS_setgroups = SYS_SETGROUPS //sys Lchown(path string, uid int, gid int) (err error) //sys Listen(s int, n int) (err error) //sys Pause() (err error) -//sys Pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64 -//sys Pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64 +//sys pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64 +//sys pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64 //sys Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error) //sys Seek(fd int, offset int64, whence int) (off int64, err error) = SYS_LSEEK //sys sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) diff --git a/src/syscall/syscall_linux_mipsx.go b/src/syscall/syscall_linux_mipsx.go index c9c9f94e42f..5390277926f 100644 --- a/src/syscall/syscall_linux_mipsx.go +++ b/src/syscall/syscall_linux_mipsx.go @@ -24,8 +24,8 @@ func Syscall9(trap, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, //sys Lchown(path string, uid int, gid int) (err error) //sys Listen(s int, n int) (err error) //sys Pause() (err error) -//sys Pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64 -//sys Pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64 +//sys pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64 +//sys pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64 //sys Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error) //sys Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error) = SYS__NEWSELECT //sys sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) = SYS_SENDFILE64 diff --git a/src/syscall/syscall_linux_ppc64x.go b/src/syscall/syscall_linux_ppc64x.go index 4180a17f3b4..88ad8e4cd4b 100644 --- a/src/syscall/syscall_linux_ppc64x.go +++ b/src/syscall/syscall_linux_ppc64x.go @@ -28,8 +28,8 @@ const _SYS_setgroups = SYS_SETGROUPS //sys Listen(s int, n int) (err error) //sys Lstat(path string, stat *Stat_t) (err error) //sys Pause() (err error) -//sys Pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64 -//sys Pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64 +//sys pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64 +//sys pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64 //sys Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error) //sys Seek(fd int, offset int64, whence int) (off int64, err error) = SYS_LSEEK //sys Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error) = SYS__NEWSELECT diff --git a/src/syscall/syscall_linux_riscv64.go b/src/syscall/syscall_linux_riscv64.go index a5fb18aa857..0ac4c5496ed 100644 --- a/src/syscall/syscall_linux_riscv64.go +++ b/src/syscall/syscall_linux_riscv64.go @@ -28,8 +28,8 @@ func EpollCreate(size int) (fd int, err error) { //sysnb Getrlimit(resource int, rlim *Rlimit) (err error) //sysnb Getuid() (uid int) //sys Listen(s int, n int) (err error) -//sys Pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64 -//sys Pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64 +//sys pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64 +//sys pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64 //sys renameat2(olddirfd int, oldpath string, newdirfd int, newpath string, flags uint) (err error) //sys Seek(fd int, offset int64, whence int) (off int64, err error) = SYS_LSEEK //sys sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) diff --git a/src/syscall/syscall_linux_s390x.go b/src/syscall/syscall_linux_s390x.go index 5d6f4d2526f..46b252dc95c 100644 --- a/src/syscall/syscall_linux_s390x.go +++ b/src/syscall/syscall_linux_s390x.go @@ -25,8 +25,8 @@ const _SYS_setgroups = SYS_SETGROUPS //sys Lchown(path string, uid int, gid int) (err error) //sys Lstat(path string, stat *Stat_t) (err error) //sys Pause() (err error) -//sys Pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64 -//sys Pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64 +//sys pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64 +//sys pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64 //sys Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error) //sys Seek(fd int, offset int64, whence int) (off int64, err error) = SYS_LSEEK //sys Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error) diff --git a/src/syscall/syscall_netbsd.go b/src/syscall/syscall_netbsd.go index 0d562cc78e4..9ccb66c0838 100644 --- a/src/syscall/syscall_netbsd.go +++ b/src/syscall/syscall_netbsd.go @@ -198,8 +198,8 @@ func sendfile(outfd int, infd int, offset *int64, count int) (written int, err e //sys Nanosleep(time *Timespec, leftover *Timespec) (err error) //sys Open(path string, mode int, perm uint32) (fd int, err error) //sys Pathconf(path string, name int) (val int, err error) -//sys Pread(fd int, p []byte, offset int64) (n int, err error) -//sys Pwrite(fd int, p []byte, offset int64) (n int, err error) +//sys pread(fd int, p []byte, offset int64) (n int, err error) +//sys pwrite(fd int, p []byte, offset int64) (n int, err error) //sys read(fd int, p []byte) (n int, err error) //sys Readlink(path string, buf []byte) (n int, err error) //sys Rename(from string, to string) (err error) diff --git a/src/syscall/syscall_openbsd.go b/src/syscall/syscall_openbsd.go index 30a95316e85..1d823510844 100644 --- a/src/syscall/syscall_openbsd.go +++ b/src/syscall/syscall_openbsd.go @@ -173,8 +173,8 @@ func Getfsstat(buf []Statfs_t, flags int) (n int, err error) { //sys Nanosleep(time *Timespec, leftover *Timespec) (err error) //sys Open(path string, mode int, perm uint32) (fd int, err error) //sys Pathconf(path string, name int) (val int, err error) -//sys Pread(fd int, p []byte, offset int64) (n int, err error) -//sys Pwrite(fd int, p []byte, offset int64) (n int, err error) +//sys pread(fd int, p []byte, offset int64) (n int, err error) +//sys pwrite(fd int, p []byte, offset int64) (n int, err error) //sys read(fd int, p []byte) (n int, err error) //sys Readlink(path string, buf []byte) (n int, err error) //sys Rename(from string, to string) (err error) diff --git a/src/syscall/syscall_solaris.go b/src/syscall/syscall_solaris.go index 38c82a11e85..37ce5c9e3c2 100644 --- a/src/syscall/syscall_solaris.go +++ b/src/syscall/syscall_solaris.go @@ -434,8 +434,8 @@ func sendmsgN(fd int, p, oob []byte, ptr unsafe.Pointer, salen _Socklen, flags i //sys Nanosleep(time *Timespec, leftover *Timespec) (err error) //sys Open(path string, mode int, perm uint32) (fd int, err error) //sys Pathconf(path string, name int) (val int, err error) -//sys Pread(fd int, p []byte, offset int64) (n int, err error) -//sys Pwrite(fd int, p []byte, offset int64) (n int, err error) +//sys pread(fd int, p []byte, offset int64) (n int, err error) +//sys pwrite(fd int, p []byte, offset int64) (n int, err error) //sys read(fd int, p []byte) (n int, err error) //sys Readlink(path string, buf []byte) (n int, err error) //sys Rename(from string, to string) (err error) diff --git a/src/syscall/syscall_unix.go b/src/syscall/syscall_unix.go index 5ee938115d4..c35df430aaa 100644 --- a/src/syscall/syscall_unix.go +++ b/src/syscall/syscall_unix.go @@ -227,6 +227,42 @@ func Write(fd int, p []byte) (n int, err error) { return } +func Pread(fd int, p []byte, offset int64) (n int, err error) { + n, err = pread(fd, p, offset) + if race.Enabled { + if n > 0 { + race.WriteRange(unsafe.Pointer(&p[0]), n) + } + if err == nil { + race.Acquire(unsafe.Pointer(&ioSync)) + } + } + if msanenabled && n > 0 { + msanWrite(unsafe.Pointer(&p[0]), n) + } + if asanenabled && n > 0 { + asanWrite(unsafe.Pointer(&p[0]), n) + } + return +} + +func Pwrite(fd int, p []byte, offset int64) (n int, err error) { + if race.Enabled { + race.ReleaseMerge(unsafe.Pointer(&ioSync)) + } + n, err = pwrite(fd, p, offset) + if race.Enabled && n > 0 { + race.ReadRange(unsafe.Pointer(&p[0]), n) + } + if msanenabled && n > 0 { + msanRead(unsafe.Pointer(&p[0]), n) + } + if asanenabled && n > 0 { + asanRead(unsafe.Pointer(&p[0]), n) + } + return +} + // For testing: clients can set this flag to force // creation of IPv6 sockets to return EAFNOSUPPORT. var SocketDisableIPv6 bool diff --git a/src/syscall/zsyscall_aix_ppc64.go b/src/syscall/zsyscall_aix_ppc64.go index 2a3411374f5..39838a42e65 100644 --- a/src/syscall/zsyscall_aix_ppc64.go +++ b/src/syscall/zsyscall_aix_ppc64.go @@ -72,8 +72,8 @@ import "unsafe" //go:cgo_import_dynamic libc_Mkdirat mkdirat "libc.a/shr_64.o" //go:cgo_import_dynamic libc_Mknodat mknodat "libc.a/shr_64.o" //go:cgo_import_dynamic libc_Open open "libc.a/shr_64.o" -//go:cgo_import_dynamic libc_Pread pread "libc.a/shr_64.o" -//go:cgo_import_dynamic libc_Pwrite pwrite "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_pread pread "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_pwrite pwrite "libc.a/shr_64.o" //go:cgo_import_dynamic libc_read read "libc.a/shr_64.o" //go:cgo_import_dynamic libc_Reboot reboot "libc.a/shr_64.o" //go:cgo_import_dynamic libc_Rename rename "libc.a/shr_64.o" @@ -165,8 +165,8 @@ import "unsafe" //go:linkname libc_Mkdirat libc_Mkdirat //go:linkname libc_Mknodat libc_Mknodat //go:linkname libc_Open libc_Open -//go:linkname libc_Pread libc_Pread -//go:linkname libc_Pwrite libc_Pwrite +//go:linkname libc_pread libc_pread +//go:linkname libc_pwrite libc_pwrite //go:linkname libc_read libc_read //go:linkname libc_Reboot libc_Reboot //go:linkname libc_Rename libc_Rename @@ -261,8 +261,8 @@ var ( libc_Mkdirat, libc_Mknodat, libc_Open, - libc_Pread, - libc_Pwrite, + libc_pread, + libc_pwrite, libc_read, libc_Reboot, libc_Rename, @@ -1067,12 +1067,12 @@ func Open(path string, mode int, perm uint32) (fd int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 *byte if len(p) > 0 { _p0 = &p[0] } - r0, _, e1 := syscall6(uintptr(unsafe.Pointer(&libc_Pread)), 4, uintptr(fd), uintptr(unsafe.Pointer(_p0)), uintptr(len(p)), uintptr(offset), 0, 0) + r0, _, e1 := syscall6(uintptr(unsafe.Pointer(&libc_pread)), 4, uintptr(fd), uintptr(unsafe.Pointer(_p0)), uintptr(len(p)), uintptr(offset), 0, 0) n = int(r0) if e1 != 0 { err = errnoErr(e1) @@ -1082,12 +1082,12 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 *byte if len(p) > 0 { _p0 = &p[0] } - r0, _, e1 := syscall6(uintptr(unsafe.Pointer(&libc_Pwrite)), 4, uintptr(fd), uintptr(unsafe.Pointer(_p0)), uintptr(len(p)), uintptr(offset), 0, 0) + r0, _, e1 := syscall6(uintptr(unsafe.Pointer(&libc_pwrite)), 4, uintptr(fd), uintptr(unsafe.Pointer(_p0)), uintptr(len(p)), uintptr(offset), 0, 0) n = int(r0) if e1 != 0 { err = errnoErr(e1) diff --git a/src/syscall/zsyscall_darwin_amd64.go b/src/syscall/zsyscall_darwin_amd64.go index 0ccdaf2d0ee..ee78a572fcb 100644 --- a/src/syscall/zsyscall_darwin_amd64.go +++ b/src/syscall/zsyscall_darwin_amd64.go @@ -1137,7 +1137,7 @@ func libc_pathconf_trampoline() // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -1158,7 +1158,7 @@ func libc_pread_trampoline() // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) diff --git a/src/syscall/zsyscall_darwin_arm64.go b/src/syscall/zsyscall_darwin_arm64.go index 09bf34bb3c5..ac1eccf7559 100644 --- a/src/syscall/zsyscall_darwin_arm64.go +++ b/src/syscall/zsyscall_darwin_arm64.go @@ -1137,7 +1137,7 @@ func libc_pathconf_trampoline() // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -1158,7 +1158,7 @@ func libc_pread_trampoline() // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) diff --git a/src/syscall/zsyscall_freebsd_386.go b/src/syscall/zsyscall_freebsd_386.go index ed0eb9fa15e..04bad4acc92 100644 --- a/src/syscall/zsyscall_freebsd_386.go +++ b/src/syscall/zsyscall_freebsd_386.go @@ -905,7 +905,7 @@ func Pathconf(path string, name int) (val int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -922,7 +922,7 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) diff --git a/src/syscall/zsyscall_freebsd_amd64.go b/src/syscall/zsyscall_freebsd_amd64.go index e291a567568..eeb9c0cb9b5 100644 --- a/src/syscall/zsyscall_freebsd_amd64.go +++ b/src/syscall/zsyscall_freebsd_amd64.go @@ -905,7 +905,7 @@ func Pathconf(path string, name int) (val int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -922,7 +922,7 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) diff --git a/src/syscall/zsyscall_freebsd_arm.go b/src/syscall/zsyscall_freebsd_arm.go index 7dd856fd970..8ea4282ba45 100644 --- a/src/syscall/zsyscall_freebsd_arm.go +++ b/src/syscall/zsyscall_freebsd_arm.go @@ -905,7 +905,7 @@ func Pathconf(path string, name int) (val int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -922,7 +922,7 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) diff --git a/src/syscall/zsyscall_freebsd_arm64.go b/src/syscall/zsyscall_freebsd_arm64.go index 229a9a22387..73bf50559d6 100644 --- a/src/syscall/zsyscall_freebsd_arm64.go +++ b/src/syscall/zsyscall_freebsd_arm64.go @@ -905,7 +905,7 @@ func Pathconf(path string, name int) (val int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -922,7 +922,7 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) diff --git a/src/syscall/zsyscall_linux_386.go b/src/syscall/zsyscall_linux_386.go index c385dd3ca14..36a3d7ed391 100644 --- a/src/syscall/zsyscall_linux_386.go +++ b/src/syscall/zsyscall_linux_386.go @@ -1196,7 +1196,7 @@ func Pause() (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -1213,7 +1213,7 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) diff --git a/src/syscall/zsyscall_linux_amd64.go b/src/syscall/zsyscall_linux_amd64.go index 3e22e209073..07f328e1e26 100644 --- a/src/syscall/zsyscall_linux_amd64.go +++ b/src/syscall/zsyscall_linux_amd64.go @@ -1211,7 +1211,7 @@ func Pause() (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -1228,7 +1228,7 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) diff --git a/src/syscall/zsyscall_linux_arm.go b/src/syscall/zsyscall_linux_arm.go index 38907a0b354..df79dbd0e15 100644 --- a/src/syscall/zsyscall_linux_arm.go +++ b/src/syscall/zsyscall_linux_arm.go @@ -1493,7 +1493,7 @@ func utimes(path string, times *[2]Timeval) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -1510,7 +1510,7 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) diff --git a/src/syscall/zsyscall_linux_arm64.go b/src/syscall/zsyscall_linux_arm64.go index f335c062d58..73321bd897c 100644 --- a/src/syscall/zsyscall_linux_arm64.go +++ b/src/syscall/zsyscall_linux_arm64.go @@ -1196,7 +1196,7 @@ func Listen(s int, n int) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -1213,7 +1213,7 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) diff --git a/src/syscall/zsyscall_linux_mips.go b/src/syscall/zsyscall_linux_mips.go index f5f73895ccc..1ef8eebe4fd 100644 --- a/src/syscall/zsyscall_linux_mips.go +++ b/src/syscall/zsyscall_linux_mips.go @@ -1180,7 +1180,7 @@ func Pause() (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -1197,7 +1197,7 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) diff --git a/src/syscall/zsyscall_linux_mips64.go b/src/syscall/zsyscall_linux_mips64.go index 32f3c32b9b3..1ed877ce7ea 100644 --- a/src/syscall/zsyscall_linux_mips64.go +++ b/src/syscall/zsyscall_linux_mips64.go @@ -1211,7 +1211,7 @@ func Pause() (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -1228,7 +1228,7 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) diff --git a/src/syscall/zsyscall_linux_mips64le.go b/src/syscall/zsyscall_linux_mips64le.go index 62dcff45a1f..3d7cc9e3733 100644 --- a/src/syscall/zsyscall_linux_mips64le.go +++ b/src/syscall/zsyscall_linux_mips64le.go @@ -1211,7 +1211,7 @@ func Pause() (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -1228,7 +1228,7 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) diff --git a/src/syscall/zsyscall_linux_mipsle.go b/src/syscall/zsyscall_linux_mipsle.go index 4761246536a..59b49ddf747 100644 --- a/src/syscall/zsyscall_linux_mipsle.go +++ b/src/syscall/zsyscall_linux_mipsle.go @@ -1180,7 +1180,7 @@ func Pause() (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -1197,7 +1197,7 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) diff --git a/src/syscall/zsyscall_linux_ppc64.go b/src/syscall/zsyscall_linux_ppc64.go index c9b1365e74e..93632bd1cb4 100644 --- a/src/syscall/zsyscall_linux_ppc64.go +++ b/src/syscall/zsyscall_linux_ppc64.go @@ -1273,7 +1273,7 @@ func Pause() (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -1290,7 +1290,7 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) diff --git a/src/syscall/zsyscall_linux_ppc64le.go b/src/syscall/zsyscall_linux_ppc64le.go index 0807390894f..fc8f6b7bcf9 100644 --- a/src/syscall/zsyscall_linux_ppc64le.go +++ b/src/syscall/zsyscall_linux_ppc64le.go @@ -1273,7 +1273,7 @@ func Pause() (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -1290,7 +1290,7 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) diff --git a/src/syscall/zsyscall_linux_riscv64.go b/src/syscall/zsyscall_linux_riscv64.go index 1661d042214..0efa70715d6 100644 --- a/src/syscall/zsyscall_linux_riscv64.go +++ b/src/syscall/zsyscall_linux_riscv64.go @@ -1196,7 +1196,7 @@ func Listen(s int, n int) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -1213,7 +1213,7 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) diff --git a/src/syscall/zsyscall_linux_s390x.go b/src/syscall/zsyscall_linux_s390x.go index 2ab78c71bfe..568bb430a64 100644 --- a/src/syscall/zsyscall_linux_s390x.go +++ b/src/syscall/zsyscall_linux_s390x.go @@ -1243,7 +1243,7 @@ func Pause() (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -1260,7 +1260,7 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) diff --git a/src/syscall/zsyscall_netbsd_386.go b/src/syscall/zsyscall_netbsd_386.go index 408318181af..9b928592060 100644 --- a/src/syscall/zsyscall_netbsd_386.go +++ b/src/syscall/zsyscall_netbsd_386.go @@ -816,7 +816,7 @@ func Pathconf(path string, name int) (val int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -833,7 +833,7 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) diff --git a/src/syscall/zsyscall_netbsd_amd64.go b/src/syscall/zsyscall_netbsd_amd64.go index 2039cf6d0ea..ac34c00b5a2 100644 --- a/src/syscall/zsyscall_netbsd_amd64.go +++ b/src/syscall/zsyscall_netbsd_amd64.go @@ -816,7 +816,7 @@ func Pathconf(path string, name int) (val int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -833,7 +833,7 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) diff --git a/src/syscall/zsyscall_netbsd_arm.go b/src/syscall/zsyscall_netbsd_arm.go index 3c287ea223d..2be5e7baa4d 100644 --- a/src/syscall/zsyscall_netbsd_arm.go +++ b/src/syscall/zsyscall_netbsd_arm.go @@ -816,7 +816,7 @@ func Pathconf(path string, name int) (val int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -833,7 +833,7 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) diff --git a/src/syscall/zsyscall_netbsd_arm64.go b/src/syscall/zsyscall_netbsd_arm64.go index 1d40db9e6b6..02a652bbbb2 100644 --- a/src/syscall/zsyscall_netbsd_arm64.go +++ b/src/syscall/zsyscall_netbsd_arm64.go @@ -816,7 +816,7 @@ func Pathconf(path string, name int) (val int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -833,7 +833,7 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) diff --git a/src/syscall/zsyscall_openbsd_386.go b/src/syscall/zsyscall_openbsd_386.go index 2dcc4b2739d..f7986d5ea5c 100644 --- a/src/syscall/zsyscall_openbsd_386.go +++ b/src/syscall/zsyscall_openbsd_386.go @@ -1105,7 +1105,7 @@ func libc_pathconf_trampoline() // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -1126,7 +1126,7 @@ func libc_pread_trampoline() // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) diff --git a/src/syscall/zsyscall_openbsd_amd64.go b/src/syscall/zsyscall_openbsd_amd64.go index 8d4cb9c1e1c..605443d8904 100644 --- a/src/syscall/zsyscall_openbsd_amd64.go +++ b/src/syscall/zsyscall_openbsd_amd64.go @@ -1105,7 +1105,7 @@ func libc_pathconf_trampoline() // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -1126,7 +1126,7 @@ func libc_pread_trampoline() // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) diff --git a/src/syscall/zsyscall_openbsd_arm.go b/src/syscall/zsyscall_openbsd_arm.go index d45bc02fbd3..0f2312fbc40 100644 --- a/src/syscall/zsyscall_openbsd_arm.go +++ b/src/syscall/zsyscall_openbsd_arm.go @@ -1105,7 +1105,7 @@ func libc_pathconf_trampoline() // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -1126,7 +1126,7 @@ func libc_pread_trampoline() // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) diff --git a/src/syscall/zsyscall_openbsd_arm64.go b/src/syscall/zsyscall_openbsd_arm64.go index e060b092fe3..1367e2aba9e 100644 --- a/src/syscall/zsyscall_openbsd_arm64.go +++ b/src/syscall/zsyscall_openbsd_arm64.go @@ -1105,7 +1105,7 @@ func libc_pathconf_trampoline() // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -1126,7 +1126,7 @@ func libc_pread_trampoline() // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) diff --git a/src/syscall/zsyscall_openbsd_mips64.go b/src/syscall/zsyscall_openbsd_mips64.go index 51904b5e29d..2cf84653191 100644 --- a/src/syscall/zsyscall_openbsd_mips64.go +++ b/src/syscall/zsyscall_openbsd_mips64.go @@ -810,7 +810,7 @@ func Pathconf(path string, name int) (val int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -827,7 +827,7 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) diff --git a/src/syscall/zsyscall_solaris_amd64.go b/src/syscall/zsyscall_solaris_amd64.go index 7b012bf9bb8..5bb50caaae8 100644 --- a/src/syscall/zsyscall_solaris_amd64.go +++ b/src/syscall/zsyscall_solaris_amd64.go @@ -48,8 +48,8 @@ import "unsafe" //go:cgo_import_dynamic libc_Nanosleep nanosleep "libc.so" //go:cgo_import_dynamic libc_Open open "libc.so" //go:cgo_import_dynamic libc_Pathconf pathconf "libc.so" -//go:cgo_import_dynamic libc_Pread pread "libc.so" -//go:cgo_import_dynamic libc_Pwrite pwrite "libc.so" +//go:cgo_import_dynamic libc_pread pread "libc.so" +//go:cgo_import_dynamic libc_pwrite pwrite "libc.so" //go:cgo_import_dynamic libc_read read "libc.so" //go:cgo_import_dynamic libc_Readlink readlink "libc.so" //go:cgo_import_dynamic libc_Rename rename "libc.so" @@ -134,8 +134,8 @@ import "unsafe" //go:linkname libc_Nanosleep libc_Nanosleep //go:linkname libc_Open libc_Open //go:linkname libc_Pathconf libc_Pathconf -//go:linkname libc_Pread libc_Pread -//go:linkname libc_Pwrite libc_Pwrite +//go:linkname libc_pread libc_pread +//go:linkname libc_pwrite libc_pwrite //go:linkname libc_read libc_read //go:linkname libc_Readlink libc_Readlink //go:linkname libc_Rename libc_Rename @@ -223,8 +223,8 @@ var ( libc_Nanosleep, libc_Open, libc_Pathconf, - libc_Pread, - libc_Pwrite, + libc_pread, + libc_pwrite, libc_read, libc_Readlink, libc_Rename, @@ -753,12 +753,12 @@ func Pathconf(path string, name int) (val int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 *byte if len(p) > 0 { _p0 = &p[0] } - r0, _, e1 := sysvicall6(uintptr(unsafe.Pointer(&libc_Pread)), 4, uintptr(fd), uintptr(unsafe.Pointer(_p0)), uintptr(len(p)), uintptr(offset), 0, 0) + r0, _, e1 := sysvicall6(uintptr(unsafe.Pointer(&libc_pread)), 4, uintptr(fd), uintptr(unsafe.Pointer(_p0)), uintptr(len(p)), uintptr(offset), 0, 0) n = int(r0) if e1 != 0 { err = errnoErr(e1) @@ -768,12 +768,12 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 *byte if len(p) > 0 { _p0 = &p[0] } - r0, _, e1 := sysvicall6(uintptr(unsafe.Pointer(&libc_Pwrite)), 4, uintptr(fd), uintptr(unsafe.Pointer(_p0)), uintptr(len(p)), uintptr(offset), 0, 0) + r0, _, e1 := sysvicall6(uintptr(unsafe.Pointer(&libc_pwrite)), 4, uintptr(fd), uintptr(unsafe.Pointer(_p0)), uintptr(len(p)), uintptr(offset), 0, 0) n = int(r0) if e1 != 0 { err = errnoErr(e1) From 3c2e73c8c3323887e6b95f72adb6242b8727ba8b Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Fri, 11 Mar 2022 08:20:55 +0100 Subject: [PATCH 084/276] runtime/pprof: use syscall.RUSAGE_SELF Change-Id: Idc37429de5a48e708eda868ca7fa26b28620bac0 Reviewed-on: https://go-review.googlesource.com/c/go/+/391854 Trust: Tobias Klauser Run-TryBot: Tobias Klauser TryBot-Result: Gopher Robot Reviewed-by: Ian Lance Taylor --- src/runtime/pprof/pprof_rusage.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime/pprof/pprof_rusage.go b/src/runtime/pprof/pprof_rusage.go index 7df81eca23c..984a32e79d4 100644 --- a/src/runtime/pprof/pprof_rusage.go +++ b/src/runtime/pprof/pprof_rusage.go @@ -28,6 +28,6 @@ func addMaxRSS(w io.Writer) { } var rusage syscall.Rusage - syscall.Getrusage(0, &rusage) + syscall.Getrusage(syscall.RUSAGE_SELF, &rusage) fmt.Fprintf(w, "# MaxRSS = %d\n", uintptr(rusage.Maxrss)*rssToBytes) } From ab0f7611d739fe10d0265dbc6bdc17684423bfc8 Mon Sep 17 00:00:00 2001 From: Uzondu Enudeme Date: Thu, 10 Mar 2022 00:08:52 +0100 Subject: [PATCH 085/276] net/url: add OmitHost bool to url.URL Previously, myscheme:/path and myscheme:///path were treated as the same URL although materially different. The distinction made clear by RFC 3986 sec. 5.3 where a different recomposition behavior is expected when a URI reference has an undefined host(authority) as in myscheme:/path vs. one with an empty host(authority) as in myscheme:///path. This change fixes the Parse/String roundtrip limitation for URLs with an undefined host and a single slash. Fixes #46059 Change-Id: I1b8d6042135513616374ff8c8dfb1cdb640f8efe Reviewed-on: https://go-review.googlesource.com/c/go/+/391294 Reviewed-by: Ian Lance Taylor Reviewed-by: Emmanuel Odeke Run-TryBot: Emmanuel Odeke TryBot-Result: Gopher Robot --- src/net/url/url.go | 28 +++++++++++++++++++--------- src/net/url/url_test.go | 13 +++++++------ 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/net/url/url.go b/src/net/url/url.go index 1571bf728ba..ecfd1d9e94b 100644 --- a/src/net/url/url.go +++ b/src/net/url/url.go @@ -363,6 +363,7 @@ type URL struct { Host string // host or host:port Path string // path (relative paths may omit leading slash) RawPath string // encoded path hint (see EscapedPath method) + OmitHost bool // do not emit empty host (authority) ForceQuery bool // append a query ('?') even if RawQuery is empty RawQuery string // encoded query values, without '?' Fragment string // fragment for references, without '#' @@ -556,7 +557,12 @@ func parse(rawURL string, viaRequest bool) (*URL, error) { if err != nil { return nil, err } + } else if url.Scheme != "" && strings.HasPrefix(rest, "/") { + // OmitHost is set to true when rawURL has an empty host (authority). + // See golang.org/issue/46059. + url.OmitHost = true } + // Set Path and, optionally, RawPath. // RawPath is a hint of the encoding of Path. We don't want to set it if // the default escaping of Path is equivalent, to help make sure that people @@ -806,15 +812,19 @@ func (u *URL) String() string { buf.WriteString(u.Opaque) } else { if u.Scheme != "" || u.Host != "" || u.User != nil { - if u.Host != "" || u.Path != "" || u.User != nil { - buf.WriteString("//") - } - if ui := u.User; ui != nil { - buf.WriteString(ui.String()) - buf.WriteByte('@') - } - if h := u.Host; h != "" { - buf.WriteString(escape(h, encodeHost)) + if u.OmitHost && u.Host == "" && u.User == nil { + // omit empty host + } else { + if u.Host != "" || u.Path != "" || u.User != nil { + buf.WriteString("//") + } + if ui := u.User; ui != nil { + buf.WriteString(ui.String()) + buf.WriteByte('@') + } + if h := u.Host; h != "" { + buf.WriteString(escape(h, encodeHost)) + } } } path := u.EscapedPath() diff --git a/src/net/url/url_test.go b/src/net/url/url_test.go index 84dba45c3c1..18aa5f8a1c5 100644 --- a/src/net/url/url_test.go +++ b/src/net/url/url_test.go @@ -163,14 +163,15 @@ var urltests = []URLTest{ }, "http:%2f%2fwww.google.com/?q=go+language", }, - // non-authority with path + // non-authority with path; see golang.org/issue/46059 { "mailto:/webmaster@golang.org", &URL{ - Scheme: "mailto", - Path: "/webmaster@golang.org", + Scheme: "mailto", + Path: "/webmaster@golang.org", + OmitHost: true, }, - "mailto:///webmaster@golang.org", // unfortunate compromise + "", }, // non-authority { @@ -625,8 +626,8 @@ func ufmt(u *URL) string { pass = p } } - return fmt.Sprintf("opaque=%q, scheme=%q, user=%#v, pass=%#v, host=%q, path=%q, rawpath=%q, rawq=%q, frag=%q, rawfrag=%q, forcequery=%v", - u.Opaque, u.Scheme, user, pass, u.Host, u.Path, u.RawPath, u.RawQuery, u.Fragment, u.RawFragment, u.ForceQuery) + return fmt.Sprintf("opaque=%q, scheme=%q, user=%#v, pass=%#v, host=%q, path=%q, rawpath=%q, rawq=%q, frag=%q, rawfrag=%q, forcequery=%v, omithost=%t", + u.Opaque, u.Scheme, user, pass, u.Host, u.Path, u.RawPath, u.RawQuery, u.Fragment, u.RawFragment, u.ForceQuery, u.OmitHost) } func BenchmarkString(b *testing.B) { From 7900576bac4630bbeec7f4f1aa4b1cb0d51bd8a1 Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Sun, 13 Mar 2022 22:38:15 +0700 Subject: [PATCH 086/276] cmd/compile: remove unified IR stmtTypeDeclHack After CL 385998, unified IR quirks mode was gone, it's time to remove stmtTypeDeclHack, too. Change-Id: Id73dd1d6c11b91c0c6c6cbe85f1b06977a9876d2 Reviewed-on: https://go-review.googlesource.com/c/go/+/392214 Trust: Cuong Manh Le Run-TryBot: Cuong Manh Le TryBot-Result: Gopher Robot Reviewed-by: Matthew Dempsky --- src/cmd/compile/internal/noder/codes.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/cmd/compile/internal/noder/codes.go b/src/cmd/compile/internal/noder/codes.go index bc0831dd788..8f54a07ca46 100644 --- a/src/cmd/compile/internal/noder/codes.go +++ b/src/cmd/compile/internal/noder/codes.go @@ -29,9 +29,6 @@ const ( stmtFor stmtSwitch stmtSelect - - // TODO(mdempsky): Remove after we don't care about toolstash -cmp. - stmtTypeDeclHack ) type codeExpr int From 471d319fb2497aa7239943eb1a6d5cfbad503a2a Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Thu, 10 Mar 2022 15:28:10 -0500 Subject: [PATCH 087/276] debug/buildinfo: use testenv.GoToolPath in tests instead of resolving "go" from $PATH MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updates #37475. Change-Id: I8c3237438da3e9521ce3be26a0b5d5ca36944b17 Reviewed-on: https://go-review.googlesource.com/c/go/+/391803 Trust: Bryan Mills Run-TryBot: Bryan Mills TryBot-Result: Gopher Robot Reviewed-by: Daniel Martí Trust: Daniel Martí --- src/debug/buildinfo/buildinfo_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/debug/buildinfo/buildinfo_test.go b/src/debug/buildinfo/buildinfo_test.go index ac71626fda1..0affc832e71 100644 --- a/src/debug/buildinfo/buildinfo_test.go +++ b/src/debug/buildinfo/buildinfo_test.go @@ -66,7 +66,7 @@ func TestReadFile(t *testing.T) { t.Fatal(err) } outPath := filepath.Join(dir, path.Base(t.Name())) - cmd := exec.Command("go", "build", "-o="+outPath) + cmd := exec.Command(testenv.GoToolPath(t), "build", "-o="+outPath) cmd.Dir = dir cmd.Env = append(os.Environ(), "GO111MODULE=on", "GOOS="+goos, "GOARCH="+goarch) stderr := &bytes.Buffer{} @@ -89,7 +89,7 @@ func TestReadFile(t *testing.T) { t.Fatal(err) } outPath := filepath.Join(gopathDir, path.Base(t.Name())) - cmd := exec.Command("go", "build", "-o="+outPath) + cmd := exec.Command(testenv.GoToolPath(t), "build", "-o="+outPath) cmd.Dir = pkgDir cmd.Env = append(os.Environ(), "GO111MODULE=off", "GOPATH="+gopathDir, "GOOS="+goos, "GOARCH="+goarch) stderr := &bytes.Buffer{} From d99ff0382116bb472b9f92ddf23cb22bf145bbcd Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Wed, 9 Mar 2022 17:17:40 -0500 Subject: [PATCH 088/276] go/build: set PWD for go subcommands MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since these commands already include an explicit Env field, they will not be fixed automatically by proposal #50599. Change-Id: Ia8157a71cf0cfe208bdc0da9aef54be3d26c795f Reviewed-on: https://go-review.googlesource.com/c/go/+/391804 Trust: Bryan Mills Run-TryBot: Bryan Mills TryBot-Result: Gopher Robot Reviewed-by: Daniel Martí Trust: Daniel Martí --- src/go/build/build.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/go/build/build.go b/src/go/build/build.go index baf76e6b7ff..c1d044e55a8 100644 --- a/src/go/build/build.go +++ b/src/go/build/build.go @@ -1186,6 +1186,13 @@ func (ctxt *Context) importGo(p *Package, path, srcDir string, mode ImportMode) "GOPATH="+ctxt.GOPATH, "CGO_ENABLED="+cgo, ) + if cmd.Dir != "" { + // If possible, set PWD: if an error occurs and PWD includes a symlink, we + // want the error to refer to Dir, not some other name for it. + if abs, err := filepath.Abs(cmd.Dir); err == nil { + cmd.Env = append(cmd.Env, "PWD="+abs) + } + } if err := cmd.Run(); err != nil { return fmt.Errorf("go/build: go list %s: %v\n%s\n", path, err, stderr.String()) From 676858f3d4786054e1b27b999b5e73190f25288c Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Thu, 10 Mar 2022 15:09:17 -0500 Subject: [PATCH 089/276] cmd/go: use testGOROOT in TestListTemplateContextFunction MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This test uses testgo to run 'go list', so it should use the correct GOROOT for testgo. (This may be particularly relevant when the test binary itself is build with -trimpath, in which case runtime.GOROOT() is not valid.) Updates #51483 Change-Id: I79b310f88e3a200122d6289073df1385e3e97cca Reviewed-on: https://go-review.googlesource.com/c/go/+/391801 Trust: Bryan Mills Run-TryBot: Bryan Mills TryBot-Result: Gopher Robot Reviewed-by: Daniel Martí Trust: Daniel Martí --- src/cmd/go/go_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cmd/go/go_test.go b/src/cmd/go/go_test.go index 01356f9dd00..fa0d44dae60 100644 --- a/src/cmd/go/go_test.go +++ b/src/cmd/go/go_test.go @@ -1631,7 +1631,7 @@ func TestListTemplateContextFunction(t *testing.T) { }{ {"GOARCH", runtime.GOARCH}, {"GOOS", runtime.GOOS}, - {"GOROOT", filepath.Clean(runtime.GOROOT())}, + {"GOROOT", testGOROOT}, {"GOPATH", os.Getenv("GOPATH")}, {"CgoEnabled", ""}, {"UseAllFiles", ""}, From 8419ec295cd86a3d26cd360ef5f919a51fe33ebb Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Sun, 13 Mar 2022 00:04:46 +0700 Subject: [PATCH 090/276] cmd/compile: fix wrong dict param when getting dict type CL 338129 added getDictionaryType to get the dictionary type from the specified dict param, but still using the one in info.dictParam, which is wrong. Fixes #51413 Change-Id: Ie13460c1e5751c4c5fc44479a44f6eed8b3b06e4 Reviewed-on: https://go-review.googlesource.com/c/go/+/391994 Trust: Cuong Manh Le Run-TryBot: Cuong Manh Le TryBot-Result: Gopher Robot Reviewed-by: Matthew Dempsky Trust: Matthew Dempsky Reviewed-by: Keith Randall --- src/cmd/compile/internal/noder/stencil.go | 2 +- test/typeparam/mdempsky/13.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cmd/compile/internal/noder/stencil.go b/src/cmd/compile/internal/noder/stencil.go index cd586cab784..c78a169d310 100644 --- a/src/cmd/compile/internal/noder/stencil.go +++ b/src/cmd/compile/internal/noder/stencil.go @@ -898,7 +898,7 @@ func getDictionaryType(info *instInfo, dictParam *ir.Name, pos src.XPos, i int) base.Fatalf(fmt.Sprintf("bad dict index %d", i)) } - r := getDictionaryEntry(pos, info.dictParam, i, info.dictInfo.startSubDict) + r := getDictionaryEntry(pos, dictParam, i, info.dictInfo.startSubDict) // change type of retrieved dictionary entry to *byte, which is the // standard typing of a *runtime._type in the compiler typed(types.Types[types.TUINT8].PtrTo(), r) diff --git a/test/typeparam/mdempsky/13.go b/test/typeparam/mdempsky/13.go index bf37a64177a..8e11352b514 100644 --- a/test/typeparam/mdempsky/13.go +++ b/test/typeparam/mdempsky/13.go @@ -1,4 +1,4 @@ -// run -gcflags="" +// run // Copyright 2021 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style From 41fe746857104d8775a23dc8f69494240d683e54 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Mon, 14 Mar 2022 10:45:16 -0700 Subject: [PATCH 091/276] go/types, types2: use correct underlying type in union set computation Fixes #51658. Change-Id: Ibf415d7e12849b8f50b58d74713613d4e65bc347 Reviewed-on: https://go-review.googlesource.com/c/go/+/392575 Trust: Robert Griesemer Run-TryBot: Robert Griesemer Reviewed-by: Robert Findley --- .../types2/testdata/fixedbugs/issue51658.go2 | 39 +++++++++++++++++++ src/cmd/compile/internal/types2/typeset.go | 2 +- .../types/testdata/fixedbugs/issue51658.go2 | 39 +++++++++++++++++++ src/go/types/typeset.go | 2 +- 4 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 src/cmd/compile/internal/types2/testdata/fixedbugs/issue51658.go2 create mode 100644 src/go/types/testdata/fixedbugs/issue51658.go2 diff --git a/src/cmd/compile/internal/types2/testdata/fixedbugs/issue51658.go2 b/src/cmd/compile/internal/types2/testdata/fixedbugs/issue51658.go2 new file mode 100644 index 00000000000..c437c92d291 --- /dev/null +++ b/src/cmd/compile/internal/types2/testdata/fixedbugs/issue51658.go2 @@ -0,0 +1,39 @@ +// Copyright 2022 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 p + +type F { // ERROR syntax error + float64 +} // ERROR syntax error + +func _[T F | int](x T) { + _ = x == 0 // don't crash when recording type of 0 +} + +// test case from issue + +type FloatType { // ERROR syntax error + float32 | float64 +} // ERROR syntax error + +type IntegerType interface { + int8 | int16 | int32 | int64 | int | + uint8 | uint16 | uint32 | uint64 | uint +} + +type ComplexType interface { + complex64 | complex128 +} + +type Number interface { + FloatType | IntegerType | ComplexType +} + +func GetDefaultNumber[T Number](value, defaultValue T) T { + if value == 0 { + return defaultValue + } + return value +} diff --git a/src/cmd/compile/internal/types2/typeset.go b/src/cmd/compile/internal/types2/typeset.go index 8df89494352..646b436685c 100644 --- a/src/cmd/compile/internal/types2/typeset.go +++ b/src/cmd/compile/internal/types2/typeset.go @@ -406,7 +406,7 @@ func computeUnionTypeSet(check *Checker, unionSets map[*Union]*_TypeSet, pos syn // For now we don't permit type parameters as constraints. assert(!isTypeParam(t.typ)) terms = computeInterfaceTypeSet(check, pos, ui).terms - } else if t.typ == Typ[Invalid] { + } else if u == Typ[Invalid] { continue } else { if t.tilde && !Identical(t.typ, u) { diff --git a/src/go/types/testdata/fixedbugs/issue51658.go2 b/src/go/types/testdata/fixedbugs/issue51658.go2 new file mode 100644 index 00000000000..04ce6a97600 --- /dev/null +++ b/src/go/types/testdata/fixedbugs/issue51658.go2 @@ -0,0 +1,39 @@ +// Copyright 2022 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 p + +type F { // ERROR expected type + float64 +} // ERROR expected declaration + +func _[T F | int](x T) { + _ = x == 0 // don't crash when recording type of 0 +} + +// test case from issue + +type FloatType { // ERROR expected type + float32 | float64 +} // ERROR expected declaration + +type IntegerType interface { + int8 | int16 | int32 | int64 | int | + uint8 | uint16 | uint32 | uint64 | uint +} + +type ComplexType interface { + complex64 | complex128 +} + +type Number interface { + FloatType | IntegerType | ComplexType +} + +func GetDefaultNumber[T Number](value, defaultValue T) T { + if value == 0 { + return defaultValue + } + return value +} diff --git a/src/go/types/typeset.go b/src/go/types/typeset.go index 6603383ea3c..b33141ec327 100644 --- a/src/go/types/typeset.go +++ b/src/go/types/typeset.go @@ -406,7 +406,7 @@ func computeUnionTypeSet(check *Checker, unionSets map[*Union]*_TypeSet, pos tok // For now we don't permit type parameters as constraints. assert(!isTypeParam(t.typ)) terms = computeInterfaceTypeSet(check, pos, ui).terms - } else if t.typ == Typ[Invalid] { + } else if u == Typ[Invalid] { continue } else { if t.tilde && !Identical(t.typ, u) { From 5ccd8e5133a43e574be8d66aae3a230c39b4b67a Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Thu, 10 Mar 2022 15:26:22 -0800 Subject: [PATCH 092/276] internal/cpu: disallow disabling options that are required for microarch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit e.g., if GOAMD64=v3, don't allow GODEBUG=cpu.XXX=off for XXX which are required for v3. Change-Id: Ib58a4c8b13c5464ba476448ba44bbb261218787c Reviewed-on: https://go-review.googlesource.com/c/go/+/391694 Trust: Keith Randall Run-TryBot: Keith Randall TryBot-Result: Gopher Robot Reviewed-by: Martin Möhrmann --- src/internal/cpu/cpu_x86.go | 34 ++++++++++++++++++++++++---------- src/internal/cpu/cpu_x86.s | 17 +++++++++++++++++ 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/src/internal/cpu/cpu_x86.go b/src/internal/cpu/cpu_x86.go index 81d5ceed61a..6fd979a7470 100644 --- a/src/internal/cpu/cpu_x86.go +++ b/src/internal/cpu/cpu_x86.go @@ -14,6 +14,9 @@ func cpuid(eaxArg, ecxArg uint32) (eax, ebx, ecx, edx uint32) // xgetbv with ecx = 0 is implemented in cpu_x86.s. func xgetbv() (eax, edx uint32) +// getGOAMD64level is implemented in cpu_x86.s. Returns number in [1,4]. +func getGOAMD64level() int32 + const ( // edx bits cpuid_SSE2 = 1 << 26 @@ -47,19 +50,30 @@ func doinit() { options = []option{ {Name: "adx", Feature: &X86.HasADX}, {Name: "aes", Feature: &X86.HasAES}, - {Name: "avx", Feature: &X86.HasAVX}, - {Name: "avx2", Feature: &X86.HasAVX2}, - {Name: "bmi1", Feature: &X86.HasBMI1}, - {Name: "bmi2", Feature: &X86.HasBMI2}, {Name: "erms", Feature: &X86.HasERMS}, - {Name: "fma", Feature: &X86.HasFMA}, {Name: "pclmulqdq", Feature: &X86.HasPCLMULQDQ}, - {Name: "popcnt", Feature: &X86.HasPOPCNT}, {Name: "rdtscp", Feature: &X86.HasRDTSCP}, - {Name: "sse3", Feature: &X86.HasSSE3}, - {Name: "sse41", Feature: &X86.HasSSE41}, - {Name: "sse42", Feature: &X86.HasSSE42}, - {Name: "ssse3", Feature: &X86.HasSSSE3}, + } + level := getGOAMD64level() + if level < 2 { + // These options are required at level 2. At lower levels + // they can be turned off. + options = append(options, + option{Name: "popcnt", Feature: &X86.HasPOPCNT}, + option{Name: "sse3", Feature: &X86.HasSSE3}, + option{Name: "sse41", Feature: &X86.HasSSE41}, + option{Name: "sse42", Feature: &X86.HasSSE42}, + option{Name: "ssse3", Feature: &X86.HasSSSE3}) + } + if level < 3 { + // These options are required at level 3. At lower levels + // they can be turned off. + options = append(options, + option{Name: "avx", Feature: &X86.HasAVX}, + option{Name: "avx2", Feature: &X86.HasAVX2}, + option{Name: "bmi1", Feature: &X86.HasBMI1}, + option{Name: "bmi2", Feature: &X86.HasBMI2}, + option{Name: "fma", Feature: &X86.HasFMA}) } maxID, _, _, _ := cpuid(0, 0) diff --git a/src/internal/cpu/cpu_x86.s b/src/internal/cpu/cpu_x86.s index edef21905ca..2ee8eca248a 100644 --- a/src/internal/cpu/cpu_x86.s +++ b/src/internal/cpu/cpu_x86.s @@ -24,3 +24,20 @@ TEXT ·xgetbv(SB),NOSPLIT,$0-8 MOVL AX, eax+0(FP) MOVL DX, edx+4(FP) RET + +// func getGOAMD64level() int32 +TEXT ·getGOAMD64level(SB),NOSPLIT,$0-4 +#ifdef GOAMD64_v4 + MOVL $4, ret+0(FP) +#else +#ifdef GOAMD64_v3 + MOVL $3, ret+0(FP) +#else +#ifdef GOAMD64_v2 + MOVL $2, ret+0(FP) +#else + MOVL $1, ret+0(FP) +#endif +#endif +#endif + RET From b7041c7ad1c9d42078cfc376320e5b307e617a80 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Mon, 14 Mar 2022 11:03:23 -0400 Subject: [PATCH 093/276] cmd/api: require proposal # for new API features Having the proposal numbers recorded in the API files should help significantly when it comes time to audit the new API additions at the end of each release cycle. Change-Id: Id18e8cbdf892228a10ac17e4e21c7e17de5d4ff7 Reviewed-on: https://go-review.googlesource.com/c/go/+/392414 Trust: Russ Cox Run-TryBot: Russ Cox Reviewed-by: Dmitri Shuralyov TryBot-Result: Gopher Robot --- api/README | 16 +++++++++-- api/next.txt | 9 ------ api/next/45754.txt | 2 ++ api/next/46059.txt | 2 ++ api/next/47005.txt | 2 ++ api/next/50601.txt | 5 ++++ src/cmd/api/goapi.go | 58 +++++++++++++++++++++++++++----------- src/cmd/api/run.go | 66 +++++++++++++++++++++++++++----------------- 8 files changed, 107 insertions(+), 53 deletions(-) delete mode 100644 api/next.txt create mode 100644 api/next/45754.txt create mode 100644 api/next/46059.txt create mode 100644 api/next/47005.txt create mode 100644 api/next/50601.txt diff --git a/api/README b/api/README index ce24efcd312..1e52f7a843b 100644 --- a/api/README +++ b/api/README @@ -8,6 +8,16 @@ shipped. Each file adds new lines but does not remove any. except.txt lists features that may disappear without breaking true compatibility. -next.txt is the only file intended to be mutated. It's a list of -features that may be added to the next version. It only affects -warning output from the go api tool. +Starting with go1.19.txt, each API feature line must end in "#nnnnn" +giving the GitHub issue number of the proposal issue that accepted +the new API. This helps with our end-of-cycle audit of new APIs. +The same requirement applies to next/* (described below), which will +become a go1.XX.txt for XX >= 19. + +The next/ directory contains the only files intended to be mutated. +Each file in that directory contains a list of features that may be added +to the next release of Go. The files in this directory only affect the +warning output from the go api tool. Each file should be named +nnnnn.txt, after the issue number for the accepted proposal. +(The #nnnnn suffix must also appear at the end of each line in the file; +that will be preserved when next/*.txt is concatenated into go1.XX.txt.) diff --git a/api/next.txt b/api/next.txt deleted file mode 100644 index a0f2bed8d1a..00000000000 --- a/api/next.txt +++ /dev/null @@ -1,9 +0,0 @@ -pkg encoding/binary, type AppendByteOrder interface { AppendUint16, AppendUint32, AppendUint64, String } -pkg encoding/binary, type AppendByteOrder interface, AppendUint16([]uint8, uint16) []uint8 -pkg encoding/binary, type AppendByteOrder interface, AppendUint32([]uint8, uint32) []uint8 -pkg encoding/binary, type AppendByteOrder interface, AppendUint64([]uint8, uint64) []uint8 -pkg encoding/binary, type AppendByteOrder interface, String() string -pkg flag, func TextVar(encoding.TextUnmarshaler, string, encoding.TextMarshaler, string) -pkg flag, method (*FlagSet) TextVar(encoding.TextUnmarshaler, string, encoding.TextMarshaler, string) -pkg net/url, func JoinPath(string, ...string) (string, error) -pkg net/url, method (*URL) JoinPath(...string) *URL diff --git a/api/next/45754.txt b/api/next/45754.txt new file mode 100644 index 00000000000..e980342c04e --- /dev/null +++ b/api/next/45754.txt @@ -0,0 +1,2 @@ +pkg flag, func TextVar(encoding.TextUnmarshaler, string, encoding.TextMarshaler, string) #45754 +pkg flag, method (*FlagSet) TextVar(encoding.TextUnmarshaler, string, encoding.TextMarshaler, string) #45754 diff --git a/api/next/46059.txt b/api/next/46059.txt new file mode 100644 index 00000000000..3cc44966a2f --- /dev/null +++ b/api/next/46059.txt @@ -0,0 +1,2 @@ +pkg net/url, type URL struct, OmitHost bool #46059 + diff --git a/api/next/47005.txt b/api/next/47005.txt new file mode 100644 index 00000000000..0d7695e45c4 --- /dev/null +++ b/api/next/47005.txt @@ -0,0 +1,2 @@ +pkg net/url, func JoinPath(string, ...string) (string, error) #47005 +pkg net/url, method (*URL) JoinPath(...string) *URL #47005 diff --git a/api/next/50601.txt b/api/next/50601.txt new file mode 100644 index 00000000000..261dce375da --- /dev/null +++ b/api/next/50601.txt @@ -0,0 +1,5 @@ +pkg encoding/binary, type AppendByteOrder interface { AppendUint16, AppendUint32, AppendUint64, String } #50601 +pkg encoding/binary, type AppendByteOrder interface, AppendUint16([]uint8, uint16) []uint8 #50601 +pkg encoding/binary, type AppendByteOrder interface, AppendUint32([]uint8, uint32) []uint8 #50601 +pkg encoding/binary, type AppendByteOrder interface, AppendUint64([]uint8, uint64) []uint8 #50601 +pkg encoding/binary, type AppendByteOrder interface, String() string #50601 diff --git a/src/cmd/api/goapi.go b/src/cmd/api/goapi.go index 5ae059e4cec..2a0e1095750 100644 --- a/src/cmd/api/goapi.go +++ b/src/cmd/api/goapi.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// Binary api computes the exported API of a set of Go packages. +// Api computes the exported API of a set of Go packages. package main import ( @@ -24,6 +24,7 @@ import ( "regexp" "runtime" "sort" + "strconv" "strings" "sync" ) @@ -42,12 +43,13 @@ func goCmd() string { // Flags var ( - checkFile = flag.String("c", "", "optional comma-separated filename(s) to check API against") - allowNew = flag.Bool("allow_new", true, "allow API additions") - exceptFile = flag.String("except", "", "optional filename of packages that are allowed to change without triggering a failure in the tool") - nextFile = flag.String("next", "", "optional filename of tentative upcoming API features for the next release. This file can be lazily maintained. It only affects the delta warnings from the -c file printed on success.") - verbose = flag.Bool("v", false, "verbose debugging") - forceCtx = flag.String("contexts", "", "optional comma-separated list of -[-cgo] to override default contexts.") + checkFiles = flag.String("c", "", "optional comma-separated filename(s) to check API against") + requireApproval = flag.String("approval", "", "require approvals in comma-separated list of `files`") + allowNew = flag.Bool("allow_new", true, "allow API additions") + exceptFile = flag.String("except", "", "optional filename of packages that are allowed to change without triggering a failure in the tool") + nextFiles = flag.String("next", "", "comma-separated list of `files` for upcoming API features for the next release. These files can be lazily maintained. They only affects the delta warnings from the -c file printed on success.") + verbose = flag.Bool("v", false, "verbose debugging") + forceCtx = flag.String("contexts", "", "optional comma-separated list of -[-cgo] to override default contexts.") ) // contexts are the default contexts which are scanned, unless @@ -126,9 +128,9 @@ func main() { flag.Parse() if !strings.Contains(runtime.Version(), "weekly") && !strings.Contains(runtime.Version(), "devel") { - if *nextFile != "" { - fmt.Printf("Go version is %q, ignoring -next %s\n", runtime.Version(), *nextFile) - *nextFile = "" + if *nextFiles != "" { + fmt.Printf("Go version is %q, ignoring -next %s\n", runtime.Version(), *nextFiles) + *nextFiles = "" } } @@ -201,7 +203,7 @@ func main() { bw := bufio.NewWriter(os.Stdout) defer bw.Flush() - if *checkFile == "" { + if *checkFiles == "" { sort.Strings(features) for _, f := range features { fmt.Fprintln(bw, f) @@ -210,10 +212,15 @@ func main() { } var required []string - for _, file := range strings.Split(*checkFile, ",") { + for _, file := range strings.Split(*checkFiles, ",") { required = append(required, fileFeatures(file)...) } - optional := fileFeatures(*nextFile) + var optional []string + if *nextFiles != "" { + for _, file := range strings.Split(*nextFiles, ",") { + optional = append(optional, fileFeatures(file)...) + } + } exception := fileFeatures(*exceptFile) fail = !compareAPI(bw, features, required, optional, exception, *allowNew) } @@ -340,6 +347,13 @@ func fileFeatures(filename string) []string { if filename == "" { return nil } + needApproval := false + for _, name := range strings.Split(*requireApproval, ",") { + if filename == name { + needApproval = true + break + } + } bs, err := os.ReadFile(filename) if err != nil { log.Fatalf("Error reading file %s: %v", filename, err) @@ -348,11 +362,23 @@ func fileFeatures(filename string) []string { s = aliasReplacer.Replace(s) lines := strings.Split(s, "\n") var nonblank []string - for _, line := range lines { + for i, line := range lines { line = strings.TrimSpace(line) - if line != "" && !strings.HasPrefix(line, "#") { - nonblank = append(nonblank, line) + if line == "" || strings.HasPrefix(line, "#") { + continue + } + if needApproval { + feature, approval, ok := strings.Cut(line, "#") + if !ok { + log.Fatalf("%s:%d: missing proposal approval\n", filename, i+1) + } + _, err := strconv.Atoi(approval) + if err != nil { + log.Fatalf("%s:%d: malformed proposal approval #%s\n", filename, i+1, approval) + } + line = strings.TrimSpace(feature) } + nonblank = append(nonblank, line) } return nonblank } diff --git a/src/cmd/api/run.go b/src/cmd/api/run.go index 1b94a1b883f..130166e7b92 100644 --- a/src/cmd/api/run.go +++ b/src/cmd/api/run.go @@ -18,6 +18,7 @@ import ( "os" "path/filepath" "runtime" + "strconv" "strings" ) @@ -41,51 +42,66 @@ func main() { if goroot == "" { log.Fatal("No $GOROOT set.") } - - apiDir := filepath.Join(goroot, "api") - out, err := exec.Command(goCmd(), "tool", "api", - "-c", findAPIDirFiles(apiDir), - allowNew(apiDir), - "-next", filepath.Join(apiDir, "next.txt"), - "-except", filepath.Join(apiDir, "except.txt")).CombinedOutput() - if err != nil { - log.Fatalf("Error running API checker: %v\n%s", err, out) + if err := os.Chdir(filepath.Join(goroot, "api")); err != nil { + log.Fatal(err) } - fmt.Print(string(out)) -} -// findAPIDirFiles returns a comma-separated list of Go API files -// (go1.txt, go1.1.txt, etc.) located in apiDir. -func findAPIDirFiles(apiDir string) string { - dir, err := os.Open(apiDir) + files, err := filepath.Glob("go1*.txt") if err != nil { log.Fatal(err) } - defer dir.Close() - fs, err := dir.Readdirnames(-1) + next, err := filepath.Glob(filepath.Join("next", "*.txt")) if err != nil { log.Fatal(err) } - var apiFiles []string - for _, fn := range fs { - if strings.HasPrefix(fn, "go1") { - apiFiles = append(apiFiles, filepath.Join(apiDir, fn)) + cmd := exec.Command(goCmd(), "tool", "api", + "-c", strings.Join(files, ","), + "-approval", strings.Join(append(approvalNeeded(files), next...), ","), + allowNew(), + "-next", strings.Join(next, ","), + "-except", "except.txt", + ) + fmt.Println(cmd.Args) + out, err := cmd.CombinedOutput() + if err != nil { + log.Fatalf("Error running API checker: %v\n%s", err, out) + } + fmt.Print(string(out)) +} + +func approvalNeeded(files []string) []string { + var out []string + for _, f := range files { + name := filepath.Base(f) + if name == "go1.txt" { + continue + } + minor := strings.TrimSuffix(strings.TrimPrefix(name, "go1."), ".txt") + n, err := strconv.Atoi(minor) + if err != nil { + log.Fatalf("unexpected api file: %v", f) + } + if n >= 19 { // approvals started being tracked in Go 1.19 + out = append(out, f) } } - return strings.Join(apiFiles, ",") + return out } // allowNew returns the -allow_new flag to use for the 'go tool api' invocation. -func allowNew(apiDir string) string { +func allowNew() string { + // Experiment for Go 1.19: always require api file updates. + return "-allow_new=false" + // Verify that the api/go1.n.txt for previous Go version exists. // It definitely should, otherwise it's a signal that the logic below may be outdated. - if _, err := os.Stat(filepath.Join(apiDir, fmt.Sprintf("go1.%d.txt", goversion.Version-1))); err != nil { + if _, err := os.Stat(fmt.Sprintf("go1.%d.txt", goversion.Version-1)); err != nil { log.Fatalln("Problem with api file for previous release:", err) } // See whether the api/go1.n.txt for this Go version has been created. // (As of April 2021, it gets created during the release of the first Beta.) - _, err := os.Stat(filepath.Join(apiDir, fmt.Sprintf("go1.%d.txt", goversion.Version))) + _, err := os.Stat(fmt.Sprintf("go1.%d.txt", goversion.Version)) if errors.Is(err, fs.ErrNotExist) { // It doesn't exist, so we're in development or before Beta 1. // At this stage, unmentioned API additions are deemed okay. From 15728ce950eea43d6f1b9fb29819d006071e843a Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Mon, 14 Mar 2022 15:17:43 -0700 Subject: [PATCH 094/276] cmd/compile: disable rewrite loop detector for deadcode-only changes We're guaranteed we won't infinite loop on deadcode-only changes, because each change converts valid -> invalid, and there are only a finite number of valid values. The loops this test is looking for are those generated by rule applications, so it isn't useful to check for loops when rules aren't involved. Fixes #51639 Change-Id: Idf1abeab9d47baafddc3a1197d5064faaf07ef78 Reviewed-on: https://go-review.googlesource.com/c/go/+/392760 Trust: Keith Randall Run-TryBot: Keith Randall TryBot-Result: Gopher Robot Reviewed-by: Josh Bleecher Snyder Trust: Josh Bleecher Snyder --- src/cmd/compile/internal/ssa/rewrite.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/cmd/compile/internal/ssa/rewrite.go b/src/cmd/compile/internal/ssa/rewrite.go index 9136c59e654..eb8fa0c02ab 100644 --- a/src/cmd/compile/internal/ssa/rewrite.go +++ b/src/cmd/compile/internal/ssa/rewrite.go @@ -40,6 +40,7 @@ func applyRewrite(f *Func, rb blockRewriter, rv valueRewriter, deadcode deadValu var states map[string]bool for { change := false + deadChange := false for _, b := range f.Blocks { var b0 *Block if debug > 1 { @@ -73,7 +74,7 @@ func applyRewrite(f *Func, rb blockRewriter, rv valueRewriter, deadcode deadValu // Not quite a deadcode pass, because it does not handle cycles. // But it should help Uses==1 rules to fire. v.reset(OpInvalid) - change = true + deadChange = true } // No point rewriting values which aren't used. continue @@ -145,15 +146,16 @@ func applyRewrite(f *Func, rb blockRewriter, rv valueRewriter, deadcode deadValu } } } - if !change { + if !change && !deadChange { break } iters++ - if iters > 1000 || debug >= 2 { + if (iters > 1000 || debug >= 2) && change { // We've done a suspiciously large number of rewrites (or we're in debug mode). // As of Sep 2021, 90% of rewrites complete in 4 iterations or fewer // and the maximum value encountered during make.bash is 12. // Start checking for cycles. (This is too expensive to do routinely.) + // Note: we avoid this path for deadChange-only iterations, to fix #51639. if states == nil { states = make(map[string]bool) } From 41a82aa9c36bffab2593d50aa55a462fef4e5bd4 Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Tue, 15 Mar 2022 10:21:08 +1100 Subject: [PATCH 095/276] text/template/parse: allow space after continue or break MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Trivial fix: We must skip space after either of these keywords before we expect a closing delimiter. Also delete the stutter-generating extra 'in' in the error message. (See what I did there?) Fixes #51670 Change-Id: If5415632c36eaac6699bdc0aa6ce18be956c9b53 Reviewed-on: https://go-review.googlesource.com/c/go/+/392615 Reviewed-by: Ian Lance Taylor Run-TryBot: Ian Lance Taylor Reviewed-by: Daniel Martí Trust: Daniel Martí TryBot-Result: Gopher Robot --- src/text/template/parse/parse.go | 8 ++++---- src/text/template/parse/parse_test.go | 4 ++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/text/template/parse/parse.go b/src/text/template/parse/parse.go index b0cbe9dfc8b..ce548b08865 100644 --- a/src/text/template/parse/parse.go +++ b/src/text/template/parse/parse.go @@ -415,8 +415,8 @@ func (t *Tree) action() (n Node) { // {{break}} // Break keyword is past. func (t *Tree) breakControl(pos Pos, line int) Node { - if token := t.next(); token.typ != itemRightDelim { - t.unexpected(token, "in {{break}}") + if token := t.nextNonSpace(); token.typ != itemRightDelim { + t.unexpected(token, "{{break}}") } if t.rangeDepth == 0 { t.errorf("{{break}} outside {{range}}") @@ -428,8 +428,8 @@ func (t *Tree) breakControl(pos Pos, line int) Node { // {{continue}} // Continue keyword is past. func (t *Tree) continueControl(pos Pos, line int) Node { - if token := t.next(); token.typ != itemRightDelim { - t.unexpected(token, "in {{continue}}") + if token := t.nextNonSpace(); token.typ != itemRightDelim { + t.unexpected(token, "{{continue}}") } if t.rangeDepth == 0 { t.errorf("{{continue}} outside {{range}}") diff --git a/src/text/template/parse/parse_test.go b/src/text/template/parse/parse_test.go index 0c4778c7b3b..fdb25d78f55 100644 --- a/src/text/template/parse/parse_test.go +++ b/src/text/template/parse/parse_test.go @@ -260,6 +260,10 @@ var parseTests = []parseTest{ {"newline in pipeline", "{{\n\"x\"\n|\nprintf\n}}", noError, `{{"x" | printf}}`}, {"newline in comment", "{{/*\nhello\n*/}}", noError, ""}, {"newline in comment", "{{-\n/*\nhello\n*/\n-}}", noError, ""}, + {"spaces around continue", "{{range .SI}}{{.}}{{ continue }}{{end}}", noError, + `{{range .SI}}{{.}}{{continue}}{{end}}`}, + {"spaces around break", "{{range .SI}}{{.}}{{ break }}{{end}}", noError, + `{{range .SI}}{{.}}{{break}}{{end}}`}, // Errors. {"unclosed action", "hello{{range", hasError, ""}, From 44a0da4ff11a5447dcfe2b62ac46bca134736d81 Mon Sep 17 00:00:00 2001 From: eric fang Date: Tue, 20 Apr 2021 02:46:33 +0000 Subject: [PATCH 096/276] cmd/internal/obj/arm64: refactor the handling of shifted RSP Some arithmetic operation instructions such as ADD and SUB support two formats of left shift (<<) operation, namely shifted register format and extended register format. And the encoding, supported registers and shifted amount are both different. The assembly parser doesn't distinguish them and parses them into TYPE_SHIFT type, because the parser can't tell them apart and in most cases extended left-shift can be replaced by shifted left-shift. The only exception is when the second source register or the destination register is RSP. This CL converts this case into the extended format in the preprocess stage, which helps to simplify some of the logic of the new assembler implementation and also makes this situation look more reasonable. Change-Id: I2cd7d2d663b38a7ba77a9fef1092708b8cb9bc3d Reviewed-on: https://go-review.googlesource.com/c/go/+/311709 Trust: Eric Fang Run-TryBot: Eric Fang TryBot-Result: Gopher Robot Reviewed-by: Cherry Mui --- .../asm/internal/asm/testdata/arm64error.s | 4 +- src/cmd/internal/obj/arm64/asm7.go | 61 +++++-------------- src/cmd/internal/obj/arm64/obj7.go | 18 ++++++ 3 files changed, 35 insertions(+), 48 deletions(-) diff --git a/src/cmd/asm/internal/asm/testdata/arm64error.s b/src/cmd/asm/internal/asm/testdata/arm64error.s index 3d3de1d9b13..033c4cda6c8 100644 --- a/src/cmd/asm/internal/asm/testdata/arm64error.s +++ b/src/cmd/asm/internal/asm/testdata/arm64error.s @@ -417,8 +417,8 @@ TEXT errors(SB),$0 CASPD (R2, R4), (R2), (R8, R9) // ERROR "source register pair must be contiguous" CASPD (R2, R3), (R2), (R8, R10) // ERROR "destination register pair must be contiguous" ADD R1>>2, RSP, R3 // ERROR "illegal combination" - ADDS R2<<3, R3, RSP // ERROR "unexpected SP reference" - CMP R1<<5, RSP // ERROR "the left shift amount out of range 0 to 4" + ADDS R2<<3, R3, RSP // ERROR "illegal destination register" + CMP R1<<5, RSP // ERROR "shift amount out of range 0 to 4" MOVD.P y+8(FP), R1 // ERROR "illegal combination" MOVD.W x-8(SP), R1 // ERROR "illegal combination" LDP.P x+8(FP), (R0, R1) // ERROR "illegal combination" diff --git a/src/cmd/internal/obj/arm64/asm7.go b/src/cmd/internal/obj/arm64/asm7.go index f4111f4f5cd..5435b2248fa 100644 --- a/src/cmd/internal/obj/arm64/asm7.go +++ b/src/cmd/internal/obj/arm64/asm7.go @@ -321,11 +321,8 @@ var optab = []Optab{ {ACMP, C_VCON, C_REG, C_NONE, C_NONE, 13, 20, 0, 0, 0}, {AADD, C_SHIFT, C_REG, C_NONE, C_REG, 3, 4, 0, 0, 0}, {AADD, C_SHIFT, C_NONE, C_NONE, C_REG, 3, 4, 0, 0, 0}, - {AADD, C_SHIFT, C_RSP, C_NONE, C_RSP, 26, 4, 0, 0, 0}, - {AADD, C_SHIFT, C_NONE, C_NONE, C_RSP, 26, 4, 0, 0, 0}, {AMVN, C_SHIFT, C_NONE, C_NONE, C_REG, 3, 4, 0, 0, 0}, {ACMP, C_SHIFT, C_REG, C_NONE, C_NONE, 3, 4, 0, 0, 0}, - {ACMP, C_SHIFT, C_RSP, C_NONE, C_NONE, 26, 4, 0, 0, 0}, {ANEG, C_SHIFT, C_NONE, C_NONE, C_REG, 3, 4, 0, 0, 0}, {AADD, C_REG, C_RSP, C_NONE, C_RSP, 27, 4, 0, 0, 0}, {AADD, C_REG, C_NONE, C_NONE, C_RSP, 27, 4, 0, 0, 0}, @@ -1687,7 +1684,8 @@ func rclass(r int16) int { return C_ARNG case r >= REG_ELEM && r < REG_ELEM_END: return C_ELEM - case r >= REG_UXTB && r < REG_SPECIAL: + case r >= REG_UXTB && r < REG_SPECIAL, + r >= REG_LSL && r < REG_ARNG: return C_EXTREG case r >= REG_SPECIAL: return C_SPR @@ -3666,52 +3664,18 @@ func (c *ctxt7) asmout(p *obj.Prog, o *Optab, out []uint32) { rt := int(p.To.Reg) o1 |= (uint32(rf&31) << 16) | (REGZERO & 31 << 5) | uint32(rt&31) - case 26: // op R<> 10) & 63 - shift := (p.From.Offset >> 22) & 3 - if shift != 0 { - c.ctxt.Diag("illegal combination: %v", p) - break - } - - if amount > 4 { - c.ctxt.Diag("the left shift amount out of range 0 to 4: %v", p) - break - } - rf := (p.From.Offset >> 16) & 31 - rt := int(p.To.Reg) - r := int(p.Reg) - if p.To.Type == obj.TYPE_NONE { - rt = REGZERO - } - if r == 0 { - r = rt - } - - o1 = c.opxrrr(p, p.As, false) - o1 |= uint32(rf)<<16 | uint32(amount&7)<<10 | (uint32(r&31) << 5) | uint32(rt&31) - case 27: /* op Rm<= REG_LSL && p.From.Reg < REG_ARNG) { amount := (p.From.Reg >> 5) & 7 if amount > 4 { c.ctxt.Diag("shift amount out of range 0 to 4: %v", p) } o1 = c.opxrrr(p, p.As, true) - o1 |= c.encRegShiftOrExt(&p.From, p.From.Reg) /* includes reg, op, etc */ + o1 |= c.encRegShiftOrExt(p, &p.From, p.From.Reg) /* includes reg, op, etc */ } else { o1 = c.opxrrr(p, p.As, false) o1 |= uint32(p.From.Reg&31) << 16 @@ -5344,7 +5308,7 @@ func (c *ctxt7) asmout(p *obj.Prog, o *Optab, out []uint32) { c.checkShiftAmount(p, &p.From) o1 = c.opldrr(p, p.As, true) - o1 |= c.encRegShiftOrExt(&p.From, p.From.Index) /* includes reg, op, etc */ + o1 |= c.encRegShiftOrExt(p, &p.From, p.From.Index) /* includes reg, op, etc */ } else { // (Rn)(Rm), no extension or shift. o1 = c.opldrr(p, p.As, false) @@ -5360,7 +5324,7 @@ func (c *ctxt7) asmout(p *obj.Prog, o *Optab, out []uint32) { c.checkShiftAmount(p, &p.To) o1 = c.opstrr(p, p.As, true) - o1 |= c.encRegShiftOrExt(&p.To, p.To.Index) /* includes reg, op, etc */ + o1 |= c.encRegShiftOrExt(p, &p.To, p.To.Index) /* includes reg, op, etc */ } else { // (Rn)(Rm), no extension or shift. o1 = c.opstrr(p, p.As, false) @@ -7427,7 +7391,7 @@ func roff(rm int16, o uint32, amount int16) uint32 { } // encRegShiftOrExt returns the encoding of shifted/extended register, Rx<> 5) & 7 rm = r & 31 @@ -7472,8 +7436,13 @@ func (c *ctxt7) encRegShiftOrExt(a *obj.Addr, r int16) uint32 { } else { return roff(rm, 7, num) } - case REG_LSL <= r && r < (REG_LSL+1<<8): - return roff(rm, 3, 6) + case REG_LSL <= r && r < REG_ARNG: + if a.Type == obj.TYPE_MEM { // (R1)(R2<<1) + return roff(rm, 3, 6) + } else if isADDWop(p.As) { + return roff(rm, 2, num) + } + return roff(rm, 3, num) default: c.ctxt.Diag("unsupported register extension type.") } diff --git a/src/cmd/internal/obj/arm64/obj7.go b/src/cmd/internal/obj/arm64/obj7.go index 43f7b16d6e2..ee5a6fa273e 100644 --- a/src/cmd/internal/obj/arm64/obj7.go +++ b/src/cmd/internal/obj/arm64/obj7.go @@ -1089,6 +1089,24 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) { } } } + if p.From.Type == obj.TYPE_SHIFT && (p.To.Reg == REG_RSP || p.Reg == REG_RSP) { + offset := p.From.Offset + op := offset & (3 << 22) + if op != SHIFT_LL { + ctxt.Diag("illegal combination: %v", p) + } + r := (offset >> 16) & 31 + shift := (offset >> 10) & 63 + if shift > 4 { + // the shift amount is out of range, in order to avoid repeated error + // reportings, don't call ctxt.Diag, because asmout case 27 has the + // same check. + shift = 7 + } + p.From.Type = obj.TYPE_REG + p.From.Reg = int16(REG_LSL + r + (shift&7)<<5) + p.From.Offset = 0 + } } } From 49f16625c82483ab26929a2761031c93dd5d2c83 Mon Sep 17 00:00:00 2001 From: fanzha02 Date: Mon, 14 Mar 2022 02:40:25 +0000 Subject: [PATCH 097/276] cmd/internal/obj/arm64: add TRN1 and TRN2 instructions support Add test cases. Fixes #51628 Change-Id: I433367d87e6bb5da5579c4be540079b92701c1fa Reviewed-on: https://go-review.googlesource.com/c/go/+/392294 Trust: Josh Bleecher Snyder Reviewed-by: Josh Bleecher Snyder Reviewed-by: Cherry Mui Trust: Fannie Zhang --- src/cmd/asm/internal/asm/testdata/arm64.s | 4 ++++ src/cmd/internal/obj/arm64/a.out.go | 2 ++ src/cmd/internal/obj/arm64/anames.go | 2 ++ src/cmd/internal/obj/arm64/asm7.go | 8 ++++++++ 4 files changed, 16 insertions(+) diff --git a/src/cmd/asm/internal/asm/testdata/arm64.s b/src/cmd/asm/internal/asm/testdata/arm64.s index a4b56b0696b..8a7dd299aab 100644 --- a/src/cmd/asm/internal/asm/testdata/arm64.s +++ b/src/cmd/asm/internal/asm/testdata/arm64.s @@ -241,6 +241,10 @@ TEXT foo(SB), DUPOK|NOSPLIT, $-8 FADDS F2, F3, F4 // 6428221e FADDD F1, F2 // 4228611e VDUP V19.S[0], V17.S4 // 7106044e + VTRN1 V3.D2, V2.D2, V20.D2 // 5428c34e + VTRN2 V3.D2, V2.D2, V21.D2 // 5568c34e + VTRN1 V5.D2, V4.D2, V22.D2 // 9628c54e + VTRN2 V5.D2, V4.D2, V23.D2 // 9768c54e // special diff --git a/src/cmd/internal/obj/arm64/a.out.go b/src/cmd/internal/obj/arm64/a.out.go index aa7c54df9ae..f3480e0f5e1 100644 --- a/src/cmd/internal/obj/arm64/a.out.go +++ b/src/cmd/internal/obj/arm64/a.out.go @@ -1053,6 +1053,8 @@ const ( AVUADDW2 AVUADDW AVUSRA + AVTRN1 + AVTRN2 ALAST AB = obj.AJMP ABL = obj.ACALL diff --git a/src/cmd/internal/obj/arm64/anames.go b/src/cmd/internal/obj/arm64/anames.go index 9cc58716488..ab97a1a1307 100644 --- a/src/cmd/internal/obj/arm64/anames.go +++ b/src/cmd/internal/obj/arm64/anames.go @@ -537,5 +537,7 @@ var Anames = []string{ "VUADDW2", "VUADDW", "VUSRA", + "VTRN1", + "VTRN2", "LAST", } diff --git a/src/cmd/internal/obj/arm64/asm7.go b/src/cmd/internal/obj/arm64/asm7.go index 5435b2248fa..244430eb8fc 100644 --- a/src/cmd/internal/obj/arm64/asm7.go +++ b/src/cmd/internal/obj/arm64/asm7.go @@ -2985,6 +2985,8 @@ func buildop(ctxt *obj.Link) { case AVZIP1: oprangeset(AVZIP2, t) + oprangeset(AVTRN1, t) + oprangeset(AVTRN2, t) case AVUXTL: oprangeset(AVUXTL2, t) @@ -6179,6 +6181,12 @@ func (c *ctxt7) oprrr(p *obj.Prog, a obj.As) uint32 { case AVUADDW, AVUADDW2: return 0x17<<25 | 1<<21 | 1<<12 + + case AVTRN1: + return 7<<25 | 5<<11 + + case AVTRN2: + return 7<<25 | 1<<14 | 5<<11 } c.ctxt.Diag("%v: bad rrr %d %v", p, a, a) From e475cf2e705d4eda8647426e060898ab3f643610 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Mon, 14 Mar 2022 17:39:35 -0700 Subject: [PATCH 098/276] syscall: add race annotations to Windows ReadFile and WriteFile For #51618 Fixes #51673 Change-Id: Ie63408d62303293d80afed8d5cf1cb164a8abecc Reviewed-on: https://go-review.googlesource.com/c/go/+/392774 Trust: Ian Lance Taylor Run-TryBot: Ian Lance Taylor Reviewed-by: Keith Randall TryBot-Result: Gopher Robot --- src/syscall/syscall_windows.go | 54 +++++++++++++++++++-------------- src/syscall/zsyscall_windows.go | 4 +-- 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/src/syscall/syscall_windows.go b/src/syscall/syscall_windows.go index 78e46a656d8..aba6c3f5fb8 100644 --- a/src/syscall/syscall_windows.go +++ b/src/syscall/syscall_windows.go @@ -202,8 +202,8 @@ func NewCallbackCDecl(fn any) uintptr { //sys formatMessage(flags uint32, msgsrc uintptr, msgid uint32, langid uint32, buf []uint16, args *byte) (n uint32, err error) = FormatMessageW //sys ExitProcess(exitcode uint32) //sys CreateFile(name *uint16, access uint32, mode uint32, sa *SecurityAttributes, createmode uint32, attrs uint32, templatefile int32) (handle Handle, err error) [failretval==InvalidHandle] = CreateFileW -//sys ReadFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error) -//sys WriteFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error) +//sys readFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error) = ReadFile +//sys writeFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error) = WriteFile //sys SetFilePointer(handle Handle, lowoffset int32, highoffsetptr *int32, whence uint32) (newlowoffset uint32, err error) [failretval==0xffffffff] //sys CloseHandle(handle Handle) (err error) //sys GetStdHandle(stdhandle int) (handle Handle, err error) [failretval==InvalidHandle] @@ -385,40 +385,50 @@ func Read(fd Handle, p []byte) (n int, err error) { } return 0, e } + return int(done), nil +} + +func Write(fd Handle, p []byte) (n int, err error) { + var done uint32 + e := WriteFile(fd, p, &done, nil) + if e != nil { + return 0, e + } + return int(done), nil +} + +func ReadFile(fd Handle, p []byte, done *uint32, overlapped *Overlapped) error { + err := readFile(fd, p, done, overlapped) if race.Enabled { - if done > 0 { - race.WriteRange(unsafe.Pointer(&p[0]), int(done)) + if *done > 0 { + race.WriteRange(unsafe.Pointer(&p[0]), int(*done)) } race.Acquire(unsafe.Pointer(&ioSync)) } - if msanenabled && done > 0 { - msanWrite(unsafe.Pointer(&p[0]), int(done)) + if msanenabled && *done > 0 { + msanWrite(unsafe.Pointer(&p[0]), int(*done)) } - if asanenabled && done > 0 { - asanWrite(unsafe.Pointer(&p[0]), int(done)) + if asanenabled && *done > 0 { + asanWrite(unsafe.Pointer(&p[0]), int(*done)) } - return int(done), nil + return err } -func Write(fd Handle, p []byte) (n int, err error) { +func WriteFile(fd Handle, p []byte, done *uint32, overlapped *Overlapped) error { if race.Enabled { race.ReleaseMerge(unsafe.Pointer(&ioSync)) } - var done uint32 - e := WriteFile(fd, p, &done, nil) - if e != nil { - return 0, e - } - if race.Enabled && done > 0 { - race.ReadRange(unsafe.Pointer(&p[0]), int(done)) + err := writeFile(fd, p, done, overlapped) + if race.Enabled && *done > 0 { + race.ReadRange(unsafe.Pointer(&p[0]), int(*done)) } - if msanenabled && done > 0 { - msanRead(unsafe.Pointer(&p[0]), int(done)) + if msanenabled && *done > 0 { + msanRead(unsafe.Pointer(&p[0]), int(*done)) } - if asanenabled && done > 0 { - asanRead(unsafe.Pointer(&p[0]), int(done)) + if asanenabled && *done > 0 { + asanRead(unsafe.Pointer(&p[0]), int(*done)) } - return int(done), nil + return err } var ioSync int64 diff --git a/src/syscall/zsyscall_windows.go b/src/syscall/zsyscall_windows.go index 2d6f34e059d..61d89f14604 100644 --- a/src/syscall/zsyscall_windows.go +++ b/src/syscall/zsyscall_windows.go @@ -1016,7 +1016,7 @@ func ReadDirectoryChanges(handle Handle, buf *byte, buflen uint32, watchSubTree return } -func ReadFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error) { +func readFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error) { var _p0 *byte if len(buf) > 0 { _p0 = &buf[0] @@ -1158,7 +1158,7 @@ func WriteConsole(console Handle, buf *uint16, towrite uint32, written *uint32, return } -func WriteFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error) { +func writeFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error) { var _p0 *byte if len(buf) > 0 { _p0 = &buf[0] From 7b15e297a26842f1f3408ee9d7942f8cfab2e5ea Mon Sep 17 00:00:00 2001 From: Archana R Date: Mon, 7 Mar 2022 01:54:14 -0600 Subject: [PATCH 099/276] cmd/compile: fix PrefetchStreamed builtin implementation on PPC64 This CL fixes encoding of PrefetchStreamed on PPC64 to be consistent with what is implemented on AMD64 and ARM64 platforms which is prefetchNTA (prefetch non-temporal access). Looking at the definition of prefetchNTA, the closest corresponding Touch hint (TH) value to be used on PPC64 is 16 that states that the address is accessed in a transient manner. Current usage of TH=8 may cause degraded performance. Change-Id: I393bf5a9b971a22f632b3cbfb4fa659062af9a27 Reviewed-on: https://go-review.googlesource.com/c/go/+/390316 Reviewed-by: Paul Murphy Reviewed-by: Cherry Mui Run-TryBot: Cherry Mui TryBot-Result: Gopher Robot --- src/cmd/compile/internal/ssa/gen/PPC64.rules | 8 ++++++-- src/cmd/compile/internal/ssa/rewritePPC64.go | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/cmd/compile/internal/ssa/gen/PPC64.rules b/src/cmd/compile/internal/ssa/gen/PPC64.rules index c3f07a4e22c..eb9fe3cf723 100644 --- a/src/cmd/compile/internal/ssa/gen/PPC64.rules +++ b/src/cmd/compile/internal/ssa/gen/PPC64.rules @@ -1479,7 +1479,11 @@ && clobber(call) => (Move [sz] dst src mem) -// Prefetch instructions (aux is option: 0 - DCBT ; 8 - DCBT stream) +// Prefetch instructions (TH specified using aux field) +// For DCBT Ra,Rb,TH, A value of TH indicates: +// 0, hint this cache line will be used soon. (PrefetchCache) +// 16, hint this cache line will not be used for long. (PrefetchCacheStreamed) +// See ISA 3.0 Book II 4.3.2 for more detail. https://openpower.foundation/specifications/isa/ (PrefetchCache ptr mem) => (DCBT ptr mem [0]) -(PrefetchCacheStreamed ptr mem) => (DCBT ptr mem [8]) +(PrefetchCacheStreamed ptr mem) => (DCBT ptr mem [16]) diff --git a/src/cmd/compile/internal/ssa/rewritePPC64.go b/src/cmd/compile/internal/ssa/rewritePPC64.go index 7592b4f5058..5da6d9641ce 100644 --- a/src/cmd/compile/internal/ssa/rewritePPC64.go +++ b/src/cmd/compile/internal/ssa/rewritePPC64.go @@ -14140,12 +14140,12 @@ func rewriteValuePPC64_OpPrefetchCacheStreamed(v *Value) bool { v_1 := v.Args[1] v_0 := v.Args[0] // match: (PrefetchCacheStreamed ptr mem) - // result: (DCBT ptr mem [8]) + // result: (DCBT ptr mem [16]) for { ptr := v_0 mem := v_1 v.reset(OpPPC64DCBT) - v.AuxInt = int64ToAuxInt(8) + v.AuxInt = int64ToAuxInt(16) v.AddArg2(ptr, mem) return true } From b054c7dc1738c810e74756ae0ac4797ce5d31cf6 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Mon, 14 Mar 2022 11:27:46 -0400 Subject: [PATCH 100/276] os: raise open file rlimit at startup Some systems set an artificially low soft limit on open file count, for compatibility with code that uses select and its hard-coded maximum file descriptor (limited by the size of fd_set). Go does not use select, so it should not be subject to these limits. On some systems the limit is 256, which is very easy to run into, even in simple programs like gofmt when they parallelize walking a file tree. After a long discussion on go.dev/issue/46279, we decided the best approach was for Go to raise the limit unconditionally for itself, and then leave old software to set the limit back as needed. Code that really wants Go to leave the limit alone can set the hard limit, which Go of course has no choice but to respect. Fixes #46279. Change-Id: Id6107503437d47a870a41be25e822fc79cea08b2 Reviewed-on: https://go-review.googlesource.com/c/go/+/392415 Trust: Russ Cox Run-TryBot: Russ Cox TryBot-Result: Gopher Robot Reviewed-by: Ian Lance Taylor --- src/os/rlimit.go | 31 +++++++++++++++++++++++++++++++ src/os/rlimit_test.go | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 src/os/rlimit.go create mode 100644 src/os/rlimit_test.go diff --git a/src/os/rlimit.go b/src/os/rlimit.go new file mode 100644 index 00000000000..3e29db95629 --- /dev/null +++ b/src/os/rlimit.go @@ -0,0 +1,31 @@ +// Copyright 2022 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 os + +import "syscall" + +// Some systems set an artificially low soft limit on open file count, for compatibility +// with code that uses select and its hard-coded maximum file descriptor +// (limited by the size of fd_set). +// +// Go does not use select, so it should not be subject to these limits. +// On some systems the limit is 256, which is very easy to run into, +// even in simple programs like gofmt when they parallelize walking +// a file tree. +// +// After a long discussion on go.dev/issue/46279, we decided the +// best approach was for Go to raise the limit unconditionally for itself, +// and then leave old software to set the limit back as needed. +// Code that really wants Go to leave the limit alone can set the hard limit, +// which Go of course has no choice but to respect. +func init() { + var lim syscall.Rlimit + if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &lim); err == nil && lim.Cur != lim.Max { + lim.Cur = lim.Max + syscall.Setrlimit(syscall.RLIMIT_NOFILE, &lim) + } +} diff --git a/src/os/rlimit_test.go b/src/os/rlimit_test.go new file mode 100644 index 00000000000..9bb6858a867 --- /dev/null +++ b/src/os/rlimit_test.go @@ -0,0 +1,32 @@ +// Copyright 2022 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 os_test + +import ( + . "os" + "testing" +) + +func TestOpenFileLimit(t *testing.T) { + // For open file count, + // macOS sets the default soft limit to 256 and no hard limit. + // CentOS and Fedora set the default soft limit to 1024, + // with hard limits of 4096 and 524288, respectively. + // Check that we can open 1200 files, which proves + // that the rlimit is being raised appropriately on those systems. + var files []*File + for i := 0; i < 1200; i++ { + f, err := Open("rlimit.go") + if err != nil { + t.Error(err) + break + } + files = append(files, f) + } + + for _, f := range files { + f.Close() + } +} From 9b112cec8363c0c574750d92cffe8682e80aacbe Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Tue, 15 Mar 2022 08:56:07 -0700 Subject: [PATCH 101/276] internal/cpu: don't run SSE3 disable test if GOAMD64>1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit That feature can't be disabled if the microarchitectural version requires it. Change-Id: Iad8aaa8089d2f023e9ae5044c6da33224499f09b Reviewed-on: https://go-review.googlesource.com/c/go/+/392994 Run-TryBot: Keith Randall Trust: Keith Randall Reviewed-by: Tobias Klauser Reviewed-by: Martin Möhrmann TryBot-Result: Gopher Robot --- src/internal/cpu/cpu_x86_test.go | 3 +++ src/internal/cpu/export_x86_test.go | 11 +++++++++++ 2 files changed, 14 insertions(+) create mode 100644 src/internal/cpu/export_x86_test.go diff --git a/src/internal/cpu/cpu_x86_test.go b/src/internal/cpu/cpu_x86_test.go index c8be210055c..43d6b211ea4 100644 --- a/src/internal/cpu/cpu_x86_test.go +++ b/src/internal/cpu/cpu_x86_test.go @@ -19,6 +19,9 @@ func TestX86ifAVX2hasAVX(t *testing.T) { } func TestDisableSSE3(t *testing.T) { + if GetGOAMD64level() > 1 { + t.Skip("skipping test: can't run on GOAMD64>v1 machines") + } runDebugOptionsTest(t, "TestSSE3DebugOption", "cpu.sse3=off") } diff --git a/src/internal/cpu/export_x86_test.go b/src/internal/cpu/export_x86_test.go new file mode 100644 index 00000000000..a12b6f27234 --- /dev/null +++ b/src/internal/cpu/export_x86_test.go @@ -0,0 +1,11 @@ +// Copyright 2022 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 386 || amd64 + +package cpu + +var ( + GetGOAMD64level = getGOAMD64level +) From 1178255f8596ea503daf30c84c7c1039f755e7f0 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Thu, 3 Feb 2022 11:50:45 -0500 Subject: [PATCH 102/276] all: untab /* */ doc comments A long time ago, gofmt insisted on inserting tabs in /* */ comments at the top level of the file, like this: /* Package doc comment. */ package p Gofmt still insists on the tab for comments not at top level, but it has relaxed the rules about top-level comments. A few very old doc comments are indented, left over from the old rule. We are considering formatting doc comments, and so to make everything consistent, standardize on unindented doc comments by removing tabs in the few doc comments that are still indented this way. Also update some cmd/gofmt testdata to match. Change-Id: I293742e39b52f8a48ec41f72ca4acdafa7ce43bc Reviewed-on: https://go-review.googlesource.com/c/go/+/384261 Trust: Russ Cox Run-TryBot: Russ Cox TryBot-Result: Gopher Robot Reviewed-by: Ian Lance Taylor --- src/builtin/builtin.go | 8 +- src/cmd/gofmt/testdata/crlf.golden | 8 +- src/cmd/gofmt/testdata/crlf.input | 8 +- src/cmd/gofmt/testdata/typeswitch.golden | 26 +- src/cmd/gofmt/testdata/typeswitch.input | 26 +- src/flag/flag.go | 116 ++-- src/fmt/doc.go | 674 +++++++++++------------ src/go/doc/headscan.go | 10 +- src/net/rpc/server.go | 182 +++--- src/runtime/debug/stack_test.go | 30 +- src/unsafe/unsafe.go | 6 +- 11 files changed, 547 insertions(+), 547 deletions(-) diff --git a/src/builtin/builtin.go b/src/builtin/builtin.go index 5657be45642..8997902f8f9 100644 --- a/src/builtin/builtin.go +++ b/src/builtin/builtin.go @@ -3,10 +3,10 @@ // license that can be found in the LICENSE file. /* - Package builtin provides documentation for Go's predeclared identifiers. - The items documented here are not actually in package builtin - but their descriptions here allow godoc to present documentation - for the language's special identifiers. +Package builtin provides documentation for Go's predeclared identifiers. +The items documented here are not actually in package builtin +but their descriptions here allow godoc to present documentation +for the language's special identifiers. */ package builtin diff --git a/src/cmd/gofmt/testdata/crlf.golden b/src/cmd/gofmt/testdata/crlf.golden index 193dbacc727..65de9cf1994 100644 --- a/src/cmd/gofmt/testdata/crlf.golden +++ b/src/cmd/gofmt/testdata/crlf.golden @@ -1,8 +1,8 @@ /* - Source containing CR/LF line endings. - The gofmt'ed output must only have LF - line endings. - Test case for issue 3961. +Source containing CR/LF line endings. +The gofmt'ed output must only have LF +line endings. +Test case for issue 3961. */ package main diff --git a/src/cmd/gofmt/testdata/crlf.input b/src/cmd/gofmt/testdata/crlf.input index ae7e14dbf13..3cd4934caf2 100644 --- a/src/cmd/gofmt/testdata/crlf.input +++ b/src/cmd/gofmt/testdata/crlf.input @@ -1,8 +1,8 @@ /* - Source containing CR/LF line endings. - The gofmt'ed output must only have LF - line endings. - Test case for issue 3961. +Source containing CR/LF line endings. +The gofmt'ed output must only have LF +line endings. +Test case for issue 3961. */ package main diff --git a/src/cmd/gofmt/testdata/typeswitch.golden b/src/cmd/gofmt/testdata/typeswitch.golden index 2b1905edd3b..3cf4dca7d4d 100644 --- a/src/cmd/gofmt/testdata/typeswitch.golden +++ b/src/cmd/gofmt/testdata/typeswitch.golden @@ -1,17 +1,17 @@ /* - Parenthesized type switch expressions originally - accepted by gofmt must continue to be rewritten - into the correct unparenthesized form. - - Only type-switches that didn't declare a variable - in the type switch type assertion and which - contained only "expression-like" (named) types in their - cases were permitted to have their type assertion parenthesized - by go/parser (due to a weak predicate in the parser). All others - were rejected always, either with a syntax error in the - type switch header or in the case. - - See also issue 4470. +Parenthesized type switch expressions originally +accepted by gofmt must continue to be rewritten +into the correct unparenthesized form. + +Only type-switches that didn't declare a variable +in the type switch type assertion and which +contained only "expression-like" (named) types in their +cases were permitted to have their type assertion parenthesized +by go/parser (due to a weak predicate in the parser). All others +were rejected always, either with a syntax error in the +type switch header or in the case. + +See also issue 4470. */ package p diff --git a/src/cmd/gofmt/testdata/typeswitch.input b/src/cmd/gofmt/testdata/typeswitch.input index 8f8cba9b855..992a772d521 100644 --- a/src/cmd/gofmt/testdata/typeswitch.input +++ b/src/cmd/gofmt/testdata/typeswitch.input @@ -1,17 +1,17 @@ /* - Parenthesized type switch expressions originally - accepted by gofmt must continue to be rewritten - into the correct unparenthesized form. - - Only type-switches that didn't declare a variable - in the type switch type assertion and which - contained only "expression-like" (named) types in their - cases were permitted to have their type assertion parenthesized - by go/parser (due to a weak predicate in the parser). All others - were rejected always, either with a syntax error in the - type switch header or in the case. - - See also issue 4470. +Parenthesized type switch expressions originally +accepted by gofmt must continue to be rewritten +into the correct unparenthesized form. + +Only type-switches that didn't declare a variable +in the type switch type assertion and which +contained only "expression-like" (named) types in their +cases were permitted to have their type assertion parenthesized +by go/parser (due to a weak predicate in the parser). All others +were rejected always, either with a syntax error in the +type switch header or in the case. + +See also issue 4470. */ package p diff --git a/src/flag/flag.go b/src/flag/flag.go index c27a1444348..cdea949a2f0 100644 --- a/src/flag/flag.go +++ b/src/flag/flag.go @@ -3,67 +3,67 @@ // license that can be found in the LICENSE file. /* - Package flag implements command-line flag parsing. +Package flag implements command-line flag parsing. - Usage +Usage - Define flags using flag.String(), Bool(), Int(), etc. +Define flags using flag.String(), Bool(), Int(), etc. - This declares an integer flag, -n, stored in the pointer nFlag, with type *int: - import "flag" - var nFlag = flag.Int("n", 1234, "help message for flag n") - If you like, you can bind the flag to a variable using the Var() functions. - var flagvar int - func init() { - flag.IntVar(&flagvar, "flagname", 1234, "help message for flagname") - } - Or you can create custom flags that satisfy the Value interface (with - pointer receivers) and couple them to flag parsing by - flag.Var(&flagVal, "name", "help message for flagname") - For such flags, the default value is just the initial value of the variable. - - After all flags are defined, call - flag.Parse() - to parse the command line into the defined flags. - - Flags may then be used directly. If you're using the flags themselves, - they are all pointers; if you bind to variables, they're values. - fmt.Println("ip has value ", *ip) - fmt.Println("flagvar has value ", flagvar) - - After parsing, the arguments following the flags are available as the - slice flag.Args() or individually as flag.Arg(i). - The arguments are indexed from 0 through flag.NArg()-1. - - Command line flag syntax - - The following forms are permitted: - - -flag - -flag=x - -flag x // non-boolean flags only - One or two minus signs may be used; they are equivalent. - The last form is not permitted for boolean flags because the - meaning of the command - cmd -x * - where * is a Unix shell wildcard, will change if there is a file - called 0, false, etc. You must use the -flag=false form to turn - off a boolean flag. - - Flag parsing stops just before the first non-flag argument - ("-" is a non-flag argument) or after the terminator "--". - - Integer flags accept 1234, 0664, 0x1234 and may be negative. - Boolean flags may be: - 1, 0, t, f, T, F, true, false, TRUE, FALSE, True, False - Duration flags accept any input valid for time.ParseDuration. - - The default set of command-line flags is controlled by - top-level functions. The FlagSet type allows one to define - independent sets of flags, such as to implement subcommands - in a command-line interface. The methods of FlagSet are - analogous to the top-level functions for the command-line - flag set. +This declares an integer flag, -n, stored in the pointer nFlag, with type *int: + import "flag" + var nFlag = flag.Int("n", 1234, "help message for flag n") +If you like, you can bind the flag to a variable using the Var() functions. + var flagvar int + func init() { + flag.IntVar(&flagvar, "flagname", 1234, "help message for flagname") + } +Or you can create custom flags that satisfy the Value interface (with +pointer receivers) and couple them to flag parsing by + flag.Var(&flagVal, "name", "help message for flagname") +For such flags, the default value is just the initial value of the variable. + +After all flags are defined, call + flag.Parse() +to parse the command line into the defined flags. + +Flags may then be used directly. If you're using the flags themselves, +they are all pointers; if you bind to variables, they're values. + fmt.Println("ip has value ", *ip) + fmt.Println("flagvar has value ", flagvar) + +After parsing, the arguments following the flags are available as the +slice flag.Args() or individually as flag.Arg(i). +The arguments are indexed from 0 through flag.NArg()-1. + +Command line flag syntax + +The following forms are permitted: + + -flag + -flag=x + -flag x // non-boolean flags only +One or two minus signs may be used; they are equivalent. +The last form is not permitted for boolean flags because the +meaning of the command + cmd -x * +where * is a Unix shell wildcard, will change if there is a file +called 0, false, etc. You must use the -flag=false form to turn +off a boolean flag. + +Flag parsing stops just before the first non-flag argument +("-" is a non-flag argument) or after the terminator "--". + +Integer flags accept 1234, 0664, 0x1234 and may be negative. +Boolean flags may be: + 1, 0, t, f, T, F, true, false, TRUE, FALSE, True, False +Duration flags accept any input valid for time.ParseDuration. + +The default set of command-line flags is controlled by +top-level functions. The FlagSet type allows one to define +independent sets of flags, such as to implement subcommands +in a command-line interface. The methods of FlagSet are +analogous to the top-level functions for the command-line +flag set. */ package flag diff --git a/src/fmt/doc.go b/src/fmt/doc.go index a7bd02b627f..f14a7a73e33 100644 --- a/src/fmt/doc.go +++ b/src/fmt/doc.go @@ -3,342 +3,342 @@ // license that can be found in the LICENSE file. /* - Package fmt implements formatted I/O with functions analogous - to C's printf and scanf. The format 'verbs' are derived from C's but - are simpler. - - - Printing - - The verbs: - - General: - %v the value in a default format - when printing structs, the plus flag (%+v) adds field names - %#v a Go-syntax representation of the value - %T a Go-syntax representation of the type of the value - %% a literal percent sign; consumes no value - - Boolean: - %t the word true or false - Integer: - %b base 2 - %c the character represented by the corresponding Unicode code point - %d base 10 - %o base 8 - %O base 8 with 0o prefix - %q a single-quoted character literal safely escaped with Go syntax. - %x base 16, with lower-case letters for a-f - %X base 16, with upper-case letters for A-F - %U Unicode format: U+1234; same as "U+%04X" - Floating-point and complex constituents: - %b decimalless scientific notation with exponent a power of two, - in the manner of strconv.FormatFloat with the 'b' format, - e.g. -123456p-78 - %e scientific notation, e.g. -1.234456e+78 - %E scientific notation, e.g. -1.234456E+78 - %f decimal point but no exponent, e.g. 123.456 - %F synonym for %f - %g %e for large exponents, %f otherwise. Precision is discussed below. - %G %E for large exponents, %F otherwise - %x hexadecimal notation (with decimal power of two exponent), e.g. -0x1.23abcp+20 - %X upper-case hexadecimal notation, e.g. -0X1.23ABCP+20 - String and slice of bytes (treated equivalently with these verbs): - %s the uninterpreted bytes of the string or slice - %q a double-quoted string safely escaped with Go syntax - %x base 16, lower-case, two characters per byte - %X base 16, upper-case, two characters per byte - Slice: - %p address of 0th element in base 16 notation, with leading 0x - Pointer: - %p base 16 notation, with leading 0x - The %b, %d, %o, %x and %X verbs also work with pointers, - formatting the value exactly as if it were an integer. - - The default format for %v is: - bool: %t - int, int8 etc.: %d - uint, uint8 etc.: %d, %#x if printed with %#v - float32, complex64, etc: %g - string: %s - chan: %p - pointer: %p - For compound objects, the elements are printed using these rules, recursively, - laid out like this: - struct: {field0 field1 ...} - array, slice: [elem0 elem1 ...] - maps: map[key1:value1 key2:value2 ...] - pointer to above: &{}, &[], &map[] - - Width is specified by an optional decimal number immediately preceding the verb. - If absent, the width is whatever is necessary to represent the value. - Precision is specified after the (optional) width by a period followed by a - decimal number. If no period is present, a default precision is used. - A period with no following number specifies a precision of zero. - Examples: - %f default width, default precision - %9f width 9, default precision - %.2f default width, precision 2 - %9.2f width 9, precision 2 - %9.f width 9, precision 0 - - Width and precision are measured in units of Unicode code points, - that is, runes. (This differs from C's printf where the - units are always measured in bytes.) Either or both of the flags - may be replaced with the character '*', causing their values to be - obtained from the next operand (preceding the one to format), - which must be of type int. - - For most values, width is the minimum number of runes to output, - padding the formatted form with spaces if necessary. - - For strings, byte slices and byte arrays, however, precision - limits the length of the input to be formatted (not the size of - the output), truncating if necessary. Normally it is measured in - runes, but for these types when formatted with the %x or %X format - it is measured in bytes. - - For floating-point values, width sets the minimum width of the field and - precision sets the number of places after the decimal, if appropriate, - except that for %g/%G precision sets the maximum number of significant - digits (trailing zeros are removed). For example, given 12.345 the format - %6.3f prints 12.345 while %.3g prints 12.3. The default precision for %e, %f - and %#g is 6; for %g it is the smallest number of digits necessary to identify - the value uniquely. - - For complex numbers, the width and precision apply to the two - components independently and the result is parenthesized, so %f applied - to 1.2+3.4i produces (1.200000+3.400000i). - - Other flags: - + always print a sign for numeric values; - guarantee ASCII-only output for %q (%+q) - - pad with spaces on the right rather than the left (left-justify the field) - # alternate format: add leading 0b for binary (%#b), 0 for octal (%#o), - 0x or 0X for hex (%#x or %#X); suppress 0x for %p (%#p); - for %q, print a raw (backquoted) string if strconv.CanBackquote - returns true; - always print a decimal point for %e, %E, %f, %F, %g and %G; - do not remove trailing zeros for %g and %G; - write e.g. U+0078 'x' if the character is printable for %U (%#U). - ' ' (space) leave a space for elided sign in numbers (% d); - put spaces between bytes printing strings or slices in hex (% x, % X) - 0 pad with leading zeros rather than spaces; - for numbers, this moves the padding after the sign; - ignored for strings, byte slices and byte arrays - - Flags are ignored by verbs that do not expect them. - For example there is no alternate decimal format, so %#d and %d - behave identically. - - For each Printf-like function, there is also a Print function - that takes no format and is equivalent to saying %v for every - operand. Another variant Println inserts blanks between - operands and appends a newline. - - Regardless of the verb, if an operand is an interface value, - the internal concrete value is used, not the interface itself. - Thus: - var i interface{} = 23 - fmt.Printf("%v\n", i) - will print 23. - - Except when printed using the verbs %T and %p, special - formatting considerations apply for operands that implement - certain interfaces. In order of application: - - 1. If the operand is a reflect.Value, the operand is replaced by the - concrete value that it holds, and printing continues with the next rule. - - 2. If an operand implements the Formatter interface, it will - be invoked. In this case the interpretation of verbs and flags is - controlled by that implementation. - - 3. If the %v verb is used with the # flag (%#v) and the operand - implements the GoStringer interface, that will be invoked. - - If the format (which is implicitly %v for Println etc.) is valid - for a string (%s %q %v %x %X), the following two rules apply: - - 4. If an operand implements the error interface, the Error method - will be invoked to convert the object to a string, which will then - be formatted as required by the verb (if any). - - 5. If an operand implements method String() string, that method - will be invoked to convert the object to a string, which will then - be formatted as required by the verb (if any). - - For compound operands such as slices and structs, the format - applies to the elements of each operand, recursively, not to the - operand as a whole. Thus %q will quote each element of a slice - of strings, and %6.2f will control formatting for each element - of a floating-point array. - - However, when printing a byte slice with a string-like verb - (%s %q %x %X), it is treated identically to a string, as a single item. - - To avoid recursion in cases such as - type X string - func (x X) String() string { return Sprintf("<%s>", x) } - convert the value before recurring: - func (x X) String() string { return Sprintf("<%s>", string(x)) } - Infinite recursion can also be triggered by self-referential data - structures, such as a slice that contains itself as an element, if - that type has a String method. Such pathologies are rare, however, - and the package does not protect against them. - - When printing a struct, fmt cannot and therefore does not invoke - formatting methods such as Error or String on unexported fields. - - Explicit argument indexes - - In Printf, Sprintf, and Fprintf, the default behavior is for each - formatting verb to format successive arguments passed in the call. - However, the notation [n] immediately before the verb indicates that the - nth one-indexed argument is to be formatted instead. The same notation - before a '*' for a width or precision selects the argument index holding - the value. After processing a bracketed expression [n], subsequent verbs - will use arguments n+1, n+2, etc. unless otherwise directed. - - For example, - fmt.Sprintf("%[2]d %[1]d\n", 11, 22) - will yield "22 11", while - fmt.Sprintf("%[3]*.[2]*[1]f", 12.0, 2, 6) - equivalent to - fmt.Sprintf("%6.2f", 12.0) - will yield " 12.00". Because an explicit index affects subsequent verbs, - this notation can be used to print the same values multiple times - by resetting the index for the first argument to be repeated: - fmt.Sprintf("%d %d %#[1]x %#x", 16, 17) - will yield "16 17 0x10 0x11". - - Format errors - - If an invalid argument is given for a verb, such as providing - a string to %d, the generated string will contain a - description of the problem, as in these examples: - - Wrong type or unknown verb: %!verb(type=value) - Printf("%d", "hi"): %!d(string=hi) - Too many arguments: %!(EXTRA type=value) - Printf("hi", "guys"): hi%!(EXTRA string=guys) - Too few arguments: %!verb(MISSING) - Printf("hi%d"): hi%!d(MISSING) - Non-int for width or precision: %!(BADWIDTH) or %!(BADPREC) - Printf("%*s", 4.5, "hi"): %!(BADWIDTH)hi - Printf("%.*s", 4.5, "hi"): %!(BADPREC)hi - Invalid or invalid use of argument index: %!(BADINDEX) - Printf("%*[2]d", 7): %!d(BADINDEX) - Printf("%.[2]d", 7): %!d(BADINDEX) - - All errors begin with the string "%!" followed sometimes - by a single character (the verb) and end with a parenthesized - description. - - If an Error or String method triggers a panic when called by a - print routine, the fmt package reformats the error message - from the panic, decorating it with an indication that it came - through the fmt package. For example, if a String method - calls panic("bad"), the resulting formatted message will look - like - %!s(PANIC=bad) - - The %!s just shows the print verb in use when the failure - occurred. If the panic is caused by a nil receiver to an Error - or String method, however, the output is the undecorated - string, "". - - Scanning - - An analogous set of functions scans formatted text to yield - values. Scan, Scanf and Scanln read from os.Stdin; Fscan, - Fscanf and Fscanln read from a specified io.Reader; Sscan, - Sscanf and Sscanln read from an argument string. - - Scan, Fscan, Sscan treat newlines in the input as spaces. - - Scanln, Fscanln and Sscanln stop scanning at a newline and - require that the items be followed by a newline or EOF. - - Scanf, Fscanf, and Sscanf parse the arguments according to a - format string, analogous to that of Printf. In the text that - follows, 'space' means any Unicode whitespace character - except newline. - - In the format string, a verb introduced by the % character - consumes and parses input; these verbs are described in more - detail below. A character other than %, space, or newline in - the format consumes exactly that input character, which must - be present. A newline with zero or more spaces before it in - the format string consumes zero or more spaces in the input - followed by a single newline or the end of the input. A space - following a newline in the format string consumes zero or more - spaces in the input. Otherwise, any run of one or more spaces - in the format string consumes as many spaces as possible in - the input. Unless the run of spaces in the format string - appears adjacent to a newline, the run must consume at least - one space from the input or find the end of the input. - - The handling of spaces and newlines differs from that of C's - scanf family: in C, newlines are treated as any other space, - and it is never an error when a run of spaces in the format - string finds no spaces to consume in the input. - - The verbs behave analogously to those of Printf. - For example, %x will scan an integer as a hexadecimal number, - and %v will scan the default representation format for the value. - The Printf verbs %p and %T and the flags # and + are not implemented. - For floating-point and complex values, all valid formatting verbs - (%b %e %E %f %F %g %G %x %X and %v) are equivalent and accept - both decimal and hexadecimal notation (for example: "2.3e+7", "0x4.5p-8") - and digit-separating underscores (for example: "3.14159_26535_89793"). - - Input processed by verbs is implicitly space-delimited: the - implementation of every verb except %c starts by discarding - leading spaces from the remaining input, and the %s verb - (and %v reading into a string) stops consuming input at the first - space or newline character. - - The familiar base-setting prefixes 0b (binary), 0o and 0 (octal), - and 0x (hexadecimal) are accepted when scanning integers - without a format or with the %v verb, as are digit-separating - underscores. - - Width is interpreted in the input text but there is no - syntax for scanning with a precision (no %5.2f, just %5f). - If width is provided, it applies after leading spaces are - trimmed and specifies the maximum number of runes to read - to satisfy the verb. For example, - Sscanf(" 1234567 ", "%5s%d", &s, &i) - will set s to "12345" and i to 67 while - Sscanf(" 12 34 567 ", "%5s%d", &s, &i) - will set s to "12" and i to 34. - - In all the scanning functions, a carriage return followed - immediately by a newline is treated as a plain newline - (\r\n means the same as \n). - - In all the scanning functions, if an operand implements method - Scan (that is, it implements the Scanner interface) that - method will be used to scan the text for that operand. Also, - if the number of arguments scanned is less than the number of - arguments provided, an error is returned. - - All arguments to be scanned must be either pointers to basic - types or implementations of the Scanner interface. - - Like Scanf and Fscanf, Sscanf need not consume its entire input. - There is no way to recover how much of the input string Sscanf used. - - Note: Fscan etc. can read one character (rune) past the input - they return, which means that a loop calling a scan routine - may skip some of the input. This is usually a problem only - when there is no space between input values. If the reader - provided to Fscan implements ReadRune, that method will be used - to read characters. If the reader also implements UnreadRune, - that method will be used to save the character and successive - calls will not lose data. To attach ReadRune and UnreadRune - methods to a reader without that capability, use - bufio.NewReader. +Package fmt implements formatted I/O with functions analogous +to C's printf and scanf. The format 'verbs' are derived from C's but +are simpler. + + +Printing + +The verbs: + +General: + %v the value in a default format + when printing structs, the plus flag (%+v) adds field names + %#v a Go-syntax representation of the value + %T a Go-syntax representation of the type of the value + %% a literal percent sign; consumes no value + +Boolean: + %t the word true or false +Integer: + %b base 2 + %c the character represented by the corresponding Unicode code point + %d base 10 + %o base 8 + %O base 8 with 0o prefix + %q a single-quoted character literal safely escaped with Go syntax. + %x base 16, with lower-case letters for a-f + %X base 16, with upper-case letters for A-F + %U Unicode format: U+1234; same as "U+%04X" +Floating-point and complex constituents: + %b decimalless scientific notation with exponent a power of two, + in the manner of strconv.FormatFloat with the 'b' format, + e.g. -123456p-78 + %e scientific notation, e.g. -1.234456e+78 + %E scientific notation, e.g. -1.234456E+78 + %f decimal point but no exponent, e.g. 123.456 + %F synonym for %f + %g %e for large exponents, %f otherwise. Precision is discussed below. + %G %E for large exponents, %F otherwise + %x hexadecimal notation (with decimal power of two exponent), e.g. -0x1.23abcp+20 + %X upper-case hexadecimal notation, e.g. -0X1.23ABCP+20 +String and slice of bytes (treated equivalently with these verbs): + %s the uninterpreted bytes of the string or slice + %q a double-quoted string safely escaped with Go syntax + %x base 16, lower-case, two characters per byte + %X base 16, upper-case, two characters per byte +Slice: + %p address of 0th element in base 16 notation, with leading 0x +Pointer: + %p base 16 notation, with leading 0x + The %b, %d, %o, %x and %X verbs also work with pointers, + formatting the value exactly as if it were an integer. + +The default format for %v is: + bool: %t + int, int8 etc.: %d + uint, uint8 etc.: %d, %#x if printed with %#v + float32, complex64, etc: %g + string: %s + chan: %p + pointer: %p +For compound objects, the elements are printed using these rules, recursively, +laid out like this: + struct: {field0 field1 ...} + array, slice: [elem0 elem1 ...] + maps: map[key1:value1 key2:value2 ...] + pointer to above: &{}, &[], &map[] + +Width is specified by an optional decimal number immediately preceding the verb. +If absent, the width is whatever is necessary to represent the value. +Precision is specified after the (optional) width by a period followed by a +decimal number. If no period is present, a default precision is used. +A period with no following number specifies a precision of zero. +Examples: + %f default width, default precision + %9f width 9, default precision + %.2f default width, precision 2 + %9.2f width 9, precision 2 + %9.f width 9, precision 0 + +Width and precision are measured in units of Unicode code points, +that is, runes. (This differs from C's printf where the +units are always measured in bytes.) Either or both of the flags +may be replaced with the character '*', causing their values to be +obtained from the next operand (preceding the one to format), +which must be of type int. + +For most values, width is the minimum number of runes to output, +padding the formatted form with spaces if necessary. + +For strings, byte slices and byte arrays, however, precision +limits the length of the input to be formatted (not the size of +the output), truncating if necessary. Normally it is measured in +runes, but for these types when formatted with the %x or %X format +it is measured in bytes. + +For floating-point values, width sets the minimum width of the field and +precision sets the number of places after the decimal, if appropriate, +except that for %g/%G precision sets the maximum number of significant +digits (trailing zeros are removed). For example, given 12.345 the format +%6.3f prints 12.345 while %.3g prints 12.3. The default precision for %e, %f +and %#g is 6; for %g it is the smallest number of digits necessary to identify +the value uniquely. + +For complex numbers, the width and precision apply to the two +components independently and the result is parenthesized, so %f applied +to 1.2+3.4i produces (1.200000+3.400000i). + +Other flags: + + always print a sign for numeric values; + guarantee ASCII-only output for %q (%+q) + - pad with spaces on the right rather than the left (left-justify the field) + # alternate format: add leading 0b for binary (%#b), 0 for octal (%#o), + 0x or 0X for hex (%#x or %#X); suppress 0x for %p (%#p); + for %q, print a raw (backquoted) string if strconv.CanBackquote + returns true; + always print a decimal point for %e, %E, %f, %F, %g and %G; + do not remove trailing zeros for %g and %G; + write e.g. U+0078 'x' if the character is printable for %U (%#U). + ' ' (space) leave a space for elided sign in numbers (% d); + put spaces between bytes printing strings or slices in hex (% x, % X) + 0 pad with leading zeros rather than spaces; + for numbers, this moves the padding after the sign; + ignored for strings, byte slices and byte arrays + +Flags are ignored by verbs that do not expect them. +For example there is no alternate decimal format, so %#d and %d +behave identically. + +For each Printf-like function, there is also a Print function +that takes no format and is equivalent to saying %v for every +operand. Another variant Println inserts blanks between +operands and appends a newline. + +Regardless of the verb, if an operand is an interface value, +the internal concrete value is used, not the interface itself. +Thus: + var i interface{} = 23 + fmt.Printf("%v\n", i) +will print 23. + +Except when printed using the verbs %T and %p, special +formatting considerations apply for operands that implement +certain interfaces. In order of application: + +1. If the operand is a reflect.Value, the operand is replaced by the +concrete value that it holds, and printing continues with the next rule. + +2. If an operand implements the Formatter interface, it will +be invoked. In this case the interpretation of verbs and flags is +controlled by that implementation. + +3. If the %v verb is used with the # flag (%#v) and the operand +implements the GoStringer interface, that will be invoked. + +If the format (which is implicitly %v for Println etc.) is valid +for a string (%s %q %v %x %X), the following two rules apply: + +4. If an operand implements the error interface, the Error method +will be invoked to convert the object to a string, which will then +be formatted as required by the verb (if any). + +5. If an operand implements method String() string, that method +will be invoked to convert the object to a string, which will then +be formatted as required by the verb (if any). + +For compound operands such as slices and structs, the format +applies to the elements of each operand, recursively, not to the +operand as a whole. Thus %q will quote each element of a slice +of strings, and %6.2f will control formatting for each element +of a floating-point array. + +However, when printing a byte slice with a string-like verb +(%s %q %x %X), it is treated identically to a string, as a single item. + +To avoid recursion in cases such as + type X string + func (x X) String() string { return Sprintf("<%s>", x) } +convert the value before recurring: + func (x X) String() string { return Sprintf("<%s>", string(x)) } +Infinite recursion can also be triggered by self-referential data +structures, such as a slice that contains itself as an element, if +that type has a String method. Such pathologies are rare, however, +and the package does not protect against them. + +When printing a struct, fmt cannot and therefore does not invoke +formatting methods such as Error or String on unexported fields. + +Explicit argument indexes + +In Printf, Sprintf, and Fprintf, the default behavior is for each +formatting verb to format successive arguments passed in the call. +However, the notation [n] immediately before the verb indicates that the +nth one-indexed argument is to be formatted instead. The same notation +before a '*' for a width or precision selects the argument index holding +the value. After processing a bracketed expression [n], subsequent verbs +will use arguments n+1, n+2, etc. unless otherwise directed. + +For example, + fmt.Sprintf("%[2]d %[1]d\n", 11, 22) +will yield "22 11", while + fmt.Sprintf("%[3]*.[2]*[1]f", 12.0, 2, 6) +equivalent to + fmt.Sprintf("%6.2f", 12.0) +will yield " 12.00". Because an explicit index affects subsequent verbs, +this notation can be used to print the same values multiple times +by resetting the index for the first argument to be repeated: + fmt.Sprintf("%d %d %#[1]x %#x", 16, 17) +will yield "16 17 0x10 0x11". + +Format errors + +If an invalid argument is given for a verb, such as providing +a string to %d, the generated string will contain a +description of the problem, as in these examples: + + Wrong type or unknown verb: %!verb(type=value) + Printf("%d", "hi"): %!d(string=hi) + Too many arguments: %!(EXTRA type=value) + Printf("hi", "guys"): hi%!(EXTRA string=guys) + Too few arguments: %!verb(MISSING) + Printf("hi%d"): hi%!d(MISSING) + Non-int for width or precision: %!(BADWIDTH) or %!(BADPREC) + Printf("%*s", 4.5, "hi"): %!(BADWIDTH)hi + Printf("%.*s", 4.5, "hi"): %!(BADPREC)hi + Invalid or invalid use of argument index: %!(BADINDEX) + Printf("%*[2]d", 7): %!d(BADINDEX) + Printf("%.[2]d", 7): %!d(BADINDEX) + +All errors begin with the string "%!" followed sometimes +by a single character (the verb) and end with a parenthesized +description. + +If an Error or String method triggers a panic when called by a +print routine, the fmt package reformats the error message +from the panic, decorating it with an indication that it came +through the fmt package. For example, if a String method +calls panic("bad"), the resulting formatted message will look +like + %!s(PANIC=bad) + +The %!s just shows the print verb in use when the failure +occurred. If the panic is caused by a nil receiver to an Error +or String method, however, the output is the undecorated +string, "". + +Scanning + +An analogous set of functions scans formatted text to yield +values. Scan, Scanf and Scanln read from os.Stdin; Fscan, +Fscanf and Fscanln read from a specified io.Reader; Sscan, +Sscanf and Sscanln read from an argument string. + +Scan, Fscan, Sscan treat newlines in the input as spaces. + +Scanln, Fscanln and Sscanln stop scanning at a newline and +require that the items be followed by a newline or EOF. + +Scanf, Fscanf, and Sscanf parse the arguments according to a +format string, analogous to that of Printf. In the text that +follows, 'space' means any Unicode whitespace character +except newline. + +In the format string, a verb introduced by the % character +consumes and parses input; these verbs are described in more +detail below. A character other than %, space, or newline in +the format consumes exactly that input character, which must +be present. A newline with zero or more spaces before it in +the format string consumes zero or more spaces in the input +followed by a single newline or the end of the input. A space +following a newline in the format string consumes zero or more +spaces in the input. Otherwise, any run of one or more spaces +in the format string consumes as many spaces as possible in +the input. Unless the run of spaces in the format string +appears adjacent to a newline, the run must consume at least +one space from the input or find the end of the input. + +The handling of spaces and newlines differs from that of C's +scanf family: in C, newlines are treated as any other space, +and it is never an error when a run of spaces in the format +string finds no spaces to consume in the input. + +The verbs behave analogously to those of Printf. +For example, %x will scan an integer as a hexadecimal number, +and %v will scan the default representation format for the value. +The Printf verbs %p and %T and the flags # and + are not implemented. +For floating-point and complex values, all valid formatting verbs +(%b %e %E %f %F %g %G %x %X and %v) are equivalent and accept +both decimal and hexadecimal notation (for example: "2.3e+7", "0x4.5p-8") +and digit-separating underscores (for example: "3.14159_26535_89793"). + +Input processed by verbs is implicitly space-delimited: the +implementation of every verb except %c starts by discarding +leading spaces from the remaining input, and the %s verb +(and %v reading into a string) stops consuming input at the first +space or newline character. + +The familiar base-setting prefixes 0b (binary), 0o and 0 (octal), +and 0x (hexadecimal) are accepted when scanning integers +without a format or with the %v verb, as are digit-separating +underscores. + +Width is interpreted in the input text but there is no +syntax for scanning with a precision (no %5.2f, just %5f). +If width is provided, it applies after leading spaces are +trimmed and specifies the maximum number of runes to read +to satisfy the verb. For example, + Sscanf(" 1234567 ", "%5s%d", &s, &i) +will set s to "12345" and i to 67 while + Sscanf(" 12 34 567 ", "%5s%d", &s, &i) +will set s to "12" and i to 34. + +In all the scanning functions, a carriage return followed +immediately by a newline is treated as a plain newline +(\r\n means the same as \n). + +In all the scanning functions, if an operand implements method +Scan (that is, it implements the Scanner interface) that +method will be used to scan the text for that operand. Also, +if the number of arguments scanned is less than the number of +arguments provided, an error is returned. + +All arguments to be scanned must be either pointers to basic +types or implementations of the Scanner interface. + +Like Scanf and Fscanf, Sscanf need not consume its entire input. +There is no way to recover how much of the input string Sscanf used. + +Note: Fscan etc. can read one character (rune) past the input +they return, which means that a loop calling a scan routine +may skip some of the input. This is usually a problem only +when there is no space between input values. If the reader +provided to Fscan implements ReadRune, that method will be used +to read characters. If the reader also implements UnreadRune, +that method will be used to save the character and successive +calls will not lose data. To attach ReadRune and UnreadRune +methods to a reader without that capability, use +bufio.NewReader. */ package fmt diff --git a/src/go/doc/headscan.go b/src/go/doc/headscan.go index 320895e43a4..f55ca754a65 100644 --- a/src/go/doc/headscan.go +++ b/src/go/doc/headscan.go @@ -5,13 +5,13 @@ //go:build ignore /* - The headscan command extracts comment headings from package files; - it is used to detect false positives which may require an adjustment - to the comment formatting heuristics in comment.go. +The headscan command extracts comment headings from package files; +it is used to detect false positives which may require an adjustment +to the comment formatting heuristics in comment.go. - Usage: headscan [-root root_directory] +Usage: headscan [-root root_directory] - By default, the $GOROOT/src directory is scanned. +By default, the $GOROOT/src directory is scanned. */ package main diff --git a/src/net/rpc/server.go b/src/net/rpc/server.go index d5207a42cf1..f53ea75f9ce 100644 --- a/src/net/rpc/server.go +++ b/src/net/rpc/server.go @@ -3,126 +3,126 @@ // license that can be found in the LICENSE file. /* - Package rpc provides access to the exported methods of an object across a - network or other I/O connection. A server registers an object, making it visible - as a service with the name of the type of the object. After registration, exported - methods of the object will be accessible remotely. A server may register multiple - objects (services) of different types but it is an error to register multiple - objects of the same type. +Package rpc provides access to the exported methods of an object across a +network or other I/O connection. A server registers an object, making it visible +as a service with the name of the type of the object. After registration, exported +methods of the object will be accessible remotely. A server may register multiple +objects (services) of different types but it is an error to register multiple +objects of the same type. - Only methods that satisfy these criteria will be made available for remote access; - other methods will be ignored: +Only methods that satisfy these criteria will be made available for remote access; +other methods will be ignored: - - the method's type is exported. - - the method is exported. - - the method has two arguments, both exported (or builtin) types. - - the method's second argument is a pointer. - - the method has return type error. + - the method's type is exported. + - the method is exported. + - the method has two arguments, both exported (or builtin) types. + - the method's second argument is a pointer. + - the method has return type error. - In effect, the method must look schematically like +In effect, the method must look schematically like - func (t *T) MethodName(argType T1, replyType *T2) error + func (t *T) MethodName(argType T1, replyType *T2) error - where T1 and T2 can be marshaled by encoding/gob. - These requirements apply even if a different codec is used. - (In the future, these requirements may soften for custom codecs.) +where T1 and T2 can be marshaled by encoding/gob. +These requirements apply even if a different codec is used. +(In the future, these requirements may soften for custom codecs.) - The method's first argument represents the arguments provided by the caller; the - second argument represents the result parameters to be returned to the caller. - The method's return value, if non-nil, is passed back as a string that the client - sees as if created by errors.New. If an error is returned, the reply parameter - will not be sent back to the client. +The method's first argument represents the arguments provided by the caller; the +second argument represents the result parameters to be returned to the caller. +The method's return value, if non-nil, is passed back as a string that the client +sees as if created by errors.New. If an error is returned, the reply parameter +will not be sent back to the client. - The server may handle requests on a single connection by calling ServeConn. More - typically it will create a network listener and call Accept or, for an HTTP - listener, HandleHTTP and http.Serve. +The server may handle requests on a single connection by calling ServeConn. More +typically it will create a network listener and call Accept or, for an HTTP +listener, HandleHTTP and http.Serve. - A client wishing to use the service establishes a connection and then invokes - NewClient on the connection. The convenience function Dial (DialHTTP) performs - both steps for a raw network connection (an HTTP connection). The resulting - Client object has two methods, Call and Go, that specify the service and method to - call, a pointer containing the arguments, and a pointer to receive the result - parameters. +A client wishing to use the service establishes a connection and then invokes +NewClient on the connection. The convenience function Dial (DialHTTP) performs +both steps for a raw network connection (an HTTP connection). The resulting +Client object has two methods, Call and Go, that specify the service and method to +call, a pointer containing the arguments, and a pointer to receive the result +parameters. - The Call method waits for the remote call to complete while the Go method - launches the call asynchronously and signals completion using the Call - structure's Done channel. +The Call method waits for the remote call to complete while the Go method +launches the call asynchronously and signals completion using the Call +structure's Done channel. - Unless an explicit codec is set up, package encoding/gob is used to - transport the data. +Unless an explicit codec is set up, package encoding/gob is used to +transport the data. - Here is a simple example. A server wishes to export an object of type Arith: +Here is a simple example. A server wishes to export an object of type Arith: - package server + package server - import "errors" + import "errors" - type Args struct { - A, B int - } + type Args struct { + A, B int + } - type Quotient struct { - Quo, Rem int - } + type Quotient struct { + Quo, Rem int + } - type Arith int + type Arith int - func (t *Arith) Multiply(args *Args, reply *int) error { - *reply = args.A * args.B - return nil - } + func (t *Arith) Multiply(args *Args, reply *int) error { + *reply = args.A * args.B + return nil + } - func (t *Arith) Divide(args *Args, quo *Quotient) error { - if args.B == 0 { - return errors.New("divide by zero") - } - quo.Quo = args.A / args.B - quo.Rem = args.A % args.B - return nil + func (t *Arith) Divide(args *Args, quo *Quotient) error { + if args.B == 0 { + return errors.New("divide by zero") } + quo.Quo = args.A / args.B + quo.Rem = args.A % args.B + return nil + } - The server calls (for HTTP service): +The server calls (for HTTP service): - arith := new(Arith) - rpc.Register(arith) - rpc.HandleHTTP() - l, e := net.Listen("tcp", ":1234") - if e != nil { - log.Fatal("listen error:", e) - } - go http.Serve(l, nil) + arith := new(Arith) + rpc.Register(arith) + rpc.HandleHTTP() + l, e := net.Listen("tcp", ":1234") + if e != nil { + log.Fatal("listen error:", e) + } + go http.Serve(l, nil) - At this point, clients can see a service "Arith" with methods "Arith.Multiply" and - "Arith.Divide". To invoke one, a client first dials the server: +At this point, clients can see a service "Arith" with methods "Arith.Multiply" and +"Arith.Divide". To invoke one, a client first dials the server: - client, err := rpc.DialHTTP("tcp", serverAddress + ":1234") - if err != nil { - log.Fatal("dialing:", err) - } + client, err := rpc.DialHTTP("tcp", serverAddress + ":1234") + if err != nil { + log.Fatal("dialing:", err) + } - Then it can make a remote call: +Then it can make a remote call: - // Synchronous call - args := &server.Args{7,8} - var reply int - err = client.Call("Arith.Multiply", args, &reply) - if err != nil { - log.Fatal("arith error:", err) - } - fmt.Printf("Arith: %d*%d=%d", args.A, args.B, reply) + // Synchronous call + args := &server.Args{7,8} + var reply int + err = client.Call("Arith.Multiply", args, &reply) + if err != nil { + log.Fatal("arith error:", err) + } + fmt.Printf("Arith: %d*%d=%d", args.A, args.B, reply) - or +or - // Asynchronous call - quotient := new(Quotient) - divCall := client.Go("Arith.Divide", args, quotient, nil) - replyCall := <-divCall.Done // will be equal to divCall - // check errors, print, etc. + // Asynchronous call + quotient := new(Quotient) + divCall := client.Go("Arith.Divide", args, quotient, nil) + replyCall := <-divCall.Done // will be equal to divCall + // check errors, print, etc. - A server implementation will often provide a simple, type-safe wrapper for the - client. +A server implementation will often provide a simple, type-safe wrapper for the +client. - The net/rpc package is frozen and is not accepting new features. +The net/rpc package is frozen and is not accepting new features. */ package rpc diff --git a/src/runtime/debug/stack_test.go b/src/runtime/debug/stack_test.go index 9376e82b845..4cab8864df4 100644 --- a/src/runtime/debug/stack_test.go +++ b/src/runtime/debug/stack_test.go @@ -20,22 +20,22 @@ func (t T) method() []byte { } /* - The traceback should look something like this, modulo line numbers and hex constants. - Don't worry much about the base levels, but check the ones in our own package. +The traceback should look something like this, modulo line numbers and hex constants. +Don't worry much about the base levels, but check the ones in our own package. - goroutine 10 [running]: - runtime/debug.Stack(0x0, 0x0, 0x0) - /Users/r/go/src/runtime/debug/stack.go:28 +0x80 - runtime/debug.(*T).ptrmethod(0xc82005ee70, 0x0, 0x0, 0x0) - /Users/r/go/src/runtime/debug/stack_test.go:15 +0x29 - runtime/debug.T.method(0x0, 0x0, 0x0, 0x0) - /Users/r/go/src/runtime/debug/stack_test.go:18 +0x32 - runtime/debug.TestStack(0xc8201ce000) - /Users/r/go/src/runtime/debug/stack_test.go:37 +0x38 - testing.tRunner(0xc8201ce000, 0x664b58) - /Users/r/go/src/testing/testing.go:456 +0x98 - created by testing.RunTests - /Users/r/go/src/testing/testing.go:561 +0x86d + goroutine 10 [running]: + runtime/debug.Stack(0x0, 0x0, 0x0) + /Users/r/go/src/runtime/debug/stack.go:28 +0x80 + runtime/debug.(*T).ptrmethod(0xc82005ee70, 0x0, 0x0, 0x0) + /Users/r/go/src/runtime/debug/stack_test.go:15 +0x29 + runtime/debug.T.method(0x0, 0x0, 0x0, 0x0) + /Users/r/go/src/runtime/debug/stack_test.go:18 +0x32 + runtime/debug.TestStack(0xc8201ce000) + /Users/r/go/src/runtime/debug/stack_test.go:37 +0x38 + testing.tRunner(0xc8201ce000, 0x664b58) + /Users/r/go/src/testing/testing.go:456 +0x98 + created by testing.RunTests + /Users/r/go/src/testing/testing.go:561 +0x86d */ func TestStack(t *testing.T) { b := T(0).method() diff --git a/src/unsafe/unsafe.go b/src/unsafe/unsafe.go index 16e3890d0be..a6a255658b6 100644 --- a/src/unsafe/unsafe.go +++ b/src/unsafe/unsafe.go @@ -3,10 +3,10 @@ // license that can be found in the LICENSE file. /* - Package unsafe contains operations that step around the type safety of Go programs. +Package unsafe contains operations that step around the type safety of Go programs. - Packages that import unsafe may be non-portable and are not protected by the - Go 1 compatibility guidelines. +Packages that import unsafe may be non-portable and are not protected by the +Go 1 compatibility guidelines. */ package unsafe From 4e26ab0ed891530cd07174813b89cea04b0fa559 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Mon, 14 Mar 2022 10:29:51 -0700 Subject: [PATCH 103/276] cmd/go: document that 'go run' strips debug info Change-Id: Ie7293a33862853ac56ee0a9017b201d8ff0ba1f0 Reviewed-on: https://go-review.googlesource.com/c/go/+/392574 Trust: Ian Lance Taylor Run-TryBot: Ian Lance Taylor TryBot-Result: Gopher Robot Reviewed-by: Bryan Mills --- src/cmd/go/alldocs.go | 4 ++++ src/cmd/go/internal/run/run.go | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/cmd/go/alldocs.go b/src/cmd/go/alldocs.go index 825de1e64a8..8410731a28a 100644 --- a/src/cmd/go/alldocs.go +++ b/src/cmd/go/alldocs.go @@ -1599,6 +1599,10 @@ // cross-compiled programs when a simulator or other execution method is // available. // +// By default, 'go run' compiles the binary without generating the information +// used by debuggers, to reduce build time. To include debugger information in +// the binary, use 'go build'. +// // The exit status of Run is not the exit status of the compiled binary. // // For more about build flags, see 'go help build'. diff --git a/src/cmd/go/internal/run/run.go b/src/cmd/go/internal/run/run.go index 312b49ef5df..35c57833730 100644 --- a/src/cmd/go/internal/run/run.go +++ b/src/cmd/go/internal/run/run.go @@ -52,6 +52,10 @@ for example 'go_js_wasm_exec a.out arguments...'. This allows execution of cross-compiled programs when a simulator or other execution method is available. +By default, 'go run' compiles the binary without generating the information +used by debuggers, to reduce build time. To include debugger information in +the binary, use 'go build'. + The exit status of Run is not the exit status of the compiled binary. For more about build flags, see 'go help build'. From 201a2e9c2f82dd2c57c8e79bbe2c028d7c13b8ea Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Wed, 2 Mar 2022 15:49:27 -0800 Subject: [PATCH 104/276] compress/gzip: add example of compressing reader For #51092 Change-Id: If0a233651ac75f113569ddfffd056084f6092564 Reviewed-on: https://go-review.googlesource.com/c/go/+/389514 Trust: Ian Lance Taylor Run-TryBot: Ian Lance Taylor Reviewed-by: Joseph Tsai TryBot-Result: Gopher Robot --- src/compress/gzip/example_test.go | 87 +++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/src/compress/gzip/example_test.go b/src/compress/gzip/example_test.go index ce29e9ba365..27aae152d40 100644 --- a/src/compress/gzip/example_test.go +++ b/src/compress/gzip/example_test.go @@ -10,7 +10,10 @@ import ( "fmt" "io" "log" + "net/http" + "net/http/httptest" "os" + "strings" "time" ) @@ -126,3 +129,87 @@ func ExampleReader_Multistream() { // // Hello Gophers - 2 } + +func Example_compressingReader() { + // This is an example of writing a compressing reader. + // This can be useful for an HTTP client body, as shown. + + const testdata = "the data to be compressed" + + // This HTTP handler is just for testing purposes. + handler := http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { + zr, err := gzip.NewReader(req.Body) + if err != nil { + log.Fatal(err) + } + + // Just output the data for the example. + if _, err := io.Copy(os.Stdout, zr); err != nil { + log.Fatal(err) + } + }) + ts := httptest.NewServer(handler) + defer ts.Close() + + // The remainder is the example code. + + // The data we want to compress, as an io.Reader + dataReader := strings.NewReader(testdata) + + // bodyReader is the body of the HTTP request, as an io.Reader. + // httpWriter is the body of the HTTP request, as an io.Writer. + bodyReader, httpWriter := io.Pipe() + + // gzipWriter compresses data to httpWriter. + gzipWriter := gzip.NewWriter(httpWriter) + + // errch collects any errors from the writing goroutine. + errch := make(chan error, 1) + + go func() { + defer close(errch) + sentErr := false + sendErr := func(err error) { + if !sentErr { + errch <- err + sentErr = true + } + } + + // Copy our data to gzipWriter, which compresses it to + // gzipWriter, which feeds it to bodyReader. + if _, err := io.Copy(gzipWriter, dataReader); err != nil && err != io.ErrClosedPipe { + sendErr(err) + } + if err := gzipWriter.Close(); err != nil && err != io.ErrClosedPipe { + sendErr(err) + } + if err := httpWriter.Close(); err != nil && err != io.ErrClosedPipe { + sendErr(err) + } + }() + + // Send an HTTP request to the test server. + req, err := http.NewRequest("PUT", ts.URL, bodyReader) + if err != nil { + log.Fatal(err) + } + + // Note that passing req to http.Client.Do promises that it + // will close the body, in this case bodyReader. + // That ensures that the goroutine will exit. + resp, err := ts.Client().Do(req) + if err != nil { + log.Fatal(err) + } + + // Check whether there was an error compressing the data. + if err := <-errch; err != nil { + log.Fatal(err) + } + + // For this example we don't care about the response. + resp.Body.Close() + + // Output: the data to be compressed +} From b4428325e266d8ffdd1131d71862f0767c616e27 Mon Sep 17 00:00:00 2001 From: Bryan Mills Date: Tue, 15 Mar 2022 17:49:01 +0000 Subject: [PATCH 105/276] Revert "os: raise open file rlimit at startup" This reverts CL 392415. Reason for revert: new test is failing on at least darwin-amd64-10_14, darwin-amd64-10_15, and openbsd-arm64-jsing. Updates #46279. Change-Id: I2890b72f8ee74f31000d65f7d47b5bb0ed5d6007 Reviewed-on: https://go-review.googlesource.com/c/go/+/393016 Trust: Bryan Mills Run-TryBot: Bryan Mills Reviewed-by: Russ Cox --- src/os/rlimit.go | 31 ------------------------------- src/os/rlimit_test.go | 32 -------------------------------- 2 files changed, 63 deletions(-) delete mode 100644 src/os/rlimit.go delete mode 100644 src/os/rlimit_test.go diff --git a/src/os/rlimit.go b/src/os/rlimit.go deleted file mode 100644 index 3e29db95629..00000000000 --- a/src/os/rlimit.go +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2022 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 os - -import "syscall" - -// Some systems set an artificially low soft limit on open file count, for compatibility -// with code that uses select and its hard-coded maximum file descriptor -// (limited by the size of fd_set). -// -// Go does not use select, so it should not be subject to these limits. -// On some systems the limit is 256, which is very easy to run into, -// even in simple programs like gofmt when they parallelize walking -// a file tree. -// -// After a long discussion on go.dev/issue/46279, we decided the -// best approach was for Go to raise the limit unconditionally for itself, -// and then leave old software to set the limit back as needed. -// Code that really wants Go to leave the limit alone can set the hard limit, -// which Go of course has no choice but to respect. -func init() { - var lim syscall.Rlimit - if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &lim); err == nil && lim.Cur != lim.Max { - lim.Cur = lim.Max - syscall.Setrlimit(syscall.RLIMIT_NOFILE, &lim) - } -} diff --git a/src/os/rlimit_test.go b/src/os/rlimit_test.go deleted file mode 100644 index 9bb6858a867..00000000000 --- a/src/os/rlimit_test.go +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2022 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 os_test - -import ( - . "os" - "testing" -) - -func TestOpenFileLimit(t *testing.T) { - // For open file count, - // macOS sets the default soft limit to 256 and no hard limit. - // CentOS and Fedora set the default soft limit to 1024, - // with hard limits of 4096 and 524288, respectively. - // Check that we can open 1200 files, which proves - // that the rlimit is being raised appropriately on those systems. - var files []*File - for i := 0; i < 1200; i++ { - f, err := Open("rlimit.go") - if err != nil { - t.Error(err) - break - } - files = append(files, f) - } - - for _, f := range files { - f.Close() - } -} From db3045b4be5b91cd42c3387dc550c89bbc2f7fb4 Mon Sep 17 00:00:00 2001 From: Cherry Mui Date: Thu, 24 Feb 2022 23:44:05 -0500 Subject: [PATCH 106/276] cmd/asm: support -d=pctab flag To debug PC data generation. Change-Id: Id7ac8d607cc27ad52db490bd758c3a768c3e1df2 Reviewed-on: https://go-review.googlesource.com/c/go/+/388015 Trust: Cherry Mui Run-TryBot: Cherry Mui Reviewed-by: Than McIntosh TryBot-Result: Gopher Robot --- src/cmd/asm/internal/flags/flags.go | 1 + src/cmd/asm/main.go | 1 + 2 files changed, 2 insertions(+) diff --git a/src/cmd/asm/internal/flags/flags.go b/src/cmd/asm/internal/flags/flags.go index 607166e664d..273d4223709 100644 --- a/src/cmd/asm/internal/flags/flags.go +++ b/src/cmd/asm/internal/flags/flags.go @@ -30,6 +30,7 @@ var ( var DebugFlags struct { MayMoreStack string `help:"call named function before all stack growth checks"` + PCTab string `help:"print named pc-value table\nOne of: pctospadj, pctofile, pctoline, pctoinline, pctopcdata"` } var ( diff --git a/src/cmd/asm/main.go b/src/cmd/asm/main.go index 3683527f5b8..6a25fd426b7 100644 --- a/src/cmd/asm/main.go +++ b/src/cmd/asm/main.go @@ -43,6 +43,7 @@ func main() { ctxt.Flag_linkshared = *flags.Linkshared ctxt.Flag_shared = *flags.Shared || *flags.Dynlink ctxt.Flag_maymorestack = flags.DebugFlags.MayMoreStack + ctxt.Debugpcln = flags.DebugFlags.PCTab ctxt.IsAsm = true ctxt.Pkgpath = *flags.Importpath switch *flags.Spectre { From 0d71234ee4cfcac4a6664d8fef4be575cca1d7c7 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Tue, 15 Mar 2022 13:36:10 -0400 Subject: [PATCH 107/276] reflect: avoid panic in reflect.Kind.String for negative Kind Kind(-1).String() used to panic; let's not. Change-Id: I1dfc0e3298beb37d77713d8327579bbde90dd156 Reviewed-on: https://go-review.googlesource.com/c/go/+/393015 Trust: Russ Cox Reviewed-by: Ian Lance Taylor --- src/reflect/all_test.go | 9 +++++++++ src/reflect/type.go | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/reflect/all_test.go b/src/reflect/all_test.go index 5364166eab4..06026232eea 100644 --- a/src/reflect/all_test.go +++ b/src/reflect/all_test.go @@ -7807,3 +7807,12 @@ func TestIssue50208(t *testing.T) { t.Errorf("name of type parameter mismatched, want:%s, got:%s", want2, got) } } + +func TestNegativeKindString(t *testing.T) { + x := -1 + s := Kind(x).String() + want := "kind-1" + if s != want { + t.Fatalf("Kind(-1).String() = %q, want %q", s, want) + } +} diff --git a/src/reflect/type.go b/src/reflect/type.go index 8ba63bcad05..83047062bdb 100644 --- a/src/reflect/type.go +++ b/src/reflect/type.go @@ -632,8 +632,8 @@ const ( // String returns the name of k. func (k Kind) String() string { - if int(k) < len(kindNames) { - return kindNames[k] + if uint(k) < uint(len(kindNames)) { + return kindNames[uint(k)] } return "kind" + strconv.Itoa(int(k)) } From 1cb34fbb26a406faa64f696242841ddff64517c9 Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Tue, 1 Feb 2022 17:45:28 -0800 Subject: [PATCH 108/276] go/types, cmd/compile: remove unused Interface.obj field Change-Id: I6d0f629f9c7379074a03c8f13b99924d872872a3 Reviewed-on: https://go-review.googlesource.com/c/go/+/385996 Trust: Matthew Dempsky Run-TryBot: Matthew Dempsky Reviewed-by: David Chase TryBot-Result: Gopher Robot Reviewed-by: Robert Findley --- src/cmd/compile/internal/types2/interface.go | 1 - src/cmd/compile/internal/types2/sizeof_test.go | 2 +- src/cmd/compile/internal/types2/typexpr.go | 3 --- src/cmd/compile/internal/types2/universe.go | 4 ++-- src/go/types/interface.go | 1 - src/go/types/sizeof_test.go | 2 +- src/go/types/typexpr.go | 3 --- src/go/types/universe.go | 4 ++-- 8 files changed, 6 insertions(+), 14 deletions(-) diff --git a/src/cmd/compile/internal/types2/interface.go b/src/cmd/compile/internal/types2/interface.go index 75597abaf9c..b8bf88dc624 100644 --- a/src/cmd/compile/internal/types2/interface.go +++ b/src/cmd/compile/internal/types2/interface.go @@ -12,7 +12,6 @@ import "cmd/compile/internal/syntax" // An Interface represents an interface type. type Interface struct { check *Checker // for error reporting; nil once type set is computed - obj *TypeName // corresponding declared object; or nil (for better error messages) methods []*Func // ordered list of explicitly declared methods embeddeds []Type // ordered list of explicitly embedded elements embedPos *[]syntax.Pos // positions of embedded elements; or nil (for error messages) - use pointer to save space diff --git a/src/cmd/compile/internal/types2/sizeof_test.go b/src/cmd/compile/internal/types2/sizeof_test.go index 14020050a93..bd31a041b76 100644 --- a/src/cmd/compile/internal/types2/sizeof_test.go +++ b/src/cmd/compile/internal/types2/sizeof_test.go @@ -28,7 +28,7 @@ func TestSizeof(t *testing.T) { {Tuple{}, 12, 24}, {Signature{}, 28, 56}, {Union{}, 12, 24}, - {Interface{}, 44, 88}, + {Interface{}, 40, 80}, {Map{}, 16, 32}, {Chan{}, 12, 24}, {Named{}, 56, 104}, diff --git a/src/cmd/compile/internal/types2/typexpr.go b/src/cmd/compile/internal/types2/typexpr.go index 7e30562e972..40333fd77f9 100644 --- a/src/cmd/compile/internal/types2/typexpr.go +++ b/src/cmd/compile/internal/types2/typexpr.go @@ -348,9 +348,6 @@ func (check *Checker) typInternal(e0 syntax.Expr, def *Named) (T Type) { case *syntax.InterfaceType: typ := check.newInterface() def.setUnderlying(typ) - if def != nil { - typ.obj = def.obj - } check.interfaceType(typ, e, def) return typ diff --git a/src/cmd/compile/internal/types2/universe.go b/src/cmd/compile/internal/types2/universe.go index 11c81863a98..1deff3961f5 100644 --- a/src/cmd/compile/internal/types2/universe.go +++ b/src/cmd/compile/internal/types2/universe.go @@ -97,7 +97,7 @@ func defPredeclaredTypes() { err := NewFunc(nopos, nil, "Error", sig) // interface{ Error() string } - ityp := &Interface{obj: obj, methods: []*Func{err}, complete: true} + ityp := &Interface{methods: []*Func{err}, complete: true} computeInterfaceTypeSet(nil, nopos, ityp) // prevent races due to lazy computation of tset typ.SetUnderlying(ityp) @@ -111,7 +111,7 @@ func defPredeclaredTypes() { typ := NewNamed(obj, nil, nil) // interface{} // marked as comparable - ityp := &Interface{obj: obj, complete: true, tset: &_TypeSet{nil, allTermlist, true}} + ityp := &Interface{complete: true, tset: &_TypeSet{nil, allTermlist, true}} typ.SetUnderlying(ityp) def(obj) diff --git a/src/go/types/interface.go b/src/go/types/interface.go index 3db3580a91b..361ef7eddf6 100644 --- a/src/go/types/interface.go +++ b/src/go/types/interface.go @@ -15,7 +15,6 @@ import ( // An Interface represents an interface type. type Interface struct { check *Checker // for error reporting; nil once type set is computed - obj *TypeName // type name object defining this interface; or nil (for better error messages) methods []*Func // ordered list of explicitly declared methods embeddeds []Type // ordered list of explicitly embedded elements embedPos *[]token.Pos // positions of embedded elements; or nil (for error messages) - use pointer to save space diff --git a/src/go/types/sizeof_test.go b/src/go/types/sizeof_test.go index bfd14a81098..ba8edf8ad58 100644 --- a/src/go/types/sizeof_test.go +++ b/src/go/types/sizeof_test.go @@ -27,7 +27,7 @@ func TestSizeof(t *testing.T) { {Tuple{}, 12, 24}, {Signature{}, 28, 56}, {Union{}, 12, 24}, - {Interface{}, 44, 88}, + {Interface{}, 40, 80}, {Map{}, 16, 32}, {Chan{}, 12, 24}, {Named{}, 56, 104}, diff --git a/src/go/types/typexpr.go b/src/go/types/typexpr.go index 5bb2d8f8112..d72b48185ad 100644 --- a/src/go/types/typexpr.go +++ b/src/go/types/typexpr.go @@ -329,9 +329,6 @@ func (check *Checker) typInternal(e0 ast.Expr, def *Named) (T Type) { case *ast.InterfaceType: typ := check.newInterface() def.setUnderlying(typ) - if def != nil { - typ.obj = def.obj - } check.interfaceType(typ, e, def) return typ diff --git a/src/go/types/universe.go b/src/go/types/universe.go index 303ada4e57b..f58128f480e 100644 --- a/src/go/types/universe.go +++ b/src/go/types/universe.go @@ -98,7 +98,7 @@ func defPredeclaredTypes() { err := NewFunc(token.NoPos, nil, "Error", sig) // interface{ Error() string } - ityp := &Interface{obj: obj, methods: []*Func{err}, complete: true} + ityp := &Interface{methods: []*Func{err}, complete: true} computeInterfaceTypeSet(nil, token.NoPos, ityp) // prevent races due to lazy computation of tset typ.SetUnderlying(ityp) @@ -112,7 +112,7 @@ func defPredeclaredTypes() { typ := NewNamed(obj, nil, nil) // interface{} // marked as comparable - ityp := &Interface{obj: obj, complete: true, tset: &_TypeSet{nil, allTermlist, true}} + ityp := &Interface{complete: true, tset: &_TypeSet{nil, allTermlist, true}} typ.SetUnderlying(ityp) def(obj) From 6e49c592de91fd7ea7d47aa50360a1c4f49172f8 Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Mon, 14 Feb 2022 17:20:48 -0800 Subject: [PATCH 109/276] go/types: return Universe for (*Package)(nil).Scope() Port of go.dev/cl/325469. Fixes #46594. Change-Id: I4bcdafecaa86885360599c204678871646bb221b Reviewed-on: https://go-review.googlesource.com/c/go/+/385997 Trust: Matthew Dempsky Run-TryBot: Matthew Dempsky Reviewed-by: David Chase TryBot-Result: Gopher Robot Reviewed-by: Robert Findley --- src/go/types/package.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/go/types/package.go b/src/go/types/package.go index 7b89def1b5d..26385dc39b9 100644 --- a/src/go/types/package.go +++ b/src/go/types/package.go @@ -39,7 +39,13 @@ func (pkg *Package) SetName(name string) { pkg.name = name } // Scope returns the (complete or incomplete) package scope // holding the objects declared at package level (TypeNames, // Consts, Vars, and Funcs). -func (pkg *Package) Scope() *Scope { return pkg.scope } +// For a nil pkg receiver, Scope returns the Universe scope. +func (pkg *Package) Scope() *Scope { + if pkg != nil { + return pkg.scope + } + return Universe +} // A package is complete if its scope contains (at least) all // exported objects; otherwise it is incomplete. From d34287a4f68de5b8a796ec50b8c6b0582a4afc40 Mon Sep 17 00:00:00 2001 From: Meng Zhuo Date: Wed, 26 Jan 2022 10:23:48 +0800 Subject: [PATCH 110/276] cmd/link: default generic ABI compression for ELF This CL change all debug dwarf headers to generic ABI "Compression header" for ELF (http://www.sco.com/developers/gabi/latest/ch4.sheader.html#compression_header) Fixes #50796 Change-Id: I188625e596f11cd120dbd802ac2d79341d5eaf41 Reviewed-on: https://go-review.googlesource.com/c/go/+/380755 Trust: mzh Run-TryBot: mzh TryBot-Result: Gopher Robot Reviewed-by: Than McIntosh Reviewed-by: Cherry Mui --- src/cmd/link/elf_test.go | 3 +++ src/cmd/link/internal/ld/data.go | 27 ++++++++++++++++++---- src/cmd/link/internal/ld/dwarf.go | 11 +++++++-- src/cmd/link/internal/ld/elf.go | 3 +++ src/cmd/link/internal/ld/lib.go | 2 +- src/cmd/link/internal/sym/segment.go | 2 ++ src/debug/elf/file.go | 34 ++++++++++++++++++++++++---- 7 files changed, 71 insertions(+), 11 deletions(-) diff --git a/src/cmd/link/elf_test.go b/src/cmd/link/elf_test.go index 760d9ea60d9..318bd76abae 100644 --- a/src/cmd/link/elf_test.go +++ b/src/cmd/link/elf_test.go @@ -455,6 +455,9 @@ func TestPIESize(t *testing.T) { extraexe := extrasize(elfexe) extrapie := extrasize(elfpie) + if sizepie < sizeexe || sizepie-extrapie < sizeexe-extraexe { + return + } diffReal := (sizepie - extrapie) - (sizeexe - extraexe) diffExpected := (textpie + dynpie) - (textexe + dynexe) diff --git a/src/cmd/link/internal/ld/data.go b/src/cmd/link/internal/ld/data.go index 95a8e0facb4..0ec1e526a98 100644 --- a/src/cmd/link/internal/ld/data.go +++ b/src/cmd/link/internal/ld/data.go @@ -2778,10 +2778,29 @@ func compressSyms(ctxt *Link, syms []loader.Sym) []byte { } var buf bytes.Buffer - buf.Write([]byte("ZLIB")) - var sizeBytes [8]byte - binary.BigEndian.PutUint64(sizeBytes[:], uint64(total)) - buf.Write(sizeBytes[:]) + if ctxt.IsELF { + switch ctxt.Arch.PtrSize { + case 8: + binary.Write(&buf, ctxt.Arch.ByteOrder, elf.Chdr64{ + Type: uint32(elf.COMPRESS_ZLIB), + Size: uint64(total), + Addralign: uint64(ctxt.Arch.Alignment), + }) + case 4: + binary.Write(&buf, ctxt.Arch.ByteOrder, elf.Chdr32{ + Type: uint32(elf.COMPRESS_ZLIB), + Size: uint32(total), + Addralign: uint32(ctxt.Arch.Alignment), + }) + default: + log.Fatalf("can't compress header size:%d", ctxt.Arch.PtrSize) + } + } else { + buf.Write([]byte("ZLIB")) + var sizeBytes [8]byte + binary.BigEndian.PutUint64(sizeBytes[:], uint64(total)) + buf.Write(sizeBytes[:]) + } var relocbuf []byte // temporary buffer for applying relocations diff --git a/src/cmd/link/internal/ld/dwarf.go b/src/cmd/link/internal/ld/dwarf.go index 4aaed7baf04..289ebcb5958 100644 --- a/src/cmd/link/internal/ld/dwarf.go +++ b/src/cmd/link/internal/ld/dwarf.go @@ -2227,11 +2227,18 @@ func dwarfcompress(ctxt *Link) { newDwarfp = append(newDwarfp, ds) Segdwarf.Sections = append(Segdwarf.Sections, ldr.SymSect(s)) } else { - compressedSegName := ".zdebug_" + ldr.SymSect(s).Name[len(".debug_"):] + var compressedSegName string + if ctxt.IsELF { + compressedSegName = ldr.SymSect(s).Name + } else { + compressedSegName = ".zdebug_" + ldr.SymSect(s).Name[len(".debug_"):] + } sect := addsection(ctxt.loader, ctxt.Arch, &Segdwarf, compressedSegName, 04) sect.Align = 1 sect.Length = uint64(len(z.compressed)) - newSym := ldr.CreateSymForUpdate(compressedSegName, 0) + sect.Compressed = true + newSym := ldr.MakeSymbolBuilder(compressedSegName) + ldr.SetAttrReachable(s, true) newSym.SetData(z.compressed) newSym.SetSize(int64(len(z.compressed))) ldr.SetSymSect(newSym.Sym(), sect) diff --git a/src/cmd/link/internal/ld/elf.go b/src/cmd/link/internal/ld/elf.go index 1bdfb3369c7..7f45a8fce5e 100644 --- a/src/cmd/link/internal/ld/elf.go +++ b/src/cmd/link/internal/ld/elf.go @@ -1102,6 +1102,9 @@ func elfshbits(linkmode LinkMode, sect *sym.Section) *ElfShdr { } if strings.HasPrefix(sect.Name, ".debug") || strings.HasPrefix(sect.Name, ".zdebug") { sh.Flags = 0 + if sect.Compressed { + sh.Flags |= uint64(elf.SHF_COMPRESSED) + } } if linkmode != LinkExternal { diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go index f1a37e955e9..a81232b2a49 100644 --- a/src/cmd/link/internal/ld/lib.go +++ b/src/cmd/link/internal/ld/lib.go @@ -1477,7 +1477,7 @@ func (ctxt *Link) hostlink() { argv = append(argv, unusedArguments) } - const compressDWARF = "-Wl,--compress-debug-sections=zlib-gnu" + const compressDWARF = "-Wl,--compress-debug-sections=zlib" if ctxt.compressDWARF && linkerFlagSupported(ctxt.Arch, argv[0], altLinker, compressDWARF) { argv = append(argv, compressDWARF) } diff --git a/src/cmd/link/internal/sym/segment.go b/src/cmd/link/internal/sym/segment.go index 97853b9355f..c889e71ad64 100644 --- a/src/cmd/link/internal/sym/segment.go +++ b/src/cmd/link/internal/sym/segment.go @@ -63,4 +63,6 @@ type Section struct { Relcount uint32 Sym LoaderSym // symbol for the section, if any Index uint16 // each section has a unique index, used internally + + Compressed bool } diff --git a/src/debug/elf/file.go b/src/debug/elf/file.go index 8c84661c5f7..e93200a11d7 100644 --- a/src/debug/elf/file.go +++ b/src/debug/elf/file.go @@ -1150,11 +1150,37 @@ func (f *File) DWARF() (*dwarf.Data, error) { if err != nil && uint64(len(b)) < s.Size { return nil, err } - + var ( + dlen uint64 + dbuf []byte + ) if len(b) >= 12 && string(b[:4]) == "ZLIB" { - dlen := binary.BigEndian.Uint64(b[4:12]) - dbuf := make([]byte, dlen) - r, err := zlib.NewReader(bytes.NewBuffer(b[12:])) + dlen = binary.BigEndian.Uint64(b[4:12]) + s.compressionOffset = 12 + } + if dlen == 0 && len(b) >= 12 && s.Flags&SHF_COMPRESSED != 0 && + s.Flags&SHF_ALLOC == 0 && + f.FileHeader.ByteOrder.Uint32(b[:]) == uint32(COMPRESS_ZLIB) { + s.compressionType = COMPRESS_ZLIB + switch f.FileHeader.Class { + case ELFCLASS32: + // Chdr32.Size offset + dlen = uint64(f.FileHeader.ByteOrder.Uint32(b[4:])) + s.compressionOffset = 12 + case ELFCLASS64: + if len(b) < 24 { + return nil, errors.New("invalid compress header 64") + } + // Chdr64.Size offset + dlen = f.FileHeader.ByteOrder.Uint64(b[8:]) + s.compressionOffset = 24 + default: + return nil, fmt.Errorf("unsupported compress header:%s", f.FileHeader.Class) + } + } + if dlen > 0 { + dbuf = make([]byte, dlen) + r, err := zlib.NewReader(bytes.NewBuffer(b[s.compressionOffset:])) if err != nil { return nil, err } From 5fd0ed7aaf39f783ea6f505a3f2ac7d9da7cb03b Mon Sep 17 00:00:00 2001 From: fanzha02 Date: Mon, 7 Jun 2021 14:24:45 +0800 Subject: [PATCH 111/276] cmd/compile: set conversions to unsafe.Pointer as an escaping operation when -asan is enabled When ASan is enabled, treat conversions to unsafe.Pointer as an escaping operation. In this way, all pointer operations on the stack objects will become operations on the escaped heap objects. As we've already supported ASan detection of error memory accesses to heap objects. With this trick, we can use -asan option to report errors on bad stack operations. Add test cases. Updates #44853. CustomizedGitHooks: yes Change-Id: I4e7fe46a3ce01f0d219e6a67dc50f4aff7d2ad87 Reviewed-on: https://go-review.googlesource.com/c/go/+/325629 Trust: Fannie Zhang Reviewed-by: Keith Randall --- misc/cgo/testsanitizers/asan_test.go | 3 ++ .../testdata/asan_unsafe_fail1.go | 27 ++++++++++++++++++ .../testdata/asan_unsafe_fail2.go | 28 +++++++++++++++++++ .../testdata/asan_unsafe_fail3.go | 21 ++++++++++++++ src/cmd/compile/internal/escape/expr.go | 6 ++-- src/cmd/compile/internal/ir/expr.go | 6 ++++ 6 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 misc/cgo/testsanitizers/testdata/asan_unsafe_fail1.go create mode 100644 misc/cgo/testsanitizers/testdata/asan_unsafe_fail2.go create mode 100644 misc/cgo/testsanitizers/testdata/asan_unsafe_fail3.go diff --git a/misc/cgo/testsanitizers/asan_test.go b/misc/cgo/testsanitizers/asan_test.go index 22dcf23c3ba..ff578ac63e1 100644 --- a/misc/cgo/testsanitizers/asan_test.go +++ b/misc/cgo/testsanitizers/asan_test.go @@ -41,6 +41,9 @@ func TestASAN(t *testing.T) { {src: "asan4_fail.go", memoryAccessError: "use-after-poison", errorLocation: "asan4_fail.go:13"}, {src: "asan5_fail.go", memoryAccessError: "use-after-poison", errorLocation: "asan5_fail.go:18"}, {src: "asan_useAfterReturn.go"}, + {src: "asan_unsafe_fail1.go", memoryAccessError: "use-after-poison", errorLocation: "asan_unsafe_fail1.go:25"}, + {src: "asan_unsafe_fail2.go", memoryAccessError: "use-after-poison", errorLocation: "asan_unsafe_fail2.go:25"}, + {src: "asan_unsafe_fail3.go", memoryAccessError: "use-after-poison", errorLocation: "asan_unsafe_fail3.go:18"}, } for _, tc := range cases { tc := tc diff --git a/misc/cgo/testsanitizers/testdata/asan_unsafe_fail1.go b/misc/cgo/testsanitizers/testdata/asan_unsafe_fail1.go new file mode 100644 index 00000000000..e66387c5a45 --- /dev/null +++ b/misc/cgo/testsanitizers/testdata/asan_unsafe_fail1.go @@ -0,0 +1,27 @@ +// Copyright 2022 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 main + +import ( + "fmt" + "unsafe" +) + +func main() { + a := 1 + b := 2 + c := add(a, b) + d := a + b + fmt.Println(c, d) +} + +//go:noinline +func add(a1, b1 int) int { + // The arguments. + // When -asan is enabled, unsafe.Pointer(&a1) conversion is escaping. + var p *int = (*int)(unsafe.Pointer(uintptr(unsafe.Pointer(&a1)) + 1*unsafe.Sizeof(int(1)))) + *p = 10 // BOOM + return a1 + b1 +} diff --git a/misc/cgo/testsanitizers/testdata/asan_unsafe_fail2.go b/misc/cgo/testsanitizers/testdata/asan_unsafe_fail2.go new file mode 100644 index 00000000000..4f25aac1bdd --- /dev/null +++ b/misc/cgo/testsanitizers/testdata/asan_unsafe_fail2.go @@ -0,0 +1,28 @@ +// Copyright 2022 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 main + +import ( + "fmt" + "unsafe" +) + +func main() { + a := 1 + b := 2 + c := add(a, b) + d := a + b + fmt.Println(c, d) +} + +//go:noinline +func add(a1, b1 int) (ret int) { + // The return value + // When -asan is enabled, the unsafe.Pointer(&ret) conversion is escaping. + var p *int = (*int)(unsafe.Pointer(uintptr(unsafe.Pointer(&ret)) + 1*unsafe.Sizeof(int(1)))) + *p = 123 // BOOM + ret = a1 + b1 + return +} diff --git a/misc/cgo/testsanitizers/testdata/asan_unsafe_fail3.go b/misc/cgo/testsanitizers/testdata/asan_unsafe_fail3.go new file mode 100644 index 00000000000..a05044fc664 --- /dev/null +++ b/misc/cgo/testsanitizers/testdata/asan_unsafe_fail3.go @@ -0,0 +1,21 @@ +// Copyright 2022 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 main + +import ( + "fmt" + "unsafe" +) + +func main() { + a := 1 + b := 2 + // The local variables. + // When -asan is enabled, the unsafe.Pointer(&a) conversion is escaping. + var p *int = (*int)(unsafe.Pointer(uintptr(unsafe.Pointer(&a)) + 1*unsafe.Sizeof(int(1)))) + *p = 20 // BOOM + d := a + b + fmt.Println(d) +} diff --git a/src/cmd/compile/internal/escape/expr.go b/src/cmd/compile/internal/escape/expr.go index ced90a47bcb..9c3e09d10da 100644 --- a/src/cmd/compile/internal/escape/expr.go +++ b/src/cmd/compile/internal/escape/expr.go @@ -100,9 +100,9 @@ func (e *escape) exprSkipInit(k hole, n ir.Node) { case ir.OCONV, ir.OCONVNOP: n := n.(*ir.ConvExpr) - if ir.ShouldCheckPtr(e.curfn, 2) && n.Type().IsUnsafePtr() && n.X.Type().IsPtr() { - // When -d=checkptr=2 is enabled, treat - // conversions to unsafe.Pointer as an + if (ir.ShouldCheckPtr(e.curfn, 2) || ir.ShouldAsanCheckPtr(e.curfn)) && n.Type().IsUnsafePtr() && n.X.Type().IsPtr() { + // When -d=checkptr=2 or -asan is enabled, + // treat conversions to unsafe.Pointer as an // escaping operation. This allows better // runtime instrumentation, since we can more // easily detect object boundaries on the heap diff --git a/src/cmd/compile/internal/ir/expr.go b/src/cmd/compile/internal/ir/expr.go index 156fe964938..ebb84ad78fb 100644 --- a/src/cmd/compile/internal/ir/expr.go +++ b/src/cmd/compile/internal/ir/expr.go @@ -1035,6 +1035,12 @@ func ShouldCheckPtr(fn *Func, level int) bool { return base.Debug.Checkptr >= level && fn.Pragma&NoCheckPtr == 0 } +// ShouldAsanCheckPtr reports whether pointer checking should be enabled for +// function fn when -asan is enabled. +func ShouldAsanCheckPtr(fn *Func) bool { + return base.Flag.ASan && fn.Pragma&NoCheckPtr == 0 +} + // IsReflectHeaderDataField reports whether l is an expression p.Data // where p has type reflect.SliceHeader or reflect.StringHeader. func IsReflectHeaderDataField(l Node) bool { From 1a2f72619510f944289587d41fcb86cad9026f7d Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Thu, 10 Mar 2022 10:41:54 -0500 Subject: [PATCH 112/276] runtime/pprof: do not require a GOROOT/src prefix in tests When paths are trimmed, the reported file locations begin with the package import path (not GOROOT/src). Updates #51461 Change-Id: Idbd408a02e8d03329d10e30b0b08263e69e66285 Reviewed-on: https://go-review.googlesource.com/c/go/+/391812 Trust: Bryan Mills Run-TryBot: Bryan Mills Reviewed-by: Ian Lance Taylor TryBot-Result: Gopher Robot Reviewed-by: Cherry Mui --- src/runtime/pprof/mprof_test.go | 18 +++++++------- src/runtime/pprof/pprof_test.go | 42 ++++++++++++++++----------------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/runtime/pprof/mprof_test.go b/src/runtime/pprof/mprof_test.go index 665487a7c4f..391588d4acd 100644 --- a/src/runtime/pprof/mprof_test.go +++ b/src/runtime/pprof/mprof_test.go @@ -93,31 +93,31 @@ func TestMemoryProfiler(t *testing.T) { }{{ stk: []string{"runtime/pprof.allocatePersistent1K", "runtime/pprof.TestMemoryProfiler"}, legacy: fmt.Sprintf(`%v: %v \[%v: %v\] @ 0x[0-9,a-f]+ 0x[0-9,a-f]+ 0x[0-9,a-f]+ 0x[0-9,a-f]+ -# 0x[0-9,a-f]+ runtime/pprof\.allocatePersistent1K\+0x[0-9,a-f]+ .*/runtime/pprof/mprof_test\.go:47 -# 0x[0-9,a-f]+ runtime/pprof\.TestMemoryProfiler\+0x[0-9,a-f]+ .*/runtime/pprof/mprof_test\.go:82 +# 0x[0-9,a-f]+ runtime/pprof\.allocatePersistent1K\+0x[0-9,a-f]+ .*runtime/pprof/mprof_test\.go:47 +# 0x[0-9,a-f]+ runtime/pprof\.TestMemoryProfiler\+0x[0-9,a-f]+ .*runtime/pprof/mprof_test\.go:82 `, 32*memoryProfilerRun, 1024*memoryProfilerRun, 32*memoryProfilerRun, 1024*memoryProfilerRun), }, { stk: []string{"runtime/pprof.allocateTransient1M", "runtime/pprof.TestMemoryProfiler"}, legacy: fmt.Sprintf(`0: 0 \[%v: %v\] @ 0x[0-9,a-f]+ 0x[0-9,a-f]+ 0x[0-9,a-f]+ 0x[0-9,a-f]+ -# 0x[0-9,a-f]+ runtime/pprof\.allocateTransient1M\+0x[0-9,a-f]+ .*/runtime/pprof/mprof_test.go:24 -# 0x[0-9,a-f]+ runtime/pprof\.TestMemoryProfiler\+0x[0-9,a-f]+ .*/runtime/pprof/mprof_test.go:79 +# 0x[0-9,a-f]+ runtime/pprof\.allocateTransient1M\+0x[0-9,a-f]+ .*runtime/pprof/mprof_test.go:24 +# 0x[0-9,a-f]+ runtime/pprof\.TestMemoryProfiler\+0x[0-9,a-f]+ .*runtime/pprof/mprof_test.go:79 `, (1<<10)*memoryProfilerRun, (1<<20)*memoryProfilerRun), }, { stk: []string{"runtime/pprof.allocateTransient2M", "runtime/pprof.TestMemoryProfiler"}, legacy: fmt.Sprintf(`0: 0 \[%v: %v\] @ 0x[0-9,a-f]+ 0x[0-9,a-f]+ 0x[0-9,a-f]+ 0x[0-9,a-f]+ -# 0x[0-9,a-f]+ runtime/pprof\.allocateTransient2M\+0x[0-9,a-f]+ .*/runtime/pprof/mprof_test.go:30 -# 0x[0-9,a-f]+ runtime/pprof\.TestMemoryProfiler\+0x[0-9,a-f]+ .*/runtime/pprof/mprof_test.go:80 +# 0x[0-9,a-f]+ runtime/pprof\.allocateTransient2M\+0x[0-9,a-f]+ .*runtime/pprof/mprof_test.go:30 +# 0x[0-9,a-f]+ runtime/pprof\.TestMemoryProfiler\+0x[0-9,a-f]+ .*runtime/pprof/mprof_test.go:80 `, memoryProfilerRun, (2<<20)*memoryProfilerRun), }, { stk: []string{"runtime/pprof.allocateTransient2MInline", "runtime/pprof.TestMemoryProfiler"}, legacy: fmt.Sprintf(`0: 0 \[%v: %v\] @ 0x[0-9,a-f]+ 0x[0-9,a-f]+ 0x[0-9,a-f]+ 0x[0-9,a-f]+ -# 0x[0-9,a-f]+ runtime/pprof\.allocateTransient2MInline\+0x[0-9,a-f]+ .*/runtime/pprof/mprof_test.go:34 -# 0x[0-9,a-f]+ runtime/pprof\.TestMemoryProfiler\+0x[0-9,a-f]+ .*/runtime/pprof/mprof_test.go:81 +# 0x[0-9,a-f]+ runtime/pprof\.allocateTransient2MInline\+0x[0-9,a-f]+ .*runtime/pprof/mprof_test.go:34 +# 0x[0-9,a-f]+ runtime/pprof\.TestMemoryProfiler\+0x[0-9,a-f]+ .*runtime/pprof/mprof_test.go:81 `, memoryProfilerRun, (2<<20)*memoryProfilerRun), }, { stk: []string{"runtime/pprof.allocateReflectTransient"}, legacy: fmt.Sprintf(`0: 0 \[%v: %v\] @( 0x[0-9,a-f]+)+ -# 0x[0-9,a-f]+ runtime/pprof\.allocateReflectTransient\+0x[0-9,a-f]+ .*/runtime/pprof/mprof_test.go:55 +# 0x[0-9,a-f]+ runtime/pprof\.allocateReflectTransient\+0x[0-9,a-f]+ .*runtime/pprof/mprof_test.go:55 `, memoryProfilerRun, (2<<20)*memoryProfilerRun), }} diff --git a/src/runtime/pprof/pprof_test.go b/src/runtime/pprof/pprof_test.go index 322579cdc43..99897fcfdc1 100644 --- a/src/runtime/pprof/pprof_test.go +++ b/src/runtime/pprof/pprof_test.go @@ -809,9 +809,9 @@ func TestBlockProfile(t *testing.T) { }, re: ` [0-9]+ [0-9]+ @( 0x[[:xdigit:]]+)+ -# 0x[0-9a-f]+ runtime\.chanrecv1\+0x[0-9a-f]+ .*/src/runtime/chan.go:[0-9]+ -# 0x[0-9a-f]+ runtime/pprof\.blockChanRecv\+0x[0-9a-f]+ .*/src/runtime/pprof/pprof_test.go:[0-9]+ -# 0x[0-9a-f]+ runtime/pprof\.TestBlockProfile\+0x[0-9a-f]+ .*/src/runtime/pprof/pprof_test.go:[0-9]+ +# 0x[0-9a-f]+ runtime\.chanrecv1\+0x[0-9a-f]+ .*runtime/chan.go:[0-9]+ +# 0x[0-9a-f]+ runtime/pprof\.blockChanRecv\+0x[0-9a-f]+ .*runtime/pprof/pprof_test.go:[0-9]+ +# 0x[0-9a-f]+ runtime/pprof\.TestBlockProfile\+0x[0-9a-f]+ .*runtime/pprof/pprof_test.go:[0-9]+ `}, { name: "chan send", @@ -823,9 +823,9 @@ func TestBlockProfile(t *testing.T) { }, re: ` [0-9]+ [0-9]+ @( 0x[[:xdigit:]]+)+ -# 0x[0-9a-f]+ runtime\.chansend1\+0x[0-9a-f]+ .*/src/runtime/chan.go:[0-9]+ -# 0x[0-9a-f]+ runtime/pprof\.blockChanSend\+0x[0-9a-f]+ .*/src/runtime/pprof/pprof_test.go:[0-9]+ -# 0x[0-9a-f]+ runtime/pprof\.TestBlockProfile\+0x[0-9a-f]+ .*/src/runtime/pprof/pprof_test.go:[0-9]+ +# 0x[0-9a-f]+ runtime\.chansend1\+0x[0-9a-f]+ .*runtime/chan.go:[0-9]+ +# 0x[0-9a-f]+ runtime/pprof\.blockChanSend\+0x[0-9a-f]+ .*runtime/pprof/pprof_test.go:[0-9]+ +# 0x[0-9a-f]+ runtime/pprof\.TestBlockProfile\+0x[0-9a-f]+ .*runtime/pprof/pprof_test.go:[0-9]+ `}, { name: "chan close", @@ -837,9 +837,9 @@ func TestBlockProfile(t *testing.T) { }, re: ` [0-9]+ [0-9]+ @( 0x[[:xdigit:]]+)+ -# 0x[0-9a-f]+ runtime\.chanrecv1\+0x[0-9a-f]+ .*/src/runtime/chan.go:[0-9]+ -# 0x[0-9a-f]+ runtime/pprof\.blockChanClose\+0x[0-9a-f]+ .*/src/runtime/pprof/pprof_test.go:[0-9]+ -# 0x[0-9a-f]+ runtime/pprof\.TestBlockProfile\+0x[0-9a-f]+ .*/src/runtime/pprof/pprof_test.go:[0-9]+ +# 0x[0-9a-f]+ runtime\.chanrecv1\+0x[0-9a-f]+ .*runtime/chan.go:[0-9]+ +# 0x[0-9a-f]+ runtime/pprof\.blockChanClose\+0x[0-9a-f]+ .*runtime/pprof/pprof_test.go:[0-9]+ +# 0x[0-9a-f]+ runtime/pprof\.TestBlockProfile\+0x[0-9a-f]+ .*runtime/pprof/pprof_test.go:[0-9]+ `}, { name: "select recv async", @@ -851,9 +851,9 @@ func TestBlockProfile(t *testing.T) { }, re: ` [0-9]+ [0-9]+ @( 0x[[:xdigit:]]+)+ -# 0x[0-9a-f]+ runtime\.selectgo\+0x[0-9a-f]+ .*/src/runtime/select.go:[0-9]+ -# 0x[0-9a-f]+ runtime/pprof\.blockSelectRecvAsync\+0x[0-9a-f]+ .*/src/runtime/pprof/pprof_test.go:[0-9]+ -# 0x[0-9a-f]+ runtime/pprof\.TestBlockProfile\+0x[0-9a-f]+ .*/src/runtime/pprof/pprof_test.go:[0-9]+ +# 0x[0-9a-f]+ runtime\.selectgo\+0x[0-9a-f]+ .*runtime/select.go:[0-9]+ +# 0x[0-9a-f]+ runtime/pprof\.blockSelectRecvAsync\+0x[0-9a-f]+ .*runtime/pprof/pprof_test.go:[0-9]+ +# 0x[0-9a-f]+ runtime/pprof\.TestBlockProfile\+0x[0-9a-f]+ .*runtime/pprof/pprof_test.go:[0-9]+ `}, { name: "select send sync", @@ -865,9 +865,9 @@ func TestBlockProfile(t *testing.T) { }, re: ` [0-9]+ [0-9]+ @( 0x[[:xdigit:]]+)+ -# 0x[0-9a-f]+ runtime\.selectgo\+0x[0-9a-f]+ .*/src/runtime/select.go:[0-9]+ -# 0x[0-9a-f]+ runtime/pprof\.blockSelectSendSync\+0x[0-9a-f]+ .*/src/runtime/pprof/pprof_test.go:[0-9]+ -# 0x[0-9a-f]+ runtime/pprof\.TestBlockProfile\+0x[0-9a-f]+ .*/src/runtime/pprof/pprof_test.go:[0-9]+ +# 0x[0-9a-f]+ runtime\.selectgo\+0x[0-9a-f]+ .*runtime/select.go:[0-9]+ +# 0x[0-9a-f]+ runtime/pprof\.blockSelectSendSync\+0x[0-9a-f]+ .*runtime/pprof/pprof_test.go:[0-9]+ +# 0x[0-9a-f]+ runtime/pprof\.TestBlockProfile\+0x[0-9a-f]+ .*runtime/pprof/pprof_test.go:[0-9]+ `}, { name: "mutex", @@ -879,9 +879,9 @@ func TestBlockProfile(t *testing.T) { }, re: ` [0-9]+ [0-9]+ @( 0x[[:xdigit:]]+)+ -# 0x[0-9a-f]+ sync\.\(\*Mutex\)\.Lock\+0x[0-9a-f]+ .*/src/sync/mutex\.go:[0-9]+ -# 0x[0-9a-f]+ runtime/pprof\.blockMutex\+0x[0-9a-f]+ .*/src/runtime/pprof/pprof_test.go:[0-9]+ -# 0x[0-9a-f]+ runtime/pprof\.TestBlockProfile\+0x[0-9a-f]+ .*/src/runtime/pprof/pprof_test.go:[0-9]+ +# 0x[0-9a-f]+ sync\.\(\*Mutex\)\.Lock\+0x[0-9a-f]+ .*sync/mutex\.go:[0-9]+ +# 0x[0-9a-f]+ runtime/pprof\.blockMutex\+0x[0-9a-f]+ .*runtime/pprof/pprof_test.go:[0-9]+ +# 0x[0-9a-f]+ runtime/pprof\.TestBlockProfile\+0x[0-9a-f]+ .*runtime/pprof/pprof_test.go:[0-9]+ `}, { name: "cond", @@ -893,9 +893,9 @@ func TestBlockProfile(t *testing.T) { }, re: ` [0-9]+ [0-9]+ @( 0x[[:xdigit:]]+)+ -# 0x[0-9a-f]+ sync\.\(\*Cond\)\.Wait\+0x[0-9a-f]+ .*/src/sync/cond\.go:[0-9]+ -# 0x[0-9a-f]+ runtime/pprof\.blockCond\+0x[0-9a-f]+ .*/src/runtime/pprof/pprof_test.go:[0-9]+ -# 0x[0-9a-f]+ runtime/pprof\.TestBlockProfile\+0x[0-9a-f]+ .*/src/runtime/pprof/pprof_test.go:[0-9]+ +# 0x[0-9a-f]+ sync\.\(\*Cond\)\.Wait\+0x[0-9a-f]+ .*sync/cond\.go:[0-9]+ +# 0x[0-9a-f]+ runtime/pprof\.blockCond\+0x[0-9a-f]+ .*runtime/pprof/pprof_test.go:[0-9]+ +# 0x[0-9a-f]+ runtime/pprof\.TestBlockProfile\+0x[0-9a-f]+ .*runtime/pprof/pprof_test.go:[0-9]+ `}, } From 95395fdbe3e76778a9035d9478f52513fc34a97b Mon Sep 17 00:00:00 2001 From: Cherry Mui Date: Fri, 7 Jan 2022 12:13:31 -0500 Subject: [PATCH 113/276] syscall: call ABIInternal entersyscall on register ABI platforms Currently, when register ABI is used, syscall.Syscall calls entersyscall via a wrapper, so the actual entersyscall records the caller PC and SP of the wrapper. At the point of the actual syscall, the wrapper frame is gone, so the recorded PC and SP are technically invalid. Furthermore, in some functions on some platforms (e.g. Syscall9 on NetBSD/AMD64), that frame is overwritten. If we unwind the stack from the recorded syscallpc and syscallsp, it may go wrong. Fix this by calling the ABIInternal function directly. exitsyscall calls are changed as well. It doesn't really matter, just changed for consistency. Change-Id: Iead8dd22cf32b05e382414fef664b7c4c1719b7c Reviewed-on: https://go-review.googlesource.com/c/go/+/376356 Trust: Cherry Mui Run-TryBot: Cherry Mui TryBot-Result: Gopher Robot Reviewed-by: Michael Knyszek --- src/syscall/asm9_unix2_amd64.s | 6 +++--- src/syscall/asm_darwin_amd64.s | 18 +++++++++--------- src/syscall/asm_darwin_arm64.s | 18 +++++++++--------- src/syscall/asm_freebsd_arm64.s | 18 +++++++++--------- src/syscall/asm_linux_amd64.s | 12 ++++++------ src/syscall/asm_linux_arm64.s | 12 ++++++------ src/syscall/asm_linux_ppc64x.s | 12 ++++++------ src/syscall/asm_netbsd_amd64.s | 6 +++--- src/syscall/asm_netbsd_arm64.s | 19 +++++++++---------- src/syscall/asm_plan9_amd64.s | 12 ++++++------ src/syscall/asm_unix_amd64.s | 12 ++++++------ 11 files changed, 72 insertions(+), 73 deletions(-) diff --git a/src/syscall/asm9_unix2_amd64.s b/src/syscall/asm9_unix2_amd64.s index 649bc6024c9..5bf53a12511 100644 --- a/src/syscall/asm9_unix2_amd64.s +++ b/src/syscall/asm9_unix2_amd64.s @@ -13,7 +13,7 @@ // func Syscall9(trap int64, a1, a2, a3, a4, a5, a6, a7, a8, a9 int64) (r1, r2, err int64); TEXT ·Syscall9(SB),NOSPLIT,$0-104 - CALL runtime·entersyscall(SB) + CALL runtime·entersyscall(SB) MOVQ num+0(FP), AX // syscall entry MOVQ a1+8(FP), DI MOVQ a2+16(FP), SI @@ -38,11 +38,11 @@ TEXT ·Syscall9(SB),NOSPLIT,$0-104 MOVQ $-1, r1+80(FP) // r1 MOVQ $0, r2+88(FP) // r2 MOVQ AX, err+96(FP) // errno - CALL runtime·exitsyscall(SB) + CALL runtime·exitsyscall(SB) RET ok9: MOVQ AX, r1+80(FP) // r1 MOVQ DX, r2+88(FP) // r2 MOVQ $0, err+96(FP) // errno - CALL runtime·exitsyscall(SB) + CALL runtime·exitsyscall(SB) RET diff --git a/src/syscall/asm_darwin_amd64.s b/src/syscall/asm_darwin_amd64.s index c863889a713..77b58e051b9 100644 --- a/src/syscall/asm_darwin_amd64.s +++ b/src/syscall/asm_darwin_amd64.s @@ -13,7 +13,7 @@ // func Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno); TEXT ·Syscall(SB),NOSPLIT,$0-56 - CALL runtime·entersyscall(SB) + CALL runtime·entersyscall(SB) MOVQ a1+8(FP), DI MOVQ a2+16(FP), SI MOVQ a3+24(FP), DX @@ -24,18 +24,18 @@ TEXT ·Syscall(SB),NOSPLIT,$0-56 MOVQ $-1, r1+32(FP) MOVQ $0, r2+40(FP) MOVQ AX, err+48(FP) - CALL runtime·exitsyscall(SB) + CALL runtime·exitsyscall(SB) RET ok: MOVQ AX, r1+32(FP) MOVQ DX, r2+40(FP) MOVQ $0, err+48(FP) - CALL runtime·exitsyscall(SB) + CALL runtime·exitsyscall(SB) RET // func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno); TEXT ·Syscall6(SB),NOSPLIT,$0-80 - CALL runtime·entersyscall(SB) + CALL runtime·entersyscall(SB) MOVQ a1+8(FP), DI MOVQ a2+16(FP), SI MOVQ a3+24(FP), DX @@ -49,18 +49,18 @@ TEXT ·Syscall6(SB),NOSPLIT,$0-80 MOVQ $-1, r1+56(FP) MOVQ $0, r2+64(FP) MOVQ AX, err+72(FP) - CALL runtime·exitsyscall(SB) + CALL runtime·exitsyscall(SB) RET ok6: MOVQ AX, r1+56(FP) MOVQ DX, r2+64(FP) MOVQ $0, err+72(FP) - CALL runtime·exitsyscall(SB) + CALL runtime·exitsyscall(SB) RET // func Syscall9(trap, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err Errno) TEXT ·Syscall9(SB),NOSPLIT,$0-104 - CALL runtime·entersyscall(SB) + CALL runtime·entersyscall(SB) MOVQ trap+0(FP), AX // syscall entry MOVQ a1+8(FP), DI MOVQ a2+16(FP), SI @@ -82,14 +82,14 @@ TEXT ·Syscall9(SB),NOSPLIT,$0-104 MOVQ $-1, r1+80(FP) MOVQ $0, r2+88(FP) MOVQ AX, err+96(FP) - CALL runtime·exitsyscall(SB) + CALL runtime·exitsyscall(SB) RET ok9: ADDQ $32, SP MOVQ AX, r1+80(FP) MOVQ DX, r2+88(FP) MOVQ $0, err+96(FP) - CALL runtime·exitsyscall(SB) + CALL runtime·exitsyscall(SB) RET // func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno) diff --git a/src/syscall/asm_darwin_arm64.s b/src/syscall/asm_darwin_arm64.s index 95b6dc0db57..22e07666df2 100644 --- a/src/syscall/asm_darwin_arm64.s +++ b/src/syscall/asm_darwin_arm64.s @@ -10,7 +10,7 @@ // func Syscall(trap uintptr, a1, a2, a3 uintptr) (r1, r2, err uintptr) TEXT ·Syscall(SB),NOSPLIT,$0-56 - BL runtime·entersyscall(SB) + BL runtime·entersyscall(SB) MOVD trap+0(FP), R16 MOVD a1+8(FP), R0 MOVD a2+16(FP), R1 @@ -21,13 +21,13 @@ TEXT ·Syscall(SB),NOSPLIT,$0-56 MOVD R1, r1+32(FP) // r1 MOVD ZR, r2+40(FP) // r2 MOVD R0, err+48(FP) // err - BL runtime·exitsyscall(SB) + BL runtime·exitsyscall(SB) RET ok: MOVD R0, r1+32(FP) // r1 MOVD R1, r2+40(FP) // r2 MOVD ZR, err+48(FP) // err - BL runtime·exitsyscall(SB) + BL runtime·exitsyscall(SB) RET // func RawSyscall(trap uintptr, a1, a2, a3 uintptr) (r1, r2, err uintptr) @@ -51,7 +51,7 @@ ok: // func Syscall6(trap uintptr, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr) TEXT ·Syscall6(SB),NOSPLIT,$0-80 - BL runtime·entersyscall(SB) + BL runtime·entersyscall(SB) MOVD trap+0(FP), R16 // syscall entry MOVD a1+8(FP), R0 MOVD a2+16(FP), R1 @@ -65,13 +65,13 @@ TEXT ·Syscall6(SB),NOSPLIT,$0-80 MOVD R1, r1+56(FP) // r1 MOVD ZR, r2+64(FP) // r2 MOVD R0, err+72(FP) // err - BL runtime·exitsyscall(SB) + BL runtime·exitsyscall(SB) RET ok: MOVD R0, r1+56(FP) // r1 MOVD R1, r2+64(FP) // r2 MOVD ZR, err+72(FP) // err - BL runtime·exitsyscall(SB) + BL runtime·exitsyscall(SB) RET // func RawSyscall6(trap uintptr, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr) @@ -99,7 +99,7 @@ ok: // Actually Syscall7 TEXT ·Syscall9(SB),NOSPLIT,$0-104 - BL runtime·entersyscall(SB) + BL runtime·entersyscall(SB) MOVD num+0(FP), R16 // syscall entry MOVD a1+8(FP), R0 MOVD a2+16(FP), R1 @@ -116,12 +116,12 @@ TEXT ·Syscall9(SB),NOSPLIT,$0-104 MOVD R1, r1+80(FP) // r1 MOVD ZR, r2+88(FP) // r2 MOVD R0, err+96(FP) // err - BL runtime·exitsyscall(SB) + BL runtime·exitsyscall(SB) RET ok: MOVD R0, r1+80(FP) // r1 MOVD R1, r2+88(FP) // r2 MOVD ZR, err+96(FP) // err - BL runtime·exitsyscall(SB) + BL runtime·exitsyscall(SB) RET diff --git a/src/syscall/asm_freebsd_arm64.s b/src/syscall/asm_freebsd_arm64.s index 7a0809b8ec9..b032ce7f69c 100644 --- a/src/syscall/asm_freebsd_arm64.s +++ b/src/syscall/asm_freebsd_arm64.s @@ -12,7 +12,7 @@ // func Syscall(trap uintptr, a1, a2, a3 uintptr) (r1, r2, err uintptr) TEXT ·Syscall(SB),NOSPLIT,$0-56 - BL runtime·entersyscall(SB) + BL runtime·entersyscall(SB) MOVD trap+0(FP), R8 // syscall entry MOVD a1+8(FP), R0 MOVD a2+16(FP), R1 @@ -23,13 +23,13 @@ TEXT ·Syscall(SB),NOSPLIT,$0-56 MOVD R1, r1+32(FP) MOVD ZR, r2+40(FP) MOVD R0, err+48(FP) - BL runtime·exitsyscall(SB) + BL runtime·exitsyscall(SB) RET ok: MOVD R0, r1+32(FP) MOVD R1, r2+40(FP) MOVD ZR, err+48(FP) - BL runtime·exitsyscall(SB) + BL runtime·exitsyscall(SB) RET // func RawSyscall(trap uintptr, a1, a2, a3 uintptr) (r1, r2, err uintptr) @@ -53,7 +53,7 @@ ok: // func Syscall6(trap uintptr, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr) TEXT ·Syscall6(SB),NOSPLIT,$0-80 - BL runtime·entersyscall(SB) + BL runtime·entersyscall(SB) MOVD trap+0(FP), R8 // syscall entry MOVD a1+8(FP), R0 MOVD a2+16(FP), R1 @@ -67,13 +67,13 @@ TEXT ·Syscall6(SB),NOSPLIT,$0-80 MOVD R1, r1+56(FP) MOVD ZR, r2+64(FP) MOVD R0, err+72(FP) - BL runtime·exitsyscall(SB) + BL runtime·exitsyscall(SB) RET ok: MOVD R0, r1+56(FP) MOVD R1, r2+64(FP) MOVD ZR, err+72(FP) - BL runtime·exitsyscall(SB) + BL runtime·exitsyscall(SB) RET // func RawSyscall6(trap uintptr, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr) @@ -101,7 +101,7 @@ ok: // Actually Syscall7 // func Syscall9(num uintptr, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2, err uintptr) TEXT ·Syscall9(SB),NOSPLIT,$0-104 - BL runtime·entersyscall(SB) + BL runtime·entersyscall(SB) MOVD num+0(FP), R8 // syscall entry MOVD a1+8(FP), R0 MOVD a2+16(FP), R1 @@ -118,11 +118,11 @@ TEXT ·Syscall9(SB),NOSPLIT,$0-104 MOVD R1, r1+80(FP) MOVD ZR, r2+88(FP) MOVD R0, err+96(FP) - BL runtime·exitsyscall(SB) + BL runtime·exitsyscall(SB) RET ok: MOVD R0, r1+80(FP) MOVD R1, r2+88(FP) MOVD ZR, err+96(FP) - BL runtime·exitsyscall(SB) + BL runtime·exitsyscall(SB) RET diff --git a/src/syscall/asm_linux_amd64.s b/src/syscall/asm_linux_amd64.s index a9af68d51db..0b55a30fa01 100644 --- a/src/syscall/asm_linux_amd64.s +++ b/src/syscall/asm_linux_amd64.s @@ -17,7 +17,7 @@ // would pass 4th arg in CX, not R10. TEXT ·Syscall(SB),NOSPLIT,$0-56 - CALL runtime·entersyscall(SB) + CALL runtime·entersyscall(SB) MOVQ a1+8(FP), DI MOVQ a2+16(FP), SI MOVQ a3+24(FP), DX @@ -29,18 +29,18 @@ TEXT ·Syscall(SB),NOSPLIT,$0-56 MOVQ $0, r2+40(FP) NEGQ AX MOVQ AX, err+48(FP) - CALL runtime·exitsyscall(SB) + CALL runtime·exitsyscall(SB) RET ok: MOVQ AX, r1+32(FP) MOVQ DX, r2+40(FP) MOVQ $0, err+48(FP) - CALL runtime·exitsyscall(SB) + CALL runtime·exitsyscall(SB) RET // func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr) TEXT ·Syscall6(SB),NOSPLIT,$0-80 - CALL runtime·entersyscall(SB) + CALL runtime·entersyscall(SB) MOVQ a1+8(FP), DI MOVQ a2+16(FP), SI MOVQ a3+24(FP), DX @@ -55,13 +55,13 @@ TEXT ·Syscall6(SB),NOSPLIT,$0-80 MOVQ $0, r2+64(FP) NEGQ AX MOVQ AX, err+72(FP) - CALL runtime·exitsyscall(SB) + CALL runtime·exitsyscall(SB) RET ok6: MOVQ AX, r1+56(FP) MOVQ DX, r2+64(FP) MOVQ $0, err+72(FP) - CALL runtime·exitsyscall(SB) + CALL runtime·exitsyscall(SB) RET // func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2, err uintptr) diff --git a/src/syscall/asm_linux_arm64.s b/src/syscall/asm_linux_arm64.s index a30e4d87d4c..6c50fa9d7cd 100644 --- a/src/syscall/asm_linux_arm64.s +++ b/src/syscall/asm_linux_arm64.s @@ -6,7 +6,7 @@ // func Syscall(trap int64, a1, a2, a3 int64) (r1, r2, err int64); TEXT ·Syscall(SB),NOSPLIT,$0-56 - BL runtime·entersyscall(SB) + BL runtime·entersyscall(SB) MOVD a1+8(FP), R0 MOVD a2+16(FP), R1 MOVD a3+24(FP), R2 @@ -22,17 +22,17 @@ TEXT ·Syscall(SB),NOSPLIT,$0-56 MOVD ZR, r2+40(FP) // r2 NEG R0, R0 MOVD R0, err+48(FP) // errno - BL runtime·exitsyscall(SB) + BL runtime·exitsyscall(SB) RET ok: MOVD R0, r1+32(FP) // r1 MOVD R1, r2+40(FP) // r2 MOVD ZR, err+48(FP) // errno - BL runtime·exitsyscall(SB) + BL runtime·exitsyscall(SB) RET TEXT ·Syscall6(SB),NOSPLIT,$0-80 - BL runtime·entersyscall(SB) + BL runtime·entersyscall(SB) MOVD a1+8(FP), R0 MOVD a2+16(FP), R1 MOVD a3+24(FP), R2 @@ -48,13 +48,13 @@ TEXT ·Syscall6(SB),NOSPLIT,$0-80 MOVD ZR, r2+64(FP) // r2 NEG R0, R0 MOVD R0, err+72(FP) // errno - BL runtime·exitsyscall(SB) + BL runtime·exitsyscall(SB) RET ok: MOVD R0, r1+56(FP) // r1 MOVD R1, r2+64(FP) // r2 MOVD ZR, err+72(FP) // errno - BL runtime·exitsyscall(SB) + BL runtime·exitsyscall(SB) RET TEXT ·RawSyscall(SB),NOSPLIT,$0-56 diff --git a/src/syscall/asm_linux_ppc64x.s b/src/syscall/asm_linux_ppc64x.s index 1f5cb37ffee..bf701e52912 100644 --- a/src/syscall/asm_linux_ppc64x.s +++ b/src/syscall/asm_linux_ppc64x.s @@ -12,7 +12,7 @@ // func Syscall(trap int64, a1, a2, a3 int64) (r1, r2, err int64); TEXT ·Syscall(SB),NOSPLIT,$0-56 - BL runtime·entersyscall(SB) + BL runtime·entersyscall(SB) MOVD a1+8(FP), R3 MOVD a2+16(FP), R4 MOVD a3+24(FP), R5 @@ -26,17 +26,17 @@ TEXT ·Syscall(SB),NOSPLIT,$0-56 MOVD R4, r1+32(FP) // r1 MOVD R0, r2+40(FP) // r2 MOVD R3, err+48(FP) // errno - BL runtime·exitsyscall(SB) + BL runtime·exitsyscall(SB) RET ok: MOVD R3, r1+32(FP) // r1 MOVD R0, r2+40(FP) // r2 MOVD R0, err+48(FP) // errno - BL runtime·exitsyscall(SB) + BL runtime·exitsyscall(SB) RET TEXT ·Syscall6(SB),NOSPLIT,$0-80 - BL runtime·entersyscall(SB) + BL runtime·entersyscall(SB) MOVD a1+8(FP), R3 MOVD a2+16(FP), R4 MOVD a3+24(FP), R5 @@ -50,13 +50,13 @@ TEXT ·Syscall6(SB),NOSPLIT,$0-80 MOVD R4, r1+56(FP) // r1 MOVD R0, r2+64(FP) // r2 MOVD R3, err+72(FP) // errno - BL runtime·exitsyscall(SB) + BL runtime·exitsyscall(SB) RET ok6: MOVD R3, r1+56(FP) // r1 MOVD R0, r2+64(FP) // r2 MOVD R0, err+72(FP) // errno - BL runtime·exitsyscall(SB) + BL runtime·exitsyscall(SB) RET TEXT ·RawSyscall(SB),NOSPLIT,$0-56 diff --git a/src/syscall/asm_netbsd_amd64.s b/src/syscall/asm_netbsd_amd64.s index 9e4dd20ad3f..457e207296e 100644 --- a/src/syscall/asm_netbsd_amd64.s +++ b/src/syscall/asm_netbsd_amd64.s @@ -11,7 +11,7 @@ // func Syscall9(trap int64, a1, a2, a3, a4, a5, a6, a7, a8, a9 int64) (r1, r2, err int64); TEXT ·Syscall9(SB),NOSPLIT,$0-104 - CALL runtime·entersyscall(SB) + CALL runtime·entersyscall(SB) MOVQ num+0(FP), AX // syscall entry MOVQ a1+8(FP), DI MOVQ a2+16(FP), SI @@ -32,12 +32,12 @@ TEXT ·Syscall9(SB),NOSPLIT,$0-104 MOVQ $-1, 88(SP) // r1 MOVQ $0, 96(SP) // r2 MOVQ AX, 104(SP) // errno - CALL runtime·exitsyscall(SB) + CALL runtime·exitsyscall(SB) RET ok9: ADDQ $32, SP MOVQ AX, 88(SP) // r1 MOVQ DX, 96(SP) // r2 MOVQ $0, 104(SP) // errno - CALL runtime·exitsyscall(SB) + CALL runtime·exitsyscall(SB) RET diff --git a/src/syscall/asm_netbsd_arm64.s b/src/syscall/asm_netbsd_arm64.s index fbcd3388c98..aebd83f3259 100644 --- a/src/syscall/asm_netbsd_arm64.s +++ b/src/syscall/asm_netbsd_arm64.s @@ -12,7 +12,7 @@ // func Syscall(trap uintptr, a1, a2, a3 uintptr) (r1, r2, err uintptr) TEXT ·Syscall(SB),NOSPLIT,$0-56 - BL runtime·entersyscall(SB) + BL runtime·entersyscall(SB) MOVD trap+0(FP), R17 MOVD a1+8(FP), R0 MOVD a2+16(FP), R1 @@ -23,13 +23,13 @@ TEXT ·Syscall(SB),NOSPLIT,$0-56 MOVD R1, r1+32(FP) // r1 MOVD ZR, r2+40(FP) // r2 MOVD R0, err+48(FP) // err - BL runtime·exitsyscall(SB) + BL runtime·exitsyscall(SB) RET ok: MOVD R0, r1+32(FP) // r1 MOVD R1, r2+40(FP) // r2 MOVD ZR, err+48(FP) // err - BL runtime·exitsyscall(SB) + BL runtime·exitsyscall(SB) RET // func RawSyscall(trap uintptr, a1, a2, a3 uintptr) (r1, r2, err uintptr) @@ -53,7 +53,7 @@ ok: // func Syscall6(trap uintptr, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr) TEXT ·Syscall6(SB),NOSPLIT,$0-80 - BL runtime·entersyscall(SB) + BL runtime·entersyscall(SB) MOVD trap+0(FP), R17 // syscall entry MOVD a1+8(FP), R0 MOVD a2+16(FP), R1 @@ -67,13 +67,13 @@ TEXT ·Syscall6(SB),NOSPLIT,$0-80 MOVD R1, r1+56(FP) // r1 MOVD ZR, r2+64(FP) // r2 MOVD R0, err+72(FP) // err - BL runtime·exitsyscall(SB) + BL runtime·exitsyscall(SB) RET ok: MOVD R0, r1+56(FP) // r1 MOVD R1, r2+64(FP) // r2 MOVD ZR, err+72(FP) // err - BL runtime·exitsyscall(SB) + BL runtime·exitsyscall(SB) RET // func RawSyscall6(trap uintptr, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr) @@ -101,7 +101,7 @@ ok: // Actually Syscall7 TEXT ·Syscall9(SB),NOSPLIT,$0-104 - BL runtime·entersyscall(SB) + BL runtime·entersyscall(SB) MOVD num+0(FP), R17 // syscall entry MOVD a1+8(FP), R0 MOVD a2+16(FP), R1 @@ -118,12 +118,11 @@ TEXT ·Syscall9(SB),NOSPLIT,$0-104 MOVD R1, r1+80(FP) // r1 MOVD ZR, r2+88(FP) // r2 MOVD R0, err+96(FP) // err - BL runtime·exitsyscall(SB) + BL runtime·exitsyscall(SB) RET ok: MOVD R0, r1+80(FP) // r1 MOVD R1, r2+88(FP) // r2 MOVD ZR, err+96(FP) // err - BL runtime·exitsyscall(SB) + BL runtime·exitsyscall(SB) RET - diff --git a/src/syscall/asm_plan9_amd64.s b/src/syscall/asm_plan9_amd64.s index d5c9f6c63f1..f22db3238d2 100644 --- a/src/syscall/asm_plan9_amd64.s +++ b/src/syscall/asm_plan9_amd64.s @@ -18,7 +18,7 @@ TEXT ·Syscall(SB),NOSPLIT,$168-64 NO_LOCAL_POINTERS - CALL runtime·entersyscall(SB) + CALL runtime·entersyscall(SB) MOVQ trap+0(FP), BP // syscall entry // copy args down LEAQ a1+8(FP), SI @@ -38,7 +38,7 @@ TEXT ·Syscall(SB),NOSPLIT,$168-64 MOVQ $128, sysargs1-152(SP) MOVQ $SYS_ERRSTR, BP SYSCALL - CALL runtime·exitsyscall(SB) + CALL runtime·exitsyscall(SB) MOVQ sysargs-160(SP), AX MOVQ AX, errbuf-168(SP) CALL runtime·gostring(SB) @@ -46,7 +46,7 @@ TEXT ·Syscall(SB),NOSPLIT,$168-64 JMP copyresult3 ok3: - CALL runtime·exitsyscall(SB) + CALL runtime·exitsyscall(SB) LEAQ ·emptystring(SB), SI copyresult3: @@ -60,7 +60,7 @@ copyresult3: TEXT ·Syscall6(SB),NOSPLIT,$168-88 NO_LOCAL_POINTERS - CALL runtime·entersyscall(SB) + CALL runtime·entersyscall(SB) MOVQ trap+0(FP), BP // syscall entry // copy args down LEAQ a1+8(FP), SI @@ -83,7 +83,7 @@ TEXT ·Syscall6(SB),NOSPLIT,$168-88 MOVQ $128, sysargs1-152(SP) MOVQ $SYS_ERRSTR, BP SYSCALL - CALL runtime·exitsyscall(SB) + CALL runtime·exitsyscall(SB) MOVQ sysargs-160(SP), AX MOVQ AX, errbuf-168(SP) CALL runtime·gostring(SB) @@ -91,7 +91,7 @@ TEXT ·Syscall6(SB),NOSPLIT,$168-88 JMP copyresult4 ok4: - CALL runtime·exitsyscall(SB) + CALL runtime·exitsyscall(SB) LEAQ ·emptystring(SB), SI copyresult4: diff --git a/src/syscall/asm_unix_amd64.s b/src/syscall/asm_unix_amd64.s index 8ee46b86b57..6d8da715a2f 100644 --- a/src/syscall/asm_unix_amd64.s +++ b/src/syscall/asm_unix_amd64.s @@ -16,7 +16,7 @@ // Trap # in AX, args in DI SI DX, return in AX DX TEXT ·Syscall(SB),NOSPLIT,$0-56 - CALL runtime·entersyscall(SB) + CALL runtime·entersyscall(SB) MOVQ trap+0(FP), AX // syscall entry MOVQ a1+8(FP), DI MOVQ a2+16(FP), SI @@ -26,17 +26,17 @@ TEXT ·Syscall(SB),NOSPLIT,$0-56 MOVQ $-1, r1+32(FP) // r1 MOVQ $0, r2+40(FP) // r2 MOVQ AX, err+48(FP) // errno - CALL runtime·exitsyscall(SB) + CALL runtime·exitsyscall(SB) RET ok: MOVQ AX, r1+32(FP) // r1 MOVQ DX, r2+40(FP) // r2 MOVQ $0, err+48(FP) // errno - CALL runtime·exitsyscall(SB) + CALL runtime·exitsyscall(SB) RET TEXT ·Syscall6(SB),NOSPLIT,$0-80 - CALL runtime·entersyscall(SB) + CALL runtime·entersyscall(SB) MOVQ trap+0(FP), AX // syscall entry MOVQ a1+8(FP), DI MOVQ a2+16(FP), SI @@ -49,13 +49,13 @@ TEXT ·Syscall6(SB),NOSPLIT,$0-80 MOVQ $-1, r1+56(FP) // r1 MOVQ $0, r2+64(FP) // r2 MOVQ AX, err+72(FP) // errno - CALL runtime·exitsyscall(SB) + CALL runtime·exitsyscall(SB) RET ok6: MOVQ AX, r1+56(FP) // r1 MOVQ DX, r2+64(FP) // r2 MOVQ $0, err+72(FP) // errno - CALL runtime·exitsyscall(SB) + CALL runtime·exitsyscall(SB) RET TEXT ·RawSyscall(SB),NOSPLIT,$0-56 From a3fcc755db54b89855519a5b3e3fb66ed9912497 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Sat, 29 Jan 2022 15:58:19 -0500 Subject: [PATCH 114/276] internal/txtar: bring back to main repo, for tests in std This used to be cmd/go/internal/txtar, and then it was moved to golang.org/x/tools/txtar and revendored from there into cmd/vendor/golang.org/x/tools/txtar. We have a use for txtar in a new test in the standard library, which cannot access cmd/vendor. But we also don't really want to vendor it into the standard library as is, because that would be the first vendoring of x/tools in std, and it would be better to keep std separate from x/tools, even for testing. Instead, since a little copying is better than a little dependency, just make a copy in internal/txtar. The package does not change. Having done that, replace the uses in cmd/go so that there's only one copy in the main repo. Change-Id: I70b5cc05da3f6ebcc0fd9052ebcb3d369fb57956 Reviewed-on: https://go-review.googlesource.com/c/go/+/384254 Trust: Russ Cox Run-TryBot: Russ Cox Reviewed-by: Bryan Mills TryBot-Result: Gopher Robot --- src/cmd/go/internal/fsys/fsys_test.go | 3 +-- src/cmd/go/proxy_test.go | 2 +- src/cmd/go/script_test.go | 3 +-- src/cmd/go/testdata/addmod.go | 3 +-- src/cmd/go/testdata/savedir.go | 3 +-- src/cmd/go/testdata/script/README | 2 +- src/cmd/vendor/modules.txt | 1 - src/go/build/deps_test.go | 3 +++ .../vendor/golang.org/x/tools => internal}/txtar/archive.go | 0 9 files changed, 9 insertions(+), 11 deletions(-) rename src/{cmd/vendor/golang.org/x/tools => internal}/txtar/archive.go (100%) diff --git a/src/cmd/go/internal/fsys/fsys_test.go b/src/cmd/go/internal/fsys/fsys_test.go index c080c14987c..8cfe1d89e69 100644 --- a/src/cmd/go/internal/fsys/fsys_test.go +++ b/src/cmd/go/internal/fsys/fsys_test.go @@ -5,14 +5,13 @@ import ( "errors" "fmt" "internal/testenv" + "internal/txtar" "io" "io/fs" "os" "path/filepath" "reflect" "testing" - - "golang.org/x/tools/txtar" ) // initOverlay resets the overlay state to reflect the config. diff --git a/src/cmd/go/proxy_test.go b/src/cmd/go/proxy_test.go index 517a8855428..fc256968b74 100644 --- a/src/cmd/go/proxy_test.go +++ b/src/cmd/go/proxy_test.go @@ -11,6 +11,7 @@ import ( "errors" "flag" "fmt" + "internal/txtar" "io" "io/fs" "log" @@ -30,7 +31,6 @@ import ( "golang.org/x/mod/semver" "golang.org/x/mod/sumdb" "golang.org/x/mod/sumdb/dirhash" - "golang.org/x/tools/txtar" ) var ( diff --git a/src/cmd/go/script_test.go b/src/cmd/go/script_test.go index eff22135257..90ab3a6501b 100644 --- a/src/cmd/go/script_test.go +++ b/src/cmd/go/script_test.go @@ -15,6 +15,7 @@ import ( "fmt" "go/build" "internal/testenv" + "internal/txtar" "io/fs" "os" "os/exec" @@ -33,8 +34,6 @@ import ( "cmd/go/internal/robustio" "cmd/go/internal/work" "cmd/internal/sys" - - "golang.org/x/tools/txtar" ) var testSum = flag.String("testsum", "", `may be tidy, listm, or listall. If set, TestScript generates a go.sum file at the beginning of each test and updates test files if they pass.`) diff --git a/src/cmd/go/testdata/addmod.go b/src/cmd/go/testdata/addmod.go index eac2a7ad449..41997a52fff 100644 --- a/src/cmd/go/testdata/addmod.go +++ b/src/cmd/go/testdata/addmod.go @@ -24,13 +24,12 @@ import ( "flag" "fmt" exec "internal/execabs" + "internal/txtar" "io/fs" "log" "os" "path/filepath" "strings" - - "golang.org/x/tools/txtar" ) func usage() { diff --git a/src/cmd/go/testdata/savedir.go b/src/cmd/go/testdata/savedir.go index 53c78cfb00b..eaafc5e4939 100644 --- a/src/cmd/go/testdata/savedir.go +++ b/src/cmd/go/testdata/savedir.go @@ -18,14 +18,13 @@ package main import ( "flag" "fmt" + "internal/txtar" "io/fs" "log" "os" "path/filepath" "strings" "unicode/utf8" - - "golang.org/x/tools/txtar" ) func usage() { diff --git a/src/cmd/go/testdata/script/README b/src/cmd/go/testdata/script/README index b2a7fd19156..17b582d6627 100644 --- a/src/cmd/go/testdata/script/README +++ b/src/cmd/go/testdata/script/README @@ -7,7 +7,7 @@ In general script files should have short names: a few words, not whole sentence The first word should be the general category of behavior being tested, often the name of a go subcommand (list, build, test, ...) or concept (vendor, pattern). -Each script is a text archive (go doc cmd/go/internal/txtar). +Each script is a text archive (go doc internal/txtar). The script begins with an actual command script to run followed by the content of zero or more supporting files to create in the script's temporary file system before it starts executing. diff --git a/src/cmd/vendor/modules.txt b/src/cmd/vendor/modules.txt index f2cd884b820..c373ca05b19 100644 --- a/src/cmd/vendor/modules.txt +++ b/src/cmd/vendor/modules.txt @@ -96,7 +96,6 @@ golang.org/x/tools/go/types/typeutil golang.org/x/tools/internal/analysisinternal golang.org/x/tools/internal/lsp/fuzzy golang.org/x/tools/internal/typeparams -golang.org/x/tools/txtar # golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 ## explicit; go 1.11 golang.org/x/xerrors diff --git a/src/go/build/deps_test.go b/src/go/build/deps_test.go index 6b2c2933f82..ed40f43c9da 100644 --- a/src/go/build/deps_test.go +++ b/src/go/build/deps_test.go @@ -553,6 +553,9 @@ var depsRules = ` FMT, container/heap, math/rand < internal/trace; + + FMT + < internal/txtar; ` // listStdPkgs returns the same list of packages as "go list std". diff --git a/src/cmd/vendor/golang.org/x/tools/txtar/archive.go b/src/internal/txtar/archive.go similarity index 100% rename from src/cmd/vendor/golang.org/x/tools/txtar/archive.go rename to src/internal/txtar/archive.go From 33e752edd3f5fa5b738730513a7c1283d8e98fa2 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Mon, 21 Feb 2022 14:54:05 -0800 Subject: [PATCH 115/276] syscall: ensure that Getwd returns absolute path Since Linux kernel 2.6.36, the pathname returned by the getcwd() system call can be prefixed with the string "(unreachable)" in some cases [1]. Getcwd should return an absolute path, and doing otherwise is a conformance issue; it also can be dangerous, since the path returned can be an existing relative path. Fix by returning ENOENT in case the path is not absolute. This is essentially the same as what glibc does (since [2]). [1] https://man7.org/linux/man-pages/man2/getcwd.2.html#BUGS [2] https://sourceware.org/git/?p=glibc.git;a=commit;h=52a713fdd0a30e1bd79818e2e3c4ab44ddca1a94 Change-Id: I444c80eb3c836ff7d32c64c8b65d5112fa8c710f Reviewed-on: https://go-review.googlesource.com/c/go/+/387174 Reviewed-by: Ian Lance Taylor Reviewed-by: Tobias Klauser Trust: Tobias Klauser Run-TryBot: Tobias Klauser TryBot-Result: Gopher Robot --- src/syscall/syscall_linux.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/syscall/syscall_linux.go b/src/syscall/syscall_linux.go index e3891b08558..f74a79c2851 100644 --- a/src/syscall/syscall_linux.go +++ b/src/syscall/syscall_linux.go @@ -253,6 +253,13 @@ func Getwd() (wd string, err error) { if n < 1 || n > len(buf) || buf[n-1] != 0 { return "", EINVAL } + // In some cases, Linux can return a path that starts with the + // "(unreachable)" prefix, which can potentially be a valid relative + // path. To work around that, return ENOENT if path is not absolute. + if buf[0] != '/' { + return "", ENOENT + } + return string(buf[0 : n-1]), nil } From 3efc7215cbf6c7842cba0f5ebe90f72f0b6de9e1 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Tue, 8 Mar 2022 09:51:29 -0500 Subject: [PATCH 116/276] fmt, strconv: document use of Unicode replacement character in %q Fixes #51526. Change-Id: I365a763454bd201f804df29f800416b1731b8ebc Reviewed-on: https://go-review.googlesource.com/c/go/+/390436 Trust: Russ Cox Run-TryBot: Russ Cox Reviewed-by: Rob Pike TryBot-Result: Gopher Robot --- src/fmt/doc.go | 4 ++++ src/strconv/quote.go | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/src/fmt/doc.go b/src/fmt/doc.go index f14a7a73e33..6b49deda870 100644 --- a/src/fmt/doc.go +++ b/src/fmt/doc.go @@ -110,6 +110,10 @@ For complex numbers, the width and precision apply to the two components independently and the result is parenthesized, so %f applied to 1.2+3.4i produces (1.200000+3.400000i). +When formatting a single integer code point or a rune string (type []rune) +with %q, invalid Unicode code points are changed to the Unicode replacement +character, U+FFFD, as in strconv.QuoteRune. + Other flags: + always print a sign for numeric values; guarantee ASCII-only output for %q (%+q) diff --git a/src/strconv/quote.go b/src/strconv/quote.go index d2814b92da7..9d20b75a58a 100644 --- a/src/strconv/quote.go +++ b/src/strconv/quote.go @@ -165,6 +165,8 @@ func AppendQuoteToGraphic(dst []byte, s string) []byte { // QuoteRune returns a single-quoted Go character literal representing the // rune. The returned string uses Go escape sequences (\t, \n, \xFF, \u0100) // for control characters and non-printable characters as defined by IsPrint. +// If r is not a valid Unicode code point, it is interpreted as the Unicode +// replacement character U+FFFD. func QuoteRune(r rune) string { return quoteRuneWith(r, '\'', false, false) } @@ -179,6 +181,8 @@ func AppendQuoteRune(dst []byte, r rune) []byte { // the rune. The returned string uses Go escape sequences (\t, \n, \xFF, // \u0100) for non-ASCII characters and non-printable characters as defined // by IsPrint. +// If r is not a valid Unicode code point, it is interpreted as the Unicode +// replacement character U+FFFD. func QuoteRuneToASCII(r rune) string { return quoteRuneWith(r, '\'', true, false) } @@ -193,6 +197,8 @@ func AppendQuoteRuneToASCII(dst []byte, r rune) []byte { // the rune. If the rune is not a Unicode graphic character, // as defined by IsGraphic, the returned string will use a Go escape sequence // (\t, \n, \xFF, \u0100). +// If r is not a valid Unicode code point, it is interpreted as the Unicode +// replacement character U+FFFD. func QuoteRuneToGraphic(r rune) string { return quoteRuneWith(r, '\'', false, true) } From c0158b6a00eaecbd28ded0f66e65b9985f6db078 Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Thu, 10 Mar 2022 22:56:00 -0500 Subject: [PATCH 117/276] go/internal/srcimporter: use the 'go' command from the Importer's GOROOT We have no guarantee in general that there is any 'go' command in $PATH at all, let alone the correct one. However, we can expect that if a 'go' command is not in scope, the Importer should have a correct GOROOT setting: otherwise, it would not be able to import anything from 'std' at all. Given that information, when we run `go tool cgo` we should use GOROOT/bin/go specifically, not whatever 'go' we find in $PATH. This fixes a failure in go/types.TestStdlib that manifests as a timeout in when the 'go' command is not present in $PATH, due to repeated retries for every package that transitively depends on runtime/cgo. For #51461 Change-Id: I30cc4613f6f02a04e83c8d55657ef01888c7770f Reviewed-on: https://go-review.googlesource.com/c/go/+/391807 Trust: Bryan Mills Run-TryBot: Bryan Mills Reviewed-by: Ian Lance Taylor TryBot-Result: Gopher Robot --- src/go/internal/srcimporter/srcimporter.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/go/internal/srcimporter/srcimporter.go b/src/go/internal/srcimporter/srcimporter.go index e4225eb4d78..d7ec6691bc7 100644 --- a/src/go/internal/srcimporter/srcimporter.go +++ b/src/go/internal/srcimporter/srcimporter.go @@ -205,7 +205,11 @@ func (p *Importer) cgo(bp *build.Package) (*ast.File, error) { } defer os.RemoveAll(tmpdir) - args := []string{"go", "tool", "cgo", "-objdir", tmpdir} + goCmd := "go" + if p.ctxt.GOROOT != "" { + goCmd = filepath.Join(p.ctxt.GOROOT, "bin", "go") + } + args := []string{goCmd, "tool", "cgo", "-objdir", tmpdir} if bp.Goroot { switch bp.ImportPath { case "runtime/cgo": From a1bf50eefe35087ac7151116558f4c19095b8473 Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Tue, 15 Mar 2022 22:25:36 -0700 Subject: [PATCH 118/276] cmd/compile: detect invalid NIH conversions within unified IR Unified IR currently relies on typecheck to diagnose invalid //go:notinheap conversions, which prevents removing all of its (otherwise) dead error-reporting code. This CL updates the unified IR reader to instead proactively diagnose these invalid conversions. This logic can be removed again once #46731 is implemented, but in the mean time it allows progress on #51691. Updates #46731. Updates #51691. Change-Id: Ifae81aaad770209ec7a67bc10b55660f291e403e Reviewed-on: https://go-review.googlesource.com/c/go/+/392917 Trust: Matthew Dempsky Run-TryBot: Matthew Dempsky TryBot-Result: Gopher Robot Reviewed-by: Cuong Manh Le --- src/cmd/compile/internal/noder/reader.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/cmd/compile/internal/noder/reader.go b/src/cmd/compile/internal/noder/reader.go index 73e4ddbbedc..dd3bb1523e1 100644 --- a/src/cmd/compile/internal/noder/reader.go +++ b/src/cmd/compile/internal/noder/reader.go @@ -1676,6 +1676,20 @@ func (r *reader) expr() (res ir.Node) { typ := r.typ() pos := r.pos() x := r.expr() + + // TODO(mdempsky): Stop constructing expressions of untyped type. + x = typecheck.DefaultLit(x, typ) + + if op, why := typecheck.Convertop(x.Op() == ir.OLITERAL, x.Type(), typ); op == ir.OXXX { + // types2 ensured that x is convertable to typ under standard Go + // semantics, but cmd/compile also disallows some conversions + // involving //go:notinheap. + // + // TODO(mdempsky): This can be removed after #46731 is implemented. + base.ErrorfAt(pos, "cannot convert %L to type %v%v", x, typ, why) + base.ErrorExit() // harsh, but prevents constructing invalid IR + } + return typecheck.Expr(ir.NewConvExpr(pos, ir.OCONV, typ, x)) } } From 1024503f84b2ddcd59104ec5db36d10a8adaae99 Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Tue, 15 Mar 2022 22:34:19 -0700 Subject: [PATCH 119/276] cmd/compile: Fatalf in Type.SetBroke(true) and Node.SetDiag(true) Type.Broke and Node.Diag were used in the legacy typechecker to allow reporting of multiple errors in a compilation unit, while suppressing unhelpful follow-on errors. However, that's no longer needed now that types2 handles (most) user-visible diagnostics. Updates #51691. Change-Id: I919c1598d8acebe5703939256bdca3e8d021f7ad Reviewed-on: https://go-review.googlesource.com/c/go/+/392918 Trust: Matthew Dempsky Run-TryBot: Matthew Dempsky TryBot-Result: Gopher Robot Reviewed-by: Cuong Manh Le --- src/cmd/compile/internal/ir/mini.go | 6 +++--- src/cmd/compile/internal/types/type.go | 5 ++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/cmd/compile/internal/ir/mini.go b/src/cmd/compile/internal/ir/mini.go index eeb74081fb8..cfd5dcfb960 100644 --- a/src/cmd/compile/internal/ir/mini.go +++ b/src/cmd/compile/internal/ir/mini.go @@ -7,6 +7,7 @@ package ir import ( + "cmd/compile/internal/base" "cmd/compile/internal/types" "cmd/internal/src" "fmt" @@ -56,7 +57,6 @@ func (n *miniNode) SetEsc(x uint16) { n.esc = x } const ( miniWalkdefShift = 0 // TODO(mdempsky): Move to Name.flags. miniTypecheckShift = 2 - miniDiag = 1 << 4 miniWalked = 1 << 5 // to prevent/catch re-walking ) @@ -68,8 +68,8 @@ func (n *miniNode) SetTypecheck(x uint8) { n.bits.set2(miniTypecheckShift, x) } -func (n *miniNode) Diag() bool { return n.bits&miniDiag != 0 } -func (n *miniNode) SetDiag(x bool) { n.bits.set(miniDiag, x) } +func (n *miniNode) Diag() bool { return false } +func (n *miniNode) SetDiag(x bool) { base.AssertfAt(!x, n.Pos(), "SetDiag") } func (n *miniNode) Walked() bool { return n.bits&miniWalked != 0 } func (n *miniNode) SetWalked(x bool) { n.bits.set(miniWalked, x) } diff --git a/src/cmd/compile/internal/types/type.go b/src/cmd/compile/internal/types/type.go index fe352e0b6e0..51ce614bd8a 100644 --- a/src/cmd/compile/internal/types/type.go +++ b/src/cmd/compile/internal/types/type.go @@ -212,7 +212,6 @@ func (*Type) CanBeAnSSAAux() {} const ( typeNotInHeap = 1 << iota // type cannot be heap allocated - typeBroke // broken type definition typeNoalg // suppress hash and eq algorithm generation typeDeferwidth // width computation has been deferred and type is on deferredTypeStack typeRecur @@ -222,7 +221,7 @@ const ( ) func (t *Type) NotInHeap() bool { return t.flags&typeNotInHeap != 0 } -func (t *Type) Broke() bool { return t.flags&typeBroke != 0 } +func (t *Type) Broke() bool { return false } func (t *Type) Noalg() bool { return t.flags&typeNoalg != 0 } func (t *Type) Deferwidth() bool { return t.flags&typeDeferwidth != 0 } func (t *Type) Recur() bool { return t.flags&typeRecur != 0 } @@ -231,7 +230,7 @@ func (t *Type) IsShape() bool { return t.flags&typeIsShape != 0 } func (t *Type) HasShape() bool { return t.flags&typeHasShape != 0 } func (t *Type) SetNotInHeap(b bool) { t.flags.set(typeNotInHeap, b) } -func (t *Type) SetBroke(b bool) { t.flags.set(typeBroke, b) } +func (t *Type) SetBroke(b bool) { base.Assertf(!b, "SetBroke") } func (t *Type) SetNoalg(b bool) { t.flags.set(typeNoalg, b) } func (t *Type) SetDeferwidth(b bool) { t.flags.set(typeDeferwidth, b) } func (t *Type) SetRecur(b bool) { t.flags.set(typeRecur, b) } From d661bdeabf479c39fe98c6fc598a6d8114047914 Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Tue, 15 Mar 2022 22:49:12 -0700 Subject: [PATCH 120/276] cmd/compile: remove OIOTA OIOTA used to be used to represent "iota" in the pre-typechecked IR, before we knew whether it was safe to replace it with a constant (because it could be redefined as a global symbol later). However, now types2 handles constant folding, including handling of "iota". So this can go away. Updates #51691. Change-Id: I3cec45b22c4c8f1c357dcc4003292c21ae32aa90 Reviewed-on: https://go-review.googlesource.com/c/go/+/393255 Trust: Matthew Dempsky Run-TryBot: Matthew Dempsky TryBot-Result: Gopher Robot Reviewed-by: Cuong Manh Le --- src/cmd/compile/internal/ir/func.go | 2 - src/cmd/compile/internal/ir/name.go | 10 -- src/cmd/compile/internal/ir/node.go | 1 - src/cmd/compile/internal/ir/op_string.go | 105 +++++++++--------- src/cmd/compile/internal/ir/sizeof_test.go | 2 +- src/cmd/compile/internal/typecheck/func.go | 6 - .../compile/internal/typecheck/typecheck.go | 23 ---- .../compile/internal/typecheck/universe.go | 4 - 8 files changed, 53 insertions(+), 100 deletions(-) diff --git a/src/cmd/compile/internal/ir/func.go b/src/cmd/compile/internal/ir/func.go index 29c77444a21..894fff23ffb 100644 --- a/src/cmd/compile/internal/ir/func.go +++ b/src/cmd/compile/internal/ir/func.go @@ -50,7 +50,6 @@ import ( type Func struct { miniNode Body Nodes - Iota int64 Nname *Name // ONAME node OClosure *ClosureExpr // OCLOSURE node @@ -140,7 +139,6 @@ func NewFunc(pos src.XPos) *Func { f := new(Func) f.pos = pos f.op = ODCLFUNC - f.Iota = -1 // Most functions are ABIInternal. The importer or symabis // pass may override this. f.ABI = obj.ABIInternal diff --git a/src/cmd/compile/internal/ir/name.go b/src/cmd/compile/internal/ir/name.go index f522d3e76a8..ee28ca83321 100644 --- a/src/cmd/compile/internal/ir/name.go +++ b/src/cmd/compile/internal/ir/name.go @@ -166,14 +166,6 @@ func NewNameAt(pos src.XPos, sym *types.Sym) *Name { return newNameAt(pos, ONAME, sym) } -// NewIota returns a new OIOTA Node. -func NewIota(pos src.XPos, sym *types.Sym) *Name { - if sym == nil { - base.Fatalf("NewIota nil") - } - return newNameAt(pos, OIOTA, sym) -} - // NewDeclNameAt returns a new Name associated with symbol s at position pos. // The caller is responsible for setting Curfn. func NewDeclNameAt(pos src.XPos, op Op, sym *types.Sym) *Name { @@ -223,8 +215,6 @@ func (n *Name) SetOffset(x int64) { } func (n *Name) FrameOffset() int64 { return n.Offset_ } func (n *Name) SetFrameOffset(x int64) { n.Offset_ = x } -func (n *Name) Iota() int64 { return n.Offset_ } -func (n *Name) SetIota(x int64) { n.Offset_ = x } func (n *Name) Walkdef() uint8 { return n.bits.get2(miniWalkdefShift) } func (n *Name) SetWalkdef(x uint8) { if x > 3 { diff --git a/src/cmd/compile/internal/ir/node.go b/src/cmd/compile/internal/ir/node.go index e4cff85136c..d8c40229505 100644 --- a/src/cmd/compile/internal/ir/node.go +++ b/src/cmd/compile/internal/ir/node.go @@ -240,7 +240,6 @@ const ( ORECV // <-X ORUNESTR // Type(X) (Type is string, X is rune) OSELRECV2 // like OAS2: Lhs = Rhs where len(Lhs)=2, len(Rhs)=1, Rhs[0].Op = ORECV (appears as .Var of OCASE) - OIOTA // iota OREAL // real(X) OIMAG // imag(X) OCOMPLEX // complex(X, Y) diff --git a/src/cmd/compile/internal/ir/op_string.go b/src/cmd/compile/internal/ir/op_string.go index f623735f6dc..14eb84083a8 100644 --- a/src/cmd/compile/internal/ir/op_string.go +++ b/src/cmd/compile/internal/ir/op_string.go @@ -112,62 +112,61 @@ func _() { _ = x[ORECV-101] _ = x[ORUNESTR-102] _ = x[OSELRECV2-103] - _ = x[OIOTA-104] - _ = x[OREAL-105] - _ = x[OIMAG-106] - _ = x[OCOMPLEX-107] - _ = x[OALIGNOF-108] - _ = x[OOFFSETOF-109] - _ = x[OSIZEOF-110] - _ = x[OUNSAFEADD-111] - _ = x[OUNSAFESLICE-112] - _ = x[OMETHEXPR-113] - _ = x[OMETHVALUE-114] - _ = x[OBLOCK-115] - _ = x[OBREAK-116] - _ = x[OCASE-117] - _ = x[OCONTINUE-118] - _ = x[ODEFER-119] - _ = x[OFALL-120] - _ = x[OFOR-121] - _ = x[OFORUNTIL-122] - _ = x[OGOTO-123] - _ = x[OIF-124] - _ = x[OLABEL-125] - _ = x[OGO-126] - _ = x[ORANGE-127] - _ = x[ORETURN-128] - _ = x[OSELECT-129] - _ = x[OSWITCH-130] - _ = x[OTYPESW-131] - _ = x[OFUNCINST-132] - _ = x[OTFUNC-133] - _ = x[OINLCALL-134] - _ = x[OEFACE-135] - _ = x[OITAB-136] - _ = x[OIDATA-137] - _ = x[OSPTR-138] - _ = x[OCFUNC-139] - _ = x[OCHECKNIL-140] - _ = x[OVARDEF-141] - _ = x[OVARKILL-142] - _ = x[OVARLIVE-143] - _ = x[ORESULT-144] - _ = x[OINLMARK-145] - _ = x[OLINKSYMOFFSET-146] - _ = x[ODYNAMICDOTTYPE-147] - _ = x[ODYNAMICDOTTYPE2-148] - _ = x[ODYNAMICTYPE-149] - _ = x[OTAILCALL-150] - _ = x[OGETG-151] - _ = x[OGETCALLERPC-152] - _ = x[OGETCALLERSP-153] - _ = x[OEND-154] + _ = x[OREAL-104] + _ = x[OIMAG-105] + _ = x[OCOMPLEX-106] + _ = x[OALIGNOF-107] + _ = x[OOFFSETOF-108] + _ = x[OSIZEOF-109] + _ = x[OUNSAFEADD-110] + _ = x[OUNSAFESLICE-111] + _ = x[OMETHEXPR-112] + _ = x[OMETHVALUE-113] + _ = x[OBLOCK-114] + _ = x[OBREAK-115] + _ = x[OCASE-116] + _ = x[OCONTINUE-117] + _ = x[ODEFER-118] + _ = x[OFALL-119] + _ = x[OFOR-120] + _ = x[OFORUNTIL-121] + _ = x[OGOTO-122] + _ = x[OIF-123] + _ = x[OLABEL-124] + _ = x[OGO-125] + _ = x[ORANGE-126] + _ = x[ORETURN-127] + _ = x[OSELECT-128] + _ = x[OSWITCH-129] + _ = x[OTYPESW-130] + _ = x[OFUNCINST-131] + _ = x[OTFUNC-132] + _ = x[OINLCALL-133] + _ = x[OEFACE-134] + _ = x[OITAB-135] + _ = x[OIDATA-136] + _ = x[OSPTR-137] + _ = x[OCFUNC-138] + _ = x[OCHECKNIL-139] + _ = x[OVARDEF-140] + _ = x[OVARKILL-141] + _ = x[OVARLIVE-142] + _ = x[ORESULT-143] + _ = x[OINLMARK-144] + _ = x[OLINKSYMOFFSET-145] + _ = x[ODYNAMICDOTTYPE-146] + _ = x[ODYNAMICDOTTYPE2-147] + _ = x[ODYNAMICTYPE-148] + _ = x[OTAILCALL-149] + _ = x[OGETG-150] + _ = x[OGETCALLERPC-151] + _ = x[OGETCALLERSP-152] + _ = x[OEND-153] } -const _Op_name = "XXXNAMENONAMETYPELITERALNILADDSUBORXORADDSTRADDRANDANDAPPENDBYTES2STRBYTES2STRTMPRUNES2STRSTR2BYTESSTR2BYTESTMPSTR2RUNESSLICE2ARRPTRASAS2AS2DOTTYPEAS2FUNCAS2MAPRAS2RECVASOPCALLCALLFUNCCALLMETHCALLINTERCAPCLOSECLOSURECOMPLITMAPLITSTRUCTLITARRAYLITSLICELITPTRLITCONVCONVIFACECONVIDATACONVNOPCOPYDCLDCLFUNCDCLCONSTDCLTYPEDELETEDOTDOTPTRDOTMETHDOTINTERXDOTDOTTYPEDOTTYPE2EQNELTLEGEGTDEREFINDEXINDEXMAPKEYSTRUCTKEYLENMAKEMAKECHANMAKEMAPMAKESLICEMAKESLICECOPYMULDIVMODLSHRSHANDANDNOTNEWNOTBITNOTPLUSNEGORORPANICPRINTPRINTNPARENSENDSLICESLICEARRSLICESTRSLICE3SLICE3ARRSLICEHEADERRECOVERRECOVERFPRECVRUNESTRSELRECV2IOTAREALIMAGCOMPLEXALIGNOFOFFSETOFSIZEOFUNSAFEADDUNSAFESLICEMETHEXPRMETHVALUEBLOCKBREAKCASECONTINUEDEFERFALLFORFORUNTILGOTOIFLABELGORANGERETURNSELECTSWITCHTYPESWFUNCINSTTFUNCINLCALLEFACEITABIDATASPTRCFUNCCHECKNILVARDEFVARKILLVARLIVERESULTINLMARKLINKSYMOFFSETDYNAMICDOTTYPEDYNAMICDOTTYPE2DYNAMICTYPETAILCALLGETGGETCALLERPCGETCALLERSPEND" +const _Op_name = "XXXNAMENONAMETYPELITERALNILADDSUBORXORADDSTRADDRANDANDAPPENDBYTES2STRBYTES2STRTMPRUNES2STRSTR2BYTESSTR2BYTESTMPSTR2RUNESSLICE2ARRPTRASAS2AS2DOTTYPEAS2FUNCAS2MAPRAS2RECVASOPCALLCALLFUNCCALLMETHCALLINTERCAPCLOSECLOSURECOMPLITMAPLITSTRUCTLITARRAYLITSLICELITPTRLITCONVCONVIFACECONVIDATACONVNOPCOPYDCLDCLFUNCDCLCONSTDCLTYPEDELETEDOTDOTPTRDOTMETHDOTINTERXDOTDOTTYPEDOTTYPE2EQNELTLEGEGTDEREFINDEXINDEXMAPKEYSTRUCTKEYLENMAKEMAKECHANMAKEMAPMAKESLICEMAKESLICECOPYMULDIVMODLSHRSHANDANDNOTNEWNOTBITNOTPLUSNEGORORPANICPRINTPRINTNPARENSENDSLICESLICEARRSLICESTRSLICE3SLICE3ARRSLICEHEADERRECOVERRECOVERFPRECVRUNESTRSELRECV2REALIMAGCOMPLEXALIGNOFOFFSETOFSIZEOFUNSAFEADDUNSAFESLICEMETHEXPRMETHVALUEBLOCKBREAKCASECONTINUEDEFERFALLFORFORUNTILGOTOIFLABELGORANGERETURNSELECTSWITCHTYPESWFUNCINSTTFUNCINLCALLEFACEITABIDATASPTRCFUNCCHECKNILVARDEFVARKILLVARLIVERESULTINLMARKLINKSYMOFFSETDYNAMICDOTTYPEDYNAMICDOTTYPE2DYNAMICTYPETAILCALLGETGGETCALLERPCGETCALLERSPEND" -var _Op_index = [...]uint16{0, 3, 7, 13, 17, 24, 27, 30, 33, 35, 38, 44, 48, 54, 60, 69, 81, 90, 99, 111, 120, 132, 134, 137, 147, 154, 161, 168, 172, 176, 184, 192, 201, 204, 209, 216, 223, 229, 238, 246, 254, 260, 264, 273, 282, 289, 293, 296, 303, 311, 318, 324, 327, 333, 340, 348, 352, 359, 367, 369, 371, 373, 375, 377, 379, 384, 389, 397, 400, 409, 412, 416, 424, 431, 440, 453, 456, 459, 462, 465, 468, 471, 477, 480, 483, 489, 493, 496, 500, 505, 510, 516, 521, 525, 530, 538, 546, 552, 561, 572, 579, 588, 592, 599, 607, 611, 615, 619, 626, 633, 641, 647, 656, 667, 675, 684, 689, 694, 698, 706, 711, 715, 718, 726, 730, 732, 737, 739, 744, 750, 756, 762, 768, 776, 781, 788, 793, 797, 802, 806, 811, 819, 825, 832, 839, 845, 852, 865, 879, 894, 905, 913, 917, 928, 939, 942} +var _Op_index = [...]uint16{0, 3, 7, 13, 17, 24, 27, 30, 33, 35, 38, 44, 48, 54, 60, 69, 81, 90, 99, 111, 120, 132, 134, 137, 147, 154, 161, 168, 172, 176, 184, 192, 201, 204, 209, 216, 223, 229, 238, 246, 254, 260, 264, 273, 282, 289, 293, 296, 303, 311, 318, 324, 327, 333, 340, 348, 352, 359, 367, 369, 371, 373, 375, 377, 379, 384, 389, 397, 400, 409, 412, 416, 424, 431, 440, 453, 456, 459, 462, 465, 468, 471, 477, 480, 483, 489, 493, 496, 500, 505, 510, 516, 521, 525, 530, 538, 546, 552, 561, 572, 579, 588, 592, 599, 607, 611, 615, 622, 629, 637, 643, 652, 663, 671, 680, 685, 690, 694, 702, 707, 711, 714, 722, 726, 728, 733, 735, 740, 746, 752, 758, 764, 772, 777, 784, 789, 793, 798, 802, 807, 815, 821, 828, 835, 841, 848, 861, 875, 890, 901, 909, 913, 924, 935, 938} func (i Op) String() string { if i >= Op(len(_Op_index)-1) { diff --git a/src/cmd/compile/internal/ir/sizeof_test.go b/src/cmd/compile/internal/ir/sizeof_test.go index fca11ffc7cb..c1167f23f8e 100644 --- a/src/cmd/compile/internal/ir/sizeof_test.go +++ b/src/cmd/compile/internal/ir/sizeof_test.go @@ -20,7 +20,7 @@ func TestSizeof(t *testing.T) { _32bit uintptr // size on 32bit platforms _64bit uintptr // size on 64bit platforms }{ - {Func{}, 192, 328}, + {Func{}, 184, 320}, {Name{}, 108, 192}, } diff --git a/src/cmd/compile/internal/typecheck/func.go b/src/cmd/compile/internal/typecheck/func.go index c6fd273bd12..5c1a2341b63 100644 --- a/src/cmd/compile/internal/typecheck/func.go +++ b/src/cmd/compile/internal/typecheck/func.go @@ -241,12 +241,6 @@ func tcClosure(clo *ir.ClosureExpr, top int) ir.Node { base.FatalfAt(fn.Pos(), "underlying closure func already typechecked: %v", fn) } - // Set current associated iota value, so iota can be used inside - // function in ConstSpec, see issue #22344 - if x := getIotaValue(); x >= 0 { - fn.Iota = x - } - ir.NameClosure(clo, ir.CurFunc) Func(fn) diff --git a/src/cmd/compile/internal/typecheck/typecheck.go b/src/cmd/compile/internal/typecheck/typecheck.go index 71a78416842..6b1c820818e 100644 --- a/src/cmd/compile/internal/typecheck/typecheck.go +++ b/src/cmd/compile/internal/typecheck/typecheck.go @@ -153,13 +153,6 @@ func Resolve(n ir.Node) (res ir.Node) { return n } - if r.Op() == ir.OIOTA { - if x := getIotaValue(); x >= 0 { - return ir.NewInt(x) - } - return n - } - return r } @@ -2152,22 +2145,6 @@ func CheckReturn(fn *ir.Func) { } } -// getIotaValue returns the current value for "iota", -// or -1 if not within a ConstSpec. -func getIotaValue() int64 { - if i := len(typecheckdefstack); i > 0 { - if x := typecheckdefstack[i-1]; x.Op() == ir.OLITERAL { - return x.Iota() - } - } - - if ir.CurFunc != nil && ir.CurFunc.Iota >= 0 { - return ir.CurFunc.Iota - } - - return -1 -} - // curpkg returns the current package, based on Curfn. func curpkg() *types.Pkg { fn := ir.CurFunc diff --git a/src/cmd/compile/internal/typecheck/universe.go b/src/cmd/compile/internal/typecheck/universe.go index 0254d96e682..204c31b7582 100644 --- a/src/cmd/compile/internal/typecheck/universe.go +++ b/src/cmd/compile/internal/typecheck/universe.go @@ -7,7 +7,6 @@ package typecheck import ( "go/constant" - "cmd/compile/internal/base" "cmd/compile/internal/ir" "cmd/compile/internal/types" "cmd/internal/src" @@ -108,9 +107,6 @@ func InitUniverse() { nnil.(*ir.NilExpr).SetSym(s) s.Def = nnil - s = types.BuiltinPkg.Lookup("iota") - s.Def = ir.NewIota(base.Pos, s) - // initialize okfor for et := types.Kind(0); et < types.NTYPE; et++ { if types.IsInt[et] || et == types.TIDEAL { From 81d3c25c6cf39a76b17ab4eda97e8ad7b92a21e9 Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Tue, 15 Mar 2022 23:07:41 -0700 Subject: [PATCH 121/276] cmd/compile: remove unused code from typecheckdef typecheckdef used to be used to handle references to package-level declarations that hadn't yet been typechecked yet. It's no longer needed, as the current IR frontends construct package-level declarations with proper types upfront. Exception: this code is still used for compiler-generated function declarations, so that code needs to be kept. Eventually that code can be moved elsewhere, but for now this CL makes it obvious that the rest of the code paths really are unused. Updates #51691. Change-Id: I5322edb686aaf5dc4627288f3d9ba910a017b41d Reviewed-on: https://go-review.googlesource.com/c/go/+/393256 Trust: Matthew Dempsky Run-TryBot: Matthew Dempsky TryBot-Result: Gopher Robot Reviewed-by: Cuong Manh Le --- .../compile/internal/typecheck/typecheck.go | 156 +----------------- 1 file changed, 6 insertions(+), 150 deletions(-) diff --git a/src/cmd/compile/internal/typecheck/typecheck.go b/src/cmd/compile/internal/typecheck/typecheck.go index 6b1c820818e..9c084934c3b 100644 --- a/src/cmd/compile/internal/typecheck/typecheck.go +++ b/src/cmd/compile/internal/typecheck/typecheck.go @@ -1686,41 +1686,6 @@ func stringtoruneslit(n *ir.ConvExpr) ir.Node { return Expr(nn) } -func typecheckdeftype(n *ir.Name) { - if base.EnableTrace && base.Flag.LowerT { - defer tracePrint("typecheckdeftype", n)(nil) - } - - t := types.NewNamed(n) - if n.Curfn != nil { - t.SetVargen() - } - - if n.Pragma()&ir.NotInHeap != 0 { - t.SetNotInHeap(true) - } - - n.SetType(t) - n.SetTypecheck(1) - n.SetWalkdef(1) - - types.DeferCheckSize() - errorsBefore := base.Errors() - n.Ntype = typecheckNtype(n.Ntype) - if underlying := n.Ntype.Type(); underlying != nil { - t.SetUnderlying(underlying) - } else { - n.SetDiag(true) - n.SetType(nil) - } - if t.Kind() == types.TFORW && base.Errors() > errorsBefore { - // Something went wrong during type-checking, - // but it was reported. Silence future errors. - t.SetBroke(true) - } - types.ResumeCheckSize() -} - func typecheckdef(n *ir.Name) { if base.EnableTrace && base.Flag.LowerT { defer tracePrint("typecheckdef", n)(nil) @@ -1741,15 +1706,7 @@ func typecheckdef(n *ir.Name) { } lno := ir.SetPos(n) - typecheckdefstack = append(typecheckdefstack, n) if n.Walkdef() == 2 { - base.FlushErrors() - fmt.Printf("typecheckdef loop:") - for i := len(typecheckdefstack) - 1; i >= 0; i-- { - n := typecheckdefstack[i] - fmt.Printf(" %v", n.Sym()) - } - fmt.Printf("\n") base.Fatalf("typecheckdef loop") } @@ -1759,126 +1716,25 @@ func typecheckdef(n *ir.Name) { default: base.Fatalf("typecheckdef %v", n.Op()) - case ir.OLITERAL: - if n.Ntype != nil { - n.Ntype = typecheckNtype(n.Ntype) - n.SetType(n.Ntype.Type()) - n.Ntype = nil - if n.Type() == nil { - n.SetDiag(true) - goto ret - } - } - - e := n.Defn - n.Defn = nil - if e == nil { - ir.Dump("typecheckdef nil defn", n) - base.ErrorfAt(n.Pos(), "xxx") - } - - e = Expr(e) - if e.Type() == nil { - goto ret - } - if !ir.IsConstNode(e) { - if !e.Diag() { - if e.Op() == ir.ONIL { - base.ErrorfAt(n.Pos(), "const initializer cannot be nil") - } else { - base.ErrorfAt(n.Pos(), "const initializer %v is not a constant", e) - } - e.SetDiag(true) - } - goto ret - } - - t := n.Type() - if t != nil { - if !ir.OKForConst[t.Kind()] { - base.ErrorfAt(n.Pos(), "invalid constant type %v", t) - goto ret - } - - if !e.Type().IsUntyped() && !types.Identical(t, e.Type()) { - base.ErrorfAt(n.Pos(), "cannot use %L as type %v in const initializer", e, t) - goto ret - } - - e = convlit(e, t) + case ir.ONAME: + if n.BuiltinOp != 0 { // like OPRINTN + base.Assertf(n.Ntype == nil, "unexpected Ntype: %+v", n) + break } - n.SetType(e.Type()) - if n.Type() != nil { - n.SetVal(e.Val()) - } + base.Assertf(n.Class == ir.PFUNC, "expected PFUNC: %+v", n) - case ir.ONAME: if n.Ntype != nil { n.Ntype = typecheckNtype(n.Ntype) n.SetType(n.Ntype.Type()) - if n.Type() == nil { - n.SetDiag(true) - goto ret - } } if n.Type() != nil { break } - if n.Defn == nil { - if n.BuiltinOp != 0 { // like OPRINTN - break - } - if base.Errors() > 0 { - // Can have undefined variables in x := foo - // that make x have an n.name.Defn == nil. - // If there are other errors anyway, don't - // bother adding to the noise. - break - } - - base.Fatalf("var without type, init: %v", n.Sym()) - } - - if n.Defn.Op() == ir.ONAME { - n.Defn = Expr(n.Defn) - n.SetType(n.Defn.Type()) - break - } - - n.Defn = Stmt(n.Defn) // fills in n.Type - - case ir.OTYPE: - if n.Alias() { - // Type alias declaration: Simply use the rhs type - no need - // to create a new type. - // If we have a syntax error, name.Ntype may be nil. - if n.Ntype != nil { - n.Ntype = typecheckNtype(n.Ntype) - n.SetType(n.Ntype.Type()) - if n.Type() == nil { - n.SetDiag(true) - goto ret - } - } - break - } - - // regular type declaration - typecheckdeftype(n) - } -ret: - if n.Op() != ir.OLITERAL && n.Type() != nil && n.Type().IsUntyped() { - base.Fatalf("got %v for %v", n.Type(), n) - } - last := len(typecheckdefstack) - 1 - if typecheckdefstack[last] != n { - base.Fatalf("typecheckdefstack mismatch") + base.Fatalf("missing type: %v", n) } - typecheckdefstack[last] = nil - typecheckdefstack = typecheckdefstack[:last] base.Pos = lno n.SetWalkdef(1) From 91631bc7e0131367eb051b581cf34573399ac592 Mon Sep 17 00:00:00 2001 From: Cherry Mui Date: Wed, 16 Mar 2022 13:07:57 -0400 Subject: [PATCH 122/276] cmd/link: mark unexported methods for plugins When plugin is used, we already mark all exported methods reachable. However, when the plugin and the host program share a common package, an unexported method could also be reachable from both the plugin and the host via interfaces. We need to mark them as well. Fixes #51621. Change-Id: I1a70d3f96b66b803f2d0ab14d00ed0df276ea500 Reviewed-on: https://go-review.googlesource.com/c/go/+/393365 Trust: Cherry Mui Run-TryBot: Cherry Mui TryBot-Result: Gopher Robot Reviewed-by: Than McIntosh --- misc/cgo/testplugin/plugin_test.go | 6 ++++ misc/cgo/testplugin/testdata/method3/main.go | 32 +++++++++++++++++++ misc/cgo/testplugin/testdata/method3/p/p.go | 17 ++++++++++ .../cgo/testplugin/testdata/method3/plugin.go | 11 +++++++ src/cmd/link/internal/ld/deadcode.go | 2 +- 5 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 misc/cgo/testplugin/testdata/method3/main.go create mode 100644 misc/cgo/testplugin/testdata/method3/p/p.go create mode 100644 misc/cgo/testplugin/testdata/method3/plugin.go diff --git a/misc/cgo/testplugin/plugin_test.go b/misc/cgo/testplugin/plugin_test.go index 10c5db2646b..53e79a46265 100644 --- a/misc/cgo/testplugin/plugin_test.go +++ b/misc/cgo/testplugin/plugin_test.go @@ -283,6 +283,12 @@ func TestMethod2(t *testing.T) { run(t, "./method2.exe") } +func TestMethod3(t *testing.T) { + goCmd(t, "build", "-buildmode=plugin", "-o", "method3.so", "./method3/plugin.go") + goCmd(t, "build", "-o", "method3.exe", "./method3/main.go") + run(t, "./method3.exe") +} + func TestIssue44956(t *testing.T) { goCmd(t, "build", "-buildmode=plugin", "-o", "issue44956p1.so", "./issue44956/plugin1.go") goCmd(t, "build", "-buildmode=plugin", "-o", "issue44956p2.so", "./issue44956/plugin2.go") diff --git a/misc/cgo/testplugin/testdata/method3/main.go b/misc/cgo/testplugin/testdata/method3/main.go new file mode 100644 index 00000000000..a3a51711cda --- /dev/null +++ b/misc/cgo/testplugin/testdata/method3/main.go @@ -0,0 +1,32 @@ +// Copyright 2022 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. + +// An unexported method can be reachable from the plugin via interface +// when a package is shared. So it need to be live. + +package main + +import ( + "plugin" + + "testplugin/method3/p" +) + +var i p.I + +func main() { + pl, err := plugin.Open("method3.so") + if err != nil { + panic(err) + } + + f, err := pl.Lookup("F") + if err != nil { + panic(err) + } + + f.(func())() + + i = p.T(123) +} diff --git a/misc/cgo/testplugin/testdata/method3/p/p.go b/misc/cgo/testplugin/testdata/method3/p/p.go new file mode 100644 index 00000000000..3846bc07f50 --- /dev/null +++ b/misc/cgo/testplugin/testdata/method3/p/p.go @@ -0,0 +1,17 @@ +// Copyright 2022 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 p + +type T int + +func (T) m() { println("m") } + +type I interface { m() } + +func F() { + i.m() +} + +var i I = T(123) diff --git a/misc/cgo/testplugin/testdata/method3/plugin.go b/misc/cgo/testplugin/testdata/method3/plugin.go new file mode 100644 index 00000000000..bd25b31857e --- /dev/null +++ b/misc/cgo/testplugin/testdata/method3/plugin.go @@ -0,0 +1,11 @@ +// Copyright 2022 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 main + +import "testplugin/method3/p" + +func main() {} + +func F() { p.F() } diff --git a/src/cmd/link/internal/ld/deadcode.go b/src/cmd/link/internal/ld/deadcode.go index dba22323b0c..3ba4b06f4a5 100644 --- a/src/cmd/link/internal/ld/deadcode.go +++ b/src/cmd/link/internal/ld/deadcode.go @@ -355,7 +355,7 @@ func deadcode(ctxt *Link) { // in the last pass. rem := d.markableMethods[:0] for _, m := range d.markableMethods { - if (d.reflectSeen && m.isExported()) || d.ifaceMethod[m.m] || d.genericIfaceMethod[m.m.name] { + if (d.reflectSeen && (m.isExported() || d.dynlink)) || d.ifaceMethod[m.m] || d.genericIfaceMethod[m.m.name] { d.markMethod(m) } else { rem = append(rem, m) From ed4db861182456a63b7d837780c146d4e58e63d8 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 16 Mar 2022 12:27:07 -0400 Subject: [PATCH 123/276] cmd/api: remove debug print Left over from CL 392414. Change-Id: I32ff1d660ba03d6c2005ad247e2129daf83aac04 Reviewed-on: https://go-review.googlesource.com/c/go/+/393361 Trust: Russ Cox Run-TryBot: Russ Cox TryBot-Result: Gopher Robot Reviewed-by: Dmitri Shuralyov --- src/cmd/api/run.go | 1 - 1 file changed, 1 deletion(-) diff --git a/src/cmd/api/run.go b/src/cmd/api/run.go index 130166e7b92..3ceaae6b894 100644 --- a/src/cmd/api/run.go +++ b/src/cmd/api/run.go @@ -61,7 +61,6 @@ func main() { "-next", strings.Join(next, ","), "-except", "except.txt", ) - fmt.Println(cmd.Args) out, err := cmd.CombinedOutput() if err != nil { log.Fatalf("Error running API checker: %v\n%s", err, out) From e5e638e512e1ec27673d5e01e99eb870899be7f7 Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Wed, 16 Mar 2022 09:24:06 -0700 Subject: [PATCH 124/276] cmd/compile: allow noop conversions when comparing expressions Allows mapclear optimization to trigger in more cases, including some generic instantiations. Fixes #51699 Change-Id: Ic54f7686e5fcb8fbcad640aa77ed326d7338b938 Reviewed-on: https://go-review.googlesource.com/c/go/+/393434 Trust: Keith Randall Run-TryBot: Keith Randall Reviewed-by: Cuong Manh Le TryBot-Result: Gopher Robot --- src/cmd/compile/internal/ir/expr.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/cmd/compile/internal/ir/expr.go b/src/cmd/compile/internal/ir/expr.go index ebb84ad78fb..ff3cc8ed6e7 100644 --- a/src/cmd/compile/internal/ir/expr.go +++ b/src/cmd/compile/internal/ir/expr.go @@ -973,6 +973,12 @@ var IsIntrinsicCall = func(*CallExpr) bool { return false } // lvalue expression is for OSLICE and OAPPEND optimizations, and it // is correct in those settings. func SameSafeExpr(l Node, r Node) bool { + for l.Op() == OCONVNOP { + l = l.(*ConvExpr).X + } + for r.Op() == OCONVNOP { + r = r.(*ConvExpr).X + } if l.Op() != r.Op() || !types.Identical(l.Type(), r.Type()) { return false } @@ -996,11 +1002,6 @@ func SameSafeExpr(l Node, r Node) bool { r := r.(*UnaryExpr) return SameSafeExpr(l.X, r.X) - case OCONVNOP: - l := l.(*ConvExpr) - r := r.(*ConvExpr) - return SameSafeExpr(l.X, r.X) - case OCONV: l := l.(*ConvExpr) r := r.(*ConvExpr) From 8d4da2c7b582783f30f9c93c2bcb0641748103e2 Mon Sep 17 00:00:00 2001 From: Robert Findley Date: Wed, 16 Mar 2022 18:42:57 -0400 Subject: [PATCH 125/276] all: update vendored golang.org/x/tools Update the vendored golang.org/x/tools to pick up the fix for #51717. This also picks up some changes to support Fuzz tests in the tests analyzer, but they are currently still guarded by an internal flag. Fixes #51717 Updates #36905 Change-Id: Ibcd5006624dd9cd9797c811093985e8775c57d51 Reviewed-on: https://go-review.googlesource.com/c/go/+/393373 Reviewed-by: Dmitri Shuralyov Trust: Robert Findley Run-TryBot: Robert Findley TryBot-Result: Gopher Robot --- src/cmd/go.mod | 4 +- src/cmd/go.sum | 8 +- .../go/analysis/passes/composite/whitelist.go | 9 +- .../x/tools/go/analysis/passes/tests/tests.go | 230 ++++++++++++++++++ .../x/tools/go/types/objectpath/objectpath.go | 56 +++-- .../x/tools/go/types/typeutil/map.go | 10 +- .../internal/analysisinternal/analysis.go | 3 + .../x/tools/internal/typeparams/common.go | 101 ++++++++ .../internal/typeparams/typeparams_go117.go | 5 + .../internal/typeparams/typeparams_go118.go | 5 + src/cmd/vendor/modules.txt | 4 +- 11 files changed, 396 insertions(+), 39 deletions(-) diff --git a/src/cmd/go.mod b/src/cmd/go.mod index fd54a886309..c5582e7dc7c 100644 --- a/src/cmd/go.mod +++ b/src/cmd/go.mod @@ -5,11 +5,11 @@ go 1.18 require ( github.com/google/pprof v0.0.0-20211104044539-f987b9c94b31 golang.org/x/arch v0.0.0-20210923205945-b76863e36670 - golang.org/x/mod v0.6.0-dev.0.20211102181907-3a5865c02020 + golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 golang.org/x/sync v0.0.0-20210220032951-036812b2e83c golang.org/x/sys v0.0.0-20211205182925-97ca703d548d golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 - golang.org/x/tools v0.1.9-0.20220124164225-97de9ec46646 + golang.org/x/tools v0.1.11-0.20220316221636-85d68bc98d0d ) require ( diff --git a/src/cmd/go.sum b/src/cmd/go.sum index 4a5479f881b..9060d68517b 100644 --- a/src/cmd/go.sum +++ b/src/cmd/go.sum @@ -9,8 +9,8 @@ golang.org/x/arch v0.0.0-20210923205945-b76863e36670 h1:18EFjUmQOcUvxNYSkA6jO9VA golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 h1:0es+/5331RGQPcXlMfP+WrnIIS6dNnNRe0WB02W0F4M= golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/mod v0.6.0-dev.0.20211102181907-3a5865c02020 h1:HjtpZuJcnSa+yHlL4Y5aypjDvbHkJne5FS8JRmKI2+I= -golang.org/x/mod v0.6.0-dev.0.20211102181907-3a5865c02020/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY= +golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 h1:kQgndtyPBW/JIYERgdxfwMYh3AVStj88WQTlNDi2a+o= +golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -18,7 +18,7 @@ golang.org/x/sys v0.0.0-20211205182925-97ca703d548d h1:FjkYO/PPp4Wi0EAUOVLxePm7q golang.org/x/sys v0.0.0-20211205182925-97ca703d548d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/tools v0.1.9-0.20220124164225-97de9ec46646 h1:f8aekWvlQQ8ZhD8SL7lOu18dtWslZYl029PN2F0VnS4= -golang.org/x/tools v0.1.9-0.20220124164225-97de9ec46646/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU= +golang.org/x/tools v0.1.11-0.20220316221636-85d68bc98d0d h1:ODHIU0shdFMaUzD/IIhSde/2e2hoMJlgKMKF3e2rCHU= +golang.org/x/tools v0.1.11-0.20220316221636-85d68bc98d0d/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/composite/whitelist.go b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/composite/whitelist.go index 1e5f5fd20b5..f84c1871d7d 100644 --- a/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/composite/whitelist.go +++ b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/composite/whitelist.go @@ -26,9 +26,10 @@ var unkeyedLiteral = map[string]bool{ "unicode.Range16": true, "unicode.Range32": true, - // These three structs are used in generated test main files, + // These four structs are used in generated test main files, // but the generator can be trusted. - "testing.InternalBenchmark": true, - "testing.InternalExample": true, - "testing.InternalTest": true, + "testing.InternalBenchmark": true, + "testing.InternalExample": true, + "testing.InternalTest": true, + "testing.InternalFuzzTarget": true, } diff --git a/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/tests/tests.go b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/tests/tests.go index 2c878824966..ffa5205dd77 100644 --- a/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/tests/tests.go +++ b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/tests/tests.go @@ -7,6 +7,7 @@ package tests import ( + "fmt" "go/ast" "go/token" "go/types" @@ -16,6 +17,7 @@ import ( "unicode/utf8" "golang.org/x/tools/go/analysis" + "golang.org/x/tools/internal/analysisinternal" "golang.org/x/tools/internal/typeparams" ) @@ -34,6 +36,24 @@ var Analyzer = &analysis.Analyzer{ Run: run, } +var acceptedFuzzTypes = []types.Type{ + types.Typ[types.String], + types.Typ[types.Bool], + types.Typ[types.Float32], + types.Typ[types.Float64], + types.Typ[types.Int], + types.Typ[types.Int8], + types.Typ[types.Int16], + types.Typ[types.Int32], + types.Typ[types.Int64], + types.Typ[types.Uint], + types.Typ[types.Uint8], + types.Typ[types.Uint16], + types.Typ[types.Uint32], + types.Typ[types.Uint64], + types.NewSlice(types.Universe.Lookup("byte").Type()), +} + func run(pass *analysis.Pass) (interface{}, error) { for _, f := range pass.Files { if !strings.HasSuffix(pass.Fset.File(f.Pos()).Name(), "_test.go") { @@ -54,11 +74,221 @@ func run(pass *analysis.Pass) (interface{}, error) { case strings.HasPrefix(fn.Name.Name, "Benchmark"): checkTest(pass, fn, "Benchmark") } + // run fuzz tests diagnostics only for 1.18 i.e. when analysisinternal.DiagnoseFuzzTests is turned on. + if strings.HasPrefix(fn.Name.Name, "Fuzz") && analysisinternal.DiagnoseFuzzTests { + checkTest(pass, fn, "Fuzz") + checkFuzz(pass, fn) + } } } return nil, nil } +// Checks the contents of a fuzz function. +func checkFuzz(pass *analysis.Pass, fn *ast.FuncDecl) { + params := checkFuzzCall(pass, fn) + if params != nil { + checkAddCalls(pass, fn, params) + } +} + +// Check the arguments of f.Fuzz() calls : +// 1. f.Fuzz() should call a function and it should be of type (*testing.F).Fuzz(). +// 2. The called function in f.Fuzz(func(){}) should not return result. +// 3. First argument of func() should be of type *testing.T +// 4. Second argument onwards should be of type []byte, string, bool, byte, +// rune, float32, float64, int, int8, int16, int32, int64, uint, uint8, uint16, +// uint32, uint64 +// 5. func() must not call any *F methods, e.g. (*F).Log, (*F).Error, (*F).Skip +// The only *F methods that are allowed in the (*F).Fuzz function are (*F).Failed and (*F).Name. +// Returns the list of parameters to the fuzz function, if they are valid fuzz parameters. +func checkFuzzCall(pass *analysis.Pass, fn *ast.FuncDecl) (params *types.Tuple) { + ast.Inspect(fn, func(n ast.Node) bool { + call, ok := n.(*ast.CallExpr) + if ok { + if !isFuzzTargetDotFuzz(pass, call) { + return true + } + + // Only one argument (func) must be passed to (*testing.F).Fuzz. + if len(call.Args) != 1 { + return true + } + expr := call.Args[0] + if pass.TypesInfo.Types[expr].Type == nil { + return true + } + t := pass.TypesInfo.Types[expr].Type.Underlying() + tSign, argOk := t.(*types.Signature) + // Argument should be a function + if !argOk { + pass.ReportRangef(expr, "argument to Fuzz must be a function") + return false + } + // ff Argument function should not return + if tSign.Results().Len() != 0 { + pass.ReportRangef(expr, "fuzz target must not return any value") + } + // ff Argument function should have 1 or more argument + if tSign.Params().Len() == 0 { + pass.ReportRangef(expr, "fuzz target must have 1 or more argument") + return false + } + ok := validateFuzzArgs(pass, tSign.Params(), expr) + if ok && params == nil { + params = tSign.Params() + } + // Inspect the function that was passed as an argument to make sure that + // there are no calls to *F methods, except for Name and Failed. + ast.Inspect(expr, func(n ast.Node) bool { + if call, ok := n.(*ast.CallExpr); ok { + if !isFuzzTargetDot(pass, call, "") { + return true + } + if !isFuzzTargetDot(pass, call, "Name") && !isFuzzTargetDot(pass, call, "Failed") { + pass.ReportRangef(call, "fuzz target must not call any *F methods") + } + } + return true + }) + // We do not need to look at any calls to f.Fuzz inside of a Fuzz call, + // since they are not allowed. + return false + } + return true + }) + return params +} + +// Check that the arguments of f.Add() calls have the same number and type of arguments as +// the signature of the function passed to (*testing.F).Fuzz +func checkAddCalls(pass *analysis.Pass, fn *ast.FuncDecl, params *types.Tuple) { + ast.Inspect(fn, func(n ast.Node) bool { + call, ok := n.(*ast.CallExpr) + if ok { + if !isFuzzTargetDotAdd(pass, call) { + return true + } + + // The first argument to function passed to (*testing.F).Fuzz is (*testing.T). + if len(call.Args) != params.Len()-1 { + pass.ReportRangef(call, "wrong number of values in call to (*testing.F).Add: %d, fuzz target expects %d", len(call.Args), params.Len()-1) + return true + } + var mismatched []int + for i, expr := range call.Args { + if pass.TypesInfo.Types[expr].Type == nil { + return true + } + t := pass.TypesInfo.Types[expr].Type + if !types.Identical(t, params.At(i+1).Type()) { + mismatched = append(mismatched, i) + } + } + // If just one of the types is mismatched report for that + // type only. Otherwise report for the whole call to (*testing.F).Add + if len(mismatched) == 1 { + i := mismatched[0] + expr := call.Args[i] + t := pass.TypesInfo.Types[expr].Type + pass.ReportRangef(expr, fmt.Sprintf("mismatched type in call to (*testing.F).Add: %v, fuzz target expects %v", t, params.At(i+1).Type())) + } else if len(mismatched) > 1 { + var gotArgs, wantArgs []types.Type + for i := 0; i < len(call.Args); i++ { + gotArgs, wantArgs = append(gotArgs, pass.TypesInfo.Types[call.Args[i]].Type), append(wantArgs, params.At(i+1).Type()) + } + pass.ReportRangef(call, fmt.Sprintf("mismatched types in call to (*testing.F).Add: %v, fuzz target expects %v", gotArgs, wantArgs)) + } + } + return true + }) +} + +// isFuzzTargetDotFuzz reports whether call is (*testing.F).Fuzz(). +func isFuzzTargetDotFuzz(pass *analysis.Pass, call *ast.CallExpr) bool { + return isFuzzTargetDot(pass, call, "Fuzz") +} + +// isFuzzTargetDotAdd reports whether call is (*testing.F).Add(). +func isFuzzTargetDotAdd(pass *analysis.Pass, call *ast.CallExpr) bool { + return isFuzzTargetDot(pass, call, "Add") +} + +// isFuzzTargetDot reports whether call is (*testing.F).(). +func isFuzzTargetDot(pass *analysis.Pass, call *ast.CallExpr, name string) bool { + if selExpr, ok := call.Fun.(*ast.SelectorExpr); ok { + if !isTestingType(pass.TypesInfo.Types[selExpr.X].Type, "F") { + return false + } + if name == "" || selExpr.Sel.Name == name { + return true + } + } + return false +} + +// Validate the arguments of fuzz target. +func validateFuzzArgs(pass *analysis.Pass, params *types.Tuple, expr ast.Expr) bool { + fLit, isFuncLit := expr.(*ast.FuncLit) + exprRange := expr + ok := true + if !isTestingType(params.At(0).Type(), "T") { + if isFuncLit { + exprRange = fLit.Type.Params.List[0].Type + } + pass.ReportRangef(exprRange, "the first parameter of a fuzz target must be *testing.T") + ok = false + } + for i := 1; i < params.Len(); i++ { + if !isAcceptedFuzzType(params.At(i).Type()) { + if isFuncLit { + curr := 0 + for _, field := range fLit.Type.Params.List { + curr += len(field.Names) + if i < curr { + exprRange = field.Type + break + } + } + } + pass.ReportRangef(exprRange, "fuzzing arguments can only have the following types: "+formatAcceptedFuzzType()) + ok = false + } + } + return ok +} + +func isTestingType(typ types.Type, testingType string) bool { + ptr, ok := typ.(*types.Pointer) + if !ok { + return false + } + named, ok := ptr.Elem().(*types.Named) + if !ok { + return false + } + return named.Obj().Pkg().Path() == "testing" && named.Obj().Name() == testingType +} + +// Validate that fuzz target function's arguments are of accepted types. +func isAcceptedFuzzType(paramType types.Type) bool { + for _, typ := range acceptedFuzzTypes { + if types.Identical(typ, paramType) { + return true + } + } + return false +} + +func formatAcceptedFuzzType() string { + var acceptedFuzzTypesStrings []string + for _, typ := range acceptedFuzzTypes { + acceptedFuzzTypesStrings = append(acceptedFuzzTypesStrings, typ.String()) + } + acceptedFuzzTypesMsg := strings.Join(acceptedFuzzTypesStrings, ", ") + return acceptedFuzzTypesMsg +} + func isExampleSuffix(s string) bool { r, size := utf8.DecodeRuneInString(s) return size > 0 && unicode.IsLower(r) diff --git a/src/cmd/vendor/golang.org/x/tools/go/types/objectpath/objectpath.go b/src/cmd/vendor/golang.org/x/tools/go/types/objectpath/objectpath.go index 7e96fc234e5..557202b4d16 100644 --- a/src/cmd/vendor/golang.org/x/tools/go/types/objectpath/objectpath.go +++ b/src/cmd/vendor/golang.org/x/tools/go/types/objectpath/objectpath.go @@ -254,18 +254,18 @@ func For(obj types.Object) (Path, error) { if tname.IsAlias() { // type alias - if r := find(obj, T, path); r != nil { + if r := find(obj, T, path, nil); r != nil { return Path(r), nil } } else { if named, _ := T.(*types.Named); named != nil { - if r := findTypeParam(obj, typeparams.ForNamed(named), path); r != nil { + if r := findTypeParam(obj, typeparams.ForNamed(named), path, nil); r != nil { // generic named type return Path(r), nil } } // defined (named) type - if r := find(obj, T.Underlying(), append(path, opUnderlying)); r != nil { + if r := find(obj, T.Underlying(), append(path, opUnderlying), nil); r != nil { return Path(r), nil } } @@ -279,7 +279,7 @@ func For(obj types.Object) (Path, error) { if _, ok := o.(*types.TypeName); !ok { if o.Exported() { // exported non-type (const, var, func) - if r := find(obj, o.Type(), append(path, opType)); r != nil { + if r := find(obj, o.Type(), append(path, opType), nil); r != nil { return Path(r), nil } } @@ -299,7 +299,7 @@ func For(obj types.Object) (Path, error) { if m == obj { return Path(path2), nil // found declared method } - if r := find(obj, m.Type(), append(path2, opType)); r != nil { + if r := find(obj, m.Type(), append(path2, opType), nil); r != nil { return Path(r), nil } } @@ -316,41 +316,44 @@ func appendOpArg(path []byte, op byte, arg int) []byte { } // find finds obj within type T, returning the path to it, or nil if not found. -func find(obj types.Object, T types.Type, path []byte) []byte { +// +// The seen map is used to short circuit cycles through type parameters. If +// nil, it will be allocated as necessary. +func find(obj types.Object, T types.Type, path []byte, seen map[*types.TypeName]bool) []byte { switch T := T.(type) { case *types.Basic, *types.Named: // Named types belonging to pkg were handled already, // so T must belong to another package. No path. return nil case *types.Pointer: - return find(obj, T.Elem(), append(path, opElem)) + return find(obj, T.Elem(), append(path, opElem), seen) case *types.Slice: - return find(obj, T.Elem(), append(path, opElem)) + return find(obj, T.Elem(), append(path, opElem), seen) case *types.Array: - return find(obj, T.Elem(), append(path, opElem)) + return find(obj, T.Elem(), append(path, opElem), seen) case *types.Chan: - return find(obj, T.Elem(), append(path, opElem)) + return find(obj, T.Elem(), append(path, opElem), seen) case *types.Map: - if r := find(obj, T.Key(), append(path, opKey)); r != nil { + if r := find(obj, T.Key(), append(path, opKey), seen); r != nil { return r } - return find(obj, T.Elem(), append(path, opElem)) + return find(obj, T.Elem(), append(path, opElem), seen) case *types.Signature: - if r := findTypeParam(obj, typeparams.ForSignature(T), path); r != nil { + if r := findTypeParam(obj, typeparams.ForSignature(T), path, seen); r != nil { return r } - if r := find(obj, T.Params(), append(path, opParams)); r != nil { + if r := find(obj, T.Params(), append(path, opParams), seen); r != nil { return r } - return find(obj, T.Results(), append(path, opResults)) + return find(obj, T.Results(), append(path, opResults), seen) case *types.Struct: for i := 0; i < T.NumFields(); i++ { - f := T.Field(i) + fld := T.Field(i) path2 := appendOpArg(path, opField, i) - if f == obj { + if fld == obj { return path2 // found field var } - if r := find(obj, f.Type(), append(path2, opType)); r != nil { + if r := find(obj, fld.Type(), append(path2, opType), seen); r != nil { return r } } @@ -362,7 +365,7 @@ func find(obj types.Object, T types.Type, path []byte) []byte { if v == obj { return path2 // found param/result var } - if r := find(obj, v.Type(), append(path2, opType)); r != nil { + if r := find(obj, v.Type(), append(path2, opType), seen); r != nil { return r } } @@ -374,7 +377,7 @@ func find(obj types.Object, T types.Type, path []byte) []byte { if m == obj { return path2 // found interface method } - if r := find(obj, m.Type(), append(path2, opType)); r != nil { + if r := find(obj, m.Type(), append(path2, opType), seen); r != nil { return r } } @@ -384,7 +387,14 @@ func find(obj types.Object, T types.Type, path []byte) []byte { if name == obj { return append(path, opObj) } - if r := find(obj, T.Constraint(), append(path, opConstraint)); r != nil { + if seen[name] { + return nil + } + if seen == nil { + seen = make(map[*types.TypeName]bool) + } + seen[name] = true + if r := find(obj, T.Constraint(), append(path, opConstraint), seen); r != nil { return r } return nil @@ -392,11 +402,11 @@ func find(obj types.Object, T types.Type, path []byte) []byte { panic(T) } -func findTypeParam(obj types.Object, list *typeparams.TypeParamList, path []byte) []byte { +func findTypeParam(obj types.Object, list *typeparams.TypeParamList, path []byte, seen map[*types.TypeName]bool) []byte { for i := 0; i < list.Len(); i++ { tparam := list.At(i) path2 := appendOpArg(path, opTypeParam, i) - if r := find(obj, tparam, path2); r != nil { + if r := find(obj, tparam, path2, seen); r != nil { return r } } diff --git a/src/cmd/vendor/golang.org/x/tools/go/types/typeutil/map.go b/src/cmd/vendor/golang.org/x/tools/go/types/typeutil/map.go index 490ee904a62..c9f8f25a0d8 100644 --- a/src/cmd/vendor/golang.org/x/tools/go/types/typeutil/map.go +++ b/src/cmd/vendor/golang.org/x/tools/go/types/typeutil/map.go @@ -379,7 +379,7 @@ func (h Hasher) hashFor(t types.Type) uint32 { func (h Hasher) hashTuple(tuple *types.Tuple) uint32 { // See go/types.identicalTypes for rationale. n := tuple.Len() - var hash uint32 = 9137 + 2*uint32(n) + hash := 9137 + 2*uint32(n) for i := 0; i < n; i++ { hash += 3 * h.Hash(tuple.At(i).Type()) } @@ -398,7 +398,7 @@ func (h Hasher) hashUnion(t *typeparams.Union) uint32 { } func (h Hasher) hashTermSet(terms []*typeparams.Term) uint32 { - var hash uint32 = 9157 + 2*uint32(len(terms)) + hash := 9157 + 2*uint32(len(terms)) for _, term := range terms { // term order is not significant. termHash := h.Hash(term.Type()) @@ -416,14 +416,16 @@ func (h Hasher) hashTermSet(terms []*typeparams.Term) uint32 { // If h.sigTParams is set and contains t, then we are in the process of hashing // a signature, and the hash value of t must depend only on t's index and // constraint: signatures are considered identical modulo type parameter -// renaming. +// renaming. To avoid infinite recursion, we only hash the type parameter +// index, and rely on types.Identical to handle signatures where constraints +// are not identical. // // Otherwise the hash of t depends only on t's pointer identity. func (h Hasher) hashTypeParam(t *typeparams.TypeParam) uint32 { if h.sigTParams != nil { i := t.Index() if i >= 0 && i < h.sigTParams.Len() && t == h.sigTParams.At(i) { - return 9173 + 2*h.Hash(t.Constraint()) + 3*uint32(i) + return 9173 + 3*uint32(i) } } return h.hashPtr(t.Obj()) diff --git a/src/cmd/vendor/golang.org/x/tools/internal/analysisinternal/analysis.go b/src/cmd/vendor/golang.org/x/tools/internal/analysisinternal/analysis.go index 01f6e829f75..78ee2c06bea 100644 --- a/src/cmd/vendor/golang.org/x/tools/internal/analysisinternal/analysis.go +++ b/src/cmd/vendor/golang.org/x/tools/internal/analysisinternal/analysis.go @@ -17,6 +17,9 @@ import ( "golang.org/x/tools/internal/lsp/fuzzy" ) +// Flag to gate diagnostics for fuzz tests in 1.18. +var DiagnoseFuzzTests bool = false + var ( GetTypeErrors func(p interface{}) []types.Error SetTypeErrors func(p interface{}, errors []types.Error) diff --git a/src/cmd/vendor/golang.org/x/tools/internal/typeparams/common.go b/src/cmd/vendor/golang.org/x/tools/internal/typeparams/common.go index 1222764b6a3..ab6b30b83e4 100644 --- a/src/cmd/vendor/golang.org/x/tools/internal/typeparams/common.go +++ b/src/cmd/vendor/golang.org/x/tools/internal/typeparams/common.go @@ -77,3 +77,104 @@ func IsTypeParam(t types.Type) bool { _, ok := t.(*TypeParam) return ok } + +// OriginMethod returns the origin method associated with the method fn. +// For methods on a non-generic receiver base type, this is just +// fn. However, for methods with a generic receiver, OriginMethod returns the +// corresponding method in the method set of the origin type. +// +// As a special case, if fn is not a method (has no receiver), OriginMethod +// returns fn. +func OriginMethod(fn *types.Func) *types.Func { + recv := fn.Type().(*types.Signature).Recv() + if recv == nil { + + return fn + } + base := recv.Type() + p, isPtr := base.(*types.Pointer) + if isPtr { + base = p.Elem() + } + named, isNamed := base.(*types.Named) + if !isNamed { + // Receiver is a *types.Interface. + return fn + } + if ForNamed(named).Len() == 0 { + // Receiver base has no type parameters, so we can avoid the lookup below. + return fn + } + orig := NamedTypeOrigin(named) + gfn, _, _ := types.LookupFieldOrMethod(orig, true, fn.Pkg(), fn.Name()) + return gfn.(*types.Func) +} + +// GenericAssignableTo is a generalization of types.AssignableTo that +// implements the following rule for uninstantiated generic types: +// +// If V and T are generic named types, then V is considered assignable to T if, +// for every possible instantation of V[A_1, ..., A_N], the instantiation +// T[A_1, ..., A_N] is valid and V[A_1, ..., A_N] implements T[A_1, ..., A_N]. +// +// If T has structural constraints, they must be satisfied by V. +// +// For example, consider the following type declarations: +// +// type Interface[T any] interface { +// Accept(T) +// } +// +// type Container[T any] struct { +// Element T +// } +// +// func (c Container[T]) Accept(t T) { c.Element = t } +// +// In this case, GenericAssignableTo reports that instantiations of Container +// are assignable to the corresponding instantiation of Interface. +func GenericAssignableTo(ctxt *Context, V, T types.Type) bool { + // If V and T are not both named, or do not have matching non-empty type + // parameter lists, fall back on types.AssignableTo. + + VN, Vnamed := V.(*types.Named) + TN, Tnamed := T.(*types.Named) + if !Vnamed || !Tnamed { + return types.AssignableTo(V, T) + } + + vtparams := ForNamed(VN) + ttparams := ForNamed(TN) + if vtparams.Len() == 0 || vtparams.Len() != ttparams.Len() || NamedTypeArgs(VN).Len() != 0 || NamedTypeArgs(TN).Len() != 0 { + return types.AssignableTo(V, T) + } + + // V and T have the same (non-zero) number of type params. Instantiate both + // with the type parameters of V. This must always succeed for V, and will + // succeed for T if and only if the type set of each type parameter of V is a + // subset of the type set of the corresponding type parameter of T, meaning + // that every instantiation of V corresponds to a valid instantiation of T. + + // Minor optimization: ensure we share a context across the two + // instantiations below. + if ctxt == nil { + ctxt = NewContext() + } + + var targs []types.Type + for i := 0; i < vtparams.Len(); i++ { + targs = append(targs, vtparams.At(i)) + } + + vinst, err := Instantiate(ctxt, V, targs, true) + if err != nil { + panic("type parameters should satisfy their own constraints") + } + + tinst, err := Instantiate(ctxt, T, targs, true) + if err != nil { + return false + } + + return types.AssignableTo(vinst, tinst) +} diff --git a/src/cmd/vendor/golang.org/x/tools/internal/typeparams/typeparams_go117.go b/src/cmd/vendor/golang.org/x/tools/internal/typeparams/typeparams_go117.go index 5fd3fc35156..b4788978ff4 100644 --- a/src/cmd/vendor/golang.org/x/tools/internal/typeparams/typeparams_go117.go +++ b/src/cmd/vendor/golang.org/x/tools/internal/typeparams/typeparams_go117.go @@ -185,6 +185,11 @@ func GetInstances(info *types.Info) map[*ast.Ident]Instance { return nil } // this Go version. type Context struct{} +// NewContext returns a placeholder Context instance. +func NewContext() *Context { + return &Context{} +} + // Instantiate is unsupported on this Go version, and panics. func Instantiate(ctxt *Context, typ types.Type, targs []types.Type, validate bool) (types.Type, error) { unsupported() diff --git a/src/cmd/vendor/golang.org/x/tools/internal/typeparams/typeparams_go118.go b/src/cmd/vendor/golang.org/x/tools/internal/typeparams/typeparams_go118.go index 7470aed8c99..114a36b866b 100644 --- a/src/cmd/vendor/golang.org/x/tools/internal/typeparams/typeparams_go118.go +++ b/src/cmd/vendor/golang.org/x/tools/internal/typeparams/typeparams_go118.go @@ -140,6 +140,11 @@ func GetInstances(info *types.Info) map[*ast.Ident]Instance { // Context is an alias for types.Context. type Context = types.Context +// NewContext calls types.NewContext. +func NewContext() *Context { + return types.NewContext() +} + // Instantiate calls types.Instantiate. func Instantiate(ctxt *Context, typ types.Type, targs []types.Type, validate bool) (types.Type, error) { return types.Instantiate(ctxt, typ, targs, validate) diff --git a/src/cmd/vendor/modules.txt b/src/cmd/vendor/modules.txt index c373ca05b19..9e797f555bd 100644 --- a/src/cmd/vendor/modules.txt +++ b/src/cmd/vendor/modules.txt @@ -28,7 +28,7 @@ golang.org/x/arch/x86/x86asm ## explicit; go 1.17 golang.org/x/crypto/ed25519 golang.org/x/crypto/ed25519/internal/edwards25519 -# golang.org/x/mod v0.6.0-dev.0.20211102181907-3a5865c02020 +# golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 ## explicit; go 1.17 golang.org/x/mod/internal/lazyregexp golang.org/x/mod/modfile @@ -51,7 +51,7 @@ golang.org/x/sys/windows # golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 ## explicit; go 1.17 golang.org/x/term -# golang.org/x/tools v0.1.9-0.20220124164225-97de9ec46646 +# golang.org/x/tools v0.1.11-0.20220316221636-85d68bc98d0d ## explicit; go 1.17 golang.org/x/tools/cover golang.org/x/tools/go/analysis From 1cfe1007cdf17ee381443cd0d8ae31962805f96e Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Tue, 15 Mar 2022 22:44:31 -0700 Subject: [PATCH 126/276] cmd/compile: remove typecheckdef and Name.Walkdef The only remaining use for typecheckdef after CL 393256 is to typecheck the ONAME node that represents function names, so we might as well just move that code into tcFunc instead. Updates #51691. Change-Id: Icbca51d4b0fb33c90faa95f16254c7171b171d8a Reviewed-on: https://go-review.googlesource.com/c/go/+/393367 Trust: Matthew Dempsky Run-TryBot: Matthew Dempsky TryBot-Result: Gopher Robot Reviewed-by: Cuong Manh Le --- src/cmd/compile/internal/ir/mini.go | 5 +- src/cmd/compile/internal/ir/name.go | 7 --- src/cmd/compile/internal/noder/expr.go | 1 - src/cmd/compile/internal/noder/object.go | 1 - src/cmd/compile/internal/noder/reader.go | 1 - src/cmd/compile/internal/typecheck/func.go | 8 ++- src/cmd/compile/internal/typecheck/stmt.go | 1 - .../compile/internal/typecheck/typecheck.go | 60 ------------------- 8 files changed, 9 insertions(+), 75 deletions(-) diff --git a/src/cmd/compile/internal/ir/mini.go b/src/cmd/compile/internal/ir/mini.go index cfd5dcfb960..cb05dfae26b 100644 --- a/src/cmd/compile/internal/ir/mini.go +++ b/src/cmd/compile/internal/ir/mini.go @@ -55,9 +55,8 @@ func (n *miniNode) Esc() uint16 { return n.esc } func (n *miniNode) SetEsc(x uint16) { n.esc = x } const ( - miniWalkdefShift = 0 // TODO(mdempsky): Move to Name.flags. - miniTypecheckShift = 2 - miniWalked = 1 << 5 // to prevent/catch re-walking + miniTypecheckShift = 0 + miniWalked = 1 << 2 // to prevent/catch re-walking ) func (n *miniNode) Typecheck() uint8 { return n.bits.get2(miniTypecheckShift) } diff --git a/src/cmd/compile/internal/ir/name.go b/src/cmd/compile/internal/ir/name.go index ee28ca83321..183aa6db7c6 100644 --- a/src/cmd/compile/internal/ir/name.go +++ b/src/cmd/compile/internal/ir/name.go @@ -215,13 +215,6 @@ func (n *Name) SetOffset(x int64) { } func (n *Name) FrameOffset() int64 { return n.Offset_ } func (n *Name) SetFrameOffset(x int64) { n.Offset_ = x } -func (n *Name) Walkdef() uint8 { return n.bits.get2(miniWalkdefShift) } -func (n *Name) SetWalkdef(x uint8) { - if x > 3 { - panic(fmt.Sprintf("cannot SetWalkdef %d", x)) - } - n.bits.set2(miniWalkdefShift, x) -} func (n *Name) Linksym() *obj.LSym { return n.sym.Linksym() } func (n *Name) LinksymABI(abi obj.ABI) *obj.LSym { return n.sym.LinksymABI(abi) } diff --git a/src/cmd/compile/internal/noder/expr.go b/src/cmd/compile/internal/noder/expr.go index 4b5ae706c18..566abda963e 100644 --- a/src/cmd/compile/internal/noder/expr.go +++ b/src/cmd/compile/internal/noder/expr.go @@ -439,7 +439,6 @@ func (g *irgen) funcLit(typ2 types2.Type, expr *syntax.FuncLit) ir.Node { for _, cv := range fn.ClosureVars { cv.SetType(cv.Canonical().Type()) cv.SetTypecheck(1) - cv.SetWalkdef(1) } if g.topFuncIsGeneric { diff --git a/src/cmd/compile/internal/noder/object.go b/src/cmd/compile/internal/noder/object.go index 37a995b5199..e8dbaac1613 100644 --- a/src/cmd/compile/internal/noder/object.go +++ b/src/cmd/compile/internal/noder/object.go @@ -171,7 +171,6 @@ func (g *irgen) objFinish(name *ir.Name, class ir.Class, typ *types.Type) { } name.SetTypecheck(1) - name.SetWalkdef(1) if ir.IsBlank(name) { return diff --git a/src/cmd/compile/internal/noder/reader.go b/src/cmd/compile/internal/noder/reader.go index dd3bb1523e1..62875ba0730 100644 --- a/src/cmd/compile/internal/noder/reader.go +++ b/src/cmd/compile/internal/noder/reader.go @@ -155,7 +155,6 @@ func setType(n ir.Node, typ *types.Type) { n.SetTypecheck(1) if name, ok := n.(*ir.Name); ok { - name.SetWalkdef(1) name.Ntype = ir.TypeNode(name.Type()) } } diff --git a/src/cmd/compile/internal/typecheck/func.go b/src/cmd/compile/internal/typecheck/func.go index 5c1a2341b63..7ab41e63fea 100644 --- a/src/cmd/compile/internal/typecheck/func.go +++ b/src/cmd/compile/internal/typecheck/func.go @@ -295,7 +295,13 @@ func tcFunc(n *ir.Func) { defer tracePrint("tcFunc", n)(nil) } - n.Nname = AssignExpr(n.Nname).(*ir.Name) + if name := n.Nname; name.Typecheck() == 0 { + if name.Ntype != nil { + name.Ntype = typecheckNtype(name.Ntype) + name.SetType(name.Ntype.Type()) + } + name.SetTypecheck(1) + } } // tcCall typechecks an OCALL node. diff --git a/src/cmd/compile/internal/typecheck/stmt.go b/src/cmd/compile/internal/typecheck/stmt.go index b2fba315e75..930d7ce627c 100644 --- a/src/cmd/compile/internal/typecheck/stmt.go +++ b/src/cmd/compile/internal/typecheck/stmt.go @@ -648,7 +648,6 @@ func tcSwitchType(n *ir.SwitchStmt) { } else { // Clause variable is broken; prevent typechecking. nvar.SetTypecheck(1) - nvar.SetWalkdef(1) } ncase.Var = nvar } diff --git a/src/cmd/compile/internal/typecheck/typecheck.go b/src/cmd/compile/internal/typecheck/typecheck.go index 9c084934c3b..d94a262a7f8 100644 --- a/src/cmd/compile/internal/typecheck/typecheck.go +++ b/src/cmd/compile/internal/typecheck/typecheck.go @@ -127,8 +127,6 @@ const ( // marks variables that escape the local frame. // rewrites n.Op to be more specific in some cases. -var typecheckdefstack []*ir.Name - // Resolve resolves an ONONAME node to a definition, if any. If n is not an ONONAME node, // Resolve returns n unchanged. If n is an ONONAME node and not in the same package, // then n.Sym() is resolved using import data. Otherwise, Resolve returns @@ -458,10 +456,6 @@ func indexlit(n ir.Node) ir.Node { // typecheck1 should ONLY be called from typecheck. func typecheck1(n ir.Node, top int) ir.Node { - if n, ok := n.(*ir.Name); ok { - typecheckdef(n) - } - switch n.Op() { default: ir.Dump("typecheck", n) @@ -1686,60 +1680,6 @@ func stringtoruneslit(n *ir.ConvExpr) ir.Node { return Expr(nn) } -func typecheckdef(n *ir.Name) { - if base.EnableTrace && base.Flag.LowerT { - defer tracePrint("typecheckdef", n)(nil) - } - - if n.Walkdef() == 1 { - return - } - - if n.Type() != nil { // builtin - // Mark as Walkdef so that if n.SetType(nil) is called later, we - // won't try walking again. - if got := n.Walkdef(); got != 0 { - base.Fatalf("unexpected walkdef: %v", got) - } - n.SetWalkdef(1) - return - } - - lno := ir.SetPos(n) - if n.Walkdef() == 2 { - base.Fatalf("typecheckdef loop") - } - - n.SetWalkdef(2) - - switch n.Op() { - default: - base.Fatalf("typecheckdef %v", n.Op()) - - case ir.ONAME: - if n.BuiltinOp != 0 { // like OPRINTN - base.Assertf(n.Ntype == nil, "unexpected Ntype: %+v", n) - break - } - - base.Assertf(n.Class == ir.PFUNC, "expected PFUNC: %+v", n) - - if n.Ntype != nil { - n.Ntype = typecheckNtype(n.Ntype) - n.SetType(n.Ntype.Type()) - } - - if n.Type() != nil { - break - } - - base.Fatalf("missing type: %v", n) - } - - base.Pos = lno - n.SetWalkdef(1) -} - func checkmake(t *types.Type, arg string, np *ir.Node) bool { n := *np if !n.Type().IsInteger() && n.Type().Kind() != types.TIDEAL { From 66865363f017a8d4cb0b07d84a3a6117fcf1cd30 Mon Sep 17 00:00:00 2001 From: Cherry Mui Date: Wed, 16 Mar 2022 19:21:49 -0400 Subject: [PATCH 127/276] syscall: call ABI0 exitsyscall on Plan 9/AMD64 CL 376356 changes syscall.Syscall to call ABIInternal entersyscall and exitsyscall. As mentioned in the CL description, it is important to call entersyscall without ABI wrapper, but it is not important to call exitsyscall this way. In fact, it is actually problematic -- on Plan 9, syscall may clobber our fixed G register, and we did not restore it. This CL changes it back to ABI0 exitsyscall, which will restore the G register through the wrapper. Should fix Plan 9/AMD64 build. Change-Id: I1f03d553f03e7b9f36d64686f20f2b2df0a0bf79 Reviewed-on: https://go-review.googlesource.com/c/go/+/393494 Trust: Cherry Mui Run-TryBot: Cherry Mui Reviewed-by: Michael Knyszek --- src/syscall/asm_plan9_amd64.s | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/syscall/asm_plan9_amd64.s b/src/syscall/asm_plan9_amd64.s index f22db3238d2..0641513f376 100644 --- a/src/syscall/asm_plan9_amd64.s +++ b/src/syscall/asm_plan9_amd64.s @@ -38,7 +38,7 @@ TEXT ·Syscall(SB),NOSPLIT,$168-64 MOVQ $128, sysargs1-152(SP) MOVQ $SYS_ERRSTR, BP SYSCALL - CALL runtime·exitsyscall(SB) + CALL runtime·exitsyscall(SB) // call via ABI wrapper, ensuring ABIInternal fixed registers are set MOVQ sysargs-160(SP), AX MOVQ AX, errbuf-168(SP) CALL runtime·gostring(SB) @@ -46,7 +46,7 @@ TEXT ·Syscall(SB),NOSPLIT,$168-64 JMP copyresult3 ok3: - CALL runtime·exitsyscall(SB) + CALL runtime·exitsyscall(SB) // call via ABI wrapper, ensuring ABIInternal fixed registers are set LEAQ ·emptystring(SB), SI copyresult3: @@ -83,7 +83,7 @@ TEXT ·Syscall6(SB),NOSPLIT,$168-88 MOVQ $128, sysargs1-152(SP) MOVQ $SYS_ERRSTR, BP SYSCALL - CALL runtime·exitsyscall(SB) + CALL runtime·exitsyscall(SB) // call via ABI wrapper, ensuring ABIInternal fixed registers are set MOVQ sysargs-160(SP), AX MOVQ AX, errbuf-168(SP) CALL runtime·gostring(SB) @@ -91,7 +91,7 @@ TEXT ·Syscall6(SB),NOSPLIT,$168-88 JMP copyresult4 ok4: - CALL runtime·exitsyscall(SB) + CALL runtime·exitsyscall(SB) // call via ABI wrapper, ensuring ABIInternal fixed registers are set LEAQ ·emptystring(SB), SI copyresult4: From f839aaa22b66bc556fac72f7396082212d2ef45d Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Wed, 16 Mar 2022 14:25:50 -0700 Subject: [PATCH 128/276] syscall: allow EINVAL in TestSCMCredentials This can occur on NixOS. Change-Id: I0571b0cc5345d01396dca6a4116aa1024c390a5a Reviewed-on: https://go-review.googlesource.com/c/go/+/393437 Trust: Josh Bleecher Snyder Run-TryBot: Josh Bleecher Snyder TryBot-Result: Gopher Robot Reviewed-by: Ian Lance Taylor --- src/syscall/creds_test.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/syscall/creds_test.go b/src/syscall/creds_test.go index 1ee56fc3401..2fc61df1c50 100644 --- a/src/syscall/creds_test.go +++ b/src/syscall/creds_test.go @@ -77,8 +77,10 @@ func TestSCMCredentials(t *testing.T) { if sys, ok := err.(*os.SyscallError); ok { err = sys.Err } - if err != syscall.EPERM { - t.Fatalf("WriteMsgUnix failed with %v, want EPERM", err) + switch err { + case syscall.EPERM, syscall.EINVAL: + default: + t.Fatalf("WriteMsgUnix failed with %v, want EPERM or EINVAL", err) } } From 8427429c592588af8c49522c76b3e0e0e335d270 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Mon, 14 Mar 2022 11:27:46 -0400 Subject: [PATCH 129/276] os: raise open file rlimit at startup Some systems set an artificially low soft limit on open file count, for compatibility with code that uses select and its hard-coded maximum file descriptor (limited by the size of fd_set). Go does not use select, so it should not be subject to these limits. On some systems the limit is 256, which is very easy to run into, even in simple programs like gofmt when they parallelize walking a file tree. After a long discussion on go.dev/issue/46279, we decided the best approach was for Go to raise the limit unconditionally for itself, and then leave old software to set the limit back as needed. Code that really wants Go to leave the limit alone can set the hard limit, which Go of course has no choice but to respect. Take 2, after CL 392415 was rolled back for macOS and OpenBSD failures. The macOS failures should be handled by the new call to sysctl("kern.maxfilesperproc"), and the OpenBSD failures are handled by skipping the test (and filing #51713). Fixes #46279. Change-Id: I45c81b94590b447b483018a05ae980b8f02dc5de Reviewed-on: https://go-review.googlesource.com/c/go/+/393354 Trust: Russ Cox Reviewed-by: Bryan Mills Run-TryBot: Russ Cox TryBot-Result: Gopher Robot --- src/os/rlimit.go | 32 ++++++++++++++++++++++++++++++++ src/os/rlimit_darwin.go | 22 ++++++++++++++++++++++ src/os/rlimit_stub.go | 12 ++++++++++++ src/os/rlimit_test.go | 37 +++++++++++++++++++++++++++++++++++++ 4 files changed, 103 insertions(+) create mode 100644 src/os/rlimit.go create mode 100644 src/os/rlimit_darwin.go create mode 100644 src/os/rlimit_stub.go create mode 100644 src/os/rlimit_test.go diff --git a/src/os/rlimit.go b/src/os/rlimit.go new file mode 100644 index 00000000000..a89414d098b --- /dev/null +++ b/src/os/rlimit.go @@ -0,0 +1,32 @@ +// Copyright 2022 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 os + +import "syscall" + +// Some systems set an artificially low soft limit on open file count, for compatibility +// with code that uses select and its hard-coded maximum file descriptor +// (limited by the size of fd_set). +// +// Go does not use select, so it should not be subject to these limits. +// On some systems the limit is 256, which is very easy to run into, +// even in simple programs like gofmt when they parallelize walking +// a file tree. +// +// After a long discussion on go.dev/issue/46279, we decided the +// best approach was for Go to raise the limit unconditionally for itself, +// and then leave old software to set the limit back as needed. +// Code that really wants Go to leave the limit alone can set the hard limit, +// which Go of course has no choice but to respect. +func init() { + var lim syscall.Rlimit + if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &lim); err == nil && lim.Cur != lim.Max { + lim.Cur = lim.Max + adjustFileLimit(&lim) + syscall.Setrlimit(syscall.RLIMIT_NOFILE, &lim) + } +} diff --git a/src/os/rlimit_darwin.go b/src/os/rlimit_darwin.go new file mode 100644 index 00000000000..b28982a83a1 --- /dev/null +++ b/src/os/rlimit_darwin.go @@ -0,0 +1,22 @@ +// Copyright 2022 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 darwin + +package os + +import "syscall" + +// adjustFileLimit adds per-OS limitations on the Rlimit used for RLIMIT_NOFILE. See rlimit.go. +func adjustFileLimit(lim *syscall.Rlimit) { + // On older macOS, setrlimit(RLIMIT_NOFILE, lim) with lim.Cur = infinity fails. + // Set to the value of kern.maxfilesperproc instead. + n, err := syscall.SysctlUint32("kern.maxfilesperproc") + if err != nil { + return + } + if lim.Cur > uint64(n) { + lim.Cur = uint64(n) + } +} diff --git a/src/os/rlimit_stub.go b/src/os/rlimit_stub.go new file mode 100644 index 00000000000..cbe28400c5b --- /dev/null +++ b/src/os/rlimit_stub.go @@ -0,0 +1,12 @@ +// Copyright 2022 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 || dragonfly || freebsd || linux || netbsd || openbsd || solaris + +package os + +import "syscall" + +// adjustFileLimit adds per-OS limitations on the Rlimit used for RLIMIT_NOFILE. See rlimit.go. +func adjustFileLimit(lim *syscall.Rlimit) {} diff --git a/src/os/rlimit_test.go b/src/os/rlimit_test.go new file mode 100644 index 00000000000..5859e682ea9 --- /dev/null +++ b/src/os/rlimit_test.go @@ -0,0 +1,37 @@ +// Copyright 2022 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 os_test + +import ( + . "os" + "runtime" + "testing" +) + +func TestOpenFileLimit(t *testing.T) { + if runtime.GOOS == "openbsd" && (runtime.GOARCH == "arm" || runtime.GOARCH == "arm64") { + t.Skip("broken on openbsd/arm and openbsd/arm64 builder - go.dev/issue/51713") + } + + // For open file count, + // macOS sets the default soft limit to 256 and no hard limit. + // CentOS and Fedora set the default soft limit to 1024, + // with hard limits of 4096 and 524288, respectively. + // Check that we can open 1200 files, which proves + // that the rlimit is being raised appropriately on those systems. + var files []*File + for i := 0; i < 1200; i++ { + f, err := Open("rlimit.go") + if err != nil { + t.Error(err) + break + } + files = append(files, f) + } + + for _, f := range files { + f.Close() + } +} From 9956a5423e40bab92c572489eae26ba80ed803ab Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Tue, 15 Mar 2022 21:44:37 -0700 Subject: [PATCH 130/276] text/scanner: guard against installed IsIdentRune that accepts EOF IsIdentRune may be installed by a client of the scanner. If the installed function accepts EOF as a valid identifier rune, Scan calls may not terminate. Check for EOF when a user-defined IsIdentRune is used. Fixes #50909. Change-Id: Ib104b03ee59e2d58faa71f227c3b51ba424f7f61 Reviewed-on: https://go-review.googlesource.com/c/go/+/393254 Trust: Robert Griesemer Run-TryBot: Robert Griesemer TryBot-Result: Gopher Robot Reviewed-by: Ian Lance Taylor --- src/text/scanner/scanner.go | 2 +- src/text/scanner/scanner_test.go | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/text/scanner/scanner.go b/src/text/scanner/scanner.go index f1fbf9861d0..735982afcb2 100644 --- a/src/text/scanner/scanner.go +++ b/src/text/scanner/scanner.go @@ -346,7 +346,7 @@ func (s *Scanner) errorf(format string, args ...any) { func (s *Scanner) isIdentRune(ch rune, i int) bool { if s.IsIdentRune != nil { - return s.IsIdentRune(ch, i) + return ch != EOF && s.IsIdentRune(ch, i) } return ch == '_' || unicode.IsLetter(ch) || unicode.IsDigit(ch) && i > 0 } diff --git a/src/text/scanner/scanner_test.go b/src/text/scanner/scanner_test.go index fe39d3060bf..6a454d9be77 100644 --- a/src/text/scanner/scanner_test.go +++ b/src/text/scanner/scanner_test.go @@ -913,3 +913,22 @@ func extractInts(t string, mode uint) (res string) { } } } + +func TestIssue50909(t *testing.T) { + var s Scanner + s.Init(strings.NewReader("hello \n\nworld\n!\n")) + s.IsIdentRune = func(ch rune, _ int) bool { return ch != '\n' } + + r := "" + n := 0 + for s.Scan() != EOF && n < 10 { + r += s.TokenText() + n++ + } + + const R = "hello world!" + const N = 3 + if r != R || n != N { + t.Errorf("got %q (n = %d); want %q (n = %d)", r, n, R, N) + } +} From 599d5395ebb41eb17bbe77e75d12ed0d13294767 Mon Sep 17 00:00:00 2001 From: Fannie Zhang Date: Wed, 16 Mar 2022 12:08:54 +0000 Subject: [PATCH 131/276] Revert "cmd/compile: set conversions to unsafe.Pointer as an escaping operation when -asan is enabled" This reverts commit 5fd0ed7aaf39f783ea6f505a3f2ac7d9da7cb03b. Reason for revert: Change-Id: Id6845a9c8114ac71c56a1007a4d133a560a37fbc Reviewed-on: https://go-review.googlesource.com/c/go/+/393314 Trust: Fannie Zhang Reviewed-by: Eric Fang --- misc/cgo/testsanitizers/asan_test.go | 3 -- .../testdata/asan_unsafe_fail1.go | 27 ------------------ .../testdata/asan_unsafe_fail2.go | 28 ------------------- .../testdata/asan_unsafe_fail3.go | 21 -------------- src/cmd/compile/internal/escape/expr.go | 6 ++-- src/cmd/compile/internal/ir/expr.go | 6 ---- 6 files changed, 3 insertions(+), 88 deletions(-) delete mode 100644 misc/cgo/testsanitizers/testdata/asan_unsafe_fail1.go delete mode 100644 misc/cgo/testsanitizers/testdata/asan_unsafe_fail2.go delete mode 100644 misc/cgo/testsanitizers/testdata/asan_unsafe_fail3.go diff --git a/misc/cgo/testsanitizers/asan_test.go b/misc/cgo/testsanitizers/asan_test.go index ff578ac63e1..22dcf23c3ba 100644 --- a/misc/cgo/testsanitizers/asan_test.go +++ b/misc/cgo/testsanitizers/asan_test.go @@ -41,9 +41,6 @@ func TestASAN(t *testing.T) { {src: "asan4_fail.go", memoryAccessError: "use-after-poison", errorLocation: "asan4_fail.go:13"}, {src: "asan5_fail.go", memoryAccessError: "use-after-poison", errorLocation: "asan5_fail.go:18"}, {src: "asan_useAfterReturn.go"}, - {src: "asan_unsafe_fail1.go", memoryAccessError: "use-after-poison", errorLocation: "asan_unsafe_fail1.go:25"}, - {src: "asan_unsafe_fail2.go", memoryAccessError: "use-after-poison", errorLocation: "asan_unsafe_fail2.go:25"}, - {src: "asan_unsafe_fail3.go", memoryAccessError: "use-after-poison", errorLocation: "asan_unsafe_fail3.go:18"}, } for _, tc := range cases { tc := tc diff --git a/misc/cgo/testsanitizers/testdata/asan_unsafe_fail1.go b/misc/cgo/testsanitizers/testdata/asan_unsafe_fail1.go deleted file mode 100644 index e66387c5a45..00000000000 --- a/misc/cgo/testsanitizers/testdata/asan_unsafe_fail1.go +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2022 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 main - -import ( - "fmt" - "unsafe" -) - -func main() { - a := 1 - b := 2 - c := add(a, b) - d := a + b - fmt.Println(c, d) -} - -//go:noinline -func add(a1, b1 int) int { - // The arguments. - // When -asan is enabled, unsafe.Pointer(&a1) conversion is escaping. - var p *int = (*int)(unsafe.Pointer(uintptr(unsafe.Pointer(&a1)) + 1*unsafe.Sizeof(int(1)))) - *p = 10 // BOOM - return a1 + b1 -} diff --git a/misc/cgo/testsanitizers/testdata/asan_unsafe_fail2.go b/misc/cgo/testsanitizers/testdata/asan_unsafe_fail2.go deleted file mode 100644 index 4f25aac1bdd..00000000000 --- a/misc/cgo/testsanitizers/testdata/asan_unsafe_fail2.go +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2022 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 main - -import ( - "fmt" - "unsafe" -) - -func main() { - a := 1 - b := 2 - c := add(a, b) - d := a + b - fmt.Println(c, d) -} - -//go:noinline -func add(a1, b1 int) (ret int) { - // The return value - // When -asan is enabled, the unsafe.Pointer(&ret) conversion is escaping. - var p *int = (*int)(unsafe.Pointer(uintptr(unsafe.Pointer(&ret)) + 1*unsafe.Sizeof(int(1)))) - *p = 123 // BOOM - ret = a1 + b1 - return -} diff --git a/misc/cgo/testsanitizers/testdata/asan_unsafe_fail3.go b/misc/cgo/testsanitizers/testdata/asan_unsafe_fail3.go deleted file mode 100644 index a05044fc664..00000000000 --- a/misc/cgo/testsanitizers/testdata/asan_unsafe_fail3.go +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2022 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 main - -import ( - "fmt" - "unsafe" -) - -func main() { - a := 1 - b := 2 - // The local variables. - // When -asan is enabled, the unsafe.Pointer(&a) conversion is escaping. - var p *int = (*int)(unsafe.Pointer(uintptr(unsafe.Pointer(&a)) + 1*unsafe.Sizeof(int(1)))) - *p = 20 // BOOM - d := a + b - fmt.Println(d) -} diff --git a/src/cmd/compile/internal/escape/expr.go b/src/cmd/compile/internal/escape/expr.go index 9c3e09d10da..ced90a47bcb 100644 --- a/src/cmd/compile/internal/escape/expr.go +++ b/src/cmd/compile/internal/escape/expr.go @@ -100,9 +100,9 @@ func (e *escape) exprSkipInit(k hole, n ir.Node) { case ir.OCONV, ir.OCONVNOP: n := n.(*ir.ConvExpr) - if (ir.ShouldCheckPtr(e.curfn, 2) || ir.ShouldAsanCheckPtr(e.curfn)) && n.Type().IsUnsafePtr() && n.X.Type().IsPtr() { - // When -d=checkptr=2 or -asan is enabled, - // treat conversions to unsafe.Pointer as an + if ir.ShouldCheckPtr(e.curfn, 2) && n.Type().IsUnsafePtr() && n.X.Type().IsPtr() { + // When -d=checkptr=2 is enabled, treat + // conversions to unsafe.Pointer as an // escaping operation. This allows better // runtime instrumentation, since we can more // easily detect object boundaries on the heap diff --git a/src/cmd/compile/internal/ir/expr.go b/src/cmd/compile/internal/ir/expr.go index ff3cc8ed6e7..8823115612c 100644 --- a/src/cmd/compile/internal/ir/expr.go +++ b/src/cmd/compile/internal/ir/expr.go @@ -1036,12 +1036,6 @@ func ShouldCheckPtr(fn *Func, level int) bool { return base.Debug.Checkptr >= level && fn.Pragma&NoCheckPtr == 0 } -// ShouldAsanCheckPtr reports whether pointer checking should be enabled for -// function fn when -asan is enabled. -func ShouldAsanCheckPtr(fn *Func) bool { - return base.Flag.ASan && fn.Pragma&NoCheckPtr == 0 -} - // IsReflectHeaderDataField reports whether l is an expression p.Data // where p has type reflect.SliceHeader or reflect.StringHeader. func IsReflectHeaderDataField(l Node) bool { From c379c3d58d5482f4c8fe97466a99ce70e630ad44 Mon Sep 17 00:00:00 2001 From: fanzha02 Date: Mon, 7 Jun 2021 14:24:45 +0800 Subject: [PATCH 132/276] cmd/compile: set conversions to unsafe.Pointer as an escaping operation when -asan is enabled When ASan is enabled, treat conversions to unsafe.Pointer as an escaping operation. In this way, all pointer operations on the stack objects will become operations on the escaped heap objects. As we've already supported ASan detection of error memory accesses to heap objects. With this trick, we can use -asan option to report errors on bad stack operations. Add test cases. Updates #44853. Change-Id: I6281e77f6ba581d7008d610f0b24316078b6e746 Reviewed-on: https://go-review.googlesource.com/c/go/+/393315 Trust: Fannie Zhang Run-TryBot: Fannie Zhang TryBot-Result: Gopher Robot Reviewed-by: Eric Fang --- misc/cgo/testsanitizers/asan_test.go | 3 ++ .../testdata/asan_unsafe_fail1.go | 27 ++++++++++++++++++ .../testdata/asan_unsafe_fail2.go | 28 +++++++++++++++++++ .../testdata/asan_unsafe_fail3.go | 21 ++++++++++++++ src/cmd/compile/internal/escape/expr.go | 6 ++-- src/cmd/compile/internal/ir/expr.go | 6 ++++ 6 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 misc/cgo/testsanitizers/testdata/asan_unsafe_fail1.go create mode 100644 misc/cgo/testsanitizers/testdata/asan_unsafe_fail2.go create mode 100644 misc/cgo/testsanitizers/testdata/asan_unsafe_fail3.go diff --git a/misc/cgo/testsanitizers/asan_test.go b/misc/cgo/testsanitizers/asan_test.go index 22dcf23c3ba..ff578ac63e1 100644 --- a/misc/cgo/testsanitizers/asan_test.go +++ b/misc/cgo/testsanitizers/asan_test.go @@ -41,6 +41,9 @@ func TestASAN(t *testing.T) { {src: "asan4_fail.go", memoryAccessError: "use-after-poison", errorLocation: "asan4_fail.go:13"}, {src: "asan5_fail.go", memoryAccessError: "use-after-poison", errorLocation: "asan5_fail.go:18"}, {src: "asan_useAfterReturn.go"}, + {src: "asan_unsafe_fail1.go", memoryAccessError: "use-after-poison", errorLocation: "asan_unsafe_fail1.go:25"}, + {src: "asan_unsafe_fail2.go", memoryAccessError: "use-after-poison", errorLocation: "asan_unsafe_fail2.go:25"}, + {src: "asan_unsafe_fail3.go", memoryAccessError: "use-after-poison", errorLocation: "asan_unsafe_fail3.go:18"}, } for _, tc := range cases { tc := tc diff --git a/misc/cgo/testsanitizers/testdata/asan_unsafe_fail1.go b/misc/cgo/testsanitizers/testdata/asan_unsafe_fail1.go new file mode 100644 index 00000000000..ec54a66880c --- /dev/null +++ b/misc/cgo/testsanitizers/testdata/asan_unsafe_fail1.go @@ -0,0 +1,27 @@ +// Copyright 2022 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 main + +import ( + "fmt" + "unsafe" +) + +func main() { + a := 1 + b := 2 + c := add(a, b) + d := a + b + fmt.Println(c, d) +} + +//go:noinline +func add(a1, b1 int) int { + // The arguments. + // When -asan is enabled, unsafe.Pointer(&a1) conversion is escaping. + var p *int = (*int)(unsafe.Add(unsafe.Pointer(&a1), 1*unsafe.Sizeof(int(1)))) + *p = 10 // BOOM + return a1 + b1 +} diff --git a/misc/cgo/testsanitizers/testdata/asan_unsafe_fail2.go b/misc/cgo/testsanitizers/testdata/asan_unsafe_fail2.go new file mode 100644 index 00000000000..70f21275af5 --- /dev/null +++ b/misc/cgo/testsanitizers/testdata/asan_unsafe_fail2.go @@ -0,0 +1,28 @@ +// Copyright 2022 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 main + +import ( + "fmt" + "unsafe" +) + +func main() { + a := 1 + b := 2 + c := add(a, b) + d := a + b + fmt.Println(c, d) +} + +//go:noinline +func add(a1, b1 int) (ret int) { + // The return value + // When -asan is enabled, the unsafe.Pointer(&ret) conversion is escaping. + var p *int = (*int)(unsafe.Add(unsafe.Pointer(&ret), 1*unsafe.Sizeof(int(1)))) + *p = 123 // BOOM + ret = a1 + b1 + return +} diff --git a/misc/cgo/testsanitizers/testdata/asan_unsafe_fail3.go b/misc/cgo/testsanitizers/testdata/asan_unsafe_fail3.go new file mode 100644 index 00000000000..47a8a072ef4 --- /dev/null +++ b/misc/cgo/testsanitizers/testdata/asan_unsafe_fail3.go @@ -0,0 +1,21 @@ +// Copyright 2022 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 main + +import ( + "fmt" + "unsafe" +) + +func main() { + a := 1 + b := 2 + // The local variables. + // When -asan is enabled, the unsafe.Pointer(&a) conversion is escaping. + var p *int = (*int)(unsafe.Add(unsafe.Pointer(&a), 1*unsafe.Sizeof(int(1)))) + *p = 20 // BOOM + d := a + b + fmt.Println(d) +} diff --git a/src/cmd/compile/internal/escape/expr.go b/src/cmd/compile/internal/escape/expr.go index ced90a47bcb..9c3e09d10da 100644 --- a/src/cmd/compile/internal/escape/expr.go +++ b/src/cmd/compile/internal/escape/expr.go @@ -100,9 +100,9 @@ func (e *escape) exprSkipInit(k hole, n ir.Node) { case ir.OCONV, ir.OCONVNOP: n := n.(*ir.ConvExpr) - if ir.ShouldCheckPtr(e.curfn, 2) && n.Type().IsUnsafePtr() && n.X.Type().IsPtr() { - // When -d=checkptr=2 is enabled, treat - // conversions to unsafe.Pointer as an + if (ir.ShouldCheckPtr(e.curfn, 2) || ir.ShouldAsanCheckPtr(e.curfn)) && n.Type().IsUnsafePtr() && n.X.Type().IsPtr() { + // When -d=checkptr=2 or -asan is enabled, + // treat conversions to unsafe.Pointer as an // escaping operation. This allows better // runtime instrumentation, since we can more // easily detect object boundaries on the heap diff --git a/src/cmd/compile/internal/ir/expr.go b/src/cmd/compile/internal/ir/expr.go index 8823115612c..ff3cc8ed6e7 100644 --- a/src/cmd/compile/internal/ir/expr.go +++ b/src/cmd/compile/internal/ir/expr.go @@ -1036,6 +1036,12 @@ func ShouldCheckPtr(fn *Func, level int) bool { return base.Debug.Checkptr >= level && fn.Pragma&NoCheckPtr == 0 } +// ShouldAsanCheckPtr reports whether pointer checking should be enabled for +// function fn when -asan is enabled. +func ShouldAsanCheckPtr(fn *Func) bool { + return base.Flag.ASan && fn.Pragma&NoCheckPtr == 0 +} + // IsReflectHeaderDataField reports whether l is an expression p.Data // where p has type reflect.SliceHeader or reflect.StringHeader. func IsReflectHeaderDataField(l Node) bool { From 0fca8a8f25cf4636fd980e72ba0bded4230922de Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Thu, 17 Mar 2022 09:39:46 -0700 Subject: [PATCH 133/276] crypto/x509: fix Certificate.Verify crash (Primarily from Josh) Fixes #51759 Co-authored-by: Josh Bleecher Snyder Change-Id: I0a6f2623b57750abd13d5e194b5c6ffa3be6bf72 Reviewed-on: https://go-review.googlesource.com/c/go/+/393655 Trust: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick Reviewed-by: Roland Shoemaker TryBot-Result: Gopher Robot --- src/crypto/x509/root_darwin.go | 7 ++++++- src/crypto/x509/verify_test.go | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/crypto/x509/root_darwin.go b/src/crypto/x509/root_darwin.go index 1ef9c0f71e5..ad365f577e7 100644 --- a/src/crypto/x509/root_darwin.go +++ b/src/crypto/x509/root_darwin.go @@ -13,6 +13,9 @@ func (c *Certificate) systemVerify(opts *VerifyOptions) (chains [][]*Certificate certs := macOS.CFArrayCreateMutable() defer macOS.ReleaseCFArray(certs) leaf := macOS.SecCertificateCreateWithData(c.Raw) + if leaf == 0 { + return nil, errors.New("invalid leaf certificate") + } macOS.CFArrayAppendValue(certs, leaf) if opts.Intermediates != nil { for _, lc := range opts.Intermediates.lazyCerts { @@ -21,7 +24,9 @@ func (c *Certificate) systemVerify(opts *VerifyOptions) (chains [][]*Certificate return nil, err } sc := macOS.SecCertificateCreateWithData(c.Raw) - macOS.CFArrayAppendValue(certs, sc) + if sc != 0 { + macOS.CFArrayAppendValue(certs, sc) + } } } diff --git a/src/crypto/x509/verify_test.go b/src/crypto/x509/verify_test.go index f4ea08bbf55..100a8ff0f94 100644 --- a/src/crypto/x509/verify_test.go +++ b/src/crypto/x509/verify_test.go @@ -1876,3 +1876,37 @@ func TestSystemRootsErrorUnwrap(t *testing.T) { t.Error("errors.Is failed, wanted success") } } + +func TestIssue51759(t *testing.T) { + // badCertData contains a cert that we parse as valid + // but that macOS SecCertificateCreateWithData rejects. + const badCertData = "0\x82\x01U0\x82\x01\a\xa0\x03\x02\x01\x02\x02\x01\x020\x05\x06\x03+ep0R1P0N\x06\x03U\x04\x03\x13Gderpkey8dc58100b2493614ee1692831a461f3f4dd3f9b3b088e244f887f81b4906ac260\x1e\x17\r220112235755Z\x17\r220313235755Z0R1P0N\x06\x03U\x04\x03\x13Gderpkey8dc58100b2493614ee1692831a461f3f4dd3f9b3b088e244f887f81b4906ac260*0\x05\x06\x03+ep\x03!\x00bA\xd8e\xadW\xcb\xefZ\x89\xb5\"\x1eR\x9d\xba\x0e:\x1042Q@\u007f\xbd\xfb{ks\x04\xd1£\x020\x000\x05\x06\x03+ep\x03A\x00[\xa7\x06y\x86(\x94\x97\x9eLwA\x00\x01x\xaa\xbc\xbd Ê]\n(΅!ف0\xf5\x9a%I\x19<\xffo\xf1\xeaaf@\xb1\xa7\xaf\xfd\xe9R\xc7\x0f\x8d&\xd5\xfc\x0f;Ϙ\x82\x84a\xbc\r" + badCert, err := ParseCertificate([]byte(badCertData)) + if err != nil { + t.Fatal(err) + } + + t.Run("leaf", func(t *testing.T) { + opts := VerifyOptions{} + _, err = badCert.Verify(opts) + if err == nil { + t.Fatal("expected error") + } + }) + + goodCert, err := certificateFromPEM(googleLeaf) + if err != nil { + t.Fatal(err) + } + + t.Run("intermediate", func(t *testing.T) { + opts := VerifyOptions{ + Intermediates: NewCertPool(), + } + opts.Intermediates.AddCert(badCert) + _, err = goodCert.Verify(opts) + if err == nil { + t.Fatal("expected error") + } + }) +} From c6244b59095a74b77c977d250708ba1858ae2388 Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Thu, 10 Mar 2022 23:57:57 -0500 Subject: [PATCH 134/276] runtime/debug: do not require a GOROOT/src prefix in TestStack When paths are trimmed, the reported file locations begin with the package import path (not GOROOT/src). Updates #51461. Change-Id: Ia6814f970aee11f3d933e75c75136d679d19e220 Reviewed-on: https://go-review.googlesource.com/c/go/+/391815 Trust: Bryan Mills Run-TryBot: Bryan Mills Reviewed-by: Cherry Mui TryBot-Result: Gopher Robot --- src/runtime/debug/stack_test.go | 82 +++++++++++++++++++++++++++------ 1 file changed, 69 insertions(+), 13 deletions(-) diff --git a/src/runtime/debug/stack_test.go b/src/runtime/debug/stack_test.go index 4cab8864df4..671057c3a0d 100644 --- a/src/runtime/debug/stack_test.go +++ b/src/runtime/debug/stack_test.go @@ -5,11 +5,26 @@ package debug_test import ( + "bytes" + "fmt" + "internal/testenv" + "os" + "os/exec" + "path/filepath" + "runtime" . "runtime/debug" "strings" "testing" ) +func TestMain(m *testing.M) { + if os.Getenv("GO_RUNTIME_DEBUG_TEST_DUMP_GOROOT") != "" { + fmt.Println(runtime.GOROOT()) + os.Exit(0) + } + os.Exit(m.Run()) +} + type T int func (t *T) ptrmethod() []byte { @@ -43,23 +58,64 @@ func TestStack(t *testing.T) { if len(lines) < 6 { t.Fatal("too few lines") } + + // If built with -trimpath, file locations should start with package paths. + // Otherwise, file locations should start with a GOROOT/src prefix + // (for whatever value of GOROOT is baked into the binary, not the one + // that may be set in the environment). + fileGoroot := "" + if envGoroot := os.Getenv("GOROOT"); envGoroot != "" { + // Since GOROOT is set explicitly in the environment, we can't be certain + // that it is the same GOROOT value baked into the binary, and we can't + // change the value in-process because runtime.GOROOT uses the value from + // initial (not current) environment. Spawn a subprocess to determine the + // real baked-in GOROOT. + t.Logf("found GOROOT %q from environment; checking embedded GOROOT value", envGoroot) + testenv.MustHaveExec(t) + exe, err := os.Executable() + if err != nil { + t.Fatal(err) + } + cmd := exec.Command(exe) + cmd.Env = append(os.Environ(), "GOROOT=", "GO_RUNTIME_DEBUG_TEST_DUMP_GOROOT=1") + out, err := cmd.Output() + if err != nil { + t.Fatal(err) + } + fileGoroot = string(bytes.TrimSpace(out)) + } else { + // Since GOROOT is not set in the environment, its value (if any) must come + // from the path embedded in the binary. + fileGoroot = runtime.GOROOT() + } + filePrefix := "" + if fileGoroot != "" { + filePrefix = filepath.ToSlash(fileGoroot) + "/src/" + } + n := 0 - frame := func(line, code string) { - check(t, lines[n], code) + frame := func(file, code string) { + t.Helper() + + line := lines[n] + if !strings.Contains(line, code) { + t.Errorf("expected %q in %q", code, line) + } n++ - check(t, lines[n], line) + + line = lines[n] + + wantPrefix := "\t" + filePrefix + file + if !strings.HasPrefix(line, wantPrefix) { + t.Errorf("in line %q, expected prefix %q", line, wantPrefix) + } n++ } n++ - frame("src/runtime/debug/stack.go", "runtime/debug.Stack") - frame("src/runtime/debug/stack_test.go", "runtime/debug_test.(*T).ptrmethod") - frame("src/runtime/debug/stack_test.go", "runtime/debug_test.T.method") - frame("src/runtime/debug/stack_test.go", "runtime/debug_test.TestStack") - frame("src/testing/testing.go", "") -} -func check(t *testing.T, line, has string) { - if !strings.Contains(line, has) { - t.Errorf("expected %q in %q", has, line) - } + frame("runtime/debug/stack.go", "runtime/debug.Stack") + frame("runtime/debug/stack_test.go", "runtime/debug_test.(*T).ptrmethod") + frame("runtime/debug/stack_test.go", "runtime/debug_test.T.method") + frame("runtime/debug/stack_test.go", "runtime/debug_test.TestStack") + frame("testing/testing.go", "") } From 2b0ac284cf4b81badb1c29e4fa299ea25cb9318f Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Thu, 10 Mar 2022 14:58:02 -0500 Subject: [PATCH 135/276] cmd/doc: use 'go env' to identify GOROOT if it isn't otherwise known Updates #51483. Change-Id: I13d8e58b30639d8a5ed3c9e8b72c8bbaa6a6f1cc Reviewed-on: https://go-review.googlesource.com/c/go/+/391813 Trust: Bryan Mills Run-TryBot: Bryan Mills Reviewed-by: Ian Lance Taylor TryBot-Result: Gopher Robot --- src/cmd/doc/dirs.go | 17 +++++++++++++++-- src/cmd/doc/pkg.go | 8 +++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/cmd/doc/dirs.go b/src/cmd/doc/dirs.go index f27af1d27be..cb4d45ac6ce 100644 --- a/src/cmd/doc/dirs.go +++ b/src/cmd/doc/dirs.go @@ -41,6 +41,17 @@ var dirs Dirs // dirsInit starts the scanning of package directories in GOROOT and GOPATH. Any // extra paths passed to it are included in the channel. func dirsInit(extra ...Dir) { + if buildCtx.GOROOT == "" { + stdout, err := exec.Command("go", "env", "GOROOT").Output() + if err != nil { + if ee, ok := err.(*exec.ExitError); ok && len(ee.Stderr) > 0 { + log.Fatalf("failed to determine GOROOT: $GOROOT is not set and 'go env GOROOT' failed:\n%s", ee.Stderr) + } + log.Fatalf("failed to determine GOROOT: $GOROOT is not set and could not run 'go env GOROOT':\n\t%s", err) + } + buildCtx.GOROOT = string(bytes.TrimSpace(stdout)) + } + dirs.hist = make([]Dir, 0, 1000) dirs.hist = append(dirs.hist, extra...) dirs.scan = make(chan Dir) @@ -174,7 +185,7 @@ func findCodeRoots() []Dir { gomod := string(bytes.TrimSpace(stdout)) usingModules = len(gomod) > 0 - if usingModules { + if usingModules && buildCtx.GOROOT != "" { list = append(list, Dir{dir: filepath.Join(buildCtx.GOROOT, "src"), inModule: true}, Dir{importPath: "cmd", dir: filepath.Join(buildCtx.GOROOT, "src", "cmd"), inModule: true}) @@ -190,7 +201,9 @@ func findCodeRoots() []Dir { } if !usingModules { - list = append(list, Dir{dir: filepath.Join(buildCtx.GOROOT, "src")}) + if buildCtx.GOROOT != "" { + list = append(list, Dir{dir: filepath.Join(buildCtx.GOROOT, "src")}) + } for _, root := range splitGopath() { list = append(list, Dir{dir: filepath.Join(root, "src")}) } diff --git a/src/cmd/doc/pkg.go b/src/cmd/doc/pkg.go index 02666007300..49b68873b6f 100644 --- a/src/cmd/doc/pkg.go +++ b/src/cmd/doc/pkg.go @@ -89,9 +89,11 @@ func (pkg *Package) prettyPath() string { // Also convert everything to slash-separated paths for uniform handling. path = filepath.Clean(filepath.ToSlash(pkg.build.Dir)) // Can we find a decent prefix? - goroot := filepath.Join(buildCtx.GOROOT, "src") - if p, ok := trim(path, filepath.ToSlash(goroot)); ok { - return p + if buildCtx.GOROOT != "" { + goroot := filepath.Join(buildCtx.GOROOT, "src") + if p, ok := trim(path, filepath.ToSlash(goroot)); ok { + return p + } } for _, gopath := range splitGopath() { if p, ok := trim(path, filepath.ToSlash(gopath)); ok { From 3046ae927d7664a63bb8c3a2fb3b9ca95bcf93de Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Wed, 16 Mar 2022 14:45:42 -0400 Subject: [PATCH 136/276] cmd/doc: use the 'go' command from buildCtx.GOROOT, not whatever is in $PATH For #51483. Change-Id: I6150fdf97763d858e9ab012e807515da3387c25f Reviewed-on: https://go-review.googlesource.com/c/go/+/393366 Trust: Bryan Mills Run-TryBot: Bryan Mills Reviewed-by: Ian Lance Taylor TryBot-Result: Gopher Robot --- src/cmd/doc/dirs.go | 16 ++++++++--- src/cmd/go/testdata/script/mod_doc_path.txt | 30 +++++++++++++++++++++ 2 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 src/cmd/go/testdata/script/mod_doc_path.txt diff --git a/src/cmd/doc/dirs.go b/src/cmd/doc/dirs.go index cb4d45ac6ce..489f4908899 100644 --- a/src/cmd/doc/dirs.go +++ b/src/cmd/doc/dirs.go @@ -58,6 +58,14 @@ func dirsInit(extra ...Dir) { go dirs.walk(codeRoots()) } +// goCmd returns the "go" command path corresponding to buildCtx.GOROOT. +func goCmd() string { + if buildCtx.GOROOT == "" { + return "go" + } + return filepath.Join(buildCtx.GOROOT, "bin", "go") +} + // Reset puts the scan back at the beginning. func (d *Dirs) Reset() { d.offset = 0 @@ -181,7 +189,7 @@ func findCodeRoots() []Dir { if !testGOPATH { // Check for use of modules by 'go env GOMOD', // which reports a go.mod file path if modules are enabled. - stdout, _ := exec.Command("go", "env", "GOMOD").Output() + stdout, _ := exec.Command(goCmd(), "env", "GOMOD").Output() gomod := string(bytes.TrimSpace(stdout)) usingModules = len(gomod) > 0 @@ -230,7 +238,7 @@ func findCodeRoots() []Dir { return list } - cmd := exec.Command("go", "list", "-m", "-f={{.Path}}\t{{.Dir}}", "all") + cmd := exec.Command(goCmd(), "list", "-m", "-f={{.Path}}\t{{.Dir}}", "all") cmd.Stderr = os.Stderr out, _ := cmd.Output() for _, line := range strings.Split(string(out), "\n") { @@ -259,7 +267,7 @@ func vendorEnabled() (*moduleJSON, bool, error) { return nil, false, err } - stdout, _ := exec.Command("go", "env", "GOFLAGS").Output() + stdout, _ := exec.Command(goCmd(), "env", "GOFLAGS").Output() goflags := string(bytes.TrimSpace(stdout)) matches := modFlagRegexp.FindStringSubmatch(goflags) var modFlag string @@ -293,7 +301,7 @@ func getMainModuleAnd114() (*moduleJSON, bool, error) { {{.GoVersion}} {{range context.ReleaseTags}}{{if eq . "go1.14"}}{{.}}{{end}}{{end}} ` - cmd := exec.Command("go", "list", "-m", "-f", format) + cmd := exec.Command(goCmd(), "list", "-m", "-f", format) cmd.Stderr = os.Stderr stdout, err := cmd.Output() if err != nil { diff --git a/src/cmd/go/testdata/script/mod_doc_path.txt b/src/cmd/go/testdata/script/mod_doc_path.txt new file mode 100644 index 00000000000..57470a95c4c --- /dev/null +++ b/src/cmd/go/testdata/script/mod_doc_path.txt @@ -0,0 +1,30 @@ +# cmd/doc should use GOROOT to locate the 'go' command, +# not use whatever is in $PATH. + +# Remove 'go' from $PATH. (It can still be located via $GOROOT/bin/go, and the +# test script's built-in 'go' command still knows where to find it.) +env PATH='' +[plan9] env path='' + +go doc p.X + +-- go.mod -- +module example + +go 1.19 + +require example.com/p v0.1.0 + +replace example.com/p => ./pfork +-- example.go -- +package example + +import _ "example.com/p" +-- pfork/go.mod -- +module example.com/p + +go 1.19 +-- pfork/p.go -- +package p + +const X = 42 From 79861be2059e014ca0647de3be22e7c341e61e20 Mon Sep 17 00:00:00 2001 From: Heschi Kreinick Date: Wed, 16 Mar 2022 18:04:43 -0400 Subject: [PATCH 137/276] all: update vendored x dependencies for Go 1.19 development cycle Generated with x/build/cmd/updatestd. Updates #36905. Change-Id: I5d12dfc3b49c1476ce4b8d4cbeb35bd3d3443d26 Reviewed-on: https://go-review.googlesource.com/c/go/+/393369 Trust: Heschi Kreinick Run-TryBot: Heschi Kreinick Auto-Submit: Heschi Kreinick Reviewed-by: Dmitri Shuralyov TryBot-Result: Gopher Robot --- src/cmd/go.mod | 8 +- src/cmd/go.sum | 12 +- .../golang.org/x/crypto/ed25519/ed25519.go | 188 +- .../x/crypto/ed25519/ed25519_go113.go | 74 - .../ed25519/internal/edwards25519/const.go | 1422 ------------- .../internal/edwards25519/edwards25519.go | 1793 ----------------- .../golang.org/x/sys/plan9/syscall_plan9.go | 6 +- .../golang.org/x/sys/unix/ioctl_linux.go | 23 + .../vendor/golang.org/x/sys/unix/mkerrors.sh | 6 + .../golang.org/x/sys/unix/syscall_aix.go | 22 +- .../golang.org/x/sys/unix/syscall_bsd.go | 24 +- .../golang.org/x/sys/unix/syscall_darwin.go | 10 +- .../x/sys/unix/syscall_dragonfly.go | 14 +- .../golang.org/x/sys/unix/syscall_freebsd.go | 10 +- .../golang.org/x/sys/unix/syscall_linux.go | 87 +- .../x/sys/unix/syscall_linux_386.go | 12 +- .../x/sys/unix/syscall_linux_alarm.go | 14 + .../x/sys/unix/syscall_linux_amd64.go | 5 +- .../x/sys/unix/syscall_linux_arm.go | 5 +- .../x/sys/unix/syscall_linux_arm64.go | 5 +- .../x/sys/unix/syscall_linux_mips64x.go | 5 +- .../x/sys/unix/syscall_linux_mipsx.go | 5 +- .../x/sys/unix/syscall_linux_ppc.go | 5 +- .../x/sys/unix/syscall_linux_ppc64x.go | 5 +- .../x/sys/unix/syscall_linux_riscv64.go | 5 +- .../x/sys/unix/syscall_linux_s390x.go | 13 +- .../x/sys/unix/syscall_linux_sparc64.go | 5 +- .../golang.org/x/sys/unix/syscall_netbsd.go | 18 +- .../golang.org/x/sys/unix/syscall_openbsd.go | 10 +- .../golang.org/x/sys/unix/syscall_solaris.go | 40 +- .../golang.org/x/sys/unix/syscall_unix.go | 51 + .../x/sys/unix/syscall_zos_s390x.go | 6 +- .../golang.org/x/sys/unix/zerrors_linux.go | 53 +- .../x/sys/unix/zerrors_linux_386.go | 3 + .../x/sys/unix/zerrors_linux_amd64.go | 3 + .../x/sys/unix/zerrors_linux_arm.go | 3 + .../x/sys/unix/zerrors_linux_arm64.go | 3 + .../x/sys/unix/zerrors_linux_mips.go | 3 + .../x/sys/unix/zerrors_linux_mips64.go | 3 + .../x/sys/unix/zerrors_linux_mips64le.go | 3 + .../x/sys/unix/zerrors_linux_mipsle.go | 3 + .../x/sys/unix/zerrors_linux_ppc.go | 3 + .../x/sys/unix/zerrors_linux_ppc64.go | 3 + .../x/sys/unix/zerrors_linux_ppc64le.go | 3 + .../x/sys/unix/zerrors_linux_riscv64.go | 3 + .../x/sys/unix/zerrors_linux_s390x.go | 3 + .../x/sys/unix/zerrors_linux_sparc64.go | 3 + .../golang.org/x/sys/unix/zsyscall_aix_ppc.go | 4 +- .../x/sys/unix/zsyscall_aix_ppc64.go | 4 +- .../x/sys/unix/zsyscall_darwin_amd64.go | 4 +- .../x/sys/unix/zsyscall_darwin_arm64.go | 4 +- .../x/sys/unix/zsyscall_freebsd_386.go | 4 +- .../x/sys/unix/zsyscall_freebsd_amd64.go | 4 +- .../x/sys/unix/zsyscall_freebsd_arm.go | 4 +- .../x/sys/unix/zsyscall_freebsd_arm64.go | 4 +- .../golang.org/x/sys/unix/zsyscall_linux.go | 20 + .../x/sys/unix/zsyscall_linux_386.go | 17 +- .../x/sys/unix/zsyscall_linux_amd64.go | 28 +- .../x/sys/unix/zsyscall_linux_arm.go | 15 +- .../x/sys/unix/zsyscall_linux_arm64.go | 15 +- .../x/sys/unix/zsyscall_linux_mips.go | 28 +- .../x/sys/unix/zsyscall_linux_mips64.go | 28 +- .../x/sys/unix/zsyscall_linux_mips64le.go | 15 +- .../x/sys/unix/zsyscall_linux_mipsle.go | 28 +- .../x/sys/unix/zsyscall_linux_ppc.go | 28 +- .../x/sys/unix/zsyscall_linux_ppc64.go | 28 +- .../x/sys/unix/zsyscall_linux_ppc64le.go | 28 +- .../x/sys/unix/zsyscall_linux_riscv64.go | 15 +- .../x/sys/unix/zsyscall_linux_s390x.go | 17 +- .../x/sys/unix/zsyscall_linux_sparc64.go | 28 +- .../x/sys/unix/zsyscall_netbsd_386.go | 16 +- .../x/sys/unix/zsyscall_netbsd_amd64.go | 16 +- .../x/sys/unix/zsyscall_netbsd_arm.go | 16 +- .../x/sys/unix/zsyscall_netbsd_arm64.go | 16 +- .../x/sys/unix/zsyscall_openbsd_386.go | 4 +- .../x/sys/unix/zsyscall_openbsd_amd64.go | 4 +- .../x/sys/unix/zsyscall_openbsd_arm.go | 4 +- .../x/sys/unix/zsyscall_openbsd_arm64.go | 4 +- .../x/sys/unix/zsyscall_openbsd_mips64.go | 4 +- .../x/sys/unix/zsyscall_solaris_amd64.go | 16 +- .../x/sys/unix/zsysnum_linux_386.go | 1 + .../x/sys/unix/zsysnum_linux_amd64.go | 1 + .../x/sys/unix/zsysnum_linux_arm.go | 1 + .../x/sys/unix/zsysnum_linux_arm64.go | 1 + .../x/sys/unix/zsysnum_linux_mips.go | 1 + .../x/sys/unix/zsysnum_linux_mips64.go | 1 + .../x/sys/unix/zsysnum_linux_mips64le.go | 1 + .../x/sys/unix/zsysnum_linux_mipsle.go | 1 + .../x/sys/unix/zsysnum_linux_ppc.go | 1 + .../x/sys/unix/zsysnum_linux_ppc64.go | 1 + .../x/sys/unix/zsysnum_linux_ppc64le.go | 1 + .../x/sys/unix/zsysnum_linux_riscv64.go | 1 + .../x/sys/unix/zsysnum_linux_s390x.go | 1 + .../x/sys/unix/zsysnum_linux_sparc64.go | 1 + .../golang.org/x/sys/unix/ztypes_linux.go | 1574 ++++++++++++++- .../x/sys/unix/ztypes_linux_s390x.go | 4 +- .../golang.org/x/sys/windows/exec_windows.go | 37 +- .../x/sys/windows/syscall_windows.go | 37 +- .../golang.org/x/sys/windows/types_windows.go | 43 +- .../x/sys/windows/zsyscall_windows.go | 18 +- src/cmd/vendor/modules.txt | 7 +- src/go.mod | 10 +- src/go.sum | 16 +- src/net/http/h2_bundle.go | 47 +- .../golang.org/x/sys/cpu/syscall_aix_gccgo.go | 2 +- src/vendor/modules.txt | 8 +- 106 files changed, 2309 insertions(+), 3981 deletions(-) delete mode 100644 src/cmd/vendor/golang.org/x/crypto/ed25519/ed25519_go113.go delete mode 100644 src/cmd/vendor/golang.org/x/crypto/ed25519/internal/edwards25519/const.go delete mode 100644 src/cmd/vendor/golang.org/x/crypto/ed25519/internal/edwards25519/edwards25519.go create mode 100644 src/cmd/vendor/golang.org/x/sys/unix/syscall_linux_alarm.go diff --git a/src/cmd/go.mod b/src/cmd/go.mod index c5582e7dc7c..ce1a32f3860 100644 --- a/src/cmd/go.mod +++ b/src/cmd/go.mod @@ -1,19 +1,19 @@ module cmd -go 1.18 +go 1.19 require ( github.com/google/pprof v0.0.0-20211104044539-f987b9c94b31 golang.org/x/arch v0.0.0-20210923205945-b76863e36670 golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 golang.org/x/sync v0.0.0-20210220032951-036812b2e83c - golang.org/x/sys v0.0.0-20211205182925-97ca703d548d + golang.org/x/sys v0.0.0-20220317061510-51cd9980dadf golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 - golang.org/x/tools v0.1.11-0.20220316221636-85d68bc98d0d + golang.org/x/tools v0.1.11-0.20220317151829-c7b0e9aca63d ) require ( github.com/ianlancetaylor/demangle v0.0.0-20210905161508-09a460cdf81d // indirect - golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 // indirect + golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd // indirect golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect ) diff --git a/src/cmd/go.sum b/src/cmd/go.sum index 9060d68517b..b4a800b07e6 100644 --- a/src/cmd/go.sum +++ b/src/cmd/go.sum @@ -7,18 +7,18 @@ github.com/ianlancetaylor/demangle v0.0.0-20210905161508-09a460cdf81d h1:uGg2frl github.com/ianlancetaylor/demangle v0.0.0-20210905161508-09a460cdf81d/go.mod h1:aYm2/VgdVmcIU8iMfdMvDMsRAQjcfZSKFby6HOFvi/w= golang.org/x/arch v0.0.0-20210923205945-b76863e36670 h1:18EFjUmQOcUvxNYSkA6jO9VAiXCnxFY6NyDX0bHDmkU= golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= -golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 h1:0es+/5331RGQPcXlMfP+WrnIIS6dNnNRe0WB02W0F4M= -golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd h1:XcWmESyNjXJMLahc3mqVQJcgSTDxFxhETVlfk9uGc38= +golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 h1:kQgndtyPBW/JIYERgdxfwMYh3AVStj88WQTlNDi2a+o= golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20211205182925-97ca703d548d h1:FjkYO/PPp4Wi0EAUOVLxePm7qVW4r4ctbWpURyuOD0E= -golang.org/x/sys v0.0.0-20211205182925-97ca703d548d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220317061510-51cd9980dadf h1:Fm4IcnUL803i92qDlmB0obyHmosDrxZWxJL3gIeNqOw= +golang.org/x/sys v0.0.0-20220317061510-51cd9980dadf/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/tools v0.1.11-0.20220316221636-85d68bc98d0d h1:ODHIU0shdFMaUzD/IIhSde/2e2hoMJlgKMKF3e2rCHU= -golang.org/x/tools v0.1.11-0.20220316221636-85d68bc98d0d/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E= +golang.org/x/tools v0.1.11-0.20220317151829-c7b0e9aca63d h1:zv4ADrxllJLdyAP+2lxm5nF9jMTnLYo1PdWi1xLBCsU= +golang.org/x/tools v0.1.11-0.20220317151829-c7b0e9aca63d/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/src/cmd/vendor/golang.org/x/crypto/ed25519/ed25519.go b/src/cmd/vendor/golang.org/x/crypto/ed25519/ed25519.go index 71ad917dadd..a7828345fcc 100644 --- a/src/cmd/vendor/golang.org/x/crypto/ed25519/ed25519.go +++ b/src/cmd/vendor/golang.org/x/crypto/ed25519/ed25519.go @@ -1,13 +1,7 @@ -// Copyright 2016 The Go Authors. All rights reserved. +// Copyright 2019 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. -// In Go 1.13, the ed25519 package was promoted to the standard library as -// crypto/ed25519, and this package became a wrapper for the standard library one. -// -//go:build !go1.13 -// +build !go1.13 - // Package ed25519 implements the Ed25519 signature algorithm. See // https://ed25519.cr.yp.to/. // @@ -16,21 +10,15 @@ // representation includes a public key suffix to make multiple signing // operations with the same key more efficient. This package refers to the RFC // 8032 private key as the “seed”. +// +// Beginning with Go 1.13, the functionality of this package was moved to the +// standard library as crypto/ed25519. This package only acts as a compatibility +// wrapper. package ed25519 -// This code is a port of the public domain, “ref10” implementation of ed25519 -// from SUPERCOP. - import ( - "bytes" - "crypto" - cryptorand "crypto/rand" - "crypto/sha512" - "errors" + "crypto/ed25519" "io" - "strconv" - - "golang.org/x/crypto/ed25519/internal/edwards25519" ) const ( @@ -45,57 +33,21 @@ const ( ) // PublicKey is the type of Ed25519 public keys. -type PublicKey []byte +// +// This type is an alias for crypto/ed25519's PublicKey type. +// See the crypto/ed25519 package for the methods on this type. +type PublicKey = ed25519.PublicKey // PrivateKey is the type of Ed25519 private keys. It implements crypto.Signer. -type PrivateKey []byte - -// Public returns the PublicKey corresponding to priv. -func (priv PrivateKey) Public() crypto.PublicKey { - publicKey := make([]byte, PublicKeySize) - copy(publicKey, priv[32:]) - return PublicKey(publicKey) -} - -// Seed returns the private key seed corresponding to priv. It is provided for -// interoperability with RFC 8032. RFC 8032's private keys correspond to seeds -// in this package. -func (priv PrivateKey) Seed() []byte { - seed := make([]byte, SeedSize) - copy(seed, priv[:32]) - return seed -} - -// Sign signs the given message with priv. -// Ed25519 performs two passes over messages to be signed and therefore cannot -// handle pre-hashed messages. Thus opts.HashFunc() must return zero to -// indicate the message hasn't been hashed. This can be achieved by passing -// crypto.Hash(0) as the value for opts. -func (priv PrivateKey) Sign(rand io.Reader, message []byte, opts crypto.SignerOpts) (signature []byte, err error) { - if opts.HashFunc() != crypto.Hash(0) { - return nil, errors.New("ed25519: cannot sign hashed message") - } - - return Sign(priv, message), nil -} +// +// This type is an alias for crypto/ed25519's PrivateKey type. +// See the crypto/ed25519 package for the methods on this type. +type PrivateKey = ed25519.PrivateKey // GenerateKey generates a public/private key pair using entropy from rand. // If rand is nil, crypto/rand.Reader will be used. func GenerateKey(rand io.Reader) (PublicKey, PrivateKey, error) { - if rand == nil { - rand = cryptorand.Reader - } - - seed := make([]byte, SeedSize) - if _, err := io.ReadFull(rand, seed); err != nil { - return nil, nil, err - } - - privateKey := NewKeyFromSeed(seed) - publicKey := make([]byte, PublicKeySize) - copy(publicKey, privateKey[32:]) - - return publicKey, privateKey, nil + return ed25519.GenerateKey(rand) } // NewKeyFromSeed calculates a private key from a seed. It will panic if @@ -103,121 +55,17 @@ func GenerateKey(rand io.Reader) (PublicKey, PrivateKey, error) { // with RFC 8032. RFC 8032's private keys correspond to seeds in this // package. func NewKeyFromSeed(seed []byte) PrivateKey { - if l := len(seed); l != SeedSize { - panic("ed25519: bad seed length: " + strconv.Itoa(l)) - } - - digest := sha512.Sum512(seed) - digest[0] &= 248 - digest[31] &= 127 - digest[31] |= 64 - - var A edwards25519.ExtendedGroupElement - var hBytes [32]byte - copy(hBytes[:], digest[:]) - edwards25519.GeScalarMultBase(&A, &hBytes) - var publicKeyBytes [32]byte - A.ToBytes(&publicKeyBytes) - - privateKey := make([]byte, PrivateKeySize) - copy(privateKey, seed) - copy(privateKey[32:], publicKeyBytes[:]) - - return privateKey + return ed25519.NewKeyFromSeed(seed) } // Sign signs the message with privateKey and returns a signature. It will // panic if len(privateKey) is not PrivateKeySize. func Sign(privateKey PrivateKey, message []byte) []byte { - if l := len(privateKey); l != PrivateKeySize { - panic("ed25519: bad private key length: " + strconv.Itoa(l)) - } - - h := sha512.New() - h.Write(privateKey[:32]) - - var digest1, messageDigest, hramDigest [64]byte - var expandedSecretKey [32]byte - h.Sum(digest1[:0]) - copy(expandedSecretKey[:], digest1[:]) - expandedSecretKey[0] &= 248 - expandedSecretKey[31] &= 63 - expandedSecretKey[31] |= 64 - - h.Reset() - h.Write(digest1[32:]) - h.Write(message) - h.Sum(messageDigest[:0]) - - var messageDigestReduced [32]byte - edwards25519.ScReduce(&messageDigestReduced, &messageDigest) - var R edwards25519.ExtendedGroupElement - edwards25519.GeScalarMultBase(&R, &messageDigestReduced) - - var encodedR [32]byte - R.ToBytes(&encodedR) - - h.Reset() - h.Write(encodedR[:]) - h.Write(privateKey[32:]) - h.Write(message) - h.Sum(hramDigest[:0]) - var hramDigestReduced [32]byte - edwards25519.ScReduce(&hramDigestReduced, &hramDigest) - - var s [32]byte - edwards25519.ScMulAdd(&s, &hramDigestReduced, &expandedSecretKey, &messageDigestReduced) - - signature := make([]byte, SignatureSize) - copy(signature[:], encodedR[:]) - copy(signature[32:], s[:]) - - return signature + return ed25519.Sign(privateKey, message) } // Verify reports whether sig is a valid signature of message by publicKey. It // will panic if len(publicKey) is not PublicKeySize. func Verify(publicKey PublicKey, message, sig []byte) bool { - if l := len(publicKey); l != PublicKeySize { - panic("ed25519: bad public key length: " + strconv.Itoa(l)) - } - - if len(sig) != SignatureSize || sig[63]&224 != 0 { - return false - } - - var A edwards25519.ExtendedGroupElement - var publicKeyBytes [32]byte - copy(publicKeyBytes[:], publicKey) - if !A.FromBytes(&publicKeyBytes) { - return false - } - edwards25519.FeNeg(&A.X, &A.X) - edwards25519.FeNeg(&A.T, &A.T) - - h := sha512.New() - h.Write(sig[:32]) - h.Write(publicKey[:]) - h.Write(message) - var digest [64]byte - h.Sum(digest[:0]) - - var hReduced [32]byte - edwards25519.ScReduce(&hReduced, &digest) - - var R edwards25519.ProjectiveGroupElement - var s [32]byte - copy(s[:], sig[32:]) - - // https://tools.ietf.org/html/rfc8032#section-5.1.7 requires that s be in - // the range [0, order) in order to prevent signature malleability. - if !edwards25519.ScMinimal(&s) { - return false - } - - edwards25519.GeDoubleScalarMultVartime(&R, &hReduced, &A, &s) - - var checkR [32]byte - R.ToBytes(&checkR) - return bytes.Equal(sig[:32], checkR[:]) + return ed25519.Verify(publicKey, message, sig) } diff --git a/src/cmd/vendor/golang.org/x/crypto/ed25519/ed25519_go113.go b/src/cmd/vendor/golang.org/x/crypto/ed25519/ed25519_go113.go deleted file mode 100644 index b5974dc8b27..00000000000 --- a/src/cmd/vendor/golang.org/x/crypto/ed25519/ed25519_go113.go +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright 2019 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 go1.13 -// +build go1.13 - -// Package ed25519 implements the Ed25519 signature algorithm. See -// https://ed25519.cr.yp.to/. -// -// These functions are also compatible with the “Ed25519” function defined in -// RFC 8032. However, unlike RFC 8032's formulation, this package's private key -// representation includes a public key suffix to make multiple signing -// operations with the same key more efficient. This package refers to the RFC -// 8032 private key as the “seed”. -// -// Beginning with Go 1.13, the functionality of this package was moved to the -// standard library as crypto/ed25519. This package only acts as a compatibility -// wrapper. -package ed25519 - -import ( - "crypto/ed25519" - "io" -) - -const ( - // PublicKeySize is the size, in bytes, of public keys as used in this package. - PublicKeySize = 32 - // PrivateKeySize is the size, in bytes, of private keys as used in this package. - PrivateKeySize = 64 - // SignatureSize is the size, in bytes, of signatures generated and verified by this package. - SignatureSize = 64 - // SeedSize is the size, in bytes, of private key seeds. These are the private key representations used by RFC 8032. - SeedSize = 32 -) - -// PublicKey is the type of Ed25519 public keys. -// -// This type is an alias for crypto/ed25519's PublicKey type. -// See the crypto/ed25519 package for the methods on this type. -type PublicKey = ed25519.PublicKey - -// PrivateKey is the type of Ed25519 private keys. It implements crypto.Signer. -// -// This type is an alias for crypto/ed25519's PrivateKey type. -// See the crypto/ed25519 package for the methods on this type. -type PrivateKey = ed25519.PrivateKey - -// GenerateKey generates a public/private key pair using entropy from rand. -// If rand is nil, crypto/rand.Reader will be used. -func GenerateKey(rand io.Reader) (PublicKey, PrivateKey, error) { - return ed25519.GenerateKey(rand) -} - -// NewKeyFromSeed calculates a private key from a seed. It will panic if -// len(seed) is not SeedSize. This function is provided for interoperability -// with RFC 8032. RFC 8032's private keys correspond to seeds in this -// package. -func NewKeyFromSeed(seed []byte) PrivateKey { - return ed25519.NewKeyFromSeed(seed) -} - -// Sign signs the message with privateKey and returns a signature. It will -// panic if len(privateKey) is not PrivateKeySize. -func Sign(privateKey PrivateKey, message []byte) []byte { - return ed25519.Sign(privateKey, message) -} - -// Verify reports whether sig is a valid signature of message by publicKey. It -// will panic if len(publicKey) is not PublicKeySize. -func Verify(publicKey PublicKey, message, sig []byte) bool { - return ed25519.Verify(publicKey, message, sig) -} diff --git a/src/cmd/vendor/golang.org/x/crypto/ed25519/internal/edwards25519/const.go b/src/cmd/vendor/golang.org/x/crypto/ed25519/internal/edwards25519/const.go deleted file mode 100644 index e39f086c1d8..00000000000 --- a/src/cmd/vendor/golang.org/x/crypto/ed25519/internal/edwards25519/const.go +++ /dev/null @@ -1,1422 +0,0 @@ -// Copyright 2016 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 edwards25519 - -// These values are from the public domain, “ref10” implementation of ed25519 -// from SUPERCOP. - -// d is a constant in the Edwards curve equation. -var d = FieldElement{ - -10913610, 13857413, -15372611, 6949391, 114729, -8787816, -6275908, -3247719, -18696448, -12055116, -} - -// d2 is 2*d. -var d2 = FieldElement{ - -21827239, -5839606, -30745221, 13898782, 229458, 15978800, -12551817, -6495438, 29715968, 9444199, -} - -// SqrtM1 is the square-root of -1 in the field. -var SqrtM1 = FieldElement{ - -32595792, -7943725, 9377950, 3500415, 12389472, -272473, -25146209, -2005654, 326686, 11406482, -} - -// A is a constant in the Montgomery-form of curve25519. -var A = FieldElement{ - 486662, 0, 0, 0, 0, 0, 0, 0, 0, 0, -} - -// bi contains precomputed multiples of the base-point. See the Ed25519 paper -// for a discussion about how these values are used. -var bi = [8]PreComputedGroupElement{ - { - FieldElement{25967493, -14356035, 29566456, 3660896, -12694345, 4014787, 27544626, -11754271, -6079156, 2047605}, - FieldElement{-12545711, 934262, -2722910, 3049990, -727428, 9406986, 12720692, 5043384, 19500929, -15469378}, - FieldElement{-8738181, 4489570, 9688441, -14785194, 10184609, -12363380, 29287919, 11864899, -24514362, -4438546}, - }, - { - FieldElement{15636291, -9688557, 24204773, -7912398, 616977, -16685262, 27787600, -14772189, 28944400, -1550024}, - FieldElement{16568933, 4717097, -11556148, -1102322, 15682896, -11807043, 16354577, -11775962, 7689662, 11199574}, - FieldElement{30464156, -5976125, -11779434, -15670865, 23220365, 15915852, 7512774, 10017326, -17749093, -9920357}, - }, - { - FieldElement{10861363, 11473154, 27284546, 1981175, -30064349, 12577861, 32867885, 14515107, -15438304, 10819380}, - FieldElement{4708026, 6336745, 20377586, 9066809, -11272109, 6594696, -25653668, 12483688, -12668491, 5581306}, - FieldElement{19563160, 16186464, -29386857, 4097519, 10237984, -4348115, 28542350, 13850243, -23678021, -15815942}, - }, - { - FieldElement{5153746, 9909285, 1723747, -2777874, 30523605, 5516873, 19480852, 5230134, -23952439, -15175766}, - FieldElement{-30269007, -3463509, 7665486, 10083793, 28475525, 1649722, 20654025, 16520125, 30598449, 7715701}, - FieldElement{28881845, 14381568, 9657904, 3680757, -20181635, 7843316, -31400660, 1370708, 29794553, -1409300}, - }, - { - FieldElement{-22518993, -6692182, 14201702, -8745502, -23510406, 8844726, 18474211, -1361450, -13062696, 13821877}, - FieldElement{-6455177, -7839871, 3374702, -4740862, -27098617, -10571707, 31655028, -7212327, 18853322, -14220951}, - FieldElement{4566830, -12963868, -28974889, -12240689, -7602672, -2830569, -8514358, -10431137, 2207753, -3209784}, - }, - { - FieldElement{-25154831, -4185821, 29681144, 7868801, -6854661, -9423865, -12437364, -663000, -31111463, -16132436}, - FieldElement{25576264, -2703214, 7349804, -11814844, 16472782, 9300885, 3844789, 15725684, 171356, 6466918}, - FieldElement{23103977, 13316479, 9739013, -16149481, 817875, -15038942, 8965339, -14088058, -30714912, 16193877}, - }, - { - FieldElement{-33521811, 3180713, -2394130, 14003687, -16903474, -16270840, 17238398, 4729455, -18074513, 9256800}, - FieldElement{-25182317, -4174131, 32336398, 5036987, -21236817, 11360617, 22616405, 9761698, -19827198, 630305}, - FieldElement{-13720693, 2639453, -24237460, -7406481, 9494427, -5774029, -6554551, -15960994, -2449256, -14291300}, - }, - { - FieldElement{-3151181, -5046075, 9282714, 6866145, -31907062, -863023, -18940575, 15033784, 25105118, -7894876}, - FieldElement{-24326370, 15950226, -31801215, -14592823, -11662737, -5090925, 1573892, -2625887, 2198790, -15804619}, - FieldElement{-3099351, 10324967, -2241613, 7453183, -5446979, -2735503, -13812022, -16236442, -32461234, -12290683}, - }, -} - -// base contains precomputed multiples of the base-point. See the Ed25519 paper -// for a discussion about how these values are used. -var base = [32][8]PreComputedGroupElement{ - { - { - FieldElement{25967493, -14356035, 29566456, 3660896, -12694345, 4014787, 27544626, -11754271, -6079156, 2047605}, - FieldElement{-12545711, 934262, -2722910, 3049990, -727428, 9406986, 12720692, 5043384, 19500929, -15469378}, - FieldElement{-8738181, 4489570, 9688441, -14785194, 10184609, -12363380, 29287919, 11864899, -24514362, -4438546}, - }, - { - FieldElement{-12815894, -12976347, -21581243, 11784320, -25355658, -2750717, -11717903, -3814571, -358445, -10211303}, - FieldElement{-21703237, 6903825, 27185491, 6451973, -29577724, -9554005, -15616551, 11189268, -26829678, -5319081}, - FieldElement{26966642, 11152617, 32442495, 15396054, 14353839, -12752335, -3128826, -9541118, -15472047, -4166697}, - }, - { - FieldElement{15636291, -9688557, 24204773, -7912398, 616977, -16685262, 27787600, -14772189, 28944400, -1550024}, - FieldElement{16568933, 4717097, -11556148, -1102322, 15682896, -11807043, 16354577, -11775962, 7689662, 11199574}, - FieldElement{30464156, -5976125, -11779434, -15670865, 23220365, 15915852, 7512774, 10017326, -17749093, -9920357}, - }, - { - FieldElement{-17036878, 13921892, 10945806, -6033431, 27105052, -16084379, -28926210, 15006023, 3284568, -6276540}, - FieldElement{23599295, -8306047, -11193664, -7687416, 13236774, 10506355, 7464579, 9656445, 13059162, 10374397}, - FieldElement{7798556, 16710257, 3033922, 2874086, 28997861, 2835604, 32406664, -3839045, -641708, -101325}, - }, - { - FieldElement{10861363, 11473154, 27284546, 1981175, -30064349, 12577861, 32867885, 14515107, -15438304, 10819380}, - FieldElement{4708026, 6336745, 20377586, 9066809, -11272109, 6594696, -25653668, 12483688, -12668491, 5581306}, - FieldElement{19563160, 16186464, -29386857, 4097519, 10237984, -4348115, 28542350, 13850243, -23678021, -15815942}, - }, - { - FieldElement{-15371964, -12862754, 32573250, 4720197, -26436522, 5875511, -19188627, -15224819, -9818940, -12085777}, - FieldElement{-8549212, 109983, 15149363, 2178705, 22900618, 4543417, 3044240, -15689887, 1762328, 14866737}, - FieldElement{-18199695, -15951423, -10473290, 1707278, -17185920, 3916101, -28236412, 3959421, 27914454, 4383652}, - }, - { - FieldElement{5153746, 9909285, 1723747, -2777874, 30523605, 5516873, 19480852, 5230134, -23952439, -15175766}, - FieldElement{-30269007, -3463509, 7665486, 10083793, 28475525, 1649722, 20654025, 16520125, 30598449, 7715701}, - FieldElement{28881845, 14381568, 9657904, 3680757, -20181635, 7843316, -31400660, 1370708, 29794553, -1409300}, - }, - { - FieldElement{14499471, -2729599, -33191113, -4254652, 28494862, 14271267, 30290735, 10876454, -33154098, 2381726}, - FieldElement{-7195431, -2655363, -14730155, 462251, -27724326, 3941372, -6236617, 3696005, -32300832, 15351955}, - FieldElement{27431194, 8222322, 16448760, -3907995, -18707002, 11938355, -32961401, -2970515, 29551813, 10109425}, - }, - }, - { - { - FieldElement{-13657040, -13155431, -31283750, 11777098, 21447386, 6519384, -2378284, -1627556, 10092783, -4764171}, - FieldElement{27939166, 14210322, 4677035, 16277044, -22964462, -12398139, -32508754, 12005538, -17810127, 12803510}, - FieldElement{17228999, -15661624, -1233527, 300140, -1224870, -11714777, 30364213, -9038194, 18016357, 4397660}, - }, - { - FieldElement{-10958843, -7690207, 4776341, -14954238, 27850028, -15602212, -26619106, 14544525, -17477504, 982639}, - FieldElement{29253598, 15796703, -2863982, -9908884, 10057023, 3163536, 7332899, -4120128, -21047696, 9934963}, - FieldElement{5793303, 16271923, -24131614, -10116404, 29188560, 1206517, -14747930, 4559895, -30123922, -10897950}, - }, - { - FieldElement{-27643952, -11493006, 16282657, -11036493, 28414021, -15012264, 24191034, 4541697, -13338309, 5500568}, - FieldElement{12650548, -1497113, 9052871, 11355358, -17680037, -8400164, -17430592, 12264343, 10874051, 13524335}, - FieldElement{25556948, -3045990, 714651, 2510400, 23394682, -10415330, 33119038, 5080568, -22528059, 5376628}, - }, - { - FieldElement{-26088264, -4011052, -17013699, -3537628, -6726793, 1920897, -22321305, -9447443, 4535768, 1569007}, - FieldElement{-2255422, 14606630, -21692440, -8039818, 28430649, 8775819, -30494562, 3044290, 31848280, 12543772}, - FieldElement{-22028579, 2943893, -31857513, 6777306, 13784462, -4292203, -27377195, -2062731, 7718482, 14474653}, - }, - { - FieldElement{2385315, 2454213, -22631320, 46603, -4437935, -15680415, 656965, -7236665, 24316168, -5253567}, - FieldElement{13741529, 10911568, -33233417, -8603737, -20177830, -1033297, 33040651, -13424532, -20729456, 8321686}, - FieldElement{21060490, -2212744, 15712757, -4336099, 1639040, 10656336, 23845965, -11874838, -9984458, 608372}, - }, - { - FieldElement{-13672732, -15087586, -10889693, -7557059, -6036909, 11305547, 1123968, -6780577, 27229399, 23887}, - FieldElement{-23244140, -294205, -11744728, 14712571, -29465699, -2029617, 12797024, -6440308, -1633405, 16678954}, - FieldElement{-29500620, 4770662, -16054387, 14001338, 7830047, 9564805, -1508144, -4795045, -17169265, 4904953}, - }, - { - FieldElement{24059557, 14617003, 19037157, -15039908, 19766093, -14906429, 5169211, 16191880, 2128236, -4326833}, - FieldElement{-16981152, 4124966, -8540610, -10653797, 30336522, -14105247, -29806336, 916033, -6882542, -2986532}, - FieldElement{-22630907, 12419372, -7134229, -7473371, -16478904, 16739175, 285431, 2763829, 15736322, 4143876}, - }, - { - FieldElement{2379352, 11839345, -4110402, -5988665, 11274298, 794957, 212801, -14594663, 23527084, -16458268}, - FieldElement{33431127, -11130478, -17838966, -15626900, 8909499, 8376530, -32625340, 4087881, -15188911, -14416214}, - FieldElement{1767683, 7197987, -13205226, -2022635, -13091350, 448826, 5799055, 4357868, -4774191, -16323038}, - }, - }, - { - { - FieldElement{6721966, 13833823, -23523388, -1551314, 26354293, -11863321, 23365147, -3949732, 7390890, 2759800}, - FieldElement{4409041, 2052381, 23373853, 10530217, 7676779, -12885954, 21302353, -4264057, 1244380, -12919645}, - FieldElement{-4421239, 7169619, 4982368, -2957590, 30256825, -2777540, 14086413, 9208236, 15886429, 16489664}, - }, - { - FieldElement{1996075, 10375649, 14346367, 13311202, -6874135, -16438411, -13693198, 398369, -30606455, -712933}, - FieldElement{-25307465, 9795880, -2777414, 14878809, -33531835, 14780363, 13348553, 12076947, -30836462, 5113182}, - FieldElement{-17770784, 11797796, 31950843, 13929123, -25888302, 12288344, -30341101, -7336386, 13847711, 5387222}, - }, - { - FieldElement{-18582163, -3416217, 17824843, -2340966, 22744343, -10442611, 8763061, 3617786, -19600662, 10370991}, - FieldElement{20246567, -14369378, 22358229, -543712, 18507283, -10413996, 14554437, -8746092, 32232924, 16763880}, - FieldElement{9648505, 10094563, 26416693, 14745928, -30374318, -6472621, 11094161, 15689506, 3140038, -16510092}, - }, - { - FieldElement{-16160072, 5472695, 31895588, 4744994, 8823515, 10365685, -27224800, 9448613, -28774454, 366295}, - FieldElement{19153450, 11523972, -11096490, -6503142, -24647631, 5420647, 28344573, 8041113, 719605, 11671788}, - FieldElement{8678025, 2694440, -6808014, 2517372, 4964326, 11152271, -15432916, -15266516, 27000813, -10195553}, - }, - { - FieldElement{-15157904, 7134312, 8639287, -2814877, -7235688, 10421742, 564065, 5336097, 6750977, -14521026}, - FieldElement{11836410, -3979488, 26297894, 16080799, 23455045, 15735944, 1695823, -8819122, 8169720, 16220347}, - FieldElement{-18115838, 8653647, 17578566, -6092619, -8025777, -16012763, -11144307, -2627664, -5990708, -14166033}, - }, - { - FieldElement{-23308498, -10968312, 15213228, -10081214, -30853605, -11050004, 27884329, 2847284, 2655861, 1738395}, - FieldElement{-27537433, -14253021, -25336301, -8002780, -9370762, 8129821, 21651608, -3239336, -19087449, -11005278}, - FieldElement{1533110, 3437855, 23735889, 459276, 29970501, 11335377, 26030092, 5821408, 10478196, 8544890}, - }, - { - FieldElement{32173121, -16129311, 24896207, 3921497, 22579056, -3410854, 19270449, 12217473, 17789017, -3395995}, - FieldElement{-30552961, -2228401, -15578829, -10147201, 13243889, 517024, 15479401, -3853233, 30460520, 1052596}, - FieldElement{-11614875, 13323618, 32618793, 8175907, -15230173, 12596687, 27491595, -4612359, 3179268, -9478891}, - }, - { - FieldElement{31947069, -14366651, -4640583, -15339921, -15125977, -6039709, -14756777, -16411740, 19072640, -9511060}, - FieldElement{11685058, 11822410, 3158003, -13952594, 33402194, -4165066, 5977896, -5215017, 473099, 5040608}, - FieldElement{-20290863, 8198642, -27410132, 11602123, 1290375, -2799760, 28326862, 1721092, -19558642, -3131606}, - }, - }, - { - { - FieldElement{7881532, 10687937, 7578723, 7738378, -18951012, -2553952, 21820786, 8076149, -27868496, 11538389}, - FieldElement{-19935666, 3899861, 18283497, -6801568, -15728660, -11249211, 8754525, 7446702, -5676054, 5797016}, - FieldElement{-11295600, -3793569, -15782110, -7964573, 12708869, -8456199, 2014099, -9050574, -2369172, -5877341}, - }, - { - FieldElement{-22472376, -11568741, -27682020, 1146375, 18956691, 16640559, 1192730, -3714199, 15123619, 10811505}, - FieldElement{14352098, -3419715, -18942044, 10822655, 32750596, 4699007, -70363, 15776356, -28886779, -11974553}, - FieldElement{-28241164, -8072475, -4978962, -5315317, 29416931, 1847569, -20654173, -16484855, 4714547, -9600655}, - }, - { - FieldElement{15200332, 8368572, 19679101, 15970074, -31872674, 1959451, 24611599, -4543832, -11745876, 12340220}, - FieldElement{12876937, -10480056, 33134381, 6590940, -6307776, 14872440, 9613953, 8241152, 15370987, 9608631}, - FieldElement{-4143277, -12014408, 8446281, -391603, 4407738, 13629032, -7724868, 15866074, -28210621, -8814099}, - }, - { - FieldElement{26660628, -15677655, 8393734, 358047, -7401291, 992988, -23904233, 858697, 20571223, 8420556}, - FieldElement{14620715, 13067227, -15447274, 8264467, 14106269, 15080814, 33531827, 12516406, -21574435, -12476749}, - FieldElement{236881, 10476226, 57258, -14677024, 6472998, 2466984, 17258519, 7256740, 8791136, 15069930}, - }, - { - FieldElement{1276410, -9371918, 22949635, -16322807, -23493039, -5702186, 14711875, 4874229, -30663140, -2331391}, - FieldElement{5855666, 4990204, -13711848, 7294284, -7804282, 1924647, -1423175, -7912378, -33069337, 9234253}, - FieldElement{20590503, -9018988, 31529744, -7352666, -2706834, 10650548, 31559055, -11609587, 18979186, 13396066}, - }, - { - FieldElement{24474287, 4968103, 22267082, 4407354, 24063882, -8325180, -18816887, 13594782, 33514650, 7021958}, - FieldElement{-11566906, -6565505, -21365085, 15928892, -26158305, 4315421, -25948728, -3916677, -21480480, 12868082}, - FieldElement{-28635013, 13504661, 19988037, -2132761, 21078225, 6443208, -21446107, 2244500, -12455797, -8089383}, - }, - { - FieldElement{-30595528, 13793479, -5852820, 319136, -25723172, -6263899, 33086546, 8957937, -15233648, 5540521}, - FieldElement{-11630176, -11503902, -8119500, -7643073, 2620056, 1022908, -23710744, -1568984, -16128528, -14962807}, - FieldElement{23152971, 775386, 27395463, 14006635, -9701118, 4649512, 1689819, 892185, -11513277, -15205948}, - }, - { - FieldElement{9770129, 9586738, 26496094, 4324120, 1556511, -3550024, 27453819, 4763127, -19179614, 5867134}, - FieldElement{-32765025, 1927590, 31726409, -4753295, 23962434, -16019500, 27846559, 5931263, -29749703, -16108455}, - FieldElement{27461885, -2977536, 22380810, 1815854, -23033753, -3031938, 7283490, -15148073, -19526700, 7734629}, - }, - }, - { - { - FieldElement{-8010264, -9590817, -11120403, 6196038, 29344158, -13430885, 7585295, -3176626, 18549497, 15302069}, - FieldElement{-32658337, -6171222, -7672793, -11051681, 6258878, 13504381, 10458790, -6418461, -8872242, 8424746}, - FieldElement{24687205, 8613276, -30667046, -3233545, 1863892, -1830544, 19206234, 7134917, -11284482, -828919}, - }, - { - FieldElement{11334899, -9218022, 8025293, 12707519, 17523892, -10476071, 10243738, -14685461, -5066034, 16498837}, - FieldElement{8911542, 6887158, -9584260, -6958590, 11145641, -9543680, 17303925, -14124238, 6536641, 10543906}, - FieldElement{-28946384, 15479763, -17466835, 568876, -1497683, 11223454, -2669190, -16625574, -27235709, 8876771}, - }, - { - FieldElement{-25742899, -12566864, -15649966, -846607, -33026686, -796288, -33481822, 15824474, -604426, -9039817}, - FieldElement{10330056, 70051, 7957388, -9002667, 9764902, 15609756, 27698697, -4890037, 1657394, 3084098}, - FieldElement{10477963, -7470260, 12119566, -13250805, 29016247, -5365589, 31280319, 14396151, -30233575, 15272409}, - }, - { - FieldElement{-12288309, 3169463, 28813183, 16658753, 25116432, -5630466, -25173957, -12636138, -25014757, 1950504}, - FieldElement{-26180358, 9489187, 11053416, -14746161, -31053720, 5825630, -8384306, -8767532, 15341279, 8373727}, - FieldElement{28685821, 7759505, -14378516, -12002860, -31971820, 4079242, 298136, -10232602, -2878207, 15190420}, - }, - { - FieldElement{-32932876, 13806336, -14337485, -15794431, -24004620, 10940928, 8669718, 2742393, -26033313, -6875003}, - FieldElement{-1580388, -11729417, -25979658, -11445023, -17411874, -10912854, 9291594, -16247779, -12154742, 6048605}, - FieldElement{-30305315, 14843444, 1539301, 11864366, 20201677, 1900163, 13934231, 5128323, 11213262, 9168384}, - }, - { - FieldElement{-26280513, 11007847, 19408960, -940758, -18592965, -4328580, -5088060, -11105150, 20470157, -16398701}, - FieldElement{-23136053, 9282192, 14855179, -15390078, -7362815, -14408560, -22783952, 14461608, 14042978, 5230683}, - FieldElement{29969567, -2741594, -16711867, -8552442, 9175486, -2468974, 21556951, 3506042, -5933891, -12449708}, - }, - { - FieldElement{-3144746, 8744661, 19704003, 4581278, -20430686, 6830683, -21284170, 8971513, -28539189, 15326563}, - FieldElement{-19464629, 10110288, -17262528, -3503892, -23500387, 1355669, -15523050, 15300988, -20514118, 9168260}, - FieldElement{-5353335, 4488613, -23803248, 16314347, 7780487, -15638939, -28948358, 9601605, 33087103, -9011387}, - }, - { - FieldElement{-19443170, -15512900, -20797467, -12445323, -29824447, 10229461, -27444329, -15000531, -5996870, 15664672}, - FieldElement{23294591, -16632613, -22650781, -8470978, 27844204, 11461195, 13099750, -2460356, 18151676, 13417686}, - FieldElement{-24722913, -4176517, -31150679, 5988919, -26858785, 6685065, 1661597, -12551441, 15271676, -15452665}, - }, - }, - { - { - FieldElement{11433042, -13228665, 8239631, -5279517, -1985436, -725718, -18698764, 2167544, -6921301, -13440182}, - FieldElement{-31436171, 15575146, 30436815, 12192228, -22463353, 9395379, -9917708, -8638997, 12215110, 12028277}, - FieldElement{14098400, 6555944, 23007258, 5757252, -15427832, -12950502, 30123440, 4617780, -16900089, -655628}, - }, - { - FieldElement{-4026201, -15240835, 11893168, 13718664, -14809462, 1847385, -15819999, 10154009, 23973261, -12684474}, - FieldElement{-26531820, -3695990, -1908898, 2534301, -31870557, -16550355, 18341390, -11419951, 32013174, -10103539}, - FieldElement{-25479301, 10876443, -11771086, -14625140, -12369567, 1838104, 21911214, 6354752, 4425632, -837822}, - }, - { - FieldElement{-10433389, -14612966, 22229858, -3091047, -13191166, 776729, -17415375, -12020462, 4725005, 14044970}, - FieldElement{19268650, -7304421, 1555349, 8692754, -21474059, -9910664, 6347390, -1411784, -19522291, -16109756}, - FieldElement{-24864089, 12986008, -10898878, -5558584, -11312371, -148526, 19541418, 8180106, 9282262, 10282508}, - }, - { - FieldElement{-26205082, 4428547, -8661196, -13194263, 4098402, -14165257, 15522535, 8372215, 5542595, -10702683}, - FieldElement{-10562541, 14895633, 26814552, -16673850, -17480754, -2489360, -2781891, 6993761, -18093885, 10114655}, - FieldElement{-20107055, -929418, 31422704, 10427861, -7110749, 6150669, -29091755, -11529146, 25953725, -106158}, - }, - { - FieldElement{-4234397, -8039292, -9119125, 3046000, 2101609, -12607294, 19390020, 6094296, -3315279, 12831125}, - FieldElement{-15998678, 7578152, 5310217, 14408357, -33548620, -224739, 31575954, 6326196, 7381791, -2421839}, - FieldElement{-20902779, 3296811, 24736065, -16328389, 18374254, 7318640, 6295303, 8082724, -15362489, 12339664}, - }, - { - FieldElement{27724736, 2291157, 6088201, -14184798, 1792727, 5857634, 13848414, 15768922, 25091167, 14856294}, - FieldElement{-18866652, 8331043, 24373479, 8541013, -701998, -9269457, 12927300, -12695493, -22182473, -9012899}, - FieldElement{-11423429, -5421590, 11632845, 3405020, 30536730, -11674039, -27260765, 13866390, 30146206, 9142070}, - }, - { - FieldElement{3924129, -15307516, -13817122, -10054960, 12291820, -668366, -27702774, 9326384, -8237858, 4171294}, - FieldElement{-15921940, 16037937, 6713787, 16606682, -21612135, 2790944, 26396185, 3731949, 345228, -5462949}, - FieldElement{-21327538, 13448259, 25284571, 1143661, 20614966, -8849387, 2031539, -12391231, -16253183, -13582083}, - }, - { - FieldElement{31016211, -16722429, 26371392, -14451233, -5027349, 14854137, 17477601, 3842657, 28012650, -16405420}, - FieldElement{-5075835, 9368966, -8562079, -4600902, -15249953, 6970560, -9189873, 16292057, -8867157, 3507940}, - FieldElement{29439664, 3537914, 23333589, 6997794, -17555561, -11018068, -15209202, -15051267, -9164929, 6580396}, - }, - }, - { - { - FieldElement{-12185861, -7679788, 16438269, 10826160, -8696817, -6235611, 17860444, -9273846, -2095802, 9304567}, - FieldElement{20714564, -4336911, 29088195, 7406487, 11426967, -5095705, 14792667, -14608617, 5289421, -477127}, - FieldElement{-16665533, -10650790, -6160345, -13305760, 9192020, -1802462, 17271490, 12349094, 26939669, -3752294}, - }, - { - FieldElement{-12889898, 9373458, 31595848, 16374215, 21471720, 13221525, -27283495, -12348559, -3698806, 117887}, - FieldElement{22263325, -6560050, 3984570, -11174646, -15114008, -566785, 28311253, 5358056, -23319780, 541964}, - FieldElement{16259219, 3261970, 2309254, -15534474, -16885711, -4581916, 24134070, -16705829, -13337066, -13552195}, - }, - { - FieldElement{9378160, -13140186, -22845982, -12745264, 28198281, -7244098, -2399684, -717351, 690426, 14876244}, - FieldElement{24977353, -314384, -8223969, -13465086, 28432343, -1176353, -13068804, -12297348, -22380984, 6618999}, - FieldElement{-1538174, 11685646, 12944378, 13682314, -24389511, -14413193, 8044829, -13817328, 32239829, -5652762}, - }, - { - FieldElement{-18603066, 4762990, -926250, 8885304, -28412480, -3187315, 9781647, -10350059, 32779359, 5095274}, - FieldElement{-33008130, -5214506, -32264887, -3685216, 9460461, -9327423, -24601656, 14506724, 21639561, -2630236}, - FieldElement{-16400943, -13112215, 25239338, 15531969, 3987758, -4499318, -1289502, -6863535, 17874574, 558605}, - }, - { - FieldElement{-13600129, 10240081, 9171883, 16131053, -20869254, 9599700, 33499487, 5080151, 2085892, 5119761}, - FieldElement{-22205145, -2519528, -16381601, 414691, -25019550, 2170430, 30634760, -8363614, -31999993, -5759884}, - FieldElement{-6845704, 15791202, 8550074, -1312654, 29928809, -12092256, 27534430, -7192145, -22351378, 12961482}, - }, - { - FieldElement{-24492060, -9570771, 10368194, 11582341, -23397293, -2245287, 16533930, 8206996, -30194652, -5159638}, - FieldElement{-11121496, -3382234, 2307366, 6362031, -135455, 8868177, -16835630, 7031275, 7589640, 8945490}, - FieldElement{-32152748, 8917967, 6661220, -11677616, -1192060, -15793393, 7251489, -11182180, 24099109, -14456170}, - }, - { - FieldElement{5019558, -7907470, 4244127, -14714356, -26933272, 6453165, -19118182, -13289025, -6231896, -10280736}, - FieldElement{10853594, 10721687, 26480089, 5861829, -22995819, 1972175, -1866647, -10557898, -3363451, -6441124}, - FieldElement{-17002408, 5906790, 221599, -6563147, 7828208, -13248918, 24362661, -2008168, -13866408, 7421392}, - }, - { - FieldElement{8139927, -6546497, 32257646, -5890546, 30375719, 1886181, -21175108, 15441252, 28826358, -4123029}, - FieldElement{6267086, 9695052, 7709135, -16603597, -32869068, -1886135, 14795160, -7840124, 13746021, -1742048}, - FieldElement{28584902, 7787108, -6732942, -15050729, 22846041, -7571236, -3181936, -363524, 4771362, -8419958}, - }, - }, - { - { - FieldElement{24949256, 6376279, -27466481, -8174608, -18646154, -9930606, 33543569, -12141695, 3569627, 11342593}, - FieldElement{26514989, 4740088, 27912651, 3697550, 19331575, -11472339, 6809886, 4608608, 7325975, -14801071}, - FieldElement{-11618399, -14554430, -24321212, 7655128, -1369274, 5214312, -27400540, 10258390, -17646694, -8186692}, - }, - { - FieldElement{11431204, 15823007, 26570245, 14329124, 18029990, 4796082, -31446179, 15580664, 9280358, -3973687}, - FieldElement{-160783, -10326257, -22855316, -4304997, -20861367, -13621002, -32810901, -11181622, -15545091, 4387441}, - FieldElement{-20799378, 12194512, 3937617, -5805892, -27154820, 9340370, -24513992, 8548137, 20617071, -7482001}, - }, - { - FieldElement{-938825, -3930586, -8714311, 16124718, 24603125, -6225393, -13775352, -11875822, 24345683, 10325460}, - FieldElement{-19855277, -1568885, -22202708, 8714034, 14007766, 6928528, 16318175, -1010689, 4766743, 3552007}, - FieldElement{-21751364, -16730916, 1351763, -803421, -4009670, 3950935, 3217514, 14481909, 10988822, -3994762}, - }, - { - FieldElement{15564307, -14311570, 3101243, 5684148, 30446780, -8051356, 12677127, -6505343, -8295852, 13296005}, - FieldElement{-9442290, 6624296, -30298964, -11913677, -4670981, -2057379, 31521204, 9614054, -30000824, 12074674}, - FieldElement{4771191, -135239, 14290749, -13089852, 27992298, 14998318, -1413936, -1556716, 29832613, -16391035}, - }, - { - FieldElement{7064884, -7541174, -19161962, -5067537, -18891269, -2912736, 25825242, 5293297, -27122660, 13101590}, - FieldElement{-2298563, 2439670, -7466610, 1719965, -27267541, -16328445, 32512469, -5317593, -30356070, -4190957}, - FieldElement{-30006540, 10162316, -33180176, 3981723, -16482138, -13070044, 14413974, 9515896, 19568978, 9628812}, - }, - { - FieldElement{33053803, 199357, 15894591, 1583059, 27380243, -4580435, -17838894, -6106839, -6291786, 3437740}, - FieldElement{-18978877, 3884493, 19469877, 12726490, 15913552, 13614290, -22961733, 70104, 7463304, 4176122}, - FieldElement{-27124001, 10659917, 11482427, -16070381, 12771467, -6635117, -32719404, -5322751, 24216882, 5944158}, - }, - { - FieldElement{8894125, 7450974, -2664149, -9765752, -28080517, -12389115, 19345746, 14680796, 11632993, 5847885}, - FieldElement{26942781, -2315317, 9129564, -4906607, 26024105, 11769399, -11518837, 6367194, -9727230, 4782140}, - FieldElement{19916461, -4828410, -22910704, -11414391, 25606324, -5972441, 33253853, 8220911, 6358847, -1873857}, - }, - { - FieldElement{801428, -2081702, 16569428, 11065167, 29875704, 96627, 7908388, -4480480, -13538503, 1387155}, - FieldElement{19646058, 5720633, -11416706, 12814209, 11607948, 12749789, 14147075, 15156355, -21866831, 11835260}, - FieldElement{19299512, 1155910, 28703737, 14890794, 2925026, 7269399, 26121523, 15467869, -26560550, 5052483}, - }, - }, - { - { - FieldElement{-3017432, 10058206, 1980837, 3964243, 22160966, 12322533, -6431123, -12618185, 12228557, -7003677}, - FieldElement{32944382, 14922211, -22844894, 5188528, 21913450, -8719943, 4001465, 13238564, -6114803, 8653815}, - FieldElement{22865569, -4652735, 27603668, -12545395, 14348958, 8234005, 24808405, 5719875, 28483275, 2841751}, - }, - { - FieldElement{-16420968, -1113305, -327719, -12107856, 21886282, -15552774, -1887966, -315658, 19932058, -12739203}, - FieldElement{-11656086, 10087521, -8864888, -5536143, -19278573, -3055912, 3999228, 13239134, -4777469, -13910208}, - FieldElement{1382174, -11694719, 17266790, 9194690, -13324356, 9720081, 20403944, 11284705, -14013818, 3093230}, - }, - { - FieldElement{16650921, -11037932, -1064178, 1570629, -8329746, 7352753, -302424, 16271225, -24049421, -6691850}, - FieldElement{-21911077, -5927941, -4611316, -5560156, -31744103, -10785293, 24123614, 15193618, -21652117, -16739389}, - FieldElement{-9935934, -4289447, -25279823, 4372842, 2087473, 10399484, 31870908, 14690798, 17361620, 11864968}, - }, - { - FieldElement{-11307610, 6210372, 13206574, 5806320, -29017692, -13967200, -12331205, -7486601, -25578460, -16240689}, - FieldElement{14668462, -12270235, 26039039, 15305210, 25515617, 4542480, 10453892, 6577524, 9145645, -6443880}, - FieldElement{5974874, 3053895, -9433049, -10385191, -31865124, 3225009, -7972642, 3936128, -5652273, -3050304}, - }, - { - FieldElement{30625386, -4729400, -25555961, -12792866, -20484575, 7695099, 17097188, -16303496, -27999779, 1803632}, - FieldElement{-3553091, 9865099, -5228566, 4272701, -5673832, -16689700, 14911344, 12196514, -21405489, 7047412}, - FieldElement{20093277, 9920966, -11138194, -5343857, 13161587, 12044805, -32856851, 4124601, -32343828, -10257566}, - }, - { - FieldElement{-20788824, 14084654, -13531713, 7842147, 19119038, -13822605, 4752377, -8714640, -21679658, 2288038}, - FieldElement{-26819236, -3283715, 29965059, 3039786, -14473765, 2540457, 29457502, 14625692, -24819617, 12570232}, - FieldElement{-1063558, -11551823, 16920318, 12494842, 1278292, -5869109, -21159943, -3498680, -11974704, 4724943}, - }, - { - FieldElement{17960970, -11775534, -4140968, -9702530, -8876562, -1410617, -12907383, -8659932, -29576300, 1903856}, - FieldElement{23134274, -14279132, -10681997, -1611936, 20684485, 15770816, -12989750, 3190296, 26955097, 14109738}, - FieldElement{15308788, 5320727, -30113809, -14318877, 22902008, 7767164, 29425325, -11277562, 31960942, 11934971}, - }, - { - FieldElement{-27395711, 8435796, 4109644, 12222639, -24627868, 14818669, 20638173, 4875028, 10491392, 1379718}, - FieldElement{-13159415, 9197841, 3875503, -8936108, -1383712, -5879801, 33518459, 16176658, 21432314, 12180697}, - FieldElement{-11787308, 11500838, 13787581, -13832590, -22430679, 10140205, 1465425, 12689540, -10301319, -13872883}, - }, - }, - { - { - FieldElement{5414091, -15386041, -21007664, 9643570, 12834970, 1186149, -2622916, -1342231, 26128231, 6032912}, - FieldElement{-26337395, -13766162, 32496025, -13653919, 17847801, -12669156, 3604025, 8316894, -25875034, -10437358}, - FieldElement{3296484, 6223048, 24680646, -12246460, -23052020, 5903205, -8862297, -4639164, 12376617, 3188849}, - }, - { - FieldElement{29190488, -14659046, 27549113, -1183516, 3520066, -10697301, 32049515, -7309113, -16109234, -9852307}, - FieldElement{-14744486, -9309156, 735818, -598978, -20407687, -5057904, 25246078, -15795669, 18640741, -960977}, - FieldElement{-6928835, -16430795, 10361374, 5642961, 4910474, 12345252, -31638386, -494430, 10530747, 1053335}, - }, - { - FieldElement{-29265967, -14186805, -13538216, -12117373, -19457059, -10655384, -31462369, -2948985, 24018831, 15026644}, - FieldElement{-22592535, -3145277, -2289276, 5953843, -13440189, 9425631, 25310643, 13003497, -2314791, -15145616}, - FieldElement{-27419985, -603321, -8043984, -1669117, -26092265, 13987819, -27297622, 187899, -23166419, -2531735}, - }, - { - FieldElement{-21744398, -13810475, 1844840, 5021428, -10434399, -15911473, 9716667, 16266922, -5070217, 726099}, - FieldElement{29370922, -6053998, 7334071, -15342259, 9385287, 2247707, -13661962, -4839461, 30007388, -15823341}, - FieldElement{-936379, 16086691, 23751945, -543318, -1167538, -5189036, 9137109, 730663, 9835848, 4555336}, - }, - { - FieldElement{-23376435, 1410446, -22253753, -12899614, 30867635, 15826977, 17693930, 544696, -11985298, 12422646}, - FieldElement{31117226, -12215734, -13502838, 6561947, -9876867, -12757670, -5118685, -4096706, 29120153, 13924425}, - FieldElement{-17400879, -14233209, 19675799, -2734756, -11006962, -5858820, -9383939, -11317700, 7240931, -237388}, - }, - { - FieldElement{-31361739, -11346780, -15007447, -5856218, -22453340, -12152771, 1222336, 4389483, 3293637, -15551743}, - FieldElement{-16684801, -14444245, 11038544, 11054958, -13801175, -3338533, -24319580, 7733547, 12796905, -6335822}, - FieldElement{-8759414, -10817836, -25418864, 10783769, -30615557, -9746811, -28253339, 3647836, 3222231, -11160462}, - }, - { - FieldElement{18606113, 1693100, -25448386, -15170272, 4112353, 10045021, 23603893, -2048234, -7550776, 2484985}, - FieldElement{9255317, -3131197, -12156162, -1004256, 13098013, -9214866, 16377220, -2102812, -19802075, -3034702}, - FieldElement{-22729289, 7496160, -5742199, 11329249, 19991973, -3347502, -31718148, 9936966, -30097688, -10618797}, - }, - { - FieldElement{21878590, -5001297, 4338336, 13643897, -3036865, 13160960, 19708896, 5415497, -7360503, -4109293}, - FieldElement{27736861, 10103576, 12500508, 8502413, -3413016, -9633558, 10436918, -1550276, -23659143, -8132100}, - FieldElement{19492550, -12104365, -29681976, -852630, -3208171, 12403437, 30066266, 8367329, 13243957, 8709688}, - }, - }, - { - { - FieldElement{12015105, 2801261, 28198131, 10151021, 24818120, -4743133, -11194191, -5645734, 5150968, 7274186}, - FieldElement{2831366, -12492146, 1478975, 6122054, 23825128, -12733586, 31097299, 6083058, 31021603, -9793610}, - FieldElement{-2529932, -2229646, 445613, 10720828, -13849527, -11505937, -23507731, 16354465, 15067285, -14147707}, - }, - { - FieldElement{7840942, 14037873, -33364863, 15934016, -728213, -3642706, 21403988, 1057586, -19379462, -12403220}, - FieldElement{915865, -16469274, 15608285, -8789130, -24357026, 6060030, -17371319, 8410997, -7220461, 16527025}, - FieldElement{32922597, -556987, 20336074, -16184568, 10903705, -5384487, 16957574, 52992, 23834301, 6588044}, - }, - { - FieldElement{32752030, 11232950, 3381995, -8714866, 22652988, -10744103, 17159699, 16689107, -20314580, -1305992}, - FieldElement{-4689649, 9166776, -25710296, -10847306, 11576752, 12733943, 7924251, -2752281, 1976123, -7249027}, - FieldElement{21251222, 16309901, -2983015, -6783122, 30810597, 12967303, 156041, -3371252, 12331345, -8237197}, - }, - { - FieldElement{8651614, -4477032, -16085636, -4996994, 13002507, 2950805, 29054427, -5106970, 10008136, -4667901}, - FieldElement{31486080, 15114593, -14261250, 12951354, 14369431, -7387845, 16347321, -13662089, 8684155, -10532952}, - FieldElement{19443825, 11385320, 24468943, -9659068, -23919258, 2187569, -26263207, -6086921, 31316348, 14219878}, - }, - { - FieldElement{-28594490, 1193785, 32245219, 11392485, 31092169, 15722801, 27146014, 6992409, 29126555, 9207390}, - FieldElement{32382935, 1110093, 18477781, 11028262, -27411763, -7548111, -4980517, 10843782, -7957600, -14435730}, - FieldElement{2814918, 7836403, 27519878, -7868156, -20894015, -11553689, -21494559, 8550130, 28346258, 1994730}, - }, - { - FieldElement{-19578299, 8085545, -14000519, -3948622, 2785838, -16231307, -19516951, 7174894, 22628102, 8115180}, - FieldElement{-30405132, 955511, -11133838, -15078069, -32447087, -13278079, -25651578, 3317160, -9943017, 930272}, - FieldElement{-15303681, -6833769, 28856490, 1357446, 23421993, 1057177, 24091212, -1388970, -22765376, -10650715}, - }, - { - FieldElement{-22751231, -5303997, -12907607, -12768866, -15811511, -7797053, -14839018, -16554220, -1867018, 8398970}, - FieldElement{-31969310, 2106403, -4736360, 1362501, 12813763, 16200670, 22981545, -6291273, 18009408, -15772772}, - FieldElement{-17220923, -9545221, -27784654, 14166835, 29815394, 7444469, 29551787, -3727419, 19288549, 1325865}, - }, - { - FieldElement{15100157, -15835752, -23923978, -1005098, -26450192, 15509408, 12376730, -3479146, 33166107, -8042750}, - FieldElement{20909231, 13023121, -9209752, 16251778, -5778415, -8094914, 12412151, 10018715, 2213263, -13878373}, - FieldElement{32529814, -11074689, 30361439, -16689753, -9135940, 1513226, 22922121, 6382134, -5766928, 8371348}, - }, - }, - { - { - FieldElement{9923462, 11271500, 12616794, 3544722, -29998368, -1721626, 12891687, -8193132, -26442943, 10486144}, - FieldElement{-22597207, -7012665, 8587003, -8257861, 4084309, -12970062, 361726, 2610596, -23921530, -11455195}, - FieldElement{5408411, -1136691, -4969122, 10561668, 24145918, 14240566, 31319731, -4235541, 19985175, -3436086}, - }, - { - FieldElement{-13994457, 16616821, 14549246, 3341099, 32155958, 13648976, -17577068, 8849297, 65030, 8370684}, - FieldElement{-8320926, -12049626, 31204563, 5839400, -20627288, -1057277, -19442942, 6922164, 12743482, -9800518}, - FieldElement{-2361371, 12678785, 28815050, 4759974, -23893047, 4884717, 23783145, 11038569, 18800704, 255233}, - }, - { - FieldElement{-5269658, -1773886, 13957886, 7990715, 23132995, 728773, 13393847, 9066957, 19258688, -14753793}, - FieldElement{-2936654, -10827535, -10432089, 14516793, -3640786, 4372541, -31934921, 2209390, -1524053, 2055794}, - FieldElement{580882, 16705327, 5468415, -2683018, -30926419, -14696000, -7203346, -8994389, -30021019, 7394435}, - }, - { - FieldElement{23838809, 1822728, -15738443, 15242727, 8318092, -3733104, -21672180, -3492205, -4821741, 14799921}, - FieldElement{13345610, 9759151, 3371034, -16137791, 16353039, 8577942, 31129804, 13496856, -9056018, 7402518}, - FieldElement{2286874, -4435931, -20042458, -2008336, -13696227, 5038122, 11006906, -15760352, 8205061, 1607563}, - }, - { - FieldElement{14414086, -8002132, 3331830, -3208217, 22249151, -5594188, 18364661, -2906958, 30019587, -9029278}, - FieldElement{-27688051, 1585953, -10775053, 931069, -29120221, -11002319, -14410829, 12029093, 9944378, 8024}, - FieldElement{4368715, -3709630, 29874200, -15022983, -20230386, -11410704, -16114594, -999085, -8142388, 5640030}, - }, - { - FieldElement{10299610, 13746483, 11661824, 16234854, 7630238, 5998374, 9809887, -16694564, 15219798, -14327783}, - FieldElement{27425505, -5719081, 3055006, 10660664, 23458024, 595578, -15398605, -1173195, -18342183, 9742717}, - FieldElement{6744077, 2427284, 26042789, 2720740, -847906, 1118974, 32324614, 7406442, 12420155, 1994844}, - }, - { - FieldElement{14012521, -5024720, -18384453, -9578469, -26485342, -3936439, -13033478, -10909803, 24319929, -6446333}, - FieldElement{16412690, -4507367, 10772641, 15929391, -17068788, -4658621, 10555945, -10484049, -30102368, -4739048}, - FieldElement{22397382, -7767684, -9293161, -12792868, 17166287, -9755136, -27333065, 6199366, 21880021, -12250760}, - }, - { - FieldElement{-4283307, 5368523, -31117018, 8163389, -30323063, 3209128, 16557151, 8890729, 8840445, 4957760}, - FieldElement{-15447727, 709327, -6919446, -10870178, -29777922, 6522332, -21720181, 12130072, -14796503, 5005757}, - FieldElement{-2114751, -14308128, 23019042, 15765735, -25269683, 6002752, 10183197, -13239326, -16395286, -2176112}, - }, - }, - { - { - FieldElement{-19025756, 1632005, 13466291, -7995100, -23640451, 16573537, -32013908, -3057104, 22208662, 2000468}, - FieldElement{3065073, -1412761, -25598674, -361432, -17683065, -5703415, -8164212, 11248527, -3691214, -7414184}, - FieldElement{10379208, -6045554, 8877319, 1473647, -29291284, -12507580, 16690915, 2553332, -3132688, 16400289}, - }, - { - FieldElement{15716668, 1254266, -18472690, 7446274, -8448918, 6344164, -22097271, -7285580, 26894937, 9132066}, - FieldElement{24158887, 12938817, 11085297, -8177598, -28063478, -4457083, -30576463, 64452, -6817084, -2692882}, - FieldElement{13488534, 7794716, 22236231, 5989356, 25426474, -12578208, 2350710, -3418511, -4688006, 2364226}, - }, - { - FieldElement{16335052, 9132434, 25640582, 6678888, 1725628, 8517937, -11807024, -11697457, 15445875, -7798101}, - FieldElement{29004207, -7867081, 28661402, -640412, -12794003, -7943086, 31863255, -4135540, -278050, -15759279}, - FieldElement{-6122061, -14866665, -28614905, 14569919, -10857999, -3591829, 10343412, -6976290, -29828287, -10815811}, - }, - { - FieldElement{27081650, 3463984, 14099042, -4517604, 1616303, -6205604, 29542636, 15372179, 17293797, 960709}, - FieldElement{20263915, 11434237, -5765435, 11236810, 13505955, -10857102, -16111345, 6493122, -19384511, 7639714}, - FieldElement{-2830798, -14839232, 25403038, -8215196, -8317012, -16173699, 18006287, -16043750, 29994677, -15808121}, - }, - { - FieldElement{9769828, 5202651, -24157398, -13631392, -28051003, -11561624, -24613141, -13860782, -31184575, 709464}, - FieldElement{12286395, 13076066, -21775189, -1176622, -25003198, 4057652, -32018128, -8890874, 16102007, 13205847}, - FieldElement{13733362, 5599946, 10557076, 3195751, -5557991, 8536970, -25540170, 8525972, 10151379, 10394400}, - }, - { - FieldElement{4024660, -16137551, 22436262, 12276534, -9099015, -2686099, 19698229, 11743039, -33302334, 8934414}, - FieldElement{-15879800, -4525240, -8580747, -2934061, 14634845, -698278, -9449077, 3137094, -11536886, 11721158}, - FieldElement{17555939, -5013938, 8268606, 2331751, -22738815, 9761013, 9319229, 8835153, -9205489, -1280045}, - }, - { - FieldElement{-461409, -7830014, 20614118, 16688288, -7514766, -4807119, 22300304, 505429, 6108462, -6183415}, - FieldElement{-5070281, 12367917, -30663534, 3234473, 32617080, -8422642, 29880583, -13483331, -26898490, -7867459}, - FieldElement{-31975283, 5726539, 26934134, 10237677, -3173717, -605053, 24199304, 3795095, 7592688, -14992079}, - }, - { - FieldElement{21594432, -14964228, 17466408, -4077222, 32537084, 2739898, 6407723, 12018833, -28256052, 4298412}, - FieldElement{-20650503, -11961496, -27236275, 570498, 3767144, -1717540, 13891942, -1569194, 13717174, 10805743}, - FieldElement{-14676630, -15644296, 15287174, 11927123, 24177847, -8175568, -796431, 14860609, -26938930, -5863836}, - }, - }, - { - { - FieldElement{12962541, 5311799, -10060768, 11658280, 18855286, -7954201, 13286263, -12808704, -4381056, 9882022}, - FieldElement{18512079, 11319350, -20123124, 15090309, 18818594, 5271736, -22727904, 3666879, -23967430, -3299429}, - FieldElement{-6789020, -3146043, 16192429, 13241070, 15898607, -14206114, -10084880, -6661110, -2403099, 5276065}, - }, - { - FieldElement{30169808, -5317648, 26306206, -11750859, 27814964, 7069267, 7152851, 3684982, 1449224, 13082861}, - FieldElement{10342826, 3098505, 2119311, 193222, 25702612, 12233820, 23697382, 15056736, -21016438, -8202000}, - FieldElement{-33150110, 3261608, 22745853, 7948688, 19370557, -15177665, -26171976, 6482814, -10300080, -11060101}, - }, - { - FieldElement{32869458, -5408545, 25609743, 15678670, -10687769, -15471071, 26112421, 2521008, -22664288, 6904815}, - FieldElement{29506923, 4457497, 3377935, -9796444, -30510046, 12935080, 1561737, 3841096, -29003639, -6657642}, - FieldElement{10340844, -6630377, -18656632, -2278430, 12621151, -13339055, 30878497, -11824370, -25584551, 5181966}, - }, - { - FieldElement{25940115, -12658025, 17324188, -10307374, -8671468, 15029094, 24396252, -16450922, -2322852, -12388574}, - FieldElement{-21765684, 9916823, -1300409, 4079498, -1028346, 11909559, 1782390, 12641087, 20603771, -6561742}, - FieldElement{-18882287, -11673380, 24849422, 11501709, 13161720, -4768874, 1925523, 11914390, 4662781, 7820689}, - }, - { - FieldElement{12241050, -425982, 8132691, 9393934, 32846760, -1599620, 29749456, 12172924, 16136752, 15264020}, - FieldElement{-10349955, -14680563, -8211979, 2330220, -17662549, -14545780, 10658213, 6671822, 19012087, 3772772}, - FieldElement{3753511, -3421066, 10617074, 2028709, 14841030, -6721664, 28718732, -15762884, 20527771, 12988982}, - }, - { - FieldElement{-14822485, -5797269, -3707987, 12689773, -898983, -10914866, -24183046, -10564943, 3299665, -12424953}, - FieldElement{-16777703, -15253301, -9642417, 4978983, 3308785, 8755439, 6943197, 6461331, -25583147, 8991218}, - FieldElement{-17226263, 1816362, -1673288, -6086439, 31783888, -8175991, -32948145, 7417950, -30242287, 1507265}, - }, - { - FieldElement{29692663, 6829891, -10498800, 4334896, 20945975, -11906496, -28887608, 8209391, 14606362, -10647073}, - FieldElement{-3481570, 8707081, 32188102, 5672294, 22096700, 1711240, -33020695, 9761487, 4170404, -2085325}, - FieldElement{-11587470, 14855945, -4127778, -1531857, -26649089, 15084046, 22186522, 16002000, -14276837, -8400798}, - }, - { - FieldElement{-4811456, 13761029, -31703877, -2483919, -3312471, 7869047, -7113572, -9620092, 13240845, 10965870}, - FieldElement{-7742563, -8256762, -14768334, -13656260, -23232383, 12387166, 4498947, 14147411, 29514390, 4302863}, - FieldElement{-13413405, -12407859, 20757302, -13801832, 14785143, 8976368, -5061276, -2144373, 17846988, -13971927}, - }, - }, - { - { - FieldElement{-2244452, -754728, -4597030, -1066309, -6247172, 1455299, -21647728, -9214789, -5222701, 12650267}, - FieldElement{-9906797, -16070310, 21134160, 12198166, -27064575, 708126, 387813, 13770293, -19134326, 10958663}, - FieldElement{22470984, 12369526, 23446014, -5441109, -21520802, -9698723, -11772496, -11574455, -25083830, 4271862}, - }, - { - FieldElement{-25169565, -10053642, -19909332, 15361595, -5984358, 2159192, 75375, -4278529, -32526221, 8469673}, - FieldElement{15854970, 4148314, -8893890, 7259002, 11666551, 13824734, -30531198, 2697372, 24154791, -9460943}, - FieldElement{15446137, -15806644, 29759747, 14019369, 30811221, -9610191, -31582008, 12840104, 24913809, 9815020}, - }, - { - FieldElement{-4709286, -5614269, -31841498, -12288893, -14443537, 10799414, -9103676, 13438769, 18735128, 9466238}, - FieldElement{11933045, 9281483, 5081055, -5183824, -2628162, -4905629, -7727821, -10896103, -22728655, 16199064}, - FieldElement{14576810, 379472, -26786533, -8317236, -29426508, -10812974, -102766, 1876699, 30801119, 2164795}, - }, - { - FieldElement{15995086, 3199873, 13672555, 13712240, -19378835, -4647646, -13081610, -15496269, -13492807, 1268052}, - FieldElement{-10290614, -3659039, -3286592, 10948818, 23037027, 3794475, -3470338, -12600221, -17055369, 3565904}, - FieldElement{29210088, -9419337, -5919792, -4952785, 10834811, -13327726, -16512102, -10820713, -27162222, -14030531}, - }, - { - FieldElement{-13161890, 15508588, 16663704, -8156150, -28349942, 9019123, -29183421, -3769423, 2244111, -14001979}, - FieldElement{-5152875, -3800936, -9306475, -6071583, 16243069, 14684434, -25673088, -16180800, 13491506, 4641841}, - FieldElement{10813417, 643330, -19188515, -728916, 30292062, -16600078, 27548447, -7721242, 14476989, -12767431}, - }, - { - FieldElement{10292079, 9984945, 6481436, 8279905, -7251514, 7032743, 27282937, -1644259, -27912810, 12651324}, - FieldElement{-31185513, -813383, 22271204, 11835308, 10201545, 15351028, 17099662, 3988035, 21721536, -3148940}, - FieldElement{10202177, -6545839, -31373232, -9574638, -32150642, -8119683, -12906320, 3852694, 13216206, 14842320}, - }, - { - FieldElement{-15815640, -10601066, -6538952, -7258995, -6984659, -6581778, -31500847, 13765824, -27434397, 9900184}, - FieldElement{14465505, -13833331, -32133984, -14738873, -27443187, 12990492, 33046193, 15796406, -7051866, -8040114}, - FieldElement{30924417, -8279620, 6359016, -12816335, 16508377, 9071735, -25488601, 15413635, 9524356, -7018878}, - }, - { - FieldElement{12274201, -13175547, 32627641, -1785326, 6736625, 13267305, 5237659, -5109483, 15663516, 4035784}, - FieldElement{-2951309, 8903985, 17349946, 601635, -16432815, -4612556, -13732739, -15889334, -22258478, 4659091}, - FieldElement{-16916263, -4952973, -30393711, -15158821, 20774812, 15897498, 5736189, 15026997, -2178256, -13455585}, - }, - }, - { - { - FieldElement{-8858980, -2219056, 28571666, -10155518, -474467, -10105698, -3801496, 278095, 23440562, -290208}, - FieldElement{10226241, -5928702, 15139956, 120818, -14867693, 5218603, 32937275, 11551483, -16571960, -7442864}, - FieldElement{17932739, -12437276, -24039557, 10749060, 11316803, 7535897, 22503767, 5561594, -3646624, 3898661}, - }, - { - FieldElement{7749907, -969567, -16339731, -16464, -25018111, 15122143, -1573531, 7152530, 21831162, 1245233}, - FieldElement{26958459, -14658026, 4314586, 8346991, -5677764, 11960072, -32589295, -620035, -30402091, -16716212}, - FieldElement{-12165896, 9166947, 33491384, 13673479, 29787085, 13096535, 6280834, 14587357, -22338025, 13987525}, - }, - { - FieldElement{-24349909, 7778775, 21116000, 15572597, -4833266, -5357778, -4300898, -5124639, -7469781, -2858068}, - FieldElement{9681908, -6737123, -31951644, 13591838, -6883821, 386950, 31622781, 6439245, -14581012, 4091397}, - FieldElement{-8426427, 1470727, -28109679, -1596990, 3978627, -5123623, -19622683, 12092163, 29077877, -14741988}, - }, - { - FieldElement{5269168, -6859726, -13230211, -8020715, 25932563, 1763552, -5606110, -5505881, -20017847, 2357889}, - FieldElement{32264008, -15407652, -5387735, -1160093, -2091322, -3946900, 23104804, -12869908, 5727338, 189038}, - FieldElement{14609123, -8954470, -6000566, -16622781, -14577387, -7743898, -26745169, 10942115, -25888931, -14884697}, - }, - { - FieldElement{20513500, 5557931, -15604613, 7829531, 26413943, -2019404, -21378968, 7471781, 13913677, -5137875}, - FieldElement{-25574376, 11967826, 29233242, 12948236, -6754465, 4713227, -8940970, 14059180, 12878652, 8511905}, - FieldElement{-25656801, 3393631, -2955415, -7075526, -2250709, 9366908, -30223418, 6812974, 5568676, -3127656}, - }, - { - FieldElement{11630004, 12144454, 2116339, 13606037, 27378885, 15676917, -17408753, -13504373, -14395196, 8070818}, - FieldElement{27117696, -10007378, -31282771, -5570088, 1127282, 12772488, -29845906, 10483306, -11552749, -1028714}, - FieldElement{10637467, -5688064, 5674781, 1072708, -26343588, -6982302, -1683975, 9177853, -27493162, 15431203}, - }, - { - FieldElement{20525145, 10892566, -12742472, 12779443, -29493034, 16150075, -28240519, 14943142, -15056790, -7935931}, - FieldElement{-30024462, 5626926, -551567, -9981087, 753598, 11981191, 25244767, -3239766, -3356550, 9594024}, - FieldElement{-23752644, 2636870, -5163910, -10103818, 585134, 7877383, 11345683, -6492290, 13352335, -10977084}, - }, - { - FieldElement{-1931799, -5407458, 3304649, -12884869, 17015806, -4877091, -29783850, -7752482, -13215537, -319204}, - FieldElement{20239939, 6607058, 6203985, 3483793, -18386976, -779229, -20723742, 15077870, -22750759, 14523817}, - FieldElement{27406042, -6041657, 27423596, -4497394, 4996214, 10002360, -28842031, -4545494, -30172742, -4805667}, - }, - }, - { - { - FieldElement{11374242, 12660715, 17861383, -12540833, 10935568, 1099227, -13886076, -9091740, -27727044, 11358504}, - FieldElement{-12730809, 10311867, 1510375, 10778093, -2119455, -9145702, 32676003, 11149336, -26123651, 4985768}, - FieldElement{-19096303, 341147, -6197485, -239033, 15756973, -8796662, -983043, 13794114, -19414307, -15621255}, - }, - { - FieldElement{6490081, 11940286, 25495923, -7726360, 8668373, -8751316, 3367603, 6970005, -1691065, -9004790}, - FieldElement{1656497, 13457317, 15370807, 6364910, 13605745, 8362338, -19174622, -5475723, -16796596, -5031438}, - FieldElement{-22273315, -13524424, -64685, -4334223, -18605636, -10921968, -20571065, -7007978, -99853, -10237333}, - }, - { - FieldElement{17747465, 10039260, 19368299, -4050591, -20630635, -16041286, 31992683, -15857976, -29260363, -5511971}, - FieldElement{31932027, -4986141, -19612382, 16366580, 22023614, 88450, 11371999, -3744247, 4882242, -10626905}, - FieldElement{29796507, 37186, 19818052, 10115756, -11829032, 3352736, 18551198, 3272828, -5190932, -4162409}, - }, - { - FieldElement{12501286, 4044383, -8612957, -13392385, -32430052, 5136599, -19230378, -3529697, 330070, -3659409}, - FieldElement{6384877, 2899513, 17807477, 7663917, -2358888, 12363165, 25366522, -8573892, -271295, 12071499}, - FieldElement{-8365515, -4042521, 25133448, -4517355, -6211027, 2265927, -32769618, 1936675, -5159697, 3829363}, - }, - { - FieldElement{28425966, -5835433, -577090, -4697198, -14217555, 6870930, 7921550, -6567787, 26333140, 14267664}, - FieldElement{-11067219, 11871231, 27385719, -10559544, -4585914, -11189312, 10004786, -8709488, -21761224, 8930324}, - FieldElement{-21197785, -16396035, 25654216, -1725397, 12282012, 11008919, 1541940, 4757911, -26491501, -16408940}, - }, - { - FieldElement{13537262, -7759490, -20604840, 10961927, -5922820, -13218065, -13156584, 6217254, -15943699, 13814990}, - FieldElement{-17422573, 15157790, 18705543, 29619, 24409717, -260476, 27361681, 9257833, -1956526, -1776914}, - FieldElement{-25045300, -10191966, 15366585, 15166509, -13105086, 8423556, -29171540, 12361135, -18685978, 4578290}, - }, - { - FieldElement{24579768, 3711570, 1342322, -11180126, -27005135, 14124956, -22544529, 14074919, 21964432, 8235257}, - FieldElement{-6528613, -2411497, 9442966, -5925588, 12025640, -1487420, -2981514, -1669206, 13006806, 2355433}, - FieldElement{-16304899, -13605259, -6632427, -5142349, 16974359, -10911083, 27202044, 1719366, 1141648, -12796236}, - }, - { - FieldElement{-12863944, -13219986, -8318266, -11018091, -6810145, -4843894, 13475066, -3133972, 32674895, 13715045}, - FieldElement{11423335, -5468059, 32344216, 8962751, 24989809, 9241752, -13265253, 16086212, -28740881, -15642093}, - FieldElement{-1409668, 12530728, -6368726, 10847387, 19531186, -14132160, -11709148, 7791794, -27245943, 4383347}, - }, - }, - { - { - FieldElement{-28970898, 5271447, -1266009, -9736989, -12455236, 16732599, -4862407, -4906449, 27193557, 6245191}, - FieldElement{-15193956, 5362278, -1783893, 2695834, 4960227, 12840725, 23061898, 3260492, 22510453, 8577507}, - FieldElement{-12632451, 11257346, -32692994, 13548177, -721004, 10879011, 31168030, 13952092, -29571492, -3635906}, - }, - { - FieldElement{3877321, -9572739, 32416692, 5405324, -11004407, -13656635, 3759769, 11935320, 5611860, 8164018}, - FieldElement{-16275802, 14667797, 15906460, 12155291, -22111149, -9039718, 32003002, -8832289, 5773085, -8422109}, - FieldElement{-23788118, -8254300, 1950875, 8937633, 18686727, 16459170, -905725, 12376320, 31632953, 190926}, - }, - { - FieldElement{-24593607, -16138885, -8423991, 13378746, 14162407, 6901328, -8288749, 4508564, -25341555, -3627528}, - FieldElement{8884438, -5884009, 6023974, 10104341, -6881569, -4941533, 18722941, -14786005, -1672488, 827625}, - FieldElement{-32720583, -16289296, -32503547, 7101210, 13354605, 2659080, -1800575, -14108036, -24878478, 1541286}, - }, - { - FieldElement{2901347, -1117687, 3880376, -10059388, -17620940, -3612781, -21802117, -3567481, 20456845, -1885033}, - FieldElement{27019610, 12299467, -13658288, -1603234, -12861660, -4861471, -19540150, -5016058, 29439641, 15138866}, - FieldElement{21536104, -6626420, -32447818, -10690208, -22408077, 5175814, -5420040, -16361163, 7779328, 109896}, - }, - { - FieldElement{30279744, 14648750, -8044871, 6425558, 13639621, -743509, 28698390, 12180118, 23177719, -554075}, - FieldElement{26572847, 3405927, -31701700, 12890905, -19265668, 5335866, -6493768, 2378492, 4439158, -13279347}, - FieldElement{-22716706, 3489070, -9225266, -332753, 18875722, -1140095, 14819434, -12731527, -17717757, -5461437}, - }, - { - FieldElement{-5056483, 16566551, 15953661, 3767752, -10436499, 15627060, -820954, 2177225, 8550082, -15114165}, - FieldElement{-18473302, 16596775, -381660, 15663611, 22860960, 15585581, -27844109, -3582739, -23260460, -8428588}, - FieldElement{-32480551, 15707275, -8205912, -5652081, 29464558, 2713815, -22725137, 15860482, -21902570, 1494193}, - }, - { - FieldElement{-19562091, -14087393, -25583872, -9299552, 13127842, 759709, 21923482, 16529112, 8742704, 12967017}, - FieldElement{-28464899, 1553205, 32536856, -10473729, -24691605, -406174, -8914625, -2933896, -29903758, 15553883}, - FieldElement{21877909, 3230008, 9881174, 10539357, -4797115, 2841332, 11543572, 14513274, 19375923, -12647961}, - }, - { - FieldElement{8832269, -14495485, 13253511, 5137575, 5037871, 4078777, 24880818, -6222716, 2862653, 9455043}, - FieldElement{29306751, 5123106, 20245049, -14149889, 9592566, 8447059, -2077124, -2990080, 15511449, 4789663}, - FieldElement{-20679756, 7004547, 8824831, -9434977, -4045704, -3750736, -5754762, 108893, 23513200, 16652362}, - }, - }, - { - { - FieldElement{-33256173, 4144782, -4476029, -6579123, 10770039, -7155542, -6650416, -12936300, -18319198, 10212860}, - FieldElement{2756081, 8598110, 7383731, -6859892, 22312759, -1105012, 21179801, 2600940, -9988298, -12506466}, - FieldElement{-24645692, 13317462, -30449259, -15653928, 21365574, -10869657, 11344424, 864440, -2499677, -16710063}, - }, - { - FieldElement{-26432803, 6148329, -17184412, -14474154, 18782929, -275997, -22561534, 211300, 2719757, 4940997}, - FieldElement{-1323882, 3911313, -6948744, 14759765, -30027150, 7851207, 21690126, 8518463, 26699843, 5276295}, - FieldElement{-13149873, -6429067, 9396249, 365013, 24703301, -10488939, 1321586, 149635, -15452774, 7159369}, - }, - { - FieldElement{9987780, -3404759, 17507962, 9505530, 9731535, -2165514, 22356009, 8312176, 22477218, -8403385}, - FieldElement{18155857, -16504990, 19744716, 9006923, 15154154, -10538976, 24256460, -4864995, -22548173, 9334109}, - FieldElement{2986088, -4911893, 10776628, -3473844, 10620590, -7083203, -21413845, 14253545, -22587149, 536906}, - }, - { - FieldElement{4377756, 8115836, 24567078, 15495314, 11625074, 13064599, 7390551, 10589625, 10838060, -15420424}, - FieldElement{-19342404, 867880, 9277171, -3218459, -14431572, -1986443, 19295826, -15796950, 6378260, 699185}, - FieldElement{7895026, 4057113, -7081772, -13077756, -17886831, -323126, -716039, 15693155, -5045064, -13373962}, - }, - { - FieldElement{-7737563, -5869402, -14566319, -7406919, 11385654, 13201616, 31730678, -10962840, -3918636, -9669325}, - FieldElement{10188286, -15770834, -7336361, 13427543, 22223443, 14896287, 30743455, 7116568, -21786507, 5427593}, - FieldElement{696102, 13206899, 27047647, -10632082, 15285305, -9853179, 10798490, -4578720, 19236243, 12477404}, - }, - { - FieldElement{-11229439, 11243796, -17054270, -8040865, -788228, -8167967, -3897669, 11180504, -23169516, 7733644}, - FieldElement{17800790, -14036179, -27000429, -11766671, 23887827, 3149671, 23466177, -10538171, 10322027, 15313801}, - FieldElement{26246234, 11968874, 32263343, -5468728, 6830755, -13323031, -15794704, -101982, -24449242, 10890804}, - }, - { - FieldElement{-31365647, 10271363, -12660625, -6267268, 16690207, -13062544, -14982212, 16484931, 25180797, -5334884}, - FieldElement{-586574, 10376444, -32586414, -11286356, 19801893, 10997610, 2276632, 9482883, 316878, 13820577}, - FieldElement{-9882808, -4510367, -2115506, 16457136, -11100081, 11674996, 30756178, -7515054, 30696930, -3712849}, - }, - { - FieldElement{32988917, -9603412, 12499366, 7910787, -10617257, -11931514, -7342816, -9985397, -32349517, 7392473}, - FieldElement{-8855661, 15927861, 9866406, -3649411, -2396914, -16655781, -30409476, -9134995, 25112947, -2926644}, - FieldElement{-2504044, -436966, 25621774, -5678772, 15085042, -5479877, -24884878, -13526194, 5537438, -13914319}, - }, - }, - { - { - FieldElement{-11225584, 2320285, -9584280, 10149187, -33444663, 5808648, -14876251, -1729667, 31234590, 6090599}, - FieldElement{-9633316, 116426, 26083934, 2897444, -6364437, -2688086, 609721, 15878753, -6970405, -9034768}, - FieldElement{-27757857, 247744, -15194774, -9002551, 23288161, -10011936, -23869595, 6503646, 20650474, 1804084}, - }, - { - FieldElement{-27589786, 15456424, 8972517, 8469608, 15640622, 4439847, 3121995, -10329713, 27842616, -202328}, - FieldElement{-15306973, 2839644, 22530074, 10026331, 4602058, 5048462, 28248656, 5031932, -11375082, 12714369}, - FieldElement{20807691, -7270825, 29286141, 11421711, -27876523, -13868230, -21227475, 1035546, -19733229, 12796920}, - }, - { - FieldElement{12076899, -14301286, -8785001, -11848922, -25012791, 16400684, -17591495, -12899438, 3480665, -15182815}, - FieldElement{-32361549, 5457597, 28548107, 7833186, 7303070, -11953545, -24363064, -15921875, -33374054, 2771025}, - FieldElement{-21389266, 421932, 26597266, 6860826, 22486084, -6737172, -17137485, -4210226, -24552282, 15673397}, - }, - { - FieldElement{-20184622, 2338216, 19788685, -9620956, -4001265, -8740893, -20271184, 4733254, 3727144, -12934448}, - FieldElement{6120119, 814863, -11794402, -622716, 6812205, -15747771, 2019594, 7975683, 31123697, -10958981}, - FieldElement{30069250, -11435332, 30434654, 2958439, 18399564, -976289, 12296869, 9204260, -16432438, 9648165}, - }, - { - FieldElement{32705432, -1550977, 30705658, 7451065, -11805606, 9631813, 3305266, 5248604, -26008332, -11377501}, - FieldElement{17219865, 2375039, -31570947, -5575615, -19459679, 9219903, 294711, 15298639, 2662509, -16297073}, - FieldElement{-1172927, -7558695, -4366770, -4287744, -21346413, -8434326, 32087529, -1222777, 32247248, -14389861}, - }, - { - FieldElement{14312628, 1221556, 17395390, -8700143, -4945741, -8684635, -28197744, -9637817, -16027623, -13378845}, - FieldElement{-1428825, -9678990, -9235681, 6549687, -7383069, -468664, 23046502, 9803137, 17597934, 2346211}, - FieldElement{18510800, 15337574, 26171504, 981392, -22241552, 7827556, -23491134, -11323352, 3059833, -11782870}, - }, - { - FieldElement{10141598, 6082907, 17829293, -1947643, 9830092, 13613136, -25556636, -5544586, -33502212, 3592096}, - FieldElement{33114168, -15889352, -26525686, -13343397, 33076705, 8716171, 1151462, 1521897, -982665, -6837803}, - FieldElement{-32939165, -4255815, 23947181, -324178, -33072974, -12305637, -16637686, 3891704, 26353178, 693168}, - }, - { - FieldElement{30374239, 1595580, -16884039, 13186931, 4600344, 406904, 9585294, -400668, 31375464, 14369965}, - FieldElement{-14370654, -7772529, 1510301, 6434173, -18784789, -6262728, 32732230, -13108839, 17901441, 16011505}, - FieldElement{18171223, -11934626, -12500402, 15197122, -11038147, -15230035, -19172240, -16046376, 8764035, 12309598}, - }, - }, - { - { - FieldElement{5975908, -5243188, -19459362, -9681747, -11541277, 14015782, -23665757, 1228319, 17544096, -10593782}, - FieldElement{5811932, -1715293, 3442887, -2269310, -18367348, -8359541, -18044043, -15410127, -5565381, 12348900}, - FieldElement{-31399660, 11407555, 25755363, 6891399, -3256938, 14872274, -24849353, 8141295, -10632534, -585479}, - }, - { - FieldElement{-12675304, 694026, -5076145, 13300344, 14015258, -14451394, -9698672, -11329050, 30944593, 1130208}, - FieldElement{8247766, -6710942, -26562381, -7709309, -14401939, -14648910, 4652152, 2488540, 23550156, -271232}, - FieldElement{17294316, -3788438, 7026748, 15626851, 22990044, 113481, 2267737, -5908146, -408818, -137719}, - }, - { - FieldElement{16091085, -16253926, 18599252, 7340678, 2137637, -1221657, -3364161, 14550936, 3260525, -7166271}, - FieldElement{-4910104, -13332887, 18550887, 10864893, -16459325, -7291596, -23028869, -13204905, -12748722, 2701326}, - FieldElement{-8574695, 16099415, 4629974, -16340524, -20786213, -6005432, -10018363, 9276971, 11329923, 1862132}, - }, - { - FieldElement{14763076, -15903608, -30918270, 3689867, 3511892, 10313526, -21951088, 12219231, -9037963, -940300}, - FieldElement{8894987, -3446094, 6150753, 3013931, 301220, 15693451, -31981216, -2909717, -15438168, 11595570}, - FieldElement{15214962, 3537601, -26238722, -14058872, 4418657, -15230761, 13947276, 10730794, -13489462, -4363670}, - }, - { - FieldElement{-2538306, 7682793, 32759013, 263109, -29984731, -7955452, -22332124, -10188635, 977108, 699994}, - FieldElement{-12466472, 4195084, -9211532, 550904, -15565337, 12917920, 19118110, -439841, -30534533, -14337913}, - FieldElement{31788461, -14507657, 4799989, 7372237, 8808585, -14747943, 9408237, -10051775, 12493932, -5409317}, - }, - { - FieldElement{-25680606, 5260744, -19235809, -6284470, -3695942, 16566087, 27218280, 2607121, 29375955, 6024730}, - FieldElement{842132, -2794693, -4763381, -8722815, 26332018, -12405641, 11831880, 6985184, -9940361, 2854096}, - FieldElement{-4847262, -7969331, 2516242, -5847713, 9695691, -7221186, 16512645, 960770, 12121869, 16648078}, - }, - { - FieldElement{-15218652, 14667096, -13336229, 2013717, 30598287, -464137, -31504922, -7882064, 20237806, 2838411}, - FieldElement{-19288047, 4453152, 15298546, -16178388, 22115043, -15972604, 12544294, -13470457, 1068881, -12499905}, - FieldElement{-9558883, -16518835, 33238498, 13506958, 30505848, -1114596, -8486907, -2630053, 12521378, 4845654}, - }, - { - FieldElement{-28198521, 10744108, -2958380, 10199664, 7759311, -13088600, 3409348, -873400, -6482306, -12885870}, - FieldElement{-23561822, 6230156, -20382013, 10655314, -24040585, -11621172, 10477734, -1240216, -3113227, 13974498}, - FieldElement{12966261, 15550616, -32038948, -1615346, 21025980, -629444, 5642325, 7188737, 18895762, 12629579}, - }, - }, - { - { - FieldElement{14741879, -14946887, 22177208, -11721237, 1279741, 8058600, 11758140, 789443, 32195181, 3895677}, - FieldElement{10758205, 15755439, -4509950, 9243698, -4879422, 6879879, -2204575, -3566119, -8982069, 4429647}, - FieldElement{-2453894, 15725973, -20436342, -10410672, -5803908, -11040220, -7135870, -11642895, 18047436, -15281743}, - }, - { - FieldElement{-25173001, -11307165, 29759956, 11776784, -22262383, -15820455, 10993114, -12850837, -17620701, -9408468}, - FieldElement{21987233, 700364, -24505048, 14972008, -7774265, -5718395, 32155026, 2581431, -29958985, 8773375}, - FieldElement{-25568350, 454463, -13211935, 16126715, 25240068, 8594567, 20656846, 12017935, -7874389, -13920155}, - }, - { - FieldElement{6028182, 6263078, -31011806, -11301710, -818919, 2461772, -31841174, -5468042, -1721788, -2776725}, - FieldElement{-12278994, 16624277, 987579, -5922598, 32908203, 1248608, 7719845, -4166698, 28408820, 6816612}, - FieldElement{-10358094, -8237829, 19549651, -12169222, 22082623, 16147817, 20613181, 13982702, -10339570, 5067943}, - }, - { - FieldElement{-30505967, -3821767, 12074681, 13582412, -19877972, 2443951, -19719286, 12746132, 5331210, -10105944}, - FieldElement{30528811, 3601899, -1957090, 4619785, -27361822, -15436388, 24180793, -12570394, 27679908, -1648928}, - FieldElement{9402404, -13957065, 32834043, 10838634, -26580150, -13237195, 26653274, -8685565, 22611444, -12715406}, - }, - { - FieldElement{22190590, 1118029, 22736441, 15130463, -30460692, -5991321, 19189625, -4648942, 4854859, 6622139}, - FieldElement{-8310738, -2953450, -8262579, -3388049, -10401731, -271929, 13424426, -3567227, 26404409, 13001963}, - FieldElement{-31241838, -15415700, -2994250, 8939346, 11562230, -12840670, -26064365, -11621720, -15405155, 11020693}, - }, - { - FieldElement{1866042, -7949489, -7898649, -10301010, 12483315, 13477547, 3175636, -12424163, 28761762, 1406734}, - FieldElement{-448555, -1777666, 13018551, 3194501, -9580420, -11161737, 24760585, -4347088, 25577411, -13378680}, - FieldElement{-24290378, 4759345, -690653, -1852816, 2066747, 10693769, -29595790, 9884936, -9368926, 4745410}, - }, - { - FieldElement{-9141284, 6049714, -19531061, -4341411, -31260798, 9944276, -15462008, -11311852, 10931924, -11931931}, - FieldElement{-16561513, 14112680, -8012645, 4817318, -8040464, -11414606, -22853429, 10856641, -20470770, 13434654}, - FieldElement{22759489, -10073434, -16766264, -1871422, 13637442, -10168091, 1765144, -12654326, 28445307, -5364710}, - }, - { - FieldElement{29875063, 12493613, 2795536, -3786330, 1710620, 15181182, -10195717, -8788675, 9074234, 1167180}, - FieldElement{-26205683, 11014233, -9842651, -2635485, -26908120, 7532294, -18716888, -9535498, 3843903, 9367684}, - FieldElement{-10969595, -6403711, 9591134, 9582310, 11349256, 108879, 16235123, 8601684, -139197, 4242895}, - }, - }, - { - { - FieldElement{22092954, -13191123, -2042793, -11968512, 32186753, -11517388, -6574341, 2470660, -27417366, 16625501}, - FieldElement{-11057722, 3042016, 13770083, -9257922, 584236, -544855, -7770857, 2602725, -27351616, 14247413}, - FieldElement{6314175, -10264892, -32772502, 15957557, -10157730, 168750, -8618807, 14290061, 27108877, -1180880}, - }, - { - FieldElement{-8586597, -7170966, 13241782, 10960156, -32991015, -13794596, 33547976, -11058889, -27148451, 981874}, - FieldElement{22833440, 9293594, -32649448, -13618667, -9136966, 14756819, -22928859, -13970780, -10479804, -16197962}, - FieldElement{-7768587, 3326786, -28111797, 10783824, 19178761, 14905060, 22680049, 13906969, -15933690, 3797899}, - }, - { - FieldElement{21721356, -4212746, -12206123, 9310182, -3882239, -13653110, 23740224, -2709232, 20491983, -8042152}, - FieldElement{9209270, -15135055, -13256557, -6167798, -731016, 15289673, 25947805, 15286587, 30997318, -6703063}, - FieldElement{7392032, 16618386, 23946583, -8039892, -13265164, -1533858, -14197445, -2321576, 17649998, -250080}, - }, - { - FieldElement{-9301088, -14193827, 30609526, -3049543, -25175069, -1283752, -15241566, -9525724, -2233253, 7662146}, - FieldElement{-17558673, 1763594, -33114336, 15908610, -30040870, -12174295, 7335080, -8472199, -3174674, 3440183}, - FieldElement{-19889700, -5977008, -24111293, -9688870, 10799743, -16571957, 40450, -4431835, 4862400, 1133}, - }, - { - FieldElement{-32856209, -7873957, -5422389, 14860950, -16319031, 7956142, 7258061, 311861, -30594991, -7379421}, - FieldElement{-3773428, -1565936, 28985340, 7499440, 24445838, 9325937, 29727763, 16527196, 18278453, 15405622}, - FieldElement{-4381906, 8508652, -19898366, -3674424, -5984453, 15149970, -13313598, 843523, -21875062, 13626197}, - }, - { - FieldElement{2281448, -13487055, -10915418, -2609910, 1879358, 16164207, -10783882, 3953792, 13340839, 15928663}, - FieldElement{31727126, -7179855, -18437503, -8283652, 2875793, -16390330, -25269894, -7014826, -23452306, 5964753}, - FieldElement{4100420, -5959452, -17179337, 6017714, -18705837, 12227141, -26684835, 11344144, 2538215, -7570755}, - }, - { - FieldElement{-9433605, 6123113, 11159803, -2156608, 30016280, 14966241, -20474983, 1485421, -629256, -15958862}, - FieldElement{-26804558, 4260919, 11851389, 9658551, -32017107, 16367492, -20205425, -13191288, 11659922, -11115118}, - FieldElement{26180396, 10015009, -30844224, -8581293, 5418197, 9480663, 2231568, -10170080, 33100372, -1306171}, - }, - { - FieldElement{15121113, -5201871, -10389905, 15427821, -27509937, -15992507, 21670947, 4486675, -5931810, -14466380}, - FieldElement{16166486, -9483733, -11104130, 6023908, -31926798, -1364923, 2340060, -16254968, -10735770, -10039824}, - FieldElement{28042865, -3557089, -12126526, 12259706, -3717498, -6945899, 6766453, -8689599, 18036436, 5803270}, - }, - }, - { - { - FieldElement{-817581, 6763912, 11803561, 1585585, 10958447, -2671165, 23855391, 4598332, -6159431, -14117438}, - FieldElement{-31031306, -14256194, 17332029, -2383520, 31312682, -5967183, 696309, 50292, -20095739, 11763584}, - FieldElement{-594563, -2514283, -32234153, 12643980, 12650761, 14811489, 665117, -12613632, -19773211, -10713562}, - }, - { - FieldElement{30464590, -11262872, -4127476, -12734478, 19835327, -7105613, -24396175, 2075773, -17020157, 992471}, - FieldElement{18357185, -6994433, 7766382, 16342475, -29324918, 411174, 14578841, 8080033, -11574335, -10601610}, - FieldElement{19598397, 10334610, 12555054, 2555664, 18821899, -10339780, 21873263, 16014234, 26224780, 16452269}, - }, - { - FieldElement{-30223925, 5145196, 5944548, 16385966, 3976735, 2009897, -11377804, -7618186, -20533829, 3698650}, - FieldElement{14187449, 3448569, -10636236, -10810935, -22663880, -3433596, 7268410, -10890444, 27394301, 12015369}, - FieldElement{19695761, 16087646, 28032085, 12999827, 6817792, 11427614, 20244189, -1312777, -13259127, -3402461}, - }, - { - FieldElement{30860103, 12735208, -1888245, -4699734, -16974906, 2256940, -8166013, 12298312, -8550524, -10393462}, - FieldElement{-5719826, -11245325, -1910649, 15569035, 26642876, -7587760, -5789354, -15118654, -4976164, 12651793}, - FieldElement{-2848395, 9953421, 11531313, -5282879, 26895123, -12697089, -13118820, -16517902, 9768698, -2533218}, - }, - { - FieldElement{-24719459, 1894651, -287698, -4704085, 15348719, -8156530, 32767513, 12765450, 4940095, 10678226}, - FieldElement{18860224, 15980149, -18987240, -1562570, -26233012, -11071856, -7843882, 13944024, -24372348, 16582019}, - FieldElement{-15504260, 4970268, -29893044, 4175593, -20993212, -2199756, -11704054, 15444560, -11003761, 7989037}, - }, - { - FieldElement{31490452, 5568061, -2412803, 2182383, -32336847, 4531686, -32078269, 6200206, -19686113, -14800171}, - FieldElement{-17308668, -15879940, -31522777, -2831, -32887382, 16375549, 8680158, -16371713, 28550068, -6857132}, - FieldElement{-28126887, -5688091, 16837845, -1820458, -6850681, 12700016, -30039981, 4364038, 1155602, 5988841}, - }, - { - FieldElement{21890435, -13272907, -12624011, 12154349, -7831873, 15300496, 23148983, -4470481, 24618407, 8283181}, - FieldElement{-33136107, -10512751, 9975416, 6841041, -31559793, 16356536, 3070187, -7025928, 1466169, 10740210}, - FieldElement{-1509399, -15488185, -13503385, -10655916, 32799044, 909394, -13938903, -5779719, -32164649, -15327040}, - }, - { - FieldElement{3960823, -14267803, -28026090, -15918051, -19404858, 13146868, 15567327, 951507, -3260321, -573935}, - FieldElement{24740841, 5052253, -30094131, 8961361, 25877428, 6165135, -24368180, 14397372, -7380369, -6144105}, - FieldElement{-28888365, 3510803, -28103278, -1158478, -11238128, -10631454, -15441463, -14453128, -1625486, -6494814}, - }, - }, - { - { - FieldElement{793299, -9230478, 8836302, -6235707, -27360908, -2369593, 33152843, -4885251, -9906200, -621852}, - FieldElement{5666233, 525582, 20782575, -8038419, -24538499, 14657740, 16099374, 1468826, -6171428, -15186581}, - FieldElement{-4859255, -3779343, -2917758, -6748019, 7778750, 11688288, -30404353, -9871238, -1558923, -9863646}, - }, - { - FieldElement{10896332, -7719704, 824275, 472601, -19460308, 3009587, 25248958, 14783338, -30581476, -15757844}, - FieldElement{10566929, 12612572, -31944212, 11118703, -12633376, 12362879, 21752402, 8822496, 24003793, 14264025}, - FieldElement{27713862, -7355973, -11008240, 9227530, 27050101, 2504721, 23886875, -13117525, 13958495, -5732453}, - }, - { - FieldElement{-23481610, 4867226, -27247128, 3900521, 29838369, -8212291, -31889399, -10041781, 7340521, -15410068}, - FieldElement{4646514, -8011124, -22766023, -11532654, 23184553, 8566613, 31366726, -1381061, -15066784, -10375192}, - FieldElement{-17270517, 12723032, -16993061, 14878794, 21619651, -6197576, 27584817, 3093888, -8843694, 3849921}, - }, - { - FieldElement{-9064912, 2103172, 25561640, -15125738, -5239824, 9582958, 32477045, -9017955, 5002294, -15550259}, - FieldElement{-12057553, -11177906, 21115585, -13365155, 8808712, -12030708, 16489530, 13378448, -25845716, 12741426}, - FieldElement{-5946367, 10645103, -30911586, 15390284, -3286982, -7118677, 24306472, 15852464, 28834118, -7646072}, - }, - { - FieldElement{-17335748, -9107057, -24531279, 9434953, -8472084, -583362, -13090771, 455841, 20461858, 5491305}, - FieldElement{13669248, -16095482, -12481974, -10203039, -14569770, -11893198, -24995986, 11293807, -28588204, -9421832}, - FieldElement{28497928, 6272777, -33022994, 14470570, 8906179, -1225630, 18504674, -14165166, 29867745, -8795943}, - }, - { - FieldElement{-16207023, 13517196, -27799630, -13697798, 24009064, -6373891, -6367600, -13175392, 22853429, -4012011}, - FieldElement{24191378, 16712145, -13931797, 15217831, 14542237, 1646131, 18603514, -11037887, 12876623, -2112447}, - FieldElement{17902668, 4518229, -411702, -2829247, 26878217, 5258055, -12860753, 608397, 16031844, 3723494}, - }, - { - FieldElement{-28632773, 12763728, -20446446, 7577504, 33001348, -13017745, 17558842, -7872890, 23896954, -4314245}, - FieldElement{-20005381, -12011952, 31520464, 605201, 2543521, 5991821, -2945064, 7229064, -9919646, -8826859}, - FieldElement{28816045, 298879, -28165016, -15920938, 19000928, -1665890, -12680833, -2949325, -18051778, -2082915}, - }, - { - FieldElement{16000882, -344896, 3493092, -11447198, -29504595, -13159789, 12577740, 16041268, -19715240, 7847707}, - FieldElement{10151868, 10572098, 27312476, 7922682, 14825339, 4723128, -32855931, -6519018, -10020567, 3852848}, - FieldElement{-11430470, 15697596, -21121557, -4420647, 5386314, 15063598, 16514493, -15932110, 29330899, -15076224}, - }, - }, - { - { - FieldElement{-25499735, -4378794, -15222908, -6901211, 16615731, 2051784, 3303702, 15490, -27548796, 12314391}, - FieldElement{15683520, -6003043, 18109120, -9980648, 15337968, -5997823, -16717435, 15921866, 16103996, -3731215}, - FieldElement{-23169824, -10781249, 13588192, -1628807, -3798557, -1074929, -19273607, 5402699, -29815713, -9841101}, - }, - { - FieldElement{23190676, 2384583, -32714340, 3462154, -29903655, -1529132, -11266856, 8911517, -25205859, 2739713}, - FieldElement{21374101, -3554250, -33524649, 9874411, 15377179, 11831242, -33529904, 6134907, 4931255, 11987849}, - FieldElement{-7732, -2978858, -16223486, 7277597, 105524, -322051, -31480539, 13861388, -30076310, 10117930}, - }, - { - FieldElement{-29501170, -10744872, -26163768, 13051539, -25625564, 5089643, -6325503, 6704079, 12890019, 15728940}, - FieldElement{-21972360, -11771379, -951059, -4418840, 14704840, 2695116, 903376, -10428139, 12885167, 8311031}, - FieldElement{-17516482, 5352194, 10384213, -13811658, 7506451, 13453191, 26423267, 4384730, 1888765, -5435404}, - }, - { - FieldElement{-25817338, -3107312, -13494599, -3182506, 30896459, -13921729, -32251644, -12707869, -19464434, -3340243}, - FieldElement{-23607977, -2665774, -526091, 4651136, 5765089, 4618330, 6092245, 14845197, 17151279, -9854116}, - FieldElement{-24830458, -12733720, -15165978, 10367250, -29530908, -265356, 22825805, -7087279, -16866484, 16176525}, - }, - { - FieldElement{-23583256, 6564961, 20063689, 3798228, -4740178, 7359225, 2006182, -10363426, -28746253, -10197509}, - FieldElement{-10626600, -4486402, -13320562, -5125317, 3432136, -6393229, 23632037, -1940610, 32808310, 1099883}, - FieldElement{15030977, 5768825, -27451236, -2887299, -6427378, -15361371, -15277896, -6809350, 2051441, -15225865}, - }, - { - FieldElement{-3362323, -7239372, 7517890, 9824992, 23555850, 295369, 5148398, -14154188, -22686354, 16633660}, - FieldElement{4577086, -16752288, 13249841, -15304328, 19958763, -14537274, 18559670, -10759549, 8402478, -9864273}, - FieldElement{-28406330, -1051581, -26790155, -907698, -17212414, -11030789, 9453451, -14980072, 17983010, 9967138}, - }, - { - FieldElement{-25762494, 6524722, 26585488, 9969270, 24709298, 1220360, -1677990, 7806337, 17507396, 3651560}, - FieldElement{-10420457, -4118111, 14584639, 15971087, -15768321, 8861010, 26556809, -5574557, -18553322, -11357135}, - FieldElement{2839101, 14284142, 4029895, 3472686, 14402957, 12689363, -26642121, 8459447, -5605463, -7621941}, - }, - { - FieldElement{-4839289, -3535444, 9744961, 2871048, 25113978, 3187018, -25110813, -849066, 17258084, -7977739}, - FieldElement{18164541, -10595176, -17154882, -1542417, 19237078, -9745295, 23357533, -15217008, 26908270, 12150756}, - FieldElement{-30264870, -7647865, 5112249, -7036672, -1499807, -6974257, 43168, -5537701, -32302074, 16215819}, - }, - }, - { - { - FieldElement{-6898905, 9824394, -12304779, -4401089, -31397141, -6276835, 32574489, 12532905, -7503072, -8675347}, - FieldElement{-27343522, -16515468, -27151524, -10722951, 946346, 16291093, 254968, 7168080, 21676107, -1943028}, - FieldElement{21260961, -8424752, -16831886, -11920822, -23677961, 3968121, -3651949, -6215466, -3556191, -7913075}, - }, - { - FieldElement{16544754, 13250366, -16804428, 15546242, -4583003, 12757258, -2462308, -8680336, -18907032, -9662799}, - FieldElement{-2415239, -15577728, 18312303, 4964443, -15272530, -12653564, 26820651, 16690659, 25459437, -4564609}, - FieldElement{-25144690, 11425020, 28423002, -11020557, -6144921, -15826224, 9142795, -2391602, -6432418, -1644817}, - }, - { - FieldElement{-23104652, 6253476, 16964147, -3768872, -25113972, -12296437, -27457225, -16344658, 6335692, 7249989}, - FieldElement{-30333227, 13979675, 7503222, -12368314, -11956721, -4621693, -30272269, 2682242, 25993170, -12478523}, - FieldElement{4364628, 5930691, 32304656, -10044554, -8054781, 15091131, 22857016, -10598955, 31820368, 15075278}, - }, - { - FieldElement{31879134, -8918693, 17258761, 90626, -8041836, -4917709, 24162788, -9650886, -17970238, 12833045}, - FieldElement{19073683, 14851414, -24403169, -11860168, 7625278, 11091125, -19619190, 2074449, -9413939, 14905377}, - FieldElement{24483667, -11935567, -2518866, -11547418, -1553130, 15355506, -25282080, 9253129, 27628530, -7555480}, - }, - { - FieldElement{17597607, 8340603, 19355617, 552187, 26198470, -3176583, 4593324, -9157582, -14110875, 15297016}, - FieldElement{510886, 14337390, -31785257, 16638632, 6328095, 2713355, -20217417, -11864220, 8683221, 2921426}, - FieldElement{18606791, 11874196, 27155355, -5281482, -24031742, 6265446, -25178240, -1278924, 4674690, 13890525}, - }, - { - FieldElement{13609624, 13069022, -27372361, -13055908, 24360586, 9592974, 14977157, 9835105, 4389687, 288396}, - FieldElement{9922506, -519394, 13613107, 5883594, -18758345, -434263, -12304062, 8317628, 23388070, 16052080}, - FieldElement{12720016, 11937594, -31970060, -5028689, 26900120, 8561328, -20155687, -11632979, -14754271, -10812892}, - }, - { - FieldElement{15961858, 14150409, 26716931, -665832, -22794328, 13603569, 11829573, 7467844, -28822128, 929275}, - FieldElement{11038231, -11582396, -27310482, -7316562, -10498527, -16307831, -23479533, -9371869, -21393143, 2465074}, - FieldElement{20017163, -4323226, 27915242, 1529148, 12396362, 15675764, 13817261, -9658066, 2463391, -4622140}, - }, - { - FieldElement{-16358878, -12663911, -12065183, 4996454, -1256422, 1073572, 9583558, 12851107, 4003896, 12673717}, - FieldElement{-1731589, -15155870, -3262930, 16143082, 19294135, 13385325, 14741514, -9103726, 7903886, 2348101}, - FieldElement{24536016, -16515207, 12715592, -3862155, 1511293, 10047386, -3842346, -7129159, -28377538, 10048127}, - }, - }, - { - { - FieldElement{-12622226, -6204820, 30718825, 2591312, -10617028, 12192840, 18873298, -7297090, -32297756, 15221632}, - FieldElement{-26478122, -11103864, 11546244, -1852483, 9180880, 7656409, -21343950, 2095755, 29769758, 6593415}, - FieldElement{-31994208, -2907461, 4176912, 3264766, 12538965, -868111, 26312345, -6118678, 30958054, 8292160}, - }, - { - FieldElement{31429822, -13959116, 29173532, 15632448, 12174511, -2760094, 32808831, 3977186, 26143136, -3148876}, - FieldElement{22648901, 1402143, -22799984, 13746059, 7936347, 365344, -8668633, -1674433, -3758243, -2304625}, - FieldElement{-15491917, 8012313, -2514730, -12702462, -23965846, -10254029, -1612713, -1535569, -16664475, 8194478}, - }, - { - FieldElement{27338066, -7507420, -7414224, 10140405, -19026427, -6589889, 27277191, 8855376, 28572286, 3005164}, - FieldElement{26287124, 4821776, 25476601, -4145903, -3764513, -15788984, -18008582, 1182479, -26094821, -13079595}, - FieldElement{-7171154, 3178080, 23970071, 6201893, -17195577, -4489192, -21876275, -13982627, 32208683, -1198248}, - }, - { - FieldElement{-16657702, 2817643, -10286362, 14811298, 6024667, 13349505, -27315504, -10497842, -27672585, -11539858}, - FieldElement{15941029, -9405932, -21367050, 8062055, 31876073, -238629, -15278393, -1444429, 15397331, -4130193}, - FieldElement{8934485, -13485467, -23286397, -13423241, -32446090, 14047986, 31170398, -1441021, -27505566, 15087184}, - }, - { - FieldElement{-18357243, -2156491, 24524913, -16677868, 15520427, -6360776, -15502406, 11461896, 16788528, -5868942}, - FieldElement{-1947386, 16013773, 21750665, 3714552, -17401782, -16055433, -3770287, -10323320, 31322514, -11615635}, - FieldElement{21426655, -5650218, -13648287, -5347537, -28812189, -4920970, -18275391, -14621414, 13040862, -12112948}, - }, - { - FieldElement{11293895, 12478086, -27136401, 15083750, -29307421, 14748872, 14555558, -13417103, 1613711, 4896935}, - FieldElement{-25894883, 15323294, -8489791, -8057900, 25967126, -13425460, 2825960, -4897045, -23971776, -11267415}, - FieldElement{-15924766, -5229880, -17443532, 6410664, 3622847, 10243618, 20615400, 12405433, -23753030, -8436416}, - }, - { - FieldElement{-7091295, 12556208, -20191352, 9025187, -17072479, 4333801, 4378436, 2432030, 23097949, -566018}, - FieldElement{4565804, -16025654, 20084412, -7842817, 1724999, 189254, 24767264, 10103221, -18512313, 2424778}, - FieldElement{366633, -11976806, 8173090, -6890119, 30788634, 5745705, -7168678, 1344109, -3642553, 12412659}, - }, - { - FieldElement{-24001791, 7690286, 14929416, -168257, -32210835, -13412986, 24162697, -15326504, -3141501, 11179385}, - FieldElement{18289522, -14724954, 8056945, 16430056, -21729724, 7842514, -6001441, -1486897, -18684645, -11443503}, - FieldElement{476239, 6601091, -6152790, -9723375, 17503545, -4863900, 27672959, 13403813, 11052904, 5219329}, - }, - }, - { - { - FieldElement{20678546, -8375738, -32671898, 8849123, -5009758, 14574752, 31186971, -3973730, 9014762, -8579056}, - FieldElement{-13644050, -10350239, -15962508, 5075808, -1514661, -11534600, -33102500, 9160280, 8473550, -3256838}, - FieldElement{24900749, 14435722, 17209120, -15292541, -22592275, 9878983, -7689309, -16335821, -24568481, 11788948}, - }, - { - FieldElement{-3118155, -11395194, -13802089, 14797441, 9652448, -6845904, -20037437, 10410733, -24568470, -1458691}, - FieldElement{-15659161, 16736706, -22467150, 10215878, -9097177, 7563911, 11871841, -12505194, -18513325, 8464118}, - FieldElement{-23400612, 8348507, -14585951, -861714, -3950205, -6373419, 14325289, 8628612, 33313881, -8370517}, - }, - { - FieldElement{-20186973, -4967935, 22367356, 5271547, -1097117, -4788838, -24805667, -10236854, -8940735, -5818269}, - FieldElement{-6948785, -1795212, -32625683, -16021179, 32635414, -7374245, 15989197, -12838188, 28358192, -4253904}, - FieldElement{-23561781, -2799059, -32351682, -1661963, -9147719, 10429267, -16637684, 4072016, -5351664, 5596589}, - }, - { - FieldElement{-28236598, -3390048, 12312896, 6213178, 3117142, 16078565, 29266239, 2557221, 1768301, 15373193}, - FieldElement{-7243358, -3246960, -4593467, -7553353, -127927, -912245, -1090902, -4504991, -24660491, 3442910}, - FieldElement{-30210571, 5124043, 14181784, 8197961, 18964734, -11939093, 22597931, 7176455, -18585478, 13365930}, - }, - { - FieldElement{-7877390, -1499958, 8324673, 4690079, 6261860, 890446, 24538107, -8570186, -9689599, -3031667}, - FieldElement{25008904, -10771599, -4305031, -9638010, 16265036, 15721635, 683793, -11823784, 15723479, -15163481}, - FieldElement{-9660625, 12374379, -27006999, -7026148, -7724114, -12314514, 11879682, 5400171, 519526, -1235876}, - }, - { - FieldElement{22258397, -16332233, -7869817, 14613016, -22520255, -2950923, -20353881, 7315967, 16648397, 7605640}, - FieldElement{-8081308, -8464597, -8223311, 9719710, 19259459, -15348212, 23994942, -5281555, -9468848, 4763278}, - FieldElement{-21699244, 9220969, -15730624, 1084137, -25476107, -2852390, 31088447, -7764523, -11356529, 728112}, - }, - { - FieldElement{26047220, -11751471, -6900323, -16521798, 24092068, 9158119, -4273545, -12555558, -29365436, -5498272}, - FieldElement{17510331, -322857, 5854289, 8403524, 17133918, -3112612, -28111007, 12327945, 10750447, 10014012}, - FieldElement{-10312768, 3936952, 9156313, -8897683, 16498692, -994647, -27481051, -666732, 3424691, 7540221}, - }, - { - FieldElement{30322361, -6964110, 11361005, -4143317, 7433304, 4989748, -7071422, -16317219, -9244265, 15258046}, - FieldElement{13054562, -2779497, 19155474, 469045, -12482797, 4566042, 5631406, 2711395, 1062915, -5136345}, - FieldElement{-19240248, -11254599, -29509029, -7499965, -5835763, 13005411, -6066489, 12194497, 32960380, 1459310}, - }, - }, - { - { - FieldElement{19852034, 7027924, 23669353, 10020366, 8586503, -6657907, 394197, -6101885, 18638003, -11174937}, - FieldElement{31395534, 15098109, 26581030, 8030562, -16527914, -5007134, 9012486, -7584354, -6643087, -5442636}, - FieldElement{-9192165, -2347377, -1997099, 4529534, 25766844, 607986, -13222, 9677543, -32294889, -6456008}, - }, - { - FieldElement{-2444496, -149937, 29348902, 8186665, 1873760, 12489863, -30934579, -7839692, -7852844, -8138429}, - FieldElement{-15236356, -15433509, 7766470, 746860, 26346930, -10221762, -27333451, 10754588, -9431476, 5203576}, - FieldElement{31834314, 14135496, -770007, 5159118, 20917671, -16768096, -7467973, -7337524, 31809243, 7347066}, - }, - { - FieldElement{-9606723, -11874240, 20414459, 13033986, 13716524, -11691881, 19797970, -12211255, 15192876, -2087490}, - FieldElement{-12663563, -2181719, 1168162, -3804809, 26747877, -14138091, 10609330, 12694420, 33473243, -13382104}, - FieldElement{33184999, 11180355, 15832085, -11385430, -1633671, 225884, 15089336, -11023903, -6135662, 14480053}, - }, - { - FieldElement{31308717, -5619998, 31030840, -1897099, 15674547, -6582883, 5496208, 13685227, 27595050, 8737275}, - FieldElement{-20318852, -15150239, 10933843, -16178022, 8335352, -7546022, -31008351, -12610604, 26498114, 66511}, - FieldElement{22644454, -8761729, -16671776, 4884562, -3105614, -13559366, 30540766, -4286747, -13327787, -7515095}, - }, - { - FieldElement{-28017847, 9834845, 18617207, -2681312, -3401956, -13307506, 8205540, 13585437, -17127465, 15115439}, - FieldElement{23711543, -672915, 31206561, -8362711, 6164647, -9709987, -33535882, -1426096, 8236921, 16492939}, - FieldElement{-23910559, -13515526, -26299483, -4503841, 25005590, -7687270, 19574902, 10071562, 6708380, -6222424}, - }, - { - FieldElement{2101391, -4930054, 19702731, 2367575, -15427167, 1047675, 5301017, 9328700, 29955601, -11678310}, - FieldElement{3096359, 9271816, -21620864, -15521844, -14847996, -7592937, -25892142, -12635595, -9917575, 6216608}, - FieldElement{-32615849, 338663, -25195611, 2510422, -29213566, -13820213, 24822830, -6146567, -26767480, 7525079}, - }, - { - FieldElement{-23066649, -13985623, 16133487, -7896178, -3389565, 778788, -910336, -2782495, -19386633, 11994101}, - FieldElement{21691500, -13624626, -641331, -14367021, 3285881, -3483596, -25064666, 9718258, -7477437, 13381418}, - FieldElement{18445390, -4202236, 14979846, 11622458, -1727110, -3582980, 23111648, -6375247, 28535282, 15779576}, - }, - { - FieldElement{30098053, 3089662, -9234387, 16662135, -21306940, 11308411, -14068454, 12021730, 9955285, -16303356}, - FieldElement{9734894, -14576830, -7473633, -9138735, 2060392, 11313496, -18426029, 9924399, 20194861, 13380996}, - FieldElement{-26378102, -7965207, -22167821, 15789297, -18055342, -6168792, -1984914, 15707771, 26342023, 10146099}, - }, - }, - { - { - FieldElement{-26016874, -219943, 21339191, -41388, 19745256, -2878700, -29637280, 2227040, 21612326, -545728}, - FieldElement{-13077387, 1184228, 23562814, -5970442, -20351244, -6348714, 25764461, 12243797, -20856566, 11649658}, - FieldElement{-10031494, 11262626, 27384172, 2271902, 26947504, -15997771, 39944, 6114064, 33514190, 2333242}, - }, - { - FieldElement{-21433588, -12421821, 8119782, 7219913, -21830522, -9016134, -6679750, -12670638, 24350578, -13450001}, - FieldElement{-4116307, -11271533, -23886186, 4843615, -30088339, 690623, -31536088, -10406836, 8317860, 12352766}, - FieldElement{18200138, -14475911, -33087759, -2696619, -23702521, -9102511, -23552096, -2287550, 20712163, 6719373}, - }, - { - FieldElement{26656208, 6075253, -7858556, 1886072, -28344043, 4262326, 11117530, -3763210, 26224235, -3297458}, - FieldElement{-17168938, -14854097, -3395676, -16369877, -19954045, 14050420, 21728352, 9493610, 18620611, -16428628}, - FieldElement{-13323321, 13325349, 11432106, 5964811, 18609221, 6062965, -5269471, -9725556, -30701573, -16479657}, - }, - { - FieldElement{-23860538, -11233159, 26961357, 1640861, -32413112, -16737940, 12248509, -5240639, 13735342, 1934062}, - FieldElement{25089769, 6742589, 17081145, -13406266, 21909293, -16067981, -15136294, -3765346, -21277997, 5473616}, - FieldElement{31883677, -7961101, 1083432, -11572403, 22828471, 13290673, -7125085, 12469656, 29111212, -5451014}, - }, - { - FieldElement{24244947, -15050407, -26262976, 2791540, -14997599, 16666678, 24367466, 6388839, -10295587, 452383}, - FieldElement{-25640782, -3417841, 5217916, 16224624, 19987036, -4082269, -24236251, -5915248, 15766062, 8407814}, - FieldElement{-20406999, 13990231, 15495425, 16395525, 5377168, 15166495, -8917023, -4388953, -8067909, 2276718}, - }, - { - FieldElement{30157918, 12924066, -17712050, 9245753, 19895028, 3368142, -23827587, 5096219, 22740376, -7303417}, - FieldElement{2041139, -14256350, 7783687, 13876377, -25946985, -13352459, 24051124, 13742383, -15637599, 13295222}, - FieldElement{33338237, -8505733, 12532113, 7977527, 9106186, -1715251, -17720195, -4612972, -4451357, -14669444}, - }, - { - FieldElement{-20045281, 5454097, -14346548, 6447146, 28862071, 1883651, -2469266, -4141880, 7770569, 9620597}, - FieldElement{23208068, 7979712, 33071466, 8149229, 1758231, -10834995, 30945528, -1694323, -33502340, -14767970}, - FieldElement{1439958, -16270480, -1079989, -793782, 4625402, 10647766, -5043801, 1220118, 30494170, -11440799}, - }, - { - FieldElement{-5037580, -13028295, -2970559, -3061767, 15640974, -6701666, -26739026, 926050, -1684339, -13333647}, - FieldElement{13908495, -3549272, 30919928, -6273825, -21521863, 7989039, 9021034, 9078865, 3353509, 4033511}, - FieldElement{-29663431, -15113610, 32259991, -344482, 24295849, -12912123, 23161163, 8839127, 27485041, 7356032}, - }, - }, - { - { - FieldElement{9661027, 705443, 11980065, -5370154, -1628543, 14661173, -6346142, 2625015, 28431036, -16771834}, - FieldElement{-23839233, -8311415, -25945511, 7480958, -17681669, -8354183, -22545972, 14150565, 15970762, 4099461}, - FieldElement{29262576, 16756590, 26350592, -8793563, 8529671, -11208050, 13617293, -9937143, 11465739, 8317062}, - }, - { - FieldElement{-25493081, -6962928, 32500200, -9419051, -23038724, -2302222, 14898637, 3848455, 20969334, -5157516}, - FieldElement{-20384450, -14347713, -18336405, 13884722, -33039454, 2842114, -21610826, -3649888, 11177095, 14989547}, - FieldElement{-24496721, -11716016, 16959896, 2278463, 12066309, 10137771, 13515641, 2581286, -28487508, 9930240}, - }, - { - FieldElement{-17751622, -2097826, 16544300, -13009300, -15914807, -14949081, 18345767, -13403753, 16291481, -5314038}, - FieldElement{-33229194, 2553288, 32678213, 9875984, 8534129, 6889387, -9676774, 6957617, 4368891, 9788741}, - FieldElement{16660756, 7281060, -10830758, 12911820, 20108584, -8101676, -21722536, -8613148, 16250552, -11111103}, - }, - { - FieldElement{-19765507, 2390526, -16551031, 14161980, 1905286, 6414907, 4689584, 10604807, -30190403, 4782747}, - FieldElement{-1354539, 14736941, -7367442, -13292886, 7710542, -14155590, -9981571, 4383045, 22546403, 437323}, - FieldElement{31665577, -12180464, -16186830, 1491339, -18368625, 3294682, 27343084, 2786261, -30633590, -14097016}, - }, - { - FieldElement{-14467279, -683715, -33374107, 7448552, 19294360, 14334329, -19690631, 2355319, -19284671, -6114373}, - FieldElement{15121312, -15796162, 6377020, -6031361, -10798111, -12957845, 18952177, 15496498, -29380133, 11754228}, - FieldElement{-2637277, -13483075, 8488727, -14303896, 12728761, -1622493, 7141596, 11724556, 22761615, -10134141}, - }, - { - FieldElement{16918416, 11729663, -18083579, 3022987, -31015732, -13339659, -28741185, -12227393, 32851222, 11717399}, - FieldElement{11166634, 7338049, -6722523, 4531520, -29468672, -7302055, 31474879, 3483633, -1193175, -4030831}, - FieldElement{-185635, 9921305, 31456609, -13536438, -12013818, 13348923, 33142652, 6546660, -19985279, -3948376}, - }, - { - FieldElement{-32460596, 11266712, -11197107, -7899103, 31703694, 3855903, -8537131, -12833048, -30772034, -15486313}, - FieldElement{-18006477, 12709068, 3991746, -6479188, -21491523, -10550425, -31135347, -16049879, 10928917, 3011958}, - FieldElement{-6957757, -15594337, 31696059, 334240, 29576716, 14796075, -30831056, -12805180, 18008031, 10258577}, - }, - { - FieldElement{-22448644, 15655569, 7018479, -4410003, -30314266, -1201591, -1853465, 1367120, 25127874, 6671743}, - FieldElement{29701166, -14373934, -10878120, 9279288, -17568, 13127210, 21382910, 11042292, 25838796, 4642684}, - FieldElement{-20430234, 14955537, -24126347, 8124619, -5369288, -5990470, 30468147, -13900640, 18423289, 4177476}, - }, - }, -} diff --git a/src/cmd/vendor/golang.org/x/crypto/ed25519/internal/edwards25519/edwards25519.go b/src/cmd/vendor/golang.org/x/crypto/ed25519/internal/edwards25519/edwards25519.go deleted file mode 100644 index fd03c252af4..00000000000 --- a/src/cmd/vendor/golang.org/x/crypto/ed25519/internal/edwards25519/edwards25519.go +++ /dev/null @@ -1,1793 +0,0 @@ -// Copyright 2016 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 edwards25519 - -import "encoding/binary" - -// This code is a port of the public domain, “ref10” implementation of ed25519 -// from SUPERCOP. - -// FieldElement represents an element of the field GF(2^255 - 19). An element -// t, entries t[0]...t[9], represents the integer t[0]+2^26 t[1]+2^51 t[2]+2^77 -// t[3]+2^102 t[4]+...+2^230 t[9]. Bounds on each t[i] vary depending on -// context. -type FieldElement [10]int32 - -var zero FieldElement - -func FeZero(fe *FieldElement) { - copy(fe[:], zero[:]) -} - -func FeOne(fe *FieldElement) { - FeZero(fe) - fe[0] = 1 -} - -func FeAdd(dst, a, b *FieldElement) { - dst[0] = a[0] + b[0] - dst[1] = a[1] + b[1] - dst[2] = a[2] + b[2] - dst[3] = a[3] + b[3] - dst[4] = a[4] + b[4] - dst[5] = a[5] + b[5] - dst[6] = a[6] + b[6] - dst[7] = a[7] + b[7] - dst[8] = a[8] + b[8] - dst[9] = a[9] + b[9] -} - -func FeSub(dst, a, b *FieldElement) { - dst[0] = a[0] - b[0] - dst[1] = a[1] - b[1] - dst[2] = a[2] - b[2] - dst[3] = a[3] - b[3] - dst[4] = a[4] - b[4] - dst[5] = a[5] - b[5] - dst[6] = a[6] - b[6] - dst[7] = a[7] - b[7] - dst[8] = a[8] - b[8] - dst[9] = a[9] - b[9] -} - -func FeCopy(dst, src *FieldElement) { - copy(dst[:], src[:]) -} - -// Replace (f,g) with (g,g) if b == 1; -// replace (f,g) with (f,g) if b == 0. -// -// Preconditions: b in {0,1}. -func FeCMove(f, g *FieldElement, b int32) { - b = -b - f[0] ^= b & (f[0] ^ g[0]) - f[1] ^= b & (f[1] ^ g[1]) - f[2] ^= b & (f[2] ^ g[2]) - f[3] ^= b & (f[3] ^ g[3]) - f[4] ^= b & (f[4] ^ g[4]) - f[5] ^= b & (f[5] ^ g[5]) - f[6] ^= b & (f[6] ^ g[6]) - f[7] ^= b & (f[7] ^ g[7]) - f[8] ^= b & (f[8] ^ g[8]) - f[9] ^= b & (f[9] ^ g[9]) -} - -func load3(in []byte) int64 { - var r int64 - r = int64(in[0]) - r |= int64(in[1]) << 8 - r |= int64(in[2]) << 16 - return r -} - -func load4(in []byte) int64 { - var r int64 - r = int64(in[0]) - r |= int64(in[1]) << 8 - r |= int64(in[2]) << 16 - r |= int64(in[3]) << 24 - return r -} - -func FeFromBytes(dst *FieldElement, src *[32]byte) { - h0 := load4(src[:]) - h1 := load3(src[4:]) << 6 - h2 := load3(src[7:]) << 5 - h3 := load3(src[10:]) << 3 - h4 := load3(src[13:]) << 2 - h5 := load4(src[16:]) - h6 := load3(src[20:]) << 7 - h7 := load3(src[23:]) << 5 - h8 := load3(src[26:]) << 4 - h9 := (load3(src[29:]) & 8388607) << 2 - - FeCombine(dst, h0, h1, h2, h3, h4, h5, h6, h7, h8, h9) -} - -// FeToBytes marshals h to s. -// Preconditions: -// |h| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc. -// -// Write p=2^255-19; q=floor(h/p). -// Basic claim: q = floor(2^(-255)(h + 19 2^(-25)h9 + 2^(-1))). -// -// Proof: -// Have |h|<=p so |q|<=1 so |19^2 2^(-255) q|<1/4. -// Also have |h-2^230 h9|<2^230 so |19 2^(-255)(h-2^230 h9)|<1/4. -// -// Write y=2^(-1)-19^2 2^(-255)q-19 2^(-255)(h-2^230 h9). -// Then 0> 25 - q = (h[0] + q) >> 26 - q = (h[1] + q) >> 25 - q = (h[2] + q) >> 26 - q = (h[3] + q) >> 25 - q = (h[4] + q) >> 26 - q = (h[5] + q) >> 25 - q = (h[6] + q) >> 26 - q = (h[7] + q) >> 25 - q = (h[8] + q) >> 26 - q = (h[9] + q) >> 25 - - // Goal: Output h-(2^255-19)q, which is between 0 and 2^255-20. - h[0] += 19 * q - // Goal: Output h-2^255 q, which is between 0 and 2^255-20. - - carry[0] = h[0] >> 26 - h[1] += carry[0] - h[0] -= carry[0] << 26 - carry[1] = h[1] >> 25 - h[2] += carry[1] - h[1] -= carry[1] << 25 - carry[2] = h[2] >> 26 - h[3] += carry[2] - h[2] -= carry[2] << 26 - carry[3] = h[3] >> 25 - h[4] += carry[3] - h[3] -= carry[3] << 25 - carry[4] = h[4] >> 26 - h[5] += carry[4] - h[4] -= carry[4] << 26 - carry[5] = h[5] >> 25 - h[6] += carry[5] - h[5] -= carry[5] << 25 - carry[6] = h[6] >> 26 - h[7] += carry[6] - h[6] -= carry[6] << 26 - carry[7] = h[7] >> 25 - h[8] += carry[7] - h[7] -= carry[7] << 25 - carry[8] = h[8] >> 26 - h[9] += carry[8] - h[8] -= carry[8] << 26 - carry[9] = h[9] >> 25 - h[9] -= carry[9] << 25 - // h10 = carry9 - - // Goal: Output h[0]+...+2^255 h10-2^255 q, which is between 0 and 2^255-20. - // Have h[0]+...+2^230 h[9] between 0 and 2^255-1; - // evidently 2^255 h10-2^255 q = 0. - // Goal: Output h[0]+...+2^230 h[9]. - - s[0] = byte(h[0] >> 0) - s[1] = byte(h[0] >> 8) - s[2] = byte(h[0] >> 16) - s[3] = byte((h[0] >> 24) | (h[1] << 2)) - s[4] = byte(h[1] >> 6) - s[5] = byte(h[1] >> 14) - s[6] = byte((h[1] >> 22) | (h[2] << 3)) - s[7] = byte(h[2] >> 5) - s[8] = byte(h[2] >> 13) - s[9] = byte((h[2] >> 21) | (h[3] << 5)) - s[10] = byte(h[3] >> 3) - s[11] = byte(h[3] >> 11) - s[12] = byte((h[3] >> 19) | (h[4] << 6)) - s[13] = byte(h[4] >> 2) - s[14] = byte(h[4] >> 10) - s[15] = byte(h[4] >> 18) - s[16] = byte(h[5] >> 0) - s[17] = byte(h[5] >> 8) - s[18] = byte(h[5] >> 16) - s[19] = byte((h[5] >> 24) | (h[6] << 1)) - s[20] = byte(h[6] >> 7) - s[21] = byte(h[6] >> 15) - s[22] = byte((h[6] >> 23) | (h[7] << 3)) - s[23] = byte(h[7] >> 5) - s[24] = byte(h[7] >> 13) - s[25] = byte((h[7] >> 21) | (h[8] << 4)) - s[26] = byte(h[8] >> 4) - s[27] = byte(h[8] >> 12) - s[28] = byte((h[8] >> 20) | (h[9] << 6)) - s[29] = byte(h[9] >> 2) - s[30] = byte(h[9] >> 10) - s[31] = byte(h[9] >> 18) -} - -func FeIsNegative(f *FieldElement) byte { - var s [32]byte - FeToBytes(&s, f) - return s[0] & 1 -} - -func FeIsNonZero(f *FieldElement) int32 { - var s [32]byte - FeToBytes(&s, f) - var x uint8 - for _, b := range s { - x |= b - } - x |= x >> 4 - x |= x >> 2 - x |= x >> 1 - return int32(x & 1) -} - -// FeNeg sets h = -f -// -// Preconditions: -// |f| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc. -// -// Postconditions: -// |h| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc. -func FeNeg(h, f *FieldElement) { - h[0] = -f[0] - h[1] = -f[1] - h[2] = -f[2] - h[3] = -f[3] - h[4] = -f[4] - h[5] = -f[5] - h[6] = -f[6] - h[7] = -f[7] - h[8] = -f[8] - h[9] = -f[9] -} - -func FeCombine(h *FieldElement, h0, h1, h2, h3, h4, h5, h6, h7, h8, h9 int64) { - var c0, c1, c2, c3, c4, c5, c6, c7, c8, c9 int64 - - /* - |h0| <= (1.1*1.1*2^52*(1+19+19+19+19)+1.1*1.1*2^50*(38+38+38+38+38)) - i.e. |h0| <= 1.2*2^59; narrower ranges for h2, h4, h6, h8 - |h1| <= (1.1*1.1*2^51*(1+1+19+19+19+19+19+19+19+19)) - i.e. |h1| <= 1.5*2^58; narrower ranges for h3, h5, h7, h9 - */ - - c0 = (h0 + (1 << 25)) >> 26 - h1 += c0 - h0 -= c0 << 26 - c4 = (h4 + (1 << 25)) >> 26 - h5 += c4 - h4 -= c4 << 26 - /* |h0| <= 2^25 */ - /* |h4| <= 2^25 */ - /* |h1| <= 1.51*2^58 */ - /* |h5| <= 1.51*2^58 */ - - c1 = (h1 + (1 << 24)) >> 25 - h2 += c1 - h1 -= c1 << 25 - c5 = (h5 + (1 << 24)) >> 25 - h6 += c5 - h5 -= c5 << 25 - /* |h1| <= 2^24; from now on fits into int32 */ - /* |h5| <= 2^24; from now on fits into int32 */ - /* |h2| <= 1.21*2^59 */ - /* |h6| <= 1.21*2^59 */ - - c2 = (h2 + (1 << 25)) >> 26 - h3 += c2 - h2 -= c2 << 26 - c6 = (h6 + (1 << 25)) >> 26 - h7 += c6 - h6 -= c6 << 26 - /* |h2| <= 2^25; from now on fits into int32 unchanged */ - /* |h6| <= 2^25; from now on fits into int32 unchanged */ - /* |h3| <= 1.51*2^58 */ - /* |h7| <= 1.51*2^58 */ - - c3 = (h3 + (1 << 24)) >> 25 - h4 += c3 - h3 -= c3 << 25 - c7 = (h7 + (1 << 24)) >> 25 - h8 += c7 - h7 -= c7 << 25 - /* |h3| <= 2^24; from now on fits into int32 unchanged */ - /* |h7| <= 2^24; from now on fits into int32 unchanged */ - /* |h4| <= 1.52*2^33 */ - /* |h8| <= 1.52*2^33 */ - - c4 = (h4 + (1 << 25)) >> 26 - h5 += c4 - h4 -= c4 << 26 - c8 = (h8 + (1 << 25)) >> 26 - h9 += c8 - h8 -= c8 << 26 - /* |h4| <= 2^25; from now on fits into int32 unchanged */ - /* |h8| <= 2^25; from now on fits into int32 unchanged */ - /* |h5| <= 1.01*2^24 */ - /* |h9| <= 1.51*2^58 */ - - c9 = (h9 + (1 << 24)) >> 25 - h0 += c9 * 19 - h9 -= c9 << 25 - /* |h9| <= 2^24; from now on fits into int32 unchanged */ - /* |h0| <= 1.8*2^37 */ - - c0 = (h0 + (1 << 25)) >> 26 - h1 += c0 - h0 -= c0 << 26 - /* |h0| <= 2^25; from now on fits into int32 unchanged */ - /* |h1| <= 1.01*2^24 */ - - h[0] = int32(h0) - h[1] = int32(h1) - h[2] = int32(h2) - h[3] = int32(h3) - h[4] = int32(h4) - h[5] = int32(h5) - h[6] = int32(h6) - h[7] = int32(h7) - h[8] = int32(h8) - h[9] = int32(h9) -} - -// FeMul calculates h = f * g -// Can overlap h with f or g. -// -// Preconditions: -// |f| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc. -// |g| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc. -// -// Postconditions: -// |h| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc. -// -// Notes on implementation strategy: -// -// Using schoolbook multiplication. -// Karatsuba would save a little in some cost models. -// -// Most multiplications by 2 and 19 are 32-bit precomputations; -// cheaper than 64-bit postcomputations. -// -// There is one remaining multiplication by 19 in the carry chain; -// one *19 precomputation can be merged into this, -// but the resulting data flow is considerably less clean. -// -// There are 12 carries below. -// 10 of them are 2-way parallelizable and vectorizable. -// Can get away with 11 carries, but then data flow is much deeper. -// -// With tighter constraints on inputs, can squeeze carries into int32. -func FeMul(h, f, g *FieldElement) { - f0 := int64(f[0]) - f1 := int64(f[1]) - f2 := int64(f[2]) - f3 := int64(f[3]) - f4 := int64(f[4]) - f5 := int64(f[5]) - f6 := int64(f[6]) - f7 := int64(f[7]) - f8 := int64(f[8]) - f9 := int64(f[9]) - - f1_2 := int64(2 * f[1]) - f3_2 := int64(2 * f[3]) - f5_2 := int64(2 * f[5]) - f7_2 := int64(2 * f[7]) - f9_2 := int64(2 * f[9]) - - g0 := int64(g[0]) - g1 := int64(g[1]) - g2 := int64(g[2]) - g3 := int64(g[3]) - g4 := int64(g[4]) - g5 := int64(g[5]) - g6 := int64(g[6]) - g7 := int64(g[7]) - g8 := int64(g[8]) - g9 := int64(g[9]) - - g1_19 := int64(19 * g[1]) /* 1.4*2^29 */ - g2_19 := int64(19 * g[2]) /* 1.4*2^30; still ok */ - g3_19 := int64(19 * g[3]) - g4_19 := int64(19 * g[4]) - g5_19 := int64(19 * g[5]) - g6_19 := int64(19 * g[6]) - g7_19 := int64(19 * g[7]) - g8_19 := int64(19 * g[8]) - g9_19 := int64(19 * g[9]) - - h0 := f0*g0 + f1_2*g9_19 + f2*g8_19 + f3_2*g7_19 + f4*g6_19 + f5_2*g5_19 + f6*g4_19 + f7_2*g3_19 + f8*g2_19 + f9_2*g1_19 - h1 := f0*g1 + f1*g0 + f2*g9_19 + f3*g8_19 + f4*g7_19 + f5*g6_19 + f6*g5_19 + f7*g4_19 + f8*g3_19 + f9*g2_19 - h2 := f0*g2 + f1_2*g1 + f2*g0 + f3_2*g9_19 + f4*g8_19 + f5_2*g7_19 + f6*g6_19 + f7_2*g5_19 + f8*g4_19 + f9_2*g3_19 - h3 := f0*g3 + f1*g2 + f2*g1 + f3*g0 + f4*g9_19 + f5*g8_19 + f6*g7_19 + f7*g6_19 + f8*g5_19 + f9*g4_19 - h4 := f0*g4 + f1_2*g3 + f2*g2 + f3_2*g1 + f4*g0 + f5_2*g9_19 + f6*g8_19 + f7_2*g7_19 + f8*g6_19 + f9_2*g5_19 - h5 := f0*g5 + f1*g4 + f2*g3 + f3*g2 + f4*g1 + f5*g0 + f6*g9_19 + f7*g8_19 + f8*g7_19 + f9*g6_19 - h6 := f0*g6 + f1_2*g5 + f2*g4 + f3_2*g3 + f4*g2 + f5_2*g1 + f6*g0 + f7_2*g9_19 + f8*g8_19 + f9_2*g7_19 - h7 := f0*g7 + f1*g6 + f2*g5 + f3*g4 + f4*g3 + f5*g2 + f6*g1 + f7*g0 + f8*g9_19 + f9*g8_19 - h8 := f0*g8 + f1_2*g7 + f2*g6 + f3_2*g5 + f4*g4 + f5_2*g3 + f6*g2 + f7_2*g1 + f8*g0 + f9_2*g9_19 - h9 := f0*g9 + f1*g8 + f2*g7 + f3*g6 + f4*g5 + f5*g4 + f6*g3 + f7*g2 + f8*g1 + f9*g0 - - FeCombine(h, h0, h1, h2, h3, h4, h5, h6, h7, h8, h9) -} - -func feSquare(f *FieldElement) (h0, h1, h2, h3, h4, h5, h6, h7, h8, h9 int64) { - f0 := int64(f[0]) - f1 := int64(f[1]) - f2 := int64(f[2]) - f3 := int64(f[3]) - f4 := int64(f[4]) - f5 := int64(f[5]) - f6 := int64(f[6]) - f7 := int64(f[7]) - f8 := int64(f[8]) - f9 := int64(f[9]) - f0_2 := int64(2 * f[0]) - f1_2 := int64(2 * f[1]) - f2_2 := int64(2 * f[2]) - f3_2 := int64(2 * f[3]) - f4_2 := int64(2 * f[4]) - f5_2 := int64(2 * f[5]) - f6_2 := int64(2 * f[6]) - f7_2 := int64(2 * f[7]) - f5_38 := 38 * f5 // 1.31*2^30 - f6_19 := 19 * f6 // 1.31*2^30 - f7_38 := 38 * f7 // 1.31*2^30 - f8_19 := 19 * f8 // 1.31*2^30 - f9_38 := 38 * f9 // 1.31*2^30 - - h0 = f0*f0 + f1_2*f9_38 + f2_2*f8_19 + f3_2*f7_38 + f4_2*f6_19 + f5*f5_38 - h1 = f0_2*f1 + f2*f9_38 + f3_2*f8_19 + f4*f7_38 + f5_2*f6_19 - h2 = f0_2*f2 + f1_2*f1 + f3_2*f9_38 + f4_2*f8_19 + f5_2*f7_38 + f6*f6_19 - h3 = f0_2*f3 + f1_2*f2 + f4*f9_38 + f5_2*f8_19 + f6*f7_38 - h4 = f0_2*f4 + f1_2*f3_2 + f2*f2 + f5_2*f9_38 + f6_2*f8_19 + f7*f7_38 - h5 = f0_2*f5 + f1_2*f4 + f2_2*f3 + f6*f9_38 + f7_2*f8_19 - h6 = f0_2*f6 + f1_2*f5_2 + f2_2*f4 + f3_2*f3 + f7_2*f9_38 + f8*f8_19 - h7 = f0_2*f7 + f1_2*f6 + f2_2*f5 + f3_2*f4 + f8*f9_38 - h8 = f0_2*f8 + f1_2*f7_2 + f2_2*f6 + f3_2*f5_2 + f4*f4 + f9*f9_38 - h9 = f0_2*f9 + f1_2*f8 + f2_2*f7 + f3_2*f6 + f4_2*f5 - - return -} - -// FeSquare calculates h = f*f. Can overlap h with f. -// -// Preconditions: -// |f| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc. -// -// Postconditions: -// |h| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc. -func FeSquare(h, f *FieldElement) { - h0, h1, h2, h3, h4, h5, h6, h7, h8, h9 := feSquare(f) - FeCombine(h, h0, h1, h2, h3, h4, h5, h6, h7, h8, h9) -} - -// FeSquare2 sets h = 2 * f * f -// -// Can overlap h with f. -// -// Preconditions: -// |f| bounded by 1.65*2^26,1.65*2^25,1.65*2^26,1.65*2^25,etc. -// -// Postconditions: -// |h| bounded by 1.01*2^25,1.01*2^24,1.01*2^25,1.01*2^24,etc. -// See fe_mul.c for discussion of implementation strategy. -func FeSquare2(h, f *FieldElement) { - h0, h1, h2, h3, h4, h5, h6, h7, h8, h9 := feSquare(f) - - h0 += h0 - h1 += h1 - h2 += h2 - h3 += h3 - h4 += h4 - h5 += h5 - h6 += h6 - h7 += h7 - h8 += h8 - h9 += h9 - - FeCombine(h, h0, h1, h2, h3, h4, h5, h6, h7, h8, h9) -} - -func FeInvert(out, z *FieldElement) { - var t0, t1, t2, t3 FieldElement - var i int - - FeSquare(&t0, z) // 2^1 - FeSquare(&t1, &t0) // 2^2 - for i = 1; i < 2; i++ { // 2^3 - FeSquare(&t1, &t1) - } - FeMul(&t1, z, &t1) // 2^3 + 2^0 - FeMul(&t0, &t0, &t1) // 2^3 + 2^1 + 2^0 - FeSquare(&t2, &t0) // 2^4 + 2^2 + 2^1 - FeMul(&t1, &t1, &t2) // 2^4 + 2^3 + 2^2 + 2^1 + 2^0 - FeSquare(&t2, &t1) // 5,4,3,2,1 - for i = 1; i < 5; i++ { // 9,8,7,6,5 - FeSquare(&t2, &t2) - } - FeMul(&t1, &t2, &t1) // 9,8,7,6,5,4,3,2,1,0 - FeSquare(&t2, &t1) // 10..1 - for i = 1; i < 10; i++ { // 19..10 - FeSquare(&t2, &t2) - } - FeMul(&t2, &t2, &t1) // 19..0 - FeSquare(&t3, &t2) // 20..1 - for i = 1; i < 20; i++ { // 39..20 - FeSquare(&t3, &t3) - } - FeMul(&t2, &t3, &t2) // 39..0 - FeSquare(&t2, &t2) // 40..1 - for i = 1; i < 10; i++ { // 49..10 - FeSquare(&t2, &t2) - } - FeMul(&t1, &t2, &t1) // 49..0 - FeSquare(&t2, &t1) // 50..1 - for i = 1; i < 50; i++ { // 99..50 - FeSquare(&t2, &t2) - } - FeMul(&t2, &t2, &t1) // 99..0 - FeSquare(&t3, &t2) // 100..1 - for i = 1; i < 100; i++ { // 199..100 - FeSquare(&t3, &t3) - } - FeMul(&t2, &t3, &t2) // 199..0 - FeSquare(&t2, &t2) // 200..1 - for i = 1; i < 50; i++ { // 249..50 - FeSquare(&t2, &t2) - } - FeMul(&t1, &t2, &t1) // 249..0 - FeSquare(&t1, &t1) // 250..1 - for i = 1; i < 5; i++ { // 254..5 - FeSquare(&t1, &t1) - } - FeMul(out, &t1, &t0) // 254..5,3,1,0 -} - -func fePow22523(out, z *FieldElement) { - var t0, t1, t2 FieldElement - var i int - - FeSquare(&t0, z) - for i = 1; i < 1; i++ { - FeSquare(&t0, &t0) - } - FeSquare(&t1, &t0) - for i = 1; i < 2; i++ { - FeSquare(&t1, &t1) - } - FeMul(&t1, z, &t1) - FeMul(&t0, &t0, &t1) - FeSquare(&t0, &t0) - for i = 1; i < 1; i++ { - FeSquare(&t0, &t0) - } - FeMul(&t0, &t1, &t0) - FeSquare(&t1, &t0) - for i = 1; i < 5; i++ { - FeSquare(&t1, &t1) - } - FeMul(&t0, &t1, &t0) - FeSquare(&t1, &t0) - for i = 1; i < 10; i++ { - FeSquare(&t1, &t1) - } - FeMul(&t1, &t1, &t0) - FeSquare(&t2, &t1) - for i = 1; i < 20; i++ { - FeSquare(&t2, &t2) - } - FeMul(&t1, &t2, &t1) - FeSquare(&t1, &t1) - for i = 1; i < 10; i++ { - FeSquare(&t1, &t1) - } - FeMul(&t0, &t1, &t0) - FeSquare(&t1, &t0) - for i = 1; i < 50; i++ { - FeSquare(&t1, &t1) - } - FeMul(&t1, &t1, &t0) - FeSquare(&t2, &t1) - for i = 1; i < 100; i++ { - FeSquare(&t2, &t2) - } - FeMul(&t1, &t2, &t1) - FeSquare(&t1, &t1) - for i = 1; i < 50; i++ { - FeSquare(&t1, &t1) - } - FeMul(&t0, &t1, &t0) - FeSquare(&t0, &t0) - for i = 1; i < 2; i++ { - FeSquare(&t0, &t0) - } - FeMul(out, &t0, z) -} - -// Group elements are members of the elliptic curve -x^2 + y^2 = 1 + d * x^2 * -// y^2 where d = -121665/121666. -// -// Several representations are used: -// ProjectiveGroupElement: (X:Y:Z) satisfying x=X/Z, y=Y/Z -// ExtendedGroupElement: (X:Y:Z:T) satisfying x=X/Z, y=Y/Z, XY=ZT -// CompletedGroupElement: ((X:Z),(Y:T)) satisfying x=X/Z, y=Y/T -// PreComputedGroupElement: (y+x,y-x,2dxy) - -type ProjectiveGroupElement struct { - X, Y, Z FieldElement -} - -type ExtendedGroupElement struct { - X, Y, Z, T FieldElement -} - -type CompletedGroupElement struct { - X, Y, Z, T FieldElement -} - -type PreComputedGroupElement struct { - yPlusX, yMinusX, xy2d FieldElement -} - -type CachedGroupElement struct { - yPlusX, yMinusX, Z, T2d FieldElement -} - -func (p *ProjectiveGroupElement) Zero() { - FeZero(&p.X) - FeOne(&p.Y) - FeOne(&p.Z) -} - -func (p *ProjectiveGroupElement) Double(r *CompletedGroupElement) { - var t0 FieldElement - - FeSquare(&r.X, &p.X) - FeSquare(&r.Z, &p.Y) - FeSquare2(&r.T, &p.Z) - FeAdd(&r.Y, &p.X, &p.Y) - FeSquare(&t0, &r.Y) - FeAdd(&r.Y, &r.Z, &r.X) - FeSub(&r.Z, &r.Z, &r.X) - FeSub(&r.X, &t0, &r.Y) - FeSub(&r.T, &r.T, &r.Z) -} - -func (p *ProjectiveGroupElement) ToBytes(s *[32]byte) { - var recip, x, y FieldElement - - FeInvert(&recip, &p.Z) - FeMul(&x, &p.X, &recip) - FeMul(&y, &p.Y, &recip) - FeToBytes(s, &y) - s[31] ^= FeIsNegative(&x) << 7 -} - -func (p *ExtendedGroupElement) Zero() { - FeZero(&p.X) - FeOne(&p.Y) - FeOne(&p.Z) - FeZero(&p.T) -} - -func (p *ExtendedGroupElement) Double(r *CompletedGroupElement) { - var q ProjectiveGroupElement - p.ToProjective(&q) - q.Double(r) -} - -func (p *ExtendedGroupElement) ToCached(r *CachedGroupElement) { - FeAdd(&r.yPlusX, &p.Y, &p.X) - FeSub(&r.yMinusX, &p.Y, &p.X) - FeCopy(&r.Z, &p.Z) - FeMul(&r.T2d, &p.T, &d2) -} - -func (p *ExtendedGroupElement) ToProjective(r *ProjectiveGroupElement) { - FeCopy(&r.X, &p.X) - FeCopy(&r.Y, &p.Y) - FeCopy(&r.Z, &p.Z) -} - -func (p *ExtendedGroupElement) ToBytes(s *[32]byte) { - var recip, x, y FieldElement - - FeInvert(&recip, &p.Z) - FeMul(&x, &p.X, &recip) - FeMul(&y, &p.Y, &recip) - FeToBytes(s, &y) - s[31] ^= FeIsNegative(&x) << 7 -} - -func (p *ExtendedGroupElement) FromBytes(s *[32]byte) bool { - var u, v, v3, vxx, check FieldElement - - FeFromBytes(&p.Y, s) - FeOne(&p.Z) - FeSquare(&u, &p.Y) - FeMul(&v, &u, &d) - FeSub(&u, &u, &p.Z) // y = y^2-1 - FeAdd(&v, &v, &p.Z) // v = dy^2+1 - - FeSquare(&v3, &v) - FeMul(&v3, &v3, &v) // v3 = v^3 - FeSquare(&p.X, &v3) - FeMul(&p.X, &p.X, &v) - FeMul(&p.X, &p.X, &u) // x = uv^7 - - fePow22523(&p.X, &p.X) // x = (uv^7)^((q-5)/8) - FeMul(&p.X, &p.X, &v3) - FeMul(&p.X, &p.X, &u) // x = uv^3(uv^7)^((q-5)/8) - - var tmpX, tmp2 [32]byte - - FeSquare(&vxx, &p.X) - FeMul(&vxx, &vxx, &v) - FeSub(&check, &vxx, &u) // vx^2-u - if FeIsNonZero(&check) == 1 { - FeAdd(&check, &vxx, &u) // vx^2+u - if FeIsNonZero(&check) == 1 { - return false - } - FeMul(&p.X, &p.X, &SqrtM1) - - FeToBytes(&tmpX, &p.X) - for i, v := range tmpX { - tmp2[31-i] = v - } - } - - if FeIsNegative(&p.X) != (s[31] >> 7) { - FeNeg(&p.X, &p.X) - } - - FeMul(&p.T, &p.X, &p.Y) - return true -} - -func (p *CompletedGroupElement) ToProjective(r *ProjectiveGroupElement) { - FeMul(&r.X, &p.X, &p.T) - FeMul(&r.Y, &p.Y, &p.Z) - FeMul(&r.Z, &p.Z, &p.T) -} - -func (p *CompletedGroupElement) ToExtended(r *ExtendedGroupElement) { - FeMul(&r.X, &p.X, &p.T) - FeMul(&r.Y, &p.Y, &p.Z) - FeMul(&r.Z, &p.Z, &p.T) - FeMul(&r.T, &p.X, &p.Y) -} - -func (p *PreComputedGroupElement) Zero() { - FeOne(&p.yPlusX) - FeOne(&p.yMinusX) - FeZero(&p.xy2d) -} - -func geAdd(r *CompletedGroupElement, p *ExtendedGroupElement, q *CachedGroupElement) { - var t0 FieldElement - - FeAdd(&r.X, &p.Y, &p.X) - FeSub(&r.Y, &p.Y, &p.X) - FeMul(&r.Z, &r.X, &q.yPlusX) - FeMul(&r.Y, &r.Y, &q.yMinusX) - FeMul(&r.T, &q.T2d, &p.T) - FeMul(&r.X, &p.Z, &q.Z) - FeAdd(&t0, &r.X, &r.X) - FeSub(&r.X, &r.Z, &r.Y) - FeAdd(&r.Y, &r.Z, &r.Y) - FeAdd(&r.Z, &t0, &r.T) - FeSub(&r.T, &t0, &r.T) -} - -func geSub(r *CompletedGroupElement, p *ExtendedGroupElement, q *CachedGroupElement) { - var t0 FieldElement - - FeAdd(&r.X, &p.Y, &p.X) - FeSub(&r.Y, &p.Y, &p.X) - FeMul(&r.Z, &r.X, &q.yMinusX) - FeMul(&r.Y, &r.Y, &q.yPlusX) - FeMul(&r.T, &q.T2d, &p.T) - FeMul(&r.X, &p.Z, &q.Z) - FeAdd(&t0, &r.X, &r.X) - FeSub(&r.X, &r.Z, &r.Y) - FeAdd(&r.Y, &r.Z, &r.Y) - FeSub(&r.Z, &t0, &r.T) - FeAdd(&r.T, &t0, &r.T) -} - -func geMixedAdd(r *CompletedGroupElement, p *ExtendedGroupElement, q *PreComputedGroupElement) { - var t0 FieldElement - - FeAdd(&r.X, &p.Y, &p.X) - FeSub(&r.Y, &p.Y, &p.X) - FeMul(&r.Z, &r.X, &q.yPlusX) - FeMul(&r.Y, &r.Y, &q.yMinusX) - FeMul(&r.T, &q.xy2d, &p.T) - FeAdd(&t0, &p.Z, &p.Z) - FeSub(&r.X, &r.Z, &r.Y) - FeAdd(&r.Y, &r.Z, &r.Y) - FeAdd(&r.Z, &t0, &r.T) - FeSub(&r.T, &t0, &r.T) -} - -func geMixedSub(r *CompletedGroupElement, p *ExtendedGroupElement, q *PreComputedGroupElement) { - var t0 FieldElement - - FeAdd(&r.X, &p.Y, &p.X) - FeSub(&r.Y, &p.Y, &p.X) - FeMul(&r.Z, &r.X, &q.yMinusX) - FeMul(&r.Y, &r.Y, &q.yPlusX) - FeMul(&r.T, &q.xy2d, &p.T) - FeAdd(&t0, &p.Z, &p.Z) - FeSub(&r.X, &r.Z, &r.Y) - FeAdd(&r.Y, &r.Z, &r.Y) - FeSub(&r.Z, &t0, &r.T) - FeAdd(&r.T, &t0, &r.T) -} - -func slide(r *[256]int8, a *[32]byte) { - for i := range r { - r[i] = int8(1 & (a[i>>3] >> uint(i&7))) - } - - for i := range r { - if r[i] != 0 { - for b := 1; b <= 6 && i+b < 256; b++ { - if r[i+b] != 0 { - if r[i]+(r[i+b]<= -15 { - r[i] -= r[i+b] << uint(b) - for k := i + b; k < 256; k++ { - if r[k] == 0 { - r[k] = 1 - break - } - r[k] = 0 - } - } else { - break - } - } - } - } - } -} - -// GeDoubleScalarMultVartime sets r = a*A + b*B -// where a = a[0]+256*a[1]+...+256^31 a[31]. -// and b = b[0]+256*b[1]+...+256^31 b[31]. -// B is the Ed25519 base point (x,4/5) with x positive. -func GeDoubleScalarMultVartime(r *ProjectiveGroupElement, a *[32]byte, A *ExtendedGroupElement, b *[32]byte) { - var aSlide, bSlide [256]int8 - var Ai [8]CachedGroupElement // A,3A,5A,7A,9A,11A,13A,15A - var t CompletedGroupElement - var u, A2 ExtendedGroupElement - var i int - - slide(&aSlide, a) - slide(&bSlide, b) - - A.ToCached(&Ai[0]) - A.Double(&t) - t.ToExtended(&A2) - - for i := 0; i < 7; i++ { - geAdd(&t, &A2, &Ai[i]) - t.ToExtended(&u) - u.ToCached(&Ai[i+1]) - } - - r.Zero() - - for i = 255; i >= 0; i-- { - if aSlide[i] != 0 || bSlide[i] != 0 { - break - } - } - - for ; i >= 0; i-- { - r.Double(&t) - - if aSlide[i] > 0 { - t.ToExtended(&u) - geAdd(&t, &u, &Ai[aSlide[i]/2]) - } else if aSlide[i] < 0 { - t.ToExtended(&u) - geSub(&t, &u, &Ai[(-aSlide[i])/2]) - } - - if bSlide[i] > 0 { - t.ToExtended(&u) - geMixedAdd(&t, &u, &bi[bSlide[i]/2]) - } else if bSlide[i] < 0 { - t.ToExtended(&u) - geMixedSub(&t, &u, &bi[(-bSlide[i])/2]) - } - - t.ToProjective(r) - } -} - -// equal returns 1 if b == c and 0 otherwise, assuming that b and c are -// non-negative. -func equal(b, c int32) int32 { - x := uint32(b ^ c) - x-- - return int32(x >> 31) -} - -// negative returns 1 if b < 0 and 0 otherwise. -func negative(b int32) int32 { - return (b >> 31) & 1 -} - -func PreComputedGroupElementCMove(t, u *PreComputedGroupElement, b int32) { - FeCMove(&t.yPlusX, &u.yPlusX, b) - FeCMove(&t.yMinusX, &u.yMinusX, b) - FeCMove(&t.xy2d, &u.xy2d, b) -} - -func selectPoint(t *PreComputedGroupElement, pos int32, b int32) { - var minusT PreComputedGroupElement - bNegative := negative(b) - bAbs := b - (((-bNegative) & b) << 1) - - t.Zero() - for i := int32(0); i < 8; i++ { - PreComputedGroupElementCMove(t, &base[pos][i], equal(bAbs, i+1)) - } - FeCopy(&minusT.yPlusX, &t.yMinusX) - FeCopy(&minusT.yMinusX, &t.yPlusX) - FeNeg(&minusT.xy2d, &t.xy2d) - PreComputedGroupElementCMove(t, &minusT, bNegative) -} - -// GeScalarMultBase computes h = a*B, where -// a = a[0]+256*a[1]+...+256^31 a[31] -// B is the Ed25519 base point (x,4/5) with x positive. -// -// Preconditions: -// a[31] <= 127 -func GeScalarMultBase(h *ExtendedGroupElement, a *[32]byte) { - var e [64]int8 - - for i, v := range a { - e[2*i] = int8(v & 15) - e[2*i+1] = int8((v >> 4) & 15) - } - - // each e[i] is between 0 and 15 and e[63] is between 0 and 7. - - carry := int8(0) - for i := 0; i < 63; i++ { - e[i] += carry - carry = (e[i] + 8) >> 4 - e[i] -= carry << 4 - } - e[63] += carry - // each e[i] is between -8 and 8. - - h.Zero() - var t PreComputedGroupElement - var r CompletedGroupElement - for i := int32(1); i < 64; i += 2 { - selectPoint(&t, i/2, int32(e[i])) - geMixedAdd(&r, h, &t) - r.ToExtended(h) - } - - var s ProjectiveGroupElement - - h.Double(&r) - r.ToProjective(&s) - s.Double(&r) - r.ToProjective(&s) - s.Double(&r) - r.ToProjective(&s) - s.Double(&r) - r.ToExtended(h) - - for i := int32(0); i < 64; i += 2 { - selectPoint(&t, i/2, int32(e[i])) - geMixedAdd(&r, h, &t) - r.ToExtended(h) - } -} - -// The scalars are GF(2^252 + 27742317777372353535851937790883648493). - -// Input: -// a[0]+256*a[1]+...+256^31*a[31] = a -// b[0]+256*b[1]+...+256^31*b[31] = b -// c[0]+256*c[1]+...+256^31*c[31] = c -// -// Output: -// s[0]+256*s[1]+...+256^31*s[31] = (ab+c) mod l -// where l = 2^252 + 27742317777372353535851937790883648493. -func ScMulAdd(s, a, b, c *[32]byte) { - a0 := 2097151 & load3(a[:]) - a1 := 2097151 & (load4(a[2:]) >> 5) - a2 := 2097151 & (load3(a[5:]) >> 2) - a3 := 2097151 & (load4(a[7:]) >> 7) - a4 := 2097151 & (load4(a[10:]) >> 4) - a5 := 2097151 & (load3(a[13:]) >> 1) - a6 := 2097151 & (load4(a[15:]) >> 6) - a7 := 2097151 & (load3(a[18:]) >> 3) - a8 := 2097151 & load3(a[21:]) - a9 := 2097151 & (load4(a[23:]) >> 5) - a10 := 2097151 & (load3(a[26:]) >> 2) - a11 := (load4(a[28:]) >> 7) - b0 := 2097151 & load3(b[:]) - b1 := 2097151 & (load4(b[2:]) >> 5) - b2 := 2097151 & (load3(b[5:]) >> 2) - b3 := 2097151 & (load4(b[7:]) >> 7) - b4 := 2097151 & (load4(b[10:]) >> 4) - b5 := 2097151 & (load3(b[13:]) >> 1) - b6 := 2097151 & (load4(b[15:]) >> 6) - b7 := 2097151 & (load3(b[18:]) >> 3) - b8 := 2097151 & load3(b[21:]) - b9 := 2097151 & (load4(b[23:]) >> 5) - b10 := 2097151 & (load3(b[26:]) >> 2) - b11 := (load4(b[28:]) >> 7) - c0 := 2097151 & load3(c[:]) - c1 := 2097151 & (load4(c[2:]) >> 5) - c2 := 2097151 & (load3(c[5:]) >> 2) - c3 := 2097151 & (load4(c[7:]) >> 7) - c4 := 2097151 & (load4(c[10:]) >> 4) - c5 := 2097151 & (load3(c[13:]) >> 1) - c6 := 2097151 & (load4(c[15:]) >> 6) - c7 := 2097151 & (load3(c[18:]) >> 3) - c8 := 2097151 & load3(c[21:]) - c9 := 2097151 & (load4(c[23:]) >> 5) - c10 := 2097151 & (load3(c[26:]) >> 2) - c11 := (load4(c[28:]) >> 7) - var carry [23]int64 - - s0 := c0 + a0*b0 - s1 := c1 + a0*b1 + a1*b0 - s2 := c2 + a0*b2 + a1*b1 + a2*b0 - s3 := c3 + a0*b3 + a1*b2 + a2*b1 + a3*b0 - s4 := c4 + a0*b4 + a1*b3 + a2*b2 + a3*b1 + a4*b0 - s5 := c5 + a0*b5 + a1*b4 + a2*b3 + a3*b2 + a4*b1 + a5*b0 - s6 := c6 + a0*b6 + a1*b5 + a2*b4 + a3*b3 + a4*b2 + a5*b1 + a6*b0 - s7 := c7 + a0*b7 + a1*b6 + a2*b5 + a3*b4 + a4*b3 + a5*b2 + a6*b1 + a7*b0 - s8 := c8 + a0*b8 + a1*b7 + a2*b6 + a3*b5 + a4*b4 + a5*b3 + a6*b2 + a7*b1 + a8*b0 - s9 := c9 + a0*b9 + a1*b8 + a2*b7 + a3*b6 + a4*b5 + a5*b4 + a6*b3 + a7*b2 + a8*b1 + a9*b0 - s10 := c10 + a0*b10 + a1*b9 + a2*b8 + a3*b7 + a4*b6 + a5*b5 + a6*b4 + a7*b3 + a8*b2 + a9*b1 + a10*b0 - s11 := c11 + a0*b11 + a1*b10 + a2*b9 + a3*b8 + a4*b7 + a5*b6 + a6*b5 + a7*b4 + a8*b3 + a9*b2 + a10*b1 + a11*b0 - s12 := a1*b11 + a2*b10 + a3*b9 + a4*b8 + a5*b7 + a6*b6 + a7*b5 + a8*b4 + a9*b3 + a10*b2 + a11*b1 - s13 := a2*b11 + a3*b10 + a4*b9 + a5*b8 + a6*b7 + a7*b6 + a8*b5 + a9*b4 + a10*b3 + a11*b2 - s14 := a3*b11 + a4*b10 + a5*b9 + a6*b8 + a7*b7 + a8*b6 + a9*b5 + a10*b4 + a11*b3 - s15 := a4*b11 + a5*b10 + a6*b9 + a7*b8 + a8*b7 + a9*b6 + a10*b5 + a11*b4 - s16 := a5*b11 + a6*b10 + a7*b9 + a8*b8 + a9*b7 + a10*b6 + a11*b5 - s17 := a6*b11 + a7*b10 + a8*b9 + a9*b8 + a10*b7 + a11*b6 - s18 := a7*b11 + a8*b10 + a9*b9 + a10*b8 + a11*b7 - s19 := a8*b11 + a9*b10 + a10*b9 + a11*b8 - s20 := a9*b11 + a10*b10 + a11*b9 - s21 := a10*b11 + a11*b10 - s22 := a11 * b11 - s23 := int64(0) - - carry[0] = (s0 + (1 << 20)) >> 21 - s1 += carry[0] - s0 -= carry[0] << 21 - carry[2] = (s2 + (1 << 20)) >> 21 - s3 += carry[2] - s2 -= carry[2] << 21 - carry[4] = (s4 + (1 << 20)) >> 21 - s5 += carry[4] - s4 -= carry[4] << 21 - carry[6] = (s6 + (1 << 20)) >> 21 - s7 += carry[6] - s6 -= carry[6] << 21 - carry[8] = (s8 + (1 << 20)) >> 21 - s9 += carry[8] - s8 -= carry[8] << 21 - carry[10] = (s10 + (1 << 20)) >> 21 - s11 += carry[10] - s10 -= carry[10] << 21 - carry[12] = (s12 + (1 << 20)) >> 21 - s13 += carry[12] - s12 -= carry[12] << 21 - carry[14] = (s14 + (1 << 20)) >> 21 - s15 += carry[14] - s14 -= carry[14] << 21 - carry[16] = (s16 + (1 << 20)) >> 21 - s17 += carry[16] - s16 -= carry[16] << 21 - carry[18] = (s18 + (1 << 20)) >> 21 - s19 += carry[18] - s18 -= carry[18] << 21 - carry[20] = (s20 + (1 << 20)) >> 21 - s21 += carry[20] - s20 -= carry[20] << 21 - carry[22] = (s22 + (1 << 20)) >> 21 - s23 += carry[22] - s22 -= carry[22] << 21 - - carry[1] = (s1 + (1 << 20)) >> 21 - s2 += carry[1] - s1 -= carry[1] << 21 - carry[3] = (s3 + (1 << 20)) >> 21 - s4 += carry[3] - s3 -= carry[3] << 21 - carry[5] = (s5 + (1 << 20)) >> 21 - s6 += carry[5] - s5 -= carry[5] << 21 - carry[7] = (s7 + (1 << 20)) >> 21 - s8 += carry[7] - s7 -= carry[7] << 21 - carry[9] = (s9 + (1 << 20)) >> 21 - s10 += carry[9] - s9 -= carry[9] << 21 - carry[11] = (s11 + (1 << 20)) >> 21 - s12 += carry[11] - s11 -= carry[11] << 21 - carry[13] = (s13 + (1 << 20)) >> 21 - s14 += carry[13] - s13 -= carry[13] << 21 - carry[15] = (s15 + (1 << 20)) >> 21 - s16 += carry[15] - s15 -= carry[15] << 21 - carry[17] = (s17 + (1 << 20)) >> 21 - s18 += carry[17] - s17 -= carry[17] << 21 - carry[19] = (s19 + (1 << 20)) >> 21 - s20 += carry[19] - s19 -= carry[19] << 21 - carry[21] = (s21 + (1 << 20)) >> 21 - s22 += carry[21] - s21 -= carry[21] << 21 - - s11 += s23 * 666643 - s12 += s23 * 470296 - s13 += s23 * 654183 - s14 -= s23 * 997805 - s15 += s23 * 136657 - s16 -= s23 * 683901 - s23 = 0 - - s10 += s22 * 666643 - s11 += s22 * 470296 - s12 += s22 * 654183 - s13 -= s22 * 997805 - s14 += s22 * 136657 - s15 -= s22 * 683901 - s22 = 0 - - s9 += s21 * 666643 - s10 += s21 * 470296 - s11 += s21 * 654183 - s12 -= s21 * 997805 - s13 += s21 * 136657 - s14 -= s21 * 683901 - s21 = 0 - - s8 += s20 * 666643 - s9 += s20 * 470296 - s10 += s20 * 654183 - s11 -= s20 * 997805 - s12 += s20 * 136657 - s13 -= s20 * 683901 - s20 = 0 - - s7 += s19 * 666643 - s8 += s19 * 470296 - s9 += s19 * 654183 - s10 -= s19 * 997805 - s11 += s19 * 136657 - s12 -= s19 * 683901 - s19 = 0 - - s6 += s18 * 666643 - s7 += s18 * 470296 - s8 += s18 * 654183 - s9 -= s18 * 997805 - s10 += s18 * 136657 - s11 -= s18 * 683901 - s18 = 0 - - carry[6] = (s6 + (1 << 20)) >> 21 - s7 += carry[6] - s6 -= carry[6] << 21 - carry[8] = (s8 + (1 << 20)) >> 21 - s9 += carry[8] - s8 -= carry[8] << 21 - carry[10] = (s10 + (1 << 20)) >> 21 - s11 += carry[10] - s10 -= carry[10] << 21 - carry[12] = (s12 + (1 << 20)) >> 21 - s13 += carry[12] - s12 -= carry[12] << 21 - carry[14] = (s14 + (1 << 20)) >> 21 - s15 += carry[14] - s14 -= carry[14] << 21 - carry[16] = (s16 + (1 << 20)) >> 21 - s17 += carry[16] - s16 -= carry[16] << 21 - - carry[7] = (s7 + (1 << 20)) >> 21 - s8 += carry[7] - s7 -= carry[7] << 21 - carry[9] = (s9 + (1 << 20)) >> 21 - s10 += carry[9] - s9 -= carry[9] << 21 - carry[11] = (s11 + (1 << 20)) >> 21 - s12 += carry[11] - s11 -= carry[11] << 21 - carry[13] = (s13 + (1 << 20)) >> 21 - s14 += carry[13] - s13 -= carry[13] << 21 - carry[15] = (s15 + (1 << 20)) >> 21 - s16 += carry[15] - s15 -= carry[15] << 21 - - s5 += s17 * 666643 - s6 += s17 * 470296 - s7 += s17 * 654183 - s8 -= s17 * 997805 - s9 += s17 * 136657 - s10 -= s17 * 683901 - s17 = 0 - - s4 += s16 * 666643 - s5 += s16 * 470296 - s6 += s16 * 654183 - s7 -= s16 * 997805 - s8 += s16 * 136657 - s9 -= s16 * 683901 - s16 = 0 - - s3 += s15 * 666643 - s4 += s15 * 470296 - s5 += s15 * 654183 - s6 -= s15 * 997805 - s7 += s15 * 136657 - s8 -= s15 * 683901 - s15 = 0 - - s2 += s14 * 666643 - s3 += s14 * 470296 - s4 += s14 * 654183 - s5 -= s14 * 997805 - s6 += s14 * 136657 - s7 -= s14 * 683901 - s14 = 0 - - s1 += s13 * 666643 - s2 += s13 * 470296 - s3 += s13 * 654183 - s4 -= s13 * 997805 - s5 += s13 * 136657 - s6 -= s13 * 683901 - s13 = 0 - - s0 += s12 * 666643 - s1 += s12 * 470296 - s2 += s12 * 654183 - s3 -= s12 * 997805 - s4 += s12 * 136657 - s5 -= s12 * 683901 - s12 = 0 - - carry[0] = (s0 + (1 << 20)) >> 21 - s1 += carry[0] - s0 -= carry[0] << 21 - carry[2] = (s2 + (1 << 20)) >> 21 - s3 += carry[2] - s2 -= carry[2] << 21 - carry[4] = (s4 + (1 << 20)) >> 21 - s5 += carry[4] - s4 -= carry[4] << 21 - carry[6] = (s6 + (1 << 20)) >> 21 - s7 += carry[6] - s6 -= carry[6] << 21 - carry[8] = (s8 + (1 << 20)) >> 21 - s9 += carry[8] - s8 -= carry[8] << 21 - carry[10] = (s10 + (1 << 20)) >> 21 - s11 += carry[10] - s10 -= carry[10] << 21 - - carry[1] = (s1 + (1 << 20)) >> 21 - s2 += carry[1] - s1 -= carry[1] << 21 - carry[3] = (s3 + (1 << 20)) >> 21 - s4 += carry[3] - s3 -= carry[3] << 21 - carry[5] = (s5 + (1 << 20)) >> 21 - s6 += carry[5] - s5 -= carry[5] << 21 - carry[7] = (s7 + (1 << 20)) >> 21 - s8 += carry[7] - s7 -= carry[7] << 21 - carry[9] = (s9 + (1 << 20)) >> 21 - s10 += carry[9] - s9 -= carry[9] << 21 - carry[11] = (s11 + (1 << 20)) >> 21 - s12 += carry[11] - s11 -= carry[11] << 21 - - s0 += s12 * 666643 - s1 += s12 * 470296 - s2 += s12 * 654183 - s3 -= s12 * 997805 - s4 += s12 * 136657 - s5 -= s12 * 683901 - s12 = 0 - - carry[0] = s0 >> 21 - s1 += carry[0] - s0 -= carry[0] << 21 - carry[1] = s1 >> 21 - s2 += carry[1] - s1 -= carry[1] << 21 - carry[2] = s2 >> 21 - s3 += carry[2] - s2 -= carry[2] << 21 - carry[3] = s3 >> 21 - s4 += carry[3] - s3 -= carry[3] << 21 - carry[4] = s4 >> 21 - s5 += carry[4] - s4 -= carry[4] << 21 - carry[5] = s5 >> 21 - s6 += carry[5] - s5 -= carry[5] << 21 - carry[6] = s6 >> 21 - s7 += carry[6] - s6 -= carry[6] << 21 - carry[7] = s7 >> 21 - s8 += carry[7] - s7 -= carry[7] << 21 - carry[8] = s8 >> 21 - s9 += carry[8] - s8 -= carry[8] << 21 - carry[9] = s9 >> 21 - s10 += carry[9] - s9 -= carry[9] << 21 - carry[10] = s10 >> 21 - s11 += carry[10] - s10 -= carry[10] << 21 - carry[11] = s11 >> 21 - s12 += carry[11] - s11 -= carry[11] << 21 - - s0 += s12 * 666643 - s1 += s12 * 470296 - s2 += s12 * 654183 - s3 -= s12 * 997805 - s4 += s12 * 136657 - s5 -= s12 * 683901 - s12 = 0 - - carry[0] = s0 >> 21 - s1 += carry[0] - s0 -= carry[0] << 21 - carry[1] = s1 >> 21 - s2 += carry[1] - s1 -= carry[1] << 21 - carry[2] = s2 >> 21 - s3 += carry[2] - s2 -= carry[2] << 21 - carry[3] = s3 >> 21 - s4 += carry[3] - s3 -= carry[3] << 21 - carry[4] = s4 >> 21 - s5 += carry[4] - s4 -= carry[4] << 21 - carry[5] = s5 >> 21 - s6 += carry[5] - s5 -= carry[5] << 21 - carry[6] = s6 >> 21 - s7 += carry[6] - s6 -= carry[6] << 21 - carry[7] = s7 >> 21 - s8 += carry[7] - s7 -= carry[7] << 21 - carry[8] = s8 >> 21 - s9 += carry[8] - s8 -= carry[8] << 21 - carry[9] = s9 >> 21 - s10 += carry[9] - s9 -= carry[9] << 21 - carry[10] = s10 >> 21 - s11 += carry[10] - s10 -= carry[10] << 21 - - s[0] = byte(s0 >> 0) - s[1] = byte(s0 >> 8) - s[2] = byte((s0 >> 16) | (s1 << 5)) - s[3] = byte(s1 >> 3) - s[4] = byte(s1 >> 11) - s[5] = byte((s1 >> 19) | (s2 << 2)) - s[6] = byte(s2 >> 6) - s[7] = byte((s2 >> 14) | (s3 << 7)) - s[8] = byte(s3 >> 1) - s[9] = byte(s3 >> 9) - s[10] = byte((s3 >> 17) | (s4 << 4)) - s[11] = byte(s4 >> 4) - s[12] = byte(s4 >> 12) - s[13] = byte((s4 >> 20) | (s5 << 1)) - s[14] = byte(s5 >> 7) - s[15] = byte((s5 >> 15) | (s6 << 6)) - s[16] = byte(s6 >> 2) - s[17] = byte(s6 >> 10) - s[18] = byte((s6 >> 18) | (s7 << 3)) - s[19] = byte(s7 >> 5) - s[20] = byte(s7 >> 13) - s[21] = byte(s8 >> 0) - s[22] = byte(s8 >> 8) - s[23] = byte((s8 >> 16) | (s9 << 5)) - s[24] = byte(s9 >> 3) - s[25] = byte(s9 >> 11) - s[26] = byte((s9 >> 19) | (s10 << 2)) - s[27] = byte(s10 >> 6) - s[28] = byte((s10 >> 14) | (s11 << 7)) - s[29] = byte(s11 >> 1) - s[30] = byte(s11 >> 9) - s[31] = byte(s11 >> 17) -} - -// Input: -// s[0]+256*s[1]+...+256^63*s[63] = s -// -// Output: -// s[0]+256*s[1]+...+256^31*s[31] = s mod l -// where l = 2^252 + 27742317777372353535851937790883648493. -func ScReduce(out *[32]byte, s *[64]byte) { - s0 := 2097151 & load3(s[:]) - s1 := 2097151 & (load4(s[2:]) >> 5) - s2 := 2097151 & (load3(s[5:]) >> 2) - s3 := 2097151 & (load4(s[7:]) >> 7) - s4 := 2097151 & (load4(s[10:]) >> 4) - s5 := 2097151 & (load3(s[13:]) >> 1) - s6 := 2097151 & (load4(s[15:]) >> 6) - s7 := 2097151 & (load3(s[18:]) >> 3) - s8 := 2097151 & load3(s[21:]) - s9 := 2097151 & (load4(s[23:]) >> 5) - s10 := 2097151 & (load3(s[26:]) >> 2) - s11 := 2097151 & (load4(s[28:]) >> 7) - s12 := 2097151 & (load4(s[31:]) >> 4) - s13 := 2097151 & (load3(s[34:]) >> 1) - s14 := 2097151 & (load4(s[36:]) >> 6) - s15 := 2097151 & (load3(s[39:]) >> 3) - s16 := 2097151 & load3(s[42:]) - s17 := 2097151 & (load4(s[44:]) >> 5) - s18 := 2097151 & (load3(s[47:]) >> 2) - s19 := 2097151 & (load4(s[49:]) >> 7) - s20 := 2097151 & (load4(s[52:]) >> 4) - s21 := 2097151 & (load3(s[55:]) >> 1) - s22 := 2097151 & (load4(s[57:]) >> 6) - s23 := (load4(s[60:]) >> 3) - - s11 += s23 * 666643 - s12 += s23 * 470296 - s13 += s23 * 654183 - s14 -= s23 * 997805 - s15 += s23 * 136657 - s16 -= s23 * 683901 - s23 = 0 - - s10 += s22 * 666643 - s11 += s22 * 470296 - s12 += s22 * 654183 - s13 -= s22 * 997805 - s14 += s22 * 136657 - s15 -= s22 * 683901 - s22 = 0 - - s9 += s21 * 666643 - s10 += s21 * 470296 - s11 += s21 * 654183 - s12 -= s21 * 997805 - s13 += s21 * 136657 - s14 -= s21 * 683901 - s21 = 0 - - s8 += s20 * 666643 - s9 += s20 * 470296 - s10 += s20 * 654183 - s11 -= s20 * 997805 - s12 += s20 * 136657 - s13 -= s20 * 683901 - s20 = 0 - - s7 += s19 * 666643 - s8 += s19 * 470296 - s9 += s19 * 654183 - s10 -= s19 * 997805 - s11 += s19 * 136657 - s12 -= s19 * 683901 - s19 = 0 - - s6 += s18 * 666643 - s7 += s18 * 470296 - s8 += s18 * 654183 - s9 -= s18 * 997805 - s10 += s18 * 136657 - s11 -= s18 * 683901 - s18 = 0 - - var carry [17]int64 - - carry[6] = (s6 + (1 << 20)) >> 21 - s7 += carry[6] - s6 -= carry[6] << 21 - carry[8] = (s8 + (1 << 20)) >> 21 - s9 += carry[8] - s8 -= carry[8] << 21 - carry[10] = (s10 + (1 << 20)) >> 21 - s11 += carry[10] - s10 -= carry[10] << 21 - carry[12] = (s12 + (1 << 20)) >> 21 - s13 += carry[12] - s12 -= carry[12] << 21 - carry[14] = (s14 + (1 << 20)) >> 21 - s15 += carry[14] - s14 -= carry[14] << 21 - carry[16] = (s16 + (1 << 20)) >> 21 - s17 += carry[16] - s16 -= carry[16] << 21 - - carry[7] = (s7 + (1 << 20)) >> 21 - s8 += carry[7] - s7 -= carry[7] << 21 - carry[9] = (s9 + (1 << 20)) >> 21 - s10 += carry[9] - s9 -= carry[9] << 21 - carry[11] = (s11 + (1 << 20)) >> 21 - s12 += carry[11] - s11 -= carry[11] << 21 - carry[13] = (s13 + (1 << 20)) >> 21 - s14 += carry[13] - s13 -= carry[13] << 21 - carry[15] = (s15 + (1 << 20)) >> 21 - s16 += carry[15] - s15 -= carry[15] << 21 - - s5 += s17 * 666643 - s6 += s17 * 470296 - s7 += s17 * 654183 - s8 -= s17 * 997805 - s9 += s17 * 136657 - s10 -= s17 * 683901 - s17 = 0 - - s4 += s16 * 666643 - s5 += s16 * 470296 - s6 += s16 * 654183 - s7 -= s16 * 997805 - s8 += s16 * 136657 - s9 -= s16 * 683901 - s16 = 0 - - s3 += s15 * 666643 - s4 += s15 * 470296 - s5 += s15 * 654183 - s6 -= s15 * 997805 - s7 += s15 * 136657 - s8 -= s15 * 683901 - s15 = 0 - - s2 += s14 * 666643 - s3 += s14 * 470296 - s4 += s14 * 654183 - s5 -= s14 * 997805 - s6 += s14 * 136657 - s7 -= s14 * 683901 - s14 = 0 - - s1 += s13 * 666643 - s2 += s13 * 470296 - s3 += s13 * 654183 - s4 -= s13 * 997805 - s5 += s13 * 136657 - s6 -= s13 * 683901 - s13 = 0 - - s0 += s12 * 666643 - s1 += s12 * 470296 - s2 += s12 * 654183 - s3 -= s12 * 997805 - s4 += s12 * 136657 - s5 -= s12 * 683901 - s12 = 0 - - carry[0] = (s0 + (1 << 20)) >> 21 - s1 += carry[0] - s0 -= carry[0] << 21 - carry[2] = (s2 + (1 << 20)) >> 21 - s3 += carry[2] - s2 -= carry[2] << 21 - carry[4] = (s4 + (1 << 20)) >> 21 - s5 += carry[4] - s4 -= carry[4] << 21 - carry[6] = (s6 + (1 << 20)) >> 21 - s7 += carry[6] - s6 -= carry[6] << 21 - carry[8] = (s8 + (1 << 20)) >> 21 - s9 += carry[8] - s8 -= carry[8] << 21 - carry[10] = (s10 + (1 << 20)) >> 21 - s11 += carry[10] - s10 -= carry[10] << 21 - - carry[1] = (s1 + (1 << 20)) >> 21 - s2 += carry[1] - s1 -= carry[1] << 21 - carry[3] = (s3 + (1 << 20)) >> 21 - s4 += carry[3] - s3 -= carry[3] << 21 - carry[5] = (s5 + (1 << 20)) >> 21 - s6 += carry[5] - s5 -= carry[5] << 21 - carry[7] = (s7 + (1 << 20)) >> 21 - s8 += carry[7] - s7 -= carry[7] << 21 - carry[9] = (s9 + (1 << 20)) >> 21 - s10 += carry[9] - s9 -= carry[9] << 21 - carry[11] = (s11 + (1 << 20)) >> 21 - s12 += carry[11] - s11 -= carry[11] << 21 - - s0 += s12 * 666643 - s1 += s12 * 470296 - s2 += s12 * 654183 - s3 -= s12 * 997805 - s4 += s12 * 136657 - s5 -= s12 * 683901 - s12 = 0 - - carry[0] = s0 >> 21 - s1 += carry[0] - s0 -= carry[0] << 21 - carry[1] = s1 >> 21 - s2 += carry[1] - s1 -= carry[1] << 21 - carry[2] = s2 >> 21 - s3 += carry[2] - s2 -= carry[2] << 21 - carry[3] = s3 >> 21 - s4 += carry[3] - s3 -= carry[3] << 21 - carry[4] = s4 >> 21 - s5 += carry[4] - s4 -= carry[4] << 21 - carry[5] = s5 >> 21 - s6 += carry[5] - s5 -= carry[5] << 21 - carry[6] = s6 >> 21 - s7 += carry[6] - s6 -= carry[6] << 21 - carry[7] = s7 >> 21 - s8 += carry[7] - s7 -= carry[7] << 21 - carry[8] = s8 >> 21 - s9 += carry[8] - s8 -= carry[8] << 21 - carry[9] = s9 >> 21 - s10 += carry[9] - s9 -= carry[9] << 21 - carry[10] = s10 >> 21 - s11 += carry[10] - s10 -= carry[10] << 21 - carry[11] = s11 >> 21 - s12 += carry[11] - s11 -= carry[11] << 21 - - s0 += s12 * 666643 - s1 += s12 * 470296 - s2 += s12 * 654183 - s3 -= s12 * 997805 - s4 += s12 * 136657 - s5 -= s12 * 683901 - s12 = 0 - - carry[0] = s0 >> 21 - s1 += carry[0] - s0 -= carry[0] << 21 - carry[1] = s1 >> 21 - s2 += carry[1] - s1 -= carry[1] << 21 - carry[2] = s2 >> 21 - s3 += carry[2] - s2 -= carry[2] << 21 - carry[3] = s3 >> 21 - s4 += carry[3] - s3 -= carry[3] << 21 - carry[4] = s4 >> 21 - s5 += carry[4] - s4 -= carry[4] << 21 - carry[5] = s5 >> 21 - s6 += carry[5] - s5 -= carry[5] << 21 - carry[6] = s6 >> 21 - s7 += carry[6] - s6 -= carry[6] << 21 - carry[7] = s7 >> 21 - s8 += carry[7] - s7 -= carry[7] << 21 - carry[8] = s8 >> 21 - s9 += carry[8] - s8 -= carry[8] << 21 - carry[9] = s9 >> 21 - s10 += carry[9] - s9 -= carry[9] << 21 - carry[10] = s10 >> 21 - s11 += carry[10] - s10 -= carry[10] << 21 - - out[0] = byte(s0 >> 0) - out[1] = byte(s0 >> 8) - out[2] = byte((s0 >> 16) | (s1 << 5)) - out[3] = byte(s1 >> 3) - out[4] = byte(s1 >> 11) - out[5] = byte((s1 >> 19) | (s2 << 2)) - out[6] = byte(s2 >> 6) - out[7] = byte((s2 >> 14) | (s3 << 7)) - out[8] = byte(s3 >> 1) - out[9] = byte(s3 >> 9) - out[10] = byte((s3 >> 17) | (s4 << 4)) - out[11] = byte(s4 >> 4) - out[12] = byte(s4 >> 12) - out[13] = byte((s4 >> 20) | (s5 << 1)) - out[14] = byte(s5 >> 7) - out[15] = byte((s5 >> 15) | (s6 << 6)) - out[16] = byte(s6 >> 2) - out[17] = byte(s6 >> 10) - out[18] = byte((s6 >> 18) | (s7 << 3)) - out[19] = byte(s7 >> 5) - out[20] = byte(s7 >> 13) - out[21] = byte(s8 >> 0) - out[22] = byte(s8 >> 8) - out[23] = byte((s8 >> 16) | (s9 << 5)) - out[24] = byte(s9 >> 3) - out[25] = byte(s9 >> 11) - out[26] = byte((s9 >> 19) | (s10 << 2)) - out[27] = byte(s10 >> 6) - out[28] = byte((s10 >> 14) | (s11 << 7)) - out[29] = byte(s11 >> 1) - out[30] = byte(s11 >> 9) - out[31] = byte(s11 >> 17) -} - -// order is the order of Curve25519 in little-endian form. -var order = [4]uint64{0x5812631a5cf5d3ed, 0x14def9dea2f79cd6, 0, 0x1000000000000000} - -// ScMinimal returns true if the given scalar is less than the order of the -// curve. -func ScMinimal(scalar *[32]byte) bool { - for i := 3; ; i-- { - v := binary.LittleEndian.Uint64(scalar[i*8:]) - if v > order[i] { - return false - } else if v < order[i] { - break - } else if i == 0 { - return false - } - } - - return true -} diff --git a/src/cmd/vendor/golang.org/x/sys/plan9/syscall_plan9.go b/src/cmd/vendor/golang.org/x/sys/plan9/syscall_plan9.go index 84e14714811..723b1f4002a 100644 --- a/src/cmd/vendor/golang.org/x/sys/plan9/syscall_plan9.go +++ b/src/cmd/vendor/golang.org/x/sys/plan9/syscall_plan9.go @@ -132,8 +132,10 @@ func Pipe(p []int) (err error) { } var pp [2]int32 err = pipe(&pp) - p[0] = int(pp[0]) - p[1] = int(pp[1]) + if err == nil { + p[0] = int(pp[0]) + p[1] = int(pp[1]) + } return } diff --git a/src/cmd/vendor/golang.org/x/sys/unix/ioctl_linux.go b/src/cmd/vendor/golang.org/x/sys/unix/ioctl_linux.go index 1dadead21e6..884430b810c 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/ioctl_linux.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/ioctl_linux.go @@ -194,3 +194,26 @@ func ioctlIfreqData(fd int, req uint, value *ifreqData) error { // identical so pass *IfreqData directly. return ioctlPtr(fd, req, unsafe.Pointer(value)) } + +// IoctlKCMClone attaches a new file descriptor to a multiplexor by cloning an +// existing KCM socket, returning a structure containing the file descriptor of +// the new socket. +func IoctlKCMClone(fd int) (*KCMClone, error) { + var info KCMClone + if err := ioctlPtr(fd, SIOCKCMCLONE, unsafe.Pointer(&info)); err != nil { + return nil, err + } + + return &info, nil +} + +// IoctlKCMAttach attaches a TCP socket and associated BPF program file +// descriptor to a multiplexor. +func IoctlKCMAttach(fd int, info KCMAttach) error { + return ioctlPtr(fd, SIOCKCMATTACH, unsafe.Pointer(&info)) +} + +// IoctlKCMUnattach unattaches a TCP socket file descriptor from a multiplexor. +func IoctlKCMUnattach(fd int, info KCMUnattach) error { + return ioctlPtr(fd, SIOCKCMUNATTACH, unsafe.Pointer(&info)) +} diff --git a/src/cmd/vendor/golang.org/x/sys/unix/mkerrors.sh b/src/cmd/vendor/golang.org/x/sys/unix/mkerrors.sh index 4945739ea0a..a037087481d 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/mkerrors.sh +++ b/src/cmd/vendor/golang.org/x/sys/unix/mkerrors.sh @@ -205,6 +205,7 @@ struct ltchars { #include #include #include +#include #include #include #include @@ -231,6 +232,7 @@ struct ltchars { #include #include #include +#include #include #include #include @@ -261,6 +263,7 @@ struct ltchars { #include #include #include +#include #include #include @@ -502,6 +505,7 @@ ccflags="$@" $2 ~ /^O?XTABS$/ || $2 ~ /^TC[IO](ON|OFF)$/ || $2 ~ /^IN_/ || + $2 ~ /^KCM/ || $2 ~ /^LANDLOCK_/ || $2 ~ /^LOCK_(SH|EX|NB|UN)$/ || $2 ~ /^LO_(KEY|NAME)_SIZE$/ || @@ -596,6 +600,7 @@ ccflags="$@" $2 ~ /^DEVLINK_/ || $2 ~ /^ETHTOOL_/ || $2 ~ /^LWTUNNEL_IP/ || + $2 ~ /^ITIMER_/ || $2 !~ "WMESGLEN" && $2 ~ /^W[A-Z0-9]+$/ || $2 ~/^PPPIOC/ || @@ -606,6 +611,7 @@ ccflags="$@" $2 ~ /^MTD/ || $2 ~ /^OTP/ || $2 ~ /^MEM/ || + $2 ~ /^WG/ || $2 ~ /^BLK[A-Z]*(GET$|SET$|BUF$|PART$|SIZE)/ {printf("\t%s = C.%s\n", $2, $2)} $2 ~ /^__WCOREFLAG$/ {next} $2 ~ /^__W[A-Z0-9]+$/ {printf("\t%s = C.%s\n", substr($2,3), $2)} diff --git a/src/cmd/vendor/golang.org/x/sys/unix/syscall_aix.go b/src/cmd/vendor/golang.org/x/sys/unix/syscall_aix.go index 6192750ce31..f2a114fc27b 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/syscall_aix.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/syscall_aix.go @@ -215,18 +215,12 @@ func Accept(fd int) (nfd int, sa Sockaddr, err error) { return } -func Recvmsg(fd int, p, oob []byte, flags int) (n, oobn int, recvflags int, from Sockaddr, err error) { +func recvmsgRaw(fd int, p, oob []byte, flags int, rsa *RawSockaddrAny) (n, oobn int, recvflags int, err error) { // Recvmsg not implemented on AIX - sa := new(SockaddrUnix) - return -1, -1, -1, sa, ENOSYS + return -1, -1, -1, ENOSYS } -func Sendmsg(fd int, p, oob []byte, to Sockaddr, flags int) (err error) { - _, err = SendmsgN(fd, p, oob, to, flags) - return -} - -func SendmsgN(fd int, p, oob []byte, to Sockaddr, flags int) (n int, err error) { +func sendmsgN(fd int, p, oob []byte, ptr unsafe.Pointer, salen _Socklen, flags int) (n int, err error) { // SendmsgN not implemented on AIX return -1, ENOSYS } @@ -458,8 +452,8 @@ func Fsync(fd int) error { //sys Listen(s int, n int) (err error) //sys lstat(path string, stat *Stat_t) (err error) //sys Pause() (err error) -//sys Pread(fd int, p []byte, offset int64) (n int, err error) = pread64 -//sys Pwrite(fd int, p []byte, offset int64) (n int, err error) = pwrite64 +//sys pread(fd int, p []byte, offset int64) (n int, err error) = pread64 +//sys pwrite(fd int, p []byte, offset int64) (n int, err error) = pwrite64 //sys Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error) //sys Pselect(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timespec, sigmask *Sigset_t) (n int, err error) //sysnb Setregid(rgid int, egid int) (err error) @@ -519,8 +513,10 @@ func Pipe(p []int) (err error) { } var pp [2]_C_int err = pipe(&pp) - p[0] = int(pp[0]) - p[1] = int(pp[1]) + if err == nil { + p[0] = int(pp[0]) + p[1] = int(pp[1]) + } return } diff --git a/src/cmd/vendor/golang.org/x/sys/unix/syscall_bsd.go b/src/cmd/vendor/golang.org/x/sys/unix/syscall_bsd.go index 0ce45232611..a801b1b1b84 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/syscall_bsd.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/syscall_bsd.go @@ -325,10 +325,9 @@ func GetsockoptString(fd, level, opt int) (string, error) { //sys sendto(s int, buf []byte, flags int, to unsafe.Pointer, addrlen _Socklen) (err error) //sys recvmsg(s int, msg *Msghdr, flags int) (n int, err error) -func Recvmsg(fd int, p, oob []byte, flags int) (n, oobn int, recvflags int, from Sockaddr, err error) { +func recvmsgRaw(fd int, p, oob []byte, flags int, rsa *RawSockaddrAny) (n, oobn int, recvflags int, err error) { var msg Msghdr - var rsa RawSockaddrAny - msg.Name = (*byte)(unsafe.Pointer(&rsa)) + msg.Name = (*byte)(unsafe.Pointer(rsa)) msg.Namelen = uint32(SizeofSockaddrAny) var iov Iovec if len(p) > 0 { @@ -352,29 +351,12 @@ func Recvmsg(fd int, p, oob []byte, flags int) (n, oobn int, recvflags int, from } oobn = int(msg.Controllen) recvflags = int(msg.Flags) - // source address is only specified if the socket is unconnected - if rsa.Addr.Family != AF_UNSPEC { - from, err = anyToSockaddr(fd, &rsa) - } return } //sys sendmsg(s int, msg *Msghdr, flags int) (n int, err error) -func Sendmsg(fd int, p, oob []byte, to Sockaddr, flags int) (err error) { - _, err = SendmsgN(fd, p, oob, to, flags) - return -} - -func SendmsgN(fd int, p, oob []byte, to Sockaddr, flags int) (n int, err error) { - var ptr unsafe.Pointer - var salen _Socklen - if to != nil { - ptr, salen, err = to.sockaddr() - if err != nil { - return 0, err - } - } +func sendmsgN(fd int, p, oob []byte, ptr unsafe.Pointer, salen _Socklen, flags int) (n int, err error) { var msg Msghdr msg.Name = (*byte)(unsafe.Pointer(ptr)) msg.Namelen = uint32(salen) diff --git a/src/cmd/vendor/golang.org/x/sys/unix/syscall_darwin.go b/src/cmd/vendor/golang.org/x/sys/unix/syscall_darwin.go index 8826f41435e..ca2ae357195 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/syscall_darwin.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/syscall_darwin.go @@ -159,8 +159,10 @@ func Pipe(p []int) (err error) { } var x [2]int32 err = pipe(&x) - p[0] = int(x[0]) - p[1] = int(x[1]) + if err == nil { + p[0] = int(x[0]) + p[1] = int(x[1]) + } return } @@ -544,8 +546,8 @@ func SysctlKinfoProcSlice(name string, args ...int) ([]KinfoProc, error) { //sys Open(path string, mode int, perm uint32) (fd int, err error) //sys Openat(dirfd int, path string, mode int, perm uint32) (fd int, err error) //sys Pathconf(path string, name int) (val int, err error) -//sys Pread(fd int, p []byte, offset int64) (n int, err error) -//sys Pwrite(fd int, p []byte, offset int64) (n int, err error) +//sys pread(fd int, p []byte, offset int64) (n int, err error) +//sys pwrite(fd int, p []byte, offset int64) (n int, err error) //sys read(fd int, p []byte) (n int, err error) //sys Readlink(path string, buf []byte) (n int, err error) //sys Readlinkat(dirfd int, path string, buf []byte) (n int, err error) diff --git a/src/cmd/vendor/golang.org/x/sys/unix/syscall_dragonfly.go b/src/cmd/vendor/golang.org/x/sys/unix/syscall_dragonfly.go index 5af108a5038..36c268b3525 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/syscall_dragonfly.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/syscall_dragonfly.go @@ -101,7 +101,10 @@ func Pipe(p []int) (err error) { if len(p) != 2 { return EINVAL } - p[0], p[1], err = pipe() + r, w, err := pipe() + if err == nil { + p[0], p[1] = r, w + } return } @@ -114,17 +117,20 @@ func Pipe2(p []int, flags int) (err error) { var pp [2]_C_int // pipe2 on dragonfly takes an fds array as an argument, but still // returns the file descriptors. - p[0], p[1], err = pipe2(&pp, flags) + r, w, err := pipe2(&pp, flags) + if err == nil { + p[0], p[1] = r, w + } return err } //sys extpread(fd int, p []byte, flags int, offset int64) (n int, err error) -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { return extpread(fd, p, 0, offset) } //sys extpwrite(fd int, p []byte, flags int, offset int64) (n int, err error) -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { return extpwrite(fd, p, 0, offset) } diff --git a/src/cmd/vendor/golang.org/x/sys/unix/syscall_freebsd.go b/src/cmd/vendor/golang.org/x/sys/unix/syscall_freebsd.go index 18c392cf369..ac3db019b59 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/syscall_freebsd.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/syscall_freebsd.go @@ -110,8 +110,10 @@ func Pipe2(p []int, flags int) error { } var pp [2]_C_int err := pipe2(&pp, flags) - p[0] = int(pp[0]) - p[1] = int(pp[1]) + if err == nil { + p[0] = int(pp[0]) + p[1] = int(pp[1]) + } return err } @@ -636,8 +638,8 @@ func PtraceSingleStep(pid int) (err error) { //sys Open(path string, mode int, perm uint32) (fd int, err error) //sys Openat(fdat int, path string, mode int, perm uint32) (fd int, err error) //sys Pathconf(path string, name int) (val int, err error) -//sys Pread(fd int, p []byte, offset int64) (n int, err error) -//sys Pwrite(fd int, p []byte, offset int64) (n int, err error) +//sys pread(fd int, p []byte, offset int64) (n int, err error) +//sys pwrite(fd int, p []byte, offset int64) (n int, err error) //sys read(fd int, p []byte) (n int, err error) //sys Readlink(path string, buf []byte) (n int, err error) //sys Readlinkat(dirfd int, path string, buf []byte) (n int, err error) diff --git a/src/cmd/vendor/golang.org/x/sys/unix/syscall_linux.go b/src/cmd/vendor/golang.org/x/sys/unix/syscall_linux.go index 4bc5baf77d9..d7a94e767de 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/syscall_linux.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/syscall_linux.go @@ -14,6 +14,7 @@ package unix import ( "encoding/binary" "syscall" + "time" "unsafe" ) @@ -131,8 +132,10 @@ func Pipe2(p []int, flags int) error { } var pp [2]_C_int err := pipe2(&pp, flags) - p[0] = int(pp[0]) - p[1] = int(pp[1]) + if err == nil { + p[0] = int(pp[0]) + p[1] = int(pp[1]) + } return err } @@ -247,6 +250,13 @@ func Getwd() (wd string, err error) { if n < 1 || n > len(buf) || buf[n-1] != 0 { return "", EINVAL } + // In some cases, Linux can return a path that starts with the + // "(unreachable)" prefix, which can potentially be a valid relative + // path. To work around that, return ENOENT if path is not absolute. + if buf[0] != '/' { + return "", ENOENT + } + return string(buf[0 : n-1]), nil } @@ -1487,10 +1497,9 @@ func KeyctlRestrictKeyring(ringid int, keyType string, restriction string) error //sys keyctlRestrictKeyringByType(cmd int, arg2 int, keyType string, restriction string) (err error) = SYS_KEYCTL //sys keyctlRestrictKeyring(cmd int, arg2 int) (err error) = SYS_KEYCTL -func Recvmsg(fd int, p, oob []byte, flags int) (n, oobn int, recvflags int, from Sockaddr, err error) { +func recvmsgRaw(fd int, p, oob []byte, flags int, rsa *RawSockaddrAny) (n, oobn int, recvflags int, err error) { var msg Msghdr - var rsa RawSockaddrAny - msg.Name = (*byte)(unsafe.Pointer(&rsa)) + msg.Name = (*byte)(unsafe.Pointer(rsa)) msg.Namelen = uint32(SizeofSockaddrAny) var iov Iovec if len(p) > 0 { @@ -1521,28 +1530,10 @@ func Recvmsg(fd int, p, oob []byte, flags int) (n, oobn int, recvflags int, from } oobn = int(msg.Controllen) recvflags = int(msg.Flags) - // source address is only specified if the socket is unconnected - if rsa.Addr.Family != AF_UNSPEC { - from, err = anyToSockaddr(fd, &rsa) - } return } -func Sendmsg(fd int, p, oob []byte, to Sockaddr, flags int) (err error) { - _, err = SendmsgN(fd, p, oob, to, flags) - return -} - -func SendmsgN(fd int, p, oob []byte, to Sockaddr, flags int) (n int, err error) { - var ptr unsafe.Pointer - var salen _Socklen - if to != nil { - var err error - ptr, salen, err = to.sockaddr() - if err != nil { - return 0, err - } - } +func sendmsgN(fd int, p, oob []byte, ptr unsafe.Pointer, salen _Socklen, flags int) (n int, err error) { var msg Msghdr msg.Name = (*byte)(ptr) msg.Namelen = uint32(salen) @@ -2312,11 +2303,56 @@ type RemoteIovec struct { //sys shmdt(addr uintptr) (err error) //sys shmget(key int, size int, flag int) (id int, err error) +//sys getitimer(which int, currValue *Itimerval) (err error) +//sys setitimer(which int, newValue *Itimerval, oldValue *Itimerval) (err error) + +// MakeItimerval creates an Itimerval from interval and value durations. +func MakeItimerval(interval, value time.Duration) Itimerval { + return Itimerval{ + Interval: NsecToTimeval(interval.Nanoseconds()), + Value: NsecToTimeval(value.Nanoseconds()), + } +} + +// A value which may be passed to the which parameter for Getitimer and +// Setitimer. +type ItimerWhich int + +// Possible which values for Getitimer and Setitimer. +const ( + ItimerReal ItimerWhich = ITIMER_REAL + ItimerVirtual ItimerWhich = ITIMER_VIRTUAL + ItimerProf ItimerWhich = ITIMER_PROF +) + +// Getitimer wraps getitimer(2) to return the current value of the timer +// specified by which. +func Getitimer(which ItimerWhich) (Itimerval, error) { + var it Itimerval + if err := getitimer(int(which), &it); err != nil { + return Itimerval{}, err + } + + return it, nil +} + +// Setitimer wraps setitimer(2) to arm or disarm the timer specified by which. +// It returns the previous value of the timer. +// +// If the Itimerval argument is the zero value, the timer will be disarmed. +func Setitimer(which ItimerWhich, it Itimerval) (Itimerval, error) { + var prev Itimerval + if err := setitimer(int(which), &it, &prev); err != nil { + return Itimerval{}, err + } + + return prev, nil +} + /* * Unimplemented */ // AfsSyscall -// Alarm // ArchPrctl // Brk // ClockNanosleep @@ -2332,7 +2368,6 @@ type RemoteIovec struct { // GetMempolicy // GetRobustList // GetThreadArea -// Getitimer // Getpmsg // IoCancel // IoDestroy diff --git a/src/cmd/vendor/golang.org/x/sys/unix/syscall_linux_386.go b/src/cmd/vendor/golang.org/x/sys/unix/syscall_linux_386.go index 5f757e8aa77..518e476e6dd 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/syscall_linux_386.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/syscall_linux_386.go @@ -35,8 +35,8 @@ func setTimeval(sec, usec int64) Timeval { //sys Iopl(level int) (err error) //sys Lchown(path string, uid int, gid int) (err error) = SYS_LCHOWN32 //sys Lstat(path string, stat *Stat_t) (err error) = SYS_LSTAT64 -//sys Pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64 -//sys Pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64 +//sys pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64 +//sys pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64 //sys Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error) //sys sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) = SYS_SENDFILE64 //sys setfsgid(gid int) (prev int, err error) = SYS_SETFSGID32 @@ -173,14 +173,6 @@ const ( _SENDMMSG = 20 ) -func accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) { - fd, e := socketcall(_ACCEPT, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), 0, 0, 0) - if e != 0 { - err = e - } - return -} - func accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) { fd, e := socketcall(_ACCEPT4, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 0) if e != 0 { diff --git a/src/cmd/vendor/golang.org/x/sys/unix/syscall_linux_alarm.go b/src/cmd/vendor/golang.org/x/sys/unix/syscall_linux_alarm.go new file mode 100644 index 00000000000..08086ac6a4c --- /dev/null +++ b/src/cmd/vendor/golang.org/x/sys/unix/syscall_linux_alarm.go @@ -0,0 +1,14 @@ +// Copyright 2022 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 linux && (386 || amd64 || mips || mipsle || mips64 || mipsle || ppc64 || ppc64le || ppc || s390x || sparc64) +// +build linux +// +build 386 amd64 mips mipsle mips64 mipsle ppc64 ppc64le ppc s390x sparc64 + +package unix + +// SYS_ALARM is not defined on arm or riscv, but is available for other GOARCH +// values. + +//sys Alarm(seconds uint) (remaining uint, err error) diff --git a/src/cmd/vendor/golang.org/x/sys/unix/syscall_linux_amd64.go b/src/cmd/vendor/golang.org/x/sys/unix/syscall_linux_amd64.go index 4299125aa7c..b945ab254dd 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/syscall_linux_amd64.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/syscall_linux_amd64.go @@ -29,8 +29,8 @@ func Lstat(path string, stat *Stat_t) (err error) { } //sys Pause() (err error) -//sys Pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64 -//sys Pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64 +//sys pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64 +//sys pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64 //sys Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error) //sys Seek(fd int, offset int64, whence int) (off int64, err error) = SYS_LSEEK @@ -62,7 +62,6 @@ func Stat(path string, stat *Stat_t) (err error) { //sys SyncFileRange(fd int, off int64, n int64, flags int) (err error) //sys Truncate(path string, length int64) (err error) //sys Ustat(dev int, ubuf *Ustat_t) (err error) -//sys accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) //sys accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) //sys bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) //sys connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) diff --git a/src/cmd/vendor/golang.org/x/sys/unix/syscall_linux_arm.go b/src/cmd/vendor/golang.org/x/sys/unix/syscall_linux_arm.go index 79edeb9cb14..c1a7778f105 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/syscall_linux_arm.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/syscall_linux_arm.go @@ -27,7 +27,6 @@ func Seek(fd int, offset int64, whence int) (newoffset int64, err error) { return newoffset, nil } -//sys accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) //sys accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) //sys bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) //sys connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) @@ -97,8 +96,8 @@ func Utime(path string, buf *Utimbuf) error { //sys utimes(path string, times *[2]Timeval) (err error) -//sys Pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64 -//sys Pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64 +//sys pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64 +//sys pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64 //sys Truncate(path string, length int64) (err error) = SYS_TRUNCATE64 //sys Ftruncate(fd int, length int64) (err error) = SYS_FTRUNCATE64 diff --git a/src/cmd/vendor/golang.org/x/sys/unix/syscall_linux_arm64.go b/src/cmd/vendor/golang.org/x/sys/unix/syscall_linux_arm64.go index 862890de29b..81db4833a57 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/syscall_linux_arm64.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/syscall_linux_arm64.go @@ -22,8 +22,8 @@ import "unsafe" //sysnb getrlimit(resource int, rlim *Rlimit) (err error) //sysnb Getuid() (uid int) //sys Listen(s int, n int) (err error) -//sys Pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64 -//sys Pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64 +//sys pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64 +//sys pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64 //sys Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error) //sys Seek(fd int, offset int64, whence int) (off int64, err error) = SYS_LSEEK @@ -66,7 +66,6 @@ func Ustat(dev int, ubuf *Ustat_t) (err error) { return ENOSYS } -//sys accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) //sys accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) //sys bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) //sys connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) diff --git a/src/cmd/vendor/golang.org/x/sys/unix/syscall_linux_mips64x.go b/src/cmd/vendor/golang.org/x/sys/unix/syscall_linux_mips64x.go index 8932e34ad2a..98a2660b91f 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/syscall_linux_mips64x.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/syscall_linux_mips64x.go @@ -21,8 +21,8 @@ package unix //sys Lchown(path string, uid int, gid int) (err error) //sys Listen(s int, n int) (err error) //sys Pause() (err error) -//sys Pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64 -//sys Pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64 +//sys pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64 +//sys pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64 //sys Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error) //sys Seek(fd int, offset int64, whence int) (off int64, err error) = SYS_LSEEK @@ -48,7 +48,6 @@ func Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err //sys SyncFileRange(fd int, off int64, n int64, flags int) (err error) //sys Truncate(path string, length int64) (err error) //sys Ustat(dev int, ubuf *Ustat_t) (err error) -//sys accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) //sys accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) //sys bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) //sys connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) diff --git a/src/cmd/vendor/golang.org/x/sys/unix/syscall_linux_mipsx.go b/src/cmd/vendor/golang.org/x/sys/unix/syscall_linux_mipsx.go index 7821c25d9f7..b8a18c0ad22 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/syscall_linux_mipsx.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/syscall_linux_mipsx.go @@ -25,8 +25,8 @@ func Syscall9(trap, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, //sysnb Getuid() (uid int) //sys Lchown(path string, uid int, gid int) (err error) //sys Listen(s int, n int) (err error) -//sys Pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64 -//sys Pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64 +//sys pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64 +//sys pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64 //sys Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error) //sys Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error) = SYS__NEWSELECT //sys sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) = SYS_SENDFILE64 @@ -41,7 +41,6 @@ func Syscall9(trap, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, //sys SyncFileRange(fd int, off int64, n int64, flags int) (err error) //sys Truncate(path string, length int64) (err error) = SYS_TRUNCATE64 //sys Ustat(dev int, ubuf *Ustat_t) (err error) -//sys accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) //sys accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) //sys bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) //sys connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) diff --git a/src/cmd/vendor/golang.org/x/sys/unix/syscall_linux_ppc.go b/src/cmd/vendor/golang.org/x/sys/unix/syscall_linux_ppc.go index c5053a0f03f..4ed9e67c6df 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/syscall_linux_ppc.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/syscall_linux_ppc.go @@ -27,8 +27,8 @@ import ( //sys Listen(s int, n int) (err error) //sys Lstat(path string, stat *Stat_t) (err error) = SYS_LSTAT64 //sys Pause() (err error) -//sys Pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64 -//sys Pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64 +//sys pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64 +//sys pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64 //sys Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error) //sys Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error) = SYS__NEWSELECT //sys sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) = SYS_SENDFILE64 @@ -43,7 +43,6 @@ import ( //sys Stat(path string, stat *Stat_t) (err error) = SYS_STAT64 //sys Truncate(path string, length int64) (err error) = SYS_TRUNCATE64 //sys Ustat(dev int, ubuf *Ustat_t) (err error) -//sys accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) //sys accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) //sys bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) //sys connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) diff --git a/src/cmd/vendor/golang.org/x/sys/unix/syscall_linux_ppc64x.go b/src/cmd/vendor/golang.org/x/sys/unix/syscall_linux_ppc64x.go index 25786c4216b..db63d384c5b 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/syscall_linux_ppc64x.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/syscall_linux_ppc64x.go @@ -26,8 +26,8 @@ package unix //sys Listen(s int, n int) (err error) //sys Lstat(path string, stat *Stat_t) (err error) //sys Pause() (err error) -//sys Pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64 -//sys Pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64 +//sys pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64 +//sys pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64 //sys Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error) //sys Seek(fd int, offset int64, whence int) (off int64, err error) = SYS_LSEEK //sys Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error) = SYS__NEWSELECT @@ -45,7 +45,6 @@ package unix //sys Statfs(path string, buf *Statfs_t) (err error) //sys Truncate(path string, length int64) (err error) //sys Ustat(dev int, ubuf *Ustat_t) (err error) -//sys accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) //sys accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) //sys bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) //sys connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) diff --git a/src/cmd/vendor/golang.org/x/sys/unix/syscall_linux_riscv64.go b/src/cmd/vendor/golang.org/x/sys/unix/syscall_linux_riscv64.go index 6f9f710414f..8ff7adba039 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/syscall_linux_riscv64.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/syscall_linux_riscv64.go @@ -22,8 +22,8 @@ import "unsafe" //sysnb Getrlimit(resource int, rlim *Rlimit) (err error) //sysnb Getuid() (uid int) //sys Listen(s int, n int) (err error) -//sys Pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64 -//sys Pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64 +//sys pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64 +//sys pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64 //sys Seek(fd int, offset int64, whence int) (off int64, err error) = SYS_LSEEK func Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error) { @@ -65,7 +65,6 @@ func Ustat(dev int, ubuf *Ustat_t) (err error) { return ENOSYS } -//sys accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) //sys accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) //sys bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) //sys connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) diff --git a/src/cmd/vendor/golang.org/x/sys/unix/syscall_linux_s390x.go b/src/cmd/vendor/golang.org/x/sys/unix/syscall_linux_s390x.go index 6aa59cb270d..6fcf277b0d7 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/syscall_linux_s390x.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/syscall_linux_s390x.go @@ -26,8 +26,8 @@ import ( //sys Lchown(path string, uid int, gid int) (err error) //sys Lstat(path string, stat *Stat_t) (err error) //sys Pause() (err error) -//sys Pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64 -//sys Pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64 +//sys pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64 +//sys pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64 //sys Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error) //sys Seek(fd int, offset int64, whence int) (off int64, err error) = SYS_LSEEK //sys Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error) @@ -145,15 +145,6 @@ const ( netSendMMsg = 20 ) -func accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (int, error) { - args := [3]uintptr{uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))} - fd, _, err := Syscall(SYS_SOCKETCALL, netAccept, uintptr(unsafe.Pointer(&args)), 0) - if err != 0 { - return 0, err - } - return int(fd), nil -} - func accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (int, error) { args := [4]uintptr{uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags)} fd, _, err := Syscall(SYS_SOCKETCALL, netAccept4, uintptr(unsafe.Pointer(&args)), 0) diff --git a/src/cmd/vendor/golang.org/x/sys/unix/syscall_linux_sparc64.go b/src/cmd/vendor/golang.org/x/sys/unix/syscall_linux_sparc64.go index bbe8d174f8c..02a45d9cc06 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/syscall_linux_sparc64.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/syscall_linux_sparc64.go @@ -23,8 +23,8 @@ package unix //sys Listen(s int, n int) (err error) //sys Lstat(path string, stat *Stat_t) (err error) //sys Pause() (err error) -//sys Pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64 -//sys Pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64 +//sys pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64 +//sys pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64 //sys Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error) //sys Seek(fd int, offset int64, whence int) (off int64, err error) = SYS_LSEEK //sys Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error) @@ -42,7 +42,6 @@ package unix //sys Statfs(path string, buf *Statfs_t) (err error) //sys SyncFileRange(fd int, off int64, n int64, flags int) (err error) //sys Truncate(path string, length int64) (err error) -//sys accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) //sys accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) //sys bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) //sys connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) diff --git a/src/cmd/vendor/golang.org/x/sys/unix/syscall_netbsd.go b/src/cmd/vendor/golang.org/x/sys/unix/syscall_netbsd.go index 853d5f0f436..d9946e5f545 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/syscall_netbsd.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/syscall_netbsd.go @@ -110,14 +110,8 @@ func direntNamlen(buf []byte) (uint64, bool) { return readInt(buf, unsafe.Offsetof(Dirent{}.Namlen), unsafe.Sizeof(Dirent{}.Namlen)) } -//sysnb pipe() (fd1 int, fd2 int, err error) - func Pipe(p []int) (err error) { - if len(p) != 2 { - return EINVAL - } - p[0], p[1], err = pipe() - return + return Pipe2(p, 0) } //sysnb pipe2(p *[2]_C_int, flags int) (err error) @@ -128,8 +122,10 @@ func Pipe2(p []int, flags int) error { } var pp [2]_C_int err := pipe2(&pp, flags) - p[0] = int(pp[0]) - p[1] = int(pp[1]) + if err == nil { + p[0] = int(pp[0]) + p[1] = int(pp[1]) + } return err } @@ -317,8 +313,8 @@ func Statvfs(path string, buf *Statvfs_t) (err error) { //sys Open(path string, mode int, perm uint32) (fd int, err error) //sys Openat(dirfd int, path string, mode int, perm uint32) (fd int, err error) //sys Pathconf(path string, name int) (val int, err error) -//sys Pread(fd int, p []byte, offset int64) (n int, err error) -//sys Pwrite(fd int, p []byte, offset int64) (n int, err error) +//sys pread(fd int, p []byte, offset int64) (n int, err error) +//sys pwrite(fd int, p []byte, offset int64) (n int, err error) //sys read(fd int, p []byte) (n int, err error) //sys Readlink(path string, buf []byte) (n int, err error) //sys Readlinkat(dirfd int, path string, buf []byte) (n int, err error) diff --git a/src/cmd/vendor/golang.org/x/sys/unix/syscall_openbsd.go b/src/cmd/vendor/golang.org/x/sys/unix/syscall_openbsd.go index 22b55038501..0d94765b1a6 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/syscall_openbsd.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/syscall_openbsd.go @@ -87,8 +87,10 @@ func Pipe2(p []int, flags int) error { } var pp [2]_C_int err := pipe2(&pp, flags) - p[0] = int(pp[0]) - p[1] = int(pp[1]) + if err == nil { + p[0] = int(pp[0]) + p[1] = int(pp[1]) + } return err } @@ -272,8 +274,8 @@ func Uname(uname *Utsname) error { //sys Open(path string, mode int, perm uint32) (fd int, err error) //sys Openat(dirfd int, path string, mode int, perm uint32) (fd int, err error) //sys Pathconf(path string, name int) (val int, err error) -//sys Pread(fd int, p []byte, offset int64) (n int, err error) -//sys Pwrite(fd int, p []byte, offset int64) (n int, err error) +//sys pread(fd int, p []byte, offset int64) (n int, err error) +//sys pwrite(fd int, p []byte, offset int64) (n int, err error) //sys read(fd int, p []byte) (n int, err error) //sys Readlink(path string, buf []byte) (n int, err error) //sys Readlinkat(dirfd int, path string, buf []byte) (n int, err error) diff --git a/src/cmd/vendor/golang.org/x/sys/unix/syscall_solaris.go b/src/cmd/vendor/golang.org/x/sys/unix/syscall_solaris.go index 8b88ac21333..8c4e8006078 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/syscall_solaris.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/syscall_solaris.go @@ -66,8 +66,10 @@ func Pipe(p []int) (err error) { if n != 0 { return err } - p[0] = int(pp[0]) - p[1] = int(pp[1]) + if err == nil { + p[0] = int(pp[0]) + p[1] = int(pp[1]) + } return nil } @@ -79,8 +81,10 @@ func Pipe2(p []int, flags int) error { } var pp [2]_C_int err := pipe2(&pp, flags) - p[0] = int(pp[0]) - p[1] = int(pp[1]) + if err == nil { + p[0] = int(pp[0]) + p[1] = int(pp[1]) + } return err } @@ -447,10 +451,9 @@ func Accept(fd int) (nfd int, sa Sockaddr, err error) { //sys recvmsg(s int, msg *Msghdr, flags int) (n int, err error) = libsocket.__xnet_recvmsg -func Recvmsg(fd int, p, oob []byte, flags int) (n, oobn int, recvflags int, from Sockaddr, err error) { +func recvmsgRaw(fd int, p, oob []byte, flags int, rsa *RawSockaddrAny) (n, oobn int, recvflags int, err error) { var msg Msghdr - var rsa RawSockaddrAny - msg.Name = (*byte)(unsafe.Pointer(&rsa)) + msg.Name = (*byte)(unsafe.Pointer(rsa)) msg.Namelen = uint32(SizeofSockaddrAny) var iov Iovec if len(p) > 0 { @@ -472,29 +475,12 @@ func Recvmsg(fd int, p, oob []byte, flags int) (n, oobn int, recvflags int, from return } oobn = int(msg.Accrightslen) - // source address is only specified if the socket is unconnected - if rsa.Addr.Family != AF_UNSPEC { - from, err = anyToSockaddr(fd, &rsa) - } - return -} - -func Sendmsg(fd int, p, oob []byte, to Sockaddr, flags int) (err error) { - _, err = SendmsgN(fd, p, oob, to, flags) return } //sys sendmsg(s int, msg *Msghdr, flags int) (n int, err error) = libsocket.__xnet_sendmsg -func SendmsgN(fd int, p, oob []byte, to Sockaddr, flags int) (n int, err error) { - var ptr unsafe.Pointer - var salen _Socklen - if to != nil { - ptr, salen, err = to.sockaddr() - if err != nil { - return 0, err - } - } +func sendmsgN(fd int, p, oob []byte, ptr unsafe.Pointer, salen _Socklen, flags int) (n int, err error) { var msg Msghdr msg.Name = (*byte)(unsafe.Pointer(ptr)) msg.Namelen = uint32(salen) @@ -657,8 +643,8 @@ func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err e //sys Openat(dirfd int, path string, flags int, mode uint32) (fd int, err error) //sys Pathconf(path string, name int) (val int, err error) //sys Pause() (err error) -//sys Pread(fd int, p []byte, offset int64) (n int, err error) -//sys Pwrite(fd int, p []byte, offset int64) (n int, err error) +//sys pread(fd int, p []byte, offset int64) (n int, err error) +//sys pwrite(fd int, p []byte, offset int64) (n int, err error) //sys read(fd int, p []byte) (n int, err error) //sys Readlink(path string, buf []byte) (n int, err error) //sys Rename(from string, to string) (err error) diff --git a/src/cmd/vendor/golang.org/x/sys/unix/syscall_unix.go b/src/cmd/vendor/golang.org/x/sys/unix/syscall_unix.go index cf296a2433a..70508afc1d1 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/syscall_unix.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/syscall_unix.go @@ -177,6 +177,30 @@ func Write(fd int, p []byte) (n int, err error) { return } +func Pread(fd int, p []byte, offset int64) (n int, err error) { + n, err = pread(fd, p, offset) + if raceenabled { + if n > 0 { + raceWriteRange(unsafe.Pointer(&p[0]), n) + } + if err == nil { + raceAcquire(unsafe.Pointer(&ioSync)) + } + } + return +} + +func Pwrite(fd int, p []byte, offset int64) (n int, err error) { + if raceenabled { + raceReleaseMerge(unsafe.Pointer(&ioSync)) + } + n, err = pwrite(fd, p, offset) + if raceenabled && n > 0 { + raceReadRange(unsafe.Pointer(&p[0]), n) + } + return +} + // For testing: clients can set this flag to force // creation of IPv6 sockets to return EAFNOSUPPORT. var SocketDisableIPv6 bool @@ -313,6 +337,33 @@ func Recvfrom(fd int, p []byte, flags int) (n int, from Sockaddr, err error) { return } +func Recvmsg(fd int, p, oob []byte, flags int) (n, oobn int, recvflags int, from Sockaddr, err error) { + var rsa RawSockaddrAny + n, oobn, recvflags, err = recvmsgRaw(fd, p, oob, flags, &rsa) + // source address is only specified if the socket is unconnected + if rsa.Addr.Family != AF_UNSPEC { + from, err = anyToSockaddr(fd, &rsa) + } + return +} + +func Sendmsg(fd int, p, oob []byte, to Sockaddr, flags int) (err error) { + _, err = SendmsgN(fd, p, oob, to, flags) + return +} + +func SendmsgN(fd int, p, oob []byte, to Sockaddr, flags int) (n int, err error) { + var ptr unsafe.Pointer + var salen _Socklen + if to != nil { + ptr, salen, err = to.sockaddr() + if err != nil { + return 0, err + } + } + return sendmsgN(fd, p, oob, ptr, salen, flags) +} + func Send(s int, buf []byte, flags int) (err error) { return sendto(s, buf, flags, nil, 0) } diff --git a/src/cmd/vendor/golang.org/x/sys/unix/syscall_zos_s390x.go b/src/cmd/vendor/golang.org/x/sys/unix/syscall_zos_s390x.go index 5fb76a14684..f8616f454ec 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/syscall_zos_s390x.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/syscall_zos_s390x.go @@ -579,8 +579,10 @@ func Pipe(p []int) (err error) { } var pp [2]_C_int err = pipe(&pp) - p[0] = int(pp[0]) - p[1] = int(pp[1]) + if err == nil { + p[0] = int(pp[0]) + p[1] = int(pp[1]) + } return } diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux.go b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux.go index d175aae896c..bc7c9d07559 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux.go @@ -38,7 +38,8 @@ const ( AF_KEY = 0xf AF_LLC = 0x1a AF_LOCAL = 0x1 - AF_MAX = 0x2d + AF_MAX = 0x2e + AF_MCTP = 0x2d AF_MPLS = 0x1c AF_NETBEUI = 0xd AF_NETLINK = 0x10 @@ -259,6 +260,17 @@ const ( BUS_USB = 0x3 BUS_VIRTUAL = 0x6 CAN_BCM = 0x2 + CAN_CTRLMODE_3_SAMPLES = 0x4 + CAN_CTRLMODE_BERR_REPORTING = 0x10 + CAN_CTRLMODE_CC_LEN8_DLC = 0x100 + CAN_CTRLMODE_FD = 0x20 + CAN_CTRLMODE_FD_NON_ISO = 0x80 + CAN_CTRLMODE_LISTENONLY = 0x2 + CAN_CTRLMODE_LOOPBACK = 0x1 + CAN_CTRLMODE_ONE_SHOT = 0x8 + CAN_CTRLMODE_PRESUME_ACK = 0x40 + CAN_CTRLMODE_TDC_AUTO = 0x200 + CAN_CTRLMODE_TDC_MANUAL = 0x400 CAN_EFF_FLAG = 0x80000000 CAN_EFF_ID_BITS = 0x1d CAN_EFF_MASK = 0x1fffffff @@ -336,6 +348,7 @@ const ( CAN_RTR_FLAG = 0x40000000 CAN_SFF_ID_BITS = 0xb CAN_SFF_MASK = 0x7ff + CAN_TERMINATION_DISABLED = 0x0 CAN_TP16 = 0x3 CAN_TP20 = 0x4 CAP_AUDIT_CONTROL = 0x1e @@ -741,6 +754,7 @@ const ( ETH_P_QINQ2 = 0x9200 ETH_P_QINQ3 = 0x9300 ETH_P_RARP = 0x8035 + ETH_P_REALTEK = 0x8899 ETH_P_SCA = 0x6007 ETH_P_SLOW = 0x8809 ETH_P_SNAP = 0x5 @@ -810,10 +824,12 @@ const ( FAN_EPIDFD = -0x2 FAN_EVENT_INFO_TYPE_DFID = 0x3 FAN_EVENT_INFO_TYPE_DFID_NAME = 0x2 + FAN_EVENT_INFO_TYPE_ERROR = 0x5 FAN_EVENT_INFO_TYPE_FID = 0x1 FAN_EVENT_INFO_TYPE_PIDFD = 0x4 FAN_EVENT_METADATA_LEN = 0x18 FAN_EVENT_ON_CHILD = 0x8000000 + FAN_FS_ERROR = 0x8000 FAN_MARK_ADD = 0x1 FAN_MARK_DONT_FOLLOW = 0x4 FAN_MARK_FILESYSTEM = 0x100 @@ -1264,9 +1280,14 @@ const ( IP_XFRM_POLICY = 0x11 ISOFS_SUPER_MAGIC = 0x9660 ISTRIP = 0x20 + ITIMER_PROF = 0x2 + ITIMER_REAL = 0x0 + ITIMER_VIRTUAL = 0x1 IUTF8 = 0x4000 IXANY = 0x800 JFFS2_SUPER_MAGIC = 0x72b6 + KCMPROTO_CONNECTED = 0x0 + KCM_RECV_DISABLE = 0x1 KEXEC_ARCH_386 = 0x30000 KEXEC_ARCH_68K = 0x40000 KEXEC_ARCH_AARCH64 = 0xb70000 @@ -1827,6 +1848,8 @@ const ( PERF_MEM_BLK_DATA = 0x2 PERF_MEM_BLK_NA = 0x1 PERF_MEM_BLK_SHIFT = 0x28 + PERF_MEM_HOPS_0 = 0x1 + PERF_MEM_HOPS_SHIFT = 0x2b PERF_MEM_LOCK_LOCKED = 0x2 PERF_MEM_LOCK_NA = 0x1 PERF_MEM_LOCK_SHIFT = 0x18 @@ -1986,6 +2009,9 @@ const ( PR_SCHED_CORE_CREATE = 0x1 PR_SCHED_CORE_GET = 0x0 PR_SCHED_CORE_MAX = 0x4 + PR_SCHED_CORE_SCOPE_PROCESS_GROUP = 0x2 + PR_SCHED_CORE_SCOPE_THREAD = 0x0 + PR_SCHED_CORE_SCOPE_THREAD_GROUP = 0x1 PR_SCHED_CORE_SHARE_FROM = 0x3 PR_SCHED_CORE_SHARE_TO = 0x2 PR_SET_CHILD_SUBREAPER = 0x24 @@ -2167,12 +2193,23 @@ const ( RTCF_NAT = 0x800000 RTCF_VALVE = 0x200000 RTC_AF = 0x20 + RTC_BSM_DIRECT = 0x1 + RTC_BSM_DISABLED = 0x0 + RTC_BSM_LEVEL = 0x2 + RTC_BSM_STANDBY = 0x3 RTC_FEATURE_ALARM = 0x0 + RTC_FEATURE_ALARM_RES_2S = 0x3 RTC_FEATURE_ALARM_RES_MINUTE = 0x1 - RTC_FEATURE_CNT = 0x3 + RTC_FEATURE_BACKUP_SWITCH_MODE = 0x6 + RTC_FEATURE_CNT = 0x7 + RTC_FEATURE_CORRECTION = 0x5 RTC_FEATURE_NEED_WEEK_DAY = 0x2 + RTC_FEATURE_UPDATE_INTERRUPT = 0x4 RTC_IRQF = 0x80 RTC_MAX_FREQ = 0x2000 + RTC_PARAM_BACKUP_SWITCH_MODE = 0x2 + RTC_PARAM_CORRECTION = 0x1 + RTC_PARAM_FEATURES = 0x0 RTC_PF = 0x40 RTC_UF = 0x10 RTF_ADDRCLASSMASK = 0xf8000000 @@ -2423,6 +2460,9 @@ const ( SIOCGSTAMPNS = 0x8907 SIOCGSTAMPNS_OLD = 0x8907 SIOCGSTAMP_OLD = 0x8906 + SIOCKCMATTACH = 0x89e0 + SIOCKCMCLONE = 0x89e2 + SIOCKCMUNATTACH = 0x89e1 SIOCOUTQNSD = 0x894b SIOCPROTOPRIVATE = 0x89e0 SIOCRTMSG = 0x890d @@ -2532,6 +2572,8 @@ const ( SO_VM_SOCKETS_BUFFER_MIN_SIZE = 0x1 SO_VM_SOCKETS_BUFFER_SIZE = 0x0 SO_VM_SOCKETS_CONNECT_TIMEOUT = 0x6 + SO_VM_SOCKETS_CONNECT_TIMEOUT_NEW = 0x8 + SO_VM_SOCKETS_CONNECT_TIMEOUT_OLD = 0x6 SO_VM_SOCKETS_NONBLOCK_TXRX = 0x7 SO_VM_SOCKETS_PEER_HOST_VM_ID = 0x3 SO_VM_SOCKETS_TRUSTED = 0x5 @@ -2826,6 +2868,13 @@ const ( WDIOS_TEMPPANIC = 0x4 WDIOS_UNKNOWN = -0x1 WEXITED = 0x4 + WGALLOWEDIP_A_MAX = 0x3 + WGDEVICE_A_MAX = 0x8 + WGPEER_A_MAX = 0xa + WG_CMD_MAX = 0x1 + WG_GENL_NAME = "wireguard" + WG_GENL_VERSION = 0x1 + WG_KEY_LEN = 0x20 WIN_ACKMEDIACHANGE = 0xdb WIN_CHECKPOWERMODE1 = 0xe5 WIN_CHECKPOWERMODE2 = 0x98 diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_386.go b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_386.go index 3ca40ca7f02..234fd4a5d1a 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_386.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_386.go @@ -250,6 +250,8 @@ const ( RTC_EPOCH_SET = 0x4004700e RTC_IRQP_READ = 0x8004700b RTC_IRQP_SET = 0x4004700c + RTC_PARAM_GET = 0x40187013 + RTC_PARAM_SET = 0x40187014 RTC_PIE_OFF = 0x7006 RTC_PIE_ON = 0x7005 RTC_PLL_GET = 0x801c7011 @@ -327,6 +329,7 @@ const ( SO_RCVTIMEO = 0x14 SO_RCVTIMEO_NEW = 0x42 SO_RCVTIMEO_OLD = 0x14 + SO_RESERVE_MEM = 0x49 SO_REUSEADDR = 0x2 SO_REUSEPORT = 0xf SO_RXQ_OVFL = 0x28 diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_amd64.go b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_amd64.go index ead332091af..58619b7589b 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_amd64.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_amd64.go @@ -251,6 +251,8 @@ const ( RTC_EPOCH_SET = 0x4008700e RTC_IRQP_READ = 0x8008700b RTC_IRQP_SET = 0x4008700c + RTC_PARAM_GET = 0x40187013 + RTC_PARAM_SET = 0x40187014 RTC_PIE_OFF = 0x7006 RTC_PIE_ON = 0x7005 RTC_PLL_GET = 0x80207011 @@ -328,6 +330,7 @@ const ( SO_RCVTIMEO = 0x14 SO_RCVTIMEO_NEW = 0x42 SO_RCVTIMEO_OLD = 0x14 + SO_RESERVE_MEM = 0x49 SO_REUSEADDR = 0x2 SO_REUSEPORT = 0xf SO_RXQ_OVFL = 0x28 diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_arm.go b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_arm.go index 39bdc945589..3a64ff59dce 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_arm.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_arm.go @@ -257,6 +257,8 @@ const ( RTC_EPOCH_SET = 0x4004700e RTC_IRQP_READ = 0x8004700b RTC_IRQP_SET = 0x4004700c + RTC_PARAM_GET = 0x40187013 + RTC_PARAM_SET = 0x40187014 RTC_PIE_OFF = 0x7006 RTC_PIE_ON = 0x7005 RTC_PLL_GET = 0x801c7011 @@ -334,6 +336,7 @@ const ( SO_RCVTIMEO = 0x14 SO_RCVTIMEO_NEW = 0x42 SO_RCVTIMEO_OLD = 0x14 + SO_RESERVE_MEM = 0x49 SO_REUSEADDR = 0x2 SO_REUSEPORT = 0xf SO_RXQ_OVFL = 0x28 diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_arm64.go b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_arm64.go index 9aec987db1c..abe0b925789 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_arm64.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_arm64.go @@ -247,6 +247,8 @@ const ( RTC_EPOCH_SET = 0x4008700e RTC_IRQP_READ = 0x8008700b RTC_IRQP_SET = 0x4008700c + RTC_PARAM_GET = 0x40187013 + RTC_PARAM_SET = 0x40187014 RTC_PIE_OFF = 0x7006 RTC_PIE_ON = 0x7005 RTC_PLL_GET = 0x80207011 @@ -324,6 +326,7 @@ const ( SO_RCVTIMEO = 0x14 SO_RCVTIMEO_NEW = 0x42 SO_RCVTIMEO_OLD = 0x14 + SO_RESERVE_MEM = 0x49 SO_REUSEADDR = 0x2 SO_REUSEPORT = 0xf SO_RXQ_OVFL = 0x28 diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_mips.go b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_mips.go index a8bba9491e8..14d7a84399d 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_mips.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_mips.go @@ -250,6 +250,8 @@ const ( RTC_EPOCH_SET = 0x8004700e RTC_IRQP_READ = 0x4004700b RTC_IRQP_SET = 0x8004700c + RTC_PARAM_GET = 0x80187013 + RTC_PARAM_SET = 0x80187014 RTC_PIE_OFF = 0x20007006 RTC_PIE_ON = 0x20007005 RTC_PLL_GET = 0x401c7011 @@ -327,6 +329,7 @@ const ( SO_RCVTIMEO = 0x1006 SO_RCVTIMEO_NEW = 0x42 SO_RCVTIMEO_OLD = 0x1006 + SO_RESERVE_MEM = 0x49 SO_REUSEADDR = 0x4 SO_REUSEPORT = 0x200 SO_RXQ_OVFL = 0x28 diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_mips64.go b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_mips64.go index ee9e7e2020e..99e7c4ac0b4 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_mips64.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_mips64.go @@ -250,6 +250,8 @@ const ( RTC_EPOCH_SET = 0x8008700e RTC_IRQP_READ = 0x4008700b RTC_IRQP_SET = 0x8008700c + RTC_PARAM_GET = 0x80187013 + RTC_PARAM_SET = 0x80187014 RTC_PIE_OFF = 0x20007006 RTC_PIE_ON = 0x20007005 RTC_PLL_GET = 0x40207011 @@ -327,6 +329,7 @@ const ( SO_RCVTIMEO = 0x1006 SO_RCVTIMEO_NEW = 0x42 SO_RCVTIMEO_OLD = 0x1006 + SO_RESERVE_MEM = 0x49 SO_REUSEADDR = 0x4 SO_REUSEPORT = 0x200 SO_RXQ_OVFL = 0x28 diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_mips64le.go b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_mips64le.go index ba4b288a3c0..496364c33cc 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_mips64le.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_mips64le.go @@ -250,6 +250,8 @@ const ( RTC_EPOCH_SET = 0x8008700e RTC_IRQP_READ = 0x4008700b RTC_IRQP_SET = 0x8008700c + RTC_PARAM_GET = 0x80187013 + RTC_PARAM_SET = 0x80187014 RTC_PIE_OFF = 0x20007006 RTC_PIE_ON = 0x20007005 RTC_PLL_GET = 0x40207011 @@ -327,6 +329,7 @@ const ( SO_RCVTIMEO = 0x1006 SO_RCVTIMEO_NEW = 0x42 SO_RCVTIMEO_OLD = 0x1006 + SO_RESERVE_MEM = 0x49 SO_REUSEADDR = 0x4 SO_REUSEPORT = 0x200 SO_RXQ_OVFL = 0x28 diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_mipsle.go b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_mipsle.go index bc93afc3675..3e40830857d 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_mipsle.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_mipsle.go @@ -250,6 +250,8 @@ const ( RTC_EPOCH_SET = 0x8004700e RTC_IRQP_READ = 0x4004700b RTC_IRQP_SET = 0x8004700c + RTC_PARAM_GET = 0x80187013 + RTC_PARAM_SET = 0x80187014 RTC_PIE_OFF = 0x20007006 RTC_PIE_ON = 0x20007005 RTC_PLL_GET = 0x401c7011 @@ -327,6 +329,7 @@ const ( SO_RCVTIMEO = 0x1006 SO_RCVTIMEO_NEW = 0x42 SO_RCVTIMEO_OLD = 0x1006 + SO_RESERVE_MEM = 0x49 SO_REUSEADDR = 0x4 SO_REUSEPORT = 0x200 SO_RXQ_OVFL = 0x28 diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_ppc.go b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_ppc.go index 9295e694785..1151a7dfab3 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_ppc.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_ppc.go @@ -305,6 +305,8 @@ const ( RTC_EPOCH_SET = 0x8004700e RTC_IRQP_READ = 0x4004700b RTC_IRQP_SET = 0x8004700c + RTC_PARAM_GET = 0x80187013 + RTC_PARAM_SET = 0x80187014 RTC_PIE_OFF = 0x20007006 RTC_PIE_ON = 0x20007005 RTC_PLL_GET = 0x401c7011 @@ -382,6 +384,7 @@ const ( SO_RCVTIMEO = 0x12 SO_RCVTIMEO_NEW = 0x42 SO_RCVTIMEO_OLD = 0x12 + SO_RESERVE_MEM = 0x49 SO_REUSEADDR = 0x2 SO_REUSEPORT = 0xf SO_RXQ_OVFL = 0x28 diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64.go b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64.go index 1fa081c9a67..ed17f249e75 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64.go @@ -309,6 +309,8 @@ const ( RTC_EPOCH_SET = 0x8008700e RTC_IRQP_READ = 0x4008700b RTC_IRQP_SET = 0x8008700c + RTC_PARAM_GET = 0x80187013 + RTC_PARAM_SET = 0x80187014 RTC_PIE_OFF = 0x20007006 RTC_PIE_ON = 0x20007005 RTC_PLL_GET = 0x40207011 @@ -386,6 +388,7 @@ const ( SO_RCVTIMEO = 0x12 SO_RCVTIMEO_NEW = 0x42 SO_RCVTIMEO_OLD = 0x12 + SO_RESERVE_MEM = 0x49 SO_REUSEADDR = 0x2 SO_REUSEPORT = 0xf SO_RXQ_OVFL = 0x28 diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64le.go b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64le.go index 74b32114946..d84a37c1ac2 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64le.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64le.go @@ -309,6 +309,8 @@ const ( RTC_EPOCH_SET = 0x8008700e RTC_IRQP_READ = 0x4008700b RTC_IRQP_SET = 0x8008700c + RTC_PARAM_GET = 0x80187013 + RTC_PARAM_SET = 0x80187014 RTC_PIE_OFF = 0x20007006 RTC_PIE_ON = 0x20007005 RTC_PLL_GET = 0x40207011 @@ -386,6 +388,7 @@ const ( SO_RCVTIMEO = 0x12 SO_RCVTIMEO_NEW = 0x42 SO_RCVTIMEO_OLD = 0x12 + SO_RESERVE_MEM = 0x49 SO_REUSEADDR = 0x2 SO_REUSEPORT = 0xf SO_RXQ_OVFL = 0x28 diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_riscv64.go b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_riscv64.go index c91c8ac5b01..5cafba83f6b 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_riscv64.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_riscv64.go @@ -238,6 +238,8 @@ const ( RTC_EPOCH_SET = 0x4008700e RTC_IRQP_READ = 0x8008700b RTC_IRQP_SET = 0x4008700c + RTC_PARAM_GET = 0x40187013 + RTC_PARAM_SET = 0x40187014 RTC_PIE_OFF = 0x7006 RTC_PIE_ON = 0x7005 RTC_PLL_GET = 0x80207011 @@ -315,6 +317,7 @@ const ( SO_RCVTIMEO = 0x14 SO_RCVTIMEO_NEW = 0x42 SO_RCVTIMEO_OLD = 0x14 + SO_RESERVE_MEM = 0x49 SO_REUSEADDR = 0x2 SO_REUSEPORT = 0xf SO_RXQ_OVFL = 0x28 diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_s390x.go b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_s390x.go index b66bf222894..6d122da41c5 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_s390x.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_s390x.go @@ -313,6 +313,8 @@ const ( RTC_EPOCH_SET = 0x4008700e RTC_IRQP_READ = 0x8008700b RTC_IRQP_SET = 0x4008700c + RTC_PARAM_GET = 0x40187013 + RTC_PARAM_SET = 0x40187014 RTC_PIE_OFF = 0x7006 RTC_PIE_ON = 0x7005 RTC_PLL_GET = 0x80207011 @@ -390,6 +392,7 @@ const ( SO_RCVTIMEO = 0x14 SO_RCVTIMEO_NEW = 0x42 SO_RCVTIMEO_OLD = 0x14 + SO_RESERVE_MEM = 0x49 SO_REUSEADDR = 0x2 SO_REUSEPORT = 0xf SO_RXQ_OVFL = 0x28 diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_sparc64.go b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_sparc64.go index f7fb149b0c9..6bd19e51dbb 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_sparc64.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_sparc64.go @@ -304,6 +304,8 @@ const ( RTC_EPOCH_SET = 0x8008700e RTC_IRQP_READ = 0x4008700b RTC_IRQP_SET = 0x8008700c + RTC_PARAM_GET = 0x80187013 + RTC_PARAM_SET = 0x80187014 RTC_PIE_OFF = 0x20007006 RTC_PIE_ON = 0x20007005 RTC_PLL_GET = 0x40207011 @@ -381,6 +383,7 @@ const ( SO_RCVTIMEO = 0x2000 SO_RCVTIMEO_NEW = 0x44 SO_RCVTIMEO_OLD = 0x2000 + SO_RESERVE_MEM = 0x52 SO_REUSEADDR = 0x4 SO_REUSEPORT = 0x200 SO_RXQ_OVFL = 0x24 diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_aix_ppc.go b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_aix_ppc.go index 85e0cc38667..870215d2c47 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_aix_ppc.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_aix_ppc.go @@ -975,7 +975,7 @@ func Pause() (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 *byte if len(p) > 0 { _p0 = &p[0] @@ -992,7 +992,7 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 *byte if len(p) > 0 { _p0 = &p[0] diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_aix_ppc64.go b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_aix_ppc64.go index f1d4a73b089..a89b0bfa53c 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_aix_ppc64.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_aix_ppc64.go @@ -931,7 +931,7 @@ func Pause() (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 *byte if len(p) > 0 { _p0 = &p[0] @@ -946,7 +946,7 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 *byte if len(p) > 0 { _p0 = &p[0] diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_darwin_amd64.go b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_darwin_amd64.go index 0ae0ed4cb8a..fbfce0204ff 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_darwin_amd64.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_darwin_amd64.go @@ -1698,7 +1698,7 @@ var libc_pathconf_trampoline_addr uintptr // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -1719,7 +1719,7 @@ var libc_pread_trampoline_addr uintptr // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_darwin_arm64.go b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_darwin_arm64.go index cf71be3edb3..49d2225ef5a 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_darwin_arm64.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_darwin_arm64.go @@ -1698,7 +1698,7 @@ var libc_pathconf_trampoline_addr uintptr // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -1719,7 +1719,7 @@ var libc_pread_trampoline_addr uintptr // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_freebsd_386.go b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_freebsd_386.go index 3e9bddb7b22..e9d9997eeda 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_freebsd_386.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_freebsd_386.go @@ -1420,7 +1420,7 @@ func Pathconf(path string, name int) (val int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -1437,7 +1437,7 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_freebsd_amd64.go b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_freebsd_amd64.go index c72a462b91e..edd373b1a56 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_freebsd_amd64.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_freebsd_amd64.go @@ -1420,7 +1420,7 @@ func Pathconf(path string, name int) (val int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -1437,7 +1437,7 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_freebsd_arm.go b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_freebsd_arm.go index 530d5df90c0..82e9764b257 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_freebsd_arm.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_freebsd_arm.go @@ -1420,7 +1420,7 @@ func Pathconf(path string, name int) (val int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -1437,7 +1437,7 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_freebsd_arm64.go b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_freebsd_arm64.go index 71e7df9e855..a6479acd1fc 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_freebsd_arm64.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_freebsd_arm64.go @@ -1420,7 +1420,7 @@ func Pathconf(path string, name int) (val int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -1437,7 +1437,7 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux.go b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux.go index 93edda4c493..30fa4055ec1 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux.go @@ -2032,3 +2032,23 @@ func shmget(key int, size int, flag int) (id int, err error) { } return } + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getitimer(which int, currValue *Itimerval) (err error) { + _, _, e1 := Syscall(SYS_GETITIMER, uintptr(which), uintptr(unsafe.Pointer(currValue)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func setitimer(which int, newValue *Itimerval, oldValue *Itimerval) (err error) { + _, _, e1 := Syscall(SYS_SETITIMER, uintptr(which), uintptr(unsafe.Pointer(newValue)), uintptr(unsafe.Pointer(oldValue))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_386.go b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_386.go index ff90c81e730..88af526b7e2 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_386.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_386.go @@ -1,4 +1,4 @@ -// go run mksyscall.go -l32 -tags linux,386 syscall_linux.go syscall_linux_386.go +// go run mksyscall.go -l32 -tags linux,386 syscall_linux.go syscall_linux_386.go syscall_linux_alarm.go // Code generated by the command above; see README.md. DO NOT EDIT. //go:build linux && 386 @@ -200,7 +200,7 @@ func Lstat(path string, stat *Stat_t) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -217,7 +217,7 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -524,3 +524,14 @@ func utimes(path string, times *[2]Timeval) (err error) { } return } + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Alarm(seconds uint) (remaining uint, err error) { + r0, _, e1 := Syscall(SYS_ALARM, uintptr(seconds), 0, 0) + remaining = uint(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_amd64.go b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_amd64.go index fa7d3dbe4e9..c947a4d10e8 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_amd64.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_amd64.go @@ -1,4 +1,4 @@ -// go run mksyscall.go -tags linux,amd64 syscall_linux.go syscall_linux_amd64.go +// go run mksyscall.go -tags linux,amd64 syscall_linux.go syscall_linux_amd64.go syscall_linux_alarm.go // Code generated by the command above; see README.md. DO NOT EDIT. //go:build linux && amd64 @@ -225,7 +225,7 @@ func Pause() (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -242,7 +242,7 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -444,17 +444,6 @@ func Ustat(dev int, ubuf *Ustat_t) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) { - r0, _, e1 := Syscall(SYS_ACCEPT, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) - fd = int(r0) - if e1 != 0 { - err = errnoErr(e1) - } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - func accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) { r0, _, e1 := Syscall6(SYS_ACCEPT4, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 0) fd = int(r0) @@ -691,3 +680,14 @@ func kexecFileLoad(kernelFd int, initrdFd int, cmdlineLen int, cmdline string, f } return } + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Alarm(seconds uint) (remaining uint, err error) { + r0, _, e1 := Syscall(SYS_ALARM, uintptr(seconds), 0, 0) + remaining = uint(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_arm.go b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_arm.go index 654f91530f6..4882bde3af0 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_arm.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_arm.go @@ -46,17 +46,6 @@ func Tee(rfd int, wfd int, len int, flags int) (n int64, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) { - r0, _, e1 := Syscall(SYS_ACCEPT, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) - fd = int(r0) - if e1 != 0 { - err = errnoErr(e1) - } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - func accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) { r0, _, e1 := Syscall6(SYS_ACCEPT4, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 0) fd = int(r0) @@ -549,7 +538,7 @@ func utimes(path string, times *[2]Timeval) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -566,7 +555,7 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_arm64.go b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_arm64.go index e893f987f91..dd15284d84b 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_arm64.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_arm64.go @@ -180,7 +180,7 @@ func Listen(s int, n int) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -197,7 +197,7 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -389,17 +389,6 @@ func Truncate(path string, length int64) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) { - r0, _, e1 := Syscall(SYS_ACCEPT, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) - fd = int(r0) - if e1 != 0 { - err = errnoErr(e1) - } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - func accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) { r0, _, e1 := Syscall6(SYS_ACCEPT4, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 0) fd = int(r0) diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_mips.go b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_mips.go index 6d155288531..d7d6f42441b 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_mips.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_mips.go @@ -1,4 +1,4 @@ -// go run mksyscall.go -b32 -arm -tags linux,mips syscall_linux.go syscall_linux_mipsx.go +// go run mksyscall.go -b32 -arm -tags linux,mips syscall_linux.go syscall_linux_mipsx.go syscall_linux_alarm.go // Code generated by the command above; see README.md. DO NOT EDIT. //go:build linux && mips @@ -150,7 +150,7 @@ func Listen(s int, n int) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -167,7 +167,7 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -344,17 +344,6 @@ func Ustat(dev int, ubuf *Ustat_t) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) { - r0, _, e1 := Syscall(SYS_ACCEPT, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) - fd = int(r0) - if e1 != 0 { - err = errnoErr(e1) - } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - func accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) { r0, _, e1 := Syscall6(SYS_ACCEPT4, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 0) fd = int(r0) @@ -702,3 +691,14 @@ func setrlimit(resource int, rlim *rlimit32) (err error) { } return } + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Alarm(seconds uint) (remaining uint, err error) { + r0, _, e1 := Syscall(SYS_ALARM, uintptr(seconds), 0, 0) + remaining = uint(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_mips64.go b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_mips64.go index 1e20d72df21..7f1f8e65339 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_mips64.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_mips64.go @@ -1,4 +1,4 @@ -// go run mksyscall.go -tags linux,mips64 syscall_linux.go syscall_linux_mips64x.go +// go run mksyscall.go -tags linux,mips64 syscall_linux.go syscall_linux_mips64x.go syscall_linux_alarm.go // Code generated by the command above; see README.md. DO NOT EDIT. //go:build linux && mips64 @@ -180,7 +180,7 @@ func Pause() (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -197,7 +197,7 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -399,17 +399,6 @@ func Ustat(dev int, ubuf *Ustat_t) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) { - r0, _, e1 := Syscall(SYS_ACCEPT, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) - fd = int(r0) - if e1 != 0 { - err = errnoErr(e1) - } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - func accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) { r0, _, e1 := Syscall6(SYS_ACCEPT4, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 0) fd = int(r0) @@ -696,3 +685,14 @@ func stat(path string, st *stat_t) (err error) { } return } + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Alarm(seconds uint) (remaining uint, err error) { + r0, _, e1 := Syscall(SYS_ALARM, uintptr(seconds), 0, 0) + remaining = uint(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_mips64le.go b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_mips64le.go index 82b5e2d9eda..f933d0f51a1 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_mips64le.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_mips64le.go @@ -180,7 +180,7 @@ func Pause() (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -197,7 +197,7 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -399,17 +399,6 @@ func Ustat(dev int, ubuf *Ustat_t) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) { - r0, _, e1 := Syscall(SYS_ACCEPT, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) - fd = int(r0) - if e1 != 0 { - err = errnoErr(e1) - } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - func accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) { r0, _, e1 := Syscall6(SYS_ACCEPT4, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 0) fd = int(r0) diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_mipsle.go b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_mipsle.go index a0440c1d43b..297d0a99822 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_mipsle.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_mipsle.go @@ -1,4 +1,4 @@ -// go run mksyscall.go -l32 -arm -tags linux,mipsle syscall_linux.go syscall_linux_mipsx.go +// go run mksyscall.go -l32 -arm -tags linux,mipsle syscall_linux.go syscall_linux_mipsx.go syscall_linux_alarm.go // Code generated by the command above; see README.md. DO NOT EDIT. //go:build linux && mipsle @@ -150,7 +150,7 @@ func Listen(s int, n int) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -167,7 +167,7 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -344,17 +344,6 @@ func Ustat(dev int, ubuf *Ustat_t) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) { - r0, _, e1 := Syscall(SYS_ACCEPT, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) - fd = int(r0) - if e1 != 0 { - err = errnoErr(e1) - } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - func accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) { r0, _, e1 := Syscall6(SYS_ACCEPT4, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 0) fd = int(r0) @@ -702,3 +691,14 @@ func setrlimit(resource int, rlim *rlimit32) (err error) { } return } + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Alarm(seconds uint) (remaining uint, err error) { + r0, _, e1 := Syscall(SYS_ALARM, uintptr(seconds), 0, 0) + remaining = uint(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc.go b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc.go index 5864b9ca649..2e32e7a449f 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc.go @@ -1,4 +1,4 @@ -// go run mksyscall.go -b32 -tags linux,ppc syscall_linux.go syscall_linux_ppc.go +// go run mksyscall.go -b32 -tags linux,ppc syscall_linux.go syscall_linux_ppc.go syscall_linux_alarm.go // Code generated by the command above; see README.md. DO NOT EDIT. //go:build linux && ppc @@ -210,7 +210,7 @@ func Pause() (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -227,7 +227,7 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -409,17 +409,6 @@ func Ustat(dev int, ubuf *Ustat_t) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) { - r0, _, e1 := Syscall(SYS_ACCEPT, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) - fd = int(r0) - if e1 != 0 { - err = errnoErr(e1) - } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - func accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) { r0, _, e1 := Syscall6(SYS_ACCEPT4, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 0) fd = int(r0) @@ -707,3 +696,14 @@ func kexecFileLoad(kernelFd int, initrdFd int, cmdlineLen int, cmdline string, f } return } + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Alarm(seconds uint) (remaining uint, err error) { + r0, _, e1 := Syscall(SYS_ALARM, uintptr(seconds), 0, 0) + remaining = uint(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64.go b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64.go index beeb49e3421..3c531704647 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64.go @@ -1,4 +1,4 @@ -// go run mksyscall.go -tags linux,ppc64 syscall_linux.go syscall_linux_ppc64x.go +// go run mksyscall.go -tags linux,ppc64 syscall_linux.go syscall_linux_ppc64x.go syscall_linux_alarm.go // Code generated by the command above; see README.md. DO NOT EDIT. //go:build linux && ppc64 @@ -240,7 +240,7 @@ func Pause() (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -257,7 +257,7 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -475,17 +475,6 @@ func Ustat(dev int, ubuf *Ustat_t) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) { - r0, _, e1 := Syscall(SYS_ACCEPT, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) - fd = int(r0) - if e1 != 0 { - err = errnoErr(e1) - } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - func accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) { r0, _, e1 := Syscall6(SYS_ACCEPT4, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 0) fd = int(r0) @@ -753,3 +742,14 @@ func kexecFileLoad(kernelFd int, initrdFd int, cmdlineLen int, cmdline string, f } return } + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Alarm(seconds uint) (remaining uint, err error) { + r0, _, e1 := Syscall(SYS_ALARM, uintptr(seconds), 0, 0) + remaining = uint(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64le.go b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64le.go index 53139b82c7b..a00c6744ecb 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64le.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64le.go @@ -1,4 +1,4 @@ -// go run mksyscall.go -tags linux,ppc64le syscall_linux.go syscall_linux_ppc64x.go +// go run mksyscall.go -tags linux,ppc64le syscall_linux.go syscall_linux_ppc64x.go syscall_linux_alarm.go // Code generated by the command above; see README.md. DO NOT EDIT. //go:build linux && ppc64le @@ -240,7 +240,7 @@ func Pause() (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -257,7 +257,7 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -475,17 +475,6 @@ func Ustat(dev int, ubuf *Ustat_t) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) { - r0, _, e1 := Syscall(SYS_ACCEPT, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) - fd = int(r0) - if e1 != 0 { - err = errnoErr(e1) - } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - func accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) { r0, _, e1 := Syscall6(SYS_ACCEPT4, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 0) fd = int(r0) @@ -753,3 +742,14 @@ func kexecFileLoad(kernelFd int, initrdFd int, cmdlineLen int, cmdline string, f } return } + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Alarm(seconds uint) (remaining uint, err error) { + r0, _, e1 := Syscall(SYS_ALARM, uintptr(seconds), 0, 0) + remaining = uint(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_riscv64.go b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_riscv64.go index 63b393b8027..a1a9bcbbdf6 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_riscv64.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_riscv64.go @@ -180,7 +180,7 @@ func Listen(s int, n int) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -197,7 +197,7 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -369,17 +369,6 @@ func Truncate(path string, length int64) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) { - r0, _, e1 := Syscall(SYS_ACCEPT, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) - fd = int(r0) - if e1 != 0 { - err = errnoErr(e1) - } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - func accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) { r0, _, e1 := Syscall6(SYS_ACCEPT4, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 0) fd = int(r0) diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_s390x.go b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_s390x.go index 202add37d10..e0dabc60278 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_s390x.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_s390x.go @@ -1,4 +1,4 @@ -// go run mksyscall.go -tags linux,s390x syscall_linux.go syscall_linux_s390x.go +// go run mksyscall.go -tags linux,s390x syscall_linux.go syscall_linux_s390x.go syscall_linux_alarm.go // Code generated by the command above; see README.md. DO NOT EDIT. //go:build linux && s390x @@ -210,7 +210,7 @@ func Pause() (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -227,7 +227,7 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -533,3 +533,14 @@ func kexecFileLoad(kernelFd int, initrdFd int, cmdlineLen int, cmdline string, f } return } + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Alarm(seconds uint) (remaining uint, err error) { + r0, _, e1 := Syscall(SYS_ALARM, uintptr(seconds), 0, 0) + remaining = uint(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_sparc64.go b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_sparc64.go index 2ab268c3435..368623c0f2e 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_sparc64.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_linux_sparc64.go @@ -1,4 +1,4 @@ -// go run mksyscall.go -tags linux,sparc64 syscall_linux.go syscall_linux_sparc64.go +// go run mksyscall.go -tags linux,sparc64 syscall_linux.go syscall_linux_sparc64.go syscall_linux_alarm.go // Code generated by the command above; see README.md. DO NOT EDIT. //go:build linux && sparc64 @@ -220,7 +220,7 @@ func Pause() (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -237,7 +237,7 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -455,17 +455,6 @@ func Truncate(path string, length int64) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) { - r0, _, e1 := Syscall(SYS_ACCEPT, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) - fd = int(r0) - if e1 != 0 { - err = errnoErr(e1) - } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - func accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) { r0, _, e1 := Syscall6(SYS_ACCEPT4, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 0) fd = int(r0) @@ -697,3 +686,14 @@ func utimes(path string, times *[2]Timeval) (err error) { } return } + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Alarm(seconds uint) (remaining uint, err error) { + r0, _, e1 := Syscall(SYS_ALARM, uintptr(seconds), 0, 0) + remaining = uint(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_netbsd_386.go b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_netbsd_386.go index 4726ab30a8f..4af561a48d8 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_netbsd_386.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_netbsd_386.go @@ -351,18 +351,6 @@ func Munlockall() (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func pipe() (fd1 int, fd2 int, err error) { - r0, r1, e1 := RawSyscall(SYS_PIPE, 0, 0, 0) - fd1 = int(r0) - fd2 = int(r1) - if e1 != 0 { - err = errnoErr(e1) - } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - func pipe2(p *[2]_C_int, flags int) (err error) { _, _, e1 := RawSyscall(SYS_PIPE2, uintptr(unsafe.Pointer(p)), uintptr(flags), 0) if e1 != 0 { @@ -1342,7 +1330,7 @@ func Pathconf(path string, name int) (val int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -1359,7 +1347,7 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_netbsd_amd64.go b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_netbsd_amd64.go index fe71456dbc0..3b90e9448ad 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_netbsd_amd64.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_netbsd_amd64.go @@ -351,18 +351,6 @@ func Munlockall() (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func pipe() (fd1 int, fd2 int, err error) { - r0, r1, e1 := RawSyscall(SYS_PIPE, 0, 0, 0) - fd1 = int(r0) - fd2 = int(r1) - if e1 != 0 { - err = errnoErr(e1) - } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - func pipe2(p *[2]_C_int, flags int) (err error) { _, _, e1 := RawSyscall(SYS_PIPE2, uintptr(unsafe.Pointer(p)), uintptr(flags), 0) if e1 != 0 { @@ -1342,7 +1330,7 @@ func Pathconf(path string, name int) (val int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -1359,7 +1347,7 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_netbsd_arm.go b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_netbsd_arm.go index 0b5b2f0143b..890f4ccd131 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_netbsd_arm.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_netbsd_arm.go @@ -351,18 +351,6 @@ func Munlockall() (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func pipe() (fd1 int, fd2 int, err error) { - r0, r1, e1 := RawSyscall(SYS_PIPE, 0, 0, 0) - fd1 = int(r0) - fd2 = int(r1) - if e1 != 0 { - err = errnoErr(e1) - } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - func pipe2(p *[2]_C_int, flags int) (err error) { _, _, e1 := RawSyscall(SYS_PIPE2, uintptr(unsafe.Pointer(p)), uintptr(flags), 0) if e1 != 0 { @@ -1342,7 +1330,7 @@ func Pathconf(path string, name int) (val int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -1359,7 +1347,7 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_netbsd_arm64.go b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_netbsd_arm64.go index bfca28648fb..c79f071fc6a 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_netbsd_arm64.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_netbsd_arm64.go @@ -351,18 +351,6 @@ func Munlockall() (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func pipe() (fd1 int, fd2 int, err error) { - r0, r1, e1 := RawSyscall(SYS_PIPE, 0, 0, 0) - fd1 = int(r0) - fd2 = int(r1) - if e1 != 0 { - err = errnoErr(e1) - } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - func pipe2(p *[2]_C_int, flags int) (err error) { _, _, e1 := RawSyscall(SYS_PIPE2, uintptr(unsafe.Pointer(p)), uintptr(flags), 0) if e1 != 0 { @@ -1342,7 +1330,7 @@ func Pathconf(path string, name int) (val int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -1359,7 +1347,7 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_openbsd_386.go b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_openbsd_386.go index 8f80f4ade51..a057fc5d351 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_openbsd_386.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_openbsd_386.go @@ -1128,7 +1128,7 @@ func Pathconf(path string, name int) (val int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -1145,7 +1145,7 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_openbsd_amd64.go b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_openbsd_amd64.go index 3a47aca7bf7..04db8fa2fea 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_openbsd_amd64.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_openbsd_amd64.go @@ -1128,7 +1128,7 @@ func Pathconf(path string, name int) (val int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -1145,7 +1145,7 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_openbsd_arm.go b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_openbsd_arm.go index 883a9b45e8e..69f80300674 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_openbsd_arm.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_openbsd_arm.go @@ -1128,7 +1128,7 @@ func Pathconf(path string, name int) (val int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -1145,7 +1145,7 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_openbsd_arm64.go b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_openbsd_arm64.go index aac7fdc95e2..c96a505178f 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_openbsd_arm64.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_openbsd_arm64.go @@ -1128,7 +1128,7 @@ func Pathconf(path string, name int) (val int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -1145,7 +1145,7 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_openbsd_mips64.go b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_openbsd_mips64.go index 8776187462b..016d959bc66 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_openbsd_mips64.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_openbsd_mips64.go @@ -1128,7 +1128,7 @@ func Pathconf(path string, name int) (val int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) @@ -1145,7 +1145,7 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { _p0 = unsafe.Pointer(&p[0]) diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_solaris_amd64.go b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_solaris_amd64.go index b5f926cee2a..d12f4fbfea5 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_solaris_amd64.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_solaris_amd64.go @@ -227,8 +227,8 @@ import ( //go:linkname procOpenat libc_openat //go:linkname procPathconf libc_pathconf //go:linkname procPause libc_pause -//go:linkname procPread libc_pread -//go:linkname procPwrite libc_pwrite +//go:linkname procpread libc_pread +//go:linkname procpwrite libc_pwrite //go:linkname procread libc_read //go:linkname procReadlink libc_readlink //go:linkname procRename libc_rename @@ -364,8 +364,8 @@ var ( procOpenat, procPathconf, procPause, - procPread, - procPwrite, + procpread, + procpwrite, procread, procReadlink, procRename, @@ -1380,12 +1380,12 @@ func Pause() (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pread(fd int, p []byte, offset int64) (n int, err error) { +func pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 *byte if len(p) > 0 { _p0 = &p[0] } - r0, _, e1 := sysvicall6(uintptr(unsafe.Pointer(&procPread)), 4, uintptr(fd), uintptr(unsafe.Pointer(_p0)), uintptr(len(p)), uintptr(offset), 0, 0) + r0, _, e1 := sysvicall6(uintptr(unsafe.Pointer(&procpread)), 4, uintptr(fd), uintptr(unsafe.Pointer(_p0)), uintptr(len(p)), uintptr(offset), 0, 0) n = int(r0) if e1 != 0 { err = e1 @@ -1395,12 +1395,12 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pwrite(fd int, p []byte, offset int64) (n int, err error) { +func pwrite(fd int, p []byte, offset int64) (n int, err error) { var _p0 *byte if len(p) > 0 { _p0 = &p[0] } - r0, _, e1 := sysvicall6(uintptr(unsafe.Pointer(&procPwrite)), 4, uintptr(fd), uintptr(unsafe.Pointer(_p0)), uintptr(len(p)), uintptr(offset), 0, 0) + r0, _, e1 := sysvicall6(uintptr(unsafe.Pointer(&procpwrite)), 4, uintptr(fd), uintptr(unsafe.Pointer(_p0)), uintptr(len(p)), uintptr(offset), 0, 0) n = int(r0) if e1 != 0 { err = e1 diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_386.go b/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_386.go index 31847d2305f..cac1f758bf7 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_386.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_386.go @@ -445,4 +445,5 @@ const ( SYS_LANDLOCK_RESTRICT_SELF = 446 SYS_MEMFD_SECRET = 447 SYS_PROCESS_MRELEASE = 448 + SYS_FUTEX_WAITV = 449 ) diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_amd64.go b/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_amd64.go index 3503cbbde38..f327e4a0bcc 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_amd64.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_amd64.go @@ -367,4 +367,5 @@ const ( SYS_LANDLOCK_RESTRICT_SELF = 446 SYS_MEMFD_SECRET = 447 SYS_PROCESS_MRELEASE = 448 + SYS_FUTEX_WAITV = 449 ) diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_arm.go b/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_arm.go index 5ecd24bf683..fb06a08d4ee 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_arm.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_arm.go @@ -409,4 +409,5 @@ const ( SYS_LANDLOCK_ADD_RULE = 445 SYS_LANDLOCK_RESTRICT_SELF = 446 SYS_PROCESS_MRELEASE = 448 + SYS_FUTEX_WAITV = 449 ) diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_arm64.go b/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_arm64.go index 7e5c94cc7fe..58285646eb7 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_arm64.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_arm64.go @@ -312,4 +312,5 @@ const ( SYS_LANDLOCK_RESTRICT_SELF = 446 SYS_MEMFD_SECRET = 447 SYS_PROCESS_MRELEASE = 448 + SYS_FUTEX_WAITV = 449 ) diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_mips.go b/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_mips.go index e1e2a2bf59e..3b0418e6894 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_mips.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_mips.go @@ -429,4 +429,5 @@ const ( SYS_LANDLOCK_ADD_RULE = 4445 SYS_LANDLOCK_RESTRICT_SELF = 4446 SYS_PROCESS_MRELEASE = 4448 + SYS_FUTEX_WAITV = 4449 ) diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_mips64.go b/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_mips64.go index 7651915a3ad..314ebf166ab 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_mips64.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_mips64.go @@ -359,4 +359,5 @@ const ( SYS_LANDLOCK_ADD_RULE = 5445 SYS_LANDLOCK_RESTRICT_SELF = 5446 SYS_PROCESS_MRELEASE = 5448 + SYS_FUTEX_WAITV = 5449 ) diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_mips64le.go b/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_mips64le.go index a26a2c050bc..b8fbb937a33 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_mips64le.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_mips64le.go @@ -359,4 +359,5 @@ const ( SYS_LANDLOCK_ADD_RULE = 5445 SYS_LANDLOCK_RESTRICT_SELF = 5446 SYS_PROCESS_MRELEASE = 5448 + SYS_FUTEX_WAITV = 5449 ) diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_mipsle.go b/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_mipsle.go index fda9a6a9913..ee309b2bac9 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_mipsle.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_mipsle.go @@ -429,4 +429,5 @@ const ( SYS_LANDLOCK_ADD_RULE = 4445 SYS_LANDLOCK_RESTRICT_SELF = 4446 SYS_PROCESS_MRELEASE = 4448 + SYS_FUTEX_WAITV = 4449 ) diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_ppc.go b/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_ppc.go index e8496150d41..ac3748104ed 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_ppc.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_ppc.go @@ -436,4 +436,5 @@ const ( SYS_LANDLOCK_ADD_RULE = 445 SYS_LANDLOCK_RESTRICT_SELF = 446 SYS_PROCESS_MRELEASE = 448 + SYS_FUTEX_WAITV = 449 ) diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_ppc64.go b/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_ppc64.go index 5ee0678a360..5aa47211104 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_ppc64.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_ppc64.go @@ -408,4 +408,5 @@ const ( SYS_LANDLOCK_ADD_RULE = 445 SYS_LANDLOCK_RESTRICT_SELF = 446 SYS_PROCESS_MRELEASE = 448 + SYS_FUTEX_WAITV = 449 ) diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_ppc64le.go b/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_ppc64le.go index 29c0f9a39ea..0793ac1a65b 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_ppc64le.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_ppc64le.go @@ -408,4 +408,5 @@ const ( SYS_LANDLOCK_ADD_RULE = 445 SYS_LANDLOCK_RESTRICT_SELF = 446 SYS_PROCESS_MRELEASE = 448 + SYS_FUTEX_WAITV = 449 ) diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_riscv64.go b/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_riscv64.go index 5c9a9a3b61c..a520962e395 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_riscv64.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_riscv64.go @@ -310,4 +310,5 @@ const ( SYS_LANDLOCK_ADD_RULE = 445 SYS_LANDLOCK_RESTRICT_SELF = 446 SYS_PROCESS_MRELEASE = 448 + SYS_FUTEX_WAITV = 449 ) diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_s390x.go b/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_s390x.go index 913f50f98b9..d1738586b4f 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_s390x.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_s390x.go @@ -373,4 +373,5 @@ const ( SYS_LANDLOCK_ADD_RULE = 445 SYS_LANDLOCK_RESTRICT_SELF = 446 SYS_PROCESS_MRELEASE = 448 + SYS_FUTEX_WAITV = 449 ) diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_sparc64.go b/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_sparc64.go index 0de03a7227c..dfd5660f974 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_sparc64.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zsysnum_linux_sparc64.go @@ -387,4 +387,5 @@ const ( SYS_LANDLOCK_ADD_RULE = 445 SYS_LANDLOCK_RESTRICT_SELF = 446 SYS_PROCESS_MRELEASE = 448 + SYS_FUTEX_WAITV = 449 ) diff --git a/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux.go b/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux.go index 37b521436bc..2c26466e07c 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux.go @@ -24,6 +24,11 @@ type ItimerSpec struct { Value Timespec } +type Itimerval struct { + Interval Timeval + Value Timeval +} + const ( TIME_OK = 0x0 TIME_INS = 0x1 @@ -867,6 +872,7 @@ const ( CTRL_CMD_NEWMCAST_GRP = 0x7 CTRL_CMD_DELMCAST_GRP = 0x8 CTRL_CMD_GETMCAST_GRP = 0x9 + CTRL_CMD_GETPOLICY = 0xa CTRL_ATTR_UNSPEC = 0x0 CTRL_ATTR_FAMILY_ID = 0x1 CTRL_ATTR_FAMILY_NAME = 0x2 @@ -875,12 +881,19 @@ const ( CTRL_ATTR_MAXATTR = 0x5 CTRL_ATTR_OPS = 0x6 CTRL_ATTR_MCAST_GROUPS = 0x7 + CTRL_ATTR_POLICY = 0x8 + CTRL_ATTR_OP_POLICY = 0x9 + CTRL_ATTR_OP = 0xa CTRL_ATTR_OP_UNSPEC = 0x0 CTRL_ATTR_OP_ID = 0x1 CTRL_ATTR_OP_FLAGS = 0x2 CTRL_ATTR_MCAST_GRP_UNSPEC = 0x0 CTRL_ATTR_MCAST_GRP_NAME = 0x1 CTRL_ATTR_MCAST_GRP_ID = 0x2 + CTRL_ATTR_POLICY_UNSPEC = 0x0 + CTRL_ATTR_POLICY_DO = 0x1 + CTRL_ATTR_POLICY_DUMP = 0x2 + CTRL_ATTR_POLICY_DUMP_MAX = 0x2 ) const ( @@ -1136,7 +1149,8 @@ const ( PERF_RECORD_BPF_EVENT = 0x12 PERF_RECORD_CGROUP = 0x13 PERF_RECORD_TEXT_POKE = 0x14 - PERF_RECORD_MAX = 0x15 + PERF_RECORD_AUX_OUTPUT_HW_ID = 0x15 + PERF_RECORD_MAX = 0x16 PERF_RECORD_KSYMBOL_TYPE_UNKNOWN = 0x0 PERF_RECORD_KSYMBOL_TYPE_BPF = 0x1 PERF_RECORD_KSYMBOL_TYPE_OOL = 0x2 @@ -1776,7 +1790,8 @@ const ( const ( NF_NETDEV_INGRESS = 0x0 - NF_NETDEV_NUMHOOKS = 0x1 + NF_NETDEV_EGRESS = 0x1 + NF_NETDEV_NUMHOOKS = 0x2 ) const ( @@ -3158,7 +3173,13 @@ const ( DEVLINK_ATTR_RELOAD_ACTION_INFO = 0xa2 DEVLINK_ATTR_RELOAD_ACTION_STATS = 0xa3 DEVLINK_ATTR_PORT_PCI_SF_NUMBER = 0xa4 - DEVLINK_ATTR_MAX = 0xa9 + DEVLINK_ATTR_RATE_TYPE = 0xa5 + DEVLINK_ATTR_RATE_TX_SHARE = 0xa6 + DEVLINK_ATTR_RATE_TX_MAX = 0xa7 + DEVLINK_ATTR_RATE_NODE_NAME = 0xa8 + DEVLINK_ATTR_RATE_PARENT_NODE_NAME = 0xa9 + DEVLINK_ATTR_REGION_MAX_SNAPSHOTS = 0xaa + DEVLINK_ATTR_MAX = 0xaa DEVLINK_DPIPE_FIELD_MAPPING_TYPE_NONE = 0x0 DEVLINK_DPIPE_FIELD_MAPPING_TYPE_IFINDEX = 0x1 DEVLINK_DPIPE_MATCH_TYPE_FIELD_EXACT = 0x0 @@ -3455,7 +3476,14 @@ const ( ETHTOOL_MSG_CABLE_TEST_ACT = 0x1a ETHTOOL_MSG_CABLE_TEST_TDR_ACT = 0x1b ETHTOOL_MSG_TUNNEL_INFO_GET = 0x1c - ETHTOOL_MSG_USER_MAX = 0x21 + ETHTOOL_MSG_FEC_GET = 0x1d + ETHTOOL_MSG_FEC_SET = 0x1e + ETHTOOL_MSG_MODULE_EEPROM_GET = 0x1f + ETHTOOL_MSG_STATS_GET = 0x20 + ETHTOOL_MSG_PHC_VCLOCKS_GET = 0x21 + ETHTOOL_MSG_MODULE_GET = 0x22 + ETHTOOL_MSG_MODULE_SET = 0x23 + ETHTOOL_MSG_USER_MAX = 0x23 ETHTOOL_MSG_KERNEL_NONE = 0x0 ETHTOOL_MSG_STRSET_GET_REPLY = 0x1 ETHTOOL_MSG_LINKINFO_GET_REPLY = 0x2 @@ -3486,7 +3514,14 @@ const ( ETHTOOL_MSG_CABLE_TEST_NTF = 0x1b ETHTOOL_MSG_CABLE_TEST_TDR_NTF = 0x1c ETHTOOL_MSG_TUNNEL_INFO_GET_REPLY = 0x1d - ETHTOOL_MSG_KERNEL_MAX = 0x22 + ETHTOOL_MSG_FEC_GET_REPLY = 0x1e + ETHTOOL_MSG_FEC_NTF = 0x1f + ETHTOOL_MSG_MODULE_EEPROM_GET_REPLY = 0x20 + ETHTOOL_MSG_STATS_GET_REPLY = 0x21 + ETHTOOL_MSG_PHC_VCLOCKS_GET_REPLY = 0x22 + ETHTOOL_MSG_MODULE_GET_REPLY = 0x23 + ETHTOOL_MSG_MODULE_NTF = 0x24 + ETHTOOL_MSG_KERNEL_MAX = 0x24 ETHTOOL_A_HEADER_UNSPEC = 0x0 ETHTOOL_A_HEADER_DEV_INDEX = 0x1 ETHTOOL_A_HEADER_DEV_NAME = 0x2 @@ -3736,6 +3771,8 @@ const ( ETHTOOL_A_TUNNEL_INFO_MAX = 0x2 ) +const SPEED_UNKNOWN = -0x1 + type EthtoolDrvinfo struct { Cmd uint32 Driver [32]byte @@ -3968,3 +4005,1530 @@ type MountAttr struct { Propagation uint64 Userns_fd uint64 } + +const ( + WG_CMD_GET_DEVICE = 0x0 + WG_CMD_SET_DEVICE = 0x1 + WGDEVICE_F_REPLACE_PEERS = 0x1 + WGDEVICE_A_UNSPEC = 0x0 + WGDEVICE_A_IFINDEX = 0x1 + WGDEVICE_A_IFNAME = 0x2 + WGDEVICE_A_PRIVATE_KEY = 0x3 + WGDEVICE_A_PUBLIC_KEY = 0x4 + WGDEVICE_A_FLAGS = 0x5 + WGDEVICE_A_LISTEN_PORT = 0x6 + WGDEVICE_A_FWMARK = 0x7 + WGDEVICE_A_PEERS = 0x8 + WGPEER_F_REMOVE_ME = 0x1 + WGPEER_F_REPLACE_ALLOWEDIPS = 0x2 + WGPEER_F_UPDATE_ONLY = 0x4 + WGPEER_A_UNSPEC = 0x0 + WGPEER_A_PUBLIC_KEY = 0x1 + WGPEER_A_PRESHARED_KEY = 0x2 + WGPEER_A_FLAGS = 0x3 + WGPEER_A_ENDPOINT = 0x4 + WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL = 0x5 + WGPEER_A_LAST_HANDSHAKE_TIME = 0x6 + WGPEER_A_RX_BYTES = 0x7 + WGPEER_A_TX_BYTES = 0x8 + WGPEER_A_ALLOWEDIPS = 0x9 + WGPEER_A_PROTOCOL_VERSION = 0xa + WGALLOWEDIP_A_UNSPEC = 0x0 + WGALLOWEDIP_A_FAMILY = 0x1 + WGALLOWEDIP_A_IPADDR = 0x2 + WGALLOWEDIP_A_CIDR_MASK = 0x3 +) + +const ( + NL_ATTR_TYPE_INVALID = 0x0 + NL_ATTR_TYPE_FLAG = 0x1 + NL_ATTR_TYPE_U8 = 0x2 + NL_ATTR_TYPE_U16 = 0x3 + NL_ATTR_TYPE_U32 = 0x4 + NL_ATTR_TYPE_U64 = 0x5 + NL_ATTR_TYPE_S8 = 0x6 + NL_ATTR_TYPE_S16 = 0x7 + NL_ATTR_TYPE_S32 = 0x8 + NL_ATTR_TYPE_S64 = 0x9 + NL_ATTR_TYPE_BINARY = 0xa + NL_ATTR_TYPE_STRING = 0xb + NL_ATTR_TYPE_NUL_STRING = 0xc + NL_ATTR_TYPE_NESTED = 0xd + NL_ATTR_TYPE_NESTED_ARRAY = 0xe + NL_ATTR_TYPE_BITFIELD32 = 0xf + + NL_POLICY_TYPE_ATTR_UNSPEC = 0x0 + NL_POLICY_TYPE_ATTR_TYPE = 0x1 + NL_POLICY_TYPE_ATTR_MIN_VALUE_S = 0x2 + NL_POLICY_TYPE_ATTR_MAX_VALUE_S = 0x3 + NL_POLICY_TYPE_ATTR_MIN_VALUE_U = 0x4 + NL_POLICY_TYPE_ATTR_MAX_VALUE_U = 0x5 + NL_POLICY_TYPE_ATTR_MIN_LENGTH = 0x6 + NL_POLICY_TYPE_ATTR_MAX_LENGTH = 0x7 + NL_POLICY_TYPE_ATTR_POLICY_IDX = 0x8 + NL_POLICY_TYPE_ATTR_POLICY_MAXTYPE = 0x9 + NL_POLICY_TYPE_ATTR_BITFIELD32_MASK = 0xa + NL_POLICY_TYPE_ATTR_PAD = 0xb + NL_POLICY_TYPE_ATTR_MASK = 0xc + NL_POLICY_TYPE_ATTR_MAX = 0xc +) + +type CANBitTiming struct { + Bitrate uint32 + Sample_point uint32 + Tq uint32 + Prop_seg uint32 + Phase_seg1 uint32 + Phase_seg2 uint32 + Sjw uint32 + Brp uint32 +} + +type CANBitTimingConst struct { + Name [16]uint8 + Tseg1_min uint32 + Tseg1_max uint32 + Tseg2_min uint32 + Tseg2_max uint32 + Sjw_max uint32 + Brp_min uint32 + Brp_max uint32 + Brp_inc uint32 +} + +type CANClock struct { + Freq uint32 +} + +type CANBusErrorCounters struct { + Txerr uint16 + Rxerr uint16 +} + +type CANCtrlMode struct { + Mask uint32 + Flags uint32 +} + +type CANDeviceStats struct { + Bus_error uint32 + Error_warning uint32 + Error_passive uint32 + Bus_off uint32 + Arbitration_lost uint32 + Restarts uint32 +} + +const ( + CAN_STATE_ERROR_ACTIVE = 0x0 + CAN_STATE_ERROR_WARNING = 0x1 + CAN_STATE_ERROR_PASSIVE = 0x2 + CAN_STATE_BUS_OFF = 0x3 + CAN_STATE_STOPPED = 0x4 + CAN_STATE_SLEEPING = 0x5 + CAN_STATE_MAX = 0x6 +) + +const ( + IFLA_CAN_UNSPEC = 0x0 + IFLA_CAN_BITTIMING = 0x1 + IFLA_CAN_BITTIMING_CONST = 0x2 + IFLA_CAN_CLOCK = 0x3 + IFLA_CAN_STATE = 0x4 + IFLA_CAN_CTRLMODE = 0x5 + IFLA_CAN_RESTART_MS = 0x6 + IFLA_CAN_RESTART = 0x7 + IFLA_CAN_BERR_COUNTER = 0x8 + IFLA_CAN_DATA_BITTIMING = 0x9 + IFLA_CAN_DATA_BITTIMING_CONST = 0xa + IFLA_CAN_TERMINATION = 0xb + IFLA_CAN_TERMINATION_CONST = 0xc + IFLA_CAN_BITRATE_CONST = 0xd + IFLA_CAN_DATA_BITRATE_CONST = 0xe + IFLA_CAN_BITRATE_MAX = 0xf +) + +type KCMAttach struct { + Fd int32 + Bpf_fd int32 +} + +type KCMUnattach struct { + Fd int32 +} + +type KCMClone struct { + Fd int32 +} + +const ( + NL80211_AC_BE = 0x2 + NL80211_AC_BK = 0x3 + NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED = 0x0 + NL80211_ACL_POLICY_DENY_UNLESS_LISTED = 0x1 + NL80211_AC_VI = 0x1 + NL80211_AC_VO = 0x0 + NL80211_ATTR_4ADDR = 0x53 + NL80211_ATTR_ACK = 0x5c + NL80211_ATTR_ACK_SIGNAL = 0x107 + NL80211_ATTR_ACL_POLICY = 0xa5 + NL80211_ATTR_ADMITTED_TIME = 0xd4 + NL80211_ATTR_AIRTIME_WEIGHT = 0x112 + NL80211_ATTR_AKM_SUITES = 0x4c + NL80211_ATTR_AP_ISOLATE = 0x60 + NL80211_ATTR_AUTH_DATA = 0x9c + NL80211_ATTR_AUTH_TYPE = 0x35 + NL80211_ATTR_BANDS = 0xef + NL80211_ATTR_BEACON_HEAD = 0xe + NL80211_ATTR_BEACON_INTERVAL = 0xc + NL80211_ATTR_BEACON_TAIL = 0xf + NL80211_ATTR_BG_SCAN_PERIOD = 0x98 + NL80211_ATTR_BSS_BASIC_RATES = 0x24 + NL80211_ATTR_BSS = 0x2f + NL80211_ATTR_BSS_CTS_PROT = 0x1c + NL80211_ATTR_BSS_HT_OPMODE = 0x6d + NL80211_ATTR_BSSID = 0xf5 + NL80211_ATTR_BSS_SELECT = 0xe3 + NL80211_ATTR_BSS_SHORT_PREAMBLE = 0x1d + NL80211_ATTR_BSS_SHORT_SLOT_TIME = 0x1e + NL80211_ATTR_CENTER_FREQ1 = 0xa0 + NL80211_ATTR_CENTER_FREQ1_OFFSET = 0x123 + NL80211_ATTR_CENTER_FREQ2 = 0xa1 + NL80211_ATTR_CHANNEL_WIDTH = 0x9f + NL80211_ATTR_CH_SWITCH_BLOCK_TX = 0xb8 + NL80211_ATTR_CH_SWITCH_COUNT = 0xb7 + NL80211_ATTR_CIPHER_SUITE_GROUP = 0x4a + NL80211_ATTR_CIPHER_SUITES = 0x39 + NL80211_ATTR_CIPHER_SUITES_PAIRWISE = 0x49 + NL80211_ATTR_CNTDWN_OFFS_BEACON = 0xba + NL80211_ATTR_CNTDWN_OFFS_PRESP = 0xbb + NL80211_ATTR_COALESCE_RULE = 0xb6 + NL80211_ATTR_COALESCE_RULE_CONDITION = 0x2 + NL80211_ATTR_COALESCE_RULE_DELAY = 0x1 + NL80211_ATTR_COALESCE_RULE_MAX = 0x3 + NL80211_ATTR_COALESCE_RULE_PKT_PATTERN = 0x3 + NL80211_ATTR_CONN_FAILED_REASON = 0x9b + NL80211_ATTR_CONTROL_PORT = 0x44 + NL80211_ATTR_CONTROL_PORT_ETHERTYPE = 0x66 + NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT = 0x67 + NL80211_ATTR_CONTROL_PORT_NO_PREAUTH = 0x11e + NL80211_ATTR_CONTROL_PORT_OVER_NL80211 = 0x108 + NL80211_ATTR_COOKIE = 0x58 + NL80211_ATTR_CQM_BEACON_LOSS_EVENT = 0x8 + NL80211_ATTR_CQM = 0x5e + NL80211_ATTR_CQM_MAX = 0x9 + NL80211_ATTR_CQM_PKT_LOSS_EVENT = 0x4 + NL80211_ATTR_CQM_RSSI_HYST = 0x2 + NL80211_ATTR_CQM_RSSI_LEVEL = 0x9 + NL80211_ATTR_CQM_RSSI_THOLD = 0x1 + NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT = 0x3 + NL80211_ATTR_CQM_TXE_INTVL = 0x7 + NL80211_ATTR_CQM_TXE_PKTS = 0x6 + NL80211_ATTR_CQM_TXE_RATE = 0x5 + NL80211_ATTR_CRIT_PROT_ID = 0xb3 + NL80211_ATTR_CSA_C_OFF_BEACON = 0xba + NL80211_ATTR_CSA_C_OFF_PRESP = 0xbb + NL80211_ATTR_CSA_C_OFFSETS_TX = 0xcd + NL80211_ATTR_CSA_IES = 0xb9 + NL80211_ATTR_DEVICE_AP_SME = 0x8d + NL80211_ATTR_DFS_CAC_TIME = 0x7 + NL80211_ATTR_DFS_REGION = 0x92 + NL80211_ATTR_DISABLE_HE = 0x12d + NL80211_ATTR_DISABLE_HT = 0x93 + NL80211_ATTR_DISABLE_VHT = 0xaf + NL80211_ATTR_DISCONNECTED_BY_AP = 0x47 + NL80211_ATTR_DONT_WAIT_FOR_ACK = 0x8e + NL80211_ATTR_DTIM_PERIOD = 0xd + NL80211_ATTR_DURATION = 0x57 + NL80211_ATTR_EXT_CAPA = 0xa9 + NL80211_ATTR_EXT_CAPA_MASK = 0xaa + NL80211_ATTR_EXTERNAL_AUTH_ACTION = 0x104 + NL80211_ATTR_EXTERNAL_AUTH_SUPPORT = 0x105 + NL80211_ATTR_EXT_FEATURES = 0xd9 + NL80211_ATTR_FEATURE_FLAGS = 0x8f + NL80211_ATTR_FILS_CACHE_ID = 0xfd + NL80211_ATTR_FILS_DISCOVERY = 0x126 + NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM = 0xfb + NL80211_ATTR_FILS_ERP_REALM = 0xfa + NL80211_ATTR_FILS_ERP_RRK = 0xfc + NL80211_ATTR_FILS_ERP_USERNAME = 0xf9 + NL80211_ATTR_FILS_KEK = 0xf2 + NL80211_ATTR_FILS_NONCES = 0xf3 + NL80211_ATTR_FRAME = 0x33 + NL80211_ATTR_FRAME_MATCH = 0x5b + NL80211_ATTR_FRAME_TYPE = 0x65 + NL80211_ATTR_FREQ_AFTER = 0x3b + NL80211_ATTR_FREQ_BEFORE = 0x3a + NL80211_ATTR_FREQ_FIXED = 0x3c + NL80211_ATTR_FREQ_RANGE_END = 0x3 + NL80211_ATTR_FREQ_RANGE_MAX_BW = 0x4 + NL80211_ATTR_FREQ_RANGE_START = 0x2 + NL80211_ATTR_FTM_RESPONDER = 0x10e + NL80211_ATTR_FTM_RESPONDER_STATS = 0x10f + NL80211_ATTR_GENERATION = 0x2e + NL80211_ATTR_HANDLE_DFS = 0xbf + NL80211_ATTR_HE_6GHZ_CAPABILITY = 0x125 + NL80211_ATTR_HE_BSS_COLOR = 0x11b + NL80211_ATTR_HE_CAPABILITY = 0x10d + NL80211_ATTR_HE_OBSS_PD = 0x117 + NL80211_ATTR_HIDDEN_SSID = 0x7e + NL80211_ATTR_HT_CAPABILITY = 0x1f + NL80211_ATTR_HT_CAPABILITY_MASK = 0x94 + NL80211_ATTR_IE_ASSOC_RESP = 0x80 + NL80211_ATTR_IE = 0x2a + NL80211_ATTR_IE_PROBE_RESP = 0x7f + NL80211_ATTR_IE_RIC = 0xb2 + NL80211_ATTR_IFACE_SOCKET_OWNER = 0xcc + NL80211_ATTR_IFINDEX = 0x3 + NL80211_ATTR_IFNAME = 0x4 + NL80211_ATTR_IFTYPE_AKM_SUITES = 0x11c + NL80211_ATTR_IFTYPE = 0x5 + NL80211_ATTR_IFTYPE_EXT_CAPA = 0xe6 + NL80211_ATTR_INACTIVITY_TIMEOUT = 0x96 + NL80211_ATTR_INTERFACE_COMBINATIONS = 0x78 + NL80211_ATTR_KEY_CIPHER = 0x9 + NL80211_ATTR_KEY = 0x50 + NL80211_ATTR_KEY_DATA = 0x7 + NL80211_ATTR_KEY_DEFAULT = 0xb + NL80211_ATTR_KEY_DEFAULT_MGMT = 0x28 + NL80211_ATTR_KEY_DEFAULT_TYPES = 0x6e + NL80211_ATTR_KEY_IDX = 0x8 + NL80211_ATTR_KEYS = 0x51 + NL80211_ATTR_KEY_SEQ = 0xa + NL80211_ATTR_KEY_TYPE = 0x37 + NL80211_ATTR_LOCAL_MESH_POWER_MODE = 0xa4 + NL80211_ATTR_LOCAL_STATE_CHANGE = 0x5f + NL80211_ATTR_MAC_ACL_MAX = 0xa7 + NL80211_ATTR_MAC_ADDRS = 0xa6 + NL80211_ATTR_MAC = 0x6 + NL80211_ATTR_MAC_HINT = 0xc8 + NL80211_ATTR_MAC_MASK = 0xd7 + NL80211_ATTR_MAX_AP_ASSOC_STA = 0xca + NL80211_ATTR_MAX = 0x133 + NL80211_ATTR_MAX_CRIT_PROT_DURATION = 0xb4 + NL80211_ATTR_MAX_CSA_COUNTERS = 0xce + NL80211_ATTR_MAX_MATCH_SETS = 0x85 + NL80211_ATTR_MAX_NUM_PMKIDS = 0x56 + NL80211_ATTR_MAX_NUM_SCAN_SSIDS = 0x2b + NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS = 0xde + NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS = 0x7b + NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION = 0x6f + NL80211_ATTR_MAX_SCAN_IE_LEN = 0x38 + NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL = 0xdf + NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS = 0xe0 + NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN = 0x7c + NL80211_ATTR_MCAST_RATE = 0x6b + NL80211_ATTR_MDID = 0xb1 + NL80211_ATTR_MEASUREMENT_DURATION = 0xeb + NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY = 0xec + NL80211_ATTR_MESH_CONFIG = 0x23 + NL80211_ATTR_MESH_ID = 0x18 + NL80211_ATTR_MESH_PEER_AID = 0xed + NL80211_ATTR_MESH_SETUP = 0x70 + NL80211_ATTR_MGMT_SUBTYPE = 0x29 + NL80211_ATTR_MNTR_FLAGS = 0x17 + NL80211_ATTR_MPATH_INFO = 0x1b + NL80211_ATTR_MPATH_NEXT_HOP = 0x1a + NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED = 0xf4 + NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR = 0xe8 + NL80211_ATTR_MU_MIMO_GROUP_DATA = 0xe7 + NL80211_ATTR_NAN_FUNC = 0xf0 + NL80211_ATTR_NAN_MASTER_PREF = 0xee + NL80211_ATTR_NAN_MATCH = 0xf1 + NL80211_ATTR_NETNS_FD = 0xdb + NL80211_ATTR_NOACK_MAP = 0x95 + NL80211_ATTR_NSS = 0x106 + NL80211_ATTR_OFFCHANNEL_TX_OK = 0x6c + NL80211_ATTR_OPER_CLASS = 0xd6 + NL80211_ATTR_OPMODE_NOTIF = 0xc2 + NL80211_ATTR_P2P_CTWINDOW = 0xa2 + NL80211_ATTR_P2P_OPPPS = 0xa3 + NL80211_ATTR_PAD = 0xe5 + NL80211_ATTR_PBSS = 0xe2 + NL80211_ATTR_PEER_AID = 0xb5 + NL80211_ATTR_PEER_MEASUREMENTS = 0x111 + NL80211_ATTR_PID = 0x52 + NL80211_ATTR_PMK = 0xfe + NL80211_ATTR_PMKID = 0x55 + NL80211_ATTR_PMK_LIFETIME = 0x11f + NL80211_ATTR_PMKR0_NAME = 0x102 + NL80211_ATTR_PMK_REAUTH_THRESHOLD = 0x120 + NL80211_ATTR_PMKSA_CANDIDATE = 0x86 + NL80211_ATTR_PORT_AUTHORIZED = 0x103 + NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN = 0x5 + NL80211_ATTR_POWER_RULE_MAX_EIRP = 0x6 + NL80211_ATTR_PREV_BSSID = 0x4f + NL80211_ATTR_PRIVACY = 0x46 + NL80211_ATTR_PROBE_RESP = 0x91 + NL80211_ATTR_PROBE_RESP_OFFLOAD = 0x90 + NL80211_ATTR_PROTOCOL_FEATURES = 0xad + NL80211_ATTR_PS_STATE = 0x5d + NL80211_ATTR_QOS_MAP = 0xc7 + NL80211_ATTR_RADAR_EVENT = 0xa8 + NL80211_ATTR_REASON_CODE = 0x36 + NL80211_ATTR_RECEIVE_MULTICAST = 0x121 + NL80211_ATTR_RECONNECT_REQUESTED = 0x12b + NL80211_ATTR_REG_ALPHA2 = 0x21 + NL80211_ATTR_REG_INDOOR = 0xdd + NL80211_ATTR_REG_INITIATOR = 0x30 + NL80211_ATTR_REG_RULE_FLAGS = 0x1 + NL80211_ATTR_REG_RULES = 0x22 + NL80211_ATTR_REG_TYPE = 0x31 + NL80211_ATTR_REKEY_DATA = 0x7a + NL80211_ATTR_REQ_IE = 0x4d + NL80211_ATTR_RESP_IE = 0x4e + NL80211_ATTR_ROAM_SUPPORT = 0x83 + NL80211_ATTR_RX_FRAME_TYPES = 0x64 + NL80211_ATTR_RXMGMT_FLAGS = 0xbc + NL80211_ATTR_RX_SIGNAL_DBM = 0x97 + NL80211_ATTR_S1G_CAPABILITY = 0x128 + NL80211_ATTR_S1G_CAPABILITY_MASK = 0x129 + NL80211_ATTR_SAE_DATA = 0x9c + NL80211_ATTR_SAE_PASSWORD = 0x115 + NL80211_ATTR_SAE_PWE = 0x12a + NL80211_ATTR_SAR_SPEC = 0x12c + NL80211_ATTR_SCAN_FLAGS = 0x9e + NL80211_ATTR_SCAN_FREQ_KHZ = 0x124 + NL80211_ATTR_SCAN_FREQUENCIES = 0x2c + NL80211_ATTR_SCAN_GENERATION = 0x2e + NL80211_ATTR_SCAN_SSIDS = 0x2d + NL80211_ATTR_SCAN_START_TIME_TSF_BSSID = 0xea + NL80211_ATTR_SCAN_START_TIME_TSF = 0xe9 + NL80211_ATTR_SCAN_SUPP_RATES = 0x7d + NL80211_ATTR_SCHED_SCAN_DELAY = 0xdc + NL80211_ATTR_SCHED_SCAN_INTERVAL = 0x77 + NL80211_ATTR_SCHED_SCAN_MATCH = 0x84 + NL80211_ATTR_SCHED_SCAN_MATCH_SSID = 0x1 + NL80211_ATTR_SCHED_SCAN_MAX_REQS = 0x100 + NL80211_ATTR_SCHED_SCAN_MULTI = 0xff + NL80211_ATTR_SCHED_SCAN_PLANS = 0xe1 + NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI = 0xf6 + NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST = 0xf7 + NL80211_ATTR_SMPS_MODE = 0xd5 + NL80211_ATTR_SOCKET_OWNER = 0xcc + NL80211_ATTR_SOFTWARE_IFTYPES = 0x79 + NL80211_ATTR_SPLIT_WIPHY_DUMP = 0xae + NL80211_ATTR_SSID = 0x34 + NL80211_ATTR_STA_AID = 0x10 + NL80211_ATTR_STA_CAPABILITY = 0xab + NL80211_ATTR_STA_EXT_CAPABILITY = 0xac + NL80211_ATTR_STA_FLAGS2 = 0x43 + NL80211_ATTR_STA_FLAGS = 0x11 + NL80211_ATTR_STA_INFO = 0x15 + NL80211_ATTR_STA_LISTEN_INTERVAL = 0x12 + NL80211_ATTR_STA_PLINK_ACTION = 0x19 + NL80211_ATTR_STA_PLINK_STATE = 0x74 + NL80211_ATTR_STA_SUPPORTED_CHANNELS = 0xbd + NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES = 0xbe + NL80211_ATTR_STA_SUPPORTED_RATES = 0x13 + NL80211_ATTR_STA_SUPPORT_P2P_PS = 0xe4 + NL80211_ATTR_STATUS_CODE = 0x48 + NL80211_ATTR_STA_TX_POWER = 0x114 + NL80211_ATTR_STA_TX_POWER_SETTING = 0x113 + NL80211_ATTR_STA_VLAN = 0x14 + NL80211_ATTR_STA_WME = 0x81 + NL80211_ATTR_SUPPORT_10_MHZ = 0xc1 + NL80211_ATTR_SUPPORT_5_MHZ = 0xc0 + NL80211_ATTR_SUPPORT_AP_UAPSD = 0x82 + NL80211_ATTR_SUPPORTED_COMMANDS = 0x32 + NL80211_ATTR_SUPPORTED_IFTYPES = 0x20 + NL80211_ATTR_SUPPORT_IBSS_RSN = 0x68 + NL80211_ATTR_SUPPORT_MESH_AUTH = 0x73 + NL80211_ATTR_SURVEY_INFO = 0x54 + NL80211_ATTR_SURVEY_RADIO_STATS = 0xda + NL80211_ATTR_TDLS_ACTION = 0x88 + NL80211_ATTR_TDLS_DIALOG_TOKEN = 0x89 + NL80211_ATTR_TDLS_EXTERNAL_SETUP = 0x8c + NL80211_ATTR_TDLS_INITIATOR = 0xcf + NL80211_ATTR_TDLS_OPERATION = 0x8a + NL80211_ATTR_TDLS_PEER_CAPABILITY = 0xcb + NL80211_ATTR_TDLS_SUPPORT = 0x8b + NL80211_ATTR_TESTDATA = 0x45 + NL80211_ATTR_TID_CONFIG = 0x11d + NL80211_ATTR_TIMED_OUT = 0x41 + NL80211_ATTR_TIMEOUT = 0x110 + NL80211_ATTR_TIMEOUT_REASON = 0xf8 + NL80211_ATTR_TSID = 0xd2 + NL80211_ATTR_TWT_RESPONDER = 0x116 + NL80211_ATTR_TX_FRAME_TYPES = 0x63 + NL80211_ATTR_TX_NO_CCK_RATE = 0x87 + NL80211_ATTR_TXQ_LIMIT = 0x10a + NL80211_ATTR_TXQ_MEMORY_LIMIT = 0x10b + NL80211_ATTR_TXQ_QUANTUM = 0x10c + NL80211_ATTR_TXQ_STATS = 0x109 + NL80211_ATTR_TX_RATES = 0x5a + NL80211_ATTR_UNSOL_BCAST_PROBE_RESP = 0x127 + NL80211_ATTR_UNSPEC = 0x0 + NL80211_ATTR_USE_MFP = 0x42 + NL80211_ATTR_USER_PRIO = 0xd3 + NL80211_ATTR_USER_REG_HINT_TYPE = 0x9a + NL80211_ATTR_USE_RRM = 0xd0 + NL80211_ATTR_VENDOR_DATA = 0xc5 + NL80211_ATTR_VENDOR_EVENTS = 0xc6 + NL80211_ATTR_VENDOR_ID = 0xc3 + NL80211_ATTR_VENDOR_SUBCMD = 0xc4 + NL80211_ATTR_VHT_CAPABILITY = 0x9d + NL80211_ATTR_VHT_CAPABILITY_MASK = 0xb0 + NL80211_ATTR_VLAN_ID = 0x11a + NL80211_ATTR_WANT_1X_4WAY_HS = 0x101 + NL80211_ATTR_WDEV = 0x99 + NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX = 0x72 + NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX = 0x71 + NL80211_ATTR_WIPHY_ANTENNA_RX = 0x6a + NL80211_ATTR_WIPHY_ANTENNA_TX = 0x69 + NL80211_ATTR_WIPHY_BANDS = 0x16 + NL80211_ATTR_WIPHY_CHANNEL_TYPE = 0x27 + NL80211_ATTR_WIPHY = 0x1 + NL80211_ATTR_WIPHY_COVERAGE_CLASS = 0x59 + NL80211_ATTR_WIPHY_DYN_ACK = 0xd1 + NL80211_ATTR_WIPHY_EDMG_BW_CONFIG = 0x119 + NL80211_ATTR_WIPHY_EDMG_CHANNELS = 0x118 + NL80211_ATTR_WIPHY_FRAG_THRESHOLD = 0x3f + NL80211_ATTR_WIPHY_FREQ = 0x26 + NL80211_ATTR_WIPHY_FREQ_HINT = 0xc9 + NL80211_ATTR_WIPHY_FREQ_OFFSET = 0x122 + NL80211_ATTR_WIPHY_NAME = 0x2 + NL80211_ATTR_WIPHY_RETRY_LONG = 0x3e + NL80211_ATTR_WIPHY_RETRY_SHORT = 0x3d + NL80211_ATTR_WIPHY_RTS_THRESHOLD = 0x40 + NL80211_ATTR_WIPHY_SELF_MANAGED_REG = 0xd8 + NL80211_ATTR_WIPHY_TX_POWER_LEVEL = 0x62 + NL80211_ATTR_WIPHY_TX_POWER_SETTING = 0x61 + NL80211_ATTR_WIPHY_TXQ_PARAMS = 0x25 + NL80211_ATTR_WOWLAN_TRIGGERS = 0x75 + NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED = 0x76 + NL80211_ATTR_WPA_VERSIONS = 0x4b + NL80211_AUTHTYPE_AUTOMATIC = 0x8 + NL80211_AUTHTYPE_FILS_PK = 0x7 + NL80211_AUTHTYPE_FILS_SK = 0x5 + NL80211_AUTHTYPE_FILS_SK_PFS = 0x6 + NL80211_AUTHTYPE_FT = 0x2 + NL80211_AUTHTYPE_MAX = 0x7 + NL80211_AUTHTYPE_NETWORK_EAP = 0x3 + NL80211_AUTHTYPE_OPEN_SYSTEM = 0x0 + NL80211_AUTHTYPE_SAE = 0x4 + NL80211_AUTHTYPE_SHARED_KEY = 0x1 + NL80211_BAND_2GHZ = 0x0 + NL80211_BAND_5GHZ = 0x1 + NL80211_BAND_60GHZ = 0x2 + NL80211_BAND_6GHZ = 0x3 + NL80211_BAND_ATTR_EDMG_BW_CONFIG = 0xb + NL80211_BAND_ATTR_EDMG_CHANNELS = 0xa + NL80211_BAND_ATTR_FREQS = 0x1 + NL80211_BAND_ATTR_HT_AMPDU_DENSITY = 0x6 + NL80211_BAND_ATTR_HT_AMPDU_FACTOR = 0x5 + NL80211_BAND_ATTR_HT_CAPA = 0x4 + NL80211_BAND_ATTR_HT_MCS_SET = 0x3 + NL80211_BAND_ATTR_IFTYPE_DATA = 0x9 + NL80211_BAND_ATTR_MAX = 0xb + NL80211_BAND_ATTR_RATES = 0x2 + NL80211_BAND_ATTR_VHT_CAPA = 0x8 + NL80211_BAND_ATTR_VHT_MCS_SET = 0x7 + NL80211_BAND_IFTYPE_ATTR_HE_6GHZ_CAPA = 0x6 + NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC = 0x2 + NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET = 0x4 + NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY = 0x3 + NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE = 0x5 + NL80211_BAND_IFTYPE_ATTR_IFTYPES = 0x1 + NL80211_BAND_IFTYPE_ATTR_MAX = 0x7 + NL80211_BAND_S1GHZ = 0x4 + NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE = 0x2 + NL80211_BITRATE_ATTR_MAX = 0x2 + NL80211_BITRATE_ATTR_RATE = 0x1 + NL80211_BSS_BEACON_IES = 0xb + NL80211_BSS_BEACON_INTERVAL = 0x4 + NL80211_BSS_BEACON_TSF = 0xd + NL80211_BSS_BSSID = 0x1 + NL80211_BSS_CAPABILITY = 0x5 + NL80211_BSS_CHAIN_SIGNAL = 0x13 + NL80211_BSS_CHAN_WIDTH_10 = 0x1 + NL80211_BSS_CHAN_WIDTH_1 = 0x3 + NL80211_BSS_CHAN_WIDTH_20 = 0x0 + NL80211_BSS_CHAN_WIDTH_2 = 0x4 + NL80211_BSS_CHAN_WIDTH_5 = 0x2 + NL80211_BSS_CHAN_WIDTH = 0xc + NL80211_BSS_FREQUENCY = 0x2 + NL80211_BSS_FREQUENCY_OFFSET = 0x14 + NL80211_BSS_INFORMATION_ELEMENTS = 0x6 + NL80211_BSS_LAST_SEEN_BOOTTIME = 0xf + NL80211_BSS_MAX = 0x14 + NL80211_BSS_PAD = 0x10 + NL80211_BSS_PARENT_BSSID = 0x12 + NL80211_BSS_PARENT_TSF = 0x11 + NL80211_BSS_PRESP_DATA = 0xe + NL80211_BSS_SEEN_MS_AGO = 0xa + NL80211_BSS_SELECT_ATTR_BAND_PREF = 0x2 + NL80211_BSS_SELECT_ATTR_MAX = 0x3 + NL80211_BSS_SELECT_ATTR_RSSI_ADJUST = 0x3 + NL80211_BSS_SELECT_ATTR_RSSI = 0x1 + NL80211_BSS_SIGNAL_MBM = 0x7 + NL80211_BSS_SIGNAL_UNSPEC = 0x8 + NL80211_BSS_STATUS_ASSOCIATED = 0x1 + NL80211_BSS_STATUS_AUTHENTICATED = 0x0 + NL80211_BSS_STATUS = 0x9 + NL80211_BSS_STATUS_IBSS_JOINED = 0x2 + NL80211_BSS_TSF = 0x3 + NL80211_CHAN_HT20 = 0x1 + NL80211_CHAN_HT40MINUS = 0x2 + NL80211_CHAN_HT40PLUS = 0x3 + NL80211_CHAN_NO_HT = 0x0 + NL80211_CHAN_WIDTH_10 = 0x7 + NL80211_CHAN_WIDTH_160 = 0x5 + NL80211_CHAN_WIDTH_16 = 0xc + NL80211_CHAN_WIDTH_1 = 0x8 + NL80211_CHAN_WIDTH_20 = 0x1 + NL80211_CHAN_WIDTH_20_NOHT = 0x0 + NL80211_CHAN_WIDTH_2 = 0x9 + NL80211_CHAN_WIDTH_40 = 0x2 + NL80211_CHAN_WIDTH_4 = 0xa + NL80211_CHAN_WIDTH_5 = 0x6 + NL80211_CHAN_WIDTH_80 = 0x3 + NL80211_CHAN_WIDTH_80P80 = 0x4 + NL80211_CHAN_WIDTH_8 = 0xb + NL80211_CMD_ABORT_SCAN = 0x72 + NL80211_CMD_ACTION = 0x3b + NL80211_CMD_ACTION_TX_STATUS = 0x3c + NL80211_CMD_ADD_NAN_FUNCTION = 0x75 + NL80211_CMD_ADD_TX_TS = 0x69 + NL80211_CMD_ASSOCIATE = 0x26 + NL80211_CMD_AUTHENTICATE = 0x25 + NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL = 0x38 + NL80211_CMD_CHANGE_NAN_CONFIG = 0x77 + NL80211_CMD_CHANNEL_SWITCH = 0x66 + NL80211_CMD_CH_SWITCH_NOTIFY = 0x58 + NL80211_CMD_CH_SWITCH_STARTED_NOTIFY = 0x6e + NL80211_CMD_CONNECT = 0x2e + NL80211_CMD_CONN_FAILED = 0x5b + NL80211_CMD_CONTROL_PORT_FRAME = 0x81 + NL80211_CMD_CONTROL_PORT_FRAME_TX_STATUS = 0x8b + NL80211_CMD_CRIT_PROTOCOL_START = 0x62 + NL80211_CMD_CRIT_PROTOCOL_STOP = 0x63 + NL80211_CMD_DEAUTHENTICATE = 0x27 + NL80211_CMD_DEL_BEACON = 0x10 + NL80211_CMD_DEL_INTERFACE = 0x8 + NL80211_CMD_DEL_KEY = 0xc + NL80211_CMD_DEL_MPATH = 0x18 + NL80211_CMD_DEL_NAN_FUNCTION = 0x76 + NL80211_CMD_DEL_PMK = 0x7c + NL80211_CMD_DEL_PMKSA = 0x35 + NL80211_CMD_DEL_STATION = 0x14 + NL80211_CMD_DEL_TX_TS = 0x6a + NL80211_CMD_DEL_WIPHY = 0x4 + NL80211_CMD_DISASSOCIATE = 0x28 + NL80211_CMD_DISCONNECT = 0x30 + NL80211_CMD_EXTERNAL_AUTH = 0x7f + NL80211_CMD_FLUSH_PMKSA = 0x36 + NL80211_CMD_FRAME = 0x3b + NL80211_CMD_FRAME_TX_STATUS = 0x3c + NL80211_CMD_FRAME_WAIT_CANCEL = 0x43 + NL80211_CMD_FT_EVENT = 0x61 + NL80211_CMD_GET_BEACON = 0xd + NL80211_CMD_GET_COALESCE = 0x64 + NL80211_CMD_GET_FTM_RESPONDER_STATS = 0x82 + NL80211_CMD_GET_INTERFACE = 0x5 + NL80211_CMD_GET_KEY = 0x9 + NL80211_CMD_GET_MESH_CONFIG = 0x1c + NL80211_CMD_GET_MESH_PARAMS = 0x1c + NL80211_CMD_GET_MPATH = 0x15 + NL80211_CMD_GET_MPP = 0x6b + NL80211_CMD_GET_POWER_SAVE = 0x3e + NL80211_CMD_GET_PROTOCOL_FEATURES = 0x5f + NL80211_CMD_GET_REG = 0x1f + NL80211_CMD_GET_SCAN = 0x20 + NL80211_CMD_GET_STATION = 0x11 + NL80211_CMD_GET_SURVEY = 0x32 + NL80211_CMD_GET_WIPHY = 0x1 + NL80211_CMD_GET_WOWLAN = 0x49 + NL80211_CMD_JOIN_IBSS = 0x2b + NL80211_CMD_JOIN_MESH = 0x44 + NL80211_CMD_JOIN_OCB = 0x6c + NL80211_CMD_LEAVE_IBSS = 0x2c + NL80211_CMD_LEAVE_MESH = 0x45 + NL80211_CMD_LEAVE_OCB = 0x6d + NL80211_CMD_MAX = 0x92 + NL80211_CMD_MICHAEL_MIC_FAILURE = 0x29 + NL80211_CMD_NAN_MATCH = 0x78 + NL80211_CMD_NEW_BEACON = 0xf + NL80211_CMD_NEW_INTERFACE = 0x7 + NL80211_CMD_NEW_KEY = 0xb + NL80211_CMD_NEW_MPATH = 0x17 + NL80211_CMD_NEW_PEER_CANDIDATE = 0x48 + NL80211_CMD_NEW_SCAN_RESULTS = 0x22 + NL80211_CMD_NEW_STATION = 0x13 + NL80211_CMD_NEW_SURVEY_RESULTS = 0x33 + NL80211_CMD_NEW_WIPHY = 0x3 + NL80211_CMD_NOTIFY_CQM = 0x40 + NL80211_CMD_NOTIFY_RADAR = 0x86 + NL80211_CMD_PEER_MEASUREMENT_COMPLETE = 0x85 + NL80211_CMD_PEER_MEASUREMENT_RESULT = 0x84 + NL80211_CMD_PEER_MEASUREMENT_START = 0x83 + NL80211_CMD_PMKSA_CANDIDATE = 0x50 + NL80211_CMD_PORT_AUTHORIZED = 0x7d + NL80211_CMD_PROBE_CLIENT = 0x54 + NL80211_CMD_PROBE_MESH_LINK = 0x88 + NL80211_CMD_RADAR_DETECT = 0x5e + NL80211_CMD_REG_BEACON_HINT = 0x2a + NL80211_CMD_REG_CHANGE = 0x24 + NL80211_CMD_REGISTER_ACTION = 0x3a + NL80211_CMD_REGISTER_BEACONS = 0x55 + NL80211_CMD_REGISTER_FRAME = 0x3a + NL80211_CMD_RELOAD_REGDB = 0x7e + NL80211_CMD_REMAIN_ON_CHANNEL = 0x37 + NL80211_CMD_REQ_SET_REG = 0x1b + NL80211_CMD_ROAM = 0x2f + NL80211_CMD_SCAN_ABORTED = 0x23 + NL80211_CMD_SCHED_SCAN_RESULTS = 0x4d + NL80211_CMD_SCHED_SCAN_STOPPED = 0x4e + NL80211_CMD_SET_BEACON = 0xe + NL80211_CMD_SET_BSS = 0x19 + NL80211_CMD_SET_CHANNEL = 0x41 + NL80211_CMD_SET_COALESCE = 0x65 + NL80211_CMD_SET_CQM = 0x3f + NL80211_CMD_SET_INTERFACE = 0x6 + NL80211_CMD_SET_KEY = 0xa + NL80211_CMD_SET_MAC_ACL = 0x5d + NL80211_CMD_SET_MCAST_RATE = 0x5c + NL80211_CMD_SET_MESH_CONFIG = 0x1d + NL80211_CMD_SET_MESH_PARAMS = 0x1d + NL80211_CMD_SET_MGMT_EXTRA_IE = 0x1e + NL80211_CMD_SET_MPATH = 0x16 + NL80211_CMD_SET_MULTICAST_TO_UNICAST = 0x79 + NL80211_CMD_SET_NOACK_MAP = 0x57 + NL80211_CMD_SET_PMK = 0x7b + NL80211_CMD_SET_PMKSA = 0x34 + NL80211_CMD_SET_POWER_SAVE = 0x3d + NL80211_CMD_SET_QOS_MAP = 0x68 + NL80211_CMD_SET_REG = 0x1a + NL80211_CMD_SET_REKEY_OFFLOAD = 0x4f + NL80211_CMD_SET_SAR_SPECS = 0x8c + NL80211_CMD_SET_STATION = 0x12 + NL80211_CMD_SET_TID_CONFIG = 0x89 + NL80211_CMD_SET_TX_BITRATE_MASK = 0x39 + NL80211_CMD_SET_WDS_PEER = 0x42 + NL80211_CMD_SET_WIPHY = 0x2 + NL80211_CMD_SET_WIPHY_NETNS = 0x31 + NL80211_CMD_SET_WOWLAN = 0x4a + NL80211_CMD_STA_OPMODE_CHANGED = 0x80 + NL80211_CMD_START_AP = 0xf + NL80211_CMD_START_NAN = 0x73 + NL80211_CMD_START_P2P_DEVICE = 0x59 + NL80211_CMD_START_SCHED_SCAN = 0x4b + NL80211_CMD_STOP_AP = 0x10 + NL80211_CMD_STOP_NAN = 0x74 + NL80211_CMD_STOP_P2P_DEVICE = 0x5a + NL80211_CMD_STOP_SCHED_SCAN = 0x4c + NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH = 0x70 + NL80211_CMD_TDLS_CHANNEL_SWITCH = 0x6f + NL80211_CMD_TDLS_MGMT = 0x52 + NL80211_CMD_TDLS_OPER = 0x51 + NL80211_CMD_TESTMODE = 0x2d + NL80211_CMD_TRIGGER_SCAN = 0x21 + NL80211_CMD_UNEXPECTED_4ADDR_FRAME = 0x56 + NL80211_CMD_UNEXPECTED_FRAME = 0x53 + NL80211_CMD_UNPROT_BEACON = 0x8a + NL80211_CMD_UNPROT_DEAUTHENTICATE = 0x46 + NL80211_CMD_UNPROT_DISASSOCIATE = 0x47 + NL80211_CMD_UNSPEC = 0x0 + NL80211_CMD_UPDATE_CONNECT_PARAMS = 0x7a + NL80211_CMD_UPDATE_FT_IES = 0x60 + NL80211_CMD_UPDATE_OWE_INFO = 0x87 + NL80211_CMD_VENDOR = 0x67 + NL80211_CMD_WIPHY_REG_CHANGE = 0x71 + NL80211_COALESCE_CONDITION_MATCH = 0x0 + NL80211_COALESCE_CONDITION_NO_MATCH = 0x1 + NL80211_CONN_FAIL_BLOCKED_CLIENT = 0x1 + NL80211_CONN_FAIL_MAX_CLIENTS = 0x0 + NL80211_CQM_RSSI_BEACON_LOSS_EVENT = 0x2 + NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH = 0x1 + NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW = 0x0 + NL80211_CQM_TXE_MAX_INTVL = 0x708 + NL80211_CRIT_PROTO_APIPA = 0x3 + NL80211_CRIT_PROTO_DHCP = 0x1 + NL80211_CRIT_PROTO_EAPOL = 0x2 + NL80211_CRIT_PROTO_MAX_DURATION = 0x1388 + NL80211_CRIT_PROTO_UNSPEC = 0x0 + NL80211_DFS_AVAILABLE = 0x2 + NL80211_DFS_ETSI = 0x2 + NL80211_DFS_FCC = 0x1 + NL80211_DFS_JP = 0x3 + NL80211_DFS_UNAVAILABLE = 0x1 + NL80211_DFS_UNSET = 0x0 + NL80211_DFS_USABLE = 0x0 + NL80211_EDMG_BW_CONFIG_MAX = 0xf + NL80211_EDMG_BW_CONFIG_MIN = 0x4 + NL80211_EDMG_CHANNELS_MAX = 0x3c + NL80211_EDMG_CHANNELS_MIN = 0x1 + NL80211_EXTERNAL_AUTH_ABORT = 0x1 + NL80211_EXTERNAL_AUTH_START = 0x0 + NL80211_EXT_FEATURE_4WAY_HANDSHAKE_AP_PSK = 0x32 + NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X = 0x10 + NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK = 0xf + NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP = 0x12 + NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT = 0x1b + NL80211_EXT_FEATURE_AIRTIME_FAIRNESS = 0x21 + NL80211_EXT_FEATURE_AP_PMKSA_CACHING = 0x22 + NL80211_EXT_FEATURE_AQL = 0x28 + NL80211_EXT_FEATURE_BEACON_PROTECTION_CLIENT = 0x2e + NL80211_EXT_FEATURE_BEACON_PROTECTION = 0x29 + NL80211_EXT_FEATURE_BEACON_RATE_HE = 0x36 + NL80211_EXT_FEATURE_BEACON_RATE_HT = 0x7 + NL80211_EXT_FEATURE_BEACON_RATE_LEGACY = 0x6 + NL80211_EXT_FEATURE_BEACON_RATE_VHT = 0x8 + NL80211_EXT_FEATURE_BSS_PARENT_TSF = 0x4 + NL80211_EXT_FEATURE_CAN_REPLACE_PTK0 = 0x1f + NL80211_EXT_FEATURE_CONTROL_PORT_NO_PREAUTH = 0x2a + NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211 = 0x1a + NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211_TX_STATUS = 0x30 + NL80211_EXT_FEATURE_CQM_RSSI_LIST = 0xd + NL80211_EXT_FEATURE_DATA_ACK_SIGNAL_SUPPORT = 0x1b + NL80211_EXT_FEATURE_DEL_IBSS_STA = 0x2c + NL80211_EXT_FEATURE_DFS_OFFLOAD = 0x19 + NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER = 0x20 + NL80211_EXT_FEATURE_EXT_KEY_ID = 0x24 + NL80211_EXT_FEATURE_FILS_DISCOVERY = 0x34 + NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME = 0x11 + NL80211_EXT_FEATURE_FILS_SK_OFFLOAD = 0xe + NL80211_EXT_FEATURE_FILS_STA = 0x9 + NL80211_EXT_FEATURE_HIGH_ACCURACY_SCAN = 0x18 + NL80211_EXT_FEATURE_LOW_POWER_SCAN = 0x17 + NL80211_EXT_FEATURE_LOW_SPAN_SCAN = 0x16 + NL80211_EXT_FEATURE_MFP_OPTIONAL = 0x15 + NL80211_EXT_FEATURE_MGMT_TX_RANDOM_TA = 0xa + NL80211_EXT_FEATURE_MGMT_TX_RANDOM_TA_CONNECTED = 0xb + NL80211_EXT_FEATURE_MULTICAST_REGISTRATIONS = 0x2d + NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER = 0x2 + NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION = 0x14 + NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE = 0x13 + NL80211_EXT_FEATURE_OPERATING_CHANNEL_VALIDATION = 0x31 + NL80211_EXT_FEATURE_PROTECTED_TWT = 0x2b + NL80211_EXT_FEATURE_PROT_RANGE_NEGO_AND_MEASURE = 0x39 + NL80211_EXT_FEATURE_RRM = 0x1 + NL80211_EXT_FEATURE_SAE_OFFLOAD_AP = 0x33 + NL80211_EXT_FEATURE_SAE_OFFLOAD = 0x26 + NL80211_EXT_FEATURE_SCAN_FREQ_KHZ = 0x2f + NL80211_EXT_FEATURE_SCAN_MIN_PREQ_CONTENT = 0x1e + NL80211_EXT_FEATURE_SCAN_RANDOM_SN = 0x1d + NL80211_EXT_FEATURE_SCAN_START_TIME = 0x3 + NL80211_EXT_FEATURE_SCHED_SCAN_BAND_SPECIFIC_RSSI_THOLD = 0x23 + NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI = 0xc + NL80211_EXT_FEATURE_SECURE_LTF = 0x37 + NL80211_EXT_FEATURE_SECURE_RTT = 0x38 + NL80211_EXT_FEATURE_SET_SCAN_DWELL = 0x5 + NL80211_EXT_FEATURE_STA_TX_PWR = 0x25 + NL80211_EXT_FEATURE_TXQS = 0x1c + NL80211_EXT_FEATURE_UNSOL_BCAST_PROBE_RESP = 0x35 + NL80211_EXT_FEATURE_VHT_IBSS = 0x0 + NL80211_EXT_FEATURE_VLAN_OFFLOAD = 0x27 + NL80211_FEATURE_ACKTO_ESTIMATION = 0x800000 + NL80211_FEATURE_ACTIVE_MONITOR = 0x20000 + NL80211_FEATURE_ADVERTISE_CHAN_LIMITS = 0x4000 + NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE = 0x40000 + NL80211_FEATURE_AP_SCAN = 0x100 + NL80211_FEATURE_CELL_BASE_REG_HINTS = 0x8 + NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES = 0x80000 + NL80211_FEATURE_DYNAMIC_SMPS = 0x2000000 + NL80211_FEATURE_FULL_AP_CLIENT_STATE = 0x8000 + NL80211_FEATURE_HT_IBSS = 0x2 + NL80211_FEATURE_INACTIVITY_TIMER = 0x4 + NL80211_FEATURE_LOW_PRIORITY_SCAN = 0x40 + NL80211_FEATURE_MAC_ON_CREATE = 0x8000000 + NL80211_FEATURE_ND_RANDOM_MAC_ADDR = 0x80000000 + NL80211_FEATURE_NEED_OBSS_SCAN = 0x400 + NL80211_FEATURE_P2P_DEVICE_NEEDS_CHANNEL = 0x10 + NL80211_FEATURE_P2P_GO_CTWIN = 0x800 + NL80211_FEATURE_P2P_GO_OPPPS = 0x1000 + NL80211_FEATURE_QUIET = 0x200000 + NL80211_FEATURE_SAE = 0x20 + NL80211_FEATURE_SCAN_FLUSH = 0x80 + NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR = 0x20000000 + NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR = 0x40000000 + NL80211_FEATURE_SK_TX_STATUS = 0x1 + NL80211_FEATURE_STATIC_SMPS = 0x1000000 + NL80211_FEATURE_SUPPORTS_WMM_ADMISSION = 0x4000000 + NL80211_FEATURE_TDLS_CHANNEL_SWITCH = 0x10000000 + NL80211_FEATURE_TX_POWER_INSERTION = 0x400000 + NL80211_FEATURE_USERSPACE_MPM = 0x10000 + NL80211_FEATURE_VIF_TXPOWER = 0x200 + NL80211_FEATURE_WFA_TPC_IE_IN_PROBES = 0x100000 + NL80211_FILS_DISCOVERY_ATTR_INT_MAX = 0x2 + NL80211_FILS_DISCOVERY_ATTR_INT_MIN = 0x1 + NL80211_FILS_DISCOVERY_ATTR_MAX = 0x3 + NL80211_FILS_DISCOVERY_ATTR_TMPL = 0x3 + NL80211_FILS_DISCOVERY_TMPL_MIN_LEN = 0x2a + NL80211_FREQUENCY_ATTR_16MHZ = 0x19 + NL80211_FREQUENCY_ATTR_1MHZ = 0x15 + NL80211_FREQUENCY_ATTR_2MHZ = 0x16 + NL80211_FREQUENCY_ATTR_4MHZ = 0x17 + NL80211_FREQUENCY_ATTR_8MHZ = 0x18 + NL80211_FREQUENCY_ATTR_DFS_CAC_TIME = 0xd + NL80211_FREQUENCY_ATTR_DFS_STATE = 0x7 + NL80211_FREQUENCY_ATTR_DFS_TIME = 0x8 + NL80211_FREQUENCY_ATTR_DISABLED = 0x2 + NL80211_FREQUENCY_ATTR_FREQ = 0x1 + NL80211_FREQUENCY_ATTR_GO_CONCURRENT = 0xf + NL80211_FREQUENCY_ATTR_INDOOR_ONLY = 0xe + NL80211_FREQUENCY_ATTR_IR_CONCURRENT = 0xf + NL80211_FREQUENCY_ATTR_MAX = 0x19 + NL80211_FREQUENCY_ATTR_MAX_TX_POWER = 0x6 + NL80211_FREQUENCY_ATTR_NO_10MHZ = 0x11 + NL80211_FREQUENCY_ATTR_NO_160MHZ = 0xc + NL80211_FREQUENCY_ATTR_NO_20MHZ = 0x10 + NL80211_FREQUENCY_ATTR_NO_80MHZ = 0xb + NL80211_FREQUENCY_ATTR_NO_HE = 0x13 + NL80211_FREQUENCY_ATTR_NO_HT40_MINUS = 0x9 + NL80211_FREQUENCY_ATTR_NO_HT40_PLUS = 0xa + NL80211_FREQUENCY_ATTR_NO_IBSS = 0x3 + NL80211_FREQUENCY_ATTR_NO_IR = 0x3 + NL80211_FREQUENCY_ATTR_OFFSET = 0x14 + NL80211_FREQUENCY_ATTR_PASSIVE_SCAN = 0x3 + NL80211_FREQUENCY_ATTR_RADAR = 0x5 + NL80211_FREQUENCY_ATTR_WMM = 0x12 + NL80211_FTM_RESP_ATTR_CIVICLOC = 0x3 + NL80211_FTM_RESP_ATTR_ENABLED = 0x1 + NL80211_FTM_RESP_ATTR_LCI = 0x2 + NL80211_FTM_RESP_ATTR_MAX = 0x3 + NL80211_FTM_STATS_ASAP_NUM = 0x4 + NL80211_FTM_STATS_FAILED_NUM = 0x3 + NL80211_FTM_STATS_MAX = 0xa + NL80211_FTM_STATS_NON_ASAP_NUM = 0x5 + NL80211_FTM_STATS_OUT_OF_WINDOW_TRIGGERS_NUM = 0x9 + NL80211_FTM_STATS_PAD = 0xa + NL80211_FTM_STATS_PARTIAL_NUM = 0x2 + NL80211_FTM_STATS_RESCHEDULE_REQUESTS_NUM = 0x8 + NL80211_FTM_STATS_SUCCESS_NUM = 0x1 + NL80211_FTM_STATS_TOTAL_DURATION_MSEC = 0x6 + NL80211_FTM_STATS_UNKNOWN_TRIGGERS_NUM = 0x7 + NL80211_GENL_NAME = "nl80211" + NL80211_HE_BSS_COLOR_ATTR_COLOR = 0x1 + NL80211_HE_BSS_COLOR_ATTR_DISABLED = 0x2 + NL80211_HE_BSS_COLOR_ATTR_MAX = 0x3 + NL80211_HE_BSS_COLOR_ATTR_PARTIAL = 0x3 + NL80211_HE_MAX_CAPABILITY_LEN = 0x36 + NL80211_HE_MIN_CAPABILITY_LEN = 0x10 + NL80211_HE_NSS_MAX = 0x8 + NL80211_HE_OBSS_PD_ATTR_BSS_COLOR_BITMAP = 0x4 + NL80211_HE_OBSS_PD_ATTR_MAX = 0x6 + NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET = 0x2 + NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET = 0x1 + NL80211_HE_OBSS_PD_ATTR_NON_SRG_MAX_OFFSET = 0x3 + NL80211_HE_OBSS_PD_ATTR_PARTIAL_BSSID_BITMAP = 0x5 + NL80211_HE_OBSS_PD_ATTR_SR_CTRL = 0x6 + NL80211_HIDDEN_SSID_NOT_IN_USE = 0x0 + NL80211_HIDDEN_SSID_ZERO_CONTENTS = 0x2 + NL80211_HIDDEN_SSID_ZERO_LEN = 0x1 + NL80211_HT_CAPABILITY_LEN = 0x1a + NL80211_IFACE_COMB_BI_MIN_GCD = 0x7 + NL80211_IFACE_COMB_LIMITS = 0x1 + NL80211_IFACE_COMB_MAXNUM = 0x2 + NL80211_IFACE_COMB_NUM_CHANNELS = 0x4 + NL80211_IFACE_COMB_RADAR_DETECT_REGIONS = 0x6 + NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS = 0x5 + NL80211_IFACE_COMB_STA_AP_BI_MATCH = 0x3 + NL80211_IFACE_COMB_UNSPEC = 0x0 + NL80211_IFACE_LIMIT_MAX = 0x1 + NL80211_IFACE_LIMIT_TYPES = 0x2 + NL80211_IFACE_LIMIT_UNSPEC = 0x0 + NL80211_IFTYPE_ADHOC = 0x1 + NL80211_IFTYPE_AKM_ATTR_IFTYPES = 0x1 + NL80211_IFTYPE_AKM_ATTR_MAX = 0x2 + NL80211_IFTYPE_AKM_ATTR_SUITES = 0x2 + NL80211_IFTYPE_AP = 0x3 + NL80211_IFTYPE_AP_VLAN = 0x4 + NL80211_IFTYPE_MAX = 0xc + NL80211_IFTYPE_MESH_POINT = 0x7 + NL80211_IFTYPE_MONITOR = 0x6 + NL80211_IFTYPE_NAN = 0xc + NL80211_IFTYPE_OCB = 0xb + NL80211_IFTYPE_P2P_CLIENT = 0x8 + NL80211_IFTYPE_P2P_DEVICE = 0xa + NL80211_IFTYPE_P2P_GO = 0x9 + NL80211_IFTYPE_STATION = 0x2 + NL80211_IFTYPE_UNSPECIFIED = 0x0 + NL80211_IFTYPE_WDS = 0x5 + NL80211_KCK_EXT_LEN = 0x18 + NL80211_KCK_LEN = 0x10 + NL80211_KEK_EXT_LEN = 0x20 + NL80211_KEK_LEN = 0x10 + NL80211_KEY_CIPHER = 0x3 + NL80211_KEY_DATA = 0x1 + NL80211_KEY_DEFAULT_BEACON = 0xa + NL80211_KEY_DEFAULT = 0x5 + NL80211_KEY_DEFAULT_MGMT = 0x6 + NL80211_KEY_DEFAULT_TYPE_MULTICAST = 0x2 + NL80211_KEY_DEFAULT_TYPES = 0x8 + NL80211_KEY_DEFAULT_TYPE_UNICAST = 0x1 + NL80211_KEY_IDX = 0x2 + NL80211_KEY_MAX = 0xa + NL80211_KEY_MODE = 0x9 + NL80211_KEY_NO_TX = 0x1 + NL80211_KEY_RX_TX = 0x0 + NL80211_KEY_SEQ = 0x4 + NL80211_KEY_SET_TX = 0x2 + NL80211_KEY_TYPE = 0x7 + NL80211_KEYTYPE_GROUP = 0x0 + NL80211_KEYTYPE_PAIRWISE = 0x1 + NL80211_KEYTYPE_PEERKEY = 0x2 + NL80211_MAX_NR_AKM_SUITES = 0x2 + NL80211_MAX_NR_CIPHER_SUITES = 0x5 + NL80211_MAX_SUPP_HT_RATES = 0x4d + NL80211_MAX_SUPP_RATES = 0x20 + NL80211_MAX_SUPP_REG_RULES = 0x80 + NL80211_MESHCONF_ATTR_MAX = 0x1f + NL80211_MESHCONF_AUTO_OPEN_PLINKS = 0x7 + NL80211_MESHCONF_AWAKE_WINDOW = 0x1b + NL80211_MESHCONF_CONFIRM_TIMEOUT = 0x2 + NL80211_MESHCONF_CONNECTED_TO_AS = 0x1f + NL80211_MESHCONF_CONNECTED_TO_GATE = 0x1d + NL80211_MESHCONF_ELEMENT_TTL = 0xf + NL80211_MESHCONF_FORWARDING = 0x13 + NL80211_MESHCONF_GATE_ANNOUNCEMENTS = 0x11 + NL80211_MESHCONF_HOLDING_TIMEOUT = 0x3 + NL80211_MESHCONF_HT_OPMODE = 0x16 + NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT = 0xb + NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL = 0x19 + NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES = 0x8 + NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME = 0xd + NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT = 0x17 + NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL = 0x12 + NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL = 0xc + NL80211_MESHCONF_HWMP_RANN_INTERVAL = 0x10 + NL80211_MESHCONF_HWMP_ROOT_INTERVAL = 0x18 + NL80211_MESHCONF_HWMP_ROOTMODE = 0xe + NL80211_MESHCONF_MAX_PEER_LINKS = 0x4 + NL80211_MESHCONF_MAX_RETRIES = 0x5 + NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT = 0xa + NL80211_MESHCONF_NOLEARN = 0x1e + NL80211_MESHCONF_PATH_REFRESH_TIME = 0x9 + NL80211_MESHCONF_PLINK_TIMEOUT = 0x1c + NL80211_MESHCONF_POWER_MODE = 0x1a + NL80211_MESHCONF_RETRY_TIMEOUT = 0x1 + NL80211_MESHCONF_RSSI_THRESHOLD = 0x14 + NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR = 0x15 + NL80211_MESHCONF_TTL = 0x6 + NL80211_MESH_POWER_ACTIVE = 0x1 + NL80211_MESH_POWER_DEEP_SLEEP = 0x3 + NL80211_MESH_POWER_LIGHT_SLEEP = 0x2 + NL80211_MESH_POWER_MAX = 0x3 + NL80211_MESH_POWER_UNKNOWN = 0x0 + NL80211_MESH_SETUP_ATTR_MAX = 0x8 + NL80211_MESH_SETUP_AUTH_PROTOCOL = 0x8 + NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC = 0x2 + NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL = 0x1 + NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC = 0x6 + NL80211_MESH_SETUP_IE = 0x3 + NL80211_MESH_SETUP_USERSPACE_AMPE = 0x5 + NL80211_MESH_SETUP_USERSPACE_AUTH = 0x4 + NL80211_MESH_SETUP_USERSPACE_MPM = 0x7 + NL80211_MESH_SETUP_VENDOR_PATH_SEL_IE = 0x3 + NL80211_MFP_NO = 0x0 + NL80211_MFP_OPTIONAL = 0x2 + NL80211_MFP_REQUIRED = 0x1 + NL80211_MIN_REMAIN_ON_CHANNEL_TIME = 0xa + NL80211_MNTR_FLAG_ACTIVE = 0x6 + NL80211_MNTR_FLAG_CONTROL = 0x3 + NL80211_MNTR_FLAG_COOK_FRAMES = 0x5 + NL80211_MNTR_FLAG_FCSFAIL = 0x1 + NL80211_MNTR_FLAG_MAX = 0x6 + NL80211_MNTR_FLAG_OTHER_BSS = 0x4 + NL80211_MNTR_FLAG_PLCPFAIL = 0x2 + NL80211_MPATH_FLAG_ACTIVE = 0x1 + NL80211_MPATH_FLAG_FIXED = 0x8 + NL80211_MPATH_FLAG_RESOLVED = 0x10 + NL80211_MPATH_FLAG_RESOLVING = 0x2 + NL80211_MPATH_FLAG_SN_VALID = 0x4 + NL80211_MPATH_INFO_DISCOVERY_RETRIES = 0x7 + NL80211_MPATH_INFO_DISCOVERY_TIMEOUT = 0x6 + NL80211_MPATH_INFO_EXPTIME = 0x4 + NL80211_MPATH_INFO_FLAGS = 0x5 + NL80211_MPATH_INFO_FRAME_QLEN = 0x1 + NL80211_MPATH_INFO_HOP_COUNT = 0x8 + NL80211_MPATH_INFO_MAX = 0x9 + NL80211_MPATH_INFO_METRIC = 0x3 + NL80211_MPATH_INFO_PATH_CHANGE = 0x9 + NL80211_MPATH_INFO_SN = 0x2 + NL80211_MULTICAST_GROUP_CONFIG = "config" + NL80211_MULTICAST_GROUP_MLME = "mlme" + NL80211_MULTICAST_GROUP_NAN = "nan" + NL80211_MULTICAST_GROUP_REG = "regulatory" + NL80211_MULTICAST_GROUP_SCAN = "scan" + NL80211_MULTICAST_GROUP_TESTMODE = "testmode" + NL80211_MULTICAST_GROUP_VENDOR = "vendor" + NL80211_NAN_FUNC_ATTR_MAX = 0x10 + NL80211_NAN_FUNC_CLOSE_RANGE = 0x9 + NL80211_NAN_FUNC_FOLLOW_UP = 0x2 + NL80211_NAN_FUNC_FOLLOW_UP_DEST = 0x8 + NL80211_NAN_FUNC_FOLLOW_UP_ID = 0x6 + NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID = 0x7 + NL80211_NAN_FUNC_INSTANCE_ID = 0xf + NL80211_NAN_FUNC_MAX_TYPE = 0x2 + NL80211_NAN_FUNC_PUBLISH_BCAST = 0x4 + NL80211_NAN_FUNC_PUBLISH = 0x0 + NL80211_NAN_FUNC_PUBLISH_TYPE = 0x3 + NL80211_NAN_FUNC_RX_MATCH_FILTER = 0xd + NL80211_NAN_FUNC_SERVICE_ID = 0x2 + NL80211_NAN_FUNC_SERVICE_ID_LEN = 0x6 + NL80211_NAN_FUNC_SERVICE_INFO = 0xb + NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN = 0xff + NL80211_NAN_FUNC_SRF = 0xc + NL80211_NAN_FUNC_SRF_MAX_LEN = 0xff + NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE = 0x5 + NL80211_NAN_FUNC_SUBSCRIBE = 0x1 + NL80211_NAN_FUNC_TERM_REASON = 0x10 + NL80211_NAN_FUNC_TERM_REASON_ERROR = 0x2 + NL80211_NAN_FUNC_TERM_REASON_TTL_EXPIRED = 0x1 + NL80211_NAN_FUNC_TERM_REASON_USER_REQUEST = 0x0 + NL80211_NAN_FUNC_TTL = 0xa + NL80211_NAN_FUNC_TX_MATCH_FILTER = 0xe + NL80211_NAN_FUNC_TYPE = 0x1 + NL80211_NAN_MATCH_ATTR_MAX = 0x2 + NL80211_NAN_MATCH_FUNC_LOCAL = 0x1 + NL80211_NAN_MATCH_FUNC_PEER = 0x2 + NL80211_NAN_SOLICITED_PUBLISH = 0x1 + NL80211_NAN_SRF_ATTR_MAX = 0x4 + NL80211_NAN_SRF_BF = 0x2 + NL80211_NAN_SRF_BF_IDX = 0x3 + NL80211_NAN_SRF_INCLUDE = 0x1 + NL80211_NAN_SRF_MAC_ADDRS = 0x4 + NL80211_NAN_UNSOLICITED_PUBLISH = 0x2 + NL80211_NUM_ACS = 0x4 + NL80211_P2P_PS_SUPPORTED = 0x1 + NL80211_P2P_PS_UNSUPPORTED = 0x0 + NL80211_PKTPAT_MASK = 0x1 + NL80211_PKTPAT_OFFSET = 0x3 + NL80211_PKTPAT_PATTERN = 0x2 + NL80211_PLINK_ACTION_BLOCK = 0x2 + NL80211_PLINK_ACTION_NO_ACTION = 0x0 + NL80211_PLINK_ACTION_OPEN = 0x1 + NL80211_PLINK_BLOCKED = 0x6 + NL80211_PLINK_CNF_RCVD = 0x3 + NL80211_PLINK_ESTAB = 0x4 + NL80211_PLINK_HOLDING = 0x5 + NL80211_PLINK_LISTEN = 0x0 + NL80211_PLINK_OPN_RCVD = 0x2 + NL80211_PLINK_OPN_SNT = 0x1 + NL80211_PMKSA_CANDIDATE_BSSID = 0x2 + NL80211_PMKSA_CANDIDATE_INDEX = 0x1 + NL80211_PMKSA_CANDIDATE_PREAUTH = 0x3 + NL80211_PMSR_ATTR_MAX = 0x5 + NL80211_PMSR_ATTR_MAX_PEERS = 0x1 + NL80211_PMSR_ATTR_PEERS = 0x5 + NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR = 0x3 + NL80211_PMSR_ATTR_REPORT_AP_TSF = 0x2 + NL80211_PMSR_ATTR_TYPE_CAPA = 0x4 + NL80211_PMSR_FTM_CAPA_ATTR_ASAP = 0x1 + NL80211_PMSR_FTM_CAPA_ATTR_BANDWIDTHS = 0x6 + NL80211_PMSR_FTM_CAPA_ATTR_MAX_BURSTS_EXPONENT = 0x7 + NL80211_PMSR_FTM_CAPA_ATTR_MAX = 0xa + NL80211_PMSR_FTM_CAPA_ATTR_MAX_FTMS_PER_BURST = 0x8 + NL80211_PMSR_FTM_CAPA_ATTR_NON_ASAP = 0x2 + NL80211_PMSR_FTM_CAPA_ATTR_NON_TRIGGER_BASED = 0xa + NL80211_PMSR_FTM_CAPA_ATTR_PREAMBLES = 0x5 + NL80211_PMSR_FTM_CAPA_ATTR_REQ_CIVICLOC = 0x4 + NL80211_PMSR_FTM_CAPA_ATTR_REQ_LCI = 0x3 + NL80211_PMSR_FTM_CAPA_ATTR_TRIGGER_BASED = 0x9 + NL80211_PMSR_FTM_FAILURE_BAD_CHANGED_PARAMS = 0x7 + NL80211_PMSR_FTM_FAILURE_INVALID_TIMESTAMP = 0x5 + NL80211_PMSR_FTM_FAILURE_NO_RESPONSE = 0x1 + NL80211_PMSR_FTM_FAILURE_PEER_BUSY = 0x6 + NL80211_PMSR_FTM_FAILURE_PEER_NOT_CAPABLE = 0x4 + NL80211_PMSR_FTM_FAILURE_REJECTED = 0x2 + NL80211_PMSR_FTM_FAILURE_UNSPECIFIED = 0x0 + NL80211_PMSR_FTM_FAILURE_WRONG_CHANNEL = 0x3 + NL80211_PMSR_FTM_REQ_ATTR_ASAP = 0x1 + NL80211_PMSR_FTM_REQ_ATTR_BURST_DURATION = 0x5 + NL80211_PMSR_FTM_REQ_ATTR_BURST_PERIOD = 0x4 + NL80211_PMSR_FTM_REQ_ATTR_FTMS_PER_BURST = 0x6 + NL80211_PMSR_FTM_REQ_ATTR_LMR_FEEDBACK = 0xc + NL80211_PMSR_FTM_REQ_ATTR_MAX = 0xd + NL80211_PMSR_FTM_REQ_ATTR_NON_TRIGGER_BASED = 0xb + NL80211_PMSR_FTM_REQ_ATTR_NUM_BURSTS_EXP = 0x3 + NL80211_PMSR_FTM_REQ_ATTR_NUM_FTMR_RETRIES = 0x7 + NL80211_PMSR_FTM_REQ_ATTR_PREAMBLE = 0x2 + NL80211_PMSR_FTM_REQ_ATTR_REQUEST_CIVICLOC = 0x9 + NL80211_PMSR_FTM_REQ_ATTR_REQUEST_LCI = 0x8 + NL80211_PMSR_FTM_REQ_ATTR_TRIGGER_BASED = 0xa + NL80211_PMSR_FTM_RESP_ATTR_BURST_DURATION = 0x7 + NL80211_PMSR_FTM_RESP_ATTR_BURST_INDEX = 0x2 + NL80211_PMSR_FTM_RESP_ATTR_BUSY_RETRY_TIME = 0x5 + NL80211_PMSR_FTM_RESP_ATTR_CIVICLOC = 0x14 + NL80211_PMSR_FTM_RESP_ATTR_DIST_AVG = 0x10 + NL80211_PMSR_FTM_RESP_ATTR_DIST_SPREAD = 0x12 + NL80211_PMSR_FTM_RESP_ATTR_DIST_VARIANCE = 0x11 + NL80211_PMSR_FTM_RESP_ATTR_FAIL_REASON = 0x1 + NL80211_PMSR_FTM_RESP_ATTR_FTMS_PER_BURST = 0x8 + NL80211_PMSR_FTM_RESP_ATTR_LCI = 0x13 + NL80211_PMSR_FTM_RESP_ATTR_MAX = 0x15 + NL80211_PMSR_FTM_RESP_ATTR_NUM_BURSTS_EXP = 0x6 + NL80211_PMSR_FTM_RESP_ATTR_NUM_FTMR_ATTEMPTS = 0x3 + NL80211_PMSR_FTM_RESP_ATTR_NUM_FTMR_SUCCESSES = 0x4 + NL80211_PMSR_FTM_RESP_ATTR_PAD = 0x15 + NL80211_PMSR_FTM_RESP_ATTR_RSSI_AVG = 0x9 + NL80211_PMSR_FTM_RESP_ATTR_RSSI_SPREAD = 0xa + NL80211_PMSR_FTM_RESP_ATTR_RTT_AVG = 0xd + NL80211_PMSR_FTM_RESP_ATTR_RTT_SPREAD = 0xf + NL80211_PMSR_FTM_RESP_ATTR_RTT_VARIANCE = 0xe + NL80211_PMSR_FTM_RESP_ATTR_RX_RATE = 0xc + NL80211_PMSR_FTM_RESP_ATTR_TX_RATE = 0xb + NL80211_PMSR_PEER_ATTR_ADDR = 0x1 + NL80211_PMSR_PEER_ATTR_CHAN = 0x2 + NL80211_PMSR_PEER_ATTR_MAX = 0x4 + NL80211_PMSR_PEER_ATTR_REQ = 0x3 + NL80211_PMSR_PEER_ATTR_RESP = 0x4 + NL80211_PMSR_REQ_ATTR_DATA = 0x1 + NL80211_PMSR_REQ_ATTR_GET_AP_TSF = 0x2 + NL80211_PMSR_REQ_ATTR_MAX = 0x2 + NL80211_PMSR_RESP_ATTR_AP_TSF = 0x4 + NL80211_PMSR_RESP_ATTR_DATA = 0x1 + NL80211_PMSR_RESP_ATTR_FINAL = 0x5 + NL80211_PMSR_RESP_ATTR_HOST_TIME = 0x3 + NL80211_PMSR_RESP_ATTR_MAX = 0x6 + NL80211_PMSR_RESP_ATTR_PAD = 0x6 + NL80211_PMSR_RESP_ATTR_STATUS = 0x2 + NL80211_PMSR_STATUS_FAILURE = 0x3 + NL80211_PMSR_STATUS_REFUSED = 0x1 + NL80211_PMSR_STATUS_SUCCESS = 0x0 + NL80211_PMSR_STATUS_TIMEOUT = 0x2 + NL80211_PMSR_TYPE_FTM = 0x1 + NL80211_PMSR_TYPE_INVALID = 0x0 + NL80211_PMSR_TYPE_MAX = 0x1 + NL80211_PREAMBLE_DMG = 0x3 + NL80211_PREAMBLE_HE = 0x4 + NL80211_PREAMBLE_HT = 0x1 + NL80211_PREAMBLE_LEGACY = 0x0 + NL80211_PREAMBLE_VHT = 0x2 + NL80211_PROBE_RESP_OFFLOAD_SUPPORT_80211U = 0x8 + NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P = 0x4 + NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 = 0x2 + NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS = 0x1 + NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP = 0x1 + NL80211_PS_DISABLED = 0x0 + NL80211_PS_ENABLED = 0x1 + NL80211_RADAR_CAC_ABORTED = 0x2 + NL80211_RADAR_CAC_FINISHED = 0x1 + NL80211_RADAR_CAC_STARTED = 0x5 + NL80211_RADAR_DETECTED = 0x0 + NL80211_RADAR_NOP_FINISHED = 0x3 + NL80211_RADAR_PRE_CAC_EXPIRED = 0x4 + NL80211_RATE_INFO_10_MHZ_WIDTH = 0xb + NL80211_RATE_INFO_160_MHZ_WIDTH = 0xa + NL80211_RATE_INFO_40_MHZ_WIDTH = 0x3 + NL80211_RATE_INFO_5_MHZ_WIDTH = 0xc + NL80211_RATE_INFO_80_MHZ_WIDTH = 0x8 + NL80211_RATE_INFO_80P80_MHZ_WIDTH = 0x9 + NL80211_RATE_INFO_BITRATE32 = 0x5 + NL80211_RATE_INFO_BITRATE = 0x1 + NL80211_RATE_INFO_HE_1XLTF = 0x0 + NL80211_RATE_INFO_HE_2XLTF = 0x1 + NL80211_RATE_INFO_HE_4XLTF = 0x2 + NL80211_RATE_INFO_HE_DCM = 0x10 + NL80211_RATE_INFO_HE_GI_0_8 = 0x0 + NL80211_RATE_INFO_HE_GI_1_6 = 0x1 + NL80211_RATE_INFO_HE_GI_3_2 = 0x2 + NL80211_RATE_INFO_HE_GI = 0xf + NL80211_RATE_INFO_HE_MCS = 0xd + NL80211_RATE_INFO_HE_NSS = 0xe + NL80211_RATE_INFO_HE_RU_ALLOC_106 = 0x2 + NL80211_RATE_INFO_HE_RU_ALLOC_242 = 0x3 + NL80211_RATE_INFO_HE_RU_ALLOC_26 = 0x0 + NL80211_RATE_INFO_HE_RU_ALLOC_2x996 = 0x6 + NL80211_RATE_INFO_HE_RU_ALLOC_484 = 0x4 + NL80211_RATE_INFO_HE_RU_ALLOC_52 = 0x1 + NL80211_RATE_INFO_HE_RU_ALLOC_996 = 0x5 + NL80211_RATE_INFO_HE_RU_ALLOC = 0x11 + NL80211_RATE_INFO_MAX = 0x11 + NL80211_RATE_INFO_MCS = 0x2 + NL80211_RATE_INFO_SHORT_GI = 0x4 + NL80211_RATE_INFO_VHT_MCS = 0x6 + NL80211_RATE_INFO_VHT_NSS = 0x7 + NL80211_REGDOM_SET_BY_CORE = 0x0 + NL80211_REGDOM_SET_BY_COUNTRY_IE = 0x3 + NL80211_REGDOM_SET_BY_DRIVER = 0x2 + NL80211_REGDOM_SET_BY_USER = 0x1 + NL80211_REGDOM_TYPE_COUNTRY = 0x0 + NL80211_REGDOM_TYPE_CUSTOM_WORLD = 0x2 + NL80211_REGDOM_TYPE_INTERSECTION = 0x3 + NL80211_REGDOM_TYPE_WORLD = 0x1 + NL80211_REG_RULE_ATTR_MAX = 0x7 + NL80211_REKEY_DATA_AKM = 0x4 + NL80211_REKEY_DATA_KCK = 0x2 + NL80211_REKEY_DATA_KEK = 0x1 + NL80211_REKEY_DATA_REPLAY_CTR = 0x3 + NL80211_REPLAY_CTR_LEN = 0x8 + NL80211_RRF_AUTO_BW = 0x800 + NL80211_RRF_DFS = 0x10 + NL80211_RRF_GO_CONCURRENT = 0x1000 + NL80211_RRF_IR_CONCURRENT = 0x1000 + NL80211_RRF_NO_160MHZ = 0x10000 + NL80211_RRF_NO_80MHZ = 0x8000 + NL80211_RRF_NO_CCK = 0x2 + NL80211_RRF_NO_HE = 0x20000 + NL80211_RRF_NO_HT40 = 0x6000 + NL80211_RRF_NO_HT40MINUS = 0x2000 + NL80211_RRF_NO_HT40PLUS = 0x4000 + NL80211_RRF_NO_IBSS = 0x80 + NL80211_RRF_NO_INDOOR = 0x4 + NL80211_RRF_NO_IR_ALL = 0x180 + NL80211_RRF_NO_IR = 0x80 + NL80211_RRF_NO_OFDM = 0x1 + NL80211_RRF_NO_OUTDOOR = 0x8 + NL80211_RRF_PASSIVE_SCAN = 0x80 + NL80211_RRF_PTMP_ONLY = 0x40 + NL80211_RRF_PTP_ONLY = 0x20 + NL80211_RXMGMT_FLAG_ANSWERED = 0x1 + NL80211_RXMGMT_FLAG_EXTERNAL_AUTH = 0x2 + NL80211_SAE_PWE_BOTH = 0x3 + NL80211_SAE_PWE_HASH_TO_ELEMENT = 0x2 + NL80211_SAE_PWE_HUNT_AND_PECK = 0x1 + NL80211_SAE_PWE_UNSPECIFIED = 0x0 + NL80211_SAR_ATTR_MAX = 0x2 + NL80211_SAR_ATTR_SPECS = 0x2 + NL80211_SAR_ATTR_SPECS_END_FREQ = 0x4 + NL80211_SAR_ATTR_SPECS_MAX = 0x4 + NL80211_SAR_ATTR_SPECS_POWER = 0x1 + NL80211_SAR_ATTR_SPECS_RANGE_INDEX = 0x2 + NL80211_SAR_ATTR_SPECS_START_FREQ = 0x3 + NL80211_SAR_ATTR_TYPE = 0x1 + NL80211_SAR_TYPE_POWER = 0x0 + NL80211_SCAN_FLAG_ACCEPT_BCAST_PROBE_RESP = 0x20 + NL80211_SCAN_FLAG_AP = 0x4 + NL80211_SCAN_FLAG_COLOCATED_6GHZ = 0x4000 + NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME = 0x10 + NL80211_SCAN_FLAG_FLUSH = 0x2 + NL80211_SCAN_FLAG_FREQ_KHZ = 0x2000 + NL80211_SCAN_FLAG_HIGH_ACCURACY = 0x400 + NL80211_SCAN_FLAG_LOW_POWER = 0x200 + NL80211_SCAN_FLAG_LOW_PRIORITY = 0x1 + NL80211_SCAN_FLAG_LOW_SPAN = 0x100 + NL80211_SCAN_FLAG_MIN_PREQ_CONTENT = 0x1000 + NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION = 0x80 + NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE = 0x40 + NL80211_SCAN_FLAG_RANDOM_ADDR = 0x8 + NL80211_SCAN_FLAG_RANDOM_SN = 0x800 + NL80211_SCAN_RSSI_THOLD_OFF = -0x12c + NL80211_SCHED_SCAN_MATCH_ATTR_BSSID = 0x5 + NL80211_SCHED_SCAN_MATCH_ATTR_MAX = 0x6 + NL80211_SCHED_SCAN_MATCH_ATTR_RELATIVE_RSSI = 0x3 + NL80211_SCHED_SCAN_MATCH_ATTR_RSSI_ADJUST = 0x4 + NL80211_SCHED_SCAN_MATCH_ATTR_RSSI = 0x2 + NL80211_SCHED_SCAN_MATCH_ATTR_SSID = 0x1 + NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI = 0x6 + NL80211_SCHED_SCAN_PLAN_INTERVAL = 0x1 + NL80211_SCHED_SCAN_PLAN_ITERATIONS = 0x2 + NL80211_SCHED_SCAN_PLAN_MAX = 0x2 + NL80211_SMPS_DYNAMIC = 0x2 + NL80211_SMPS_MAX = 0x2 + NL80211_SMPS_OFF = 0x0 + NL80211_SMPS_STATIC = 0x1 + NL80211_STA_BSS_PARAM_BEACON_INTERVAL = 0x5 + NL80211_STA_BSS_PARAM_CTS_PROT = 0x1 + NL80211_STA_BSS_PARAM_DTIM_PERIOD = 0x4 + NL80211_STA_BSS_PARAM_MAX = 0x5 + NL80211_STA_BSS_PARAM_SHORT_PREAMBLE = 0x2 + NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME = 0x3 + NL80211_STA_FLAG_ASSOCIATED = 0x7 + NL80211_STA_FLAG_AUTHENTICATED = 0x5 + NL80211_STA_FLAG_AUTHORIZED = 0x1 + NL80211_STA_FLAG_MAX = 0x7 + NL80211_STA_FLAG_MAX_OLD_API = 0x6 + NL80211_STA_FLAG_MFP = 0x4 + NL80211_STA_FLAG_SHORT_PREAMBLE = 0x2 + NL80211_STA_FLAG_TDLS_PEER = 0x6 + NL80211_STA_FLAG_WME = 0x3 + NL80211_STA_INFO_ACK_SIGNAL_AVG = 0x23 + NL80211_STA_INFO_ACK_SIGNAL = 0x22 + NL80211_STA_INFO_AIRTIME_LINK_METRIC = 0x29 + NL80211_STA_INFO_AIRTIME_WEIGHT = 0x28 + NL80211_STA_INFO_ASSOC_AT_BOOTTIME = 0x2a + NL80211_STA_INFO_BEACON_LOSS = 0x12 + NL80211_STA_INFO_BEACON_RX = 0x1d + NL80211_STA_INFO_BEACON_SIGNAL_AVG = 0x1e + NL80211_STA_INFO_BSS_PARAM = 0xf + NL80211_STA_INFO_CHAIN_SIGNAL_AVG = 0x1a + NL80211_STA_INFO_CHAIN_SIGNAL = 0x19 + NL80211_STA_INFO_CONNECTED_TIME = 0x10 + NL80211_STA_INFO_CONNECTED_TO_AS = 0x2b + NL80211_STA_INFO_CONNECTED_TO_GATE = 0x26 + NL80211_STA_INFO_DATA_ACK_SIGNAL_AVG = 0x23 + NL80211_STA_INFO_EXPECTED_THROUGHPUT = 0x1b + NL80211_STA_INFO_FCS_ERROR_COUNT = 0x25 + NL80211_STA_INFO_INACTIVE_TIME = 0x1 + NL80211_STA_INFO_LLID = 0x4 + NL80211_STA_INFO_LOCAL_PM = 0x14 + NL80211_STA_INFO_MAX = 0x2b + NL80211_STA_INFO_NONPEER_PM = 0x16 + NL80211_STA_INFO_PAD = 0x21 + NL80211_STA_INFO_PEER_PM = 0x15 + NL80211_STA_INFO_PLID = 0x5 + NL80211_STA_INFO_PLINK_STATE = 0x6 + NL80211_STA_INFO_RX_BITRATE = 0xe + NL80211_STA_INFO_RX_BYTES64 = 0x17 + NL80211_STA_INFO_RX_BYTES = 0x2 + NL80211_STA_INFO_RX_DROP_MISC = 0x1c + NL80211_STA_INFO_RX_DURATION = 0x20 + NL80211_STA_INFO_RX_MPDUS = 0x24 + NL80211_STA_INFO_RX_PACKETS = 0x9 + NL80211_STA_INFO_SIGNAL_AVG = 0xd + NL80211_STA_INFO_SIGNAL = 0x7 + NL80211_STA_INFO_STA_FLAGS = 0x11 + NL80211_STA_INFO_TID_STATS = 0x1f + NL80211_STA_INFO_T_OFFSET = 0x13 + NL80211_STA_INFO_TX_BITRATE = 0x8 + NL80211_STA_INFO_TX_BYTES64 = 0x18 + NL80211_STA_INFO_TX_BYTES = 0x3 + NL80211_STA_INFO_TX_DURATION = 0x27 + NL80211_STA_INFO_TX_FAILED = 0xc + NL80211_STA_INFO_TX_PACKETS = 0xa + NL80211_STA_INFO_TX_RETRIES = 0xb + NL80211_STA_WME_MAX = 0x2 + NL80211_STA_WME_MAX_SP = 0x2 + NL80211_STA_WME_UAPSD_QUEUES = 0x1 + NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY = 0x5 + NL80211_SURVEY_INFO_CHANNEL_TIME = 0x4 + NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY = 0x6 + NL80211_SURVEY_INFO_CHANNEL_TIME_RX = 0x7 + NL80211_SURVEY_INFO_CHANNEL_TIME_TX = 0x8 + NL80211_SURVEY_INFO_FREQUENCY = 0x1 + NL80211_SURVEY_INFO_FREQUENCY_OFFSET = 0xc + NL80211_SURVEY_INFO_IN_USE = 0x3 + NL80211_SURVEY_INFO_MAX = 0xc + NL80211_SURVEY_INFO_NOISE = 0x2 + NL80211_SURVEY_INFO_PAD = 0xa + NL80211_SURVEY_INFO_TIME_BSS_RX = 0xb + NL80211_SURVEY_INFO_TIME_BUSY = 0x5 + NL80211_SURVEY_INFO_TIME = 0x4 + NL80211_SURVEY_INFO_TIME_EXT_BUSY = 0x6 + NL80211_SURVEY_INFO_TIME_RX = 0x7 + NL80211_SURVEY_INFO_TIME_SCAN = 0x9 + NL80211_SURVEY_INFO_TIME_TX = 0x8 + NL80211_TDLS_DISABLE_LINK = 0x4 + NL80211_TDLS_DISCOVERY_REQ = 0x0 + NL80211_TDLS_ENABLE_LINK = 0x3 + NL80211_TDLS_PEER_HE = 0x8 + NL80211_TDLS_PEER_HT = 0x1 + NL80211_TDLS_PEER_VHT = 0x2 + NL80211_TDLS_PEER_WMM = 0x4 + NL80211_TDLS_SETUP = 0x1 + NL80211_TDLS_TEARDOWN = 0x2 + NL80211_TID_CONFIG_ATTR_AMPDU_CTRL = 0x9 + NL80211_TID_CONFIG_ATTR_AMSDU_CTRL = 0xb + NL80211_TID_CONFIG_ATTR_MAX = 0xd + NL80211_TID_CONFIG_ATTR_NOACK = 0x6 + NL80211_TID_CONFIG_ATTR_OVERRIDE = 0x4 + NL80211_TID_CONFIG_ATTR_PAD = 0x1 + NL80211_TID_CONFIG_ATTR_PEER_SUPP = 0x3 + NL80211_TID_CONFIG_ATTR_RETRY_LONG = 0x8 + NL80211_TID_CONFIG_ATTR_RETRY_SHORT = 0x7 + NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL = 0xa + NL80211_TID_CONFIG_ATTR_TIDS = 0x5 + NL80211_TID_CONFIG_ATTR_TX_RATE = 0xd + NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE = 0xc + NL80211_TID_CONFIG_ATTR_VIF_SUPP = 0x2 + NL80211_TID_CONFIG_DISABLE = 0x1 + NL80211_TID_CONFIG_ENABLE = 0x0 + NL80211_TID_STATS_MAX = 0x6 + NL80211_TID_STATS_PAD = 0x5 + NL80211_TID_STATS_RX_MSDU = 0x1 + NL80211_TID_STATS_TX_MSDU = 0x2 + NL80211_TID_STATS_TX_MSDU_FAILED = 0x4 + NL80211_TID_STATS_TX_MSDU_RETRIES = 0x3 + NL80211_TID_STATS_TXQ_STATS = 0x6 + NL80211_TIMEOUT_ASSOC = 0x3 + NL80211_TIMEOUT_AUTH = 0x2 + NL80211_TIMEOUT_SCAN = 0x1 + NL80211_TIMEOUT_UNSPECIFIED = 0x0 + NL80211_TKIP_DATA_OFFSET_ENCR_KEY = 0x0 + NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY = 0x18 + NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY = 0x10 + NL80211_TX_POWER_AUTOMATIC = 0x0 + NL80211_TX_POWER_FIXED = 0x2 + NL80211_TX_POWER_LIMITED = 0x1 + NL80211_TXQ_ATTR_AC = 0x1 + NL80211_TXQ_ATTR_AIFS = 0x5 + NL80211_TXQ_ATTR_CWMAX = 0x4 + NL80211_TXQ_ATTR_CWMIN = 0x3 + NL80211_TXQ_ATTR_MAX = 0x5 + NL80211_TXQ_ATTR_QUEUE = 0x1 + NL80211_TXQ_ATTR_TXOP = 0x2 + NL80211_TXQ_Q_BE = 0x2 + NL80211_TXQ_Q_BK = 0x3 + NL80211_TXQ_Q_VI = 0x1 + NL80211_TXQ_Q_VO = 0x0 + NL80211_TXQ_STATS_BACKLOG_BYTES = 0x1 + NL80211_TXQ_STATS_BACKLOG_PACKETS = 0x2 + NL80211_TXQ_STATS_COLLISIONS = 0x8 + NL80211_TXQ_STATS_DROPS = 0x4 + NL80211_TXQ_STATS_ECN_MARKS = 0x5 + NL80211_TXQ_STATS_FLOWS = 0x3 + NL80211_TXQ_STATS_MAX = 0xb + NL80211_TXQ_STATS_MAX_FLOWS = 0xb + NL80211_TXQ_STATS_OVERLIMIT = 0x6 + NL80211_TXQ_STATS_OVERMEMORY = 0x7 + NL80211_TXQ_STATS_TX_BYTES = 0x9 + NL80211_TXQ_STATS_TX_PACKETS = 0xa + NL80211_TX_RATE_AUTOMATIC = 0x0 + NL80211_TXRATE_DEFAULT_GI = 0x0 + NL80211_TX_RATE_FIXED = 0x2 + NL80211_TXRATE_FORCE_LGI = 0x2 + NL80211_TXRATE_FORCE_SGI = 0x1 + NL80211_TXRATE_GI = 0x4 + NL80211_TXRATE_HE = 0x5 + NL80211_TXRATE_HE_GI = 0x6 + NL80211_TXRATE_HE_LTF = 0x7 + NL80211_TXRATE_HT = 0x2 + NL80211_TXRATE_LEGACY = 0x1 + NL80211_TX_RATE_LIMITED = 0x1 + NL80211_TXRATE_MAX = 0x7 + NL80211_TXRATE_MCS = 0x2 + NL80211_TXRATE_VHT = 0x3 + NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_INT = 0x1 + NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_MAX = 0x2 + NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_TMPL = 0x2 + NL80211_USER_REG_HINT_CELL_BASE = 0x1 + NL80211_USER_REG_HINT_INDOOR = 0x2 + NL80211_USER_REG_HINT_USER = 0x0 + NL80211_VENDOR_ID_IS_LINUX = 0x80000000 + NL80211_VHT_CAPABILITY_LEN = 0xc + NL80211_VHT_NSS_MAX = 0x8 + NL80211_WIPHY_NAME_MAXLEN = 0x40 + NL80211_WMMR_AIFSN = 0x3 + NL80211_WMMR_CW_MAX = 0x2 + NL80211_WMMR_CW_MIN = 0x1 + NL80211_WMMR_MAX = 0x4 + NL80211_WMMR_TXOP = 0x4 + NL80211_WOWLAN_PKTPAT_MASK = 0x1 + NL80211_WOWLAN_PKTPAT_OFFSET = 0x3 + NL80211_WOWLAN_PKTPAT_PATTERN = 0x2 + NL80211_WOWLAN_TCP_DATA_INTERVAL = 0x9 + NL80211_WOWLAN_TCP_DATA_PAYLOAD = 0x6 + NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ = 0x7 + NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN = 0x8 + NL80211_WOWLAN_TCP_DST_IPV4 = 0x2 + NL80211_WOWLAN_TCP_DST_MAC = 0x3 + NL80211_WOWLAN_TCP_DST_PORT = 0x5 + NL80211_WOWLAN_TCP_SRC_IPV4 = 0x1 + NL80211_WOWLAN_TCP_SRC_PORT = 0x4 + NL80211_WOWLAN_TCP_WAKE_MASK = 0xb + NL80211_WOWLAN_TCP_WAKE_PAYLOAD = 0xa + NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE = 0x8 + NL80211_WOWLAN_TRIG_ANY = 0x1 + NL80211_WOWLAN_TRIG_DISCONNECT = 0x2 + NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST = 0x7 + NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE = 0x6 + NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED = 0x5 + NL80211_WOWLAN_TRIG_MAGIC_PKT = 0x3 + NL80211_WOWLAN_TRIG_NET_DETECT = 0x12 + NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS = 0x13 + NL80211_WOWLAN_TRIG_PKT_PATTERN = 0x4 + NL80211_WOWLAN_TRIG_RFKILL_RELEASE = 0x9 + NL80211_WOWLAN_TRIG_TCP_CONNECTION = 0xe + NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211 = 0xa + NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN = 0xb + NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023 = 0xc + NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN = 0xd + NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST = 0x10 + NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH = 0xf + NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS = 0x11 + NL80211_WPA_VERSION_1 = 0x1 + NL80211_WPA_VERSION_2 = 0x2 + NL80211_WPA_VERSION_3 = 0x4 +) diff --git a/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_s390x.go b/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_s390x.go index 6358806106f..c426c35763a 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_s390x.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_s390x.go @@ -210,8 +210,8 @@ type PtraceFpregs struct { } type PtracePer struct { - _ [0]uint64 - _ [32]byte + Control_regs [3]uint64 + _ [8]byte Starting_addr uint64 Ending_addr uint64 Perc_atmid uint16 diff --git a/src/cmd/vendor/golang.org/x/sys/windows/exec_windows.go b/src/cmd/vendor/golang.org/x/sys/windows/exec_windows.go index 7a11e83b7ec..855698bb282 100644 --- a/src/cmd/vendor/golang.org/x/sys/windows/exec_windows.go +++ b/src/cmd/vendor/golang.org/x/sys/windows/exec_windows.go @@ -9,8 +9,6 @@ package windows import ( errorspkg "errors" "unsafe" - - "golang.org/x/sys/internal/unsafeheader" ) // EscapeArg rewrites command line argument s as prescribed @@ -147,8 +145,12 @@ func NewProcThreadAttributeList(maxAttrCount uint32) (*ProcThreadAttributeListCo } return nil, err } + alloc, err := LocalAlloc(LMEM_FIXED, uint32(size)) + if err != nil { + return nil, err + } // size is guaranteed to be ≥1 by InitializeProcThreadAttributeList. - al := &ProcThreadAttributeListContainer{data: (*ProcThreadAttributeList)(unsafe.Pointer(&make([]byte, size)[0]))} + al := &ProcThreadAttributeListContainer{data: (*ProcThreadAttributeList)(unsafe.Pointer(alloc))} err = initializeProcThreadAttributeList(al.data, maxAttrCount, 0, &size) if err != nil { return nil, err @@ -157,36 +159,17 @@ func NewProcThreadAttributeList(maxAttrCount uint32) (*ProcThreadAttributeListCo } // Update modifies the ProcThreadAttributeList using UpdateProcThreadAttribute. -// Note that the value passed to this function will be copied into memory -// allocated by LocalAlloc, the contents of which should not contain any -// Go-managed pointers, even if the passed value itself is a Go-managed -// pointer. func (al *ProcThreadAttributeListContainer) Update(attribute uintptr, value unsafe.Pointer, size uintptr) error { - alloc, err := LocalAlloc(LMEM_FIXED, uint32(size)) - if err != nil { - return err - } - var src, dst []byte - hdr := (*unsafeheader.Slice)(unsafe.Pointer(&src)) - hdr.Data = value - hdr.Cap = int(size) - hdr.Len = int(size) - hdr = (*unsafeheader.Slice)(unsafe.Pointer(&dst)) - hdr.Data = unsafe.Pointer(alloc) - hdr.Cap = int(size) - hdr.Len = int(size) - copy(dst, src) - al.heapAllocations = append(al.heapAllocations, alloc) - return updateProcThreadAttribute(al.data, 0, attribute, unsafe.Pointer(alloc), size, nil, nil) + al.pointers = append(al.pointers, value) + return updateProcThreadAttribute(al.data, 0, attribute, value, size, nil, nil) } // Delete frees ProcThreadAttributeList's resources. func (al *ProcThreadAttributeListContainer) Delete() { deleteProcThreadAttributeList(al.data) - for i := range al.heapAllocations { - LocalFree(Handle(al.heapAllocations[i])) - } - al.heapAllocations = nil + LocalFree(Handle(unsafe.Pointer(al.data))) + al.data = nil + al.pointers = nil } // List returns the actual ProcThreadAttributeList to be passed to StartupInfoEx. diff --git a/src/cmd/vendor/golang.org/x/sys/windows/syscall_windows.go b/src/cmd/vendor/golang.org/x/sys/windows/syscall_windows.go index 200b62a0032..98b7e4b4028 100644 --- a/src/cmd/vendor/golang.org/x/sys/windows/syscall_windows.go +++ b/src/cmd/vendor/golang.org/x/sys/windows/syscall_windows.go @@ -186,8 +186,8 @@ func NewCallbackCDecl(fn interface{}) uintptr { //sys GetNamedPipeInfo(pipe Handle, flags *uint32, outSize *uint32, inSize *uint32, maxInstances *uint32) (err error) //sys GetNamedPipeHandleState(pipe Handle, state *uint32, curInstances *uint32, maxCollectionCount *uint32, collectDataTimeout *uint32, userName *uint16, maxUserNameSize uint32) (err error) = GetNamedPipeHandleStateW //sys SetNamedPipeHandleState(pipe Handle, state *uint32, maxCollectionCount *uint32, collectDataTimeout *uint32) (err error) = SetNamedPipeHandleState -//sys ReadFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error) -//sys WriteFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error) +//sys readFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error) = ReadFile +//sys writeFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error) = WriteFile //sys GetOverlappedResult(handle Handle, overlapped *Overlapped, done *uint32, wait bool) (err error) //sys SetFilePointer(handle Handle, lowoffset int32, highoffsetptr *int32, whence uint32) (newlowoffset uint32, err error) [failretval==0xffffffff] //sys CloseHandle(handle Handle) (err error) @@ -363,6 +363,8 @@ func NewCallbackCDecl(fn interface{}) uintptr { //sys SetProcessWorkingSetSizeEx(hProcess Handle, dwMinimumWorkingSetSize uintptr, dwMaximumWorkingSetSize uintptr, flags uint32) (err error) //sys GetCommTimeouts(handle Handle, timeouts *CommTimeouts) (err error) //sys SetCommTimeouts(handle Handle, timeouts *CommTimeouts) (err error) +//sys GetActiveProcessorCount(groupNumber uint16) (ret uint32) +//sys GetMaximumProcessorCount(groupNumber uint16) (ret uint32) // Volume Management Functions //sys DefineDosDevice(flags uint32, deviceName *uint16, targetPath *uint16) (err error) = DefineDosDeviceW @@ -547,12 +549,6 @@ func Read(fd Handle, p []byte) (n int, err error) { } return 0, e } - if raceenabled { - if done > 0 { - raceWriteRange(unsafe.Pointer(&p[0]), int(done)) - } - raceAcquire(unsafe.Pointer(&ioSync)) - } return int(done), nil } @@ -565,12 +561,31 @@ func Write(fd Handle, p []byte) (n int, err error) { if e != nil { return 0, e } - if raceenabled && done > 0 { - raceReadRange(unsafe.Pointer(&p[0]), int(done)) - } return int(done), nil } +func ReadFile(fd Handle, p []byte, done *uint32, overlapped *Overlapped) error { + err := readFile(fd, p, done, overlapped) + if raceenabled { + if *done > 0 { + raceWriteRange(unsafe.Pointer(&p[0]), int(*done)) + } + raceAcquire(unsafe.Pointer(&ioSync)) + } + return err +} + +func WriteFile(fd Handle, p []byte, done *uint32, overlapped *Overlapped) error { + if raceenabled { + raceReleaseMerge(unsafe.Pointer(&ioSync)) + } + err := writeFile(fd, p, done, overlapped) + if raceenabled && *done > 0 { + raceReadRange(unsafe.Pointer(&p[0]), int(*done)) + } + return err +} + var ioSync int64 func Seek(fd Handle, offset int64, whence int) (newoffset int64, err error) { diff --git a/src/cmd/vendor/golang.org/x/sys/windows/types_windows.go b/src/cmd/vendor/golang.org/x/sys/windows/types_windows.go index 73087bf5e56..e19471c6a85 100644 --- a/src/cmd/vendor/golang.org/x/sys/windows/types_windows.go +++ b/src/cmd/vendor/golang.org/x/sys/windows/types_windows.go @@ -938,8 +938,8 @@ type StartupInfoEx struct { type ProcThreadAttributeList struct{} type ProcThreadAttributeListContainer struct { - data *ProcThreadAttributeList - heapAllocations []uintptr + data *ProcThreadAttributeList + pointers []unsafe.Pointer } type ProcessInformation struct { @@ -2749,6 +2749,43 @@ type PROCESS_BASIC_INFORMATION struct { InheritedFromUniqueProcessId uintptr } +type SYSTEM_PROCESS_INFORMATION struct { + NextEntryOffset uint32 + NumberOfThreads uint32 + WorkingSetPrivateSize int64 + HardFaultCount uint32 + NumberOfThreadsHighWatermark uint32 + CycleTime uint64 + CreateTime int64 + UserTime int64 + KernelTime int64 + ImageName NTUnicodeString + BasePriority int32 + UniqueProcessID uintptr + InheritedFromUniqueProcessID uintptr + HandleCount uint32 + SessionID uint32 + UniqueProcessKey *uint32 + PeakVirtualSize uintptr + VirtualSize uintptr + PageFaultCount uint32 + PeakWorkingSetSize uintptr + WorkingSetSize uintptr + QuotaPeakPagedPoolUsage uintptr + QuotaPagedPoolUsage uintptr + QuotaPeakNonPagedPoolUsage uintptr + QuotaNonPagedPoolUsage uintptr + PagefileUsage uintptr + PeakPagefileUsage uintptr + PrivatePageCount uintptr + ReadOperationCount int64 + WriteOperationCount int64 + OtherOperationCount int64 + ReadTransferCount int64 + WriteTransferCount int64 + OtherTransferCount int64 +} + // SystemInformationClasses for NtQuerySystemInformation and NtSetSystemInformation const ( SystemBasicInformation = iota @@ -3135,3 +3172,5 @@ type ModuleInfo struct { SizeOfImage uint32 EntryPoint uintptr } + +const ALL_PROCESSOR_GROUPS = 0xFFFF diff --git a/src/cmd/vendor/golang.org/x/sys/windows/zsyscall_windows.go b/src/cmd/vendor/golang.org/x/sys/windows/zsyscall_windows.go index 1055d47ed33..68f52c1e61e 100644 --- a/src/cmd/vendor/golang.org/x/sys/windows/zsyscall_windows.go +++ b/src/cmd/vendor/golang.org/x/sys/windows/zsyscall_windows.go @@ -226,6 +226,7 @@ var ( procFreeLibrary = modkernel32.NewProc("FreeLibrary") procGenerateConsoleCtrlEvent = modkernel32.NewProc("GenerateConsoleCtrlEvent") procGetACP = modkernel32.NewProc("GetACP") + procGetActiveProcessorCount = modkernel32.NewProc("GetActiveProcessorCount") procGetCommTimeouts = modkernel32.NewProc("GetCommTimeouts") procGetCommandLineW = modkernel32.NewProc("GetCommandLineW") procGetComputerNameExW = modkernel32.NewProc("GetComputerNameExW") @@ -251,6 +252,7 @@ var ( procGetLogicalDriveStringsW = modkernel32.NewProc("GetLogicalDriveStringsW") procGetLogicalDrives = modkernel32.NewProc("GetLogicalDrives") procGetLongPathNameW = modkernel32.NewProc("GetLongPathNameW") + procGetMaximumProcessorCount = modkernel32.NewProc("GetMaximumProcessorCount") procGetModuleFileNameW = modkernel32.NewProc("GetModuleFileNameW") procGetModuleHandleExW = modkernel32.NewProc("GetModuleHandleExW") procGetNamedPipeHandleStateW = modkernel32.NewProc("GetNamedPipeHandleStateW") @@ -1967,6 +1969,12 @@ func GetACP() (acp uint32) { return } +func GetActiveProcessorCount(groupNumber uint16) (ret uint32) { + r0, _, _ := syscall.Syscall(procGetActiveProcessorCount.Addr(), 1, uintptr(groupNumber), 0, 0) + ret = uint32(r0) + return +} + func GetCommTimeouts(handle Handle, timeouts *CommTimeouts) (err error) { r1, _, e1 := syscall.Syscall(procGetCommTimeouts.Addr(), 2, uintptr(handle), uintptr(unsafe.Pointer(timeouts)), 0) if r1 == 0 { @@ -2169,6 +2177,12 @@ func GetLongPathName(path *uint16, buf *uint16, buflen uint32) (n uint32, err er return } +func GetMaximumProcessorCount(groupNumber uint16) (ret uint32) { + r0, _, _ := syscall.Syscall(procGetMaximumProcessorCount.Addr(), 1, uintptr(groupNumber), 0, 0) + ret = uint32(r0) + return +} + func GetModuleFileName(module Handle, filename *uint16, size uint32) (n uint32, err error) { r0, _, e1 := syscall.Syscall(procGetModuleFileNameW.Addr(), 3, uintptr(module), uintptr(unsafe.Pointer(filename)), uintptr(size)) n = uint32(r0) @@ -2747,7 +2761,7 @@ func ReadDirectoryChanges(handle Handle, buf *byte, buflen uint32, watchSubTree return } -func ReadFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error) { +func readFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error) { var _p0 *byte if len(buf) > 0 { _p0 = &buf[0] @@ -3189,7 +3203,7 @@ func WriteConsole(console Handle, buf *uint16, towrite uint32, written *uint32, return } -func WriteFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error) { +func writeFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error) { var _p0 *byte if len(buf) > 0 { _p0 = &buf[0] diff --git a/src/cmd/vendor/modules.txt b/src/cmd/vendor/modules.txt index 9e797f555bd..6efe7abc5cb 100644 --- a/src/cmd/vendor/modules.txt +++ b/src/cmd/vendor/modules.txt @@ -24,10 +24,9 @@ golang.org/x/arch/arm/armasm golang.org/x/arch/arm64/arm64asm golang.org/x/arch/ppc64/ppc64asm golang.org/x/arch/x86/x86asm -# golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 +# golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd ## explicit; go 1.17 golang.org/x/crypto/ed25519 -golang.org/x/crypto/ed25519/internal/edwards25519 # golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 ## explicit; go 1.17 golang.org/x/mod/internal/lazyregexp @@ -42,7 +41,7 @@ golang.org/x/mod/zip # golang.org/x/sync v0.0.0-20210220032951-036812b2e83c ## explicit golang.org/x/sync/semaphore -# golang.org/x/sys v0.0.0-20211205182925-97ca703d548d +# golang.org/x/sys v0.0.0-20220317061510-51cd9980dadf ## explicit; go 1.17 golang.org/x/sys/internal/unsafeheader golang.org/x/sys/plan9 @@ -51,7 +50,7 @@ golang.org/x/sys/windows # golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 ## explicit; go 1.17 golang.org/x/term -# golang.org/x/tools v0.1.11-0.20220316221636-85d68bc98d0d +# golang.org/x/tools v0.1.11-0.20220317151829-c7b0e9aca63d ## explicit; go 1.17 golang.org/x/tools/cover golang.org/x/tools/go/analysis diff --git a/src/go.mod b/src/go.mod index bd6308add02..8830dc09896 100644 --- a/src/go.mod +++ b/src/go.mod @@ -1,13 +1,13 @@ module std -go 1.18 +go 1.19 require ( - golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 - golang.org/x/net v0.0.0-20211209124913-491a49abca63 + golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd + golang.org/x/net v0.0.0-20220225172249-27dd8689420f ) require ( - golang.org/x/sys v0.0.0-20211205182925-97ca703d548d // indirect - golang.org/x/text v0.3.8-0.20211105212822-18b340fc7af2 // indirect + golang.org/x/sys v0.0.0-20220317061510-51cd9980dadf // indirect + golang.org/x/text v0.3.8-0.20220124021120-d1c84af989ab // indirect ) diff --git a/src/go.sum b/src/go.sum index 8bf08531de6..70a22b98a3b 100644 --- a/src/go.sum +++ b/src/go.sum @@ -1,8 +1,8 @@ -golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 h1:0es+/5331RGQPcXlMfP+WrnIIS6dNnNRe0WB02W0F4M= -golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/net v0.0.0-20211209124913-491a49abca63 h1:iocB37TsdFuN6IBRZ+ry36wrkoV51/tl5vOWqkcPGvY= -golang.org/x/net v0.0.0-20211209124913-491a49abca63/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/sys v0.0.0-20211205182925-97ca703d548d h1:FjkYO/PPp4Wi0EAUOVLxePm7qVW4r4ctbWpURyuOD0E= -golang.org/x/sys v0.0.0-20211205182925-97ca703d548d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/text v0.3.8-0.20211105212822-18b340fc7af2 h1:GLw7MR8AfAG2GmGcmVgObFOHXYypgGjnGno25RDwn3Y= -golang.org/x/text v0.3.8-0.20211105212822-18b340fc7af2/go.mod h1:EFNZuWvGYxIRUEX+K8UmCFwYmZjqcrnq15ZuVldZkZ0= +golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd h1:XcWmESyNjXJMLahc3mqVQJcgSTDxFxhETVlfk9uGc38= +golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/net v0.0.0-20220225172249-27dd8689420f h1:oA4XRj0qtSt8Yo1Zms0CUlsT3KG69V2UGQWPBxujDmc= +golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= +golang.org/x/sys v0.0.0-20220317061510-51cd9980dadf h1:Fm4IcnUL803i92qDlmB0obyHmosDrxZWxJL3gIeNqOw= +golang.org/x/sys v0.0.0-20220317061510-51cd9980dadf/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/text v0.3.8-0.20220124021120-d1c84af989ab h1:eHo2TTVBaAPw9lDGK2Gb9GyPMXT6g7O63W6sx3ylbzU= +golang.org/x/text v0.3.8-0.20220124021120-d1c84af989ab/go.mod h1:EFNZuWvGYxIRUEX+K8UmCFwYmZjqcrnq15ZuVldZkZ0= diff --git a/src/net/http/h2_bundle.go b/src/net/http/h2_bundle.go index bb82f245858..e955135c50f 100644 --- a/src/net/http/h2_bundle.go +++ b/src/net/http/h2_bundle.go @@ -3010,6 +3010,10 @@ func (t *http2Transport) dialTLSWithContext(ctx context.Context, network, addr s return tlsCn, nil } +func http2tlsUnderlyingConn(tc *tls.Conn) net.Conn { + return tc.NetConn() +} + var http2DebugGoroutines = os.Getenv("DEBUG_HTTP2_GOROUTINES") == "1" type http2goroutineLock uint64 @@ -4439,7 +4443,7 @@ func (sc *http2serverConn) canonicalHeader(v string) string { // maxCachedCanonicalHeaders is an arbitrarily-chosen limit on the number of // entries in the canonHeader cache. This should be larger than the number // of unique, uncommon header keys likely to be sent by the peer, while not - // so high as to permit unreaasonable memory usage if the peer sends an unbounded + // so high as to permit unreasonable memory usage if the peer sends an unbounded // number of unique header keys. const maxCachedCanonicalHeaders = 32 if len(sc.canonHeader) < maxCachedCanonicalHeaders { @@ -7449,7 +7453,6 @@ func (cc *http2ClientConn) healthCheck() { err := cc.Ping(ctx) if err != nil { cc.closeForLostPing() - cc.t.connPool().MarkDead(cc) return } } @@ -7621,6 +7624,24 @@ func (cc *http2ClientConn) onIdleTimeout() { cc.closeIfIdle() } +func (cc *http2ClientConn) closeConn() error { + t := time.AfterFunc(250*time.Millisecond, cc.forceCloseConn) + defer t.Stop() + return cc.tconn.Close() +} + +// A tls.Conn.Close can hang for a long time if the peer is unresponsive. +// Try to shut it down more aggressively. +func (cc *http2ClientConn) forceCloseConn() { + tc, ok := cc.tconn.(*tls.Conn) + if !ok { + return + } + if nc := http2tlsUnderlyingConn(tc); nc != nil { + nc.Close() + } +} + func (cc *http2ClientConn) closeIfIdle() { cc.mu.Lock() if len(cc.streams) > 0 || cc.streamsReserved > 0 { @@ -7635,7 +7656,7 @@ func (cc *http2ClientConn) closeIfIdle() { if http2VerboseLogs { cc.vlogf("http2: Transport closing idle conn %p (forSingleUse=%v, maxStream=%v)", cc, cc.singleUse, nextID-2) } - cc.tconn.Close() + cc.closeConn() } func (cc *http2ClientConn) isDoNotReuseAndIdle() bool { @@ -7652,7 +7673,7 @@ func (cc *http2ClientConn) Shutdown(ctx context.Context) error { return err } // Wait for all in-flight streams to complete or connection to close - done := make(chan error, 1) + done := make(chan struct{}) cancelled := false // guarded by cc.mu go func() { cc.mu.Lock() @@ -7660,7 +7681,7 @@ func (cc *http2ClientConn) Shutdown(ctx context.Context) error { for { if len(cc.streams) == 0 || cc.closed { cc.closed = true - done <- cc.tconn.Close() + close(done) break } if cancelled { @@ -7671,8 +7692,8 @@ func (cc *http2ClientConn) Shutdown(ctx context.Context) error { }() http2shutdownEnterWaitStateHook() select { - case err := <-done: - return err + case <-done: + return cc.closeConn() case <-ctx.Done(): cc.mu.Lock() // Free the goroutine above @@ -7715,9 +7736,9 @@ func (cc *http2ClientConn) closeForError(err error) error { for _, cs := range cc.streams { cs.abortStreamLocked(err) } - defer cc.cond.Broadcast() - defer cc.mu.Unlock() - return cc.tconn.Close() + cc.cond.Broadcast() + cc.mu.Unlock() + return cc.closeConn() } // Close closes the client connection immediately. @@ -8692,7 +8713,7 @@ func (cc *http2ClientConn) forgetStreamID(id uint32) { cc.vlogf("http2: Transport closing idle conn %p (forSingleUse=%v, maxStream=%v)", cc, cc.singleUse, cc.nextStreamID-2) } cc.closed = true - defer cc.tconn.Close() + defer cc.closeConn() } cc.mu.Unlock() @@ -8739,8 +8760,8 @@ func http2isEOFOrNetReadError(err error) bool { func (rl *http2clientConnReadLoop) cleanup() { cc := rl.cc - defer cc.tconn.Close() - defer cc.t.connPool().MarkDead(cc) + cc.t.connPool().MarkDead(cc) + defer cc.closeConn() defer close(cc.readerDone) if cc.idleTimer != nil { diff --git a/src/vendor/golang.org/x/sys/cpu/syscall_aix_gccgo.go b/src/vendor/golang.org/x/sys/cpu/syscall_aix_gccgo.go index a864f24d758..96134157a10 100644 --- a/src/vendor/golang.org/x/sys/cpu/syscall_aix_gccgo.go +++ b/src/vendor/golang.org/x/sys/cpu/syscall_aix_gccgo.go @@ -5,7 +5,7 @@ // Recreate a getsystemcfg syscall handler instead of // using the one provided by x/sys/unix to avoid having // the dependency between them. (See golang.org/issue/32102) -// Morever, this file will be used during the building of +// Moreover, this file will be used during the building of // gccgo's libgo and thus must not used a CGo method. //go:build aix && gccgo diff --git a/src/vendor/modules.txt b/src/vendor/modules.txt index 3a975cde9e8..f9ae2c6aa8d 100644 --- a/src/vendor/modules.txt +++ b/src/vendor/modules.txt @@ -1,4 +1,4 @@ -# golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 +# golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd ## explicit; go 1.17 golang.org/x/crypto/chacha20 golang.org/x/crypto/chacha20poly1305 @@ -9,7 +9,7 @@ golang.org/x/crypto/curve25519/internal/field golang.org/x/crypto/hkdf golang.org/x/crypto/internal/poly1305 golang.org/x/crypto/internal/subtle -# golang.org/x/net v0.0.0-20211209124913-491a49abca63 +# golang.org/x/net v0.0.0-20220225172249-27dd8689420f ## explicit; go 1.17 golang.org/x/net/dns/dnsmessage golang.org/x/net/http/httpguts @@ -19,10 +19,10 @@ golang.org/x/net/idna golang.org/x/net/lif golang.org/x/net/nettest golang.org/x/net/route -# golang.org/x/sys v0.0.0-20211205182925-97ca703d548d +# golang.org/x/sys v0.0.0-20220317061510-51cd9980dadf ## explicit; go 1.17 golang.org/x/sys/cpu -# golang.org/x/text v0.3.8-0.20211105212822-18b340fc7af2 +# golang.org/x/text v0.3.8-0.20220124021120-d1c84af989ab ## explicit; go 1.17 golang.org/x/text/secure/bidirule golang.org/x/text/transform From 3d7392a08f00a7328af45c877dc0b3a431780c5b Mon Sep 17 00:00:00 2001 From: fangguizhen <1297394526@qq.com> Date: Thu, 27 May 2021 16:11:52 +0000 Subject: [PATCH 138/276] net/rpc: reduce the execution of reflect and decode Change-Id: Ief4b5e1c2d1002392901124c0694afe58c271573 GitHub-Last-Rev: e3b8a60377becfc9c30178d7ae6131d7a4b82dde GitHub-Pull-Request: golang/go#46421 Reviewed-on: https://go-review.googlesource.com/c/go/+/323014 Reviewed-by: Brad Fitzpatrick Trust: Brad Fitzpatrick Run-TryBot: Ian Lance Taylor TryBot-Result: Gopher Robot Trust: Ian Lance Taylor --- src/net/rpc/server.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/net/rpc/server.go b/src/net/rpc/server.go index f53ea75f9ce..0b3e6e3c58b 100644 --- a/src/net/rpc/server.go +++ b/src/net/rpc/server.go @@ -239,16 +239,16 @@ func (server *Server) register(rcvr any, name string, useName bool) error { s := new(service) s.typ = reflect.TypeOf(rcvr) s.rcvr = reflect.ValueOf(rcvr) - sname := reflect.Indirect(s.rcvr).Type().Name() - if useName { - sname = name + sname := name + if !useName { + sname = reflect.Indirect(s.rcvr).Type().Name() } if sname == "" { s := "rpc.Register: no service name for type " + s.typ.String() log.Print(s) return errors.New(s) } - if !token.IsExported(sname) && !useName { + if !useName && !token.IsExported(sname) { s := "rpc.Register: type " + sname + " is not exported" log.Print(s) return errors.New(s) From 2d32594396b231b39d09ec21d34b22b0270268b5 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Tue, 15 Mar 2022 21:05:11 -0700 Subject: [PATCH 139/276] runtime: call testenv.MustHaveCGO in a couple of tests Fixes #51695 Change-Id: Icfe9d26ecc28a7db9040d50d4661cf9e8245471e Reviewed-on: https://go-review.googlesource.com/c/go/+/392916 Trust: Ian Lance Taylor Run-TryBot: Ian Lance Taylor TryBot-Result: Gopher Robot Reviewed-by: Bryan Mills --- src/runtime/signal_windows_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/runtime/signal_windows_test.go b/src/runtime/signal_windows_test.go index 7c88ab573ea..ebe94797fb4 100644 --- a/src/runtime/signal_windows_test.go +++ b/src/runtime/signal_windows_test.go @@ -24,6 +24,7 @@ func TestVectoredHandlerDontCrashOnLibrary(t *testing.T) { t.Skip("this test can only run on windows/amd64") } testenv.MustHaveGoBuild(t) + testenv.MustHaveCGO(t) testenv.MustHaveExecPath(t, "gcc") testprog.Lock() defer testprog.Unlock() @@ -148,6 +149,7 @@ func TestLibraryCtrlHandler(t *testing.T) { t.Skip("this test can only run on windows/amd64") } testenv.MustHaveGoBuild(t) + testenv.MustHaveCGO(t) testenv.MustHaveExecPath(t, "gcc") testprog.Lock() defer testprog.Unlock() From 485d67bd38c94617921f55b99e89be0e9cbda39d Mon Sep 17 00:00:00 2001 From: Matt Layher Date: Thu, 17 Mar 2022 19:26:55 -0400 Subject: [PATCH 140/276] A+C: add PlanetScale, Inc. Change-Id: Ide2567dc66e55880b938b5814879f012c88159b8 Reviewed-on: https://go-review.googlesource.com/c/go/+/393697 Reviewed-by: Ian Lance Taylor Trust: Matt Layher --- AUTHORS | 1 + CONTRIBUTORS | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index 1a4a57bae7a..eba48215944 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1146,6 +1146,7 @@ Piers Pieter Droogendijk Pietro Gagliardi Piyush Mishra +PlanetScale, Inc. Platform.sh Pontus Leitzler Prasanga Siripala diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 48567eed15a..e4947941b4e 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -1791,7 +1791,7 @@ Matt Jibson Matt Joiner Matt Jones Matt Juran -Matt Layher +Matt Layher Matt Masurka Matt Pearring Matt Reiferson From 3ea22cf3c4b32e6473ad1358a3cbfccc11abc5be Mon Sep 17 00:00:00 2001 From: cuiweixie Date: Tue, 1 Feb 2022 00:36:33 +0000 Subject: [PATCH 141/276] crypto/x509: return err ans1.Marshal gives an error Fixes #50663 Change-Id: I18754922bf139049443c0395eaa1606049df1331 GitHub-Last-Rev: 57ff5ddfe39c211ccff60aa74a30f97ddf7015fb GitHub-Pull-Request: golang/go#50667 Reviewed-on: https://go-review.googlesource.com/c/go/+/379094 Reviewed-by: Katie Hockman Trust: Katie Hockman Reviewed-by: Ian Lance Taylor --- src/crypto/x509/x509.go | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/src/crypto/x509/x509.go b/src/crypto/x509/x509.go index 47be77d994d..837c42a3db2 100644 --- a/src/crypto/x509/x509.go +++ b/src/crypto/x509/x509.go @@ -1269,10 +1269,7 @@ func marshalKeyUsage(ku KeyUsage) (pkix.Extension, error) { bitString := a[:l] var err error ext.Value, err = asn1.Marshal(asn1.BitString{Bytes: bitString, BitLength: asn1BitLength(bitString)}) - if err != nil { - return ext, err - } - return ext, nil + return ext, err } func marshalExtKeyUsage(extUsages []ExtKeyUsage, unknownUsages []asn1.ObjectIdentifier) (pkix.Extension, error) { @@ -1291,10 +1288,7 @@ func marshalExtKeyUsage(extUsages []ExtKeyUsage, unknownUsages []asn1.ObjectIden var err error ext.Value, err = asn1.Marshal(oids) - if err != nil { - return ext, err - } - return ext, nil + return ext, err } func marshalBasicConstraints(isCA bool, maxPathLen int, maxPathLenZero bool) (pkix.Extension, error) { @@ -1307,10 +1301,7 @@ func marshalBasicConstraints(isCA bool, maxPathLen int, maxPathLenZero bool) (pk } var err error ext.Value, err = asn1.Marshal(basicConstraints{isCA, maxPathLen}) - if err != nil { - return ext, nil - } - return ext, nil + return ext, err } func marshalCertificatePolicies(policyIdentifiers []asn1.ObjectIdentifier) (pkix.Extension, error) { @@ -1321,10 +1312,7 @@ func marshalCertificatePolicies(policyIdentifiers []asn1.ObjectIdentifier) (pkix } var err error ext.Value, err = asn1.Marshal(policies) - if err != nil { - return ext, err - } - return ext, nil + return ext, err } func buildCSRExtensions(template *CertificateRequest) ([]pkix.Extension, error) { From 489102de18cff38d1b12d09eeb7e60af42492d63 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Thu, 17 Mar 2022 11:41:24 +0100 Subject: [PATCH 142/276] syscall: optimize UTF16{,Ptr}FromString Use bytealg.IndexByteString in UTF16FromString instead of an open-coded loop. Change-Id: I366448382f2d0adeca6b254131e0087a1f489258 Reviewed-on: https://go-review.googlesource.com/c/go/+/393614 Trust: Tobias Klauser Run-TryBot: Tobias Klauser TryBot-Result: Gopher Robot Reviewed-by: Ian Lance Taylor --- src/syscall/syscall_windows.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/syscall/syscall_windows.go b/src/syscall/syscall_windows.go index aba6c3f5fb8..adc865fd5ff 100644 --- a/src/syscall/syscall_windows.go +++ b/src/syscall/syscall_windows.go @@ -8,6 +8,7 @@ package syscall import ( errorspkg "errors" + "internal/bytealg" "internal/itoa" "internal/oserror" "internal/race" @@ -39,10 +40,8 @@ func StringToUTF16(s string) []uint16 { // s, with a terminating NUL added. If s contains a NUL byte at any // location, it returns (nil, EINVAL). func UTF16FromString(s string) ([]uint16, error) { - for i := 0; i < len(s); i++ { - if s[i] == 0 { - return nil, EINVAL - } + if bytealg.IndexByteString(s, 0) != -1 { + return nil, EINVAL } return utf16.Encode([]rune(s + "\x00")), nil } From adfee1e1e7b3236770c19d255e945613a53a34cc Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Thu, 17 Mar 2022 22:39:53 +0100 Subject: [PATCH 143/276] runtime/cgo: remove memset in _cgo_sys_thread_start on freebsd/arm pthread_attr_init on freebsd properly initializes the pthread_attr, there is no need to zero it before the call. The comment and code were probably copied from the linux/arm implementation. This aligns the implementation on freebsd/arm with the implementation on other freebsd architectures. Fixes #44248 Change-Id: If82ebb115b877b6c6f4862018a9419ba8d870f12 Reviewed-on: https://go-review.googlesource.com/c/go/+/393617 Trust: Tobias Klauser Run-TryBot: Tobias Klauser Reviewed-by: Ian Lance Taylor TryBot-Result: Gopher Robot Reviewed-by: Hajime Hoshi Trust: Hajime Hoshi --- src/runtime/cgo/gcc_freebsd_arm.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/runtime/cgo/gcc_freebsd_arm.c b/src/runtime/cgo/gcc_freebsd_arm.c index 74f2e0ede54..5f899783799 100644 --- a/src/runtime/cgo/gcc_freebsd_arm.c +++ b/src/runtime/cgo/gcc_freebsd_arm.c @@ -37,7 +37,6 @@ x_cgo_init(G *g, void (*setg)(void*)) pthread_attr_destroy(&attr); } - void _cgo_sys_thread_start(ThreadStart *ts) { @@ -50,12 +49,7 @@ _cgo_sys_thread_start(ThreadStart *ts) SIGFILLSET(ign); pthread_sigmask(SIG_SETMASK, &ign, &oset); - // Not sure why the memset is necessary here, - // but without it, we get a bogus stack size - // out of pthread_attr_getstacksize. C'est la Linux. - memset(&attr, 0, sizeof attr); pthread_attr_init(&attr); - size = 0; pthread_attr_getstacksize(&attr, &size); // Leave stacklo=0 and set stackhi=size; mstart will do the rest. ts->g->stackhi = size; From 3d19e8da7997eaf4ba18bfdf489c3bdb373a0c4d Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Fri, 18 Mar 2022 00:01:24 +0100 Subject: [PATCH 144/276] syscall: unskip TestDirentRepeat on freebsd TestDirentRepeat fails on FreeBSD 11, but seems to pass on newer versions. Go 1.18 is the last release to support FreeBSD 11 per https://golang.org/doc/go1.18#freebsd and there are no FreeBSD 11 builders anymore. Thus unskip TestDirentRepeat to verify the issue is indeed fixed on FreeBSD 12 and later. For #31416 Change-Id: I189ef06719ff830ffe2e402c74a75874c9e5b97b Reviewed-on: https://go-review.googlesource.com/c/go/+/393618 Trust: Tobias Klauser Run-TryBot: Tobias Klauser TryBot-Result: Gopher Robot Reviewed-by: Ian Lance Taylor --- src/syscall/dirent_test.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/syscall/dirent_test.go b/src/syscall/dirent_test.go index aeb40e57c18..a2d1b61342c 100644 --- a/src/syscall/dirent_test.go +++ b/src/syscall/dirent_test.go @@ -97,9 +97,6 @@ func TestDirentRepeat(t *testing.T) { if size < 1024 { size = 1024 // DIRBLKSIZ, see issue 31403. } - if runtime.GOOS == "freebsd" { - t.Skip("need to fix issue 31416 first") - } } // Make a directory containing N files From f02108636c3b098b3153e90b6478e292628ac4f9 Mon Sep 17 00:00:00 2001 From: Nuno Cruces Date: Thu, 17 Mar 2022 16:38:00 +0000 Subject: [PATCH 145/276] runtime: allow TestCtrlHandler to run in ConPTY Fixes #51602. Previous test would not run in a pseudo-console (ConPTY). New test avoids taskkill entirely by having the child request its own console window be closed. Verified that this runs locally (within a real console), over SSH (within a pseudo-console), and that it breaks if #41884 were reverted. Change-Id: If868b92ec36647e5d0e4107e29a2a6e048d35ced GitHub-Last-Rev: b1421e4bed2dc729c266928f002b39374d7e391a GitHub-Pull-Request: golang/go#51681 Reviewed-on: https://go-review.googlesource.com/c/go/+/392874 Reviewed-by: Bryan Mills Trust: Bryan Mills Run-TryBot: Bryan Mills TryBot-Result: Gopher Robot Reviewed-by: Alex Brainman Trust: Alex Brainman --- src/runtime/signal_windows_test.go | 32 ++++++------------- src/runtime/testdata/testwinsignal/main.go | 36 +++++++++++++++++++++- 2 files changed, 45 insertions(+), 23 deletions(-) diff --git a/src/runtime/signal_windows_test.go b/src/runtime/signal_windows_test.go index ebe94797fb4..add23cd2926 100644 --- a/src/runtime/signal_windows_test.go +++ b/src/runtime/signal_windows_test.go @@ -10,7 +10,6 @@ import ( "os/exec" "path/filepath" "runtime" - "strconv" "strings" "syscall" "testing" @@ -92,13 +91,16 @@ func TestCtrlHandler(t *testing.T) { // run test program cmd = exec.Command(exe) + var stdout bytes.Buffer var stderr bytes.Buffer + cmd.Stdout = &stdout cmd.Stderr = &stderr - outPipe, err := cmd.StdoutPipe() + inPipe, err := cmd.StdinPipe() if err != nil { - t.Fatalf("Failed to create stdout pipe: %v", err) + t.Fatalf("Failed to create stdin pipe: %v", err) } - outReader := bufio.NewReader(outPipe) + // keep inPipe alive until the end of the test + defer inPipe.Close() // in a new command window const _CREATE_NEW_CONSOLE = 0x00000010 @@ -114,29 +116,15 @@ func TestCtrlHandler(t *testing.T) { cmd.Wait() }() - // wait for child to be ready to receive signals - if line, err := outReader.ReadString('\n'); err != nil { - t.Fatalf("could not read stdout: %v", err) - } else if strings.TrimSpace(line) != "ready" { - t.Fatalf("unexpected message: %s", line) - } - - // gracefully kill pid, this closes the command window - if err := exec.Command("taskkill.exe", "/pid", strconv.Itoa(cmd.Process.Pid)).Run(); err != nil { - t.Fatalf("failed to kill: %v", err) + // check child exited gracefully, did not timeout + if err := cmd.Wait(); err != nil { + t.Fatalf("Program exited with error: %v\n%s", err, &stderr) } // check child received, handled SIGTERM - if line, err := outReader.ReadString('\n'); err != nil { - t.Fatalf("could not read stdout: %v", err) - } else if expected, got := syscall.SIGTERM.String(), strings.TrimSpace(line); expected != got { + if expected, got := syscall.SIGTERM.String(), strings.TrimSpace(stdout.String()); expected != got { t.Fatalf("Expected '%s' got: %s", expected, got) } - - // check child exited gracefully, did not timeout - if err := cmd.Wait(); err != nil { - t.Fatalf("Program exited with error: %v\n%s", err, &stderr) - } } // TestLibraryCtrlHandler tests that Go DLL allows calling program to handle console control events. diff --git a/src/runtime/testdata/testwinsignal/main.go b/src/runtime/testdata/testwinsignal/main.go index 1e7c9475fd6..e1136f38879 100644 --- a/src/runtime/testdata/testwinsignal/main.go +++ b/src/runtime/testdata/testwinsignal/main.go @@ -2,18 +2,52 @@ package main import ( "fmt" + "io" + "log" "os" "os/signal" + "syscall" "time" ) func main() { + // Ensure that this process terminates when the test times out, + // even if the expected signal never arrives. + go func() { + io.Copy(io.Discard, os.Stdin) + log.Fatal("stdin is closed; terminating") + }() + + // Register to receive all signals. c := make(chan os.Signal, 1) signal.Notify(c) - fmt.Println("ready") + // Get console window handle. + kernel32 := syscall.NewLazyDLL("kernel32.dll") + getConsoleWindow := kernel32.NewProc("GetConsoleWindow") + hwnd, _, err := getConsoleWindow.Call() + if hwnd == 0 { + log.Fatal("no associated console: ", err) + } + + // Send message to close the console window. + const _WM_CLOSE = 0x0010 + user32 := syscall.NewLazyDLL("user32.dll") + postMessage := user32.NewProc("PostMessageW") + ok, _, err := postMessage.Call(hwnd, _WM_CLOSE, 0, 0) + if ok == 0 { + log.Fatal("post message failed: ", err) + } + sig := <-c + // Allow some time for the handler to complete if it's going to. + // + // (In https://go.dev/issue/41884 the handler returned immediately, + // which caused Windows to terminate the program before the goroutine + // that received the SIGTERM had a chance to actually clean up.) time.Sleep(time.Second) + + // Print the signal's name: "terminated" makes the test succeed. fmt.Println(sig) } From 44320594855185b00af3abe038e52f7a00751d51 Mon Sep 17 00:00:00 2001 From: Changkun Ou Date: Fri, 26 Nov 2021 10:12:39 +0100 Subject: [PATCH 146/276] A+C: update Changkun Ou's email Add my current public email in both A+C, but keep old one too. Add my @changkun.de email to CONTRIBUTORS. Change-Id: Ic5a585582a5f5142fbdd0a132235c19f05d9e680 Reviewed-on: https://go-review.googlesource.com/c/go/+/367116 Run-TryBot: Changkun Ou TryBot-Result: Gopher Robot Reviewed-by: Ian Lance Taylor Reviewed-by: Ben Shi --- AUTHORS | 1 + CONTRIBUTORS | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index eba48215944..bffd52275d7 100644 --- a/AUTHORS +++ b/AUTHORS @@ -263,6 +263,7 @@ Casey Callendrello Casey Marshall Cezar Sá Espinola ChaiShushan +Changkun Ou Chaoqun Han Charles Fenwick Elliott Charles L. Dorian diff --git a/CONTRIBUTORS b/CONTRIBUTORS index e4947941b4e..e6ac7bda21d 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -486,7 +486,7 @@ Cedric Staub Cezar Sá Espinola Chad Rosier ChaiShushan -Changkun Ou +Changkun Ou Channing Kimble-Brown Chao Xu Chaoqun Han From 12eca21f1c1c0f048b985a2a8545fb304b4383f6 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Fri, 18 Mar 2022 11:49:40 +0100 Subject: [PATCH 147/276] syscall: use bytealg.IndexByte in clen MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ib3f92ea8371a13471acf9304dc9db66c0aae9bf4 Reviewed-on: https://go-review.googlesource.com/c/go/+/393756 Trust: Tobias Klauser Run-TryBot: Tobias Klauser Reviewed-by: Daniel Martí Trust: Daniel Martí TryBot-Result: Gopher Robot --- src/syscall/syscall_unix.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/syscall/syscall_unix.go b/src/syscall/syscall_unix.go index c35df430aaa..61ae09de4ed 100644 --- a/src/syscall/syscall_unix.go +++ b/src/syscall/syscall_unix.go @@ -7,6 +7,7 @@ package syscall import ( + "internal/bytealg" "internal/itoa" "internal/oserror" "internal/race" @@ -34,10 +35,8 @@ func RawSyscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errn // clen returns the index of the first NULL byte in n or len(n) if n contains no NULL byte. func clen(n []byte) int { - for i := 0; i < len(n); i++ { - if n[i] == 0 { - return i - } + if i := bytealg.IndexByte(n, 0); i != -1 { + return i } return len(n) } From 3684abbf6c82d7f151a30cce6f435ee203908b2c Mon Sep 17 00:00:00 2001 From: Cherry Mui Date: Tue, 15 Mar 2022 13:27:53 -0400 Subject: [PATCH 148/276] all: delete regabireflect goexperiment regabireflect goexperiment was helpful in the register ABI development, to control code paths for reflect calls, before the compiler can generate register ABI everywhere. It is not necessary for now. Drop it. Change-Id: I2731197d2f496e29616c426a01045c9b685946a4 Reviewed-on: https://go-review.googlesource.com/c/go/+/393362 Trust: Cherry Mui Run-TryBot: Cherry Mui TryBot-Result: Gopher Robot Reviewed-by: Michael Knyszek --- src/internal/abi/abi_arm64.go | 2 +- src/internal/abi/abi_generic.go | 2 +- src/internal/abi/abi_ppc64x.go | 2 +- src/internal/buildcfg/exp.go | 8 ++------ src/internal/goexperiment/exp_regabireflect_off.go | 9 --------- src/internal/goexperiment/exp_regabireflect_on.go | 9 --------- src/internal/goexperiment/flags.go | 5 ----- src/reflect/abi_test.go | 2 +- src/runtime/abi_test.go | 2 +- src/runtime/asm_arm64.s | 2 +- src/runtime/asm_ppc64x.s | 2 +- 11 files changed, 9 insertions(+), 36 deletions(-) delete mode 100644 src/internal/goexperiment/exp_regabireflect_off.go delete mode 100644 src/internal/goexperiment/exp_regabireflect_on.go diff --git a/src/internal/abi/abi_arm64.go b/src/internal/abi/abi_arm64.go index 5c3dd6cbe28..8f85901c478 100644 --- a/src/internal/abi/abi_arm64.go +++ b/src/internal/abi/abi_arm64.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build goexperiment.regabireflect +//go:build goexperiment.regabiargs package abi diff --git a/src/internal/abi/abi_generic.go b/src/internal/abi/abi_generic.go index a36745f402c..d7d2f3749bc 100644 --- a/src/internal/abi/abi_generic.go +++ b/src/internal/abi/abi_generic.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build !goexperiment.regabireflect && !amd64 +//go:build !goexperiment.regabiargs && !amd64 package abi diff --git a/src/internal/abi/abi_ppc64x.go b/src/internal/abi/abi_ppc64x.go index d47271d1a18..d51fb49bea2 100644 --- a/src/internal/abi/abi_ppc64x.go +++ b/src/internal/abi/abi_ppc64x.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build goexperiment.regabireflect && (ppc64 || ppc64le) +//go:build goexperiment.regabiargs && (ppc64 || ppc64le) package abi diff --git a/src/internal/buildcfg/exp.go b/src/internal/buildcfg/exp.go index a9b29d6718c..230ec0b231a 100644 --- a/src/internal/buildcfg/exp.go +++ b/src/internal/buildcfg/exp.go @@ -54,7 +54,6 @@ func ParseGOEXPERIMENT(goos, goarch, goexp string) (flags, baseline goexperiment baseline = goexperiment.Flags{ RegabiWrappers: regabiSupported, - RegabiReflect: regabiSupported, RegabiArgs: regabiSupported, PacerRedesign: true, } @@ -81,7 +80,6 @@ func ParseGOEXPERIMENT(goos, goarch, goexp string) (flags, baseline goexperiment // do the right thing. names["regabi"] = func(v bool) { flags.RegabiWrappers = v - flags.RegabiReflect = v flags.RegabiArgs = v } @@ -113,17 +111,15 @@ func ParseGOEXPERIMENT(goos, goarch, goexp string) (flags, baseline goexperiment // regabi is always enabled on amd64. if goarch == "amd64" { flags.RegabiWrappers = true - flags.RegabiReflect = true flags.RegabiArgs = true } // regabi is only supported on amd64, arm64, ppc64 and ppc64le. if !regabiSupported { - flags.RegabiReflect = false flags.RegabiArgs = false } // Check regabi dependencies. - if flags.RegabiArgs && !(flags.RegabiWrappers && flags.RegabiReflect) { - err = fmt.Errorf("GOEXPERIMENT regabiargs requires regabiwrappers,regabireflect") + if flags.RegabiArgs && !flags.RegabiWrappers { + err = fmt.Errorf("GOEXPERIMENT regabiargs requires regabiwrappers") } return } diff --git a/src/internal/goexperiment/exp_regabireflect_off.go b/src/internal/goexperiment/exp_regabireflect_off.go deleted file mode 100644 index 515f4a53e6c..00000000000 --- a/src/internal/goexperiment/exp_regabireflect_off.go +++ /dev/null @@ -1,9 +0,0 @@ -// Code generated by mkconsts.go. DO NOT EDIT. - -//go:build !goexperiment.regabireflect -// +build !goexperiment.regabireflect - -package goexperiment - -const RegabiReflect = false -const RegabiReflectInt = 0 diff --git a/src/internal/goexperiment/exp_regabireflect_on.go b/src/internal/goexperiment/exp_regabireflect_on.go deleted file mode 100644 index e8a3e9c06ac..00000000000 --- a/src/internal/goexperiment/exp_regabireflect_on.go +++ /dev/null @@ -1,9 +0,0 @@ -// Code generated by mkconsts.go. DO NOT EDIT. - -//go:build goexperiment.regabireflect -// +build goexperiment.regabireflect - -package goexperiment - -const RegabiReflect = true -const RegabiReflectInt = 1 diff --git a/src/internal/goexperiment/flags.go b/src/internal/goexperiment/flags.go index 6d935edc2b2..9150493575a 100644 --- a/src/internal/goexperiment/flags.go +++ b/src/internal/goexperiment/flags.go @@ -72,11 +72,6 @@ type Flags struct { // ABI0 and ABIInternal functions. Without this, the ABIs are // assumed to be identical so cross-ABI calls are direct. RegabiWrappers bool - // RegabiReflect enables the register-passing paths in - // reflection calls. This is also gated by intArgRegs in - // reflect and runtime (which are disabled by default) so it - // can be used in targeted tests. - RegabiReflect bool // RegabiArgs enables register arguments/results in all // compiled Go functions. // diff --git a/src/reflect/abi_test.go b/src/reflect/abi_test.go index f39eb5efeae..c9a4cd1c8e3 100644 --- a/src/reflect/abi_test.go +++ b/src/reflect/abi_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build goexperiment.regabireflect && goexperiment.regabiargs +//go:build goexperiment.regabiargs package reflect_test diff --git a/src/runtime/abi_test.go b/src/runtime/abi_test.go index f9e8d701ceb..0c9488a5f4e 100644 --- a/src/runtime/abi_test.go +++ b/src/runtime/abi_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build goexperiment.regabireflect +//go:build goexperiment.regabiargs // This file contains tests specific to making sure the register ABI // works in a bunch of contexts in the runtime. diff --git a/src/runtime/asm_arm64.s b/src/runtime/asm_arm64.s index 9e9d9314efc..46ffaaa9b3f 100644 --- a/src/runtime/asm_arm64.s +++ b/src/runtime/asm_arm64.s @@ -317,7 +317,7 @@ TEXT runtime·morestack_noctxt(SB),NOSPLIT|NOFRAME,$0-0 MOVW $0, R26 B runtime·morestack(SB) -#ifdef GOEXPERIMENT_regabireflect +#ifdef GOEXPERIMENT_regabiargs // spillArgs stores return values from registers to a *internal/abi.RegArgs in R20. TEXT ·spillArgs(SB),NOSPLIT,$0-0 MOVD R0, (0*8)(R20) diff --git a/src/runtime/asm_ppc64x.s b/src/runtime/asm_ppc64x.s index ae142139995..45e0c8240a1 100644 --- a/src/runtime/asm_ppc64x.s +++ b/src/runtime/asm_ppc64x.s @@ -788,7 +788,7 @@ TEXT runtime·cputicks(SB),NOSPLIT,$0-8 MOVD R3, ret+0(FP) RET -#ifdef GOEXPERIMENT_regabireflect +#ifdef GOEXPERIMENT_regabiargs // spillArgs stores return values from registers to a *internal/abi.RegArgs in R20. TEXT runtime·spillArgs(SB),NOSPLIT,$0-0 MOVD R3, 0(R20) From d8bee94be2fc2afa6418f0bf2d474c103d38c094 Mon Sep 17 00:00:00 2001 From: Cherry Mui Date: Wed, 16 Mar 2022 12:12:50 -0400 Subject: [PATCH 149/276] reflect, runtime: drop RegabiArgs conditions With the previous CL, internal/abi.IntArgRegs and FloatArgRegs is controlled by RegabiArgs (or always enabled), so there is no need to check for that goexperiment. There are a few places we guard register-ABI specific code and tests with the RegabiArgs flag. Switch to checking for the number of argument registers instead. Change-Id: I79fff9fd1e919684ffaf73aba9e7e85d5a9e1629 Reviewed-on: https://go-review.googlesource.com/c/go/+/393363 Trust: Cherry Mui Reviewed-by: Michael Knyszek Run-TryBot: Cherry Mui TryBot-Result: Gopher Robot --- src/reflect/abi.go | 7 +++---- src/runtime/debug_test.go | 5 ++--- src/runtime/stubs.go | 3 +-- src/runtime/traceback_test.go | 4 ++-- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/reflect/abi.go b/src/reflect/abi.go index 28204b81937..9957d237689 100644 --- a/src/reflect/abi.go +++ b/src/reflect/abi.go @@ -7,7 +7,6 @@ package reflect import ( "internal/abi" "internal/goarch" - "internal/goexperiment" "unsafe" ) @@ -30,9 +29,9 @@ import ( // commented out there should be the actual values once // we're ready to use the register ABI everywhere. var ( - intArgRegs = abi.IntArgRegs * goexperiment.RegabiArgsInt - floatArgRegs = abi.FloatArgRegs * goexperiment.RegabiArgsInt - floatRegSize = uintptr(abi.EffectiveFloatRegSize * goexperiment.RegabiArgsInt) + intArgRegs = abi.IntArgRegs + floatArgRegs = abi.FloatArgRegs + floatRegSize = uintptr(abi.EffectiveFloatRegSize) ) // abiStep represents an ABI "instruction." Each instruction diff --git a/src/runtime/debug_test.go b/src/runtime/debug_test.go index 5bb0c5cee3b..7698eacb595 100644 --- a/src/runtime/debug_test.go +++ b/src/runtime/debug_test.go @@ -16,7 +16,6 @@ package runtime_test import ( "fmt" "internal/abi" - "internal/goexperiment" "math" "os" "regexp" @@ -144,7 +143,7 @@ func TestDebugCall(t *testing.T) { intRegs := regs.Ints[:] floatRegs := regs.Floats[:] fval := float64(42.0) - if goexperiment.RegabiArgs { + if len(intRegs) > 0 { intRegs[0] = 42 floatRegs[0] = math.Float64bits(fval) } else { @@ -159,7 +158,7 @@ func TestDebugCall(t *testing.T) { } var result0 int var result1 float64 - if goexperiment.RegabiArgs { + if len(intRegs) > 0 { result0 = int(intRegs[0]) result1 = math.Float64frombits(floatRegs[0]) } else { diff --git a/src/runtime/stubs.go b/src/runtime/stubs.go index ad78363bb67..cd7c91029b0 100644 --- a/src/runtime/stubs.go +++ b/src/runtime/stubs.go @@ -7,7 +7,6 @@ package runtime import ( "internal/abi" "internal/goarch" - "internal/goexperiment" "runtime/internal/math" "unsafe" ) @@ -434,4 +433,4 @@ func sigpanic0() // registers the system supports. // // Protected by finlock. -var intArgRegs = abi.IntArgRegs * (goexperiment.RegabiArgsInt | goarch.IsAmd64) +var intArgRegs = abi.IntArgRegs diff --git a/src/runtime/traceback_test.go b/src/runtime/traceback_test.go index 7d8b04e14b7..e50bd95eade 100644 --- a/src/runtime/traceback_test.go +++ b/src/runtime/traceback_test.go @@ -6,7 +6,7 @@ package runtime_test import ( "bytes" - "internal/goexperiment" + "internal/abi" "internal/testenv" "runtime" "strings" @@ -23,7 +23,7 @@ func TestTracebackArgs(t *testing.T) { abiSel := func(x, y string) string { // select expected output based on ABI // In noopt build we always spill arguments so the output is the same as stack ABI. - if optimized && goexperiment.RegabiArgs { + if optimized && abi.IntArgRegs > 0 { return x } return y From 2c92b2349a0b735a447b07e6209f311ece8de91c Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Wed, 16 Mar 2022 16:25:47 -0400 Subject: [PATCH 150/276] internal/buildcfg: extract logic specific to cmd/go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit cmd/go/internal/cfg duplicates many of the fields of internal/buildcfg, but initializes them from a Go environment file in addition to the usual process environment. internal/buildcfg doesn't (and shouldn't) know or care about that environment file, but prior to this CL it exposed hooks for cmd/go/internal/cfg to write data back to internal/buildcfg to incorporate information from the file. It also produced quirky GOEXPERIMENT strings when a non-trivial default was overridden, seemingly so that 'go env' would produce those same quirky strings in edge-cases where they are needed. This change reverses that information flow: internal/buildcfg now exports a structured type with methods — instead of top-level functions communicating through global state — so that cmd/go can utilize its marshaling and unmarshaling functionality without also needing to write results back into buildcfg package state. The quirks specific to 'go env' have been eliminated by distinguishing between the raw GOEXPERIMENT value set by the user (which is what we should report from 'go env') and the cleaned, canonical equivalent (which is what we should use in the build cache key). For #51461. Change-Id: I4ef5b7c58b1fb3468497649a6d2fb6c19aa06c70 Reviewed-on: https://go-review.googlesource.com/c/go/+/393574 Trust: Bryan Mills Run-TryBot: Bryan Mills Reviewed-by: Russ Cox Reviewed-by: Matthew Dempsky TryBot-Result: Gopher Robot --- src/cmd/asm/internal/lex/input.go | 2 +- src/cmd/go/internal/cfg/cfg.go | 84 +++++++++++++++++++------------ src/cmd/go/internal/envcmd/env.go | 16 ++++-- src/cmd/go/internal/load/pkg.go | 4 +- src/cmd/go/internal/work/exec.go | 9 ++-- src/cmd/go/internal/work/gc.go | 3 +- src/cmd/go/main.go | 3 ++ src/cmd/internal/objabi/flag.go | 6 +-- src/cmd/internal/objabi/util.go | 2 +- src/cmd/link/internal/ld/main.go | 2 +- src/go/build/build.go | 2 +- src/internal/buildcfg/exp.go | 77 +++++++++++++--------------- 12 files changed, 118 insertions(+), 92 deletions(-) diff --git a/src/cmd/asm/internal/lex/input.go b/src/cmd/asm/internal/lex/input.go index e373ae817e0..276b4b0dcd6 100644 --- a/src/cmd/asm/internal/lex/input.go +++ b/src/cmd/asm/internal/lex/input.go @@ -50,7 +50,7 @@ func predefine(defines flags.MultiFlag) map[string]*Macro { // Set macros for GOEXPERIMENTs so we can easily switch // runtime assembly code based on them. if *flags.CompilingRuntime { - for _, exp := range buildcfg.EnabledExperiments() { + for _, exp := range buildcfg.Experiment.Enabled() { // Define macro. name := "GOEXPERIMENT_" + exp macros[name] = &Macro{ diff --git a/src/cmd/go/internal/cfg/cfg.go b/src/cmd/go/internal/cfg/cfg.go index deab3dddd0d..77c0e229e5e 100644 --- a/src/cmd/go/internal/cfg/cfg.go +++ b/src/cmd/go/internal/cfg/cfg.go @@ -22,6 +22,26 @@ import ( "cmd/go/internal/fsys" ) +// Global build parameters (used during package load) +var ( + Goos = envOr("GOOS", build.Default.GOOS) + Goarch = envOr("GOARCH", build.Default.GOARCH) + + ExeSuffix = exeSuffix() + + // ModulesEnabled specifies whether the go command is running + // in module-aware mode (as opposed to GOPATH mode). + // It is equal to modload.Enabled, but not all packages can import modload. + ModulesEnabled bool +) + +func exeSuffix() string { + if Goos == "windows" { + return ".exe" + } + return "" +} + // These are general "build flags" used by build and other commands. var ( BuildA bool // -a flag @@ -60,8 +80,6 @@ var ( // GoPathError is set when GOPATH is not set. it contains an // explanation why GOPATH is unset. GoPathError string - - GOEXPERIMENT = envOr("GOEXPERIMENT", buildcfg.DefaultGOEXPERIMENT) ) func defaultContext() build.Context { @@ -79,20 +97,15 @@ func defaultContext() build.Context { build.ToolDir = filepath.Join(ctxt.GOROOT, "pkg/tool/"+runtime.GOOS+"_"+runtime.GOARCH) } - ctxt.GOPATH = envOr("GOPATH", gopath(ctxt)) - // Override defaults computed in go/build with defaults // from go environment configuration file, if known. - ctxt.GOOS = envOr("GOOS", ctxt.GOOS) - ctxt.GOARCH = envOr("GOARCH", ctxt.GOARCH) + ctxt.GOPATH = envOr("GOPATH", gopath(ctxt)) + ctxt.GOOS = Goos + ctxt.GOARCH = Goarch - // The experiments flags are based on GOARCH, so they may - // need to change. TODO: This should be cleaned up. - buildcfg.UpdateExperiments(ctxt.GOOS, ctxt.GOARCH, GOEXPERIMENT) + // ToolTags are based on GOEXPERIMENT, which we will parse and + // initialize later. ctxt.ToolTags = nil - for _, exp := range buildcfg.EnabledExperiments() { - ctxt.ToolTags = append(ctxt.ToolTags, "goexperiment."+exp) - } // The go/build rule for whether cgo is enabled is: // 1. If $CGO_ENABLED is set, respect it. @@ -137,6 +150,33 @@ func init() { BuildToolchainLinker = func() string { return "missing-linker" } } +// Experiment configuration. +var ( + // RawGOEXPERIMENT is the GOEXPERIMENT value set by the user. + RawGOEXPERIMENT = envOr("GOEXPERIMENT", buildcfg.DefaultGOEXPERIMENT) + // CleanGOEXPERIMENT is the minimal GOEXPERIMENT value needed to reproduce the + // experiments enabled by RawGOEXPERIMENT. + CleanGOEXPERIMENT = RawGOEXPERIMENT + + Experiment *buildcfg.ExperimentFlags + ExperimentErr error +) + +func init() { + Experiment, ExperimentErr = buildcfg.ParseGOEXPERIMENT(Goos, Goarch, RawGOEXPERIMENT) + if ExperimentErr != nil { + return + } + + // GOEXPERIMENT is valid, so convert it to canonical form. + CleanGOEXPERIMENT = Experiment.String() + + // Add build tags based on the experiments in effect. + for _, exp := range Experiment.Enabled() { + BuildContext.ToolTags = append(BuildContext.ToolTags, "goexperiment."+exp) + } +} + // An EnvVar is an environment variable Name=Value. type EnvVar struct { Name string @@ -151,26 +191,6 @@ var OrigEnv []string // not CmdEnv. var CmdEnv []EnvVar -// Global build parameters (used during package load) -var ( - Goarch = BuildContext.GOARCH - Goos = BuildContext.GOOS - - ExeSuffix = exeSuffix() - - // ModulesEnabled specifies whether the go command is running - // in module-aware mode (as opposed to GOPATH mode). - // It is equal to modload.Enabled, but not all packages can import modload. - ModulesEnabled bool -) - -func exeSuffix() string { - if Goos == "windows" { - return ".exe" - } - return "" -} - var envCache struct { once sync.Once m map[string]string diff --git a/src/cmd/go/internal/envcmd/env.go b/src/cmd/go/internal/envcmd/env.go index c1adf8cef4c..fcabc8d1c71 100644 --- a/src/cmd/go/internal/envcmd/env.go +++ b/src/cmd/go/internal/envcmd/env.go @@ -74,7 +74,14 @@ func MkEnv() []cfg.EnvVar { {Name: "GOCACHE", Value: cache.DefaultDir()}, {Name: "GOENV", Value: envFile}, {Name: "GOEXE", Value: cfg.ExeSuffix}, - {Name: "GOEXPERIMENT", Value: buildcfg.GOEXPERIMENT()}, + + // List the raw value of GOEXPERIMENT, not the cleaned one. + // The set of default experiments may change from one release + // to the next, so a GOEXPERIMENT setting that is redundant + // with the current toolchain might actually be relevant with + // a different version (for example, when bisecting a regression). + {Name: "GOEXPERIMENT", Value: cfg.RawGOEXPERIMENT}, + {Name: "GOFLAGS", Value: cfg.Getenv("GOFLAGS")}, {Name: "GOHOSTARCH", Value: runtime.GOARCH}, {Name: "GOHOSTOS", Value: runtime.GOOS}, @@ -222,6 +229,9 @@ func runEnv(ctx context.Context, cmd *base.Command, args []string) { } buildcfg.Check() + if cfg.ExperimentErr != nil { + base.Fatalf("go: %v", cfg.ExperimentErr) + } env := cfg.CmdEnv env = append(env, ExtraEnvVars()...) @@ -374,9 +384,9 @@ func checkBuildConfig(add map[string]string, del map[string]bool) error { } } - goexperiment, okGOEXPERIMENT := get("GOEXPERIMENT", buildcfg.GOEXPERIMENT(), "") + goexperiment, okGOEXPERIMENT := get("GOEXPERIMENT", cfg.RawGOEXPERIMENT, buildcfg.DefaultGOEXPERIMENT) if okGOEXPERIMENT { - if _, _, err := buildcfg.ParseGOEXPERIMENT(goos, goarch, goexperiment); err != nil { + if _, err := buildcfg.ParseGOEXPERIMENT(goos, goarch, goexperiment); err != nil { return err } } diff --git a/src/cmd/go/internal/load/pkg.go b/src/cmd/go/internal/load/pkg.go index fdc00f95dca..8c169d1643a 100644 --- a/src/cmd/go/internal/load/pkg.go +++ b/src/cmd/go/internal/load/pkg.go @@ -2334,8 +2334,8 @@ func (p *Package) setBuildInfo() { } } appendSetting("GOARCH", cfg.BuildContext.GOARCH) - if cfg.GOEXPERIMENT != "" { - appendSetting("GOEXPERIMENT", cfg.GOEXPERIMENT) + if cfg.RawGOEXPERIMENT != "" { + appendSetting("GOEXPERIMENT", cfg.RawGOEXPERIMENT) } appendSetting("GOOS", cfg.BuildContext.GOOS) if key, val := cfg.GetArchEnv(); key != "" && val != "" { diff --git a/src/cmd/go/internal/work/exec.go b/src/cmd/go/internal/work/exec.go index 7d3a16c5f51..6d6837aa8a2 100644 --- a/src/cmd/go/internal/work/exec.go +++ b/src/cmd/go/internal/work/exec.go @@ -12,7 +12,6 @@ import ( "encoding/json" "errors" "fmt" - "internal/buildcfg" exec "internal/execabs" "internal/lazyregexp" "io" @@ -320,8 +319,8 @@ func (b *Builder) buildActionID(a *Action) cache.ActionID { key, val := cfg.GetArchEnv() fmt.Fprintf(h, "%s=%s\n", key, val) - if goexperiment := buildcfg.GOEXPERIMENT(); goexperiment != "" { - fmt.Fprintf(h, "GOEXPERIMENT=%q\n", goexperiment) + if cfg.CleanGOEXPERIMENT != "" { + fmt.Fprintf(h, "GOEXPERIMENT=%q\n", cfg.CleanGOEXPERIMENT) } // TODO(rsc): Convince compiler team not to add more magic environment variables, @@ -1301,8 +1300,8 @@ func (b *Builder) printLinkerConfig(h io.Writer, p *load.Package) { key, val := cfg.GetArchEnv() fmt.Fprintf(h, "%s=%s\n", key, val) - if goexperiment := buildcfg.GOEXPERIMENT(); goexperiment != "" { - fmt.Fprintf(h, "GOEXPERIMENT=%q\n", goexperiment) + if cfg.CleanGOEXPERIMENT != "" { + fmt.Fprintf(h, "GOEXPERIMENT=%q\n", cfg.CleanGOEXPERIMENT) } // The linker writes source file paths that say GOROOT_FINAL, but diff --git a/src/cmd/go/internal/work/gc.go b/src/cmd/go/internal/work/gc.go index e1e2b11dd73..a6174b2ed28 100644 --- a/src/cmd/go/internal/work/gc.go +++ b/src/cmd/go/internal/work/gc.go @@ -8,7 +8,6 @@ import ( "bufio" "bytes" "fmt" - "internal/buildcfg" "io" "log" "os" @@ -245,7 +244,7 @@ CheckFlags: } // TODO: Test and delete these conditions. - if buildcfg.Experiment.FieldTrack || buildcfg.Experiment.PreemptibleLoops { + if cfg.ExperimentErr != nil || cfg.Experiment.FieldTrack || cfg.Experiment.PreemptibleLoops { canDashC = false } diff --git a/src/cmd/go/main.go b/src/cmd/go/main.go index c0a1d3ccfc4..ed46ed822a6 100644 --- a/src/cmd/go/main.go +++ b/src/cmd/go/main.go @@ -190,6 +190,9 @@ func invoke(cmd *base.Command, args []string) { // 'go env' handles checking the build config if cmd != envcmd.CmdEnv { buildcfg.Check() + if cfg.ExperimentErr != nil { + base.Fatalf("go: %v", cfg.ExperimentErr) + } } // Set environment (GOOS, GOARCH, etc) explicitly. diff --git a/src/cmd/internal/objabi/flag.go b/src/cmd/internal/objabi/flag.go index f75c054fcb6..acb2dd59eaf 100644 --- a/src/cmd/internal/objabi/flag.go +++ b/src/cmd/internal/objabi/flag.go @@ -99,11 +99,11 @@ func (versionFlag) Set(s string) error { if s == "goexperiment" { // test/run.go uses this to discover the full set of // experiment tags. Report everything. - p = " X:" + strings.Join(buildcfg.AllExperiments(), ",") + p = " X:" + strings.Join(buildcfg.Experiment.All(), ",") } else { - // If the enabled experiments differ from the defaults, + // If the enabled experiments differ from the baseline, // include that difference. - if goexperiment := buildcfg.GOEXPERIMENT(); goexperiment != "" { + if goexperiment := buildcfg.Experiment.String(); goexperiment != "" { p = " X:" + goexperiment } } diff --git a/src/cmd/internal/objabi/util.go b/src/cmd/internal/objabi/util.go index 6bfa25a5cae..c2f1b204b98 100644 --- a/src/cmd/internal/objabi/util.go +++ b/src/cmd/internal/objabi/util.go @@ -22,5 +22,5 @@ const ( // or link object files that are incompatible with each other. This // string always starts with "go object ". func HeaderString() string { - return fmt.Sprintf("go object %s %s %s X:%s\n", buildcfg.GOOS, buildcfg.GOARCH, buildcfg.Version, strings.Join(buildcfg.EnabledExperiments(), ",")) + return fmt.Sprintf("go object %s %s %s X:%s\n", buildcfg.GOOS, buildcfg.GOARCH, buildcfg.Version, strings.Join(buildcfg.Experiment.Enabled(), ",")) } diff --git a/src/cmd/link/internal/ld/main.go b/src/cmd/link/internal/ld/main.go index 26f9db8ec41..d13c3ff8b61 100644 --- a/src/cmd/link/internal/ld/main.go +++ b/src/cmd/link/internal/ld/main.go @@ -124,7 +124,7 @@ func Main(arch *sys.Arch, theArch Arch) { addstrdata1(ctxt, "internal/buildcfg.defaultGOROOT="+final) buildVersion := buildcfg.Version - if goexperiment := buildcfg.GOEXPERIMENT(); goexperiment != "" { + if goexperiment := buildcfg.Experiment.String(); goexperiment != "" { buildVersion += " X:" + goexperiment } addstrdata1(ctxt, "runtime.buildVersion="+buildVersion) diff --git a/src/go/build/build.go b/src/go/build/build.go index c1d044e55a8..b0842b3a1a6 100644 --- a/src/go/build/build.go +++ b/src/go/build/build.go @@ -311,7 +311,7 @@ func defaultContext() Context { // used for compiling alternative files for the experiment. This allows // changes for the experiment, like extra struct fields in the runtime, // without affecting the base non-experiment code at all. - for _, exp := range buildcfg.EnabledExperiments() { + for _, exp := range buildcfg.Experiment.Enabled() { c.ToolTags = append(c.ToolTags, "goexperiment."+exp) } defaultToolTags = append([]string{}, c.ToolTags...) // our own private copy diff --git a/src/internal/buildcfg/exp.go b/src/internal/buildcfg/exp.go index 230ec0b231a..a56b36efdf5 100644 --- a/src/internal/buildcfg/exp.go +++ b/src/internal/buildcfg/exp.go @@ -12,6 +12,13 @@ import ( "internal/goexperiment" ) +// ExperimentFlags represents a set of GOEXPERIMENT flags relative to a baseline +// (platform-default) experiment configuration. +type ExperimentFlags struct { + goexperiment.Flags + baseline goexperiment.Flags +} + // Experiment contains the toolchain experiments enabled for the // current build. // @@ -21,14 +28,17 @@ import ( // experimentBaseline specifies the experiment flags that are enabled by // default in the current toolchain. This is, in effect, the "control" // configuration and any variation from this is an experiment. -var Experiment, experimentBaseline = func() (goexperiment.Flags, goexperiment.Flags) { - flags, baseline, err := ParseGOEXPERIMENT(GOOS, GOARCH, envOr("GOEXPERIMENT", defaultGOEXPERIMENT)) +var Experiment ExperimentFlags = func() ExperimentFlags { + flags, err := ParseGOEXPERIMENT(GOOS, GOARCH, envOr("GOEXPERIMENT", defaultGOEXPERIMENT)) if err != nil { Error = err + return ExperimentFlags{} } - return flags, baseline + return *flags }() +// DefaultGOEXPERIMENT is the embedded default GOEXPERIMENT string. +// It is not guaranteed to be canonical. const DefaultGOEXPERIMENT = defaultGOEXPERIMENT // FramePointerEnabled enables the use of platform conventions for @@ -45,21 +55,24 @@ var FramePointerEnabled = GOARCH == "amd64" || GOARCH == "arm64" // flag sets. // // TODO(mdempsky): Move to internal/goexperiment. -func ParseGOEXPERIMENT(goos, goarch, goexp string) (flags, baseline goexperiment.Flags, err error) { +func ParseGOEXPERIMENT(goos, goarch, goexp string) (*ExperimentFlags, error) { regabiSupported := false switch goarch { case "amd64", "arm64", "ppc64le", "ppc64": regabiSupported = true } - baseline = goexperiment.Flags{ + baseline := goexperiment.Flags{ RegabiWrappers: regabiSupported, RegabiArgs: regabiSupported, PacerRedesign: true, } // Start with the statically enabled set of experiments. - flags = baseline + flags := &ExperimentFlags{ + Flags: baseline, + baseline: baseline, + } // Pick up any changes to the baseline configuration from the // GOEXPERIMENT environment. This can be set at make.bash time @@ -67,7 +80,7 @@ func ParseGOEXPERIMENT(goos, goarch, goexp string) (flags, baseline goexperiment if goexp != "" { // Create a map of known experiment names. names := make(map[string]func(bool)) - rv := reflect.ValueOf(&flags).Elem() + rv := reflect.ValueOf(&flags.Flags).Elem() rt := rv.Type() for i := 0; i < rt.NumField(); i++ { field := rv.Field(i) @@ -92,7 +105,7 @@ func ParseGOEXPERIMENT(goos, goarch, goexp string) (flags, baseline goexperiment // GOEXPERIMENT=none disables all experiment flags. // This is used by cmd/dist, which doesn't know how // to build with any experiment flags. - flags = goexperiment.Flags{} + flags.Flags = goexperiment.Flags{} continue } val := true @@ -101,8 +114,7 @@ func ParseGOEXPERIMENT(goos, goarch, goexp string) (flags, baseline goexperiment } set, ok := names[f] if !ok { - err = fmt.Errorf("unknown GOEXPERIMENT %s", f) - return + return nil, fmt.Errorf("unknown GOEXPERIMENT %s", f) } set(val) } @@ -119,9 +131,15 @@ func ParseGOEXPERIMENT(goos, goarch, goexp string) (flags, baseline goexperiment } // Check regabi dependencies. if flags.RegabiArgs && !flags.RegabiWrappers { - err = fmt.Errorf("GOEXPERIMENT regabiargs requires regabiwrappers") + return nil, fmt.Errorf("GOEXPERIMENT regabiargs requires regabiwrappers") } - return + return flags, nil +} + +// String returns the canonical GOEXPERIMENT string to enable this experiment +// configuration. (Experiments in the same state as in the baseline are elided.) +func (exp *ExperimentFlags) String() string { + return strings.Join(expList(&exp.Flags, &exp.baseline, false), ",") } // expList returns the list of lower-cased experiment names for @@ -154,37 +172,14 @@ func expList(exp, base *goexperiment.Flags, all bool) []string { return list } -// GOEXPERIMENT is a comma-separated list of enabled or disabled -// experiments that differ from the baseline experiment configuration. -// GOEXPERIMENT is exactly what a user would set on the command line -// to get the set of enabled experiments. -func GOEXPERIMENT() string { - goexp := strings.Join(expList(&Experiment, &experimentBaseline, false), ",") - if goexp == "" && DefaultGOEXPERIMENT != "" { - goexp = "," // non-empty to override DefaultGOEXPERIMENT - } - return goexp -} - -// EnabledExperiments returns a list of enabled experiments, as +// Enabled returns a list of enabled experiments, as // lower-cased experiment names. -func EnabledExperiments() []string { - return expList(&Experiment, nil, false) +func (exp *ExperimentFlags) Enabled() []string { + return expList(&exp.Flags, nil, false) } -// AllExperiments returns a list of all experiment settings. +// All returns a list of all experiment settings. // Disabled experiments appear in the list prefixed by "no". -func AllExperiments() []string { - return expList(&Experiment, nil, true) -} - -// UpdateExperiments updates the Experiment global based on a new GOARCH value. -// This is only required for cmd/go, which can change GOARCH after -// program startup due to use of "go env -w". -func UpdateExperiments(goos, goarch, goexperiment string) { - var err error - Experiment, experimentBaseline, err = ParseGOEXPERIMENT(goos, goarch, goexperiment) - if err != nil { - Error = err - } +func (exp *ExperimentFlags) All() []string { + return expList(&exp.Flags, nil, true) } From 8ff42d1bb1919b38e0d852618168f18d33db866b Mon Sep 17 00:00:00 2001 From: Cherry Mui Date: Wed, 2 Mar 2022 11:59:48 -0500 Subject: [PATCH 151/276] internal/abi, internal/buildcfg: always enable register ABI on ARM64 In last cycle we developed register ABI for ARM64, enabled by default as a GOEXPERIMENT. This cycle we turn it on all the time. Later CLs will clean up fallback code. To support in-development platforms (e.g. RISC-V), separate the boolean variables for in-development platforms and always-on platforms. Change-Id: I97c27f6aeccc85ccc57eed2abd783b176da3ad80 Reviewed-on: https://go-review.googlesource.com/c/go/+/393364 Trust: Cherry Mui Reviewed-by: Michael Knyszek Run-TryBot: Cherry Mui TryBot-Result: Gopher Robot --- src/internal/abi/abi_arm64.go | 2 -- src/internal/abi/abi_generic.go | 2 +- src/internal/buildcfg/exp.go | 14 ++++++++++---- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/internal/abi/abi_arm64.go b/src/internal/abi/abi_arm64.go index 8f85901c478..4dc51431bfb 100644 --- a/src/internal/abi/abi_arm64.go +++ b/src/internal/abi/abi_arm64.go @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build goexperiment.regabiargs - package abi const ( diff --git a/src/internal/abi/abi_generic.go b/src/internal/abi/abi_generic.go index d7d2f3749bc..bc8483b4f93 100644 --- a/src/internal/abi/abi_generic.go +++ b/src/internal/abi/abi_generic.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build !goexperiment.regabiargs && !amd64 +//go:build !goexperiment.regabiargs && !amd64 && !arm64 package abi diff --git a/src/internal/buildcfg/exp.go b/src/internal/buildcfg/exp.go index a56b36efdf5..b2bf9b2c832 100644 --- a/src/internal/buildcfg/exp.go +++ b/src/internal/buildcfg/exp.go @@ -56,9 +56,16 @@ var FramePointerEnabled = GOARCH == "amd64" || GOARCH == "arm64" // // TODO(mdempsky): Move to internal/goexperiment. func ParseGOEXPERIMENT(goos, goarch, goexp string) (*ExperimentFlags, error) { - regabiSupported := false + // regabiSupported is set to true on platforms where register ABI is + // supported and enabled by default. + // regabiAlwaysOn is set to true on platforms where register ABI is + // always on. + var regabiSupported, regabiAlwaysOn bool switch goarch { - case "amd64", "arm64", "ppc64le", "ppc64": + case "amd64", "arm64": + regabiAlwaysOn = true + fallthrough + case "ppc64le", "ppc64": regabiSupported = true } @@ -120,8 +127,7 @@ func ParseGOEXPERIMENT(goos, goarch, goexp string) (*ExperimentFlags, error) { } } - // regabi is always enabled on amd64. - if goarch == "amd64" { + if regabiAlwaysOn { flags.RegabiWrappers = true flags.RegabiArgs = true } From 7747c33a41491be74da65b116718f4df7a2f8337 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Sat, 29 Jan 2022 16:13:12 -0500 Subject: [PATCH 152/276] internal/diff: add, replacing cmd/internal/diff MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is an in-process (non-exec'ing) replacement for cmd/internal/diff. It uses an O(n log n) algorithm instead of the O(n²) algorithm in standard diff binaries. It does not produce the absolute shortest diffs, but the results are often more meaningful than the standard diff, because it doesn't try to align random blank lines or other noise. Adding so that tests inside std (especially go/printer) can print diffs. Replacing cmd/internal/diff because we don't need two. Change-Id: I9155dd925e4a813f5bfa84a8ad3dec8ffdbf8550 Reviewed-on: https://go-review.googlesource.com/c/go/+/384255 Trust: Russ Cox Run-TryBot: Russ Cox TryBot-Result: Gopher Robot Reviewed-by: Peter Weinberger Trust: Peter Weinberger --- src/cmd/fix/main.go | 10 +- src/cmd/fix/main_test.go | 18 +- src/cmd/gofmt/gofmt.go | 49 +---- src/cmd/gofmt/gofmt_test.go | 76 +------- src/cmd/internal/diff/diff.go | 78 -------- src/go/build/deps_test.go | 2 +- src/go/printer/printer_test.go | 36 +--- src/internal/diff/diff.go | 262 ++++++++++++++++++++++++++ src/internal/diff/diff_test.go | 43 +++++ src/internal/diff/testdata/allnew.txt | 13 ++ src/internal/diff/testdata/allold.txt | 13 ++ src/internal/diff/testdata/basic.txt | 35 ++++ src/internal/diff/testdata/dups.txt | 40 ++++ src/internal/diff/testdata/end.txt | 38 ++++ src/internal/diff/testdata/eof.txt | 9 + src/internal/diff/testdata/eof1.txt | 18 ++ src/internal/diff/testdata/eof2.txt | 18 ++ src/internal/diff/testdata/long.txt | 62 ++++++ src/internal/diff/testdata/same.txt | 5 + src/internal/diff/testdata/start.txt | 34 ++++ src/internal/diff/testdata/triv.txt | 40 ++++ 21 files changed, 652 insertions(+), 247 deletions(-) delete mode 100644 src/cmd/internal/diff/diff.go create mode 100644 src/internal/diff/diff.go create mode 100644 src/internal/diff/diff_test.go create mode 100644 src/internal/diff/testdata/allnew.txt create mode 100644 src/internal/diff/testdata/allold.txt create mode 100644 src/internal/diff/testdata/basic.txt create mode 100644 src/internal/diff/testdata/dups.txt create mode 100644 src/internal/diff/testdata/end.txt create mode 100644 src/internal/diff/testdata/eof.txt create mode 100644 src/internal/diff/testdata/eof1.txt create mode 100644 src/internal/diff/testdata/eof2.txt create mode 100644 src/internal/diff/testdata/long.txt create mode 100644 src/internal/diff/testdata/same.txt create mode 100644 src/internal/diff/testdata/start.txt create mode 100644 src/internal/diff/testdata/triv.txt diff --git a/src/cmd/fix/main.go b/src/cmd/fix/main.go index 3229b71ec48..4e5c08731bb 100644 --- a/src/cmd/fix/main.go +++ b/src/cmd/fix/main.go @@ -13,6 +13,7 @@ import ( "go/parser" "go/scanner" "go/token" + "internal/diff" "io" "io/fs" "os" @@ -20,8 +21,6 @@ import ( "sort" "strconv" "strings" - - "cmd/internal/diff" ) var ( @@ -228,12 +227,7 @@ func processFile(filename string, useStdin bool) error { } if *doDiff { - data, err := diff.Diff("go-fix", src, newSrc) - if err != nil { - return fmt.Errorf("computing diff: %s", err) - } - fmt.Printf("diff %s fixed/%s\n", filename, filename) - os.Stdout.Write(data) + os.Stdout.Write(diff.Diff(filename, src, "fixed/"+filename, newSrc)) return nil } diff --git a/src/cmd/fix/main_test.go b/src/cmd/fix/main_test.go index 1baa95c5456..755007bc0d3 100644 --- a/src/cmd/fix/main_test.go +++ b/src/cmd/fix/main_test.go @@ -7,10 +7,9 @@ package main import ( "go/ast" "go/parser" + "internal/diff" "strings" "testing" - - "cmd/internal/diff" ) type testCase struct { @@ -52,7 +51,7 @@ func parseFixPrint(t *testing.T, fn func(*ast.File) bool, desc, in string, mustB if s := string(outb); in != s && mustBeGofmt { t.Errorf("not gofmt-formatted.\n--- %s\n%s\n--- %s | gofmt\n%s", desc, in, desc, s) - tdiff(t, in, s) + tdiff(t, "want", in, "have", s) return } @@ -109,7 +108,7 @@ func TestRewrite(t *testing.T) { if !strings.HasPrefix(tt.Name, "testdata/") { t.Errorf("--- have\n%s\n--- want\n%s", out, tt.Out) } - tdiff(t, out, tt.Out) + tdiff(t, "have", out, "want", tt.Out) return } @@ -132,17 +131,12 @@ func TestRewrite(t *testing.T) { if out2 != out { t.Errorf("changed output after second round of fixes.\n--- output after first round\n%s\n--- output after second round\n%s", out, out2) - tdiff(t, out, out2) + tdiff(t, "first", out, "second", out2) } }) } } -func tdiff(t *testing.T, a, b string) { - data, err := diff.Diff("go-fix-test", []byte(a), []byte(b)) - if err != nil { - t.Error(err) - return - } - t.Error(string(data)) +func tdiff(t *testing.T, aname, a, bname, b string) { + t.Errorf("%s", diff.Diff(aname, []byte(a), bname, []byte(b))) } diff --git a/src/cmd/gofmt/gofmt.go b/src/cmd/gofmt/gofmt.go index 4280ed44590..8efc88df887 100644 --- a/src/cmd/gofmt/gofmt.go +++ b/src/cmd/gofmt/gofmt.go @@ -14,6 +14,7 @@ import ( "go/printer" "go/scanner" "go/token" + "internal/diff" "io" "io/fs" "os" @@ -22,8 +23,6 @@ import ( "runtime/pprof" "strings" - "cmd/internal/diff" - "golang.org/x/sync/semaphore" ) @@ -287,12 +286,9 @@ func processFile(filename string, info fs.FileInfo, in io.Reader, r *reporter) e } } if *doDiff { - data, err := diffWithReplaceTempFile(src, res, filename) - if err != nil { - return fmt.Errorf("computing diff: %s", err) - } - fmt.Fprintf(r, "diff -u %s %s\n", filepath.ToSlash(filename+".orig"), filepath.ToSlash(filename)) - r.Write(data) + newName := filepath.ToSlash(filename) + oldName := newName + ".orig" + r.Write(diff.Diff(oldName, src, newName, res)) } } @@ -464,43 +460,6 @@ func fileWeight(path string, info fs.FileInfo) int64 { return info.Size() } -func diffWithReplaceTempFile(b1, b2 []byte, filename string) ([]byte, error) { - data, err := diff.Diff("gofmt", b1, b2) - if len(data) > 0 { - return replaceTempFilename(data, filename) - } - return data, err -} - -// replaceTempFilename replaces temporary filenames in diff with actual one. -// -// --- /tmp/gofmt316145376 2017-02-03 19:13:00.280468375 -0500 -// +++ /tmp/gofmt617882815 2017-02-03 19:13:00.280468375 -0500 -// ... -// -> -// --- path/to/file.go.orig 2017-02-03 19:13:00.280468375 -0500 -// +++ path/to/file.go 2017-02-03 19:13:00.280468375 -0500 -// ... -func replaceTempFilename(diff []byte, filename string) ([]byte, error) { - bs := bytes.SplitN(diff, []byte{'\n'}, 3) - if len(bs) < 3 { - return nil, fmt.Errorf("got unexpected diff for %s", filename) - } - // Preserve timestamps. - var t0, t1 []byte - if i := bytes.LastIndexByte(bs[0], '\t'); i != -1 { - t0 = bs[0][i:] - } - if i := bytes.LastIndexByte(bs[1], '\t'); i != -1 { - t1 = bs[1][i:] - } - // Always print filepath with slash separator. - f := filepath.ToSlash(filename) - bs[0] = []byte(fmt.Sprintf("--- %s%s", f+".orig", t0)) - bs[1] = []byte(fmt.Sprintf("+++ %s%s", f, t1)) - return bytes.Join(bs, []byte{'\n'}), nil -} - const chmodSupported = runtime.GOOS != "windows" // backupFile writes data to a new file named filename with permissions perm, diff --git a/src/cmd/gofmt/gofmt_test.go b/src/cmd/gofmt/gofmt_test.go index 676c5b43ede..641e0ea415f 100644 --- a/src/cmd/gofmt/gofmt_test.go +++ b/src/cmd/gofmt/gofmt_test.go @@ -7,10 +7,9 @@ package main import ( "bytes" "flag" + "internal/diff" "os" - "os/exec" "path/filepath" - "runtime" "strings" "testing" "text/scanner" @@ -119,11 +118,8 @@ func runTest(t *testing.T, in, out string) { t.Errorf("WARNING: -update did not rewrite input file %s", in) } - t.Errorf("(gofmt %s) != %s (see %s.gofmt)", in, out, in) - d, err := diffWithReplaceTempFile(expected, got, in) - if err == nil { - t.Errorf("%s", d) - } + t.Errorf("(gofmt %s) != %s (see %s.gofmt)\n%s", in, out, in, + diff.Diff("expected", expected, "got", got)) if err := os.WriteFile(in+".gofmt", got, 0666); err != nil { t.Error(err) } @@ -194,69 +190,3 @@ func TestBackupFile(t *testing.T) { } t.Logf("Created: %s", name) } - -func TestDiff(t *testing.T) { - if _, err := exec.LookPath("diff"); err != nil { - t.Skipf("skip test on %s: diff command is required", runtime.GOOS) - } - in := []byte("first\nsecond\n") - out := []byte("first\nthird\n") - filename := "difftest.txt" - b, err := diffWithReplaceTempFile(in, out, filename) - if err != nil { - t.Fatal(err) - } - - if runtime.GOOS == "windows" { - b = bytes.ReplaceAll(b, []byte{'\r', '\n'}, []byte{'\n'}) - } - - bs := bytes.SplitN(b, []byte{'\n'}, 3) - line0, line1 := bs[0], bs[1] - - if prefix := "--- difftest.txt.orig"; !bytes.HasPrefix(line0, []byte(prefix)) { - t.Errorf("diff: first line should start with `%s`\ngot: %s", prefix, line0) - } - - if prefix := "+++ difftest.txt"; !bytes.HasPrefix(line1, []byte(prefix)) { - t.Errorf("diff: second line should start with `%s`\ngot: %s", prefix, line1) - } - - want := `@@ -1,2 +1,2 @@ - first --second -+third -` - - if got := string(bs[2]); got != want { - t.Errorf("diff: got:\n%s\nwant:\n%s", got, want) - } -} - -func TestReplaceTempFilename(t *testing.T) { - diff := []byte(`--- /tmp/tmpfile1 2017-02-08 00:53:26.175105619 +0900 -+++ /tmp/tmpfile2 2017-02-08 00:53:38.415151275 +0900 -@@ -1,2 +1,2 @@ - first --second -+third -`) - want := []byte(`--- path/to/file.go.orig 2017-02-08 00:53:26.175105619 +0900 -+++ path/to/file.go 2017-02-08 00:53:38.415151275 +0900 -@@ -1,2 +1,2 @@ - first --second -+third -`) - // Check path in diff output is always slash regardless of the - // os.PathSeparator (`/` or `\`). - sep := string(os.PathSeparator) - filename := strings.Join([]string{"path", "to", "file.go"}, sep) - got, err := replaceTempFilename(diff, filename) - if err != nil { - t.Fatal(err) - } - if !bytes.Equal(got, want) { - t.Errorf("os.PathSeparator='%s': replacedDiff:\ngot:\n%s\nwant:\n%s", sep, got, want) - } -} diff --git a/src/cmd/internal/diff/diff.go b/src/cmd/internal/diff/diff.go deleted file mode 100644 index 0ec2d7f8f95..00000000000 --- a/src/cmd/internal/diff/diff.go +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright 2019 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 diff implements a Diff function that compare two inputs -// using the 'diff' tool. -package diff - -import ( - "bytes" - exec "internal/execabs" - "io/ioutil" - "os" - "runtime" -) - -// Returns diff of two arrays of bytes in diff tool format. -func Diff(prefix string, b1, b2 []byte) ([]byte, error) { - f1, err := writeTempFile(prefix, b1) - if err != nil { - return nil, err - } - defer os.Remove(f1) - - f2, err := writeTempFile(prefix, b2) - if err != nil { - return nil, err - } - defer os.Remove(f2) - - cmd := "diff" - if runtime.GOOS == "plan9" { - cmd = "/bin/ape/diff" - } - - data, err := exec.Command(cmd, "-u", f1, f2).CombinedOutput() - if len(data) > 0 { - // diff exits with a non-zero status when the files don't match. - // Ignore that failure as long as we get output. - err = nil - } - - // If we are on Windows and the diff is Cygwin diff, - // machines can get into a state where every Cygwin - // command works fine but prints a useless message like: - // - // Cygwin WARNING: - // Couldn't compute FAST_CWD pointer. This typically occurs if you're using - // an older Cygwin version on a newer Windows. Please update to the latest - // available Cygwin version from https://cygwin.com/. If the problem persists, - // please see https://cygwin.com/problems.html - // - // Skip over that message and just return the actual diff. - if len(data) > 0 && !bytes.HasPrefix(data, []byte("--- ")) { - i := bytes.Index(data, []byte("\n--- ")) - if i >= 0 && i < 80*10 && bytes.Contains(data[:i], []byte("://cygwin.com/")) { - data = data[i+1:] - } - } - - return data, err -} - -func writeTempFile(prefix string, data []byte) (string, error) { - file, err := ioutil.TempFile("", prefix) - if err != nil { - return "", err - } - _, err = file.Write(data) - if err1 := file.Close(); err == nil { - err = err1 - } - if err != nil { - os.Remove(file.Name()) - return "", err - } - return file.Name(), nil -} diff --git a/src/go/build/deps_test.go b/src/go/build/deps_test.go index ed40f43c9da..7b9826e0f2c 100644 --- a/src/go/build/deps_test.go +++ b/src/go/build/deps_test.go @@ -555,7 +555,7 @@ var depsRules = ` < internal/trace; FMT - < internal/txtar; + < internal/diff, internal/txtar; ` // listStdPkgs returns the same list of packages as "go list std". diff --git a/src/go/printer/printer_test.go b/src/go/printer/printer_test.go index ff8be4ae97a..2071aa8aa6e 100644 --- a/src/go/printer/printer_test.go +++ b/src/go/printer/printer_test.go @@ -6,12 +6,12 @@ package printer import ( "bytes" - "errors" "flag" "fmt" "go/ast" "go/parser" "go/token" + "internal/diff" "io" "os" "path/filepath" @@ -87,37 +87,13 @@ func lineAt(text []byte, offs int) []byte { return text[offs:i] } -// diff compares a and b. -func diff(aname, bname string, a, b []byte) error { +// checkEqual compares a and b. +func checkEqual(aname, bname string, a, b []byte) error { if bytes.Equal(a, b) { return nil } - var buf bytes.Buffer // holding long error message - // compare lengths - if len(a) != len(b) { - fmt.Fprintf(&buf, "\nlength changed: len(%s) = %d, len(%s) = %d", aname, len(a), bname, len(b)) - } - - // compare contents - line := 1 - offs := 0 - for i := 0; i < len(a) && i < len(b); i++ { - ch := a[i] - if ch != b[i] { - fmt.Fprintf(&buf, "\n%s:%d:%d: %s", aname, line, i-offs+1, lineAt(a, offs)) - fmt.Fprintf(&buf, "\n%s:%d:%d: %s", bname, line, i-offs+1, lineAt(b, offs)) - fmt.Fprintf(&buf, "\n\n") - break - } - if ch == '\n' { - line++ - offs = i + 1 - } - } - - fmt.Fprintf(&buf, "\n%s:\n%s\n%s:\n%s", aname, a, bname, b) - return errors.New(buf.String()) + return fmt.Errorf("diff %s %s\n%s", aname, bname, diff.Diff(aname, a, bname, b)) } func runcheck(t *testing.T, source, golden string, mode checkMode) { @@ -149,7 +125,7 @@ func runcheck(t *testing.T, source, golden string, mode checkMode) { } // formatted source and golden must be the same - if err := diff(source, golden, res, gld); err != nil { + if err := checkEqual(source, golden, res, gld); err != nil { t.Error(err) return } @@ -163,7 +139,7 @@ func runcheck(t *testing.T, source, golden string, mode checkMode) { t.Error(err) return } - if err := diff(golden, fmt.Sprintf("format(%s)", golden), gld, res); err != nil { + if err := checkEqual(golden, fmt.Sprintf("format(%s)", golden), gld, res); err != nil { t.Errorf("golden is not idempotent: %s", err) } } diff --git a/src/internal/diff/diff.go b/src/internal/diff/diff.go new file mode 100644 index 00000000000..e2c9e4dc65f --- /dev/null +++ b/src/internal/diff/diff.go @@ -0,0 +1,262 @@ +// Copyright 2022 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 diff + +import ( + "bytes" + "fmt" + "sort" + "strings" +) + +// A pair is a pair of values tracked for both the x and y side of a diff. +// It is typically a pair of line indexes. +type pair struct{ x, y int } + +// Diff returns an anchored diff of the two texts old and new +// in the “unified diff” format. If old and new are identical, +// Diff returns a nil slice (no output). +// +// Unix diff implementations typically look for a diff with +// the smallest number of lines inserted and removed, +// which can in the worst case take time quadratic in the +// number of lines in the texts. As a result, many implementations +// either can be made to run for a long time or cut off the search +// after a predetermined amount of work. +// +// In contrast, this implementation looks for a diff with the +// smallest number of “unique” lines inserted and removed, +// where unique means a line that appears just once in both old and new. +// We call this an “anchored diff” because the unique lines anchor +// the chosen matching regions. An anchored diff is usually clearer +// than a standard diff, because the algorithm does not try to +// reuse unrelated blank lines or closing braces. +// The algorithm also guarantees to run in O(n log n) time +// instead of the standard O(n²) time. +// +// Some systems call this approach a “patience diff,” named for +// the “patience sorting” algorithm, itself named for a solitaire card game. +// We avoid that name for two reasons. First, the name has been used +// for a few different variants of the algorithm, so it is imprecise. +// Second, the name is frequently interpreted as meaning that you have +// to wait longer (to be patient) for the diff, meaning that it is a slower algorithm, +// when in fact the algorithm is faster than the standard one. +// +func Diff(oldName string, old []byte, newName string, new []byte) []byte { + if bytes.Equal(old, new) { + return nil + } + x := lines(old) + y := lines(new) + + // Print diff header. + var out bytes.Buffer + fmt.Fprintf(&out, "diff %s %s\n", oldName, newName) + fmt.Fprintf(&out, "--- %s\n", oldName) + fmt.Fprintf(&out, "+++ %s\n", newName) + + // Loop over matches to consider, + // expanding each match to include surrounding lines, + // and then printing diff chunks. + // To avoid setup/teardown cases outside the loop, + // tgs returns a leading {0,0} and trailing {len(x), len(y)} pair + // in the sequence of matches. + var ( + done pair // printed up to x[:done.x] and y[:done.y] + chunk pair // start lines of current chunk + count pair // number of lines from each side in current chunk + ctext []string // lines for current chunk + ) + for _, m := range tgs(x, y) { + if m.x < done.x { + // Already handled scanning forward from earlier match. + continue + } + + // Expand matching lines as far possible, + // establishing that x[start.x:end.x] == y[start.y:end.y]. + // Note that on the first (or last) iteration we may (or definitey do) + // have an empty match: start.x==end.x and start.y==end.y. + start := m + for start.x > done.x && start.y > done.y && x[start.x-1] == y[start.y-1] { + start.x-- + start.y-- + } + end := m + for end.x < len(x) && end.y < len(y) && x[end.x] == y[end.y] { + end.x++ + end.y++ + } + + // Emit the mismatched lines before start into this chunk. + // (No effect on first sentinel iteration, when start = {0,0}.) + for _, s := range x[done.x:start.x] { + ctext = append(ctext, "-"+s) + count.x++ + } + for _, s := range y[done.y:start.y] { + ctext = append(ctext, "+"+s) + count.y++ + } + + // If we're not at EOF and have too few common lines, + // the chunk includes all the common lines and continues. + const C = 3 // number of context lines + if (end.x < len(x) || end.y < len(y)) && + (end.x-start.x < C || (len(ctext) > 0 && end.x-start.x < 2*C)) { + for _, s := range x[start.x:end.x] { + ctext = append(ctext, " "+s) + count.x++ + count.y++ + } + done = end + continue + } + + // End chunk with common lines for context. + if len(ctext) > 0 { + n := end.x - start.x + if n > C { + n = C + } + for _, s := range x[start.x : start.x+n] { + ctext = append(ctext, " "+s) + count.x++ + count.y++ + } + done = pair{start.x + n, start.y + n} + + // Format and emit chunk. + // Convert line numbers to 1-indexed. + // Special case: empty file shows up as 0,0 not 1,0. + if count.x > 0 { + chunk.x++ + } + if count.y > 0 { + chunk.y++ + } + fmt.Fprintf(&out, "@@ -%d,%d +%d,%d @@\n", chunk.x, count.x, chunk.y, count.y) + for _, s := range ctext { + out.WriteString(s) + } + count.x = 0 + count.y = 0 + ctext = ctext[:0] + } + + // If we reached EOF, we're done. + if end.x >= len(x) && end.y >= len(y) { + break + } + + // Otherwise start a new chunk. + chunk = pair{end.x - C, end.y - C} + for _, s := range x[chunk.x:end.x] { + ctext = append(ctext, " "+s) + count.x++ + count.y++ + } + done = end + } + + return out.Bytes() +} + +// lines returns the lines in the file x, including newlines. +// If the file does not end in a newline, one is supplied +// along with a warning about the missing newline. +func lines(x []byte) []string { + l := strings.SplitAfter(string(x), "\n") + if l[len(l)-1] == "" { + l = l[:len(l)-1] + } else { + // Treat last line as having a message about the missing newline attached, + // using the same text as BSD/GNU diff (including the leading backslash). + l[len(l)-1] += "\n\\ No newline at end of file\n" + } + return l +} + +// tgs returns the pairs of indexes of the longest common subsequence +// of unique lines in x and y, where a unique line is one that appears +// once in x and once in y. +// +// The longest common subsequence algorithm is as described in +// Thomas G. Szymanski, “A Special Case of the Maximal Common +// Subsequence Problem,” Princeton TR #170 (January 1975), +// available at https://research.swtch.com/tgs170.pdf. +func tgs(x, y []string) []pair { + // Count the number of times each string appears in a and b. + // We only care about 0, 1, many, counted as 0, -1, -2 + // for the x side and 0, -4, -8 for the y side. + // Using negative numbers now lets us distinguish positive line numbers later. + m := make(map[string]int) + for _, s := range x { + if c := m[s]; c > -2 { + m[s] = c - 1 + } + } + for _, s := range y { + if c := m[s]; c > -8 { + m[s] = c - 4 + } + } + + // Now unique strings can be identified by m[s] = -1+-4. + // + // Gather the indexes of those strings in x and y, building: + // xi[i] = increasing indexes of unique strings in x. + // yi[i] = increasing indexes of unique strings in y. + // inv[i] = index j such that x[xi[i]] = y[yi[j]]. + var xi, yi, inv []int + for i, s := range y { + if m[s] == -1+-4 { + m[s] = len(yi) + yi = append(yi, i) + } + } + for i, s := range x { + if j, ok := m[s]; ok && j >= 0 { + xi = append(xi, i) + inv = append(inv, j) + } + } + + // Apply Algorithm A from Szymanski's paper. + // In those terms, A = J = inv and B = [0, n). + // We add sentinel pairs {0,0}, and {len(x),len(y)} + // to the returned sequence, to help the processing loop. + J := inv + n := len(xi) + T := make([]int, n) + L := make([]int, n) + for i := range T { + T[i] = n + 1 + } + for i := 0; i < n; i++ { + k := sort.Search(n, func(k int) bool { + return T[k] >= J[i] + }) + T[k] = J[i] + L[i] = k + 1 + } + k := 0 + for _, v := range L { + if k < v { + k = v + } + } + seq := make([]pair, 2+k) + seq[1+k] = pair{len(x), len(y)} // sentinel at end + lastj := n + for i := n - 1; i >= 0; i-- { + if L[i] == k && J[i] < lastj { + seq[k] = pair{xi[i], yi[J[i]]} + k-- + } + } + seq[0] = pair{0, 0} // sentinel at start + return seq +} diff --git a/src/internal/diff/diff_test.go b/src/internal/diff/diff_test.go new file mode 100644 index 00000000000..37281c529b9 --- /dev/null +++ b/src/internal/diff/diff_test.go @@ -0,0 +1,43 @@ +// Copyright 2022 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 diff + +import ( + "bytes" + "internal/txtar" + "path/filepath" + "testing" +) + +func clean(text []byte) []byte { + text = bytes.ReplaceAll(text, []byte("$\n"), []byte("\n")) + text = bytes.TrimSuffix(text, []byte("^D\n")) + return text +} + +func Test(t *testing.T) { + files, _ := filepath.Glob("testdata/*.txt") + if len(files) == 0 { + t.Fatalf("no testdata") + } + + for _, file := range files { + t.Run(filepath.Base(file), func(t *testing.T) { + a, err := txtar.ParseFile(file) + if err != nil { + t.Fatal(err) + } + if len(a.Files) != 3 || a.Files[2].Name != "diff" { + t.Fatalf("%s: want three files, third named \"diff\"", file) + } + diffs := Diff(a.Files[0].Name, clean(a.Files[0].Data), a.Files[1].Name, clean(a.Files[1].Data)) + want := clean(a.Files[2].Data) + if !bytes.Equal(diffs, want) { + t.Fatalf("%s: have:\n%s\nwant:\n%s\n%s", file, + diffs, want, Diff("have", diffs, "want", want)) + } + }) + } +} diff --git a/src/internal/diff/testdata/allnew.txt b/src/internal/diff/testdata/allnew.txt new file mode 100644 index 00000000000..887564927ab --- /dev/null +++ b/src/internal/diff/testdata/allnew.txt @@ -0,0 +1,13 @@ +-- old -- +-- new -- +a +b +c +-- diff -- +diff old new +--- old ++++ new +@@ -0,0 +1,3 @@ ++a ++b ++c diff --git a/src/internal/diff/testdata/allold.txt b/src/internal/diff/testdata/allold.txt new file mode 100644 index 00000000000..bcc9ac0ee05 --- /dev/null +++ b/src/internal/diff/testdata/allold.txt @@ -0,0 +1,13 @@ +-- old -- +a +b +c +-- new -- +-- diff -- +diff old new +--- old ++++ new +@@ -1,3 +0,0 @@ +-a +-b +-c diff --git a/src/internal/diff/testdata/basic.txt b/src/internal/diff/testdata/basic.txt new file mode 100644 index 00000000000..d2565b5d6ed --- /dev/null +++ b/src/internal/diff/testdata/basic.txt @@ -0,0 +1,35 @@ +Example from Hunt and McIlroy, “An Algorithm for Differential File Comparison.” +https://www.cs.dartmouth.edu/~doug/diff.pdf + +-- old -- +a +b +c +d +e +f +g +-- new -- +w +a +b +x +y +z +e +-- diff -- +diff old new +--- old ++++ new +@@ -1,7 +1,7 @@ ++w + a + b +-c +-d ++x ++y ++z + e +-f +-g diff --git a/src/internal/diff/testdata/dups.txt b/src/internal/diff/testdata/dups.txt new file mode 100644 index 00000000000..d10524d0d81 --- /dev/null +++ b/src/internal/diff/testdata/dups.txt @@ -0,0 +1,40 @@ +-- old -- +a + +b + +c + +d + +e + +f +-- new -- +a + +B + +C + +d + +e + +f +-- diff -- +diff old new +--- old ++++ new +@@ -1,8 +1,8 @@ + a + $ +-b +- +-c ++B ++ ++C + $ + d + $ diff --git a/src/internal/diff/testdata/end.txt b/src/internal/diff/testdata/end.txt new file mode 100644 index 00000000000..158637c135b --- /dev/null +++ b/src/internal/diff/testdata/end.txt @@ -0,0 +1,38 @@ +-- old -- +1 +2 +3 +4 +5 +6 +7 +eight +nine +ten +eleven +-- new -- +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +-- diff -- +diff old new +--- old ++++ new +@@ -5,7 +5,6 @@ + 5 + 6 + 7 +-eight +-nine +-ten +-eleven ++8 ++9 ++10 diff --git a/src/internal/diff/testdata/eof.txt b/src/internal/diff/testdata/eof.txt new file mode 100644 index 00000000000..5dc145c4de4 --- /dev/null +++ b/src/internal/diff/testdata/eof.txt @@ -0,0 +1,9 @@ +-- old -- +a +b +c^D +-- new -- +a +b +c^D +-- diff -- diff --git a/src/internal/diff/testdata/eof1.txt b/src/internal/diff/testdata/eof1.txt new file mode 100644 index 00000000000..1ebf621e921 --- /dev/null +++ b/src/internal/diff/testdata/eof1.txt @@ -0,0 +1,18 @@ +-- old -- +a +b +c +-- new -- +a +b +c^D +-- diff -- +diff old new +--- old ++++ new +@@ -1,3 +1,3 @@ + a + b +-c ++c +\ No newline at end of file diff --git a/src/internal/diff/testdata/eof2.txt b/src/internal/diff/testdata/eof2.txt new file mode 100644 index 00000000000..047705e6865 --- /dev/null +++ b/src/internal/diff/testdata/eof2.txt @@ -0,0 +1,18 @@ +-- old -- +a +b +c^D +-- new -- +a +b +c +-- diff -- +diff old new +--- old ++++ new +@@ -1,3 +1,3 @@ + a + b +-c +\ No newline at end of file ++c diff --git a/src/internal/diff/testdata/long.txt b/src/internal/diff/testdata/long.txt new file mode 100644 index 00000000000..3fc99f71d51 --- /dev/null +++ b/src/internal/diff/testdata/long.txt @@ -0,0 +1,62 @@ +-- old -- +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +14½ +15 +16 +17 +18 +19 +20 +-- new -- +1 +2 +3 +4 +5 +6 +8 +9 +10 +11 +12 +13 +14 +17 +18 +19 +20 +-- diff -- +diff old new +--- old ++++ new +@@ -4,7 +4,6 @@ + 4 + 5 + 6 +-7 + 8 + 9 + 10 +@@ -12,9 +11,6 @@ + 12 + 13 + 14 +-14½ +-15 +-16 + 17 + 18 + 19 diff --git a/src/internal/diff/testdata/same.txt b/src/internal/diff/testdata/same.txt new file mode 100644 index 00000000000..86b1100d810 --- /dev/null +++ b/src/internal/diff/testdata/same.txt @@ -0,0 +1,5 @@ +-- old -- +hello world +-- new -- +hello world +-- diff -- diff --git a/src/internal/diff/testdata/start.txt b/src/internal/diff/testdata/start.txt new file mode 100644 index 00000000000..217b2fdc9f8 --- /dev/null +++ b/src/internal/diff/testdata/start.txt @@ -0,0 +1,34 @@ +-- old -- +e +pi +4 +5 +6 +7 +8 +9 +10 +-- new -- +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +-- diff -- +diff old new +--- old ++++ new +@@ -1,5 +1,6 @@ +-e +-pi ++1 ++2 ++3 + 4 + 5 + 6 diff --git a/src/internal/diff/testdata/triv.txt b/src/internal/diff/testdata/triv.txt new file mode 100644 index 00000000000..ab5759fcb2c --- /dev/null +++ b/src/internal/diff/testdata/triv.txt @@ -0,0 +1,40 @@ +Another example from Hunt and McIlroy, +“An Algorithm for Differential File Comparison.” +https://www.cs.dartmouth.edu/~doug/diff.pdf + +Anchored diff gives up on finding anything, +since there are no unique lines. + +-- old -- +a +b +c +a +b +b +a +-- new -- +c +a +b +a +b +c +-- diff -- +diff old new +--- old ++++ new +@@ -1,7 +1,6 @@ +-a +-b +-c +-a +-b +-b +-a ++c ++a ++b ++a ++b ++c From 0a49f706e172443d817cfb3d44e5b366da1cc72a Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Fri, 4 Feb 2022 11:55:33 -0500 Subject: [PATCH 153/276] cmd/go: run 'go help documentation' through gofmt in TestDocsUpToDate mkalldocs.sh runs gofmt on the output, but the test does not. If go help documentation and gofmt disagree, the test will fail. Fix that. Change-Id: I837374a2d36cb5d71278ecefe2a7b6544622c576 Reviewed-on: https://go-review.googlesource.com/c/go/+/384256 Trust: Russ Cox Run-TryBot: Russ Cox Reviewed-by: Bryan Mills TryBot-Result: Gopher Robot --- src/cmd/go/help_test.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/cmd/go/help_test.go b/src/cmd/go/help_test.go index abfc3db9936..3e1d817ca5b 100644 --- a/src/cmd/go/help_test.go +++ b/src/cmd/go/help_test.go @@ -6,6 +6,8 @@ package main_test import ( "bytes" + "go/format" + diffpkg "internal/diff" "os" "testing" @@ -23,11 +25,17 @@ func TestDocsUpToDate(t *testing.T) { buf := new(bytes.Buffer) // Match the command in mkalldocs.sh that generates alldocs.go. help.Help(buf, []string{"documentation"}) - data, err := os.ReadFile("alldocs.go") + internal := buf.Bytes() + internal, err := format.Source(internal) + if err != nil { + t.Fatalf("gofmt docs: %v", err) + } + alldocs, err := os.ReadFile("alldocs.go") if err != nil { t.Fatalf("error reading alldocs.go: %v", err) } - if !bytes.Equal(data, buf.Bytes()) { - t.Errorf("alldocs.go is not up to date; run mkalldocs.sh to regenerate it") + if !bytes.Equal(internal, alldocs) { + t.Errorf("alldocs.go is not up to date; run mkalldocs.sh to regenerate it\n%s", + diffpkg.Diff("go help documentation | gofmt", internal, "alldocs.go", alldocs)) } } From 9f252a0462bd8c279beec56d1538e8a6c26c44c5 Mon Sep 17 00:00:00 2001 From: Cherry Mui Date: Fri, 18 Mar 2022 13:04:08 -0400 Subject: [PATCH 154/276] all: delete ARM64 non-register ABI fallback path Change-Id: I3996fb31789a1f8559348e059cf371774e548a8d Reviewed-on: https://go-review.googlesource.com/c/go/+/393875 Trust: Cherry Mui Run-TryBot: Cherry Mui TryBot-Result: Gopher Robot Reviewed-by: Michael Knyszek --- src/internal/bytealg/compare_arm64.s | 27 ----- src/internal/bytealg/equal_arm64.s | 33 ------ src/reflect/asm_arm64.s | 10 -- src/runtime/asm_arm64.s | 155 +-------------------------- src/runtime/memclr_arm64.s | 5 - src/runtime/memmove_arm64.s | 5 - src/runtime/race_arm64.s | 22 ---- 7 files changed, 1 insertion(+), 256 deletions(-) diff --git a/src/internal/bytealg/compare_arm64.s b/src/internal/bytealg/compare_arm64.s index 5a802072583..cc02c464e8b 100644 --- a/src/internal/bytealg/compare_arm64.s +++ b/src/internal/bytealg/compare_arm64.s @@ -6,7 +6,6 @@ #include "textflag.h" TEXT ·Compare(SB),NOSPLIT|NOFRAME,$0-56 -#ifdef GOEXPERIMENT_regabiargs // R0 = a_base (want in R0) // R1 = a_len (want in R1) // R2 = a_cap (unused) @@ -15,28 +14,13 @@ TEXT ·Compare(SB),NOSPLIT|NOFRAME,$0-56 // R5 = b_cap (unused) MOVD R3, R2 MOVD R4, R3 -#else - MOVD a_base+0(FP), R0 - MOVD a_len+8(FP), R1 - MOVD b_base+24(FP), R2 - MOVD b_len+32(FP), R3 - MOVD $ret+48(FP), R7 -#endif B cmpbody<>(SB) TEXT runtime·cmpstring(SB),NOSPLIT|NOFRAME,$0-40 -#ifdef GOEXPERIMENT_regabiargs // R0 = a_base // R1 = a_len // R2 = b_base // R3 = b_len -#else - MOVD a_base+0(FP), R0 - MOVD a_len+8(FP), R1 - MOVD b_base+16(FP), R2 - MOVD b_len+24(FP), R3 - MOVD $ret+32(FP), R7 -#endif B cmpbody<>(SB) // On entry: @@ -44,14 +28,9 @@ TEXT runtime·cmpstring(SB),NOSPLIT|NOFRAME,$0-40 // R1 is the length of a // R2 points to the start of b // R3 is the length of b -#ifndef GOEXPERIMENT_regabiargs -// R7 points to return value (-1/0/1 will be written here) -#endif // // On exit: -#ifdef GOEXPERIMENT_regabiargs // R0 is the result -#endif // R4, R5, R6, R8, R9 and R10 are clobbered TEXT cmpbody<>(SB),NOSPLIT|NOFRAME,$0-0 CMP R0, R2 @@ -96,9 +75,6 @@ cmp: ret: MOVD $1, R0 CNEG HI, R0, R0 -#ifndef GOEXPERIMENT_regabiargs - MOVD R0, (R7) -#endif RET small: TBZ $3, R6, lt_8 @@ -141,9 +117,6 @@ samebytes: CMP R3, R1 CSET NE, R0 CNEG LO, R0, R0 -#ifndef GOEXPERIMENT_regabiargs - MOVD R0, (R7) -#endif RET cmpnext: REV R8, R4 diff --git a/src/internal/bytealg/equal_arm64.s b/src/internal/bytealg/equal_arm64.s index cf5cf54e597..d3aabba5871 100644 --- a/src/internal/bytealg/equal_arm64.s +++ b/src/internal/bytealg/equal_arm64.s @@ -7,55 +7,29 @@ // memequal(a, b unsafe.Pointer, size uintptr) bool TEXT runtime·memequal(SB),NOSPLIT|NOFRAME,$0-25 -#ifndef GOEXPERIMENT_regabiargs - MOVD size+16(FP), R2 -#endif // short path to handle 0-byte case CBZ R2, equal -#ifndef GOEXPERIMENT_regabiargs - MOVD a+0(FP), R0 - MOVD b+8(FP), R1 - MOVD $ret+24(FP), R8 -#endif B memeqbody<>(SB) equal: MOVD $1, R0 -#ifndef GOEXPERIMENT_regabiargs - MOVB R0, ret+24(FP) -#endif RET // memequal_varlen(a, b unsafe.Pointer) bool TEXT runtime·memequal_varlen(SB),NOSPLIT,$0-17 -#ifndef GOEXPERIMENT_regabiargs - MOVD a+0(FP), R0 - MOVD b+8(FP), R1 -#endif CMP R0, R1 BEQ eq MOVD 8(R26), R2 // compiler stores size at offset 8 in the closure CBZ R2, eq -#ifndef GOEXPERIMENT_regabiargs - MOVD $ret+16(FP), R8 -#endif B memeqbody<>(SB) eq: MOVD $1, R0 -#ifndef GOEXPERIMENT_regabiargs - MOVB R0, ret+16(FP) -#endif RET // input: // R0: pointer a // R1: pointer b // R2: data len -#ifdef GOEXPERIMENT_regabiargs // at return: result in R0 -#else -// R8: address to put result -#endif - TEXT memeqbody<>(SB),NOSPLIT,$0 CMP $1, R2 // handle 1-byte special case for better performance @@ -141,14 +115,7 @@ one: BNE not_equal equal: MOVD $1, R0 -#ifndef GOEXPERIMENT_regabiargs - MOVB R0, (R8) -#endif RET not_equal: -#ifdef GOEXPERIMENT_regabiargs MOVB ZR, R0 -#else - MOVB ZR, (R8) -#endif RET diff --git a/src/reflect/asm_arm64.s b/src/reflect/asm_arm64.s index 812b8a02c37..5e91e62aa14 100644 --- a/src/reflect/asm_arm64.s +++ b/src/reflect/asm_arm64.s @@ -33,13 +33,8 @@ TEXT ·makeFuncStub(SB),(NOSPLIT|WRAPPER),$432 ADD $LOCAL_REGARGS, RSP, R20 CALL runtime·spillArgs(SB) MOVD R26, 32(RSP) // outside of moveMakeFuncArgPtrs's arg area -#ifdef GOEXPERIMENT_regabiargs MOVD R26, R0 MOVD R20, R1 -#else - MOVD R26, 8(RSP) - MOVD R20, 16(RSP) -#endif CALL ·moveMakeFuncArgPtrs(SB) MOVD 32(RSP), R26 MOVD R26, 8(RSP) @@ -66,13 +61,8 @@ TEXT ·methodValueCall(SB),(NOSPLIT|WRAPPER),$432 ADD $LOCAL_REGARGS, RSP, R20 CALL runtime·spillArgs(SB) MOVD R26, 32(RSP) // outside of moveMakeFuncArgPtrs's arg area -#ifdef GOEXPERIMENT_regabiargs MOVD R26, R0 MOVD R20, R1 -#else - MOVD R26, 8(RSP) - MOVD R20, 16(RSP) -#endif CALL ·moveMakeFuncArgPtrs(SB) MOVD 32(RSP), R26 MOVD R26, 8(RSP) diff --git a/src/runtime/asm_arm64.s b/src/runtime/asm_arm64.s index 46ffaaa9b3f..62deb070aa2 100644 --- a/src/runtime/asm_arm64.s +++ b/src/runtime/asm_arm64.s @@ -150,11 +150,7 @@ TEXT gogo<>(SB), NOSPLIT|NOFRAME, $0 // Fn must never return. It should gogo(&g->sched) // to keep running g. TEXT runtime·mcall(SB), NOSPLIT|NOFRAME, $0-8 -#ifdef GOEXPERIMENT_regabiargs MOVD R0, R26 // context -#else - MOVD fn+0(FP), R26 // context -#endif // Save caller state in g->sched MOVD RSP, R0 @@ -175,11 +171,7 @@ TEXT runtime·mcall(SB), NOSPLIT|NOFRAME, $0-8 MOVD (g_sched+gobuf_sp)(g), R0 MOVD R0, RSP // sp = m->g0->sched.sp MOVD (g_sched+gobuf_bp)(g), R29 -#ifdef GOEXPERIMENT_regabiargs MOVD R3, R0 // arg = g -#else - MOVD R3, -8(RSP) // arg = g -#endif MOVD $0, -16(RSP) // dummy LR SUB $16, RSP MOVD 0(R26), R4 // code pointer @@ -317,7 +309,6 @@ TEXT runtime·morestack_noctxt(SB),NOSPLIT|NOFRAME,$0-0 MOVW $0, R26 B runtime·morestack(SB) -#ifdef GOEXPERIMENT_regabiargs // spillArgs stores return values from registers to a *internal/abi.RegArgs in R20. TEXT ·spillArgs(SB),NOSPLIT,$0-0 MOVD R0, (0*8)(R20) @@ -389,13 +380,6 @@ TEXT ·unspillArgs(SB),NOSPLIT,$0-0 FMOVD (30*8)(R20), F14 FMOVD (31*8)(R20), F15 RET -#else -TEXT ·spillArgs(SB),NOSPLIT,$0-0 - RET - -TEXT ·unspillArgs(SB),NOSPLIT,$0-0 - RET -#endif // reflectcall: call a function with the given argument list // func call(stackArgsType *_type, f *FuncVal, stackArgs *byte, stackArgsSize, stackRetOffset, frameSize uint32, regArgs *abi.RegArgs). @@ -536,11 +520,6 @@ CALLFN(·call1073741824, 1073741824) TEXT runtime·memhash32(SB),NOSPLIT|NOFRAME,$0-24 MOVB runtime·useAeshash(SB), R10 CBZ R10, noaes -#ifndef GOEXPERIMENT_regabiargs - MOVD p+0(FP), R0 - MOVD h+8(FP), R1 - MOVD $ret+16(FP), R2 -#endif MOVD $runtime·aeskeysched+0(SB), R3 VEOR V0.B16, V0.B16, V0.B16 @@ -554,11 +533,7 @@ TEXT runtime·memhash32(SB),NOSPLIT|NOFRAME,$0-24 AESMC V0.B16, V0.B16 AESE V2.B16, V0.B16 -#ifdef GOEXPERIMENT_regabiargs VMOV V0.D[0], R0 -#else - VST1 [V0.D1], (R2) -#endif RET noaes: B runtime·memhash32Fallback(SB) @@ -567,11 +542,6 @@ noaes: TEXT runtime·memhash64(SB),NOSPLIT|NOFRAME,$0-24 MOVB runtime·useAeshash(SB), R10 CBZ R10, noaes -#ifndef GOEXPERIMENT_regabiargs - MOVD p+0(FP), R0 - MOVD h+8(FP), R1 - MOVD $ret+16(FP), R2 -#endif MOVD $runtime·aeskeysched+0(SB), R3 VEOR V0.B16, V0.B16, V0.B16 @@ -585,11 +555,7 @@ TEXT runtime·memhash64(SB),NOSPLIT|NOFRAME,$0-24 AESMC V0.B16, V0.B16 AESE V2.B16, V0.B16 -#ifdef GOEXPERIMENT_regabiargs VMOV V0.D[0], R0 -#else - VST1 [V0.D1], (R2) -#endif RET noaes: B runtime·memhash64Fallback(SB) @@ -598,12 +564,6 @@ noaes: TEXT runtime·memhash(SB),NOSPLIT|NOFRAME,$0-32 MOVB runtime·useAeshash(SB), R10 CBZ R10, noaes -#ifndef GOEXPERIMENT_regabiargs - MOVD p+0(FP), R0 - MOVD h+8(FP), R1 - MOVD s+16(FP), R2 - MOVD $ret+24(FP), R8 -#endif B aeshashbody<>(SB) noaes: B runtime·memhashFallback(SB) @@ -612,14 +572,7 @@ noaes: TEXT runtime·strhash(SB),NOSPLIT|NOFRAME,$0-24 MOVB runtime·useAeshash(SB), R10 CBZ R10, noaes -#ifdef GOEXPERIMENT_regabiargs LDP (R0), (R0, R2) // string data / length -#else - MOVD p+0(FP), R10 // string pointer - LDP (R10), (R0, R2) // string data / length - MOVD h+8(FP), R1 - MOVD $ret+16(FP), R8 // return adddress -#endif B aeshashbody<>(SB) noaes: B runtime·strhashFallback(SB) @@ -627,11 +580,7 @@ noaes: // R0: data // R1: seed data // R2: length -#ifdef GOEXPERIMENT_regabiargs // At return, R0 = return value -#else -// R8: address to put return value -#endif TEXT aeshashbody<>(SB),NOSPLIT|NOFRAME,$0 VEOR V30.B16, V30.B16, V30.B16 VMOV R1, V30.D[0] @@ -676,19 +625,11 @@ done: AESMC V2.B16, V2.B16 AESE V0.B16, V2.B16 -#ifdef GOEXPERIMENT_regabiargs VMOV V2.D[0], R0 -#else - VST1 [V2.D1], (R8) -#endif RET aes0: -#ifdef GOEXPERIMENT_regabiargs VMOV V0.D[0], R0 -#else - VST1 [V0.D1], (R8) -#endif RET aes16: @@ -718,11 +659,8 @@ aes17to32: AESE V1.B16, V3.B16 VEOR V3.B16, V2.B16, V2.B16 -#ifdef GOEXPERIMENT_regabiargs + VMOV V2.D[0], R0 -#else - VST1 [V2.D1], (R8) -#endif RET aes33to64: @@ -765,11 +703,7 @@ aes33to64: VEOR V7.B16, V5.B16, V5.B16 VEOR V5.B16, V4.B16, V4.B16 -#ifdef GOEXPERIMENT_regabiargs VMOV V4.D[0], R0 -#else - VST1 [V4.D1], (R8) -#endif RET aes65to128: @@ -844,11 +778,7 @@ aes65to128: VEOR V11.B16, V9.B16, V9.B16 VEOR V9.B16, V8.B16, V8.B16 -#ifdef GOEXPERIMENT_regabiargs VMOV V8.D[0], R0 -#else - VST1 [V8.D1], (R8) -#endif RET aes129plus: @@ -967,11 +897,7 @@ aesloop: VEOR V4.B16, V6.B16, V4.B16 VEOR V4.B16, V0.B16, V0.B16 -#ifdef GOEXPERIMENT_regabiargs VMOV V0.D[0], R0 -#else - VST1 [V0.D1], (R8) -#endif RET TEXT runtime·procyield(SB),NOSPLIT,$0-0 @@ -1383,137 +1309,58 @@ flush: // Defined as ABIInternal since the compiler generates ABIInternal // calls to it directly and it does not use the stack-based Go ABI. TEXT runtime·panicIndex(SB),NOSPLIT,$0-16 -#ifndef GOEXPERIMENT_regabiargs - MOVD R0, x+0(FP) - MOVD R1, y+8(FP) -#endif JMP runtime·goPanicIndex(SB) TEXT runtime·panicIndexU(SB),NOSPLIT,$0-16 -#ifndef GOEXPERIMENT_regabiargs - MOVD R0, x+0(FP) - MOVD R1, y+8(FP) -#endif JMP runtime·goPanicIndexU(SB) TEXT runtime·panicSliceAlen(SB),NOSPLIT,$0-16 -#ifdef GOEXPERIMENT_regabiargs MOVD R1, R0 MOVD R2, R1 -#else - MOVD R1, x+0(FP) - MOVD R2, y+8(FP) -#endif JMP runtime·goPanicSliceAlen(SB) TEXT runtime·panicSliceAlenU(SB),NOSPLIT,$0-16 -#ifdef GOEXPERIMENT_regabiargs MOVD R1, R0 MOVD R2, R1 -#else - MOVD R1, x+0(FP) - MOVD R2, y+8(FP) -#endif JMP runtime·goPanicSliceAlenU(SB) TEXT runtime·panicSliceAcap(SB),NOSPLIT,$0-16 -#ifdef GOEXPERIMENT_regabiargs MOVD R1, R0 MOVD R2, R1 -#else - MOVD R1, x+0(FP) - MOVD R2, y+8(FP) -#endif JMP runtime·goPanicSliceAcap(SB) TEXT runtime·panicSliceAcapU(SB),NOSPLIT,$0-16 -#ifdef GOEXPERIMENT_regabiargs MOVD R1, R0 MOVD R2, R1 -#else - MOVD R1, x+0(FP) - MOVD R2, y+8(FP) -#endif JMP runtime·goPanicSliceAcapU(SB) TEXT runtime·panicSliceB(SB),NOSPLIT,$0-16 -#ifndef GOEXPERIMENT_regabiargs - MOVD R0, x+0(FP) - MOVD R1, y+8(FP) -#endif JMP runtime·goPanicSliceB(SB) TEXT runtime·panicSliceBU(SB),NOSPLIT,$0-16 -#ifndef GOEXPERIMENT_regabiargs - MOVD R0, x+0(FP) - MOVD R1, y+8(FP) -#endif JMP runtime·goPanicSliceBU(SB) TEXT runtime·panicSlice3Alen(SB),NOSPLIT,$0-16 -#ifdef GOEXPERIMENT_regabiargs MOVD R2, R0 MOVD R3, R1 -#else - MOVD R2, x+0(FP) - MOVD R3, y+8(FP) -#endif JMP runtime·goPanicSlice3Alen(SB) TEXT runtime·panicSlice3AlenU(SB),NOSPLIT,$0-16 -#ifdef GOEXPERIMENT_regabiargs MOVD R2, R0 MOVD R3, R1 -#else - MOVD R2, x+0(FP) - MOVD R3, y+8(FP) -#endif JMP runtime·goPanicSlice3AlenU(SB) TEXT runtime·panicSlice3Acap(SB),NOSPLIT,$0-16 -#ifdef GOEXPERIMENT_regabiargs MOVD R2, R0 MOVD R3, R1 -#else - MOVD R2, x+0(FP) - MOVD R3, y+8(FP) -#endif JMP runtime·goPanicSlice3Acap(SB) TEXT runtime·panicSlice3AcapU(SB),NOSPLIT,$0-16 -#ifdef GOEXPERIMENT_regabiargs MOVD R2, R0 MOVD R3, R1 -#else - MOVD R2, x+0(FP) - MOVD R3, y+8(FP) -#endif JMP runtime·goPanicSlice3AcapU(SB) TEXT runtime·panicSlice3B(SB),NOSPLIT,$0-16 -#ifdef GOEXPERIMENT_regabiargs MOVD R1, R0 MOVD R2, R1 -#else - MOVD R1, x+0(FP) - MOVD R2, y+8(FP) -#endif JMP runtime·goPanicSlice3B(SB) TEXT runtime·panicSlice3BU(SB),NOSPLIT,$0-16 -#ifdef GOEXPERIMENT_regabiargs MOVD R1, R0 MOVD R2, R1 -#else - MOVD R1, x+0(FP) - MOVD R2, y+8(FP) -#endif JMP runtime·goPanicSlice3BU(SB) TEXT runtime·panicSlice3C(SB),NOSPLIT,$0-16 -#ifndef GOEXPERIMENT_regabiargs - MOVD R0, x+0(FP) - MOVD R1, y+8(FP) -#endif JMP runtime·goPanicSlice3C(SB) TEXT runtime·panicSlice3CU(SB),NOSPLIT,$0-16 -#ifndef GOEXPERIMENT_regabiargs - MOVD R0, x+0(FP) - MOVD R1, y+8(FP) -#endif JMP runtime·goPanicSlice3CU(SB) TEXT runtime·panicSliceConvert(SB),NOSPLIT,$0-16 -#ifdef GOEXPERIMENT_regabiargs MOVD R2, R0 MOVD R3, R1 -#else - MOVD R2, x+0(FP) - MOVD R3, y+8(FP) -#endif JMP runtime·goPanicSliceConvert(SB) diff --git a/src/runtime/memclr_arm64.s b/src/runtime/memclr_arm64.s index b80cca6a1cd..1c35dfe0cf2 100644 --- a/src/runtime/memclr_arm64.s +++ b/src/runtime/memclr_arm64.s @@ -9,11 +9,6 @@ // func memclrNoHeapPointers(ptr unsafe.Pointer, n uintptr) // Also called from assembly in sys_windows_arm64.s without g (but using Go stack convention). TEXT runtime·memclrNoHeapPointers(SB),NOSPLIT,$0-16 -#ifndef GOEXPERIMENT_regabiargs - MOVD ptr+0(FP), R0 - MOVD n+8(FP), R1 -#endif - CMP $16, R1 // If n is equal to 16 bytes, use zero_exact_16 to zero BEQ zero_exact_16 diff --git a/src/runtime/memmove_arm64.s b/src/runtime/memmove_arm64.s index bee3b00c47d..8ec3ed86b9b 100644 --- a/src/runtime/memmove_arm64.s +++ b/src/runtime/memmove_arm64.s @@ -27,11 +27,6 @@ // func memmove(to, from unsafe.Pointer, n uintptr) TEXT runtime·memmove(SB), NOSPLIT|NOFRAME, $0-24 -#ifndef GOEXPERIMENT_regabiargs - MOVD to+0(FP), R0 - MOVD from+8(FP), R1 - MOVD n+16(FP), R2 -#endif CBZ R2, copy0 // Small copies: 1..16 bytes diff --git a/src/runtime/race_arm64.s b/src/runtime/race_arm64.s index 95fec0b9c63..8c0dd25f0ba 100644 --- a/src/runtime/race_arm64.s +++ b/src/runtime/race_arm64.s @@ -45,11 +45,7 @@ // Defined as ABIInternal so as to avoid introducing a wrapper, // which would make caller's PC ineffective. TEXT runtime·raceread(SB), NOSPLIT, $0-8 -#ifdef GOEXPERIMENT_regabiargs MOVD R0, R1 // addr -#else - MOVD addr+0(FP), R1 -#endif MOVD LR, R2 // void __tsan_read(ThreadState *thr, void *addr, void *pc); MOVD $__tsan_read(SB), R9 @@ -74,11 +70,7 @@ TEXT runtime·racereadpc(SB), NOSPLIT, $0-24 // Defined as ABIInternal so as to avoid introducing a wrapper, // which would make caller's PC ineffective. TEXT runtime·racewrite(SB), NOSPLIT, $0-8 -#ifdef GOEXPERIMENT_regabiargs MOVD R0, R1 // addr -#else - MOVD addr+0(FP), R1 -#endif MOVD LR, R2 // void __tsan_write(ThreadState *thr, void *addr, void *pc); MOVD $__tsan_write(SB), R9 @@ -103,13 +95,8 @@ TEXT runtime·racewritepc(SB), NOSPLIT, $0-24 // Defined as ABIInternal so as to avoid introducing a wrapper, // which would make caller's PC ineffective. TEXT runtime·racereadrange(SB), NOSPLIT, $0-16 -#ifdef GOEXPERIMENT_regabiargs MOVD R1, R2 // size MOVD R0, R1 // addr -#else - MOVD addr+0(FP), R1 - MOVD size+8(FP), R2 -#endif MOVD LR, R3 // void __tsan_read_range(ThreadState *thr, void *addr, uintptr size, void *pc); MOVD $__tsan_read_range(SB), R9 @@ -135,13 +122,8 @@ TEXT runtime·racereadrangepc1(SB), NOSPLIT, $0-24 // Defined as ABIInternal so as to avoid introducing a wrapper, // which would make caller's PC ineffective. TEXT runtime·racewriterange(SB), NOSPLIT, $0-16 -#ifdef GOEXPERIMENT_regabiargs MOVD R1, R2 // size MOVD R0, R1 // addr -#else - MOVD addr+0(FP), R1 - MOVD size+8(FP), R2 -#endif MOVD LR, R3 // void __tsan_write_range(ThreadState *thr, void *addr, uintptr size, void *pc); MOVD $__tsan_write_range(SB), R9 @@ -189,11 +171,7 @@ ret: // func runtime·racefuncenter(pc uintptr) // Called from instrumented code. TEXT runtime·racefuncenter(SB), NOSPLIT, $0-8 -#ifdef GOEXPERIMENT_regabiargs MOVD R0, R9 // callpc -#else - MOVD callpc+0(FP), R9 -#endif JMP racefuncenter<>(SB) // Common code for racefuncenter From 7e5804cb7014bf3154542a3d2afc68c3a61b7452 Mon Sep 17 00:00:00 2001 From: Heschi Kreinick Date: Wed, 16 Mar 2022 18:17:58 -0400 Subject: [PATCH 155/276] cmd: update vendored pprof go get github.com/google/pprof@latest go mod vendor Plus a tiny change to the pprof command to match an upstream interface change. Updates #36905. Change-Id: I4c7bbe8c317a6eeb217fce971b208f96ab0727fa Reviewed-on: https://go-review.googlesource.com/c/go/+/393370 Trust: Heschi Kreinick Run-TryBot: Heschi Kreinick Auto-Submit: Heschi Kreinick TryBot-Result: Gopher Robot Reviewed-by: Heschi Kreinick Reviewed-by: Dmitri Shuralyov Reviewed-by: Cherry Mui --- src/cmd/go.mod | 2 +- src/cmd/go.sum | 4 +- src/cmd/pprof/pprof.go | 2 +- .../github.com/google/pprof/driver/driver.go | 10 +- .../pprof/internal/binutils/binutils.go | 38 +- .../google/pprof/internal/driver/cli.go | 2 +- .../google/pprof/internal/driver/fetch.go | 6 +- .../google/pprof/internal/driver/webhtml.go | 21 +- .../google/pprof/internal/elfexec/elfexec.go | 6 +- .../google/pprof/internal/graph/dotgraph.go | 4 +- .../google/pprof/internal/plugin/plugin.go | 6 +- .../google/pprof/internal/report/report.go | 2 +- .../google/pprof/internal/report/source.go | 2 +- .../pprof/internal/symbolizer/symbolizer.go | 5 +- .../github.com/google/pprof/profile/encode.go | 9 + .../github.com/google/pprof/profile/merge.go | 21 +- .../google/pprof/profile/profile.go | 9 + .../google/pprof/third_party/d3/LICENSE | 27 - .../google/pprof/third_party/d3/README.md | 119 - .../google/pprof/third_party/d3/d3.go | 4675 ----------------- .../{LICENSE => D3_FLAME_GRAPH_LICENSE} | 0 .../pprof/third_party/d3flamegraph/D3_LICENSE | 13 + .../pprof/third_party/d3flamegraph/README.md | 33 + .../d3flamegraph/d3_flame_graph.go | 976 +--- .../pprof/third_party/d3flamegraph/index.js | 13 + .../d3flamegraph/package-lock.json | 1106 ++++ .../third_party/d3flamegraph/package.json | 17 + .../pprof/third_party/d3flamegraph/update.sh | 62 + .../d3flamegraph/webpack.config.js | 13 + src/cmd/vendor/modules.txt | 3 +- 30 files changed, 1361 insertions(+), 5845 deletions(-) delete mode 100644 src/cmd/vendor/github.com/google/pprof/third_party/d3/LICENSE delete mode 100644 src/cmd/vendor/github.com/google/pprof/third_party/d3/README.md delete mode 100644 src/cmd/vendor/github.com/google/pprof/third_party/d3/d3.go rename src/cmd/vendor/github.com/google/pprof/third_party/d3flamegraph/{LICENSE => D3_FLAME_GRAPH_LICENSE} (100%) create mode 100644 src/cmd/vendor/github.com/google/pprof/third_party/d3flamegraph/D3_LICENSE create mode 100644 src/cmd/vendor/github.com/google/pprof/third_party/d3flamegraph/README.md create mode 100644 src/cmd/vendor/github.com/google/pprof/third_party/d3flamegraph/index.js create mode 100644 src/cmd/vendor/github.com/google/pprof/third_party/d3flamegraph/package-lock.json create mode 100644 src/cmd/vendor/github.com/google/pprof/third_party/d3flamegraph/package.json create mode 100644 src/cmd/vendor/github.com/google/pprof/third_party/d3flamegraph/update.sh create mode 100644 src/cmd/vendor/github.com/google/pprof/third_party/d3flamegraph/webpack.config.js diff --git a/src/cmd/go.mod b/src/cmd/go.mod index ce1a32f3860..c99cb8cdb34 100644 --- a/src/cmd/go.mod +++ b/src/cmd/go.mod @@ -3,7 +3,7 @@ module cmd go 1.19 require ( - github.com/google/pprof v0.0.0-20211104044539-f987b9c94b31 + github.com/google/pprof v0.0.0-20220314021825-5bba342933ea golang.org/x/arch v0.0.0-20210923205945-b76863e36670 golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 golang.org/x/sync v0.0.0-20210220032951-036812b2e83c diff --git a/src/cmd/go.sum b/src/cmd/go.sum index b4a800b07e6..39d9e109adc 100644 --- a/src/cmd/go.sum +++ b/src/cmd/go.sum @@ -1,8 +1,8 @@ github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= -github.com/google/pprof v0.0.0-20211104044539-f987b9c94b31 h1:YvpxjnjGhf/vDEeYOysNbsrtB///PKS8lqkFNSDm1p8= -github.com/google/pprof v0.0.0-20211104044539-f987b9c94b31/go.mod h1:KgnwoLYCZ8IQu3XUZ8Nc/bM9CCZFOyjUNOSygVozoDg= +github.com/google/pprof v0.0.0-20220314021825-5bba342933ea h1:yVDp4C9ff/qoEAhHNf5cqk/YTxTGECSzGYzahdhEKBI= +github.com/google/pprof v0.0.0-20220314021825-5bba342933ea/go.mod h1:KgnwoLYCZ8IQu3XUZ8Nc/bM9CCZFOyjUNOSygVozoDg= github.com/ianlancetaylor/demangle v0.0.0-20210905161508-09a460cdf81d h1:uGg2frlt3IcT7kbV6LEp5ONv4vmoO2FW4qSO+my/aoM= github.com/ianlancetaylor/demangle v0.0.0-20210905161508-09a460cdf81d/go.mod h1:aYm2/VgdVmcIU8iMfdMvDMsRAQjcfZSKFby6HOFvi/w= golang.org/x/arch v0.0.0-20210923205945-b76863e36670 h1:18EFjUmQOcUvxNYSkA6jO9VAiXCnxFY6NyDX0bHDmkU= diff --git a/src/cmd/pprof/pprof.go b/src/cmd/pprof/pprof.go index e72c765adc3..c073c964b42 100644 --- a/src/cmd/pprof/pprof.go +++ b/src/cmd/pprof/pprof.go @@ -149,7 +149,7 @@ type objTool struct { disasmCache map[string]*objfile.Disasm } -func (*objTool) Open(name string, start, limit, offset uint64) (driver.ObjFile, error) { +func (*objTool) Open(name string, start, limit, offset uint64, relocationSymbol string) (driver.ObjFile, error) { of, err := objfile.Open(name) if err != nil { return nil, err diff --git a/src/cmd/vendor/github.com/google/pprof/driver/driver.go b/src/cmd/vendor/github.com/google/pprof/driver/driver.go index fc05f919baf..5a8222f70ac 100644 --- a/src/cmd/vendor/github.com/google/pprof/driver/driver.go +++ b/src/cmd/vendor/github.com/google/pprof/driver/driver.go @@ -137,8 +137,10 @@ type MappingSources map[string][]struct { type ObjTool interface { // Open opens the named object file. If the object is a shared // library, start/limit/offset are the addresses where it is mapped - // into memory in the address space being inspected. - Open(file string, start, limit, offset uint64) (ObjFile, error) + // into memory in the address space being inspected. If the object + // is a linux kernel, relocationSymbol is the name of the symbol + // corresponding to the start address. + Open(file string, start, limit, offset uint64, relocationSymbol string) (ObjFile, error) // Disasm disassembles the named object file, starting at // the start address and stopping at (before) the end address. @@ -232,8 +234,8 @@ type internalObjTool struct { ObjTool } -func (o *internalObjTool) Open(file string, start, limit, offset uint64) (plugin.ObjFile, error) { - f, err := o.ObjTool.Open(file, start, limit, offset) +func (o *internalObjTool) Open(file string, start, limit, offset uint64, relocationSymbol string) (plugin.ObjFile, error) { + f, err := o.ObjTool.Open(file, start, limit, offset, relocationSymbol) if err != nil { return nil, err } diff --git a/src/cmd/vendor/github.com/google/pprof/internal/binutils/binutils.go b/src/cmd/vendor/github.com/google/pprof/internal/binutils/binutils.go index e920eeb2fa2..efa9167af7d 100644 --- a/src/cmd/vendor/github.com/google/pprof/internal/binutils/binutils.go +++ b/src/cmd/vendor/github.com/google/pprof/internal/binutils/binutils.go @@ -284,7 +284,7 @@ func (bu *Binutils) Disasm(file string, start, end uint64, intelSyntax bool) ([] } // Open satisfies the plugin.ObjTool interface. -func (bu *Binutils) Open(name string, start, limit, offset uint64) (plugin.ObjFile, error) { +func (bu *Binutils) Open(name string, start, limit, offset uint64, relocationSymbol string) (plugin.ObjFile, error) { b := bu.get() // Make sure file is a supported executable. @@ -316,7 +316,7 @@ func (bu *Binutils) Open(name string, start, limit, offset uint64) (plugin.ObjFi // Match against supported file types. if elfMagic == elf.ELFMAG { - f, err := b.openELF(name, start, limit, offset) + f, err := b.openELF(name, start, limit, offset, relocationSymbol) if err != nil { return nil, fmt.Errorf("error reading ELF file %s: %v", name, err) } @@ -425,7 +425,7 @@ func (b *binrep) openMachO(name string, start, limit, offset uint64) (plugin.Obj return b.openMachOCommon(name, of, start, limit, offset) } -func (b *binrep) openELF(name string, start, limit, offset uint64) (plugin.ObjFile, error) { +func (b *binrep) openELF(name string, start, limit, offset uint64, relocationSymbol string) (plugin.ObjFile, error) { ef, err := elfOpen(name) if err != nil { return nil, fmt.Errorf("error parsing %s: %v", name, err) @@ -440,8 +440,8 @@ func (b *binrep) openELF(name string, start, limit, offset uint64) (plugin.ObjFi } var ( - stextOffset *uint64 - pageAligned = func(addr uint64) bool { return addr%4096 == 0 } + kernelOffset *uint64 + pageAligned = func(addr uint64) bool { return addr%4096 == 0 } ) if strings.Contains(name, "vmlinux") || !pageAligned(start) || !pageAligned(limit) || !pageAligned(offset) { // Reading all Symbols is expensive, and we only rarely need it so @@ -455,10 +455,18 @@ func (b *binrep) openELF(name string, start, limit, offset uint64) (plugin.ObjFi if err != nil && err != elf.ErrNoSymbols { return nil, err } + + // The kernel relocation symbol (the mapping start address) can be either + // _text or _stext. When profiles are generated by `perf`, which one was used is + // distinguished by the mapping name for the kernel image: + // '[kernel.kallsyms]_text' or '[kernel.kallsyms]_stext', respectively. If we haven't + // been able to parse it from the mapping, we default to _stext. + if relocationSymbol == "" { + relocationSymbol = "_stext" + } for _, s := range symbols { - if s.Name == "_stext" { - // The kernel may use _stext as the mapping start address. - stextOffset = &s.Value + if s.Name == relocationSymbol { + kernelOffset = &s.Value break } } @@ -469,7 +477,7 @@ func (b *binrep) openELF(name string, start, limit, offset uint64) (plugin.ObjFi // value until we have a sample address for this mapping, so that we can // correctly identify the associated program segment that is needed to compute // the base. - if _, err := elfexec.GetBase(&ef.FileHeader, elfexec.FindTextProgHeader(ef), stextOffset, start, limit, offset); err != nil { + if _, err := elfexec.GetBase(&ef.FileHeader, elfexec.FindTextProgHeader(ef), kernelOffset, start, limit, offset); err != nil { return nil, fmt.Errorf("could not identify base for %s: %v", name, err) } @@ -478,14 +486,14 @@ func (b *binrep) openELF(name string, start, limit, offset uint64) (plugin.ObjFi b: b, name: name, buildID: buildID, - m: &elfMapping{start: start, limit: limit, offset: offset, stextOffset: stextOffset}, + m: &elfMapping{start: start, limit: limit, offset: offset, kernelOffset: kernelOffset}, }}, nil } return &fileAddr2Line{file: file{ b: b, name: name, buildID: buildID, - m: &elfMapping{start: start, limit: limit, offset: offset, stextOffset: stextOffset}, + m: &elfMapping{start: start, limit: limit, offset: offset, kernelOffset: kernelOffset}, }}, nil } @@ -521,8 +529,8 @@ func (b *binrep) openPE(name string, start, limit, offset uint64) (plugin.ObjFil type elfMapping struct { // Runtime mapping parameters. start, limit, offset uint64 - // Offset of _stext symbol. Only defined for kernel images, nil otherwise. - stextOffset *uint64 + // Offset of kernel relocation symbol. Only defined for kernel images, nil otherwise. + kernelOffset *uint64 } // findProgramHeader returns the program segment that matches the current @@ -535,7 +543,7 @@ func (m *elfMapping) findProgramHeader(ef *elf.File, addr uint64) (*elf.ProgHead // it's a kernel / .ko module mapping, because with quipper address remapping // enabled, the address would be in the lower half of the address space. - if m.stextOffset != nil || m.start >= m.limit || m.limit >= (uint64(1)<<63) { + if m.kernelOffset != nil || m.start >= m.limit || m.limit >= (uint64(1)<<63) { // For the kernel, find the program segment that includes the .text section. return elfexec.FindTextProgHeader(ef), nil } @@ -601,7 +609,7 @@ func (f *file) computeBase(addr uint64) error { return fmt.Errorf("failed to find program header for file %q, ELF mapping %#v, address %x: %v", f.name, *f.m, addr, err) } - base, err := elfexec.GetBase(&ef.FileHeader, ph, f.m.stextOffset, f.m.start, f.m.limit, f.m.offset) + base, err := elfexec.GetBase(&ef.FileHeader, ph, f.m.kernelOffset, f.m.start, f.m.limit, f.m.offset) if err != nil { return err } diff --git a/src/cmd/vendor/github.com/google/pprof/internal/driver/cli.go b/src/cmd/vendor/github.com/google/pprof/internal/driver/cli.go index 492400c5f37..237cc332338 100644 --- a/src/cmd/vendor/github.com/google/pprof/internal/driver/cli.go +++ b/src/cmd/vendor/github.com/google/pprof/internal/driver/cli.go @@ -98,7 +98,7 @@ func parseFlags(o *plugin.Options) (*source, []string, error) { // Recognize first argument as an executable or buildid override. if len(args) > 1 { arg0 := args[0] - if file, err := o.Obj.Open(arg0, 0, ^uint64(0), 0); err == nil { + if file, err := o.Obj.Open(arg0, 0, ^uint64(0), 0, ""); err == nil { file.Close() execName = arg0 args = args[1:] diff --git a/src/cmd/vendor/github.com/google/pprof/internal/driver/fetch.go b/src/cmd/vendor/github.com/google/pprof/internal/driver/fetch.go index b8a69e87fce..0b361651bce 100644 --- a/src/cmd/vendor/github.com/google/pprof/internal/driver/fetch.go +++ b/src/cmd/vendor/github.com/google/pprof/internal/driver/fetch.go @@ -420,12 +420,14 @@ mapping: fileNames = append(fileNames, filepath.Join(path, m.File)) } for _, name := range fileNames { - if f, err := obj.Open(name, m.Start, m.Limit, m.Offset); err == nil { + if f, err := obj.Open(name, m.Start, m.Limit, m.Offset, m.KernelRelocationSymbol); err == nil { defer f.Close() fileBuildID := f.BuildID() if m.BuildID != "" && m.BuildID != fileBuildID { ui.PrintErr("Ignoring local file " + name + ": build-id mismatch (" + m.BuildID + " != " + fileBuildID + ")") } else { + // Explicitly do not update KernelRelocationSymbol -- + // the new local file name is most likely missing it. m.File = name continue mapping } @@ -449,6 +451,8 @@ mapping: if execName, buildID := s.ExecName, s.BuildID; execName != "" || buildID != "" { m := p.Mapping[0] if execName != "" { + // Explicitly do not update KernelRelocationSymbol -- + // the source override is most likely missing it. m.File = execName } if buildID != "" { diff --git a/src/cmd/vendor/github.com/google/pprof/internal/driver/webhtml.go b/src/cmd/vendor/github.com/google/pprof/internal/driver/webhtml.go index b9c73271b8c..63df668321b 100644 --- a/src/cmd/vendor/github.com/google/pprof/internal/driver/webhtml.go +++ b/src/cmd/vendor/github.com/google/pprof/internal/driver/webhtml.go @@ -17,13 +17,11 @@ package driver import ( "html/template" - "github.com/google/pprof/third_party/d3" "github.com/google/pprof/third_party/d3flamegraph" ) // addTemplates adds a set of template definitions to templates. func addTemplates(templates *template.Template) { - template.Must(templates.Parse(`{{define "d3script"}}` + d3.JSSource + `{{end}}`)) template.Must(templates.Parse(`{{define "d3flamegraphscript"}}` + d3flamegraph.JSSource + `{{end}}`)) template.Must(templates.Parse(`{{define "d3flamegraphcss"}}` + d3flamegraph.CSSSource + `{{end}}`)) template.Must(templates.Parse(` @@ -1329,40 +1327,29 @@ function viewer(baseUrl, nodes) { {{template "script" .}} -