From 7dc5d909fb465345bf1583eb978aaa56ca365f38 Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Tue, 24 Nov 2020 00:58:00 +0700 Subject: [PATCH 01/14] cmd/compile: set OpLoad argument type interface{} correctly CL 271906 allows loading single field of typed-interface{} OpIData, but it does not update the corresponding selector type. So the generated OpLoad has the named type instead, prevent it from being lowered by lower pass. Fixes #42784 Change-Id: Idf32e4f711731be09d508dd712b60bc8c58309bd Reviewed-on: https://go-review.googlesource.com/c/go/+/272466 Trust: Cuong Manh Le Run-TryBot: Cuong Manh Le TryBot-Result: Go Bot Reviewed-by: Cherry Zhang --- src/cmd/compile/internal/ssa/expand_calls.go | 3 +++ test/fixedbugs/issue42784.go | 26 ++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 test/fixedbugs/issue42784.go diff --git a/src/cmd/compile/internal/ssa/expand_calls.go b/src/cmd/compile/internal/ssa/expand_calls.go index 180afab33b1..f266e49327e 100644 --- a/src/cmd/compile/internal/ssa/expand_calls.go +++ b/src/cmd/compile/internal/ssa/expand_calls.go @@ -250,6 +250,9 @@ func expandCalls(f *Func) { if leafType != selector.Type && !selector.Type.IsEmptyInterface() { // empty interface for #42727 f.Fatalf("Unexpected Load as selector, leaf=%s, selector=%s\n", leaf.LongString(), selector.LongString()) } + if selector.Type.IsEmptyInterface() { + selector.Type = typ.BytePtr + } leaf.copyOf(selector) for _, s := range namedSelects[selector] { locs = append(locs, f.Names[s.locIndex]) diff --git a/test/fixedbugs/issue42784.go b/test/fixedbugs/issue42784.go new file mode 100644 index 00000000000..e2b06e9307f --- /dev/null +++ b/test/fixedbugs/issue42784.go @@ -0,0 +1,26 @@ +// compile + +// 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. + +// Ensure that late expansion correctly set OpLoad argument type interface{} + +package p + +type iface interface { + m() +} + +type it interface{} + +type makeIface func() iface + +func f() { + var im makeIface + e := im().(it) + g(e) +} + +//go:noinline +func g(i it) {} From 6965b01ea248cabb70c3749fd218b36089a21efb Mon Sep 17 00:00:00 2001 From: Alex Brainman Date: Sat, 21 Nov 2020 14:56:26 +1100 Subject: [PATCH 02/14] runtime: allow for usleep2HighRes to run without TLS setup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change adjusts usleep2HighRes so it does not crash when TLS is not configured. When g is not available, usleep2HighRes just calls usleep2 instead. Updates #8687 Change-Id: Idbb80f7b71d1da350a6a7df7c49154eb1ffe29a8 Reviewed-on: https://go-review.googlesource.com/c/go/+/271907 Run-TryBot: Alex Brainman TryBot-Result: Go Bot Reviewed-by: Jason A. Donenfeld Reviewed-by: Simon Rozman Trust: Jason A. Donenfeld Trust: Alex Brainman --- src/runtime/sys_windows_386.s | 11 ++++++++++- src/runtime/sys_windows_amd64.s | 11 ++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/runtime/sys_windows_386.s b/src/runtime/sys_windows_386.s index 2e5e82879c8..ef8a3dd3c27 100644 --- a/src/runtime/sys_windows_386.s +++ b/src/runtime/sys_windows_386.s @@ -415,12 +415,15 @@ TEXT runtime·usleep2(SB),NOSPLIT,$20 // Runs on OS stack. duration (in 100ns units) is in BX. TEXT runtime·usleep2HighRes(SB),NOSPLIT,$36 + get_tls(CX) + CMPL CX, $0 + JE gisnotset + // Want negative 100ns units. NEGL BX MOVL $-1, hi-4(SP) MOVL BX, lo-8(SP) - get_tls(CX) MOVL g(CX), CX MOVL g_m(CX), CX MOVL (m_mOS+mOS_highResTimer)(CX), CX @@ -449,6 +452,12 @@ TEXT runtime·usleep2HighRes(SB),NOSPLIT,$36 RET +gisnotset: + // TLS is not configured. Call usleep2 instead. + MOVL $runtime·usleep2(SB), AX + CALL AX + RET + // Runs on OS stack. TEXT runtime·switchtothread(SB),NOSPLIT,$0 MOVL SP, BP diff --git a/src/runtime/sys_windows_amd64.s b/src/runtime/sys_windows_amd64.s index e9ec99a51d3..d1690cad587 100644 --- a/src/runtime/sys_windows_amd64.s +++ b/src/runtime/sys_windows_amd64.s @@ -454,11 +454,14 @@ TEXT runtime·usleep2(SB),NOSPLIT|NOFRAME,$48 // Runs on OS stack. duration (in 100ns units) is in BX. TEXT runtime·usleep2HighRes(SB),NOSPLIT|NOFRAME,$72 + get_tls(CX) + CMPQ CX, $0 + JE gisnotset + MOVQ SP, AX ANDQ $~15, SP // alignment as per Windows requirement MOVQ AX, 64(SP) - get_tls(CX) MOVQ g(CX), CX MOVQ g_m(CX), CX MOVQ (m_mOS+mOS_highResTimer)(CX), CX // hTimer @@ -484,6 +487,12 @@ TEXT runtime·usleep2HighRes(SB),NOSPLIT|NOFRAME,$72 MOVQ 64(SP), SP RET +gisnotset: + // TLS is not configured. Call usleep2 instead. + MOVQ $runtime·usleep2(SB), AX + CALL AX + RET + // Runs on OS stack. TEXT runtime·switchtothread(SB),NOSPLIT|NOFRAME,$0 MOVQ SP, AX From 65dcd15c720585958908668fb17c47bc620a9923 Mon Sep 17 00:00:00 2001 From: Dmitri Shuralyov Date: Tue, 24 Nov 2020 13:23:10 -0500 Subject: [PATCH 03/14] doc/go1.16: fill in Go 1.16 release note TODOs using relnote The additions were generated using golang.org/x/build/cmd/relnote at CL 272907. It was modified to find previously-missed entries by querying the Gerrit API in addition to the maintner corpus. For #40700. Updates #41849. Change-Id: If575984fe40e0133ad5e8fc5411ea5063457250d Reviewed-on: https://go-review.googlesource.com/c/go/+/272871 Trust: Dmitri Shuralyov Reviewed-by: Carlos Amedee --- doc/go1.16.html | 191 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 188 insertions(+), 3 deletions(-) diff --git a/doc/go1.16.html b/doc/go1.16.html index 92cadff7138..2e26d659bab 100644 --- a/doc/go1.16.html +++ b/doc/go1.16.html @@ -33,7 +33,7 @@ Do not send CLs removing the interior tags from such phrases.

Darwin

-

+

Go 1.16 adds support of 64-bit ARM architecture on macOS (also known as Apple Silicon) with GOOS=darwin, GOARCH=arm64. Like the darwin/amd64 port, the darwin/arm64 @@ -42,7 +42,7 @@ Do not send CLs removing the interior tags from such phrases. detector.

-

+

The iOS port, which was previously darwin/arm64, is now moved to ios/arm64. GOOS=ios implies the darwin build tag, just as GOOS=android @@ -80,6 +80,15 @@ Do not send CLs removing the interior tags from such phrases.

Go command

+

+ TODO + + + + + +

+

Modules

@@ -215,8 +224,12 @@ Do not send CLs removing the interior tags from such phrases. results that were silently incorrect.

+

Vet

+

TODO + +

Runtime

@@ -245,7 +258,7 @@ Do not send CLs removing the interior tags from such phrases.

Linker

-

+

This release includes additional improvements to the Go linker, reducing linker resource usage (both time and memory) and improving code robustness/maintainability. These changes form the second half @@ -428,6 +441,14 @@ Do not send CLs removing the interior tags from such phrases. +

crypto/tls
+
+

+ TODO: https://golang.org/cl/246637: make config.Clone return nil if the source is nil +

+
+
+
crypto/x509

@@ -435,9 +456,25 @@ Do not send CLs removing the interior tags from such phrases. generation was never supported. See issue #40337.

+ +

+ TODO: https://golang.org/cl/257257: return additional chains from Verify on Windows +

+ +

+ TODO: https://golang.org/cl/262343: add Unwrap to SystemRootsError +

+
encoding/json
+
+

+ TODO: https://golang.org/cl/234818: allow semicolon in field key / struct tag +

+
+
+
encoding/xml

@@ -452,6 +489,54 @@ Do not send CLs removing the interior tags from such phrases.

+
flag
+
+

+ TODO: https://golang.org/cl/240014: add Func +

+
+
+ +
io
+
+

+ TODO: https://golang.org/cl/261577: add a new ReadSeekCloser interface +

+
+
+ +
log
+
+

+ TODO: https://golang.org/cl/264460: expose std via new Default function +

+
+
+ +
log/syslog
+
+

+ TODO: https://golang.org/cl/264297: set local to true if network is any of "unix", or "unixgram" +

+
+
+ +
mime/multipart
+
+

+ TODO: https://golang.org/cl/247477: return overflow errors in Reader.ReadForm +

+
+
+ +
net
+
+

+ TODO: https://golang.org/cl/238629: prefer /etc/hosts over DNS when no /etc/nsswitch.conf is present +

+
+
+
net/http

@@ -485,9 +570,89 @@ Do not send CLs removing the interior tags from such phrases. with the Request context when performing TLS handshakes in the client or server.

+ +

+ TODO: https://golang.org/cl/250039: set Content-Length:0 for empty PATCH requests as with POST, PATCH +

+ +

+ TODO: https://golang.org/cl/249440: match http scheme when selecting http_proxy +

+
net/http/httputil
+
+

+ TODO: https://golang.org/cl/260637: flush ReverseProxy immediately if Content-Length is -1 +

+
+
+ +
net/smtp
+
+

+ TODO: https://golang.org/cl/247257: adds support for the SMTPUTF8 extension +

+
+
+ +
os
+
+

+ TODO: https://golang.org/cl/242998: export errFinished as ErrProcessDone +

+
+
+ +
os/signal
+
+

+ TODO: https://golang.org/cl/219640: add NotifyContext to cancel context using system signals +

+
+
+ +
path
+
+

+ TODO: https://golang.org/cl/264397: validate patterns in Match, Glob +

+
+
+ +
path/filepath
+
+

+ TODO: https://golang.org/cl/264397: validate patterns in Match, Glob +

+
+
+ +
reflect
+
+

+ TODO: https://golang.org/cl/248341: support multiple keys in struct tags +

+
+
+ +
runtime
+
+

+ TODO: https://golang.org/cl/37222: make stack traces of endless recursion print only top and bottom 50 +

+ +

+ TODO: https://golang.org/cl/242258: add 24 byte allocation size class +

+ +

+ TODO: https://golang.org/cl/254659: implement GODEBUG=inittrace=1 support +

+
+
+
runtime/debug

@@ -505,6 +670,10 @@ Do not send CLs removing the interior tags from such phrases.

DLLError on Windows now has an Unwrap function for unwrapping its underlying error.

+ +

+ TODO: https://golang.org/cl/210639: support POSIX semantics for Linux syscalls +

@@ -520,3 +689,19 @@ Do not send CLs removing the interior tags from such phrases.

+ +
text/template
+
+

+ TODO: https://golang.org/cl/254257: allow newlines inside action delimiters +

+
+
+ +
time/tzdata
+
+

+ TODO: https://golang.org/cl/261877: use slim tz data format +

+
+
From ba2adc21e8c416c47dec5fbce76286758f15b177 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Fri, 20 Nov 2020 17:09:23 -0500 Subject: [PATCH 04/14] runtime/testdata/testprogcgo: refactor CrashTraceback This moves the C part of the CrashTraceback test into its own file in preparation for adding a test that transitions back into Go. Change-Id: I9560dcfd80bf8a1d30809fd360f958f5261ebb01 Reviewed-on: https://go-review.googlesource.com/c/go/+/272130 Trust: Austin Clements Run-TryBot: Austin Clements TryBot-Result: Go Bot Reviewed-by: Ian Lance Taylor Reviewed-by: Cherry Zhang --- src/runtime/testdata/testprogcgo/traceback.go | 58 ++----------------- .../testdata/testprogcgo/traceback_c.c | 58 +++++++++++++++++++ 2 files changed, 63 insertions(+), 53 deletions(-) create mode 100644 src/runtime/testdata/testprogcgo/traceback_c.c diff --git a/src/runtime/testdata/testprogcgo/traceback.go b/src/runtime/testdata/testprogcgo/traceback.go index 2a023f66cae..03de894c893 100644 --- a/src/runtime/testdata/testprogcgo/traceback.go +++ b/src/runtime/testdata/testprogcgo/traceback.go @@ -11,58 +11,10 @@ package main /* #cgo CFLAGS: -g -O0 -#include - -char *p; - -static int f3(void) { - *p = 0; - return 0; -} - -static int f2(void) { - return f3(); -} - -static int f1(void) { - return f2(); -} - -struct cgoTracebackArg { - uintptr_t context; - uintptr_t sigContext; - uintptr_t* buf; - uintptr_t max; -}; - -struct cgoSymbolizerArg { - uintptr_t pc; - const char* file; - uintptr_t lineno; - const char* func; - uintptr_t entry; - uintptr_t more; - uintptr_t data; -}; - -void cgoTraceback(void* parg) { - struct cgoTracebackArg* arg = (struct cgoTracebackArg*)(parg); - arg->buf[0] = 1; - arg->buf[1] = 2; - arg->buf[2] = 3; - arg->buf[3] = 0; -} - -void cgoSymbolizer(void* parg) { - struct cgoSymbolizerArg* arg = (struct cgoSymbolizerArg*)(parg); - if (arg->pc != arg->data + 1) { - arg->file = "unexpected data"; - } else { - arg->file = "cgo symbolizer"; - } - arg->lineno = arg->data + 1; - arg->data++; -} +// Defined in traceback_c.c. +int tracebackF1(void); +void cgoTraceback(void* parg); +void cgoSymbolizer(void* parg); */ import "C" @@ -77,5 +29,5 @@ func init() { func CrashTraceback() { runtime.SetCgoTraceback(0, unsafe.Pointer(C.cgoTraceback), nil, unsafe.Pointer(C.cgoSymbolizer)) - C.f1() + C.tracebackF1() } diff --git a/src/runtime/testdata/testprogcgo/traceback_c.c b/src/runtime/testdata/testprogcgo/traceback_c.c new file mode 100644 index 00000000000..54f44e11fc9 --- /dev/null +++ b/src/runtime/testdata/testprogcgo/traceback_c.c @@ -0,0 +1,58 @@ +// 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. + +// The C definitions for traceback.go. + +#include + +char *p; + +int tracebackF3(void) { + *p = 0; + return 0; +} + +int tracebackF2(void) { + return tracebackF3(); +} + +int tracebackF1(void) { + return tracebackF2(); +} + +struct cgoTracebackArg { + uintptr_t context; + uintptr_t sigContext; + uintptr_t* buf; + uintptr_t max; +}; + +struct cgoSymbolizerArg { + uintptr_t pc; + const char* file; + uintptr_t lineno; + const char* func; + uintptr_t entry; + uintptr_t more; + uintptr_t data; +}; + +void cgoTraceback(void* parg) { + struct cgoTracebackArg* arg = (struct cgoTracebackArg*)(parg); + arg->buf[0] = 1; + arg->buf[1] = 2; + arg->buf[2] = 3; + arg->buf[3] = 0; +} + +void cgoSymbolizer(void* parg) { + struct cgoSymbolizerArg* arg = (struct cgoSymbolizerArg*)(parg); + if (arg->pc != arg->data + 1) { + arg->file = "unexpected data"; + } else { + arg->file = "cgo symbolizer"; + } + arg->lineno = arg->data + 1; + arg->data++; +} From e8de596f04d0ea7fb6fb68b036760bf088a9c6c2 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Fri, 20 Nov 2020 17:32:46 -0500 Subject: [PATCH 05/14] runtime: use inlined function name for traceback elision Currently, gentraceback decides which frames to print or elide when unwinding inlined frames using only the name of the outermost function. If the outermost function should be elided, then inlined functions will also be elided, even if they shouldn't be. This happens in practice in at least one situation. As of CL 258938, exported Go functions (and functions they call) can now be inlined into the generated _cgoexp_HASH_FN function. The runtime elides _cgoexp_HASH_FN from tracebacks because it doesn't contain a ".". Because of this bug, it also elides anything that was inlined into it. This CL fixes this by synthesizing a funcInfo for the inlined functions to pass to showframe. Fixes #42754. Change-Id: Ie6c663a4a1ac7f0d4beb1aa60bc26fc8cddd0f9d Reviewed-on: https://go-review.googlesource.com/c/go/+/272131 Trust: Austin Clements Run-TryBot: Austin Clements TryBot-Result: Go Bot Reviewed-by: Cherry Zhang --- src/runtime/crash_cgo_test.go | 18 ++++++++ src/runtime/stack_test.go | 41 +++++++++++++++++++ src/runtime/testdata/testprogcgo/traceback.go | 21 ++++++++++ .../testdata/testprogcgo/traceback_c.c | 11 ++++- src/runtime/traceback.go | 15 ++++++- 5 files changed, 102 insertions(+), 4 deletions(-) diff --git a/src/runtime/crash_cgo_test.go b/src/runtime/crash_cgo_test.go index 0680d07a326..140c170ddc1 100644 --- a/src/runtime/crash_cgo_test.go +++ b/src/runtime/crash_cgo_test.go @@ -254,6 +254,24 @@ func TestCgoCrashTraceback(t *testing.T) { } } +func TestCgoCrashTracebackGo(t *testing.T) { + t.Parallel() + switch platform := runtime.GOOS + "/" + runtime.GOARCH; platform { + case "darwin/amd64": + case "linux/amd64": + case "linux/ppc64le": + default: + t.Skipf("not yet supported on %s", platform) + } + got := runTestProg(t, "testprogcgo", "CrashTracebackGo") + for i := 1; i <= 3; i++ { + want := fmt.Sprintf("main.h%d", i) + if !strings.Contains(got, want) { + t.Errorf("missing %s", want) + } + } +} + func TestCgoTracebackContext(t *testing.T) { t.Parallel() got := runTestProg(t, "testprogcgo", "TracebackContext") diff --git a/src/runtime/stack_test.go b/src/runtime/stack_test.go index adfc65384ab..43fc5cac55f 100644 --- a/src/runtime/stack_test.go +++ b/src/runtime/stack_test.go @@ -17,6 +17,7 @@ import ( "sync/atomic" "testing" "time" + _ "unsafe" // for go:linkname ) // TestStackMem measures per-thread stack segment cache behavior. @@ -851,3 +852,43 @@ func deferHeapAndStack(n int) (r int) { // Pass a value to escapeMe to force it to escape. var escapeMe = func(x interface{}) {} + +// Test that when F -> G is inlined and F is excluded from stack +// traces, G still appears. +func TestTracebackInlineExcluded(t *testing.T) { + defer func() { + recover() + buf := make([]byte, 4<<10) + stk := string(buf[:Stack(buf, false)]) + + t.Log(stk) + + if not := "tracebackExcluded"; strings.Contains(stk, not) { + t.Errorf("found but did not expect %q", not) + } + if want := "tracebackNotExcluded"; !strings.Contains(stk, want) { + t.Errorf("expected %q in stack", want) + } + }() + tracebackExcluded() +} + +// tracebackExcluded should be excluded from tracebacks. There are +// various ways this could come up. Linking it to a "runtime." name is +// rather synthetic, but it's easy and reliable. See issue #42754 for +// one way this happened in real code. +// +//go:linkname tracebackExcluded runtime.tracebackExcluded +//go:noinline +func tracebackExcluded() { + // Call an inlined function that should not itself be excluded + // from tracebacks. + tracebackNotExcluded() +} + +// tracebackNotExcluded should be inlined into tracebackExcluded, but +// should not itself be excluded from the traceback. +func tracebackNotExcluded() { + var x *int + *x = 0 +} diff --git a/src/runtime/testdata/testprogcgo/traceback.go b/src/runtime/testdata/testprogcgo/traceback.go index 03de894c893..e2d7599131f 100644 --- a/src/runtime/testdata/testprogcgo/traceback.go +++ b/src/runtime/testdata/testprogcgo/traceback.go @@ -12,6 +12,7 @@ package main #cgo CFLAGS: -g -O0 // Defined in traceback_c.c. +extern int crashInGo; int tracebackF1(void); void cgoTraceback(void* parg); void cgoSymbolizer(void* parg); @@ -25,9 +26,29 @@ import ( func init() { register("CrashTraceback", CrashTraceback) + register("CrashTracebackGo", CrashTracebackGo) } func CrashTraceback() { runtime.SetCgoTraceback(0, unsafe.Pointer(C.cgoTraceback), nil, unsafe.Pointer(C.cgoSymbolizer)) C.tracebackF1() } + +func CrashTracebackGo() { + C.crashInGo = 1 + CrashTraceback() +} + +//export h1 +func h1() { + h2() +} + +func h2() { + h3() +} + +func h3() { + var x *int + *x = 0 +} diff --git a/src/runtime/testdata/testprogcgo/traceback_c.c b/src/runtime/testdata/testprogcgo/traceback_c.c index 54f44e11fc9..56eda8fa8ca 100644 --- a/src/runtime/testdata/testprogcgo/traceback_c.c +++ b/src/runtime/testdata/testprogcgo/traceback_c.c @@ -2,14 +2,21 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// The C definitions for traceback.go. +// The C definitions for traceback.go. That file uses //export so +// it can't put function definitions in the "C" import comment. #include char *p; +int crashInGo; +extern void h1(void); + int tracebackF3(void) { - *p = 0; + if (crashInGo) + h1(); + else + *p = 0; return 0; } diff --git a/src/runtime/traceback.go b/src/runtime/traceback.go index f3df152535a..0825e9e7076 100644 --- a/src/runtime/traceback.go +++ b/src/runtime/traceback.go @@ -396,13 +396,21 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in // If there is inlining info, print the inner frames. if inldata := funcdata(f, _FUNCDATA_InlTree); inldata != nil { inltree := (*[1 << 20]inlinedCall)(inldata) + var inlFunc _func + inlFuncInfo := funcInfo{&inlFunc, f.datap} for { ix := pcdatavalue(f, _PCDATA_InlTreeIndex, tracepc, nil) if ix < 0 { break } - if (flags&_TraceRuntimeFrames) != 0 || showframe(f, gp, nprint == 0, inltree[ix].funcID, lastFuncID) { - name := funcnameFromNameoff(f, inltree[ix].func_) + + // Create a fake _func for the + // inlined function. + inlFunc.nameoff = inltree[ix].func_ + inlFunc.funcID = inltree[ix].funcID + + if (flags&_TraceRuntimeFrames) != 0 || showframe(inlFuncInfo, gp, nprint == 0, inlFuncInfo.funcID, lastFuncID) { + name := funcname(inlFuncInfo) file, line := funcline(f, tracepc) print(name, "(...)\n") print("\t", file, ":", line, "\n") @@ -811,6 +819,9 @@ func showframe(f funcInfo, gp *g, firstFrame bool, funcID, childID funcID) bool // showfuncinfo reports whether a function with the given characteristics should // be printed during a traceback. func showfuncinfo(f funcInfo, firstFrame bool, funcID, childID funcID) bool { + // Note that f may be a synthesized funcInfo for an inlined + // function, in which case only nameoff and funcID are set. + level, _, _ := gotraceback() if level > 1 { // Show all frames. From f6dcc975f7207340ad11d9296c42e7730ecf1f9f Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Tue, 24 Nov 2020 17:26:22 -0800 Subject: [PATCH 06/14] go/constant: make constant.Make produce "smallest" const representation Fixes #42640. Change-Id: I22b8142b0a47a0f957d1bda28cdfdbb8388cffc4 Reviewed-on: https://go-review.googlesource.com/c/go/+/273086 Trust: Robert Griesemer Reviewed-by: Matthew Dempsky --- src/go/constant/value.go | 6 +++--- src/go/constant/value_test.go | 34 ++++++++++++++++++++++++---------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/go/constant/value.go b/src/go/constant/value.go index 116c7575d9e..4baae2eb327 100644 --- a/src/go/constant/value.go +++ b/src/go/constant/value.go @@ -594,11 +594,11 @@ func Make(x interface{}) Value { case int64: return int64Val(x) case *big.Int: - return intVal{x} + return makeInt(x) case *big.Rat: - return ratVal{x} + return makeRat(x) case *big.Float: - return floatVal{x} + return makeFloat(x) default: return unknownVal{} } diff --git a/src/go/constant/value_test.go b/src/go/constant/value_test.go index 1a5025cbbd4..5edc766fde8 100644 --- a/src/go/constant/value_test.go +++ b/src/go/constant/value_test.go @@ -620,18 +620,32 @@ func TestUnknown(t *testing.T) { } } +type makeTestCase struct { + kind Kind + arg, want interface{} +} + +func dup(k Kind, x interface{}) makeTestCase { return makeTestCase{k, x, x} } + func TestMake(t *testing.T) { - for _, want := range []interface{}{ - false, - "hello", - int64(1), - big.NewInt(10), - big.NewFloat(2.0), - big.NewRat(1, 3), + for _, test := range []makeTestCase{ + {Bool, false, false}, + {String, "hello", "hello"}, + + {Int, int64(1), int64(1)}, + {Int, big.NewInt(10), int64(10)}, + {Int, new(big.Int).Lsh(big.NewInt(1), 62), int64(1 << 62)}, + dup(Int, new(big.Int).Lsh(big.NewInt(1), 63)), + + {Float, big.NewFloat(0), floatVal0.val}, + dup(Float, big.NewFloat(2.0)), + dup(Float, big.NewRat(1, 3)), } { - got := Val(Make(want)) - if got != want { - t.Errorf("got %v; want %v", got, want) + val := Make(test.arg) + got := Val(val) + if val.Kind() != test.kind || got != test.want { + t.Errorf("got %v (%T, kind = %d); want %v (%T, kind = %d)", + got, got, val.Kind(), test.want, test.want, test.kind) } } } From 1308f118974fab4bd08d04a6a982db6dde6f9e52 Mon Sep 17 00:00:00 2001 From: eric fang Date: Wed, 18 Nov 2020 04:00:57 +0000 Subject: [PATCH 07/14] cmd/link: add relocation type R_AARCH64_LDST16_ABS_LO12_NC for arm64 The linker already has R_AARCH64_LDST{8,32,64,128}_ABS_LO12_NC, some cgo tests require R_AARCH64_LDST16_ABS_LO12_NC, this CL adds this relocation type. Fixes #42660 Change-Id: I9a5120cd872f5095c61175cb602427c6ab3225cc Reviewed-on: https://go-review.googlesource.com/c/go/+/271017 Reviewed-by: eric fang Reviewed-by: Cherry Zhang Run-TryBot: eric fang TryBot-Result: Go Bot Trust: eric fang Trust: Benny Siegert --- src/cmd/internal/objabi/reloctype.go | 3 ++ src/cmd/internal/objabi/reloctype_string.go | 47 +++++++++++---------- src/cmd/link/internal/arm64/asm.go | 16 +++++++ src/cmd/link/internal/loadelf/ldelf.go | 1 + 4 files changed, 44 insertions(+), 23 deletions(-) diff --git a/src/cmd/internal/objabi/reloctype.go b/src/cmd/internal/objabi/reloctype.go index 938954e07a3..649f6901944 100644 --- a/src/cmd/internal/objabi/reloctype.go +++ b/src/cmd/internal/objabi/reloctype.go @@ -156,6 +156,9 @@ const ( // R_ARM64_LDST8 sets a LD/ST immediate value to bits [11:0] of a local address. R_ARM64_LDST8 + // R_ARM64_LDST16 sets a LD/ST immediate value to bits [11:1] of a local address. + R_ARM64_LDST16 + // R_ARM64_LDST32 sets a LD/ST immediate value to bits [11:2] of a local address. R_ARM64_LDST32 diff --git a/src/cmd/internal/objabi/reloctype_string.go b/src/cmd/internal/objabi/reloctype_string.go index 693d9631f57..658a44f8b81 100644 --- a/src/cmd/internal/objabi/reloctype_string.go +++ b/src/cmd/internal/objabi/reloctype_string.go @@ -46,32 +46,33 @@ func _() { _ = x[R_ARM64_GOT-36] _ = x[R_ARM64_PCREL-37] _ = x[R_ARM64_LDST8-38] - _ = x[R_ARM64_LDST32-39] - _ = x[R_ARM64_LDST64-40] - _ = x[R_ARM64_LDST128-41] - _ = x[R_POWER_TLS_LE-42] - _ = x[R_POWER_TLS_IE-43] - _ = x[R_POWER_TLS-44] - _ = x[R_ADDRPOWER_DS-45] - _ = x[R_ADDRPOWER_GOT-46] - _ = x[R_ADDRPOWER_PCREL-47] - _ = x[R_ADDRPOWER_TOCREL-48] - _ = x[R_ADDRPOWER_TOCREL_DS-49] - _ = x[R_RISCV_PCREL_ITYPE-50] - _ = x[R_RISCV_PCREL_STYPE-51] - _ = x[R_RISCV_TLS_IE_ITYPE-52] - _ = x[R_RISCV_TLS_IE_STYPE-53] - _ = x[R_PCRELDBL-54] - _ = x[R_ADDRMIPSU-55] - _ = x[R_ADDRMIPSTLS-56] - _ = x[R_ADDRCUOFF-57] - _ = x[R_WASMIMPORT-58] - _ = x[R_XCOFFREF-59] + _ = x[R_ARM64_LDST16-39] + _ = x[R_ARM64_LDST32-40] + _ = x[R_ARM64_LDST64-41] + _ = x[R_ARM64_LDST128-42] + _ = x[R_POWER_TLS_LE-43] + _ = x[R_POWER_TLS_IE-44] + _ = x[R_POWER_TLS-45] + _ = x[R_ADDRPOWER_DS-46] + _ = x[R_ADDRPOWER_GOT-47] + _ = x[R_ADDRPOWER_PCREL-48] + _ = x[R_ADDRPOWER_TOCREL-49] + _ = x[R_ADDRPOWER_TOCREL_DS-50] + _ = x[R_RISCV_PCREL_ITYPE-51] + _ = x[R_RISCV_PCREL_STYPE-52] + _ = x[R_RISCV_TLS_IE_ITYPE-53] + _ = x[R_RISCV_TLS_IE_STYPE-54] + _ = x[R_PCRELDBL-55] + _ = x[R_ADDRMIPSU-56] + _ = x[R_ADDRMIPSTLS-57] + _ = x[R_ADDRCUOFF-58] + _ = x[R_WASMIMPORT-59] + _ = x[R_XCOFFREF-60] } -const _RelocType_name = "R_ADDRR_ADDRPOWERR_ADDRARM64R_ADDRMIPSR_ADDROFFR_WEAKADDROFFR_SIZER_CALLR_CALLARMR_CALLARM64R_CALLINDR_CALLPOWERR_CALLMIPSR_CALLRISCVR_CONSTR_PCRELR_TLS_LER_TLS_IER_GOTOFFR_PLT0R_PLT1R_PLT2R_USEFIELDR_USETYPER_USEIFACER_USEIFACEMETHODR_METHODOFFR_POWER_TOCR_GOTPCRELR_JMPMIPSR_DWARFSECREFR_DWARFFILEREFR_ARM64_TLS_LER_ARM64_TLS_IER_ARM64_GOTPCRELR_ARM64_GOTR_ARM64_PCRELR_ARM64_LDST8R_ARM64_LDST32R_ARM64_LDST64R_ARM64_LDST128R_POWER_TLS_LER_POWER_TLS_IER_POWER_TLSR_ADDRPOWER_DSR_ADDRPOWER_GOTR_ADDRPOWER_PCRELR_ADDRPOWER_TOCRELR_ADDRPOWER_TOCREL_DSR_RISCV_PCREL_ITYPER_RISCV_PCREL_STYPER_RISCV_TLS_IE_ITYPER_RISCV_TLS_IE_STYPER_PCRELDBLR_ADDRMIPSUR_ADDRMIPSTLSR_ADDRCUOFFR_WASMIMPORTR_XCOFFREF" +const _RelocType_name = "R_ADDRR_ADDRPOWERR_ADDRARM64R_ADDRMIPSR_ADDROFFR_WEAKADDROFFR_SIZER_CALLR_CALLARMR_CALLARM64R_CALLINDR_CALLPOWERR_CALLMIPSR_CALLRISCVR_CONSTR_PCRELR_TLS_LER_TLS_IER_GOTOFFR_PLT0R_PLT1R_PLT2R_USEFIELDR_USETYPER_USEIFACER_USEIFACEMETHODR_METHODOFFR_POWER_TOCR_GOTPCRELR_JMPMIPSR_DWARFSECREFR_DWARFFILEREFR_ARM64_TLS_LER_ARM64_TLS_IER_ARM64_GOTPCRELR_ARM64_GOTR_ARM64_PCRELR_ARM64_LDST8R_ARM64_LDST16R_ARM64_LDST32R_ARM64_LDST64R_ARM64_LDST128R_POWER_TLS_LER_POWER_TLS_IER_POWER_TLSR_ADDRPOWER_DSR_ADDRPOWER_GOTR_ADDRPOWER_PCRELR_ADDRPOWER_TOCRELR_ADDRPOWER_TOCREL_DSR_RISCV_PCREL_ITYPER_RISCV_PCREL_STYPER_RISCV_TLS_IE_ITYPER_RISCV_TLS_IE_STYPER_PCRELDBLR_ADDRMIPSUR_ADDRMIPSTLSR_ADDRCUOFFR_WASMIMPORTR_XCOFFREF" -var _RelocType_index = [...]uint16{0, 6, 17, 28, 38, 47, 60, 66, 72, 81, 92, 101, 112, 122, 133, 140, 147, 155, 163, 171, 177, 183, 189, 199, 208, 218, 234, 245, 256, 266, 275, 288, 302, 316, 330, 346, 357, 370, 383, 397, 411, 426, 440, 454, 465, 479, 494, 511, 529, 550, 569, 588, 608, 628, 638, 649, 662, 673, 685, 695} +var _RelocType_index = [...]uint16{0, 6, 17, 28, 38, 47, 60, 66, 72, 81, 92, 101, 112, 122, 133, 140, 147, 155, 163, 171, 177, 183, 189, 199, 208, 218, 234, 245, 256, 266, 275, 288, 302, 316, 330, 346, 357, 370, 383, 397, 411, 425, 440, 454, 468, 479, 493, 508, 525, 543, 564, 583, 602, 622, 642, 652, 663, 676, 687, 699, 709} func (i RelocType) String() string { i -= 1 diff --git a/src/cmd/link/internal/arm64/asm.go b/src/cmd/link/internal/arm64/asm.go index cb16180657d..a7af8556460 100644 --- a/src/cmd/link/internal/arm64/asm.go +++ b/src/cmd/link/internal/arm64/asm.go @@ -177,6 +177,14 @@ func adddynrel(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, s loade su.SetRelocType(rIdx, objabi.R_ARM64_LDST8) return true + case objabi.ElfRelocOffset + objabi.RelocType(elf.R_AARCH64_LDST16_ABS_LO12_NC): + if targType == sym.SDYNIMPORT { + ldr.Errorf(s, "unexpected relocation for dynamic symbol %s", ldr.SymName(targ)) + } + su := ldr.MakeSymbolUpdater(s) + su.SetRelocType(rIdx, objabi.R_ARM64_LDST16) + return true + case objabi.ElfRelocOffset + objabi.RelocType(elf.R_AARCH64_LDST32_ABS_LO12_NC): if targType == sym.SDYNIMPORT { ldr.Errorf(s, "unexpected relocation for dynamic symbol %s", ldr.SymName(targ)) @@ -769,6 +777,14 @@ func archreloc(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, r loade o0 := uint32(t&0xfff) << 10 return val | int64(o0), noExtReloc, true + case objabi.R_ARM64_LDST16: + t := ldr.SymAddr(rs) + r.Add() - ((ldr.SymValue(s) + int64(r.Off())) &^ 0xfff) + if t&1 != 0 { + ldr.Errorf(s, "invalid address: %x for relocation type: R_AARCH64_LDST16_ABS_LO12_NC", t) + } + o0 := (uint32(t&0xfff) >> 1) << 10 + return val | int64(o0), noExtReloc, true + case objabi.R_ARM64_LDST32: t := ldr.SymAddr(rs) + r.Add() - ((ldr.SymValue(s) + int64(r.Off())) &^ 0xfff) if t&3 != 0 { diff --git a/src/cmd/link/internal/loadelf/ldelf.go b/src/cmd/link/internal/loadelf/ldelf.go index 5260c6bdcb1..db543a5e50c 100644 --- a/src/cmd/link/internal/loadelf/ldelf.go +++ b/src/cmd/link/internal/loadelf/ldelf.go @@ -1019,6 +1019,7 @@ func relSize(arch *sys.Arch, pn string, elftype uint32) (uint8, error) { ARM64 | uint32(elf.R_AARCH64_ADR_PREL_PG_HI21)<<16, ARM64 | uint32(elf.R_AARCH64_ADD_ABS_LO12_NC)<<16, ARM64 | uint32(elf.R_AARCH64_LDST8_ABS_LO12_NC)<<16, + ARM64 | uint32(elf.R_AARCH64_LDST16_ABS_LO12_NC)<<16, ARM64 | uint32(elf.R_AARCH64_LDST32_ABS_LO12_NC)<<16, ARM64 | uint32(elf.R_AARCH64_LDST64_ABS_LO12_NC)<<16, ARM64 | uint32(elf.R_AARCH64_LDST128_ABS_LO12_NC)<<16, From 750b3729dcb1e0aac239bc69959355ec2242111d Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Tue, 24 Nov 2020 20:28:20 -0800 Subject: [PATCH 08/14] go/constant: MakeFloat64(0) must return a value of Float kind Fixes #42641. Change-Id: I10fdc7c90054b37ab5b303999015262691c12927 Reviewed-on: https://go-review.googlesource.com/c/go/+/273126 Trust: Robert Griesemer Reviewed-by: Matthew Dempsky --- src/go/constant/value.go | 7 ++----- src/go/constant/value_test.go | 37 +++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/src/go/constant/value.go b/src/go/constant/value.go index 4baae2eb327..46414423f2d 100644 --- a/src/go/constant/value.go +++ b/src/go/constant/value.go @@ -370,16 +370,13 @@ func MakeUint64(x uint64) Value { } // MakeFloat64 returns the Float value for x. +// If x is -0.0, the result is 0.0. // If x is not finite, the result is an Unknown. func MakeFloat64(x float64) Value { if math.IsInf(x, 0) || math.IsNaN(x) { return unknownVal{} } - // convert -0 to 0 - if x == 0 { - return int64Val(0) - } - return ratVal{newRat().SetFloat64(x)} + return ratVal{newRat().SetFloat64(x + 0)} // convert -0 to 0 } // MakeFromLiteral returns the corresponding integer, floating-point, diff --git a/src/go/constant/value_test.go b/src/go/constant/value_test.go index 5edc766fde8..286677407d9 100644 --- a/src/go/constant/value_test.go +++ b/src/go/constant/value_test.go @@ -7,6 +7,7 @@ package constant import ( "fmt" "go/token" + "math" "math/big" "strings" "testing" @@ -620,6 +621,42 @@ func TestUnknown(t *testing.T) { } } +func TestMakeFloat64(t *testing.T) { + var zero float64 + for _, arg := range []float64{ + -math.MaxFloat32, + -10, + -0.5, + -zero, + zero, + 1, + 10, + 123456789.87654321e-23, + 1e10, + math.MaxFloat64, + } { + val := MakeFloat64(arg) + if val.Kind() != Float { + t.Errorf("%v: got kind = %d; want %d", arg, val.Kind(), Float) + } + + // -0.0 is mapped to 0.0 + got, exact := Float64Val(val) + if !exact || math.Float64bits(got) != math.Float64bits(arg+0) { + t.Errorf("%v: got %v (exact = %v)", arg, got, exact) + } + } + + // infinity + for sign := range []int{-1, 1} { + arg := math.Inf(sign) + val := MakeFloat64(arg) + if val.Kind() != Unknown { + t.Errorf("%v: got kind = %d; want %d", arg, val.Kind(), Unknown) + } + } +} + type makeTestCase struct { kind Kind arg, want interface{} From 1d3baf20dcac2d9ad88634ac3fe75e9f6d966971 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Fri, 23 Oct 2020 23:40:00 +0100 Subject: [PATCH 09/14] regexp/syntax: add note about Unicode character classes As proposed on golang-nuts: https://groups.google.com/g/golang-nuts/c/M3lmSUptExQ/m/hRySV9GsCAAJ Includes the latest updates from re2's mksyntaxgo: https://code.googlesource.com/re2/+/refs/heads/master/doc/mksyntaxgo Change-Id: Ib7b79aa6531f473feabd0a7f1d263cd65c4388e4 Reviewed-on: https://go-review.googlesource.com/c/go/+/264678 Reviewed-by: Russ Cox Trust: Emmanuel Odeke --- src/regexp/syntax/doc.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/regexp/syntax/doc.go b/src/regexp/syntax/doc.go index efc0b435711..b3f9136b5f3 100644 --- a/src/regexp/syntax/doc.go +++ b/src/regexp/syntax/doc.go @@ -66,7 +66,7 @@ Grouping: Empty strings: ^ at beginning of text or line (flag m=true) - $ at end of text (like \z not Perl's \Z) or line (flag m=true) + $ at end of text (like \z not \Z) or line (flag m=true) \A at beginning of text \b at ASCII word boundary (\w on one side and \W, \A, or \z on the other) \B not at ASCII word boundary @@ -127,5 +127,6 @@ ASCII character classes: [[:word:]] word characters (== [0-9A-Za-z_]) [[:xdigit:]] hex digit (== [0-9A-Fa-f]) +Unicode character classes are those in unicode.Categories and unicode.Scripts. */ package syntax From df68e01b6860e585033156e84f8f9716d2f41a28 Mon Sep 17 00:00:00 2001 From: Daniel S Fava Date: Fri, 20 Nov 2020 21:23:45 +0100 Subject: [PATCH 10/14] runtime: check channel's elemsize before calling race detector When c.elemsize==0 we call raceacquire() and racerelease() as opposed to calling racereleaseacquire() The reason for this change is that, when elemsize==0, we don't allocate a full buffer for the channel. Instead of individual buffer entries, the race detector uses the c.buf as the only buffer entry. This simplification prevents us following the memory model's happens-before rules implemented in racereleaseacquire(). So, instead of calling racereleaseacquire(), we accumulate happens-before information in the synchronization object associated with c.buf. The functionality in this change is implemented in a new function called racenotify() Fixes #42598 Change-Id: I75b92708633fdfde658dc52e06264e2171824e51 Reviewed-on: https://go-review.googlesource.com/c/go/+/271987 Reviewed-by: Dmitry Vyukov Reviewed-by: Russ Cox Run-TryBot: Dmitry Vyukov TryBot-Result: Go Bot Trust: Ian Lance Taylor --- src/runtime/chan.go | 48 ++++++++++++++++++++++---- src/runtime/race/testdata/chan_test.go | 22 ++++++++++++ src/runtime/select.go | 4 +-- 3 files changed, 65 insertions(+), 9 deletions(-) diff --git a/src/runtime/chan.go b/src/runtime/chan.go index 254816e3696..ba56e2cc404 100644 --- a/src/runtime/chan.go +++ b/src/runtime/chan.go @@ -215,7 +215,7 @@ func chansend(c *hchan, ep unsafe.Pointer, block bool, callerpc uintptr) bool { // Space is available in the channel buffer. Enqueue the element to send. qp := chanbuf(c, c.sendx) if raceenabled { - racereleaseacquire(qp) + racenotify(c, c.sendx, nil) } typedmemmove(c.elemtype, qp, ep) c.sendx++ @@ -297,9 +297,8 @@ func send(c *hchan, sg *sudog, ep unsafe.Pointer, unlockf func(), skip int) { // Pretend we go through the buffer, even though // we copy directly. Note that we need to increment // the head/tail locations only when raceenabled. - qp := chanbuf(c, c.recvx) - racereleaseacquire(qp) - racereleaseacquireg(sg.g, qp) + racenotify(c, c.recvx, nil) + racenotify(c, c.recvx, sg) c.recvx++ if c.recvx == c.dataqsiz { c.recvx = 0 @@ -532,7 +531,7 @@ func chanrecv(c *hchan, ep unsafe.Pointer, block bool) (selected, received bool) // Receive directly from queue qp := chanbuf(c, c.recvx) if raceenabled { - racereleaseacquire(qp) + racenotify(c, c.recvx, nil) } if ep != nil { typedmemmove(c.elemtype, ep, qp) @@ -621,8 +620,8 @@ func recv(c *hchan, sg *sudog, ep unsafe.Pointer, unlockf func(), skip int) { // queue is full, those are both the same slot. qp := chanbuf(c, c.recvx) if raceenabled { - racereleaseacquire(qp) - racereleaseacquireg(sg.g, qp) + racenotify(c, c.recvx, nil) + racenotify(c, c.recvx, sg) } // copy data from queue to receiver if ep != nil { @@ -833,3 +832,38 @@ func racesync(c *hchan, sg *sudog) { racereleaseg(sg.g, chanbuf(c, 0)) raceacquire(chanbuf(c, 0)) } + +// Notify the race detector of a send or receive involving buffer entry idx +// and a channel c or its communicating partner sg. +// This function handles the special case of c.elemsize==0. +func racenotify(c *hchan, idx uint, sg *sudog) { + // We could have passed the unsafe.Pointer corresponding to entry idx + // instead of idx itself. However, in a future version of this function, + // we can use idx to better handle the case of elemsize==0. + // A future improvement to the detector is to call TSan with c and idx: + // this way, Go will continue to not allocating buffer entries for channels + // of elemsize==0, yet the race detector can be made to handle multiple + // sync objects underneath the hood (one sync object per idx) + qp := chanbuf(c, idx) + // When elemsize==0, we don't allocate a full buffer for the channel. + // Instead of individual buffer entries, the race detector uses the + // c.buf as the only buffer entry. This simplification prevents us from + // following the memory model's happens-before rules (rules that are + // implemented in racereleaseacquire). Instead, we accumulate happens-before + // information in the synchronization object associated with c.buf. + if c.elemsize == 0 { + if sg == nil { + raceacquire(qp) + racerelease(qp) + } else { + raceacquireg(sg.g, qp) + racereleaseg(sg.g, qp) + } + } else { + if sg == nil { + racereleaseacquire(qp) + } else { + racereleaseacquireg(sg.g, qp) + } + } +} diff --git a/src/runtime/race/testdata/chan_test.go b/src/runtime/race/testdata/chan_test.go index 3e57b8221c7..e39ad4f99ce 100644 --- a/src/runtime/race/testdata/chan_test.go +++ b/src/runtime/race/testdata/chan_test.go @@ -763,3 +763,25 @@ func TestNoRaceCloseHappensBeforeRead(t *testing.T) { <-read } } + +// Test that we call the proper race detector function when c.elemsize==0. +// See https://github.com/golang/go/issues/42598 +func TestNoRaceElemetSize0(t *testing.T) { + var x, y int + var c = make(chan struct{}, 2) + c <- struct{}{} + c <- struct{}{} + go func() { + x += 1 + <-c + }() + go func() { + y += 1 + <-c + }() + time.Sleep(10 * time.Millisecond) + c <- struct{}{} + c <- struct{}{} + x += 1 + y += 1 +} diff --git a/src/runtime/select.go b/src/runtime/select.go index f04b130b15c..e72761bfa91 100644 --- a/src/runtime/select.go +++ b/src/runtime/select.go @@ -415,7 +415,7 @@ bufrecv: if cas.elem != nil { raceWriteObjectPC(c.elemtype, cas.elem, casePC(casi), chanrecvpc) } - racereleaseacquire(chanbuf(c, c.recvx)) + racenotify(c, c.recvx, nil) } if msanenabled && cas.elem != nil { msanwrite(cas.elem, c.elemtype.size) @@ -437,7 +437,7 @@ bufrecv: bufsend: // can send to buffer if raceenabled { - racereleaseacquire(chanbuf(c, c.sendx)) + racenotify(c, c.sendx, nil) raceReadObjectPC(c.elemtype, cas.elem, casePC(casi), chansendpc) } if msanenabled { From b9365488f017ba88540f21927a69e34351941db1 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Tue, 24 Nov 2020 17:48:38 +0100 Subject: [PATCH 11/14] cmd/internal/objabi: assume GOARM=7 on Android CL 34641 changed the Go runtime to assume GOARM=7 support on Android. This change completes that by assuming GOARM=7 in the toolchain, fixing the gotcha of inexplicably slow performance on non-arm64 Android devices. There is already code in cmd/dist to force GOARM to 7 on GOOS=android. However, dist is most likely run with GOOS != android. Change-Id: I5e2bf11c3ecd0f6c193229eaa8ddc570722799d1 Reviewed-on: https://go-review.googlesource.com/c/go/+/272846 Run-TryBot: Elias Naur TryBot-Result: Go Bot Reviewed-by: Cherry Zhang Trust: Elias Naur --- src/cmd/dist/util.go | 6 ------ src/cmd/internal/objabi/util.go | 7 ++++++- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/cmd/dist/util.go b/src/cmd/dist/util.go index 0a419e465fe..9b4f8d2dec7 100644 --- a/src/cmd/dist/util.go +++ b/src/cmd/dist/util.go @@ -383,12 +383,6 @@ func xsamefile(f1, f2 string) bool { } func xgetgoarm() string { - if goos == "android" { - // Assume all android devices have VFPv3. - // These ports are also mostly cross-compiled, so it makes little - // sense to auto-detect the setting. - return "7" - } if gohostarch != "arm" || goos != gohostos { // Conservative default for cross-compilation. return "5" diff --git a/src/cmd/internal/objabi/util.go b/src/cmd/internal/objabi/util.go index 9479ab2cd9f..d36e7435806 100644 --- a/src/cmd/internal/objabi/util.go +++ b/src/cmd/internal/objabi/util.go @@ -40,7 +40,12 @@ const ( ) func goarm() int { - switch v := envOr("GOARM", defaultGOARM); v { + def := defaultGOARM + if GOOS == "android" { + // Android devices always support GOARM=7. + def = "7" + } + switch v := envOr("GOARM", def); v { case "5": return 5 case "6": From 9dc2350d8cb10f8af5f3551aeb5e3e8bf820c071 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Wed, 25 Nov 2020 12:57:38 +0100 Subject: [PATCH 12/14] doc/go1.16: add time/tzdata release note for CL 261877 For #40700 Change-Id: I056cef20a5f071977d0ae589c7a50d5f69af3283 Reviewed-on: https://go-review.googlesource.com/c/go/+/273166 Trust: Tobias Klauser Reviewed-by: Ian Lance Taylor Reviewed-by: Dmitri Shuralyov --- doc/go1.16.html | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/go1.16.html b/doc/go1.16.html index 2e26d659bab..8e839306633 100644 --- a/doc/go1.16.html +++ b/doc/go1.16.html @@ -701,7 +701,9 @@ Do not send CLs removing the interior tags from such phrases.
time/tzdata

- TODO: https://golang.org/cl/261877: use slim tz data format + The slim timezone data format is now used for the time zone database in + $GOROOT/lib/time/zoneinfo.zip and the embedded copy in this + package. This reduces the size of the time zone database by about 350 KB.

From ef603bead5d336e81954f890e20efa0261581792 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Wed, 25 Nov 2020 19:12:13 +0100 Subject: [PATCH 13/14] cmd/dist: restore GOARM=7 default for android/arm Fixes the android/arm builder. Without it, the builder reported unexpected stale targets during bootstrap: https://build.golang.org/log/b951f1171be54cf4a12c2a0720ffaf07f8a11377 Tighten the GOARM=7 default in cmd/internal/objabi while here. Change-Id: I944744910193e72e91bc37b5bf0783076b45e579 Reviewed-on: https://go-review.googlesource.com/c/go/+/273167 Run-TryBot: Elias Naur Reviewed-by: Cherry Zhang TryBot-Result: Go Bot Trust: Elias Naur --- src/cmd/dist/util.go | 6 ++++++ src/cmd/internal/objabi/util.go | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/cmd/dist/util.go b/src/cmd/dist/util.go index 9b4f8d2dec7..0a419e465fe 100644 --- a/src/cmd/dist/util.go +++ b/src/cmd/dist/util.go @@ -383,6 +383,12 @@ func xsamefile(f1, f2 string) bool { } func xgetgoarm() string { + if goos == "android" { + // Assume all android devices have VFPv3. + // These ports are also mostly cross-compiled, so it makes little + // sense to auto-detect the setting. + return "7" + } if gohostarch != "arm" || goos != gohostos { // Conservative default for cross-compilation. return "5" diff --git a/src/cmd/internal/objabi/util.go b/src/cmd/internal/objabi/util.go index d36e7435806..a73ab479a16 100644 --- a/src/cmd/internal/objabi/util.go +++ b/src/cmd/internal/objabi/util.go @@ -41,8 +41,8 @@ const ( func goarm() int { def := defaultGOARM - if GOOS == "android" { - // Android devices always support GOARM=7. + if GOOS == "android" && GOARCH == "arm" { + // Android arm devices always support GOARM=7. def = "7" } switch v := envOr("GOARM", def); v { From 4481ad6eb6c2b4ee52d949289da82cc00cc829fa Mon Sep 17 00:00:00 2001 From: Dmitri Shuralyov Date: Wed, 25 Nov 2020 14:07:30 -0500 Subject: [PATCH 14/14] doc/go1.16: consolidate stdlib changes in "Minor changes" section Many of the standard library changes that were added before CL 272871 ended up in the "Core library" section. That section is meant for major changes like new packages, and most of these aren't. Consolidate all changes in the "Minor changes to the library" section for now, so that it's easier to get a complete picture of changes for each package, along with the remaining TODOs. Add a TODO to read them over at the end and factor out items that are worth highlighting. Apply minor other fixups to improve consistency. For #40700. Change-Id: I7dc2e7ebf2ea3385fce0c207bae4ce467998a717 Reviewed-on: https://go-review.googlesource.com/c/go/+/273267 Trust: Dmitri Shuralyov Run-TryBot: Dmitri Shuralyov Reviewed-by: Katie Hockman TryBot-Result: Go Bot --- doc/go1.16.html | 303 ++++++++++++++++++++++++------------------------ 1 file changed, 153 insertions(+), 150 deletions(-) diff --git a/doc/go1.16.html b/doc/go1.16.html index 8e839306633..6e371b9617c 100644 --- a/doc/go1.16.html +++ b/doc/go1.16.html @@ -216,7 +216,7 @@ Do not send CLs removing the interior tags from such phrases.

Cgo

-

+

The cgo tool will no longer try to translate C struct bitfields into Go struct fields, even if their size can be represented in Go. The order in which C bitfields appear in memory @@ -281,7 +281,7 @@ Do not send CLs removing the interior tags from such phrases. TODO: update with final numbers later in the release.

-

+

On Windows, go build -buildmode=c-shared now generates Windows ASLR DLLs by default. ASLR can be disabled with --ldflags=-aslr=false.

@@ -289,135 +289,13 @@ Do not send CLs removing the interior tags from such phrases.

Core library

- TODO + TODO: mention significant additions like new packages (io/fs), + new proposal-scoped features (//go:embed), and so on

-

crypto/hmac

- -

- New will now panic if separate calls to - the hash generation function fail to return new values. Previously, the - behavior was undefined and invalid outputs were sometimes generated. -

- -

crypto/tls

- -

- I/O operations on closing or closed TLS connections can now be detected using - the new ErrClosed error. A typical use - would be errors.Is(err, net.ErrClosed). In earlier releases - the only way to reliably detect this case was to match the string returned - by the Error method with "tls: use of closed connection". -

- -

- A default deadline is set in Close - before sending the close notify alert, in order to prevent blocking - indefinitely. -

- -

- (*Conn).HandshakeContext was added to - allow the user to control cancellation of an in-progress TLS Handshake. - The context provided is propagated into the - ClientHelloInfo - and CertificateRequestInfo - structs and accessible through the new - (*ClientHelloInfo).Context - and - - (*CertificateRequestInfo).Context - methods respectively. Canceling the context after the handshake has finished - has no effect. -

- -

- Clients now ensure that the server selects - - an ALPN protocol from - - the list advertised by the client. -

- -

- TLS servers will now prefer other AEAD cipher suites (such as ChaCha20Poly1305) - over AES-GCM cipher suites if either the client or server doesn't have AES hardware - support, unless the application set both - Config.PreferServerCipherSuites - and Config.CipherSuites - or there are no other AEAD cipher suites supported. - The client is assumed not to have AES hardware support if it does not signal a - preference for AES-GCM cipher suites. -

- -

crypto/x509

- -

- ParseCertificate and - CreateCertificate both - now enforce string encoding restrictions for the fields DNSNames, - EmailAddresses, and URIs. These fields can only - contain strings with characters within the ASCII range. -

- -

- CreateCertificate now - verifies the generated certificate's signature using the signer's - public key. If the signature is invalid, an error is returned, instead - of a malformed certificate. -

- -

- A number of additional fields have been added to the - CertificateRequest type. - These fields are now parsed in ParseCertificateRequest - and marshalled in CreateCertificateRequest. -

- -

encoding/json

- -

- The error message for - SyntaxError - now begins with "json: ", matching the other errors in the package. -

- -

net

- -

- The case of I/O on a closed network connection, or I/O on a network - connection that is closed before any of the I/O completes, can now - be detected using the new ErrClosed error. - A typical use would be errors.Is(err, net.ErrClosed). - In earlier releases the only way to reliably detect this case was to - match the string returned by the Error method - with "use of closed network connection". -

- -

- In previous Go releases the default TCP listener backlog size on Linux systems, - set by /proc/sys/net/core/somaxconn, was limited to a maximum of 65535. - On Linux kernel version 4.1 and above, the maximum is now 4294967295. -

- -

text/template/parse

- -

- A new CommentNode - was added to the parse tree. The Mode - field in the parse.Tree enables access to it. -

- - -

unicode

- -

- The unicode package and associated - support throughout the system has been upgraded from Unicode 12.0.0 to - Unicode 13.0.0, - which adds 5,930 new characters, including four new scripts, and 55 new emoji. - Unicode 13.0.0 also designates plane 3 (U+30000-U+3FFFF) as the tertiary - ideographic plane. +

+ TODO: when the "Minor changes to the library" section is close to completion, + decide if any changes are worth factoring out and highlighting in "Core library"

Minor changes to the library

@@ -429,7 +307,7 @@ Do not send CLs removing the interior tags from such phrases.

- TODO + TODO: complete this section, resolve TODOs below, add missing entries

crypto/dsa
@@ -441,8 +319,66 @@ Do not send CLs removing the interior tags from such phrases.
+
crypto/hmac
+
+

+ New will now panic if separate calls to + the hash generation function fail to return new values. Previously, the + behavior was undefined and invalid outputs were sometimes generated. +

+
+
+
crypto/tls
+

+ I/O operations on closing or closed TLS connections can now be detected using + the new ErrClosed error. A typical use + would be errors.Is(err, net.ErrClosed). In earlier releases + the only way to reliably detect this case was to match the string returned + by the Error method with "tls: use of closed connection". +

+ +

+ A default deadline is set in Close + before sending the close notify alert, in order to prevent blocking + indefinitely. +

+ +

+ (*Conn).HandshakeContext was added to + allow the user to control cancellation of an in-progress TLS Handshake. + The context provided is propagated into the + ClientHelloInfo + and CertificateRequestInfo + structs and accessible through the new + (*ClientHelloInfo).Context + and + + (*CertificateRequestInfo).Context + methods respectively. Canceling the context after the handshake has finished + has no effect. +

+ +

+ Clients now ensure that the server selects + + an ALPN protocol from + + the list advertised by the client. +

+ +

+ TLS servers will now prefer other AEAD cipher suites (such as ChaCha20Poly1305) + over AES-GCM cipher suites if either the client or server doesn't have AES hardware + support, unless the application set both + Config.PreferServerCipherSuites + and Config.CipherSuites + or there are no other AEAD cipher suites supported. + The client is assumed not to have AES hardware support if it does not signal a + preference for AES-GCM cipher suites. +

+

TODO: https://golang.org/cl/246637: make config.Clone return nil if the source is nil

@@ -451,6 +387,28 @@ Do not send CLs removing the interior tags from such phrases.
crypto/x509
+

+ ParseCertificate and + CreateCertificate both + now enforce string encoding restrictions for the fields DNSNames, + EmailAddresses, and URIs. These fields can only + contain strings with characters within the ASCII range. +

+ +

+ CreateCertificate now + verifies the generated certificate's signature using the signer's + public key. If the signature is invalid, an error is returned, instead + of a malformed certificate. +

+ +

+ A number of additional fields have been added to the + CertificateRequest type. + These fields are now parsed in ParseCertificateRequest + and marshalled in CreateCertificateRequest. +

+

DSA signature verification is no longer supported. Note that DSA signature generation was never supported. @@ -469,6 +427,12 @@ Do not send CLs removing the interior tags from such phrases.

encoding/json
+

+ The error message for + SyntaxError + now begins with "json: ", matching the other errors in the package. +

+

TODO: https://golang.org/cl/234818: allow semicolon in field key / struct tag

@@ -531,6 +495,22 @@ Do not send CLs removing the interior tags from such phrases.
net
+

+ The case of I/O on a closed network connection, or I/O on a network + connection that is closed before any of the I/O completes, can now + be detected using the new ErrClosed error. + A typical use would be errors.Is(err, net.ErrClosed). + In earlier releases the only way to reliably detect this case was to + match the string returned by the Error method + with "use of closed network connection". +

+ +

+ In previous Go releases the default TCP listener backlog size on Linux systems, + set by /proc/sys/net/core/somaxconn, was limited to a maximum of 65535. + On Linux kernel version 4.1 and above, the maximum is now 4294967295. +

+

TODO: https://golang.org/cl/238629: prefer /etc/hosts over DNS when no /etc/nsswitch.conf is present

@@ -554,14 +534,14 @@ Do not send CLs removing the interior tags from such phrases.

- The net/http package now rejects HTTP range requests - of the form "Range": "bytes=--N" where "-N" is a negative suffix length, for - example "Range": "bytes=--2". It now replies with a 416 "Range Not Satisfiable" response. + The net/http package now rejects HTTP range requests + of the form "Range": "bytes=--N" where "-N" is a negative suffix length, for + example "Range": "bytes=--2". It now replies with a 416 "Range Not Satisfiable" response.

- Cookies set with SameSiteDefaultMode now behave according to the current - spec (no attribute is set) instead of generating a SameSite key without a value. + Cookies set with SameSiteDefaultMode now behave according to the current + spec (no attribute is set) instead of generating a SameSite key without a value.

@@ -661,6 +641,19 @@ Do not send CLs removing the interior tags from such phrases.

+
strconv
+
+

+ ParseFloat now uses + the Eisel-Lemire + algorithm, improving performance by up to a factor of 2. This can + also speed up decoding textual formats like encoding/json. +

+
+
+
syscall

@@ -677,19 +670,6 @@ Do not send CLs removing the interior tags from such phrases.

-
strconv
-
-

- ParseFloat now uses - the Eisel-Lemire - algorithm, improving performance by up to a factor of 2. This can - also speed up decoding textual formats like encoding/json. -

-
-
-
text/template

@@ -698,12 +678,35 @@ Do not send CLs removing the interior tags from such phrases.

+
text/template/parse
+
+

+ A new CommentNode + was added to the parse tree. The Mode + field in the parse.Tree enables access to it. +

+
+
+
time/tzdata

- The slim timezone data format is now used for the time zone database in + The slim timezone data format is now used for the timezone database in $GOROOT/lib/time/zoneinfo.zip and the embedded copy in this - package. This reduces the size of the time zone database by about 350 KB. + package. This reduces the size of the timezone database by about 350 KB.

+ +
unicode
+
+

+ The unicode package and associated + support throughout the system has been upgraded from Unicode 12.0.0 to + Unicode 13.0.0, + which adds 5,930 new characters, including four new scripts, and 55 new emoji. + Unicode 13.0.0 also designates plane 3 (U+30000-U+3FFFF) as the tertiary + ideographic plane. +

+
+