Skip to content

Commit

Permalink
Merge remote-tracking branch 'go/release-branch.go1.22' into update-g…
Browse files Browse the repository at this point in the history
…o1.22.4
  • Loading branch information
awly committed Jun 5, 2024
2 parents 467a489 + ace5bb4 commit 4d101c0
Show file tree
Hide file tree
Showing 27 changed files with 451 additions and 336 deletions.
4 changes: 2 additions & 2 deletions VERSION
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
go1.22.3
time 2024-05-01T19:49:47Z
go1.22.4
time 2024-05-30T19:26:07Z
8 changes: 6 additions & 2 deletions src/archive/zip/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -699,9 +699,13 @@ func findSignatureInBlock(b []byte) int {
if b[i] == 'P' && b[i+1] == 'K' && b[i+2] == 0x05 && b[i+3] == 0x06 {
// n is length of comment
n := int(b[i+directoryEndLen-2]) | int(b[i+directoryEndLen-1])<<8
if n+directoryEndLen+i <= len(b) {
return i
if n+directoryEndLen+i > len(b) {
// Truncated comment.
// Some parsers (such as Info-ZIP) ignore the truncated comment
// rather than treating it as a hard error.
return -1
}
return i
}
}
return -1
Expand Down
8 changes: 8 additions & 0 deletions src/archive/zip/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,14 @@ var tests = []ZipTest{
},
},
},
// Issue 66869: Don't skip over an EOCDR with a truncated comment.
// The test file sneakily hides a second EOCDR before the first one;
// previously we would extract one file ("file") from this archive,
// while most other tools would reject the file or extract a different one ("FILE").
{
Name: "comment-truncated.zip",
Error: ErrFormat,
},
}

func TestReader(t *testing.T) {
Expand Down
Binary file added src/archive/zip/testdata/comment-truncated.zip
Binary file not shown.
19 changes: 19 additions & 0 deletions src/cmd/cgo/internal/testplugin/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func testMain(m *testing.M) int {
}
defer os.RemoveAll(GOPATH)
tmpDir = GOPATH
fmt.Printf("TMPDIR=%s\n", tmpDir)

modRoot := filepath.Join(GOPATH, "src", "testplugin")
altRoot := filepath.Join(GOPATH, "alt", "src", "testplugin")
Expand Down Expand Up @@ -395,3 +396,21 @@ func TestIssue62430(t *testing.T) {
goCmd(t, "build", "-o", "issue62430.exe", "./issue62430/main.go")
run(t, "./issue62430.exe")
}

func TestTextSectionSplit(t *testing.T) {
globalSkip(t)
if runtime.GOOS != "darwin" || runtime.GOARCH != "arm64" {
t.Skipf("text section splitting is not done in %s/%s", runtime.GOOS, runtime.GOARCH)
}

// Use -ldflags=-debugtextsize=262144 to let the linker split text section
// at a smaller size threshold, so it actually splits for the test binary.
goCmd(nil, "build", "-ldflags=-debugtextsize=262144", "-o", "host-split.exe", "./host")
run(t, "./host-split.exe")

// Check that we did split text sections.
syms := goCmd(nil, "tool", "nm", "host-split.exe")
if !strings.Contains(syms, "runtime.text.1") {
t.Errorf("runtime.text.1 not found, text section not split?")
}
}
7 changes: 6 additions & 1 deletion src/cmd/compile/internal/compare/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func calculateCostForType(t *types.Type) int64 {
return EqStructCost(t)
case types.TSLICE:
// Slices are not comparable.
base.Fatalf("eqStructFieldCost: unexpected slice type")
base.Fatalf("calculateCostForType: unexpected slice type")
case types.TARRAY:
elemCost := calculateCostForType(t.Elem())
cost = t.NumElem() * elemCost
Expand Down Expand Up @@ -371,6 +371,11 @@ func eqmem(p, q ir.Node, field int, size int64) ir.Node {
}

func eqmemfunc(size int64, t *types.Type) (fn *ir.Name, needsize bool) {
if !base.Ctxt.Arch.CanMergeLoads && t.Alignment() < int64(base.Ctxt.Arch.Alignment) && t.Alignment() < t.Size() {
// We can't use larger comparisons if the value might not be aligned
// enough for the larger comparison. See issues 46283 and 67160.
size = 0
}
switch size {
case 1, 2, 4, 8, 16:
buf := fmt.Sprintf("memequal%d", int(size)*8)
Expand Down
26 changes: 20 additions & 6 deletions src/cmd/compile/internal/noder/irgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ func checkFiles(m posMap, noders []*noder) (*types2.Package, *types2.Info) {
posBaseMap := make(map[*syntax.PosBase]*syntax.File)
for i, p := range noders {
files[i] = p.file
posBaseMap[p.file.Pos().Base()] = p.file
// The file.Pos() is the position of the package clause.
// If there's a //line directive before that, file.Pos().Base()
// refers to that directive, not the file itself.
// Make sure to consistently map back to file base, here and
// when we look for a file in the conf.Error handler below,
// otherwise the file may not be found (was go.dev/issue/67141).
posBaseMap[fileBase(p.file.Pos())] = p.file
}

// typechecking
Expand Down Expand Up @@ -68,13 +74,12 @@ func checkFiles(m posMap, noders []*noder) (*types2.Package, *types2.Info) {
terr := err.(types2.Error)
msg := terr.Msg
if versionErrorRx.MatchString(msg) {
posBase := terr.Pos.Base()
for !posBase.IsFileBase() { // line directive base
posBase = posBase.Pos().Base()
}
posBase := fileBase(terr.Pos)
fileVersion := info.FileVersions[posBase]
file := posBaseMap[posBase]
if file.GoVersion == fileVersion {
if file == nil {
// This should never happen, but be careful and don't crash.
} else if file.GoVersion == fileVersion {
// If we have a version error caused by //go:build, report it.
msg = fmt.Sprintf("%s (file declares //go:build %s)", msg, fileVersion)
} else {
Expand Down Expand Up @@ -149,6 +154,15 @@ func checkFiles(m posMap, noders []*noder) (*types2.Package, *types2.Info) {
return pkg, info
}

// fileBase returns a file's position base given a position in the file.
func fileBase(pos syntax.Pos) *syntax.PosBase {
base := pos.Base()
for !base.IsFileBase() { // line directive base
base = base.Pos().Base()
}
return base
}

// A cycleFinder detects anonymous interface cycles (go.dev/issue/56103).
type cycleFinder struct {
cyclic map[*types2.Interface]bool
Expand Down
43 changes: 26 additions & 17 deletions src/cmd/compile/internal/walk/assign.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,21 +623,23 @@ func isAppendOfMake(n ir.Node) bool {
// panicmakeslicelen()
// }
// s := l1
// n := len(s) + l2
// // Compare n and s as uint so growslice can panic on overflow of len(s) + l2.
// // cap is a positive int and n can become negative when len(s) + l2
// // overflows int. Interpreting n when negative as uint makes it larger
// // than cap(s). growslice will check the int n arg and panic if n is
// // negative. This prevents the overflow from being undetected.
// if uint(n) <= uint(cap(s)) {
// s = s[:n]
// } else {
// s = growslice(T, s.ptr, n, s.cap, l2, T)
// if l2 != 0 {
// n := len(s) + l2
// // Compare n and s as uint so growslice can panic on overflow of len(s) + l2.
// // cap is a positive int and n can become negative when len(s) + l2
// // overflows int. Interpreting n when negative as uint makes it larger
// // than cap(s). growslice will check the int n arg and panic if n is
// // negative. This prevents the overflow from being undetected.
// if uint(n) <= uint(cap(s)) {
// s = s[:n]
// } else {
// s = growslice(T, s.ptr, n, s.cap, l2, T)
// }
// // clear the new portion of the underlying array.
// hp := &s[len(s)-l2]
// hn := l2 * sizeof(T)
// memclr(hp, hn)
// }
// // clear the new portion of the underlying array.
// hp := &s[len(s)-l2]
// hn := l2 * sizeof(T)
// memclr(hp, hn)
// }
// s
//
Expand Down Expand Up @@ -671,11 +673,18 @@ func extendSlice(n *ir.CallExpr, init *ir.Nodes) ir.Node {
s := typecheck.TempAt(base.Pos, ir.CurFunc, l1.Type())
nodes = append(nodes, ir.NewAssignStmt(base.Pos, s, l1))

// if l2 != 0 {
// Avoid work if we're not appending anything. But more importantly,
// avoid allowing hp to be a past-the-end pointer when clearing. See issue 67255.
nifnz := ir.NewIfStmt(base.Pos, ir.NewBinaryExpr(base.Pos, ir.ONE, l2, ir.NewInt(base.Pos, 0)), nil, nil)
nifnz.Likely = true
nodes = append(nodes, nifnz)

elemtype := s.Type().Elem()

// n := s.len + l2
nn := typecheck.TempAt(base.Pos, ir.CurFunc, types.Types[types.TINT])
nodes = append(nodes, ir.NewAssignStmt(base.Pos, nn, ir.NewBinaryExpr(base.Pos, ir.OADD, ir.NewUnaryExpr(base.Pos, ir.OLEN, s), l2)))
nifnz.Body = append(nifnz.Body, ir.NewAssignStmt(base.Pos, nn, ir.NewBinaryExpr(base.Pos, ir.OADD, ir.NewUnaryExpr(base.Pos, ir.OLEN, s), l2)))

// if uint(n) <= uint(s.cap)
nuint := typecheck.Conv(nn, types.Types[types.TUINT])
Expand All @@ -697,7 +706,7 @@ func extendSlice(n *ir.CallExpr, init *ir.Nodes) ir.Node {
l2)),
}

nodes = append(nodes, nif)
nifnz.Body = append(nifnz.Body, nif)

// hp := &s[s.len - l2]
// TODO: &s[s.len] - hn?
Expand All @@ -723,7 +732,7 @@ func extendSlice(n *ir.CallExpr, init *ir.Nodes) ir.Node {
// if growslice isn't called do we need to do the zeroing ourselves.
nif.Body = append(nif.Body, clr...)
} else {
nodes = append(nodes, clr...)
nifnz.Body = append(nifnz.Body, clr...)
}

typecheck.Stmts(nodes)
Expand Down
11 changes: 11 additions & 0 deletions src/cmd/go/internal/toolchain/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,13 @@ func Select() {
}
if gover.Compare(goVers, minVers) > 0 {
gotoolchain = "go" + goVers
// Starting with Go 1.21, the first released version has a .0 patch version suffix.
// Don't try to download a language version (sans patch component), such as go1.22.
// Instead, use the first toolchain of that language version, such as 1.22.0.
// See golang.org/issue/62278.
if gover.IsLang(goVers) && gover.Compare(goVers, "1.21") >= 0 {
gotoolchain += ".0"
}
gover.Startup.AutoGoVersion = goVers
gover.Startup.AutoToolchain = "" // in case we are overriding it for being too old
}
Expand Down Expand Up @@ -312,6 +319,10 @@ func Exec(gotoolchain string) {
dir, err := modfetch.Download(context.Background(), m)
if err != nil {
if errors.Is(err, fs.ErrNotExist) {
toolVers := gover.FromToolchain(gotoolchain)
if gover.IsLang(toolVers) && gover.Compare(toolVers, "1.21") >= 0 {
base.Fatalf("invalid toolchain: %s is a language version but not a toolchain version (%s.x)", gotoolchain, gotoolchain)
}
base.Fatalf("download %s for %s/%s: toolchain not available", gotoolchain, runtime.GOOS, runtime.GOARCH)
}
base.Fatalf("download %s: %v", gotoolchain, err)
Expand Down
7 changes: 7 additions & 0 deletions src/cmd/go/testdata/script/build_issue48319.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
[short] skip
[!cgo] skip

# This test has problems when run on the LUCI darwin longtest builder,
# which uses a more contemporary Xcode version that is unfriendly to
# reproducible builds (see issue #64947 for the gory details). Note
# that individual developers running "go test cmd/go" on Darwin may
# still run into failures depending on their Xcode version.
[GOOS:darwin] [go-builder] skip

# This test is sensitive to cache invalidation,
# so use a separate build cache that we can control.
env GOCACHE=$WORK/gocache
Expand Down
7 changes: 7 additions & 0 deletions src/cmd/go/testdata/script/build_plugin_reproducible.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
[!buildmode:plugin] skip
[short] skip

# This test has problems when run on the LUCI darwin longtest builder,
# which uses a more contemporary Xcode version that is unfriendly to
# reproducible builds (see issue #64947 for the gory details). Note
# that individual developers running "go test cmd/go" on Darwin may
# still run into failures depending on their Xcode version.
[GOOS:darwin] [go-builder] skip

go build -trimpath -buildvcs=false -buildmode=plugin -o a.so main.go
go build -trimpath -buildvcs=false -buildmode=plugin -o b.so main.go
cmp -q a.so b.so
Expand Down
109 changes: 109 additions & 0 deletions src/cmd/go/testdata/script/gotoolchain_issue66175.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
env TESTGO_VERSION=go1.14

# Clear the path so this test doesn't fail if the system running it\
# has a binary named go1.21 or go1.22 on its path.
[GOOS:plan9] env path=
[!GOOS:plan9] env PATH=

# check for invalid toolchain in go.mod
go mod init m
go mod edit -go=1.14 -toolchain=go1.22
! go version
stderr 'go: invalid toolchain: go1.22 is a language version but not a toolchain version \(go1.22.x\)'

rm go.mod
go mod init m
go mod edit -go=1.14 -toolchain=go1.21
! go version
stderr 'go: invalid toolchain: go1.21 is a language version but not a toolchain version \(go1.21.x\)'

rm go.mod
go mod init m
go mod edit -go=1.14 -toolchain=go1.20
! go version
stderr 'go: downloading go1.20 '


# check for invalid GOTOOLCHAIN
env GOTOOLCHAIN=go1.14
go version
stdout 'go1.14'

env GOTOOLCHAIN=go1.20
! go version
stderr 'go: downloading go1.20 '

env GOTOOLCHAIN=go1.21
! go version
stderr 'go: invalid toolchain: go1.21 is a language version but not a toolchain version \(go1.21.x\)'

env GOTOOLCHAIN=go1.22
! go version
stderr 'go: invalid toolchain: go1.22 is a language version but not a toolchain version \(go1.22.x\)'

env GOTOOLCHAIN=go1.20+auto
! go version
stderr 'go: downloading go1.20 '

env GOTOOLCHAIN=go1.21+auto
! go version
stderr 'go: invalid toolchain: go1.21 is a language version but not a toolchain version \(go1.21.x\)'

env GOTOOLCHAIN=go1.22+auto
! go version
stderr 'go: invalid toolchain: go1.22 is a language version but not a toolchain version \(go1.22.x\)'

env GOTOOLCHAIN=go1.21rc3
! go version
stderr 'go: downloading go1.21rc3 '

env GOTOOLCHAIN=go1.22rc2
! go version
stderr 'go: downloading go1.22rc2 '

env GOTOOLCHAIN=go1.66
! go version
stderr 'go: invalid toolchain: go1.66 is a language version but not a toolchain version \(go1.66.x\)'

env GOTOOLCHAIN=go1.18beta2
! go version
stderr 'go: downloading go1.18beta2 '

# go1.X is okay for path lookups
env GOTOOLCHAIN=go1.20+path
! go version
stderr 'go: cannot find "go1.20" in PATH'

env GOTOOLCHAIN=go1.21+path
! go version
stderr 'go: cannot find "go1.21" in PATH'

env GOTOOLCHAIN=go1.22+path
! go version
stderr 'go: cannot find "go1.22" in PATH'

# When a toolchain download takes place, download 1.X.0
env GOTOOLCHAIN=auto
rm go.mod
go mod init m
go mod edit -go=1.300 -toolchain=none
! go version
stderr 'go: downloading go1.300.0 '

rm go.mod
go mod init m
go mod edit -go=1.21 -toolchain=none
! go version
stderr 'go: downloading go1.21.0 '

rm go.mod
go mod init m
go mod edit -go=1.22 -toolchain=none
! go version
stderr 'go: downloading go1.22.0 '

rm go.mod
go mod init m
go mod edit -go=1.15 -toolchain=none
! go version
stderr 'go: downloading go1.15 '
Loading

0 comments on commit 4d101c0

Please sign in to comment.