diff --git a/.gitignore b/.gitignore
index 39723909c71..aa62a9fad71 100644
--- a/.gitignore
+++ b/.gitignore
@@ -37,6 +37,7 @@ _testmain.go
/src/cmd/internal/objabi/zbootstrap.go
/src/go/build/zcgo.go
/src/go/doc/headscan
+/src/internal/buildcfg/zbootstrap.go
/src/runtime/internal/sys/zversion.go
/src/unicode/maketables
/test.out
diff --git a/AUTHORS b/AUTHORS
index 4828ba36cc6..48ce71f4cc6 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -145,7 +145,7 @@ Andy Davis
- The latest Go release, version 1.16, arrives six months after Go 1.15.
- Most of its changes are in the implementation of the toolchain, runtime, and libraries.
- As always, the release maintains the Go 1 promise of compatibility.
- We expect almost all Go programs to continue to compile and run as before.
-
- There are no changes to the language.
-
- Go 1.16 adds support of 64-bit ARM architecture on macOS (also known as
- Apple Silicon) with
- The iOS port, which was previously
- Go 1.16 adds an
- Go 1.16 is the last release that will run on macOS 10.12 Sierra.
- Go 1.17 will require macOS 10.13 High Sierra or later.
-
- Go now supports the 64-bit ARM architecture on NetBSD (the
-
- Go now supports the MIPS64 architecture on OpenBSD
- (the
- On the 64-bit x86 and 64-bit ARM architectures on OpenBSD (the
-
- As announced in the Go 1.15 release notes,
- Go 1.16 drops support for x87 mode compilation (
- The
- Module-aware mode is enabled by default, regardless of whether a
-
- Build commands like
-
-
-
- The
- The
- In module mode, the
- The
- When using
-
- The
-
-
- When the main module's
- When the
- The
- When the
- The
- 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
- is implementation dependent, so in some cases the cgo tool produced
- results that were silently incorrect.
-
- The vet tool now warns about invalid calls to the
- Calls to these methods stop the execution of the created goroutine and not
- the
- Code calling
- The vet tool now warns about amd64 assembly that clobbers the BP
- register (the frame pointer) without saving and restoring it,
- contrary to the calling convention. Code that doesn't preserve the
- BP register must be modified to either not use BP at all or preserve
- BP by saving and restoring it. An easy way to preserve BP is to set
- the frame size to a nonzero value, which causes the generated
- prologue and epilogue to preserve the BP register for you.
- See CL 248260 for example
- fixes.
-
- The vet tool now warns about incorrectly passing a non-pointer or nil argument to
-
- The new
- Setting the
- On Linux, the runtime now defaults to releasing memory to the
- operating system promptly (using
- Go 1.16 fixes a discrepancy between the race detector and
- the Go memory model. The race detector now
- more precisely follows the channel synchronization rules of the
- memory model. As a result, the detector may now report races it
- previously missed.
-
- The compiler can now inline functions with
- non-labeled
- 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
- of a two-release project to
- modernize the Go
- linker.
-
- The linker changes in 1.16 extend the 1.15 improvements to all
- supported architecture/OS combinations (the 1.15 performance improvements
- were primarily focused on
- On Windows,
- The new
- The new
- On the producer side of the interface,
- the new
- On the consumer side,
- the new
- For testing code that implements
- The Introduction to Go 1.16
-
-Changes to the language
-
-Ports
-
-Darwin and iOS
-
-GOOS=darwin, GOARCH=arm64.
- Like the darwin/amd64 port, the darwin/arm64
- port supports cgo, internal and external linking, c-archive,
- c-shared, and pie build modes, and the race
- detector.
-darwin/arm64, has
- been renamed to ios/arm64. GOOS=ios
- implies the
- darwin build tag, just as GOOS=android
- implies the linux build tag. This change should be
- transparent to anyone using gomobile to build iOS apps.
-ios/amd64 port, which targets the iOS
- simulator running on AMD64-based macOS. Previously this was
- unofficially supported through darwin/amd64 with
- the ios build tag set. See also
- misc/ios/README for
- details about how to build programs for iOS and iOS simulator.
-NetBSD
-
-netbsd/arm64 port).
-OpenBSD
-
-openbsd/mips64 port). This port does not yet
- support cgo.
-openbsd/amd64 and openbsd/arm64 ports), system
- calls are now made through libc, instead of directly using
- the SYSCALL/SVC instruction. This ensures
- forward-compatibility with future versions of OpenBSD. In particular,
- OpenBSD 6.9 onwards will require system calls to be made through
- libc for non-static Go binaries.
-386
-
-GO386=387).
- Support for non-SSE2 processors is now available using soft float
- mode (GO386=softfloat).
- Users running on non-SSE2 processors should replace GO386=387
- with GO386=softfloat.
-RISC-V
-
-linux/riscv64 port now supports cgo and
- -buildmode=pie. This release also includes performance
- optimizations and code generation improvements for RISC-V.
-Tools
-
-Go command
-
-Modules
-
-go.mod file is present in the current working directory or a
- parent directory. More precisely, the GO111MODULE environment
- variable now defaults to on. To switch to the previous behavior,
- set GO111MODULE to auto.
-go build and go
- test no longer modify go.mod and go.sum
- by default. Instead, they report an error if a module requirement or checksum
- needs to be added or updated (as if the -mod=readonly flag were
- used). Module requirements and sums may be adjusted with go
- mod tidy or go get.
-go install now accepts arguments with
- version suffixes (for example, go install
- example.com/cmd@v1.0.0). This causes go
- install to build and install packages in module-aware mode,
- ignoring the go.mod file in the current directory or any parent
- directory, if there is one. This is useful for installing executables without
- affecting the dependencies of the main module.
-go install, with or without a version suffix (as
- described above), is now the recommended way to build and install packages in
- module mode. go get should be used with the
- -d flag to adjust the current module's dependencies without
- building packages, and use of go get to build and
- install packages is deprecated. In a future release, the -d flag
- will always be enabled.
-retract directives may now be used in a go.mod file
- to indicate that certain published versions of the module should not be used
- by other modules. A module author may retract a version after a severe problem
- is discovered or if the version was published unintentionally.
-go mod vendor
- and go mod tidy subcommands now accept
- the -e flag, which instructs them to proceed despite errors in
- resolving missing packages.
-go command now ignores requirements on module versions
- excluded by exclude directives in the main module. Previously,
- the go command used the next version higher than an excluded
- version, but that version could change over time, resulting in
- non-reproducible builds.
-go command now disallows import paths that
- include non-ASCII characters or path elements with a leading dot character
- (.). Module paths with these characters were already disallowed
- (see Module paths and versions),
- so this change affects only paths within module subdirectories.
-Embedding Files
-
-go command now supports including
- static files and file trees as part of the final executable,
- using the new //go:embed directive.
- See the documentation for the new
- embed
- package for details.
-
-
-go testgo test, a test that
- calls os.Exit(0) during execution of a test function
- will now be considered to fail.
- This will help catch cases in which a test calls code that calls
- os.Exit(0) and thereby stops running all future tests.
- If a TestMain function calls os.Exit(0)
- that is still considered to be a passing test.
-go test reports an error when the -c
- or -i flags are used together with unknown flags. Normally,
- unknown flags are passed to tests, but when -c or -i
- are used, tests are not run.
-
-
-go getgo get -insecure flag is
- deprecated and will be removed in a future version. This flag permits
- fetching from repositories and resolving custom domains using insecure
- schemes such as HTTP, and also bypasses module sum validation using the
- checksum database. To permit the use of insecure schemes, use the
- GOINSECURE environment variable instead. To bypass module
- sum validation, use GOPRIVATE or GONOSUMDB.
- See go help environment for details.
-go get example.com/mod@patch now
- requires that some version of example.com/mod already be
- required by the main module.
- (However, go get -u=patch continues
- to patch even newly-added dependencies.)
-
-
-GOVCS environment variableGOVCS is a new environment variable that limits which version
- control tools the go command may use to download source code.
- This mitigates security issues with tools that are typically used in trusted,
- authenticated environments. By default, git and hg
- may be used to download code from any repository. svn,
- bzr, and fossil may only be used to download code
- from repositories with module paths or package paths matching patterns in
- the GOPRIVATE environment variable. See
- go
- help vcs for details.
-The
-
-all patterngo.mod file
- declares go 1.16 or higher, the all
- package pattern now matches only those packages that are transitively imported
- by a package or test found in the main module. (Packages imported by tests
- of packages imported by the main module are no longer included.) This is
- the same set of packages retained
- by go mod vendor since Go 1.11.
-The
-
--toolexec build flag-toolexec build flag is specified to use a program when
- invoking toolchain programs like compile or asm, the environment variable
- TOOLEXEC_IMPORTPATH is now set to the import path of the package
- being built.
-The
-
--i build flag-i flag accepted by go build,
- go install, and go test is
- now deprecated. The -i flag instructs the go command
- to install packages imported by packages named on the command line. Since
- the build cache was introduced in Go 1.10, the -i flag no longer
- has a significant effect on build times, and it causes errors when the install
- directory is not writable.
-The
-
-list command-export flag is specified, the BuildID
- field is now set to the build ID of the compiled package. This is equivalent
- to running go tool buildid on
- go list -exported -f {{.Export}},
- but without the extra step.
-The
-
--overlay flag-overlay flag specifies a JSON configuration file containing
- a set of file path replacements. The -overlay flag may be used
- with all build commands and go mod subcommands.
- It is primarily intended to be used by editor tooling such as gopls to
- understand the effects of unsaved changes to source files. The config file
- maps actual file paths to replacement file paths and the go
- command and its builds will run as if the actual file paths exist with the
- contents given by the replacement file paths, or don't exist if the replacement
- file paths are empty.
-Cgo
-
-Vet
-
-New warning for invalid testing.T use in
-goroutines
-
-testing.T
- method Fatal from within a goroutine created during the test.
- This also warns on calls to Fatalf, FailNow, and
- Skip{,f,Now} methods on testing.T tests or
- testing.B benchmarks.
-Test* or Benchmark* function. So these are
- required to be called by the goroutine
- running the test or benchmark function. For example:
-
-func TestFoo(t *testing.T) {
- go func() {
- if condition() {
- t.Fatal("oops") // This exits the inner func instead of TestFoo.
- }
- ...
- }()
-}
-
-
-t.Fatal (or a similar method) from a created
- goroutine should be rewritten to signal the test failure using
- t.Error and exit the goroutine early using an alternative
- method, such as using a return statement. The previous example
- could be rewritten as:
-
-func TestFoo(t *testing.T) {
- go func() {
- if condition() {
- t.Error("oops")
- return
- }
- ...
- }()
-}
-
-
-New warning for frame pointer
-
-New warning for asn1.Unmarshal
-
-asn1.Unmarshal.
- This is like the existing checks for
- encoding/json.Unmarshal
- and encoding/xml.Unmarshal.
-Runtime
-
-runtime/metrics package
- introduces a stable interface for reading
- implementation-defined metrics from the Go runtime.
- It supersedes existing functions like
- runtime.ReadMemStats
- and
- debug.GCStats
- and is significantly more general and efficient.
- See the package documentation for more details.
-GODEBUG environment variable
- to inittrace=1 now causes the runtime to emit a single
- line to standard error for each package init,
- summarizing its execution time and memory allocation. This trace can
- be used to find bottlenecks or regressions in Go startup
- performance.
- The GODEBUG
- documentation describes the format.
-MADV_DONTNEED), rather
- than lazily when the operating system is under memory pressure
- (using MADV_FREE). This means process-level memory
- statistics like RSS will more accurately reflect the amount of
- physical memory being used by Go processes. Systems that are
- currently using GODEBUG=madvdontneed=1 to improve
- memory monitoring behavior no longer need to set this environment
- variable.
-Compiler
-
-for loops, method values, and type
- switches. The inliner can also detect more indirect calls where
- inlining is possible.
-Linker
-
-ELF-based OSes and
- amd64 architectures). For a representative set of
- large Go programs, linking is 20-25% faster than 1.15 and requires
- 5-15% less memory on average for linux/amd64, with larger
- improvements for other architectures and OSes. Most binaries are
- also smaller as a result of more aggressive symbol pruning.
-go build -buildmode=c-shared now generates Windows
- ASLR DLLs by default. ASLR can be disabled with --ldflags=-aslr=false.
-Core library
-
-Embedded Files
-
-embed package
- provides access to files embedded in the program during compilation
- using the new //go:embed directive.
-File Systems
-
-io/fs package
- defines the fs.FS interface,
- an abstraction for read-only trees of files.
- The standard library packages have been adapted to make use
- of the interface as appropriate.
-embed.FS type
- implements fs.FS, as does
- zip.Reader.
- The new os.DirFS function
- provides an implementation of fs.FS backed by a tree
- of operating system files.
-http.FS
- function converts an fs.FS to an
- http.FileSystem.
- Also, the html/template
- and text/template
- packages’ ParseFS
- functions and methods read templates from an fs.FS.
-fs.FS,
- the new testing/fstest
- package provides a TestFS
- function that checks for and reports common mistakes.
- It also provides a simple in-memory file system implementation,
- MapFS,
- which can be useful for testing code that accepts fs.FS
- implementations.
-Deprecation of io/ioutil
-
-io/ioutil package has
- turned out to be a poorly defined and hard to understand collection
- of things. All functionality provided by the package has been moved
- to other packages. The io/ioutil package remains and
- will continue to work as before, but we encourage new code to use
- the new definitions in the io and
- os packages.
-
- Here is a list of the new locations of the names exported
- by io/ioutil:
-
-
-Discard
- => io.DiscardNopCloser
- => io.NopCloserReadAll
- => io.ReadAllReadDir
- => os.ReadDir
- (note: returns a slice of
- os.DirEntry
- rather than a slice of
- fs.FileInfo)
- ReadFile
- => os.ReadFileTempDir
- => os.MkdirTempTempFile
- => os.CreateTempWriteFile
- => os.WriteFile
- As always, there are various minor changes and updates to the library, - made with the Go 1 promise of compatibility - in mind. -
- -
- The new Reader.Open
- method implements the fs.FS
- interface.
-
- The crypto/dsa package is now deprecated.
- See issue #40337.
-
- 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.
-
- I/O operations on closing or closed TLS connections can now be detected
- using the new net.ErrClosed
- error. A typical use would be errors.Is(err, net.ErrClosed).
-
- A default write deadline is now set in
- Conn.Close
- before sending the "close notify" alert, in order to prevent blocking
- indefinitely.
-
- Clients now return a handshake error if the server selects - - an ALPN protocol that was not in - - the list advertised by the client. -
- -
- Servers will now prefer other available AEAD cipher suites (such as ChaCha20Poly1305)
- over AES-GCM cipher suites if either the client or server doesn't have AES hardware
- support, unless both
- Config.PreferServerCipherSuites
- and Config.CipherSuites
- are set. The client is assumed not to have AES hardware support if it does
- not signal a preference for AES-GCM cipher suites.
-
- Config.Clone now
- returns nil if the receiver is nil, rather than panicking.
-
- The GODEBUG=x509ignoreCN=0 flag will be removed in Go 1.17.
- It enables the legacy behavior of treating the CommonName
- field on X.509 certificates as a host name when no Subject Alternative
- Names are present.
-
- ParseCertificate and
- CreateCertificate
- now enforce string encoding restrictions for the DNSNames,
- EmailAddresses, and URIs fields. 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.
-
- DSA signature verification is no longer supported. Note that DSA signature - generation was never supported. - See issue #40337. -
- -
- On Windows, Certificate.Verify
- will now return all certificate chains that are built by the platform
- certificate verifier, instead of just the highest ranked chain.
-
- The new SystemRootsError.Unwrap
- method allows accessing the Err
- field through the errors package functions.
-
- On Unix systems, the crypto/x509 package is now more
- efficient in how it stores its copy of the system cert pool.
- Programs that use only a small number of roots will use around a
- half megabyte less memory.
-
- Unmarshal and
- UnmarshalWithParams
- now return an error instead of panicking when the argument is not
- a pointer or is nil. This change matches the behavior of other
- encoding packages such as encoding/json.
-
- The json struct field tags understood by
- Marshal,
- Unmarshal,
- and related functionality now permit semicolon characters within
- a JSON object name for a Go struct field.
-
- The encoder has always taken care to avoid using namespace prefixes
- beginning with xml, which are reserved by the XML
- specification.
- Now, following the specification more closely, that check is
- case-insensitive, so that prefixes beginning
- with XML, XmL, and so on are also
- avoided.
-
- The new Func function
- allows registering a flag implemented by calling a function,
- as a lighter-weight alternative to implementing the
- Value interface.
-
- The Package
- struct has new fields that report information
- about //go:embed directives in the package:
- EmbedPatterns,
- EmbedPatternPos,
- TestEmbedPatterns,
- TestEmbedPatternPos,
- XTestEmbedPatterns,
- XTestEmbedPatternPos.
-
- The Package field
- IgnoredGoFiles
- will no longer include files that start with "_" or ".",
- as those files are always ignored.
- IgnoredGoFiles is for files ignored because of
- build constraints.
-
- The new Package
- field IgnoredOtherFiles
- has a list of non-Go files ignored because of build constraints.
-
- The new
- go/build/constraint
- package parses build constraint lines, both the original
- // +build syntax and the //go:build
- syntax that will be introduced in Go 1.17.
- This package exists so that tools built with Go 1.16 will be able
- to process Go 1.17 source code.
- See https://golang.org/design/draft-gobuild
- for details about the build constraint syntaxes and the planned
- transition to the //go:build syntax.
- Note that //go:build lines are not supported
- in Go 1.16 and should not be introduced into Go programs yet.
-
- The new template.ParseFS
- function and template.Template.ParseFS
- method are like template.ParseGlob
- and template.Template.ParseGlob,
- but read the templates from an fs.FS.
-
- The package now defines a
- ReadSeekCloser interface.
-
- The package now defines
- Discard,
- NopCloser, and
- ReadAll,
- to be used instead of the same names in the
- io/ioutil package.
-
- The Writer
- now uses the local message format
- (omitting the host name and using a shorter time stamp)
- when logging to custom Unix domain sockets,
- matching the format already used for the default log socket.
-
- The Reader's
- ReadForm
- method no longer rejects form data
- when passed the maximum int64 value as a limit.
-
- 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.
-
- On Linux, host name lookups no longer use DNS before checking
- /etc/hosts when /etc/nsswitch.conf
- is missing; this is common on musl-based systems and makes
- Go programs match the behavior of C programs on those systems.
-
- In the net/http package, the
- behavior of StripPrefix
- has been changed to strip the prefix from the request URL's
- RawPath field in addition to its Path field.
- In past releases, only the Path field was trimmed, and so if the
- request URL contained any escaped characters the URL would be modified to
- have mismatched Path and RawPath fields.
- In Go 1.16, StripPrefix trims both fields.
- If there are escaped characters in the prefix part of the request URL the
- handler serves a 404 instead of its previous behavior of invoking the
- underlying handler with a mismatched Path/RawPath pair.
-
- 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.
-
- The Client now sends
- an explicit Content-Length: 0
- header in PATCH requests with empty bodies,
- matching the existing behavior of POST and PUT.
-
- The ProxyFromEnvironment
- function no longer returns the setting of the HTTP_PROXY
- environment variable for https:// URLs when
- HTTPS_PROXY is unset.
-
- The Transport
- type has a new field
- GetProxyConnectHeader
- which may be set to a function that returns headers to send to a
- proxy during a CONNECT request.
- In effect GetProxyConnectHeader is a dynamic
- version of the existing field
- ProxyConnectHeader;
- if GetProxyConnectHeader is not nil,
- then ProxyConnectHeader is ignored.
-
- The new http.FS
- function converts an fs.FS
- to an http.FileSystem.
-
- ReverseProxy
- now flushes buffered data more aggressively when proxying
- streamed responses with unknown body lengths.
-
- The Client's
- Mail
- method now sends the SMTPUTF8 directive to
- servers that support it, signaling that addresses are encoded in UTF-8.
-
- Process.Signal now
- returns ErrProcessDone
- instead of the unexported errFinished when the process has
- already finished.
-
- The package defines a new type
- DirEntry
- as an alias for fs.DirEntry.
- The new ReadDir
- function and the new
- File.ReadDir
- method can be used to read the contents of a directory into a
- slice of DirEntry.
- The File.Readdir
- method (note the lower case d in dir)
- still exists, returning a slice of
- FileInfo, but for
- most programs it will be more efficient to switch to
- File.ReadDir.
-
- The package now defines
- CreateTemp,
- MkdirTemp,
- ReadFile, and
- WriteFile,
- to be used instead of functions defined in the
- io/ioutil package.
-
- The types FileInfo,
- FileMode, and
- PathError
- are now aliases for types of the same name in the
- io/fs package.
- Function signatures in the os
- package have been updated to refer to the names in the
- io/fs package.
- This should not affect any existing code.
-
- The new DirFS function
- provides an implementation of
- fs.FS backed by a tree
- of operating system files.
-
- The new
- NotifyContext
- function allows creating contexts that are canceled upon arrival of
- specific signals.
-
- The Match function now
- returns an error if the unmatched part of the pattern has a
- syntax error. Previously, the function returned early on a failed
- match, and thus did not report any later syntax error in the
- pattern.
-
- The new function
- WalkDir
- is similar to
- Walk,
- but is typically more efficient.
- The function passed to WalkDir receives a
- fs.DirEntry
- instead of a
- fs.FileInfo.
- (To clarify for those who recall the Walk function
- as taking an os.FileInfo,
- os.FileInfo is now an alias for fs.FileInfo.)
-
- The Match and
- Glob functions now
- return an error if the unmatched part of the pattern has a
- syntax error. Previously, the functions returned early on a failed
- match, and thus did not report any later syntax error in the
- pattern.
-
- The runtime.Error values
- used when SetPanicOnFault is enabled may now have an
- Addr method. If that method exists, it returns the memory
- address that triggered the fault.
-
- 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.
-
- NewCallback
- and
- NewCallbackCDecl
- now correctly support callback functions with multiple
- sub-uintptr-sized arguments in a row. This may
- require changing uses of these functions to eliminate manual
- padding between small arguments.
-
- SysProcAttr on Windows has a new NoInheritHandles field that disables inheriting handles when creating a new process.
-
- DLLError on Windows now has an Unwrap method for unwrapping its underlying error.
-
- On Linux,
- Setgid,
- Setuid,
- and related calls are now implemented.
- Previously, they returned an syscall.EOPNOTSUPP error.
-
- On Linux, the new functions
- AllThreadsSyscall
- and AllThreadsSyscall6
- may be used to make a system call on all Go threads in the process.
- These functions may only be used by programs that do not use cgo;
- if a program uses cgo, they will always return
- syscall.ENOTSUP.
-
- The new
- ErrReader
- function returns an
- io.Reader that always
- returns an error.
-
- The new
- TestReader
- function tests that an io.Reader
- behaves correctly.
-
- Newlines characters are now allowed inside action delimiters, - permitting actions to span multiple lines. -
- -
- The new template.ParseFS
- function and template.Template.ParseFS
- method are like template.ParseGlob
- and template.Template.ParseGlob,
- but read the templates from an fs.FS.
-
- A new CommentNode
- was added to the parse tree. The Mode
- field in the parse.Tree enables access to it.
-
- 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 timezone database by about 350 KB.
-
- 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.
-
+ + Go 1.17 is not yet released. These are work-in-progress + release notes. Go 1.17 is expected to be released in August 2021. + +
+ ++ TODO: https://golang.org/cl/216424: allow conversion from slice to array ptr +
+ ++ TODO: https://golang.org/cl/312212: add unsafe.Add and unsafe.Slice +
+ ++ As announced in the Go 1.16 release + notes, Go 1.17 requires macOS 10.13 High Sierra or later; support + for previous versions has been discontinued. +
+ ++ TODO: complete the Ports section +
+ ++ TODO: complete the Tools section +
+ +
+ If a module specifies go 1.17 or higher in its
+ go.mod file, its transitive requirements are now loaded lazily,
+ avoding the need to download or read go.mod files for
+ otherwise-irrelevant dependencies. To support lazy loading, in Go 1.17 modules
+ the go command maintains explicit requirements in
+ the go.mod file for every dependency that provides any package
+ transitively imported by any package or test within the module.
+ See the design
+ document for more detail.
+
+
To facilitate the upgrade to lazy loading,
+ the go mod tidy subcommand now supports
+ a -go flag to set or change the go version in
+ the go.mod file. To enable lazy loading for an existing module
+ without changing the selected versions of its dependencies, run:
+
+ go mod tidy -go=1.17 ++ +
+ Module authors may deprecate a module by adding a
+ // Deprecated:
+ comment to go.mod, then tagging a new version.
+ go get now prints a warning if a module needed to
+ build packages named on the command line is deprecated. go
+ list -m -u prints deprecations for all
+ dependencies (use -f or -json to show the full
+ message). The go command considers different major versions to
+ be distinct modules, so this mechanism may be used, for example, to provide
+ users with migration instructions for a new major version.
+
go get
+ The go get -insecure flag is
+ deprecated and has been removed. To permit the use of insecure schemes
+ when fetching dependencies, please use the GOINSECURE
+ environment variable. The -insecure flag also bypassed module
+ sum validation, use GOPRIVATE or GONOSUMDB if
+ you need that functionality. See go help
+ environment for details.
+
go.mod files missing go directives
+ If the main module's go.mod file does not contain
+ a go directive and
+ the go command cannot update the go.mod file, the
+ go command now assumes go 1.11 instead of the
+ current release. (go mod init has added
+ go directives automatically since
+ Go 1.12.)
+
+ If a module dependency lacks an explicit go.mod file, or
+ its go.mod file does not contain
+ a go directive,
+ the go command now assumes go 1.16 for that
+ dependency instead of the current release. (Dependencies developed in GOPATH
+ mode may lack a go.mod file, and
+ the vendor/modules.txt has to date never recorded
+ the go versions indicated by dependencies' go.mod
+ files.)
+
vendor contents
+ If the main module specifies go 1.17 or higher,
+ go mod vendor now annotates
+ vendor/modules.txt with the go version indicated by
+ each vendored module in its own go.mod file. The annotated
+ version is used when building the module's packages from vendored source code.
+
+ If the main module specifies go 1.17 or higher,
+ go mod vendor now omits go.mod
+ and go.sum files for vendored dependencies, which can otherwise
+ interfere with the ability of the go command to identify the correct
+ module root when invoked within the vendor tree.
+
+ The go command by default now suppresses SSH password prompts and
+ Git Credential Manager prompts when fetching Git repositories using SSH, as it
+ already did previously for other Git password prompts. Users authenticating to
+ private Git repos with password-protected SSH may configure
+ an ssh-agent to enable the go command to use
+ password-protected SSH keys.
+
+ TODO: https://golang.org/cl/249759: cmd/cover: replace code using optimized golang.org/x/tools/cover +
+ ++ TODO: https://golang.org/cl/299532: cmd/vet: bring in sigchanyzer to report unbuffered channels to signal.Notify +
+ ++ TODO: complete the Vet section +
+ ++ TODO: https://golang.org/cl/304470: cmd/compile, runtime: add metadata for argument printing in traceback +
+ ++ TODO: complete the Runtime section +
+ ++ TODO: complete the Compiler section, or delete if not needed +
+ ++ TODO: complete the Linker section, or delete if not needed +
+ ++ TODO: complete the Core library section +
+ ++ (*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. +
+ +
+ When Config.NextProtos is set, servers now
+ enforce that there is an overlap between the configured protocols and the protocols
+ advertised by the client, if any. If there is no overlap the connection is closed
+ with the no_application_protocol alert, as required by RFC 7301.
+
+ The runtime/cgo package now provides a + new facility that allows to turn any Go values to a safe representation + that can be used to pass values between C and Go safely. See + runtime/cgo.Handle for more information. +
+ ++ As always, there are various minor changes and updates to the library, + made with the Go 1 promise of compatibility + in mind. +
+ ++ TODO: https://golang.org/cl/312310: add File.OpenRaw, Writer.CreateRaw, Writer.Copy +
+
+ The Writer.WriteRune method
+ now writes the replacement character U+FFFD for negative rune values,
+ as it does for other invalid runes.
+
+ The Buffer.WriteRune method
+ now writes the replacement character U+FFFD for negative rune values,
+ as it does for other invalid runes.
+
+ The new
+ Reader.Reset
+ and
+ Writer.Reset
+ methods allow reuse of a Reader or Writer.
+
+ TODO: https://golang.org/cl/302230: fix salt length calculation with PSSSaltLengthAuto +
++ TODO: https://golang.org/cl/258360: close driver.Connector if it implements io.Closer +
+ ++ TODO: https://golang.org/cl/311572: add NullInt16 and NullByte +
+
+ binary.Uvarint will stop reading after 10 bytes to avoid
+ wasted computations. If more than 10 bytes are needed, the byte count returned is -11.
+
+ Previous Go versions could return larger negative counts when reading incorrectly encoded varints.
+
+ TODO: https://golang.org/cl/271788: panic if flag name begins with - or contains = +
++ TODO: https://golang.org/cl/293649: implement FileInfoToDirEntry +
++ TODO: https://golang.org/cl/247058: add MaxUint, MinInt, MaxInt +
++ TODO: https://golang.org/cl/305230: support reading shared mime-info database on unix systems +
++ TODO: https://golang.org/cl/272668: add IP.IsPrivate +
+ ++ TODO: https://golang.org/cl/301709: make go resolver aware of network parameter +
+ ++ TODO: https://golang.org/cl/307030: make ErrClosed and ParseError implement net.Error +
+
+ The net/http package now uses the new
+ (*tls.Conn).HandshakeContext
+ with the Request context
+ when performing TLS handshakes in the client or server.
+
+ TODO: https://golang.org/cl/235437: add to deadlines only when positive +
+ ++ TODO: https://golang.org/cl/308952: make ReadRequest return an error when requests have multiple Host headers +
++ TODO: https://golang.org/cl/308950: panic on non-3 digit (XXX) status code in Recorder.WriteHeader +
++ TODO: https://golang.org/cl/314850: add Values.Has +
++ TODO: https://golang.org/cl/268020: avoid allocation in File.WriteString +
+
+ The new
+ StructField.IsExported
+ and
+ Method.IsExported
+ methods report whether a struct field or type method is exported.
+ They provide a more readable alternative to checking whether PkgPath
+ is empty.
+
+ TODO: https://golang.org/cl/281233: add VisibleFields function +
+ ++ TODO: https://golang.org/cl/284136: panic if ArrayOf is called with negative length +
++ TODO: https://golang.org/cl/170079: implement Ryū-like algorithm for fixed precision ftoa +
+ ++ TODO: https://golang.org/cl/170080: Implement Ryū algorithm for ftoa shortest mode +
+ +
+ The new QuotedPrefix function
+ returns the quoted string (as understood by
+ Unquote)
+ at the start of input.
+
+ The Builder.WriteRune method
+ now writes the replacement character U+FFFD for negative rune values,
+ as it does for other invalid runes.
+
+ TODO: https://golang.org/cl/241678: add (*Value).Swap and (*Value).CompareAndSwap +
++ TODO: https://golang.org/cl/295371: do not overflow key memory in GetQueuedCompletionStatus +
+ ++ TODO: https://golang.org/cl/313653: restore signal mask after setting foreground process group +
++ TODO: https://golang.org/cl/310033: add -shuffle=off|on|N to alter the execution order of tests and benchmarks +
++ TODO: https://golang.org/cl/301493: add a mode to skip func-check on parsing +
+
+ time.Time now has a GoString
+ method that will return a more useful value for times when printed with
+ the "%#v" format specifier in the fmt package.
+
+ TODO: https://golang.org/cl/264077: add Time.IsDST() to check if its Location is in Daylight Savings Time +
+ ++ TODO: https://golang.org/cl/293349: add Time.Unix{Milli,Micro} and to-Time helpers UnixMicro, UnixMilli +
+ ++ TODO: https://golang.org/cl/300996: support "," as separator for fractional seconds +
+
+ The Is,
+ IsGraphic,
+ IsLetter,
+ IsLower,
+ IsMark,
+ IsNumber,
+ IsPrint,
+ IsPunct,
+ IsSpace,
+ IsSymbol, and
+ IsUpper functions
+ now return false on negative rune values, as they do for other invalid runes.
+
[]B1, B3, and B4 i
-A type may have a method set associated with it.
+A type has a (possibly empty) method set associated with it.
The method set of an interface type is its interface.
The method set of any other type T consists of all
methods declared with receiver type T.
@@ -3532,9 +3532,9 @@ within Greeting, who will have the value
-If the final argument is assignable to a slice type []T, it is
-passed unchanged as the value for a ...T parameter if the argument
-is followed by .... In this case no new slice is created.
+If the final argument is assignable to a slice type []T and
+is followed by ..., it is passed unchanged as the value
+for a ...T parameter. In this case no new slice is created.
@@ -3681,8 +3681,8 @@ The bitwise logical and shift operators apply to integers only. ^ bitwise XOR integers &^ bit clear (AND NOT) integers -<< left shift integer << unsigned integer ->> right shift integer >> unsigned integer +<< left shift integer << integer >= 0 +>> right shift integer >> integer >= 0 @@ -4164,6 +4164,10 @@ in any of these cases:
x is a string and T is a slice of bytes or runes.
x is a slice, T is a pointer to an array,
+ and the slice and array types have identical element types.
+ @@ -4314,6 +4318,24 @@ MyRunes("白鵬翔") // []rune{0x767d, 0x9d6c, 0x7fd4} +
+Converting a slice to an array pointer yields a pointer to the underlying array of the slice. +If the length of the slice is less than the length of the array, +a run-time panic occurs. +
+ ++s := make([]byte, 2, 4) +s0 := (*[0]byte)(s) // s0 != nil +s2 := (*[2]byte)(s) // &s2[0] == &s[0] +s4 := (*[4]byte)(s) // panics: len([4]byte) > len(s) + +var t []string +t0 := (*[0]string)(t) // t0 == nil +t1 := (*[1]string)(t) // panics: len([1]string) > len(s) +
If the switch expression evaluates to an untyped constant, it is first implicitly
-converted to its default type;
-if it is an untyped boolean value, it is first implicitly converted to type bool.
+converted to its default type.
The predeclared untyped value nil cannot be used as a switch expression.
+The switch expression type must be comparable.
@@ -6689,6 +6711,10 @@ type Pointer *ArbitraryType func Alignof(variable ArbitraryType) uintptr func Offsetof(selector ArbitraryType) uintptr func Sizeof(variable ArbitraryType) uintptr + +type IntegerType int // shorthand for an integer type; it is not a real type +func Add(ptr Pointer, len IntegerType) Pointer +func Slice(ptr *ArbitraryType, len IntegerType) []ArbitraryType
@@ -6745,6 +6771,32 @@ Calls to Alignof, Offsetof, and
Sizeof are compile-time constant expressions of type uintptr.
+The function Add adds len to ptr
+and returns the updated pointer unsafe.Pointer(uintptr(ptr) + uintptr(len)).
+The len argument must be of integer type or an untyped constant.
+A constant len argument must be representable by a value of type int;
+if it is an untyped constant it is given type int.
+The rules for valid uses of Pointer still apply.
+
+The function Slice returns a slice whose underlying array starts at ptr
+and whose length and capacity are len:
+
+(*[len]ArbitraryType)(unsafe.Pointer(ptr))[:] ++ +
+The len argument must be of integer type or an untyped constant.
+A constant len argument must be non-negative and representable by a value of type int;
+if it is an untyped constant it is given type int.
+If ptr is nil or len is negative at run time,
+a run-time panic occurs.
+
diff --git a/favicon.ico b/favicon.ico
deleted file mode 100644
index 8d225846dbc..00000000000
Binary files a/favicon.ico and /dev/null differ
diff --git a/misc/android/go_android_exec.go b/misc/android/go_android_exec.go
index 7aa7fe56fc5..3af2bee5839 100644
--- a/misc/android/go_android_exec.go
+++ b/misc/android/go_android_exec.go
@@ -14,7 +14,6 @@ import (
"fmt"
"go/build"
"io"
- "io/ioutil"
"log"
"os"
"os/exec"
@@ -276,7 +275,7 @@ func adbCopyGoroot() error {
if err := syscall.Flock(int(stat.Fd()), syscall.LOCK_EX); err != nil {
return err
}
- s, err := ioutil.ReadAll(stat)
+ s, err := io.ReadAll(stat)
if err != nil {
return err
}
@@ -294,7 +293,7 @@ func adbCopyGoroot() error {
goroot := runtime.GOROOT()
// Build go for android.
goCmd := filepath.Join(goroot, "bin", "go")
- tmpGo, err := ioutil.TempFile("", "go_android_exec-cmd-go-*")
+ tmpGo, err := os.CreateTemp("", "go_android_exec-cmd-go-*")
if err != nil {
return err
}
diff --git a/misc/cgo/errors/argposition_test.go b/misc/cgo/errors/argposition_test.go
new file mode 100644
index 00000000000..331095f7473
--- /dev/null
+++ b/misc/cgo/errors/argposition_test.go
@@ -0,0 +1,134 @@
+// 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.
+
+// Issue 42580: cmd/cgo: shifting identifier position in ast
+
+package errorstest
+
+import (
+ "bytes"
+ "fmt"
+ "go/ast"
+ "go/parser"
+ "go/token"
+ "io/ioutil"
+ "os"
+ "os/exec"
+ "path/filepath"
+ "strings"
+ "testing"
+)
+
+type ShortPosition struct {
+ Line int
+ Column int
+ Visited bool
+}
+
+type IdentPositionInfo map[string][]ShortPosition
+
+type Visitor struct {
+ identPosInfo IdentPositionInfo
+ fset *token.FileSet
+ t *testing.T
+}
+
+func (v *Visitor) Visit(node ast.Node) ast.Visitor {
+ if ident, ok := node.(*ast.Ident); ok {
+ if expectedPositions, ok := v.identPosInfo[ident.Name]; ok {
+ gotMatch := false
+ var errorMessage strings.Builder
+ for caseIndex, expectedPos := range expectedPositions {
+ actualPosition := v.fset.PositionFor(ident.Pos(), true)
+ errorOccured := false
+ if expectedPos.Line != actualPosition.Line {
+ fmt.Fprintf(&errorMessage, "wrong line number for ident %s: expected: %d got: %d\n", ident.Name, expectedPos.Line, actualPosition.Line)
+ errorOccured = true
+ }
+ if expectedPos.Column != actualPosition.Column {
+ fmt.Fprintf(&errorMessage, "wrong column number for ident %s: expected: %d got: %d\n", ident.Name, expectedPos.Column, actualPosition.Column)
+ errorOccured = true
+ }
+ if errorOccured {
+ continue
+ }
+ gotMatch = true
+ expectedPositions[caseIndex].Visited = true
+ }
+
+ if !gotMatch {
+ v.t.Errorf(errorMessage.String())
+ }
+ }
+ }
+ return v
+}
+
+func TestArgumentsPositions(t *testing.T) {
+ testdata, err := filepath.Abs("testdata")
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ tmpPath := t.TempDir()
+
+ dir := filepath.Join(tmpPath, "src", "testpositions")
+ if err := os.MkdirAll(dir, 0755); err != nil {
+ t.Fatal(err)
+ }
+
+ cmd := exec.Command("go", "tool", "cgo",
+ "-srcdir", testdata,
+ "-objdir", dir,
+ "issue42580.go")
+ cmd.Stderr = new(bytes.Buffer)
+
+ err = cmd.Run()
+ if err != nil {
+ t.Fatalf("%s: %v\n%s", cmd, err, cmd.Stderr)
+ }
+ mainProcessed, err := ioutil.ReadFile(filepath.Join(dir, "issue42580.cgo1.go"))
+ if err != nil {
+ t.Fatal(err)
+ }
+ fset := token.NewFileSet()
+ f, err := parser.ParseFile(fset, "", mainProcessed, parser.AllErrors)
+ if err != nil {
+ fmt.Println(err)
+ return
+ }
+
+ expectation := IdentPositionInfo{
+ "checkedPointer": []ShortPosition{
+ ShortPosition{
+ Line: 32,
+ Column: 56,
+ },
+ },
+ "singleInnerPointerChecked": []ShortPosition{
+ ShortPosition{
+ Line: 37,
+ Column: 91,
+ },
+ },
+ "doublePointerChecked": []ShortPosition{
+ ShortPosition{
+ Line: 42,
+ Column: 91,
+ },
+ },
+ }
+ for _, decl := range f.Decls {
+ if fdecl, ok := decl.(*ast.FuncDecl); ok {
+ ast.Walk(&Visitor{expectation, fset, t}, fdecl.Body)
+ }
+ }
+ for ident, positions := range expectation {
+ for _, position := range positions {
+ if !position.Visited {
+ t.Errorf("Position %d:%d missed for %s ident", position.Line, position.Column, ident)
+ }
+ }
+ }
+}
diff --git a/misc/cgo/errors/badsym_test.go b/misc/cgo/errors/badsym_test.go
index b2701bf922e..fc687567bf7 100644
--- a/misc/cgo/errors/badsym_test.go
+++ b/misc/cgo/errors/badsym_test.go
@@ -6,7 +6,6 @@ package errorstest
import (
"bytes"
- "io/ioutil"
"os"
"os/exec"
"path/filepath"
@@ -55,7 +54,7 @@ func TestBadSymbol(t *testing.T) {
makeFile := func(mdir, base, source string) string {
ret := filepath.Join(mdir, base)
- if err := ioutil.WriteFile(ret, []byte(source), 0644); err != nil {
+ if err := os.WriteFile(ret, []byte(source), 0644); err != nil {
t.Fatal(err)
}
return ret
@@ -100,7 +99,7 @@ func TestBadSymbol(t *testing.T) {
// _cgo_import.go.
rewrite := func(from, to string) {
- obj, err := ioutil.ReadFile(from)
+ obj, err := os.ReadFile(from)
if err != nil {
t.Fatal(err)
}
@@ -115,7 +114,7 @@ func TestBadSymbol(t *testing.T) {
obj = bytes.ReplaceAll(obj, []byte(magicInput), []byte(magicReplace))
- if err := ioutil.WriteFile(to, obj, 0644); err != nil {
+ if err := os.WriteFile(to, obj, 0644); err != nil {
t.Fatal(err)
}
}
diff --git a/misc/cgo/errors/errors_test.go b/misc/cgo/errors/errors_test.go
index 1bdf843451d..a077b594786 100644
--- a/misc/cgo/errors/errors_test.go
+++ b/misc/cgo/errors/errors_test.go
@@ -7,7 +7,6 @@ package errorstest
import (
"bytes"
"fmt"
- "io/ioutil"
"os"
"os/exec"
"path/filepath"
@@ -25,7 +24,7 @@ func check(t *testing.T, file string) {
t.Run(file, func(t *testing.T) {
t.Parallel()
- contents, err := ioutil.ReadFile(path(file))
+ contents, err := os.ReadFile(path(file))
if err != nil {
t.Fatal(err)
}
@@ -56,7 +55,7 @@ func check(t *testing.T, file string) {
}
func expect(t *testing.T, file string, errors []*regexp.Regexp) {
- dir, err := ioutil.TempDir("", filepath.Base(t.Name()))
+ dir, err := os.MkdirTemp("", filepath.Base(t.Name()))
if err != nil {
t.Fatal(err)
}
diff --git a/misc/cgo/errors/ptr_test.go b/misc/cgo/errors/ptr_test.go
index 4a46b6023bb..0f39dc8e547 100644
--- a/misc/cgo/errors/ptr_test.go
+++ b/misc/cgo/errors/ptr_test.go
@@ -10,7 +10,6 @@ import (
"bytes"
"flag"
"fmt"
- "io/ioutil"
"os"
"os/exec"
"path/filepath"
@@ -463,7 +462,7 @@ func buildPtrTests(t *testing.T) (dir, exe string) {
gopath = *tmp
dir = ""
} else {
- d, err := ioutil.TempDir("", filepath.Base(t.Name()))
+ d, err := os.MkdirTemp("", filepath.Base(t.Name()))
if err != nil {
t.Fatal(err)
}
@@ -475,7 +474,7 @@ func buildPtrTests(t *testing.T) (dir, exe string) {
if err := os.MkdirAll(src, 0777); err != nil {
t.Fatal(err)
}
- if err := ioutil.WriteFile(filepath.Join(src, "go.mod"), []byte("module ptrtest"), 0666); err != nil {
+ if err := os.WriteFile(filepath.Join(src, "go.mod"), []byte("module ptrtest"), 0666); err != nil {
t.Fatal(err)
}
@@ -535,10 +534,10 @@ func buildPtrTests(t *testing.T) (dir, exe string) {
fmt.Fprintf(&cgo1, "}\n\n")
fmt.Fprintf(&cgo1, "%s\n", ptrTestMain)
- if err := ioutil.WriteFile(filepath.Join(src, "cgo1.go"), cgo1.Bytes(), 0666); err != nil {
+ if err := os.WriteFile(filepath.Join(src, "cgo1.go"), cgo1.Bytes(), 0666); err != nil {
t.Fatal(err)
}
- if err := ioutil.WriteFile(filepath.Join(src, "cgo2.go"), cgo2.Bytes(), 0666); err != nil {
+ if err := os.WriteFile(filepath.Join(src, "cgo2.go"), cgo2.Bytes(), 0666); err != nil {
t.Fatal(err)
}
diff --git a/misc/cgo/errors/testdata/issue42580.go b/misc/cgo/errors/testdata/issue42580.go
new file mode 100644
index 00000000000..aba80dfebad
--- /dev/null
+++ b/misc/cgo/errors/testdata/issue42580.go
@@ -0,0 +1,44 @@
+// 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.
+
+// Issue 42580: cmd/cgo: shifting identifier position in ast
+
+package cgotest
+
+// typedef int (*intFunc) ();
+//
+// char* strarg = "";
+//
+// int func_with_char(char* arg, void* dummy)
+// {return 5;}
+//
+// int* get_arr(char* arg, void* dummy)
+// {return NULL;}
+import "C"
+import "unsafe"
+
+// Test variables
+var (
+ checkedPointer = []byte{1}
+ doublePointerChecked = []byte{1}
+ singleInnerPointerChecked = []byte{1}
+)
+
+// This test checks the positions of variable identifiers.
+// Changing the positions of the test variables idents after this point will break the test.
+
+func TestSingleArgumentCast() C.int {
+ retcode := C.func_with_char((*C.char)(unsafe.Pointer(&checkedPointer[0])), unsafe.Pointer(C.strarg))
+ return retcode
+}
+
+func TestSingleArgumentCastRecFuncAsSimpleArg() C.int {
+ retcode := C.func_with_char((*C.char)(unsafe.Pointer(C.get_arr((*C.char)(unsafe.Pointer(&singleInnerPointerChecked[0])), unsafe.Pointer(C.strarg)))), nil)
+ return retcode
+}
+
+func TestSingleArgumentCastRecFunc() C.int {
+ retcode := C.func_with_char((*C.char)(unsafe.Pointer(C.get_arr((*C.char)(unsafe.Pointer(&doublePointerChecked[0])), unsafe.Pointer(C.strarg)))), unsafe.Pointer(C.strarg))
+ return retcode
+}
diff --git a/misc/cgo/life/life_test.go b/misc/cgo/life/life_test.go
index 3c95d87d8ad..0becb262b43 100644
--- a/misc/cgo/life/life_test.go
+++ b/misc/cgo/life/life_test.go
@@ -6,7 +6,6 @@ package life_test
import (
"bytes"
- "io/ioutil"
"log"
"os"
"os/exec"
@@ -21,7 +20,7 @@ func TestMain(m *testing.M) {
}
func testMain(m *testing.M) int {
- GOPATH, err := ioutil.TempDir("", "cgolife")
+ GOPATH, err := os.MkdirTemp("", "cgolife")
if err != nil {
log.Panic(err)
}
@@ -38,7 +37,7 @@ func testMain(m *testing.M) int {
log.Panic(err)
}
os.Setenv("PWD", modRoot)
- if err := ioutil.WriteFile("go.mod", []byte("module cgolife\n"), 0666); err != nil {
+ if err := os.WriteFile("go.mod", []byte("module cgolife\n"), 0666); err != nil {
log.Panic(err)
}
diff --git a/misc/cgo/stdio/stdio_test.go b/misc/cgo/stdio/stdio_test.go
index ab5d328f676..675418f98d0 100644
--- a/misc/cgo/stdio/stdio_test.go
+++ b/misc/cgo/stdio/stdio_test.go
@@ -6,7 +6,6 @@ package stdio_test
import (
"bytes"
- "io/ioutil"
"log"
"os"
"os/exec"
@@ -21,7 +20,7 @@ func TestMain(m *testing.M) {
}
func testMain(m *testing.M) int {
- GOPATH, err := ioutil.TempDir("", "cgostdio")
+ GOPATH, err := os.MkdirTemp("", "cgostdio")
if err != nil {
log.Panic(err)
}
@@ -38,7 +37,7 @@ func testMain(m *testing.M) int {
log.Panic(err)
}
os.Setenv("PWD", modRoot)
- if err := ioutil.WriteFile("go.mod", []byte("module cgostdio\n"), 0666); err != nil {
+ if err := os.WriteFile("go.mod", []byte("module cgostdio\n"), 0666); err != nil {
log.Panic(err)
}
diff --git a/misc/cgo/test/cgo_test.go b/misc/cgo/test/cgo_test.go
index f7a76d047bd..143f23f0e0c 100644
--- a/misc/cgo/test/cgo_test.go
+++ b/misc/cgo/test/cgo_test.go
@@ -59,6 +59,7 @@ func Test28896(t *testing.T) { test28896(t) }
func Test30065(t *testing.T) { test30065(t) }
func Test32579(t *testing.T) { test32579(t) }
func Test31891(t *testing.T) { test31891(t) }
+func Test45451(t *testing.T) { test45451(t) }
func TestAlign(t *testing.T) { testAlign(t) }
func TestAtol(t *testing.T) { testAtol(t) }
func TestBlocking(t *testing.T) { testBlocking(t) }
@@ -80,6 +81,7 @@ func TestNamedEnum(t *testing.T) { testNamedEnum(t) }
func TestCastToEnum(t *testing.T) { testCastToEnum(t) }
func TestErrno(t *testing.T) { testErrno(t) }
func TestFpVar(t *testing.T) { testFpVar(t) }
+func TestHandle(t *testing.T) { testHandle(t) }
func TestHelpers(t *testing.T) { testHelpers(t) }
func TestLibgcc(t *testing.T) { testLibgcc(t) }
func TestMultipleAssign(t *testing.T) { testMultipleAssign(t) }
diff --git a/misc/cgo/test/issue1435.go b/misc/cgo/test/issue1435.go
index a1c7cacde73..cf34ce8db6c 100644
--- a/misc/cgo/test/issue1435.go
+++ b/misc/cgo/test/issue1435.go
@@ -8,7 +8,7 @@ package cgotest
import (
"fmt"
- "io/ioutil"
+ "os"
"strings"
"syscall"
"testing"
@@ -64,7 +64,7 @@ import "C"
func compareStatus(filter, expect string) error {
expected := filter + expect
pid := syscall.Getpid()
- fs, err := ioutil.ReadDir(fmt.Sprintf("/proc/%d/task", pid))
+ fs, err := os.ReadDir(fmt.Sprintf("/proc/%d/task", pid))
if err != nil {
return fmt.Errorf("unable to find %d tasks: %v", pid, err)
}
@@ -72,7 +72,7 @@ func compareStatus(filter, expect string) error {
foundAThread := false
for _, f := range fs {
tf := fmt.Sprintf("/proc/%s/status", f.Name())
- d, err := ioutil.ReadFile(tf)
+ d, err := os.ReadFile(tf)
if err != nil {
// There are a surprising number of ways this
// can error out on linux. We've seen all of
diff --git a/misc/cgo/test/issue6997_linux.go b/misc/cgo/test/issue6997_linux.go
index 0c98ea0794e..f19afb8b7ad 100644
--- a/misc/cgo/test/issue6997_linux.go
+++ b/misc/cgo/test/issue6997_linux.go
@@ -5,7 +5,7 @@
// +build !android
// Test that pthread_cancel works as expected
-// (NPTL uses SIGRTMIN to implement thread cancelation)
+// (NPTL uses SIGRTMIN to implement thread cancellation)
// See https://golang.org/issue/6997
package cgotest
@@ -17,8 +17,10 @@ extern int CancelThread();
*/
import "C"
-import "testing"
-import "time"
+import (
+ "testing"
+ "time"
+)
func test6997(t *testing.T) {
r := C.StartThread()
diff --git a/misc/cgo/test/issue8148.c b/misc/cgo/test/issue8148.c
new file mode 100644
index 00000000000..927b4346cbe
--- /dev/null
+++ b/misc/cgo/test/issue8148.c
@@ -0,0 +1,11 @@
+// Copyright 2014 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+#include "_cgo_export.h"
+
+int get8148(void) {
+ T t;
+ t.i = 42;
+ return issue8148Callback(&t);
+}
diff --git a/misc/cgo/test/issue8148.go b/misc/cgo/test/issue8148.go
index f704788aef8..aee9003d507 100644
--- a/misc/cgo/test/issue8148.go
+++ b/misc/cgo/test/issue8148.go
@@ -10,14 +10,7 @@ package cgotest
/*
typedef struct { int i; } T;
-
-int issue8148Callback(T*);
-
-static int get() {
- T t;
- t.i = 42;
- return issue8148Callback(&t);
-}
+int get8148(void);
*/
import "C"
@@ -27,5 +20,5 @@ func issue8148Callback(t *C.T) C.int {
}
func Issue8148() int {
- return int(C.get())
+ return int(C.get8148())
}
diff --git a/misc/cgo/test/pkg_test.go b/misc/cgo/test/pkg_test.go
index 94abaa03e8d..14013a4cd96 100644
--- a/misc/cgo/test/pkg_test.go
+++ b/misc/cgo/test/pkg_test.go
@@ -5,7 +5,6 @@
package cgotest
import (
- "io/ioutil"
"os"
"os/exec"
"path/filepath"
@@ -37,7 +36,7 @@ func TestCrossPackageTests(t *testing.T) {
}
}
- GOPATH, err := ioutil.TempDir("", "cgotest")
+ GOPATH, err := os.MkdirTemp("", "cgotest")
if err != nil {
t.Fatal(err)
}
@@ -47,7 +46,7 @@ func TestCrossPackageTests(t *testing.T) {
if err := overlayDir(modRoot, "testdata"); err != nil {
t.Fatal(err)
}
- if err := ioutil.WriteFile(filepath.Join(modRoot, "go.mod"), []byte("module cgotest\n"), 0666); err != nil {
+ if err := os.WriteFile(filepath.Join(modRoot, "go.mod"), []byte("module cgotest\n"), 0666); err != nil {
t.Fatal(err)
}
diff --git a/misc/cgo/test/setgid_linux.go b/misc/cgo/test/setgid_linux.go
index 6773f94d3d6..7c64946cb34 100644
--- a/misc/cgo/test/setgid_linux.go
+++ b/misc/cgo/test/setgid_linux.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// Test that setgid does not hang on GNU/Linux.
+// Test that setgid does not hang on Linux.
// See https://golang.org/issue/3871 for details.
package cgotest
diff --git a/misc/cgo/test/test.go b/misc/cgo/test/test.go
index 65823b1ca0e..3b8f548b13d 100644
--- a/misc/cgo/test/test.go
+++ b/misc/cgo/test/test.go
@@ -899,6 +899,10 @@ static uint16_t issue31093F(uint16_t v) { return v; }
// issue 32579
typedef struct S32579 { unsigned char data[1]; } S32579;
+// issue 37033, cgo.Handle
+extern void GoFunc37033(uintptr_t handle);
+void cFunc37033(uintptr_t handle) { GoFunc37033(handle); }
+
// issue 38649
// Test that #define'd type aliases work.
#define netbsd_gid unsigned int
@@ -908,6 +912,9 @@ typedef struct S32579 { unsigned char data[1]; } S32579;
enum Enum40494 { X_40494 };
union Union40494 { int x; };
void issue40494(enum Enum40494 e, union Union40494* up) {}
+
+// Issue 45451, bad handling of go:notinheap types.
+typedef struct issue45451Undefined issue45451;
*/
import "C"
@@ -920,6 +927,7 @@ import (
"os/signal"
"reflect"
"runtime"
+ "runtime/cgo"
"sync"
"syscall"
"testing"
@@ -2230,6 +2238,23 @@ func test32579(t *testing.T) {
}
}
+// issue 37033, check if cgo.Handle works properly
+
+func testHandle(t *testing.T) {
+ ch := make(chan int)
+
+ for i := 0; i < 42; i++ {
+ h := cgo.NewHandle(ch)
+ go func() {
+ C.cFunc37033(C.uintptr_t(h))
+ }()
+ if v := <-ch; issue37033 != v {
+ t.Fatalf("unexpected receiving value: got %d, want %d", v, issue37033)
+ }
+ h.Delete()
+ }
+}
+
// issue 38649
var issue38649 C.netbsd_gid = 42
@@ -2244,3 +2269,19 @@ var issue39877 *C.void = nil
func Issue40494() {
C.issue40494(C.enum_Enum40494(C.X_40494), (*C.union_Union40494)(nil))
}
+
+// Issue 45451.
+func test45451(t *testing.T) {
+ var u *C.issue45451
+ typ := reflect.ValueOf(u).Type().Elem()
+
+ // The type is undefined in C so allocating it should panic.
+ defer func() {
+ if r := recover(); r == nil {
+ t.Error("expected panic")
+ }
+ }()
+
+ _ = reflect.New(typ)
+ t.Errorf("reflect.New(%v) should have panicked", typ)
+}
diff --git a/misc/cgo/test/testdata/issue9400/asm_386.s b/misc/cgo/test/testdata/issue9400/asm_386.s
index 7f158b5c39d..96b8b60c10f 100644
--- a/misc/cgo/test/testdata/issue9400/asm_386.s
+++ b/misc/cgo/test/testdata/issue9400/asm_386.s
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build !gccgo
+// +build gc
#include "textflag.h"
diff --git a/misc/cgo/test/testdata/issue9400/asm_amd64x.s b/misc/cgo/test/testdata/issue9400/asm_amd64x.s
index 48b86190a59..99509bce5e1 100644
--- a/misc/cgo/test/testdata/issue9400/asm_amd64x.s
+++ b/misc/cgo/test/testdata/issue9400/asm_amd64x.s
@@ -3,7 +3,7 @@
// license that can be found in the LICENSE file.
// +build amd64 amd64p32
-// +build !gccgo
+// +build gc
#include "textflag.h"
diff --git a/misc/cgo/test/testdata/issue9400/asm_arm.s b/misc/cgo/test/testdata/issue9400/asm_arm.s
index 96c278520f3..cc92856c2ff 100644
--- a/misc/cgo/test/testdata/issue9400/asm_arm.s
+++ b/misc/cgo/test/testdata/issue9400/asm_arm.s
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build !gccgo
+// +build gc
#include "textflag.h"
diff --git a/misc/cgo/test/testdata/issue9400/asm_arm64.s b/misc/cgo/test/testdata/issue9400/asm_arm64.s
index 2ebbfcca3b6..2565793f9ab 100644
--- a/misc/cgo/test/testdata/issue9400/asm_arm64.s
+++ b/misc/cgo/test/testdata/issue9400/asm_arm64.s
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build !gccgo
+// +build gc
#include "textflag.h"
diff --git a/misc/cgo/test/testdata/issue9400/asm_mips64x.s b/misc/cgo/test/testdata/issue9400/asm_mips64x.s
index 63dc90605e6..693231ddfe1 100644
--- a/misc/cgo/test/testdata/issue9400/asm_mips64x.s
+++ b/misc/cgo/test/testdata/issue9400/asm_mips64x.s
@@ -3,7 +3,7 @@
// license that can be found in the LICENSE file.
// +build mips64 mips64le
-// +build !gccgo
+// +build gc
#include "textflag.h"
diff --git a/misc/cgo/test/testdata/issue9400/asm_mipsx.s b/misc/cgo/test/testdata/issue9400/asm_mipsx.s
index 7a927351942..63261bbf9d0 100644
--- a/misc/cgo/test/testdata/issue9400/asm_mipsx.s
+++ b/misc/cgo/test/testdata/issue9400/asm_mipsx.s
@@ -3,7 +3,7 @@
// license that can be found in the LICENSE file.
// +build mips mipsle
-// +build !gccgo
+// +build gc
#include "textflag.h"
diff --git a/misc/cgo/test/testdata/issue9400/asm_ppc64x.s b/misc/cgo/test/testdata/issue9400/asm_ppc64x.s
index c88ec3b21e7..b5613fb6ec7 100644
--- a/misc/cgo/test/testdata/issue9400/asm_ppc64x.s
+++ b/misc/cgo/test/testdata/issue9400/asm_ppc64x.s
@@ -3,7 +3,7 @@
// license that can be found in the LICENSE file.
// +build ppc64 ppc64le
-// +build !gccgo
+// +build gc
#include "textflag.h"
diff --git a/misc/cgo/test/testdata/issue9400/asm_riscv64.s b/misc/cgo/test/testdata/issue9400/asm_riscv64.s
index 20fcc0066d6..244dadac350 100644
--- a/misc/cgo/test/testdata/issue9400/asm_riscv64.s
+++ b/misc/cgo/test/testdata/issue9400/asm_riscv64.s
@@ -3,7 +3,7 @@
// license that can be found in the LICENSE file.
// +build riscv64
-// +build !gccgo
+// +build gc
#include "textflag.h"
diff --git a/misc/cgo/test/testdata/issue9400/asm_s390x.s b/misc/cgo/test/testdata/issue9400/asm_s390x.s
index fc9ad724c15..4856492958b 100644
--- a/misc/cgo/test/testdata/issue9400/asm_s390x.s
+++ b/misc/cgo/test/testdata/issue9400/asm_s390x.s
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build !gccgo
+// +build gc
#include "textflag.h"
diff --git a/misc/cgo/test/testx.c b/misc/cgo/test/testx.c
new file mode 100644
index 00000000000..1258e326a41
--- /dev/null
+++ b/misc/cgo/test/testx.c
@@ -0,0 +1,24 @@
+// 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.
+
+#include "_cgo_export.h"
+
+void lockOSThreadC(void) {
+ lockOSThreadCallback();
+}
+
+void issue7978c(uint32_t *sync) {
+ while(__atomic_load_n(sync, __ATOMIC_SEQ_CST) != 0)
+ ;
+ __atomic_add_fetch(sync, 1, __ATOMIC_SEQ_CST);
+ while(__atomic_load_n(sync, __ATOMIC_SEQ_CST) != 2)
+ ;
+ issue7978cb();
+ __atomic_add_fetch(sync, 1, __ATOMIC_SEQ_CST);
+ while(__atomic_load_n(sync, __ATOMIC_SEQ_CST) != 6)
+ ;
+}
+
+void f7665(void) {
+}
diff --git a/misc/cgo/test/testx.go b/misc/cgo/test/testx.go
index 2b2e69ec00f..823c3e13d29 100644
--- a/misc/cgo/test/testx.go
+++ b/misc/cgo/test/testx.go
@@ -12,6 +12,7 @@ package cgotest
import (
"runtime"
+ "runtime/cgo"
"runtime/debug"
"strings"
"sync"
@@ -26,7 +27,6 @@ import (
extern void doAdd(int, int);
// issue 1328
-extern void BackIntoGo(void);
void IntoC(void);
// issue 1560
@@ -38,11 +38,7 @@ long long mysleep(int seconds);
long long twoSleep(int);
// issue 3775
-void lockOSThreadCallback(void);
-inline static void lockOSThreadC(void)
-{
- lockOSThreadCallback();
-}
+void lockOSThreadC(void);
int usleep(unsigned usec);
// issue 4054 part 2 - part 1 in test.go
@@ -81,21 +77,9 @@ extern void f7665(void);
#include