Skip to content

Commit

Permalink
Merge branch 'release-branch.go1.20' of https://go.googlesource.com/go
Browse files Browse the repository at this point in the history
…into bradfitz/1_20_1

For Go 1.20.1
  • Loading branch information
bradfitz committed Feb 14, 2023
2 parents 13373ca + 828b05c commit ec180cb
Show file tree
Hide file tree
Showing 38 changed files with 1,221 additions and 625 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
go1.20
go1.20.1
23 changes: 22 additions & 1 deletion src/cmd/compile/internal/pgo/irgraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,30 @@ func New(profileFile string) *Profile {
return nil
}

if len(profile.Sample) == 0 {
// We accept empty profiles, but there is nothing to do.
return nil
}

valueIndex := -1
for i, s := range profile.SampleType {
// Samples count is the raw data collected, and CPU nanoseconds is just
// a scaled version of it, so either one we can find is fine.
if (s.Type == "samples" && s.Unit == "count") ||
(s.Type == "cpu" && s.Unit == "nanoseconds") {
valueIndex = i
break
}
}

if valueIndex == -1 {
log.Fatal("failed to find CPU samples count or CPU nanoseconds value-types in profile.")
return nil
}

g := newGraph(profile, &Options{
CallTree: false,
SampleValue: func(v []int64) int64 { return v[1] },
SampleValue: func(v []int64) int64 { return v[valueIndex] },
})

p := &Profile{
Expand Down
68 changes: 68 additions & 0 deletions src/cmd/compile/internal/test/pgo_inl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package test
import (
"bufio"
"fmt"
"internal/profile"
"internal/testenv"
"io"
"os"
Expand Down Expand Up @@ -213,6 +214,73 @@ func TestPGOIntendedInliningShiftedLines(t *testing.T) {
testPGOIntendedInlining(t, dir)
}

// TestPGOSingleIndex tests that the sample index can not be 1 and compilation
// will not fail. All it should care about is that the sample type is either
// CPU nanoseconds or samples count, whichever it finds first.
func TestPGOSingleIndex(t *testing.T) {
for _, tc := range []struct {
originalIndex int
}{{
// The `testdata/pgo/inline/inline_hot.pprof` file is a standard CPU
// profile as the runtime would generate. The 0 index contains the
// value-type samples and value-unit count. The 1 index contains the
// value-type cpu and value-unit nanoseconds. These tests ensure that
// the compiler can work with profiles that only have a single index,
// but are either samples count or CPU nanoseconds.
originalIndex: 0,
}, {
originalIndex: 1,
}} {
t.Run(fmt.Sprintf("originalIndex=%d", tc.originalIndex), func(t *testing.T) {
wd, err := os.Getwd()
if err != nil {
t.Fatalf("error getting wd: %v", err)
}
srcDir := filepath.Join(wd, "testdata/pgo/inline")

// Copy the module to a scratch location so we can add a go.mod.
dir := t.TempDir()

originalPprofFile, err := os.Open(filepath.Join(srcDir, "inline_hot.pprof"))
if err != nil {
t.Fatalf("error opening inline_hot.pprof: %v", err)
}
defer originalPprofFile.Close()

p, err := profile.Parse(originalPprofFile)
if err != nil {
t.Fatalf("error parsing inline_hot.pprof: %v", err)
}

// Move the samples count value-type to the 0 index.
p.SampleType = []*profile.ValueType{p.SampleType[tc.originalIndex]}

// Ensure we only have a single set of sample values.
for _, s := range p.Sample {
s.Value = []int64{s.Value[tc.originalIndex]}
}

modifiedPprofFile, err := os.Create(filepath.Join(dir, "inline_hot.pprof"))
if err != nil {
t.Fatalf("error creating inline_hot.pprof: %v", err)
}
defer modifiedPprofFile.Close()

if err := p.Write(modifiedPprofFile); err != nil {
t.Fatalf("error writing inline_hot.pprof: %v", err)
}

for _, file := range []string{"inline_hot.go", "inline_hot_test.go"} {
if err := copyFile(filepath.Join(dir, file), filepath.Join(srcDir, file)); err != nil {
t.Fatalf("error copying %s: %v", file, err)
}
}

testPGOIntendedInlining(t, dir)
})
}
}

func copyFile(dst, src string) error {
s, err := os.Open(src)
if err != nil {
Expand Down
17 changes: 0 additions & 17 deletions src/cmd/go/internal/modfetch/coderepo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,18 +404,6 @@ var codeRepoTests = []codeRepoTest{
zipSum: "h1:YJYZRsM9BHFTlVr8YADjT0cJH8uFIDtoc5NLiVqZEx8=",
zipFileHash: "c15e49d58b7a4c37966cbe5bc01a0330cd5f2927e990e1839bda1d407766d9c5",
},
{
vcs: "git",
path: "gopkg.in/natefinch/lumberjack.v2",
rev: "latest",
version: "v2.0.0-20170531160350-a96e63847dc3",
name: "a96e63847dc3c67d17befa69c303767e2f84e54f",
short: "a96e63847dc3",
time: time.Date(2017, 5, 31, 16, 3, 50, 0, time.UTC),
gomod: "module gopkg.in/natefinch/lumberjack.v2\n",
zipSum: "h1:AFxeG48hTWHhDTQDk/m2gorfVHUEa9vo3tp3D7TzwjI=",
zipFileHash: "b5de0da7bbbec76709eef1ac71b6c9ff423b9fbf3bb97b56743450d4937b06d5",
},
{
vcs: "git",
path: "gopkg.in/natefinch/lumberjack.v2",
Expand Down Expand Up @@ -818,11 +806,6 @@ var codeRepoVersionsTests = []struct {
path: "swtch.com/testmod",
versions: []string{"v1.0.0", "v1.1.1"},
},
{
vcs: "git",
path: "gopkg.in/natefinch/lumberjack.v2",
versions: []string{"v2.0.0"},
},
{
vcs: "git",
path: "vcs-test.golang.org/git/odd-tags.git",
Expand Down
46 changes: 31 additions & 15 deletions src/cmd/go/internal/script/cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,21 +432,37 @@ func Exec(cancel func(*exec.Cmd) error, waitDelay time.Duration) Cmd {
}

func startCommand(s *State, name, path string, args []string, cancel func(*exec.Cmd) error, waitDelay time.Duration) (WaitFunc, error) {
var stdoutBuf, stderrBuf strings.Builder
cmd := exec.CommandContext(s.Context(), path, args...)
if cancel == nil {
cmd.Cancel = nil
} else {
cmd.Cancel = func() error { return cancel(cmd) }
}
cmd.WaitDelay = waitDelay
cmd.Args[0] = name
cmd.Dir = s.Getwd()
cmd.Env = s.env
cmd.Stdout = &stdoutBuf
cmd.Stderr = &stderrBuf
if err := cmd.Start(); err != nil {
return nil, err
var (
cmd *exec.Cmd
stdoutBuf, stderrBuf strings.Builder
)
for {
cmd = exec.CommandContext(s.Context(), path, args...)
if cancel == nil {
cmd.Cancel = nil
} else {
cmd.Cancel = func() error { return cancel(cmd) }
}
cmd.WaitDelay = waitDelay
cmd.Args[0] = name
cmd.Dir = s.Getwd()
cmd.Env = s.env
cmd.Stdout = &stdoutBuf
cmd.Stderr = &stderrBuf
err := cmd.Start()
if err == nil {
break
}
if isETXTBSY(err) {
// If the script (or its host process) just wrote the executable we're
// trying to run, a fork+exec in another thread may be holding open the FD
// that we used to write the executable (see https://go.dev/issue/22315).
// Since the descriptor should have CLOEXEC set, the problem should
// resolve as soon as the forked child reaches its exec call.
// Keep retrying until that happens.
} else {
return nil, err
}
}

wait := func(s *State) (stdout, stderr string, err error) {
Expand Down
11 changes: 11 additions & 0 deletions src/cmd/go/internal/script/cmds_other.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright 2023 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 !(unix || windows)

package script

func isETXTBSY(err error) bool {
return false
}
16 changes: 16 additions & 0 deletions src/cmd/go/internal/script/cmds_posix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2023 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 unix || windows

package script

import (
"errors"
"syscall"
)

func isETXTBSY(err error) bool {
return errors.Is(err, syscall.ETXTBSY)
}
1 change: 1 addition & 0 deletions src/cmd/go/internal/test/flagdefs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/cmd/go/internal/test/flagdefs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import (
"cmd/go/internal/test/internal/genflags"
"flag"
"internal/testenv"
"os"
"reflect"
"strings"
"testing"
)

func TestMain(m *testing.M) {
cfg.SetGOROOT(testenv.GOROOT(nil), false)
os.Exit(m.Run())
}

func TestPassFlagToTestIncludesAllTestFlags(t *testing.T) {
Expand Down Expand Up @@ -48,6 +50,8 @@ func TestPassFlagToTestIncludesAllTestFlags(t *testing.T) {
}

func TestVetAnalyzersSetIsCorrect(t *testing.T) {
testenv.MustHaveGoBuild(t) // runs 'go tool vet -flags'

vetAns, err := genflags.VetAnalyzers()
if err != nil {
t.Fatal(err)
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/go/internal/test/genflags.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func testFlags() []string {
}

switch name {
case "testlogfile", "paniconexit0", "fuzzcachedir", "fuzzworker":
case "testlogfile", "paniconexit0", "fuzzcachedir", "fuzzworker", "gocoverdir":
// These flags are only for use by cmd/go.
default:
names = append(names, name)
Expand Down
24 changes: 24 additions & 0 deletions src/cmd/go/testdata/script/version_gc_sections.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# This test checks that external linking with --gc-sections does not strip version information.

[short] skip
[!cgo] skip
[GOOS:aix] skip # no --gc-sections
[GOOS:darwin] skip # no --gc-sections

go build -ldflags='-linkmode=external -extldflags=-Wl,--gc-sections'
go version hello$GOEXE
! stdout 'not a Go executable'
! stderr 'not a Go executable'

-- go.mod --
module hello
-- hello.go --
package main

/*
*/
import "C"

func main() {
println("hello")
}
13 changes: 12 additions & 1 deletion src/cmd/link/internal/ld/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -1669,6 +1669,9 @@ func (ctxt *Link) dodata(symGroupType []sym.SymKind) {
func (state *dodataState) allocateDataSectionForSym(seg *sym.Segment, s loader.Sym, rwx int) *sym.Section {
ldr := state.ctxt.loader
sname := ldr.SymName(s)
if strings.HasPrefix(sname, "go:") {
sname = ".go." + sname[len("go:"):]
}
sect := addsection(ldr, state.ctxt.Arch, seg, sname, rwx)
sect.Align = symalign(ldr, s)
state.datsize = Rnd(state.datsize, int64(sect.Align))
Expand Down Expand Up @@ -2254,7 +2257,7 @@ func (ctxt *Link) buildinfo() {
// Write the buildinfo symbol, which go version looks for.
// The code reading this data is in package debug/buildinfo.
ldr := ctxt.loader
s := ldr.CreateSymForUpdate(".go.buildinfo", 0)
s := ldr.CreateSymForUpdate("go:buildinfo", 0)
s.SetType(sym.SBUILDINFO)
s.SetAlign(16)
// The \xff is invalid UTF-8, meant to make it less likely
Expand All @@ -2276,6 +2279,14 @@ func (ctxt *Link) buildinfo() {
}
s.SetData(data)
s.SetSize(int64(len(data)))

// Add reference to go:buildinfo from the rodata section,
// so that external linking with -Wl,--gc-sections does not
// delete the build info.
sr := ldr.CreateSymForUpdate("go:buildinfo.ref", 0)
sr.SetType(sym.SRODATA)
sr.SetAlign(int32(ctxt.Arch.PtrSize))
sr.AddAddr(ctxt.Arch, s.Sym())
}

// appendString appends s to data, prefixed by its varint-encoded length.
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/tls/boring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ func TestBoringClientHello(t *testing.T) {

go Client(c, clientConfig).Handshake()
srv := Server(s, testConfig)
msg, err := srv.readHandshake()
msg, err := srv.readHandshake(nil)
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/tls/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -1394,7 +1394,7 @@ func (c *Certificate) leaf() (*x509.Certificate, error) {
}

type handshakeMessage interface {
marshal() []byte
marshal() ([]byte, error)
unmarshal([]byte) bool
}

Expand Down
Loading

0 comments on commit ec180cb

Please sign in to comment.