From 9364c89e26d9601ee03fa0292c912c795d210ff9 Mon Sep 17 00:00:00 2001 From: Heschi Kreinick Date: Wed, 15 Dec 2021 18:44:36 +0000 Subject: [release-branch.go1.16] Reapply "cmd/link: support more load commands on Mach-O" This reverts commit caced3b213e879b2af0508f5f6a2d3bb3d6ef2a9 (CL 370554). Reason for revert: Minor release complete. Updates #49923. Change-Id: Ifb9fc4f6aae6313ce726726c4ec469032ed3147d Reviewed-on: https://go-review.googlesource.com/c/go/+/372354 Reviewed-by: Cherry Mui Reviewed-by: Alex Rakoczy Trust: Heschi Kreinick --- src/cmd/link/internal/ld/macho.go | 4 ++++ src/cmd/link/internal/ld/macho_combine_dwarf.go | 12 ++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/cmd/link/internal/ld/macho.go b/src/cmd/link/internal/ld/macho.go index a9f4d87229..ac2103c91e 100644 --- a/src/cmd/link/internal/ld/macho.go +++ b/src/cmd/link/internal/ld/macho.go @@ -86,6 +86,8 @@ const ( MACHO_SUBCPU_ARMV7 = 9 MACHO_CPU_ARM64 = 1<<24 | 12 MACHO_SUBCPU_ARM64_ALL = 0 + MACHO_SUBCPU_ARM64_V8 = 1 + MACHO_SUBCPU_ARM64E = 2 MACHO32SYMSIZE = 12 MACHO64SYMSIZE = 16 MACHO_X86_64_RELOC_UNSIGNED = 0 @@ -176,6 +178,8 @@ const ( LC_VERSION_MIN_WATCHOS = 0x30 LC_VERSION_NOTE = 0x31 LC_BUILD_VERSION = 0x32 + LC_DYLD_EXPORTS_TRIE = 0x80000033 + LC_DYLD_CHAINED_FIXUPS = 0x80000034 ) const ( diff --git a/src/cmd/link/internal/ld/macho_combine_dwarf.go b/src/cmd/link/internal/ld/macho_combine_dwarf.go index 77ee8a4d62..0015b7d756 100644 --- a/src/cmd/link/internal/ld/macho_combine_dwarf.go +++ b/src/cmd/link/internal/ld/macho_combine_dwarf.go @@ -222,11 +222,19 @@ func machoCombineDwarf(ctxt *Link, exef *os.File, exem *macho.File, dsym, outexe err = machoUpdateLoadCommand(reader, linkseg, linkoffset, &macho.SymtabCmd{}, "Symoff", "Stroff") case macho.LoadCmdDysymtab: err = machoUpdateLoadCommand(reader, linkseg, linkoffset, &macho.DysymtabCmd{}, "Tocoffset", "Modtaboff", "Extrefsymoff", "Indirectsymoff", "Extreloff", "Locreloff") - case LC_CODE_SIGNATURE, LC_SEGMENT_SPLIT_INFO, LC_FUNCTION_STARTS, LC_DATA_IN_CODE, LC_DYLIB_CODE_SIGN_DRS: + case LC_CODE_SIGNATURE, LC_SEGMENT_SPLIT_INFO, LC_FUNCTION_STARTS, LC_DATA_IN_CODE, LC_DYLIB_CODE_SIGN_DRS, + LC_DYLD_EXPORTS_TRIE, LC_DYLD_CHAINED_FIXUPS: err = machoUpdateLoadCommand(reader, linkseg, linkoffset, &linkEditDataCmd{}, "DataOff") case LC_ENCRYPTION_INFO, LC_ENCRYPTION_INFO_64: err = machoUpdateLoadCommand(reader, linkseg, linkoffset, &encryptionInfoCmd{}, "CryptOff") - case macho.LoadCmdDylib, macho.LoadCmdThread, macho.LoadCmdUnixThread, LC_PREBOUND_DYLIB, LC_UUID, LC_VERSION_MIN_MACOSX, LC_VERSION_MIN_IPHONEOS, LC_SOURCE_VERSION, LC_MAIN, LC_LOAD_DYLINKER, LC_LOAD_WEAK_DYLIB, LC_REEXPORT_DYLIB, LC_RPATH, LC_ID_DYLIB, LC_SYMSEG, LC_LOADFVMLIB, LC_IDFVMLIB, LC_IDENT, LC_FVMFILE, LC_PREPAGE, LC_ID_DYLINKER, LC_ROUTINES, LC_SUB_FRAMEWORK, LC_SUB_UMBRELLA, LC_SUB_CLIENT, LC_SUB_LIBRARY, LC_TWOLEVEL_HINTS, LC_PREBIND_CKSUM, LC_ROUTINES_64, LC_LAZY_LOAD_DYLIB, LC_LOAD_UPWARD_DYLIB, LC_DYLD_ENVIRONMENT, LC_LINKER_OPTION, LC_LINKER_OPTIMIZATION_HINT, LC_VERSION_MIN_TVOS, LC_VERSION_MIN_WATCHOS, LC_VERSION_NOTE, LC_BUILD_VERSION: + case macho.LoadCmdDylib, macho.LoadCmdThread, macho.LoadCmdUnixThread, + LC_PREBOUND_DYLIB, LC_UUID, LC_VERSION_MIN_MACOSX, LC_VERSION_MIN_IPHONEOS, LC_SOURCE_VERSION, + LC_MAIN, LC_LOAD_DYLINKER, LC_LOAD_WEAK_DYLIB, LC_REEXPORT_DYLIB, LC_RPATH, LC_ID_DYLIB, + LC_SYMSEG, LC_LOADFVMLIB, LC_IDFVMLIB, LC_IDENT, LC_FVMFILE, LC_PREPAGE, LC_ID_DYLINKER, + LC_ROUTINES, LC_SUB_FRAMEWORK, LC_SUB_UMBRELLA, LC_SUB_CLIENT, LC_SUB_LIBRARY, LC_TWOLEVEL_HINTS, + LC_PREBIND_CKSUM, LC_ROUTINES_64, LC_LAZY_LOAD_DYLIB, LC_LOAD_UPWARD_DYLIB, LC_DYLD_ENVIRONMENT, + LC_LINKER_OPTION, LC_LINKER_OPTIMIZATION_HINT, LC_VERSION_MIN_TVOS, LC_VERSION_MIN_WATCHOS, + LC_VERSION_NOTE, LC_BUILD_VERSION: // Nothing to update default: err = fmt.Errorf("unknown load command 0x%x (%s)", int(cmd.Cmd), cmd.Cmd) -- cgit v1.2.3-54-g00ecf From 831d491ad72601f5ea04100fc27c8580844749a9 Mon Sep 17 00:00:00 2001 From: Cherry Mui Date: Fri, 25 Jun 2021 15:58:38 -0400 Subject: [release-branch.go1.16] runtime/race: use race build tag on syso_test.go All other test files in the runtime/race package have race build tag, except syso_test.go. The test is only relevant if the race detector is supported. So apply the build tag. Updates #46931. Fixes #50194. Change-Id: Icdb94214d3821b4ccf61133412ef39b4d7cc7691 Reviewed-on: https://go-review.googlesource.com/c/go/+/331050 Trust: Cherry Mui Reviewed-by: Elias Naur Run-TryBot: Cherry Mui TryBot-Result: Go Bot (cherry picked from commit ed01ceaf4838cd67fd802df481769fa9ae9d0440) Reviewed-on: https://go-review.googlesource.com/c/go/+/372218 Reviewed-by: Dmitri Shuralyov Run-TryBot: Dmitri Shuralyov TryBot-Result: Gopher Robot --- src/runtime/race/syso_test.go | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/runtime/race/syso_test.go b/src/runtime/race/syso_test.go index db846c5d2a..f5095737a4 100644 --- a/src/runtime/race/syso_test.go +++ b/src/runtime/race/syso_test.go @@ -2,13 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build !android,!js,!ppc64le - -// Note: we don't run on Android or ppc64 because if there is any non-race test -// file in this package, the OS tries to link the .syso file into the -// test (even when we're not in race mode), which fails. I'm not sure -// why, but easiest to just punt - as long as a single builder runs -// this test, we're good. +//go:build race +// +build race package race -- cgit v1.2.3-54-g00ecf From 168bc3a76efb30910667849a03eecb69b6e8b0ea Mon Sep 17 00:00:00 2001 From: hanpro Date: Fri, 5 Nov 2021 09:47:54 +0800 Subject: [release-branch.go1.16] cmd/compile: avoid adding LECall to the entry block when has opendefers The openDeferRecord always insert vardef/varlive pairs into the entry block, it may destroy the mem chain when LECall's args are writing into the same block. So create a new block before that happens. Fixes #49412 Change-Id: Ibda6c4a45d960dd412a641f5e02276f663c80785 Reviewed-on: https://go-review.googlesource.com/c/go/+/361410 Run-TryBot: Alberto Donizetti TryBot-Result: Go Bot Trust: Alberto Donizetti Trust: Than McIntosh Reviewed-by: David Chase (cherry picked from commit 4f083c7dcf6ace3e837b337e10cf2f4e3160677e) Reviewed-on: https://go-review.googlesource.com/c/go/+/362055 Reviewed-by: Keith Randall Trust: Michael Knyszek Run-TryBot: Dmitri Shuralyov TryBot-Result: Gopher Robot --- src/cmd/compile/internal/gc/ssa.go | 11 ++++++++++ test/fixedbugs/issue49282.go | 44 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 test/fixedbugs/issue49282.go diff --git a/src/cmd/compile/internal/gc/ssa.go b/src/cmd/compile/internal/gc/ssa.go index 5b74754b53..8975ad3559 100644 --- a/src/cmd/compile/internal/gc/ssa.go +++ b/src/cmd/compile/internal/gc/ssa.go @@ -4709,6 +4709,17 @@ func (s *state) call(n *Node, k callKind, returnResultAddr bool) *ssa.Value { } } + // Split the entry block if there are open defers, because later calls to + // openDeferSave may cause a mismatch between the mem for an OpDereference + // and the call site which uses it. See #49282. + if s.curBlock.ID == s.f.Entry.ID && s.hasOpenDefers { + b := s.endBlock() + b.Kind = ssa.BlockPlain + curb := s.f.NewBlock(ssa.BlockPlain) + b.AddEdgeTo(curb) + s.startBlock(curb) + } + // Write args. t := n.Left.Type args := n.Rlist.Slice() diff --git a/test/fixedbugs/issue49282.go b/test/fixedbugs/issue49282.go new file mode 100644 index 0000000000..7543075ca1 --- /dev/null +++ b/test/fixedbugs/issue49282.go @@ -0,0 +1,44 @@ +// compile + +// 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 + +//go:noinline +func g(d uintptr, a, m []int, s struct { + a, b, c, d, e int +}, u uint) { + _ = a + _ = m + _ = s + func() { + for i := 0; i < 5; i++ { + _ = a + _ = m + _, _ = s, s + } + }() +} + +var One float64 = 1.0 + +func f(d uintptr) { + var a, m []int + var s struct { + a, b, c, d, e int + } + + g(d, a, m, s, uint(One)) // Uint of not-a-constant inserts a conditional, necessary to bug + + defer func() uint { + return 0 + }() +} + +var d uintptr + +func h() { + f(d) +} -- cgit v1.2.3-54-g00ecf From 281860c4fe199ede946122918c3535b91ceefdbc Mon Sep 17 00:00:00 2001 From: Cherry Mui Date: Tue, 30 Nov 2021 18:58:53 -0500 Subject: [release-branch.go1.16] runtime/race: rebuild darwin syso to work around macOS 12 malloc reserved address On macOS 12 a new malloc implementation (nano) is used by default, and apparently it reserves address range 0x600000000000-0x600020000000, which conflicts with the address range that TSAN uses for Go. Work around the issue by changing the address range slightly. The actual change is made on LLVM at https://reviews.llvm.org/D114825 . This CL includes syso's built with the patch applied. The syso in 1.16 was identical to the syso before the equivalent fix on the main branch, so the back-ported syso is identical to the fixed syso on the main branch. Fixes #50072. Updates #49138. Change-Id: I7b367d6e042b0db39a691c71601c98e4f8728a70 Reviewed-on: https://go-review.googlesource.com/c/go/+/367916 Trust: Cherry Mui Reviewed-by: Austin Clements (cherry picked from commit 5f6552018d1ec920c3ca3d459691528f48363c3c) Reviewed-on: https://go-review.googlesource.com/c/go/+/370698 --- src/runtime/race/README | 4 ++-- src/runtime/race/race_darwin_amd64.syso | Bin 451280 -> 455944 bytes src/runtime/race/race_darwin_arm64.syso | Bin 438936 -> 438560 bytes 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/runtime/race/README b/src/runtime/race/README index 178ab94ab5..15aa3be47a 100644 --- a/src/runtime/race/README +++ b/src/runtime/race/README @@ -4,11 +4,11 @@ the LLVM project (https://github.com/llvm/llvm-project/tree/master/compiler-rt). To update the .syso files use golang.org/x/build/cmd/racebuild. -race_darwin_amd64.syso built with LLVM 89f7ccea6f6488c443655880229c54db1f180153 and Go f62d3202bf9dbb3a00ad2a2c63ff4fa4188c5d3b. +race_darwin_amd64.syso built with LLVM 89f7ccea6f6488c443655880229c54db1f180153 with https://reviews.llvm.org/D114825 applied and Go 7ccbcc90560468937f02609a43cb39a6e13ff797. race_freebsd_amd64.syso built with LLVM 89f7ccea6f6488c443655880229c54db1f180153 and Go f62d3202bf9dbb3a00ad2a2c63ff4fa4188c5d3b. race_linux_amd64.syso built with LLVM 89f7ccea6f6488c443655880229c54db1f180153 and Go f62d3202bf9dbb3a00ad2a2c63ff4fa4188c5d3b. race_linux_ppc64le.syso built with LLVM 89f7ccea6f6488c443655880229c54db1f180153 and Go f62d3202bf9dbb3a00ad2a2c63ff4fa4188c5d3b. race_netbsd_amd64.syso built with LLVM 89f7ccea6f6488c443655880229c54db1f180153 and Go f62d3202bf9dbb3a00ad2a2c63ff4fa4188c5d3b. race_windows_amd64.syso built with LLVM 89f7ccea6f6488c443655880229c54db1f180153 and Go f62d3202bf9dbb3a00ad2a2c63ff4fa4188c5d3b. race_linux_arm64.syso built with LLVM 89f7ccea6f6488c443655880229c54db1f180153 and Go f62d3202bf9dbb3a00ad2a2c63ff4fa4188c5d3b. -race_darwin_arm64.syso built with LLVM 00da38ce2d36c07f12c287dc515d37bb7bc410e9 and Go fe70a3a0fd31441bcbb9932ecab11a6083cf2119. +race_darwin_arm64.syso built with LLVM 00da38ce2d36c07f12c287dc515d37bb7bc410e9 with https://reviews.llvm.org/D114825 applied and Go 7ccbcc90560468937f02609a43cb39a6e13ff797. diff --git a/src/runtime/race/race_darwin_amd64.syso b/src/runtime/race/race_darwin_amd64.syso index 3f95ecc8ee..6fbe140026 100644 Binary files a/src/runtime/race/race_darwin_amd64.syso and b/src/runtime/race/race_darwin_amd64.syso differ diff --git a/src/runtime/race/race_darwin_arm64.syso b/src/runtime/race/race_darwin_arm64.syso index f6eaa62ae3..207099eb1d 100644 Binary files a/src/runtime/race/race_darwin_arm64.syso and b/src/runtime/race/race_darwin_arm64.syso differ -- cgit v1.2.3-54-g00ecf From 169be8e5b123007a02adf3f742b2a200bd8f9e67 Mon Sep 17 00:00:00 2001 From: Michael Anthony Knyszek Date: Mon, 23 Aug 2021 17:27:40 +0000 Subject: [release-branch.go1.16] runtime: set iOS addr space to 40 bits with incremental pagealloc In iOS <14, the address space is strictly limited to 8 GiB, or 33 bits. As a result, the page allocator also assumes all heap memory lives in this region. This is especially necessary because the page allocator has a PROT_NONE mapping proportional to the size of the usable address space, so this keeps that mapping very small. However starting with iOS 14, this restriction is relaxed, and mmap may start returning addresses outside of the <14 range. Today this means that in iOS 14 and later, users experience an error in the page allocator when a heap arena is mapped outside of the old range. This change increases the ios/arm64 heapAddrBits to 40 while simultaneously making ios/arm64 use the 64-bit pagealloc implementation (with reservations and incremental mapping) to accommodate both iOS versions <14 and 14+. Once iOS <14 is deprecated, we can remove these exceptions and treat ios/arm64 like any other arm64 platform. This change also makes the BaseChunkIdx expression a little bit easier to read, while we're here. For #46860. Fixes #48115. Change-Id: I13865f799777739109585f14f1cc49d6d57e096b Reviewed-on: https://go-review.googlesource.com/c/go/+/344401 Trust: Michael Knyszek Run-TryBot: Michael Knyszek TryBot-Result: Gopher Robot Reviewed-by: Cherry Mui Reviewed-by: Austin Clements (cherry picked from commit af368da0b137116faba81ca249a8d964297e6e45) Reviewed-on: https://go-review.googlesource.com/c/go/+/369736 Run-TryBot: Dmitri Shuralyov --- src/runtime/export_test.go | 14 +++++++++++++- src/runtime/malloc.go | 20 +++++++++++++------- src/runtime/mgcscavenge_test.go | 5 ++++- src/runtime/mpagealloc_32bit.go | 8 +------- src/runtime/mpagealloc_64bit.go | 4 +--- src/runtime/mpagealloc_test.go | 9 +++++++-- src/runtime/mpagecache_test.go | 5 ++++- 7 files changed, 43 insertions(+), 22 deletions(-) diff --git a/src/runtime/export_test.go b/src/runtime/export_test.go index 22fef3134f..59f72ae709 100644 --- a/src/runtime/export_test.go +++ b/src/runtime/export_test.go @@ -1051,7 +1051,19 @@ func FreePageAlloc(pp *PageAlloc) { // // This should not be higher than 0x100*pallocChunkBytes to support // mips and mipsle, which only have 31-bit address spaces. -var BaseChunkIdx = ChunkIdx(chunkIndex(((0xc000*pageAlloc64Bit + 0x100*pageAlloc32Bit) * pallocChunkBytes) + arenaBaseOffset*sys.GoosAix)) +var BaseChunkIdx = func() ChunkIdx { + var prefix uintptr + if pageAlloc64Bit != 0 { + prefix = 0xc000 + } else { + prefix = 0x100 + } + baseAddr := prefix * pallocChunkBytes + if sys.GoosAix != 0 { + baseAddr += arenaBaseOffset + } + return ChunkIdx(chunkIndex(baseAddr)) +}() // PageBase returns an address given a chunk index and a page index // relative to that chunk. diff --git a/src/runtime/malloc.go b/src/runtime/malloc.go index f20ded5bf7..c57d8c617d 100644 --- a/src/runtime/malloc.go +++ b/src/runtime/malloc.go @@ -199,15 +199,21 @@ const ( // we further limit it to 31 bits. // // On ios/arm64, although 64-bit pointers are presumably - // available, pointers are truncated to 33 bits. Furthermore, - // only the top 4 GiB of the address space are actually available - // to the application, but we allow the whole 33 bits anyway for - // simplicity. - // TODO(mknyszek): Consider limiting it to 32 bits and using - // arenaBaseOffset to offset into the top 4 GiB. + // available, pointers are truncated to 33 bits in iOS <14. + // Furthermore, only the top 4 GiB of the address space are + // actually available to the application. In iOS >=14, more + // of the address space is available, and the OS can now + // provide addresses outside of those 33 bits. Pick 40 bits + // as a reasonable balance between address space usage by the + // page allocator, and flexibility for what mmap'd regions + // we'll accept for the heap. We can't just move to the full + // 48 bits because this uses too much address space for older + // iOS versions. + // TODO(mknyszek): Once iOS <14 is deprecated, promote ios/arm64 + // to a 48-bit address space like every other arm64 platform. // // WebAssembly currently has a limit of 4GB linear memory. - heapAddrBits = (_64bit*(1-sys.GoarchWasm)*(1-sys.GoosIos*sys.GoarchArm64))*48 + (1-_64bit+sys.GoarchWasm)*(32-(sys.GoarchMips+sys.GoarchMipsle)) + 33*sys.GoosIos*sys.GoarchArm64 + heapAddrBits = (_64bit*(1-sys.GoarchWasm)*(1-sys.GoosIos*sys.GoarchArm64))*48 + (1-_64bit+sys.GoarchWasm)*(32-(sys.GoarchMips+sys.GoarchMipsle)) + 40*sys.GoosIos*sys.GoarchArm64 // maxAlloc is the maximum size of an allocation. On 64-bit, // it's theoretically possible to allocate 1< Date: Tue, 21 Dec 2021 10:00:23 -0800 Subject: [release-branch.go1.16] cmd/link: use SHT_INIT_ARRAY for .init_array section For #50295 Fixes #50296 Change-Id: If55ebcd5f2af724da7c9c744458a56d21a7ddde7 Reviewed-on: https://go-review.googlesource.com/c/go/+/373734 Trust: Ian Lance Taylor Reviewed-by: Cherry Mui (cherry picked from commit cfb0cc355233d4367b188b23a3bc143985a28b8c) Reviewed-on: https://go-review.googlesource.com/c/go/+/374234 Run-TryBot: Ian Lance Taylor TryBot-Result: Gopher Robot Reviewed-by: Austin Clements --- misc/cgo/testcarchive/carchive_test.go | 177 +++++++++++++++++++++++++++++++++ src/cmd/link/internal/ld/elf.go | 7 +- 2 files changed, 183 insertions(+), 1 deletion(-) diff --git a/misc/cgo/testcarchive/carchive_test.go b/misc/cgo/testcarchive/carchive_test.go index 6a5adf79ca..e81eefafdf 100644 --- a/misc/cgo/testcarchive/carchive_test.go +++ b/misc/cgo/testcarchive/carchive_test.go @@ -10,6 +10,7 @@ import ( "debug/elf" "flag" "fmt" + "io" "io/ioutil" "log" "os" @@ -17,6 +18,7 @@ import ( "path/filepath" "regexp" "runtime" + "strconv" "strings" "syscall" "testing" @@ -264,6 +266,173 @@ func checkLineComments(t *testing.T, hdrname string) { } } +// checkArchive verifies that the created library looks OK. +// We just check a couple of things now, we can add more checks as needed. +func checkArchive(t *testing.T, arname string) { + t.Helper() + + switch GOOS { + case "aix", "darwin", "ios", "windows": + // We don't have any checks for non-ELF libraries yet. + if _, err := os.Stat(arname); err != nil { + t.Errorf("archive %s does not exist: %v", arname, err) + } + default: + checkELFArchive(t, arname) + } +} + +// checkELFArchive checks an ELF archive. +func checkELFArchive(t *testing.T, arname string) { + t.Helper() + + f, err := os.Open(arname) + if err != nil { + t.Errorf("archive %s does not exist: %v", arname, err) + return + } + defer f.Close() + + // TODO(iant): put these in a shared package? But where? + const ( + magic = "!\n" + fmag = "`\n" + + namelen = 16 + datelen = 12 + uidlen = 6 + gidlen = 6 + modelen = 8 + sizelen = 10 + fmaglen = 2 + hdrlen = namelen + datelen + uidlen + gidlen + modelen + sizelen + fmaglen + ) + + type arhdr struct { + name string + date string + uid string + gid string + mode string + size string + fmag string + } + + var magbuf [len(magic)]byte + if _, err := io.ReadFull(f, magbuf[:]); err != nil { + t.Errorf("%s: archive too short", arname) + return + } + if string(magbuf[:]) != magic { + t.Errorf("%s: incorrect archive magic string %q", arname, magbuf) + } + + off := int64(len(magic)) + for { + if off&1 != 0 { + var b [1]byte + if _, err := f.Read(b[:]); err != nil { + if err == io.EOF { + break + } + t.Errorf("%s: error skipping alignment byte at %d: %v", arname, off, err) + } + off++ + } + + var hdrbuf [hdrlen]byte + if _, err := io.ReadFull(f, hdrbuf[:]); err != nil { + if err == io.EOF { + break + } + t.Errorf("%s: error reading archive header at %d: %v", arname, off, err) + return + } + + var hdr arhdr + hdrslice := hdrbuf[:] + set := func(len int, ps *string) { + *ps = string(bytes.TrimSpace(hdrslice[:len])) + hdrslice = hdrslice[len:] + } + set(namelen, &hdr.name) + set(datelen, &hdr.date) + set(uidlen, &hdr.uid) + set(gidlen, &hdr.gid) + set(modelen, &hdr.mode) + set(sizelen, &hdr.size) + hdr.fmag = string(hdrslice[:fmaglen]) + hdrslice = hdrslice[fmaglen:] + if len(hdrslice) != 0 { + t.Fatalf("internal error: len(hdrslice) == %d", len(hdrslice)) + } + + if hdr.fmag != fmag { + t.Errorf("%s: invalid fmagic value %q at %d", arname, hdr.fmag, off) + return + } + + size, err := strconv.ParseInt(hdr.size, 10, 64) + if err != nil { + t.Errorf("%s: error parsing size %q at %d: %v", arname, hdr.size, off, err) + return + } + + off += hdrlen + + switch hdr.name { + case "__.SYMDEF", "/", "/SYM64/": + // The archive symbol map. + case "//", "ARFILENAMES/": + // The extended name table. + default: + // This should be an ELF object. + checkELFArchiveObject(t, arname, off, io.NewSectionReader(f, off, size)) + } + + off += size + if _, err := f.Seek(off, os.SEEK_SET); err != nil { + t.Errorf("%s: failed to seek to %d: %v", arname, off, err) + } + } +} + +// checkELFArchiveObject checks an object in an ELF archive. +func checkELFArchiveObject(t *testing.T, arname string, off int64, obj io.ReaderAt) { + t.Helper() + + ef, err := elf.NewFile(obj) + if err != nil { + t.Errorf("%s: failed to open ELF file at %d: %v", arname, off, err) + return + } + defer ef.Close() + + // Verify section types. + for _, sec := range ef.Sections { + want := elf.SHT_NULL + switch sec.Name { + case ".text", ".data": + want = elf.SHT_PROGBITS + case ".bss": + want = elf.SHT_NOBITS + case ".symtab": + want = elf.SHT_SYMTAB + case ".strtab": + want = elf.SHT_STRTAB + case ".init_array": + want = elf.SHT_INIT_ARRAY + case ".fini_array": + want = elf.SHT_FINI_ARRAY + case ".preinit_array": + want = elf.SHT_PREINIT_ARRAY + } + if want != elf.SHT_NULL && sec.Type != want { + t.Errorf("%s: incorrect section type in elf file at %d for section %q: got %v want %v", arname, off, sec.Name, sec.Type, want) + } + } +} + func TestInstall(t *testing.T) { if !testWork { defer os.RemoveAll(filepath.Join(GOPATH, "pkg")) @@ -322,6 +491,7 @@ func TestEarlySignalHandler(t *testing.T) { t.Fatal(err) } checkLineComments(t, "libgo2.h") + checkArchive(t, "libgo2.a") ccArgs := append(cc, "-o", "testp"+exeSuffix, "main2.c", "libgo2.a") if runtime.Compiler == "gccgo" { @@ -362,6 +532,7 @@ func TestSignalForwarding(t *testing.T) { t.Fatal(err) } checkLineComments(t, "libgo2.h") + checkArchive(t, "libgo2.a") ccArgs := append(cc, "-o", "testp"+exeSuffix, "main5.c", "libgo2.a") if runtime.Compiler == "gccgo" { @@ -412,6 +583,7 @@ func TestSignalForwardingExternal(t *testing.T) { t.Fatal(err) } checkLineComments(t, "libgo2.h") + checkArchive(t, "libgo2.a") ccArgs := append(cc, "-o", "testp"+exeSuffix, "main5.c", "libgo2.a") if runtime.Compiler == "gccgo" { @@ -529,6 +701,7 @@ func TestOsSignal(t *testing.T) { t.Fatal(err) } checkLineComments(t, "libgo3.h") + checkArchive(t, "libgo3.a") ccArgs := append(cc, "-o", "testp"+exeSuffix, "main3.c", "libgo3.a") if runtime.Compiler == "gccgo" { @@ -566,6 +739,7 @@ func TestSigaltstack(t *testing.T) { t.Fatal(err) } checkLineComments(t, "libgo4.h") + checkArchive(t, "libgo4.a") ccArgs := append(cc, "-o", "testp"+exeSuffix, "main4.c", "libgo4.a") if runtime.Compiler == "gccgo" { @@ -753,6 +927,7 @@ func TestSIGPROF(t *testing.T) { t.Fatal(err) } checkLineComments(t, "libgo6.h") + checkArchive(t, "libgo6.a") ccArgs := append(cc, "-o", "testp6"+exeSuffix, "main6.c", "libgo6.a") if runtime.Compiler == "gccgo" { @@ -796,6 +971,7 @@ func TestCompileWithoutShared(t *testing.T) { t.Fatal(err) } checkLineComments(t, "libgo2.h") + checkArchive(t, "libgo2.a") exe := "./testnoshared" + exeSuffix @@ -900,6 +1076,7 @@ func TestManyCalls(t *testing.T) { t.Fatal(err) } checkLineComments(t, "libgo7.h") + checkArchive(t, "libgo7.a") ccArgs := append(cc, "-o", "testp7"+exeSuffix, "main7.c", "libgo7.a") if runtime.Compiler == "gccgo" { diff --git a/src/cmd/link/internal/ld/elf.go b/src/cmd/link/internal/ld/elf.go index f5823a8fbf..0f2ef0df43 100644 --- a/src/cmd/link/internal/ld/elf.go +++ b/src/cmd/link/internal/ld/elf.go @@ -993,7 +993,12 @@ func elfshbits(linkmode LinkMode, sect *sym.Section) *ElfShdr { } if sect.Vaddr < sect.Seg.Vaddr+sect.Seg.Filelen { - sh.Type = uint32(elf.SHT_PROGBITS) + switch sect.Name { + case ".init_array": + sh.Type = uint32(elf.SHT_INIT_ARRAY) + default: + sh.Type = uint32(elf.SHT_PROGBITS) + } } else { sh.Type = uint32(elf.SHT_NOBITS) } -- cgit v1.2.3-54-g00ecf From 0551247ca30c574aec0252c27476e218002f6bbc Mon Sep 17 00:00:00 2001 From: Carlos Amedee Date: Wed, 5 Jan 2022 21:08:15 -0500 Subject: [release-branch.go1.16] net/http: update bundled golang.org/x/net/http2 Pull in approved backports to golang.org/x/net/http2: aa5a62b http2: prioritize RST_STREAM frames in random write scheduler By doing: $ go get -d golang.org/x/net@internal-branch.go1.16-vendor $ go mod tidy $ go mod vendor $ go generate -run=bundle std Fixes #50449 Change-Id: I4a6a8ae943d2d1705209e648a63421914062d3e4 Reviewed-on: https://go-review.googlesource.com/c/go/+/375815 Reviewed-by: Dmitri Shuralyov Run-TryBot: Carlos Amedee TryBot-Result: Gopher Robot Trust: Carlos Amedee --- src/go.mod | 2 +- src/go.sum | 4 ++-- src/net/http/h2_bundle.go | 10 ++++++---- src/vendor/modules.txt | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/go.mod b/src/go.mod index 977370d265..940ad6dda6 100644 --- a/src/go.mod +++ b/src/go.mod @@ -4,7 +4,7 @@ go 1.16 require ( golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897 - golang.org/x/net v0.0.0-20211209100217-a5309b321dca + golang.org/x/net v0.0.0-20220106012026-aa5a62bac9b2 golang.org/x/sys v0.0.0-20201204225414-ed752295db88 // indirect golang.org/x/text v0.3.4 // indirect ) diff --git a/src/go.sum b/src/go.sum index 1032a50518..fc62a8954a 100644 --- a/src/go.sum +++ b/src/go.sum @@ -2,8 +2,8 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897 h1:pLI5jrR7OSLijeIDcmRxNmw2api+jEfxLoykJVice/E= golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20211209100217-a5309b321dca h1:UmeWAm8AwB6NA/e4FSaGlK1EKTLXKX3utx4Si+6kfPg= -golang.org/x/net v0.0.0-20211209100217-a5309b321dca/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20220106012026-aa5a62bac9b2 h1:stMOlKq3irM+8bKr23owjlOdTCooe6glD9WAQcwXgxw= +golang.org/x/net v0.0.0-20220106012026-aa5a62bac9b2/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/src/net/http/h2_bundle.go b/src/net/http/h2_bundle.go index 6a0c1acf5f..00a4bcc8cb 100644 --- a/src/net/http/h2_bundle.go +++ b/src/net/http/h2_bundle.go @@ -9896,7 +9896,8 @@ type http2WriteScheduler interface { // Pop dequeues the next frame to write. Returns false if no frames can // be written. Frames with a given wr.StreamID() are Pop'd in the same - // order they are Push'd. No frames should be discarded except by CloseStream. + // order they are Push'd, except RST_STREAM frames. No frames should be + // discarded except by CloseStream. Pop() (wr http2FrameWriteRequest, ok bool) } @@ -9916,6 +9917,7 @@ type http2FrameWriteRequest struct { // stream is the stream on which this frame will be written. // nil for non-stream frames like PING and SETTINGS. + // nil for RST_STREAM streams, which use the StreamError.StreamID field instead. stream *http2stream // done, if non-nil, must be a buffered channel with space for @@ -10595,11 +10597,11 @@ func (ws *http2randomWriteScheduler) AdjustStream(streamID uint32, priority http } func (ws *http2randomWriteScheduler) Push(wr http2FrameWriteRequest) { - id := wr.StreamID() - if id == 0 { + if wr.isControl() { ws.zero.push(wr) return } + id := wr.StreamID() q, ok := ws.sq[id] if !ok { q = ws.queuePool.get() @@ -10609,7 +10611,7 @@ func (ws *http2randomWriteScheduler) Push(wr http2FrameWriteRequest) { } func (ws *http2randomWriteScheduler) Pop() (http2FrameWriteRequest, bool) { - // Control frames first. + // Control and RST_STREAM frames first. if !ws.zero.empty() { return ws.zero.shift(), true } diff --git a/src/vendor/modules.txt b/src/vendor/modules.txt index a37d539508..9a72c2320e 100644 --- a/src/vendor/modules.txt +++ b/src/vendor/modules.txt @@ -8,7 +8,7 @@ golang.org/x/crypto/curve25519 golang.org/x/crypto/hkdf golang.org/x/crypto/internal/subtle golang.org/x/crypto/poly1305 -# golang.org/x/net v0.0.0-20211209100217-a5309b321dca +# golang.org/x/net v0.0.0-20220106012026-aa5a62bac9b2 ## explicit golang.org/x/net/dns/dnsmessage golang.org/x/net/http/httpguts -- cgit v1.2.3-54-g00ecf From 378766af9ed0f2e28d67c2b50e73db7573656669 Mon Sep 17 00:00:00 2001 From: Carlos Amedee Date: Thu, 6 Jan 2022 13:17:16 -0500 Subject: [release-branch.go1.16] go1.16.13 Change-Id: I267f3a5923e7154c72d18d76ecab1a9b1a0ec472 Reviewed-on: https://go-review.googlesource.com/c/go/+/375976 Trust: Carlos Amedee Run-TryBot: Carlos Amedee TryBot-Result: Gopher Robot Reviewed-by: Than McIntosh --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index ea4f57eb63..86ad8f862a 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -go1.16.12 \ No newline at end of file +go1.16.13 \ No newline at end of file -- cgit v1.2.3-54-g00ecf