From 456df7c282f984133a4e687e5cff1bcda0f180e4 Mon Sep 17 00:00:00 2001
From: Rob Pike
+The latest Go release, version 1.4, arrives as scheduled six months after 1.3
+and contains only one tiny language change,
+a backwards-compatible simple form of
+Up until Go 1.3,
+and
+
+If one was not interested in the loop values, only the iteration itself, it was still
+necessary to mention a variable (probably the blank identifier, as in
+
+was not syntactically permitted.
+
+This situation seemed awkward, so as of Go 1.4 the variable-free form is now legal.
+The situation arises only rarely but the code can be cleaner when it does.
+
+Updating: The change is strictly backwards compatible to existing Go
+programs, but tools that analyze Go parse trees may need to be modified to accept
+this new form as the
+
+TODO news about foobarblatz
+
+The
+We have clarified this situation in the documentation included in the release.
+The Go compatibilty guidelines and the
+docs for the
+Updating: Nothing technical has changed; this is just a clarification
+of the documentation.
+
+TODO news about garbage collection
+
+TODO news about stacks
+
+TODO gccgo news
+
+TODO go command news
+
+TODO cgo news
+
+TODO godoc news
+
+In the main Go source repository, the source code for the packages was kept in
+the directory
+Updating: Tools like
+TODO misc news
+
+TODO performance news
+
+TODO new packages
+
+TODO major changes
+
+The following list summarizes a number of minor changes to the library, mostly additions.
+See the relevant package documentation for more information about each change.
+
@@ -5371,11 +5369,6 @@ so they can only appear in call expressions;
they cannot be used as function values.
From 2eb1b658305bfd32774fd1e6a32cd6463564cf89 Mon Sep 17 00:00:00 2001
From: Rob Pike
+Programs that modify data being simultaneously accessed by multiple goroutines
+must serialize such access.
+
+To serialize access, protect the data with channel operations or other synchronization primitives
+such as those in the
+If you must read the rest of this document to understand the behavior of your program,
+you are being too clever.
+
+Don't be clever.
+
From 2fe9482343a4321d54dac5eca5eb04e06aea29d6 Mon Sep 17 00:00:00 2001
From: Shenghou Ma
+Up to Go 1.4, the runtime (garbage collector, concurrency support, interface management,
+maps, slices, strings, ...) was mostly written in C, with some assembler support.
+In 1.4, much of the code has been translated to Go so that the garbage collector can scan
+the stacks of programs in the runtime and get accurate information about what variables
+are active.
+This change was large but should have no semantic effect on programs.
+
+This rewrite allows the garbage collector in 1.4 to be fully precise,
+meaning that it is aware of the location of all active pointers in the program.
+This means the heap will be smaller as there will be no false positives keeping non-pointers alive.
+Other related changes also reduce the heap size, which is smaller by 10%-30% overall
+relative to the previous release.
+
+A consequence is that stacks are no longer segmented, eliminating the "hot split" problem.
+When a stack limit is reached, a new, larger stack is allocated, all active frames for
+the goroutine are copied there, and any pointers into the stack are updated.
+Performance can be noticeably better in some cases and is always more predictable.
+Details are available in the design document.
+
+The use of contiguous stacks means that stacks can start smaller without triggering performance issues,
+so the default starting size for a goroutine's stack in 1.4 has been reduced to 2048 bytes from 8192 bytes.
+TODO: It may be bumped to 4096 for the release.
+
+As preparation for the concurrent garbage collector scheduled for the 1.5 release,
+writes to pointer values in the heap are now done by a function call,
+called a write barrier, rather than directly from the function updating the value.
+In this next release, this will permit the garbage collector to mediate writes to the heap while it is running.
+This change has no semantic effect on programs in 1.4, but was
+included in the release to test the compiler and the resulting performance.
+
+The implementation of interface values has been modified.
+In earlier releases, the interface contained a word that was either a pointer or a one-word
+scalar value, depending on the type of the concrete object stored.
+This implementation was problematical for the garbage collector,
+so as of 1.4 interface values always hold a pointer.
+In running programs, most interface values were pointers anyway,
+so the effect is minimal, but programs that store integers (for example) in
+interfaces will see more allocations.
+
@@ -177,7 +230,29 @@ TODO misc news
-TODO performance news
+Most programs will run about the same speed or slightly faster in 1.4 than in 1.3;
+some will be slightly slower.
+There are many changes, making it hard to be precise about what to expect.
+
+As mentioned above, much of the runtime was translated to Go from C,
+which led to some reduction in heap sizes.
+It also improved performance slightly because the Go compiler is better
+at optimization, due to things like inlining, than the C compiler used to build
+the runtime.
+
+The garbage collector was sped up, leading to measurable improvements for
+garbage-heavy programs.
+On the other hand, the new write barriers slow things down again, typically
+by about the same amount but, depending on their behavior, some programs
+may be somewhat slower or faster.
+
+Library changes that affect performance are documented below.
Introduction to Go 1.4
+
+for
-range
loop.
+The release focuses primarily on implementation work, improving the garbage collector
+and preparing the ground for a fully concurrent collector to be rolled out in the
+next few releases.
+Stacks are now contiguous, reallocated when necessary rather than linking on new
+"segments";
+this release therefore eliminates the notorious "hot stack split" problem.
+There are some new tools available including support in the go
command
+for build-time source code generation
+and TODO.
+The release also adds support for TODO architecture and TODO operating systems.
+As always, Go 1.4 keeps the promise
+of compatibility,
+and almost everything
+will continue to compile and run without change when moved to 1.4.
+Changes to the language
+
+For-range loops
+for
-range
loop had two forms
+
+for k, v := range x {
+ ...
+}
+
+
+
+for k := range x {
+ ...
+}
+
+
+for
_
=
range
x
), because
+the form
+
+for range x {
+ ...
+}
+
+
+Key
field of RangeStmt
+may now be nil
.
+Changes to the supported operating systems and architectures
+
+FooBarBlatz
+
+Changes to the compatibility guidelines
+
+unsafe
package allows one
+to defeat Go's type system by exploiting internal details of the implementation
+or machine representation of data.
+It was never explicitly specified what use of unsafe
meant
+with respect to compatibility as specified in the
+Go compatibilty guidelines.
+The answer, of course, is that we can make no promise of compatibility
+for code that does unsafe things.
+unsafe
package
+are now explicit that unsafe code is not guaranteed to remain compatible.
+Changes to the implementations and tools
+
+Changes to the garbage collector
+
+Stack
+
+Status of gccgo
+
+Changes to the go command
+
+Changes to cgo
+
+Changes to godoc
+Changes to package source layout
+
+src/pkg
, which made sense but differed from
+other repositories, including the Go sub-repositories such as go.tools
.
+In Go 1.4, the pkg
level of the source tree is now gone, so for example
+the fmt
package's source, once kept in
+directory src/pkg/fmt
, now lives one level higher in src/fmt
.
+godoc
that discover source code
+need to know about the new location. All tools and services maintained by the Go team
+have been updated.
+Miscellany
+
+Performance
+
+Changes to the standard library
+
+New packages
+
+Major changes to the library
+
+Minor changes to the library
+
+
+
+
+
+
+
+the directory src/pkg has been deleted, for instance src/pkg/fmt is now just src/fmt (CL 134570043)
+
+cmd/6l, liblink: use pc-relative addressing for all memory references, so that linking Go binaries at high addresses works (CL 125140043). This cuts the maximum size of a Go binary's text+data+bss from 4GB to 2GB.
+cmd/go: import comments (CL 124940043)
+cmd/go: implement "internal" (CL 120600043)
+cmd/go: implement "generate" (CL 125580044)
+cmd/go: disallow C sources except when using cgo (CL 149720043)
+cmd/go: add test -o flag (CL 149070043)
+cmd/go: redefine build -a to skip standard library in releases (CL 151730045)
+cmd/go: compile and link all _test.go files during 'go test', even in packages where there are no Test functions (CL 150980043)
+cmd/go: (via go/build): a GOOS prefix acts as a tag only if preceded by an underscore. this is a breaking change. (CL 147690043)
+
+asm: make textflag.h available outside of cmd/ld (CL 128050043)
+bufio: handling of empty tokens at EOF changed, may require scanner change (CL 145390043)
+compress/flate, compress/gzip, compress/zlib: Reset support (https://codereview.appspot.com/97140043)
+crypto/tls: add support for ALPN (RFC 7301) (CL 108710046)
+crypto/tls: support programmatic selection of server certificates (CL 107400043)
+encoding/asn1: optional elements with a default value will now only be omitted if they have that value (CL 86960045)
+flag: it is now an error to set a flag multiple times (CL 156390043)
+fmt: print type *map[T]T as &map[k:v] (CL 154870043)
+encoding/csv: do not quote empty strings, quote \. (CL 164760043)
+encoding/gob: remove unsafe (CL 102680045)
+misc: deleted editor support; refer to https://code.google.com/p/go-wiki/wiki/IDEsAndTextEditorPlugins instead (CL 105470043)
+net/http: add Request.BasicAuth method (CL 76540043)
+net/http: add Transport.DialTLS hook (CL 137940043)
+net/http/httputil: add ReverseProxy.ErrorLog (CL 132750043)
+os: implement symlink support for windows (CL 86160044)
+reflect: add type.Comparable (CL 144020043)
+runtime: implement monotonic clocks on windows (CL 108700045)
+runtime: memory consumption is reduced by 10-30% (CL 106260045 removes type info from heap, CL 145790043 reduces stack size to 2K (4K on plan 9 and windows))
+runtime: MemStats.Mallocs now counts very small allocations missed in Go 1.3. This may break tests using runtime.ReadMemStats or testing.AllocsPerRun by giving a more accurate answer than Go 1.3 did (CL 143150043).
+runtime/race: freebsd is supported (CL 107270043)
+swig: Due to runtime changes Go 1.4 will require SWIG 3.0.3 (not yet released)
+sync/atomic: add Value (CL 136710045)
+syscall: Setuid, Setgid are disabled on linux platforms. On linux those syscalls operate on the calling thread, not the whole process. This does not match the semantics of other platforms, nor the expectations of the caller, so the operations have been disabled until issue 1435 is resolved (CL 106170043)
+syscall: now frozen (CL 129820043)
+testing: add Coverage (CL 98150043)
+testing: add TestMain support (CL 148770043)
+text/scanner: add IsIdentRune field of Scanner. (CL 108030044)
+text/template: allow comparison of signed and unsigned integers (CL 149780043)
+time: use the micro symbol (µ (U+00B5)) to print microsecond duration (CL 105030046)
+unsafe: document the existing situation that unsafe programs are not go1-guaranteed (CL 162060043)
+
+go.sys subrepo created: http://golang.org/s/go1.4-syscall
+
diff --git a/doc/go1.4.txt b/doc/go1.4.txt
deleted file mode 100644
index b9d8ade245..0000000000
--- a/doc/go1.4.txt
+++ /dev/null
@@ -1,53 +0,0 @@
-This file collects notes about what has changed since Go 1.3
-and should be mentioned in the Go 1.4 release notes.
-
-Please keep the descriptions to a single line, starting with the
-package or cmd/xxx directory name, and ending in a CL number.
-Please keep the list sorted (as in sort.Strings of the lines).
-
-spec: permit for range x (CL 104680043)
-
-the directory src/pkg has been deleted, for instance src/pkg/fmt is now just src/fmt (CL 134570043)
-
-cmd/6l, liblink: use pc-relative addressing for all memory references, so that linking Go binaries at high addresses works (CL 125140043). This cuts the maximum size of a Go binary's text+data+bss from 4GB to 2GB.
-cmd/go: import comments (CL 124940043)
-cmd/go: implement "internal" (CL 120600043)
-cmd/go: implement "generate" (CL 125580044)
-cmd/go: disallow C sources except when using cgo (CL 149720043)
-cmd/go: add test -o flag (CL 149070043)
-cmd/go: redefine build -a to skip standard library in releases (CL 151730045)
-cmd/go: compile and link all _test.go files during 'go test', even in packages where there are no Test functions (CL 150980043)
-cmd/go: (via go/build): a GOOS prefix acts as a tag only if preceded by an underscore. this is a breaking change. (CL 147690043)
-
-asm: make textflag.h available outside of cmd/ld (CL 128050043)
-bufio: handling of empty tokens at EOF changed, may require scanner change (CL 145390043)
-compress/flate, compress/gzip, compress/zlib: Reset support (https://codereview.appspot.com/97140043)
-crypto/tls: add support for ALPN (RFC 7301) (CL 108710046)
-crypto/tls: support programmatic selection of server certificates (CL 107400043)
-encoding/asn1: optional elements with a default value will now only be omitted if they have that value (CL 86960045)
-flag: it is now an error to set a flag multiple times (CL 156390043)
-fmt: print type *map[T]T as &map[k:v] (CL 154870043)
-encoding/csv: do not quote empty strings, quote \. (CL 164760043)
-encoding/gob: remove unsafe (CL 102680045)
-misc: deleted editor support; refer to https://code.google.com/p/go-wiki/wiki/IDEsAndTextEditorPlugins instead (CL 105470043)
-net/http: add Request.BasicAuth method (CL 76540043)
-net/http: add Transport.DialTLS hook (CL 137940043)
-net/http/httputil: add ReverseProxy.ErrorLog (CL 132750043)
-os: implement symlink support for windows (CL 86160044)
-reflect: add type.Comparable (CL 144020043)
-runtime: implement monotonic clocks on windows (CL 108700045)
-runtime: memory consumption is reduced by 10-30% (CL 106260045 removes type info from heap, CL 145790043 reduces stack size to 2K (4K on plan 9 and windows))
-runtime: MemStats.Mallocs now counts very small allocations missed in Go 1.3. This may break tests using runtime.ReadMemStats or testing.AllocsPerRun by giving a more accurate answer than Go 1.3 did (CL 143150043).
-runtime/race: freebsd is supported (CL 107270043)
-swig: Due to runtime changes Go 1.4 will require SWIG 3.0.3 (not yet released)
-sync/atomic: add Value (CL 136710045)
-syscall: Setuid, Setgid are disabled on linux platforms. On linux those syscalls operate on the calling thread, not the whole process. This does not match the semantics of other platforms, nor the expectations of the caller, so the operations have been disabled until issue 1435 is resolved (CL 106170043)
-syscall: now frozen (CL 129820043)
-testing: add Coverage (CL 98150043)
-testing: add TestMain support (CL 148770043)
-text/scanner: add IsIdentRune field of Scanner. (CL 108030044)
-text/template: allow comparison of signed and unsigned integers (CL 149780043)
-time: use the micro symbol (µ (U+00B5)) to print microsecond duration (CL 105030046)
-unsafe: document the existing situation that unsafe programs are not go1-guaranteed (CL 162060043)
-
-go.sys subrepo created: http://golang.org/s/go1.4-syscall
From aec37e7cb1d34896f65948e88465376ceca68e0c Mon Sep 17 00:00:00 2001
From: Russ Cox
math.Atan2(x, y) // function call
var pt *Point
-pt.Scale(3.5) // method call with receiver pt
+pt.Scale(3.5) // method call with receiver pt
-BuiltinCall = identifier "(" [ BuiltinArgs [ "," ] ] ")" .
-BuiltinArgs = Type [ "," ArgumentList ] | ArgumentList .
-
-
Close
Advice
+
+sync
+and sync/atomic
packages.
+Happens Before
nil
.
TODO news about foobarblatz
Changes to the runtime
+
+Changes to the compatibility guidelines
Performance
Changes to the standard library
@@ -209,8 +284,6 @@ See the relevant package documentation for more information about each change.
-the directory src/pkg has been deleted, for instance src/pkg/fmt is now just src/fmt (CL 134570043)
-
cmd/6l, liblink: use pc-relative addressing for all memory references, so that linking Go binaries at high addresses works (CL 125140043). This cuts the maximum size of a Go binary's text+data+bss from 4GB to 2GB.
cmd/go: import comments (CL 124940043)
cmd/go: implement "internal" (CL 120600043)
@@ -237,8 +310,8 @@ net/http: add Transport.DialTLS hook (CL 137940043)
net/http/httputil: add ReverseProxy.ErrorLog (CL 132750043)
os: implement symlink support for windows (CL 86160044)
reflect: add type.Comparable (CL 144020043)
+reflect: Value is one word smaller
runtime: implement monotonic clocks on windows (CL 108700045)
-runtime: memory consumption is reduced by 10-30% (CL 106260045 removes type info from heap, CL 145790043 reduces stack size to 2K (4K on plan 9 and windows))
runtime: MemStats.Mallocs now counts very small allocations missed in Go 1.3. This may break tests using runtime.ReadMemStats or testing.AllocsPerRun by giving a more accurate answer than Go 1.3 did (CL 143150043).
runtime/race: freebsd is supported (CL 107270043)
swig: Due to runtime changes Go 1.4 will require SWIG 3.0.3 (not yet released)
From cd69218bdffc08e3c17023ac604bbb1a995b8602 Mon Sep 17 00:00:00 2001
From: Rob Pike
nil
.
TODO news about foobarblatz
+The unsafe
package allows one
+to defeat Go's type system by exploiting internal details of the implementation
+or machine representation of data.
+It was never explicitly specified what use of unsafe
meant
+with respect to compatibility as specified in the
+Go compatibilty guidelines.
+The answer, of course, is that we can make no promise of compatibility
+for code that does unsafe things.
+
+We have clarified this situation in the documentation included in the release.
+The Go compatibilty guidelines and the
+docs for the unsafe
package
+are now explicit that unsafe code is not guaranteed to remain compatible.
+
+Updating: Nothing technical has changed; this is just a clarification +of the documentation. +
+ + +Up to Go 1.4, the runtime (garbage collector, concurrency support, interface management, @@ -140,58 +168,114 @@ so the effect is minimal, but programs that store integers (for example) in interfaces will see more allocations.
-
-The unsafe
package allows one
-to defeat Go's type system by exploiting internal details of the implementation
-or machine representation of data.
-It was never explicitly specified what use of unsafe
meant
-with respect to compatibility as specified in the
-Go compatibilty guidelines.
-The answer, of course, is that we can make no promise of compatibility
-for code that does unsafe things.
-
-We have clarified this situation in the documentation included in the release.
-The Go compatibilty guidelines and the
-docs for the unsafe
package
-are now explicit that unsafe code is not guaranteed to remain compatible.
-
-Updating: Nothing technical has changed; this is just a clarification -of the documentation. -
- - --TODO news about garbage collection -
- --TODO news about stacks -
-TODO gccgo news
-+TODO prose for these +cmd/go: implement "internal" (CL 120600043) ++ +
+TODO prose for these +cmd/go: import comments (CL 124940043) ++ +
-TODO go command news
+The go
command has a new subcommand,
+go generate
,
+to automate the running of tools to generate source code before compilation.
+For example, it can be used to run the yacc
+compiler-compiler on a .y
file to produce the Go source file implementing the grammar,
+or to automate the generation of String
methods for typed constants using the new
+stringer
+tool in the go.tools
repository.
+For more information, see the +design document. +
+ +
+Build constraints, also known as build tags, control compilation by including or excluding files
+(see the documentation /go/build
).
+Compilation can also be controlled by the name of the file itself by "tagging" the file with
+a suffix (before the .go
or .s
extension) with an underscore
+and the name of the architecture or operating system.
+For instance, the file gopher_arm.go
will only be compiled if the target
+processor is an ARM.
+
+Before Go 1.4, a file called just arm.go
was similarly tagged, but this behavior
+can break sources when new architectures are added, causing files to suddenly become tagged.
+In 1.4, therefore, a file will be tagged in this manner only if the tag (architecture or operating
+system name) is preceded by an underscore.
+
+Updating: Packages that depend on the old behavior will no longer compile correctly.
+Files with names like windows.go
or arm64.go
should either
+have explicit build tags added to the source or be renamed to something like
+os_windows.go
or support_arm64.go
.
+
+There were a number of minor changes to the
+cmd/go
+command worth noting.
+
cgo
is being used to build the package,
+the go
command now refuses to compile C source files,
+since the relevant C compilers
+(6c
etc.)
+are intended to be removed from the installation in some future release.
+(They are used today only to build part of the runtime.)
+It is difficult to use them correctly in any case, so any extant uses are likely incorrect,
+so we have disabled them.
+go
test
+subcommand has a new flag, -o
, to set the name of the resulting binary,
+corresponding to the same flag in other subcommands.
+The non-functional -file
flag has been removed.
+go
test
+will compile and link all *_test.go
files in the package,
+even when there are no Test
functions in them.
+It previously ignored such files.
+go
build
's
+-a
flag has been changed for non-development installations.
+For installations running a released distribution, the -a
flag will no longer
+rebuild the standard library and commands, to avoid overwriting the installation's files.
+@@ -285,14 +369,6 @@ See the relevant package documentation for more information about each change.
cmd/6l, liblink: use pc-relative addressing for all memory references, so that linking Go binaries at high addresses works (CL 125140043). This cuts the maximum size of a Go binary's text+data+bss from 4GB to 2GB. -cmd/go: import comments (CL 124940043) -cmd/go: implement "internal" (CL 120600043) -cmd/go: implement "generate" (CL 125580044) -cmd/go: disallow C sources except when using cgo (CL 149720043) -cmd/go: add test -o flag (CL 149070043) -cmd/go: redefine build -a to skip standard library in releases (CL 151730045) -cmd/go: compile and link all _test.go files during 'go test', even in packages where there are no Test functions (CL 150980043) -cmd/go: (via go/build): a GOOS prefix acts as a tag only if preceded by an underscore. this is a breaking change. (CL 147690043) asm: make textflag.h available outside of cmd/ld (CL 128050043) bufio: handling of empty tokens at EOF changed, may require scanner change (CL 145390043) From 21a9141ab364ecfea016bf36b8222f4747afa1fb Mon Sep 17 00:00:00 2001 From: Mikio HaraFrom 8a9c2c55bd0ccbadcf49126482110bee92fb5826 Mon Sep 17 00:00:00 2001 From: Russ CoxDate: Tue, 28 Oct 2014 16:20:49 +0900 Subject: [PATCH 12/33] net: add test for lookupIPDeadline Just to confirm the fix, by typing the follwing: go test -run=TestLookupIPDeadline -dnsflood or go test -run=TestLookupIPDeadline -dnsflood -tags netgo Update #8602 LGTM=iant R=iant CC=golang-codereviews https://golang.org/cl/166740043 --- src/net/z_last_test.go | 62 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/src/net/z_last_test.go b/src/net/z_last_test.go index 4f6a54a560..716c103db2 100644 --- a/src/net/z_last_test.go +++ b/src/net/z_last_test.go @@ -8,6 +8,7 @@ import ( "flag" "fmt" "testing" + "time" ) var testDNSFlood = flag.Bool("dnsflood", false, "whether to test dns query flooding") @@ -35,3 +36,64 @@ func TestDNSThreadLimit(t *testing.T) { // If we're still here, it worked. } + +func TestLookupIPDeadline(t *testing.T) { + if !*testDNSFlood { + t.Skip("test disabled; use -dnsflood to enable") + } + + const N = 5000 + const timeout = 3 * time.Second + c := make(chan error, 2*N) + for i := 0; i < N; i++ { + name := fmt.Sprintf("%d.net-test.golang.org", i) + go func() { + _, err := lookupIPDeadline(name, time.Now().Add(timeout/2)) + c <- err + }() + go func() { + _, err := lookupIPDeadline(name, time.Now().Add(timeout)) + c <- err + }() + } + qstats := struct { + succeeded, failed int + timeout, temporary, other int + unknown int + }{} + deadline := time.After(timeout + time.Second) + for i := 0; i < 2*N; i++ { + select { + case <-deadline: + t.Fatal("deadline exceeded") + case err := <-c: + switch err := err.(type) { + case nil: + qstats.succeeded++ + case Error: + qstats.failed++ + if err.Timeout() { + qstats.timeout++ + } + if err.Temporary() { + qstats.temporary++ + } + if !err.Timeout() && !err.Temporary() { + qstats.other++ + } + default: + qstats.failed++ + qstats.unknown++ + } + } + } + + // A high volume of DNS queries for sub-domain of golang.org + // would be coordinated by authoritative or recursive server, + // or stub resolver which implements query-response rate + // limitation, so we can expect some query successes and more + // failures including timeout, temporary and other here. + // As a rule, unknown must not be shown but it might possibly + // happen due to issue 4856 for now. + t.Logf("%v succeeded, %v failed (%v timeout, %v temporary, %v other, %v unknown)", qstats.succeeded, qstats.failed, qstats.timeout, qstats.temporary, qstats.other, qstats.unknown) +} From ea295a4cfbb0641f58c41d3722e7e8fb3b3f493f Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Tue, 28 Oct 2014 11:14:25 -0400 Subject: [PATCH 13/33] cmd/go: add get -f flag get -u now checks that remote repo paths match the ones predicted by the import paths: if you are get -u'ing rsc.io/pdf, it has to be checked out from the right location. This is important in case the rsc.io/pdf redirect changes. In some cases, people have good reasons to use non-standard remote repos. Add -f flag to allow that. The f can stand for force or fork, as you see fit. Fixes #8850. LGTM=r R=r CC=golang-codereviews https://golang.org/cl/164120043 --- src/cmd/go/get.go | 14 ++++++++++++-- src/cmd/go/test.bash | 10 ++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/cmd/go/get.go b/src/cmd/go/get.go index b8eac5c1ef..86e1697618 100644 --- a/src/cmd/go/get.go +++ b/src/cmd/go/get.go @@ -16,7 +16,7 @@ import ( ) var cmdGet = &Command{ - UsageLine: "get [-d] [-fix] [-t] [-u] [build flags] [packages]", + UsageLine: "get [-d] [-f] [-fix] [-t] [-u] [build flags] [packages]", Short: "download and install packages and dependencies", Long: ` Get downloads and installs the packages named by the import paths, @@ -25,6 +25,11 @@ along with their dependencies. The -d flag instructs get to stop after downloading the packages; that is, it instructs get not to install the packages. +The -f flag, valid only when -u is set, forces get -u not to verify that +each package has been checked out from the source control repository +implied by its import path. This can be useful if the source is a local fork +of the original. + The -fix flag instructs get to run the fix tool on the downloaded packages before resolving dependencies or building the code. @@ -53,6 +58,7 @@ See also: go build, go install, go clean. } var getD = cmdGet.Flag.Bool("d", false, "") +var getF = cmdGet.Flag.Bool("f", false, "") var getT = cmdGet.Flag.Bool("t", false, "") var getU = cmdGet.Flag.Bool("u", false, "") var getFix = cmdGet.Flag.Bool("fix", false, "") @@ -63,6 +69,10 @@ func init() { } func runGet(cmd *Command, args []string) { + if *getF && !*getU { + fatalf("go get: cannot use -f flag without -u") + } + // Phase 1. Download/update. var stk importStack for _, arg := range downloadPaths(args) { @@ -268,7 +278,7 @@ func downloadPackage(p *Package) error { repo = " " // should be unused; make distinctive // Double-check where it came from. - if *getU && vcs.remoteRepo != nil { + if *getU && vcs.remoteRepo != nil && !*getF { dir := filepath.Join(p.build.SrcRoot, rootPath) if remote, err := vcs.remoteRepo(vcs, dir); err == nil { if rr, err := repoRootForImportPath(p.ImportPath); err == nil { diff --git a/src/cmd/go/test.bash b/src/cmd/go/test.bash index 652ef3b5b6..2b5230b1aa 100755 --- a/src/cmd/go/test.bash +++ b/src/cmd/go/test.bash @@ -219,6 +219,16 @@ q' | ed $d/src/$config >/dev/null 2>&1 cat $d/err ok=false fi + + if GOPATH=$d ./testgo get -d -f -u $url 2>$d/err; then + echo "go get -d -u $url succeeded with wrong remote repo" + cat $d/err + ok=false + elif ! egrep -i 'validating server certificate|not found' $d/err >/dev/null; then + echo "go get -d -f -u $url failed for wrong reason" + cat $d/err + ok=false + fi fi rm -rf $d } From 96e9e81b5f353636965fa6ba5e014c2bab13fadc Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Tue, 28 Oct 2014 11:35:00 -0400 Subject: [PATCH 14/33] syscall: fix ParseRoutingSockaddr with unexpected submessages No easy way to test (would have to actually trigger some routing events from kernel) but the code is clearly wrong as written. If the header says there is a submessage, we need to at least skip over its bytes, not just continue to the next iteration. Fixes #8203. LGTM=r R=r CC=golang-codereviews, mikioh.mikioh, p https://golang.org/cl/164140044 --- src/syscall/route_bsd.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/syscall/route_bsd.go b/src/syscall/route_bsd.go index 48af587450..1dabe42531 100644 --- a/src/syscall/route_bsd.go +++ b/src/syscall/route_bsd.go @@ -153,7 +153,7 @@ func (m *InterfaceAddrMessage) sockaddr() (sas []Sockaddr) { // RTAX_NETMASK socket address on the FreeBSD kernel. preferredFamily := uint8(AF_UNSPEC) for i := uint(0); i < RTAX_MAX; i++ { - if m.Header.Addrs&rtaIfaMask&(1< Date: Tue, 28 Oct 2014 12:35:25 -0400 Subject: [PATCH 15/33] runtime: add PauseEnd array to MemStats and GCStats Fixes #8787. LGTM=rsc R=rsc, dvyukov CC=golang-codereviews https://golang.org/cl/153670043 --- src/runtime/debug/garbage.go | 30 +++++++++++++++++++++--------- src/runtime/debug/garbage_test.go | 13 +++++++++++++ src/runtime/malloc.h | 3 ++- src/runtime/mem.go | 3 ++- src/runtime/mgc0.c | 23 ++++++++++++++--------- 5 files changed, 52 insertions(+), 20 deletions(-) diff --git a/src/runtime/debug/garbage.go b/src/runtime/debug/garbage.go index 30994f2196..4a77dcfcd6 100644 --- a/src/runtime/debug/garbage.go +++ b/src/runtime/debug/garbage.go @@ -16,6 +16,7 @@ type GCStats struct { NumGC int64 // number of garbage collections PauseTotal time.Duration // total pause for all collections Pause []time.Duration // pause history, most recent first + PauseEnd []time.Time // pause end times history, most recent first PauseQuantiles []time.Duration } @@ -30,25 +31,36 @@ type GCStats struct { func ReadGCStats(stats *GCStats) { // Create a buffer with space for at least two copies of the // pause history tracked by the runtime. One will be returned - // to the caller and the other will be used as a temporary buffer - // for computing quantiles. + // to the caller and the other will be used as transfer buffer + // for end times history and as a temporary buffer for + // computing quantiles. const maxPause = len(((*runtime.MemStats)(nil)).PauseNs) - if cap(stats.Pause) < 2*maxPause { - stats.Pause = make([]time.Duration, 2*maxPause) + if cap(stats.Pause) < 2*maxPause+3 { + stats.Pause = make([]time.Duration, 2*maxPause+3) } - // readGCStats fills in the pause history (up to maxPause entries) - // and then three more: Unix ns time of last GC, number of GC, - // and total pause time in nanoseconds. Here we depend on the - // fact that time.Duration's native unit is nanoseconds, so the - // pauses and the total pause time do not need any conversion. + // readGCStats fills in the pause and end times histories (up to + // maxPause entries) and then three more: Unix ns time of last GC, + // number of GC, and total pause time in nanoseconds. Here we + // depend on the fact that time.Duration's native unit is + // nanoseconds, so the pauses and the total pause time do not need + // any conversion. readGCStats(&stats.Pause) n := len(stats.Pause) - 3 stats.LastGC = time.Unix(0, int64(stats.Pause[n])) stats.NumGC = int64(stats.Pause[n+1]) stats.PauseTotal = stats.Pause[n+2] + n /= 2 // buffer holds pauses and end times stats.Pause = stats.Pause[:n] + if cap(stats.PauseEnd) < maxPause { + stats.PauseEnd = make([]time.Time, 0, maxPause) + } + stats.PauseEnd = stats.PauseEnd[:0] + for _, ns := range stats.Pause[n : n+n] { + stats.PauseEnd = append(stats.PauseEnd, time.Unix(0, int64(ns))) + } + if len(stats.PauseQuantiles) > 0 { if n == 0 { for i := range stats.PauseQuantiles { diff --git a/src/runtime/debug/garbage_test.go b/src/runtime/debug/garbage_test.go index 149bafc6f3..54c33bd4f3 100644 --- a/src/runtime/debug/garbage_test.go +++ b/src/runtime/debug/garbage_test.go @@ -70,6 +70,19 @@ func TestReadGCStats(t *testing.T) { t.Errorf("stats.PauseQuantiles[%d]=%d > stats.PauseQuantiles[%d]=%d", i, q[i], i+1, q[i+1]) } } + + // compare memory stats with gc stats: + if len(stats.PauseEnd) != n { + t.Fatalf("len(stats.PauseEnd) = %d, want %d", len(stats.PauseEnd), n) + } + off := (int(mstats.NumGC) + len(mstats.PauseEnd) - 1) % len(mstats.PauseEnd) + for i := 0; i < n; i++ { + dt := stats.PauseEnd[i] + if dt.UnixNano() != int64(mstats.PauseEnd[off]) { + t.Errorf("stats.PauseEnd[%d] = %d, want %d", i, dt, mstats.PauseEnd[off]) + } + off = (off + len(mstats.PauseEnd) - 1) % len(mstats.PauseEnd) + } } var big = make([]byte, 1<<20) diff --git a/src/runtime/malloc.h b/src/runtime/malloc.h index d1930756a2..adb8d3d677 100644 --- a/src/runtime/malloc.h +++ b/src/runtime/malloc.h @@ -267,7 +267,8 @@ struct MStats uint64 next_gc; // next GC (in heap_alloc time) uint64 last_gc; // last GC (in absolute time) uint64 pause_total_ns; - uint64 pause_ns[256]; + uint64 pause_ns[256]; // circular buffer of recent GC pause lengths + uint64 pause_end[256]; // circular buffer of recent GC end times (nanoseconds since 1970) uint32 numgc; bool enablegc; bool debuggc; diff --git a/src/runtime/mem.go b/src/runtime/mem.go index 438f22ec09..e6f1eb0e64 100644 --- a/src/runtime/mem.go +++ b/src/runtime/mem.go @@ -44,7 +44,8 @@ type MemStats struct { NextGC uint64 // next collection will happen when HeapAlloc ≥ this amount LastGC uint64 // end time of last collection (nanoseconds since 1970) PauseTotalNs uint64 - PauseNs [256]uint64 // circular buffer of recent GC pause times, most recent at [(NumGC+255)%256] + PauseNs [256]uint64 // circular buffer of recent GC pause durations, most recent at [(NumGC+255)%256] + PauseEnd [256]uint64 // circular buffer of recent GC pause end times NumGC uint32 EnableGC bool DebugGC bool diff --git a/src/runtime/mgc0.c b/src/runtime/mgc0.c index 2ff64aaa30..cba2beaa74 100644 --- a/src/runtime/mgc0.c +++ b/src/runtime/mgc0.c @@ -1459,6 +1459,7 @@ gc(struct gc_args *args) t4 = runtime·nanotime(); runtime·atomicstore64(&mstats.last_gc, runtime·unixnanotime()); // must be Unix time to make sense to user mstats.pause_ns[mstats.numgc%nelem(mstats.pause_ns)] = t4 - t0; + mstats.pause_end[mstats.numgc%nelem(mstats.pause_end)] = t4; mstats.pause_total_ns += t4 - t0; mstats.numgc++; if(mstats.debuggc) @@ -1572,7 +1573,7 @@ readgcstats_m(void) { Slice *pauses; uint64 *p; - uint32 i, n; + uint32 i, j, n; pauses = g->m->ptrarg[0]; g->m->ptrarg[0] = nil; @@ -1581,25 +1582,29 @@ readgcstats_m(void) if(pauses->cap < nelem(mstats.pause_ns)+3) runtime·throw("runtime: short slice passed to readGCStats"); - // Pass back: pauses, last gc (absolute time), number of gc, total pause ns. + // Pass back: pauses, pause ends, last gc (absolute time), number of gc, total pause ns. p = (uint64*)pauses->array; runtime·lock(&runtime·mheap.lock); + n = mstats.numgc; if(n > nelem(mstats.pause_ns)) n = nelem(mstats.pause_ns); - + // The pause buffer is circular. The most recent pause is at // pause_ns[(numgc-1)%nelem(pause_ns)], and then backward // from there to go back farther in time. We deliver the times // most recent first (in p[0]). - for(i=0; i len = n+3; + pauses->len = n+n+3; } void From bd1169dd2144abbe58767bf2dfaa3f20e8cf553b Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Tue, 28 Oct 2014 10:51:28 -0700 Subject: [PATCH 16/33] doc/go1.4.html: vanity imports and internal packages LGTM=rsc R=golang-codereviews, rsc CC=golang-codereviews https://golang.org/cl/165800043 --- doc/go1.4.html | 107 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 93 insertions(+), 14 deletions(-) diff --git a/doc/go1.4.html b/doc/go1.4.html index 592b8661f1..ffabdb82c0 100644 --- a/doc/go1.4.html +++ b/doc/go1.4.html @@ -95,7 +95,7 @@ to defeat Go's type system by exploiting internal details of the implementation or machine representation of data. It was never explicitly specified what use of unsafe
meant with respect to compatibility as specified in the -Go compatibilty guidelines. +Go compatibility guidelines. The answer, of course, is that we can make no promise of compatibility for code that does unsafe things. @@ -175,25 +175,103 @@ TODO gccgo newsInternal packages
--TODO prose for these -cmd/go: implement "internal" (CL 120600043) --Import comments
++Go's package system makes it easy to structure programs into components with clean boundaries, +but there are only two forms of access: local (unexported) and global (exported). +Sometimes one wishes to have components that are not exported, +for instance to avoid acquiring clients of interfaces to code that is part of a public repository +but not intended for use outside the program to which it belongs. +
+ ++The Go language does not have the power to enforce this distinction, but as of Go 1.4 the +
+ +go
command introduces +a mechanism to define "internal" packages that may not be imported by packages outside +the source subtree in which they reside. ++To create such a package, place it in a directory named
+ +internal
or in a subdirectory of a directory +named internal. +When thego
command sees an import of a package withinternal
in its path, +it verifies that the package doing the import +is within the tree rooted at the parent of theinternal
directory. +For example, a package.../a/b/c/internal/d/e/f
+can be imported only by code in the directory tree rooted at.../a/b/c
. +It cannot be imported by code in.../a/b/g
or in any other repository. ++For Go 1.4, the internal package mechanism is enforced for the main Go repository; +from 1.5 and onward it will be enforced for any repository. +
+ ++Full details of the mechanism are in +the design document. +
+ +Canonical import paths
+ ++Code often lives in repositories hosted by public services such as
+ +github.com
, +meaning that the import paths for packages begin with the name of the hosting service, +github.com/rsc/pdf
for example. +One can use +an existing mechanism +to provide a "custom" or "vanity" import path such as +rsc.io/pdf
, but +that creates two valid import paths for the package. +That is a problem: one may inadvertently import the package through the two +distinct paths in a single program, which is wasteful; +miss an update to a package because the path being used is not recognized to be +out of date; +or break clients using the old path by moving the package to a different hosting service. ++Go 1.4 introduces an annotation for package clauses in Go source that identify a canonical +import path for the package. +If an import is attempted using a path that is not canonical, +the
+ +go
command +will refuse to compile the importing package. ++The syntax is simple: put an identifying comment on the package line. +For our example, the package clause would read: +
-TODO prose for these -cmd/go: import comments (CL 124940043) +package pdf // import "rsc.io/pdf"++With this in place, +the
+ +go
command will +refuse to compile a package that importsgithub.com/rsc/pdf
, +ensuring that the code can be moved without breaking users. ++The check is at build time, not download time, so if
+ +go
get
+fails because of this check, the mis-imported package has been copied to the local machine +and should be removed manually. ++Further information is in +the design document. +
+The go generate subcommand
The
go
command has a new subcommand,go generate
, to automate the running of tools to generate source code before compilation. -For example, it can be used to run theyacc
+For example, it can be used to run theyacc
compiler-compiler on a.y
file to produce the Go source file implementing the grammar, or to automate the generation ofString
methods for typed constants using the new stringer @@ -226,9 +304,9 @@ system name) is preceded by an underscore.Updating: Packages that depend on the old behavior will no longer compile correctly. -Files with names like
windows.go
orarm64.go
should either +Files with names likewindows.go
oramd64.go
should either have explicit build tags added to the source or be renamed to something like -os_windows.go
orsupport_arm64.go
. +os_windows.go
orsupport_amd64.go
.Other changes to the go command
@@ -261,14 +339,15 @@ The non-functional-file
flag has been removed.The go
test
-will compile and link all*_test.go
files in the package, +subcommand will compile and link all*_test.go
files in the package, even when there are noTest
functions in them. It previously ignored such files.The behavior of the - go
build
's +go
build
+subcommand's-a
flag has been changed for non-development installations. For installations running a released distribution, the-a
flag will no longer rebuild the standard library and commands, to avoid overwriting the installation's files. @@ -376,7 +455,6 @@ compress/flate, compress/gzip, compress/zlib: Reset support (https://codereview. crypto/tls: add support for ALPN (RFC 7301) (CL 108710046) crypto/tls: support programmatic selection of server certificates (CL 107400043) encoding/asn1: optional elements with a default value will now only be omitted if they have that value (CL 86960045) -flag: it is now an error to set a flag multiple times (CL 156390043) fmt: print type *map[T]T as &map[k:v] (CL 154870043) encoding/csv: do not quote empty strings, quote \. (CL 164760043) encoding/gob: remove unsafe (CL 102680045) @@ -390,6 +468,7 @@ reflect: Value is one word smaller runtime: implement monotonic clocks on windows (CL 108700045) runtime: MemStats.Mallocs now counts very small allocations missed in Go 1.3. This may break tests using runtime.ReadMemStats or testing.AllocsPerRun by giving a more accurate answer than Go 1.3 did (CL 143150043). runtime/race: freebsd is supported (CL 107270043) +runtime: add PauseEnd array to MemStats and GCStats (CL 153670043) swig: Due to runtime changes Go 1.4 will require SWIG 3.0.3 (not yet released) sync/atomic: add Value (CL 136710045) syscall: Setuid, Setgid are disabled on linux platforms. On linux those syscalls operate on the calling thread, not the whole process. This does not match the semantics of other platforms, nor the expectations of the caller, so the operations have been disabled until issue 1435 is resolved (CL 106170043) From a62da2027bf0fb5e6cd242c8806c04af7161a6fa Mon Sep 17 00:00:00 2001 From: Russ CoxDate: Tue, 28 Oct 2014 15:00:13 -0400 Subject: [PATCH 17/33] os: do not assume syscall i/o funcs return n=0 on error Fixes #9007. LGTM=iant, r R=r, iant CC=golang-codereviews https://golang.org/cl/160670043 --- src/os/dir_unix.go | 2 +- src/os/file.go | 9 +++++++++ src/os/file_plan9.go | 11 ++++------- src/os/file_posix.go | 2 +- src/os/file_unix.go | 10 +++++----- src/os/file_windows.go | 4 ++-- 6 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/os/dir_unix.go b/src/os/dir_unix.go index d353e405e5..589db85274 100644 --- a/src/os/dir_unix.go +++ b/src/os/dir_unix.go @@ -36,7 +36,7 @@ func (f *File) readdirnames(n int) (names []string, err error) { if d.bufp >= d.nbuf { d.bufp = 0 var errno error - d.nbuf, errno = syscall.ReadDirent(f.fd, d.buf) + d.nbuf, errno = fixCount(syscall.ReadDirent(f.fd, d.buf)) if errno != nil { return names, NewSyscallError("readdirent", errno) } diff --git a/src/os/file.go b/src/os/file.go index b4a7458016..e12428cbe1 100644 --- a/src/os/file.go +++ b/src/os/file.go @@ -255,3 +255,12 @@ var lstat = Lstat func Rename(oldpath, newpath string) error { return rename(oldpath, newpath) } + +// Many functions in package syscall return a count of -1 instead of 0. +// Using fixCount(call()) instead of call() corrects the count. +func fixCount(n int, err error) (int, error) { + if n < 0 { + n = 0 + } + return n, err +} diff --git a/src/os/file_plan9.go b/src/os/file_plan9.go index a804b81973..22860e20af 100644 --- a/src/os/file_plan9.go +++ b/src/os/file_plan9.go @@ -244,14 +244,14 @@ func (f *File) Sync() (err error) { // read reads up to len(b) bytes from the File. // It returns the number of bytes read and an error, if any. func (f *File) read(b []byte) (n int, err error) { - return syscall.Read(f.fd, b) + return fixCount(syscall.Read(f.fd, b)) } // pread reads len(b) bytes from the File starting at byte offset off. // It returns the number of bytes read and the error, if any. // EOF is signaled by a zero count with err set to nil. func (f *File) pread(b []byte, off int64) (n int, err error) { - return syscall.Pread(f.fd, b, off) + return fixCount(syscall.Pread(f.fd, b, off)) } // write writes len(b) bytes to the File. @@ -259,10 +259,7 @@ func (f *File) pread(b []byte, off int64) (n int, err error) { // Since Plan 9 preserves message boundaries, never allow // a zero-byte write. func (f *File) write(b []byte) (n int, err error) { - if len(b) == 0 { - return 0, nil - } - return syscall.Write(f.fd, b) + return fixCount(syscall.Write(f.fd, b)) } // pwrite writes len(b) bytes to the File starting at byte offset off. @@ -273,7 +270,7 @@ func (f *File) pwrite(b []byte, off int64) (n int, err error) { if len(b) == 0 { return 0, nil } - return syscall.Pwrite(f.fd, b, off) + return fixCount(syscall.Pwrite(f.fd, b, off)) } // seek sets the offset for the next Read or Write on file to offset, interpreted diff --git a/src/os/file_posix.go b/src/os/file_posix.go index 9cff7e5bcc..fbb3b5e4d8 100644 --- a/src/os/file_posix.go +++ b/src/os/file_posix.go @@ -18,7 +18,7 @@ func sigpipe() // implemented in package runtime func Readlink(name string) (string, error) { for len := 128; ; len *= 2 { b := make([]byte, len) - n, e := syscall.Readlink(name, b) + n, e := fixCount(syscall.Readlink(name, b)) if e != nil { return "", &PathError{"readlink", name, e} } diff --git a/src/os/file_unix.go b/src/os/file_unix.go index bba0d9c0f6..4e413fbe84 100644 --- a/src/os/file_unix.go +++ b/src/os/file_unix.go @@ -187,7 +187,7 @@ func (f *File) read(b []byte) (n int, err error) { if needsMaxRW && len(b) > maxRW { b = b[:maxRW] } - return syscall.Read(f.fd, b) + return fixCount(syscall.Read(f.fd, b)) } // pread reads len(b) bytes from the File starting at byte offset off. @@ -197,7 +197,7 @@ func (f *File) pread(b []byte, off int64) (n int, err error) { if needsMaxRW && len(b) > maxRW { b = b[:maxRW] } - return syscall.Pread(f.fd, b, off) + return fixCount(syscall.Pread(f.fd, b, off)) } // write writes len(b) bytes to the File. @@ -208,7 +208,7 @@ func (f *File) write(b []byte) (n int, err error) { if needsMaxRW && len(bcap) > maxRW { bcap = bcap[:maxRW] } - m, err := syscall.Write(f.fd, bcap) + m, err := fixCount(syscall.Write(f.fd, bcap)) n += m // If the syscall wrote some data but not all (short write) @@ -234,7 +234,7 @@ func (f *File) pwrite(b []byte, off int64) (n int, err error) { if needsMaxRW && len(b) > maxRW { b = b[:maxRW] } - return syscall.Pwrite(f.fd, b, off) + return fixCount(syscall.Pwrite(f.fd, b, off)) } // seek sets the offset for the next Read or Write on file to offset, interpreted @@ -242,7 +242,7 @@ func (f *File) pwrite(b []byte, off int64) (n int, err error) { // relative to the current offset, and 2 means relative to the end. // It returns the new offset and an error, if any. func (f *File) seek(offset int64, whence int) (ret int64, err error) { - return syscall.Seek(f.fd, offset, whence) + return fixCount(syscall.Seek(f.fd, offset, whence)) } // Truncate changes the size of the named file. diff --git a/src/os/file_windows.go b/src/os/file_windows.go index e78d4abf64..3b5519390b 100644 --- a/src/os/file_windows.go +++ b/src/os/file_windows.go @@ -295,7 +295,7 @@ func (f *File) read(b []byte) (n int, err error) { if f.isConsole { return f.readConsole(b) } - return syscall.Read(f.fd, b) + return fixCount(syscall.Read(f.fd, b)) } // pread reads len(b) bytes from the File starting at byte offset off. @@ -376,7 +376,7 @@ func (f *File) write(b []byte) (n int, err error) { if f.isConsole { return f.writeConsole(b) } - return syscall.Write(f.fd, b) + return fixCount(syscall.Write(f.fd, b)) } // pwrite writes len(b) bytes to the File starting at byte offset off. From d7660143b6fb99073614b60269f57d9e47f07c2c Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Tue, 28 Oct 2014 12:11:34 -0700 Subject: [PATCH 18/33] doc/go1.4.html: new ports LGTM=rsc, aram, minux R=golang-codereviews, aram, minux, rsc CC=golang-codereviews https://golang.org/cl/162370045 --- doc/go1.4.html | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/doc/go1.4.html b/doc/go1.4.html index ffabdb82c0..35a0015a79 100644 --- a/doc/go1.4.html +++ b/doc/go1.4.html @@ -19,7 +19,8 @@ this release therefore eliminates the notorious "hot stack split" problem. There are some new tools available including support in the go
command for build-time source code generation and TODO. -The release also adds support for TODO architecture and TODO operating systems. +The release also adds support for ARM processors on Android and Native Client (NaCl) +and AMD64 on Plan 9. As always, Go 1.4 keeps the promise of compatibility, and almost everything @@ -68,7 +69,7 @@ was not syntactically permitted.This situation seemed awkward, so as of Go 1.4 the variable-free form is now legal. -The situation arises only rarely but the code can be cleaner when it does. +The pattern arises rarely but the code can be cleaner when it does.
@@ -81,10 +82,30 @@ may now be
nil
.Changes to the supported operating systems and architectures
-FooBarBlatz
+Android
-TODO news about foobarblatz +Go 1.4 can build binaries for ARM processors running the Android operating system. +It can also build a
+ +.so
library that can be loaded by an Android application +using the supporting packages in the go.mobile repository. +A brief description of the plans for this experimental port are available +here. +NaCl on ARM
+ ++The previous release introduced Native Client (NaCl) support for the 32-bit x86 +(
+ +GOARCH=386
) +and 64-bit x86 using 32-bit pointers (GOARCH=amd64p32). +The 1.4 release adds NaCl support for ARM (GOARCH=arm). +Plan9 on AMD64
+ ++This release adds support for the Plan 9 operating system on AMD64 processors, +provided the kernel supports the
nsec
system call and uses 4K pages.Changes to the compatibility guidelines
@@ -388,6 +409,7 @@ have been updated.TODO misc news +misc: deleted editor support; refer to https://code.google.com/p/go-wiki/wiki/IDEsAndTextEditorPlugins instead (CL 105470043)
Performance
@@ -432,6 +454,11 @@ TODO new packages TODO major changes ++encoding/gob: remove unsafe (CL 102680045) +syscall: now frozen (CL 129820043) ++Minor changes to the library
@@ -457,8 +484,6 @@ crypto/tls: support programmatic selection of server certificates (CL 107400043) encoding/asn1: optional elements with a default value will now only be omitted if they have that value (CL 86960045) fmt: print type *map[T]T as &map[k:v] (CL 154870043) encoding/csv: do not quote empty strings, quote \. (CL 164760043) -encoding/gob: remove unsafe (CL 102680045) -misc: deleted editor support; refer to https://code.google.com/p/go-wiki/wiki/IDEsAndTextEditorPlugins instead (CL 105470043) net/http: add Request.BasicAuth method (CL 76540043) net/http: add Transport.DialTLS hook (CL 137940043) net/http/httputil: add ReverseProxy.ErrorLog (CL 132750043) @@ -472,13 +497,11 @@ runtime: add PauseEnd array to MemStats and GCStats (CL 153670043) swig: Due to runtime changes Go 1.4 will require SWIG 3.0.3 (not yet released) sync/atomic: add Value (CL 136710045) syscall: Setuid, Setgid are disabled on linux platforms. On linux those syscalls operate on the calling thread, not the whole process. This does not match the semantics of other platforms, nor the expectations of the caller, so the operations have been disabled until issue 1435 is resolved (CL 106170043) -syscall: now frozen (CL 129820043) testing: add Coverage (CL 98150043) testing: add TestMain support (CL 148770043) text/scanner: add IsIdentRune field of Scanner. (CL 108030044) text/template: allow comparison of signed and unsigned integers (CL 149780043) time: use the micro symbol (µ (U+00B5)) to print microsecond duration (CL 105030046) -unsafe: document the existing situation that unsafe programs are not go1-guaranteed (CL 162060043) go.sys subrepo created: http://golang.org/s/go1.4-syscall
The SB
pseudo-register can be thought of as the origin of memory, so the symbol foo(SB)
is the name foo
as an address in memory.
+This form is used to name global functions and data.
+Adding <>
to the name, as in foo<>(SB)
, makes the name
+visible only in the current source file, like a top-level static
declaration in a C file.
@@ -128,8 +131,11 @@ Thus 0(FP)
is the first argument to the function,
When referring to a function argument this way, it is conventional to place the name
at the beginning, as in first_arg+0(FP)
and second_arg+8(FP)
.
Some of the assemblers enforce this convention, rejecting plain 0(FP)
and 8(FP)
.
-For assembly functions with Go prototypes, go vet
will check that the argument names
+For assembly functions with Go prototypes, go
vet
will check that the argument names
and offsets match.
+On 32-bit systems, the low and high 32 bits of a 64-bit value are distinguished by adding
+a _lo
or _hi
suffix to the name, as in arg_lo+0(FP)
or arg_hi+4(FP)
.
+If a Go prototype does not name its result, the expected assembly name is ret
.
@@ -206,6 +212,8 @@ The frame size $24-8
states that the function has a 24-byte frame
and is called with 8 bytes of argument, which live on the caller's frame.
If NOSPLIT
is not specified for the TEXT
,
the argument size must be provided.
+For assembly functions with Go prototypes, go
vet
will check that the
+argument size is correct.
@@ -216,19 +224,20 @@ simple name profileloop
.
-For DATA
directives, the symbol is followed by a slash and the number
-of bytes the memory associated with the symbol occupies.
-The arguments are optional flags and the data itself.
-For instance,
-
DATA
directives followed by a GLOBL
directive.
+Each DATA
directive initializes a section of the
+corresponding memory.
+The memory not explicitly initialized is zeroed.
+The general form of the DATA
directive is
-DATA runtime·isplan9(SB)/4, $1 +DATA symbol+offset(SB)/width, value
-declares the local symbol runtime·isplan9
of size 4 and value 1.
-Again the symbol has the middle dot and is offset from SB
.
+which initializes the symbol memory at the given offset and width with the given value.
+The DATA
directives for a given symbol must be written with increasing offsets.
@@ -237,15 +246,26 @@ The arguments are optional flags and the size of the data being declared as a gl
which will have initial value all zeros unless a DATA
directive
has initialized it.
The GLOBL
directive must follow any corresponding DATA
directives.
-This example
+
+For example,
-GLOBL runtime·tlsoffset(SB),$4 +DATA divtab<>+0x00(SB)/4, $0xf4f8fcff +DATA divtab<>+0x04(SB)/4, $0xe6eaedf0 +... +DATA divtab<>+0x3c(SB)/4, $0x81828384 +GLOBL divtab<>(SB), RODATA, $64 + +GLOBL runtime·tlsoffset(SB), NOPTR, $4
-declares runtime·tlsoffset
to have size 4.
+declares and initializes divtab<>
, a read-only 64-byte table of 4-byte integer values,
+and declares runtime·tlsoffset
, a 4-byte, implicitly zeroed variable that
+contains no pointers.
@@ -299,6 +319,80 @@ This is a wrapper function and should not count as disabling recover
+
+For garbage collection to run correctly, the runtime must know the +location of pointers in all global data and in most stack frames. +The Go compiler emits this information when compiling Go source files, +but assembly programs must define it explicitly. +
+ +
+A data symbol marked with the NOPTR
flag (see above)
+is treated as containing no pointers to runtime-allocated data.
+A data symbol with the RODATA
flag
+is allocated in read-only memory and is therefore treated
+as implicitly marked NOPTR
.
+A data symbol with a total size smaller than a pointer
+is also treated as implicitly marked NOPTR
.
+It is not possible to define a symbol containing pointers in an assembly source file;
+such a symbol must be defined in a Go source file instead.
+Assembly source can still refer to the symbol by name
+even without DATA
and GLOBL
directives.
+A good general rule of thumb is to define all non-RODATA
+symbols in Go instead of in assembly.
+
+Each function also needs annotations giving the location of
+live pointers in its arguments, results, and local stack frame.
+For an assembly function with no pointer results and
+either no local stack frame or no function calls,
+the only requirement is to define a Go prototype for the function
+in a Go source file in the same package.
+For more complex situations, explicit annotation is needed.
+These annotations use pseudo-instructions defined in the standard
+#include
file funcdata.h
.
+
+If a function has no arguments and no results,
+the pointer information can be omitted.
+This is indicated by an argument size annotation of $n-0
+on the TEXT
instruction.
+Otherwise, pointer information must be provided by
+a Go prototype for the function in a Go source file,
+even for assembly functions not called directly from Go.
+(The prototype will also let go
vet
check the argument references.)
+At the start of the function, the arguments are assumed
+to be initialized but the results are assumed uninitialized.
+If the results will hold live pointers during a call instruction,
+the function should start by zeroing the results and then
+executing the pseudo-instruction GO_RESULTS_INITIALIZED
.
+This instruction records that the results are now initialized
+and should be scanned during stack movement and garbage collection.
+It is typically easier to arrange that assembly functions do not
+return pointers or do not contain call instructions;
+no assembly functions in the standard library use
+GO_RESULTS_INITIALIZED
.
+
+If a function has no local stack frame,
+the pointer information can be omitted.
+This is indicated by a local frame size annotation of $0-n
+on the TEXT
instruction.
+The pointer information can also be omitted if the
+function contains no call instructions.
+Otherwise, the local stack frame must not contain pointers,
+and the assembly must confirm this fact by executing the
+pseudo-instruction NO_LOCAL_POINTERS
.
+Because stack resizing is implemented by moving the stack,
+the stack pointer may change during any function call:
+even pointers to stack data must not be kept in local variables.
+
@@ -434,13 +528,10 @@ Here's how the 386 runtime defines the 64-bit atomic load function.
// so actually
// void atomicload64(uint64 *res, uint64 volatile *addr);
TEXT runtime·atomicload64(SB), NOSPLIT, $0-8
- MOVL 4(SP), BX
- MOVL 8(SP), AX
- // MOVQ (%EAX), %MM0
- BYTE $0x0f; BYTE $0x6f; BYTE $0x00
- // MOVQ %MM0, 0(%EBX)
- BYTE $0x0f; BYTE $0x7f; BYTE $0x03
- // EMMS
- BYTE $0x0F; BYTE $0x77
+ MOVL ptr+0(FP), AX
+ LEAL ret_lo+4(FP), BX
+ BYTE $0x0f; BYTE $0x6f; BYTE $0x00 // MOVQ (%EAX), %MM0
+ BYTE $0x0f; BYTE $0x7f; BYTE $0x03 // MOVQ %MM0, 0(%EBX)
+ BYTE $0x0F; BYTE $0x77 // EMMS
RET
diff --git a/src/runtime/funcdata.h b/src/runtime/funcdata.h
index a2667a4c02..d6c14fcb41 100644
--- a/src/runtime/funcdata.h
+++ b/src/runtime/funcdata.h
@@ -28,6 +28,9 @@
// defines the pointer map for the function's arguments.
// GO_ARGS should be the first instruction in a function that uses it.
// It can be omitted if there are no arguments at all.
+// GO_ARGS is inserted implicitly by the linker for any function
+// that also has a Go prototype and therefore is usually not necessary
+// to write explicitly.
#define GO_ARGS FUNCDATA $FUNCDATA_ArgsPointerMaps, go_args_stackmap(SB)
// GO_RESULTS_INITIALIZED indicates that the assembly function
From 982dcb249d107c1cab844912583c5eca0a07a00f Mon Sep 17 00:00:00 2001
From: Rob Pike
The latest Go release, version 1.4, arrives as scheduled six months after 1.3
and contains only one tiny language change,
+a possibly breaking change to the compiler,
a backwards-compatible simple form of
+Given these declarations,
+
+both
+which is a double dereference of the pointer-to-pointer
+Updating: Code that depends on the old, erroneous behavior will no longer
+compile but is easy to fix by adding an explicit dereference.
+
-TODO misc news
-misc: deleted editor support; refer to https://code.google.com/p/go-wiki/wiki/IDEsAndTextEditorPlugins instead (CL 105470043)
+The standard repository's top-level
+The Go community at large is much better suited to managing this information.
+In Go 1.4, therefore, this support has been removed from the repository.
+Instead, there is a curated, informative list of what's available on
+a wiki page.
-TODO new packages
+There are no new packages in this release.
We have clarified this situation in the documentation included in the release.
-The Go compatibilty guidelines and the
+The Go compatibility guidelines and the
docs for the for
-range
loop.
The release focuses primarily on implementation work, improving the garbage collector
and preparing the ground for a fully concurrent collector to be rolled out in the
@@ -80,6 +81,39 @@ this new form as the
may now be nil
.
Method calls on **T
+
+
+type T int
+func (T) M() {}
+var x **T
+
+
+gc
and gccgo
accepted the method call
+
+x.M()
+
+
+x
.
+The Go specification allows a single dereference to be inserted automatically,
+but not two, so this call is erroneous according to the language definition.
+It has therefore been disallowed in Go 1.4, which is a breaking change,
+although very few programs will be affected.
+Changes to the supported operating systems and architectures
Android
@@ -408,8 +442,20 @@ have been updated.
Miscellany
misc
directory used to contain
+Go support for editors and IDEs: plugins, initialization scripts and so on.
+Maintaining these was becoming time-consuming
+and needed external help because many of the editors listed were not used by
+members of the core team.
+It also required us to make decisions about which plugin was best for a given
+editor, even for editors we do not use.
+Performance
@@ -445,7 +491,7 @@ Library changes that affect performance are documented below.
New packages
Major changes to the library
@@ -456,7 +502,7 @@ TODO major changes
encoding/gob: remove unsafe (CL 102680045)
-syscall: now frozen (CL 129820043)
+syscall: now frozen (CL 129820043); go.sys subrepo created: http://golang.org/s/go1.4-syscall
Minor changes to the library
@@ -502,6 +548,4 @@ testing: add TestMain support (CL 148770043)
text/scanner: add IsIdentRune field of Scanner. (CL 108030044)
text/template: allow comparison of signed and unsigned integers (CL 149780043)
time: use the micro symbol (µ (U+00B5)) to print microsecond duration (CL 105030046)
-
-go.sys subrepo created: http://golang.org/s/go1.4-syscall
From 5f54f06a359f2973521ff3f42899c12d3a6a7fed Mon Sep 17 00:00:00 2001
From: David du Colombier <0intro@gmail.com>
Date: Tue, 28 Oct 2014 22:44:59 +0100
Subject: [PATCH 22/33] os: fix write on Plan 9
In CL 160670043 the write function was changed
so a zero-length write is now allowed. This leads
the ExampleWriter_Init test to fail.
The reason is that Plan 9 preserves message
boundaries, while the os library expects systems
that don't preserve them. We have to ignore
zero-length writes so they will never turn into EOF.
This issue was previously discussed in CL 7406046.
LGTM=bradfitz
R=rsc, bradfitz
CC=golang-codereviews
https://golang.org/cl/163510043
---
src/os/file_plan9.go | 3 +++
1 file changed, 3 insertions(+)
diff --git a/src/os/file_plan9.go b/src/os/file_plan9.go
index 22860e20af..5efc2a4f1d 100644
--- a/src/os/file_plan9.go
+++ b/src/os/file_plan9.go
@@ -259,6 +259,9 @@ func (f *File) pread(b []byte, off int64) (n int, err error) {
// Since Plan 9 preserves message boundaries, never allow
// a zero-byte write.
func (f *File) write(b []byte) (n int, err error) {
+ if len(b) == 0 {
+ return 0, nil
+ }
return fixCount(syscall.Write(f.fd, b))
}
From 5e568545991cb358a8a004b21e23ac6fa9801124 Mon Sep 17 00:00:00 2001
From: Russ Cox unsafe
package
are now explicit that unsafe code is not guaranteed to remain compatible.
+As of Go 1.3, the runtime crashes if it finds a memory word that should contain
+a valid pointer but instead contains an obviously invalid pointer (for example, the value 3).
+Programs that store integers in pointer values may run afoul of this check and crash.
+In Go 1.4, setting the GODEBUG
variable
+invalidptr=0
disables
+the crash as a workaround, but we cannot guarantee that future releases will be
+able to avoid the crash; the correct fix is to rewrite code not to alias integers and pointers.
+
+The language accepted by the assemblers cmd/5a
, cmd/6a
+and cmd/8a
has had several changes,
+mostly to make it easier to deliver type information to the runtime.
+
+First, the textflag.h
file that defines flags for TEXT
directives
+has been copied from the linker source directory to a standard location so it can be
+included with the simple directive
+
+#include "textflag.h" ++ +
+The more important changes are in how assembler source can define the necessary
+type information.
+For most programs it will suffice to move data
+definitions (DATA
and GLOBL
directives)
+out of assembly into Go files
+and to write a Go declaration for each assembly function.
+The assembly document describes what to do.
+
+Updating:
+Assembly files that include textflag.h
from its old
+location will still work, but should be updated.
+For the type information, most assembly routines will need no change,
+but all should be examined.
+Assembly source files that define data,
+functions with non-empty stack frames, or functions that return pointers
+need particular attention.
+A description of the necessary (but simple) changes
+is in the assembly document.
+
+More information about these changes is in the assembly document. +
+@@ -410,13 +465,6 @@ rebuild the standard library and commands, to avoid overwriting the installation -
-TODO cgo news -
- -
TODO godoc news
@@ -522,7 +570,6 @@ See the relevant package documentation for more information about each change.
cmd/6l, liblink: use pc-relative addressing for all memory references, so that linking Go binaries at high addresses works (CL 125140043). This cuts the maximum size of a Go binary's text+data+bss from 4GB to 2GB.
-asm: make textflag.h available outside of cmd/ld (CL 128050043)
bufio: handling of empty tokens at EOF changed, may require scanner change (CL 145390043)
compress/flate, compress/gzip, compress/zlib: Reset support (https://codereview.appspot.com/97140043)
crypto/tls: add support for ALPN (RFC 7301) (CL 108710046)
From c88ba199e2cf24b6dff3d069b50d3bccda4c1552 Mon Sep 17 00:00:00 2001
From: Rob Pike