blob: 9594736e654fd8034860c4cec5bcbf7d00eaf609 [file] [log] [blame]
Russ Coxae9529a2015-12-14 23:16:21 -05001<!--{
Russ Cox939a9422016-02-17 10:39:13 -05002 "Title": "Go 1.6 Release Notes",
Russ Coxae9529a2015-12-14 23:16:21 -05003 "Path": "/doc/go1.6",
4 "Template": true
5}-->
6
7<!--
8Edit .,s;^PKG:([a-z][A-Za-z0-9_/]+);<a href="/pkg/\1/"><code>\1</code></a>;g
9Edit .,s;^([a-z][A-Za-z0-9_/]+)\.([A-Z][A-Za-z0-9_]+\.)?([A-Z][A-Za-z0-9_]+)([ .',]|$);<a href="/pkg/\1/#\2\3"><code>\3</code></a>\4;g
10-->
11
12<style>
13ul li { margin: 0.5em 0; }
14</style>
15
Russ Coxae9529a2015-12-14 23:16:21 -050016<h2 id="introduction">Introduction to Go 1.6</h2>
17
18<p>
19The latest Go release, version 1.6, arrives six months after 1.5.
20Most of its changes are in the implementation of the language, runtime, and libraries.
21There are no changes to the language specification.
22As always, the release maintains the Go 1 <a href="/doc/go1compat.html">promise of compatibility</a>.
23We expect almost all Go programs to continue to compile and run as before.
24</p>
25
26<p>
27The release adds new ports to <a href="#ports">Linux on 64-bit MIPS and Android on 32-bit x86</a>;
28defined and enforced <a href="#cgo">rules for sharing Go pointers with C</a>;
Brad Fitzpatrick32cf9852015-12-17 13:34:41 -080029transparent, automatic <a href="#http2">support for HTTP/2</a>;
Russ Coxae9529a2015-12-14 23:16:21 -050030and a new mechanism for <a href="#template">template reuse</a>.
31</p>
32
33<h2 id="language">Changes to the language</h2>
34
35<p>
36There are no language changes in this release.
37</p>
38
39<h2 id="ports">Ports</h2>
40
41<p>
42Go 1.6 adds experimental ports to
43Linux on 64-bit MIPS (<code>linux/mips64</code> and <code>linux/mips64le</code>).
44These ports support <code>cgo</code> but only with internal linking.
45</p>
46
47<p>
48Go 1.6 also adds an experimental port to Android on 32-bit x86 (<code>android/386</code>).
49</p>
50
51<p>
52On FreeBSD, Go 1.6 defaults to using <code>clang</code>, not <code>gcc</code>, as the external C compiler.
53</p>
54
55<p>
56On Linux on little-endian 64-bit PowerPC (<code>linux/ppc64le</code>),
57Go 1.6 now supports <code>cgo</code> with external linking and
58is roughly feature complete.
59</p>
60
61<p>
62On NaCl, Go 1.5 required SDK version pepper-41.
63Go 1.6 adds support for later SDK versions.
64</p>
65
Russ Cox095c0e52016-02-11 13:33:33 -050066<p>
67On 32-bit x86 systems using the <code>-dynlink</code> or <code>-shared</code> compilation modes,
68the register CX is now overwritten by certain memory references and should
69be avoided in hand-written assembly.
70See the <a href="/doc/asm#x86">assembly documentation</a> for details.
71</p>
Russ Coxae9529a2015-12-14 23:16:21 -050072
73<h2 id="tools">Tools</h2>
74
75<h3 id="cgo">Cgo</h3>
76
77<p>
78There is one major change to <a href="/cmd/cgo/"><code>cgo</code></a>, along with one minor change.
79</p>
80
81<p>
82The major change is the definition of rules for sharing Go pointers with C code,
83to ensure that such C code can coexist with Go's garbage collector.
84Briefly, Go and C may share memory allocated by Go
85when a pointer to that memory is passed to C as part of a <code>cgo</code> call,
86provided that the memory itself contains no pointers to Go-allocated memory,
87and provided that C does not retain the pointer after the call returns.
88These rules are checked by the runtime during program execution:
89if the runtime detects a violation, it prints a diagnosis and crashes the program.
90The checks can be disabled by setting the environment variable
91<code>GODEBUG=cgocheck=0</code>, but note that the vast majority of
92code identified by the checks is subtly incompatible with garbage collection
93in one way or another.
94Disabling the checks will typically only lead to more mysterious failure modes.
95Fixing the code in question should be strongly preferred
96over turning off the checks.
97See the <a href="/cmd/cgo/#hdr-Passing_pointers"><code>cgo</code> documentation</a> for more details.
98</p>
99
100<p>
101The minor change is
102the addition of explicit <code>C.complexfloat</code> and <code>C.complexdouble</code> types,
103separate from Go's <code>complex64</code> and <code>complex128</code>.
104Matching the other numeric types, C's complex types and Go's complex type are
105no longer interchangeable.
106</p>
107
108<h3 id="compiler">Compiler Toolchain</h3>
109
110<p>
111The compiler toolchain is mostly unchanged.
112Internally, the most significant change is that the parser is now hand-written
113instead of generated from <a href="/cmd/yacc/">yacc</a>.
114</p>
115
116<p>
Dominik Honnef7d8c8c02016-01-23 04:57:21 +0100117The compiler, linker, and <code>go</code> command have a new flag <code>-msan</code>,
Russ Coxae9529a2015-12-14 23:16:21 -0500118analogous to <code>-race</code> and only available on linux/amd64,
119that enables interoperation with the <a href="http://clang.llvm.org/docs/MemorySanitizer.html">Clang MemorySanitizer</a>.
Dominik Honnef7d8c8c02016-01-23 04:57:21 +0100120Such interoperation is useful mainly for testing a program containing suspect C or C++ code.
Russ Coxae9529a2015-12-14 23:16:21 -0500121</p>
122
123<p>
124The linker has a new option <code>-libgcc</code> to set the expected location
125of the C compiler support library when linking <a href="/cmd/cgo/"><code>cgo</code></a> code.
126The option is only consulted when using <code>-linkmode=internal</code>,
127and it may be set to <code>none</code> to disable the use of a support library.
128</p>
129
130<p>
Michael Hudson-Doyleb00105d2016-01-07 12:50:13 +1300131The implementation of <a href="/doc/go1.5#link">build modes started in Go 1.5</a> has been expanded to more systems.
132This release adds support for the <code>c-shared</code> mode on <code>android/386</code>, <code>android/amd64</code>,
133<code>android/arm64</code>, <code>linux/386</code>, and <code>linux/arm64</code>;
134for the <code>shared</code> mode on <code>linux/386</code>, <code>linux/arm</code>, <code>linux/amd64</code>, and <code>linux/ppc64le</code>;
135and for the new <code>pie</code> mode (generating position-independent executables) on
136<code>android/386</code>, <code>android/amd64</code>, <code>android/arm</code>, <code>android/arm64</code>, <code>linux/386</code>,
137<code>linux/amd64</code>, <code>linux/arm</code>, <code>linux/arm64</code>, and <code>linux/ppc64le</code>.
138See the <a href="https://golang.org/s/execmodes">design document</a> for details.
Russ Coxae9529a2015-12-14 23:16:21 -0500139</p>
140
141<p>
142As a reminder, the linker's <code>-X</code> flag changed in Go 1.5.
143In Go 1.4 and earlier, it took two arguments, as in
144</p>
145
146<pre>
147-X importpath.name value
148</pre>
149
150<p>
151Go 1.5 added an alternative syntax using a single argument
152that is itself a <code>name=value</code> pair:
153</p>
154
155<pre>
156-X importpath.name=value
157</pre>
158
159<p>
160In Go 1.5 the old syntax was still accepted, after printing a warning
161suggesting use of the new syntax instead.
162Go 1.6 continues to accept the old syntax and print the warning.
163Go 1.7 will remove support for the old syntax.
164</p>
165
166<h3 id="gccgo">Gccgo</h3>
167
168<p>
169The release schedules for the GCC and Go projects do not coincide.
170GCC release 5 contains the Go 1.4 version of gccgo.
Ian Lance Taylor6372c822016-04-13 21:44:35 -0700171The next release, GCC 6, will have the Go 1.6.1 version of gccgo.
Russ Coxae9529a2015-12-14 23:16:21 -0500172</p>
173
174<h3 id="go_command">Go command</h3>
175
176<p>
177The <a href="/cmd/go"><code>go</code></a> command's basic operation
178is unchanged, but there are a number of changes worth noting.
179</p>
180
181<p>
182Go 1.5 introduced experimental support for vendoring,
183enabled by setting the <code>GO15VENDOREXPERIMENT</code> environment variable to <code>1</code>.
184Go 1.6 keeps the vendoring support, no longer considered experimental,
185and enables it by default.
186It can be disabled explicitly by setting
187the <code>GO15VENDOREXPERIMENT</code> environment variable to <code>0</code>.
188Go 1.7 will remove support for the environment variable.
189</p>
190
191<p>
192The most likely problem caused by enabling vendoring by default happens
193in source trees containing an existing directory named <code>vendor</code> that
194does not expect to be interpreted according to new vendoring semantics.
195In this case, the simplest fix is to rename the directory to anything other
196than <code>vendor</code> and update any affected import paths.
197</p>
198
199<p>
200For details about vendoring,
201see the documentation for the <a href="/cmd/go/#hdr-Vendor_Directories"><code>go</code> command</a>
202and the <a href="https://golang.org/s/go15vendor">design document</a>.
203</p>
204
205<p>
206There is a new build flag, <code>-msan</code>,
207that compiles Go with support for the LLVM memory sanitizer.
208This is intended mainly for use when linking against C or C++ code
209that is being checked with the memory sanitizer.
210</p>
211
212<h3 id="doc_command">Go doc command</h3>
213
214<p>
215Go 1.5 introduced the
216<a href="/cmd/go/#hdr-Show_documentation_for_package_or_symbol"><code>go doc</code></a> command,
217which allows references to packages using only the package name, as in
218<code>go</code> <code>doc</code> <code>http</code>.
219In the event of ambiguity, the Go 1.5 behavior was to use the package
220with the lexicographically earliest import path.
221In Go 1.6, ambiguity is resolved by preferring import paths with
222fewer elements, breaking ties using lexicographic comparison.
223An important effect of this change is that original copies of packages
224are now preferred over vendored copies.
225Successful searches also tend to run faster.
226</p>
227
228<h3 id="vet_command">Go vet command</h3>
229
230<p>
231The <a href="/cmd/vet"><code>go vet</code></a> command now diagnoses
232passing function or method values as arguments to <code>Printf</code>,
233such as when passing <code>f</code> where <code>f()</code> was intended.
234</p>
235
236<h2 id="performance">Performance</h2>
237
238<p>
239As always, the changes are so general and varied that precise statements
240about performance are difficult to make.
241Some programs may run faster, some slower.
242On average the programs in the Go 1 benchmark suite run a few percent faster in Go 1.6
243than they did in Go 1.5.
244The garbage collector's pauses are even lower than in Go 1.5,
Austin Clements62fad432016-02-14 15:09:21 -0500245especially for programs using
Russ Coxae9529a2015-12-14 23:16:21 -0500246a large amount of memory.
247</p>
248
249<p>
250There have been significant optimizations bringing more than 10% improvements
251to implementations of the
252<a href="/pkg/compress/bzip2/"><code>compress/bzip2</code></a>,
253<a href="/pkg/compress/gzip/"><code>compress/gzip</code></a>,
254<a href="/pkg/crypto/aes/"><code>crypto/aes</code></a>,
255<a href="/pkg/crypto/elliptic/"><code>crypto/elliptic</code></a>,
256<a href="/pkg/crypto/ecdsa/"><code>crypto/ecdsa</code></a>, and
257<a href="/pkg/sort/"><code>sort</code></a> packages.
258</p>
259
260<h2 id="library">Core library</h2>
261
Brad Fitzpatrick32cf9852015-12-17 13:34:41 -0800262<h3 id="http2">HTTP/2</h3>
Russ Coxae9529a2015-12-14 23:16:21 -0500263
264<p>
265Go 1.6 adds transparent support in the
266<a href="/pkg/net/http/"><code>net/http</code></a> package
267for the new <a href="https://http2.github.io/">HTTP/2 protocol</a>.
268Go clients and servers will automatically use HTTP/2 as appropriate when using HTTPS.
269There is no exported API specific to details of the HTTP/2 protocol handling,
270just as there is no exported API specific to HTTP/1.1.
271</p>
272
273<p>
274Programs that must disable HTTP/2 can do so by setting
275<a href="/pkg/net/http/#Transport"><code>Transport.TLSNextProto</code></a> (for clients)
276or
277<a href="/pkg/net/http/#Server"><code>Server.TLSNextProto</code></a> (for servers)
278to a non-nil, empty map.
279</p>
280
281<p>
282Programs that must adjust HTTP/2 protocol-specific details can import and use
283<a href="https://golang.org/x/net/http2"><code>golang.org/x/net/http2</code></a>,
284in particular its
285<a href="https://godoc.org/golang.org/x/net/http2/#ConfigureServer">ConfigureServer</a>
286and
287<a href="https://godoc.org/golang.org/x/net/http2/#ConfigureTransport">ConfigureTransport</a>
288functions.
289</p>
290
291<h3 id="runtime">Runtime</h3>
292
293<p>
Russ Coxae9529a2015-12-14 23:16:21 -0500294The runtime has added lightweight, best-effort detection of concurrent misuse of maps.
295As always, if one goroutine is writing to a map, no other goroutine should be
296reading or writing the map concurrently.
297If the runtime detects this condition, it prints a diagnosis and crashes the program.
298The best way to find out more about the problem is to run the program
299under the
300<a href="https://blog.golang.org/race-detector">race detector</a>,
301which will more reliably identify the race
302and give more detail.
303</p>
304
Russ Coxe5ef5d42015-12-18 11:29:15 -0500305<p>
306For program-ending panics, the runtime now by default
307prints only the stack of the running goroutine,
308not all existing goroutines.
309Usually only the current goroutine is relevant to a panic,
310so omitting the others significantly reduces irrelevant output
311in a crash message.
312To see the stacks from all goroutines in crash messages, set the environment variable
313<code>GOTRACEBACK</code> to <code>all</code>
314or call
315<a href="/pkg/runtime/debug/#SetTraceback"><code>debug.SetTraceback</code></a>
316before the crash, and rerun the program.
317See the <a href="/pkg/runtime/#hdr-Environment_Variables">runtime documentation</a> for details.
318</p>
319
320<p>
321<em>Updating</em>:
322Uncaught panics intended to dump the state of the entire program,
323such as when a timeout is detected or when explicitly handling a received signal,
324should now call <code>debug.SetTraceback("all")</code> before panicking.
325Searching for uses of
326<a href="/pkg/os/signal/#Notify"><code>signal.Notify</code></a> may help identify such code.
327</p>
328
Russ Coxf962fc02016-01-06 21:28:06 -0500329<p>
330On Windows, Go programs in Go 1.5 and earlier forced
331the global Windows timer resolution to 1ms at startup
332by calling <code>timeBeginPeriod(1)</code>.
333Go no longer needs this for good scheduler performance,
334and changing the global timer resolution caused problems on some systems,
335so the call has been removed.
336</p>
337
Ian Lance Taylor08396f72016-01-27 06:42:10 -0800338<p>
339When using <code>-buildmode=c-archive</code> or
340<code>-buildmode=c-shared</code> to build an archive or a shared
341library, the handling of signals has changed.
342In Go 1.5 the archive or shared library would install a signal handler
343for most signals.
344In Go 1.6 it will only install a signal handler for the
345synchronous signals needed to handle run-time panics in Go code:
346SIGBUS, SIGFPE, SIGSEGV.
347See the <a href="/pkg/os/signal">os/signal</a> package for more
348details.
349</p>
350
Russ Coxae9529a2015-12-14 23:16:21 -0500351<h3 id="reflect">Reflect</h3>
352
353<p>
354The
355<a href="/pkg/reflect/"><code>reflect</code></a> package has
356<a href="https://golang.org/issue/12367">resolved a long-standing incompatibility</a>
357between the gc and gccgo toolchains
358regarding embedded unexported struct types containing exported fields.
359Code that walks data structures using reflection, especially to implement
360serialization in the spirit
361of the
362<a href="/pkg/encoding/json/"><code>encoding/json</code></a> and
363<a href="/pkg/encoding/xml/"><code>encoding/xml</code></a> packages,
364may need to be updated.
365</p>
366
367<p>
368The problem arises when using reflection to walk through
369an embedded unexported struct-typed field
370into an exported field of that struct.
371In this case, <code>reflect</code> had incorrectly reported
372the embedded field as exported, by returning an empty <code>Field.PkgPath</code>.
373Now it correctly reports the field as unexported
374but ignores that fact when evaluating access to exported fields
375contained within the struct.
376</p>
377
378<p>
379<em>Updating</em>:
380Typically, code that previously walked over structs and used
381</p>
382
383<pre>
384f.PkgPath != ""
385</pre>
386
387<p>
388to exclude inaccessible fields
389should now use
390</p>
391
392<pre>
393f.PkgPath != "" &amp;&amp; !f.Anonymous
394</pre>
395
396<p>
397For example, see the changes to the implementations of
398<a href="https://go-review.googlesource.com/#/c/14011/2/src/encoding/json/encode.go"><code>encoding/json</code></a> and
399<a href="https://go-review.googlesource.com/#/c/14012/2/src/encoding/xml/typeinfo.go"><code>encoding/xml</code></a>.
400</p>
401
402<h3 id="sort">Sorting</h3>
403
404<p>
405In the
406<a href="/pkg/sort/"><code>sort</code></a>
407package,
408the implementation of
409<a href="/pkg/sort/#Sort"><code>Sort</code></a>
410has been rewritten to make about 10% fewer calls to the
411<a href="/pkg/sort/#Interface"><code>Interface</code></a>'s
412<code>Less</code> and <code>Swap</code>
413methods, with a corresponding overall time savings.
414The new algorithm does choose a different ordering than before
415for values that compare equal (those pairs for which <code>Less(i,</code> <code>j)</code> and <code>Less(j,</code> <code>i)</code> are false).
416</p>
417
418<p>
419<em>Updating</em>:
420The definition of <code>Sort</code> makes no guarantee about the final order of equal values,
421but the new behavior may still break programs that expect a specific order.
422Such programs should either refine their <code>Less</code> implementations
423to report the desired order
424or should switch to
425<a href="/pkg/sort/#Stable"><code>Stable</code></a>,
426which preserves the original input order
427of equal values.
428</p>
429
430<h3 id="template">Templates</h3>
431
432<p>
433In the
434<a href="/pkg/text/template/">text/template</a> package,
435there are two significant new features to make writing templates easier.
436</p>
437
438<p>
439First, it is now possible to <a href="/pkg/text/template/#hdr-Text_and_spaces">trim spaces around template actions</a>,
440which can make template definitions more readable.
441A minus sign at the beginning of an action says to trim space before the action,
442and a minus sign at the end of an action says to trim space after the action.
443For example, the template
444</p>
445
446<pre>
447{{"{{"}}23 -}}
448 &lt;
449{{"{{"}}- 45}}
450</pre>
451
452<p>
453formats as <code>23&lt;45</code>.
454</p>
455
456<p>
457Second, the new <a href="/pkg/text/template/#hdr-Actions"><code>{{"{{"}}block}}</code> action</a>,
458combined with allowing redefinition of named templates,
459provides a simple way to define pieces of a template that
460can be replaced in different instantiations.
Andrew Gerrand1ab900e2016-01-29 16:44:16 +1100461There is <a href="/pkg/text/template/#example_Template_block">an example</a>
462in the <code>text/template</code> package that demonstrates this new feature.
Russ Coxae9529a2015-12-14 23:16:21 -0500463</p>
464
465<h3 id="minor_library_changes">Minor changes to the library</h3>
466
467<ul>
468
469<li>
Russ Cox353ee322016-01-13 21:13:02 -0500470The <a href="/pkg/archive/tar/"><code>archive/tar</code></a> package's
471implementation corrects many bugs in rare corner cases of the file format.
472One visible change is that the
473<a href="/pkg/archive/tar/#Reader"><code>Reader</code></a> type's
474<a href="/pkg/archive/tar/#Reader.Read"><code>Read</code></a> method
475now presents the content of special file types as being empty,
476returning <code>io.EOF</code> immediately.
477</li>
478
479<li>
Russ Coxae9529a2015-12-14 23:16:21 -0500480In the <a href="/pkg/archive/zip/"><code>archive/zip</code></a> package, the
481<a href="/pkg/archive/zip/#Reader"><code>Reader</code></a> type now has a
482<a href="/pkg/archive/zip/#Reader.RegisterDecompressor"><code>RegisterDecompressor</code></a> method,
483and the
484<a href="/pkg/archive/zip/#Writer"><code>Writer</code></a> type now has a
485<a href="/pkg/archive/zip/#Writer.RegisterCompressor"><code>RegisterCompressor</code></a> method,
486enabling control over compression options for individual zip files.
487These take precedence over the pre-existing global
488<a href="/pkg/archive/zip/#RegisterDecompressor"><code>RegisterDecompressor</code></a> and
489<a href="/pkg/archive/zip/#RegisterCompressor"><code>RegisterCompressor</code></a> functions.
490</li>
491
492<li>
493The <a href="/pkg/bufio/"><code>bufio</code></a> package's
494<a href="/pkg/bufio/#Scanner"><code>Scanner</code></a> type now has a
495<a href="/pkg/bufio/#Scanner.Buffer"><code>Buffer</code></a> method,
496to specify an initial buffer and maximum buffer size to use during scanning.
497This makes it possible, when needed, to scan tokens larger than
498<code>MaxScanTokenSize</code>.
499Also for the <code>Scanner</code>, the package now defines the
500<a href="/pkg/bufio/#ErrFinalToken"><code>ErrFinalToken</code></a> error value, for use by
501<a href="/pkg/bufio/#SplitFunc">split functions</a> to abort processing or to return a final empty token.
502</li>
503
504<li>
505The <a href="/pkg/compress/flate/"><code>compress/flate</code></a> package
506has deprecated its
507<a href="/pkg/compress/flate/#ReadError"><code>ReadError</code></a> and
508<a href="/pkg/compress/flate/#WriteError"><code>WriteError</code></a> error implementations.
509In Go 1.5 they were only rarely returned when an error was encountered;
510now they are never returned, although they remain defined for compatibility.
511</li>
512
513<li>
514The <a href="/pkg/compress/flate/"><code>compress/flate</code></a>,
515<a href="/pkg/compress/gzip/"><code>compress/gzip</code></a>, and
516<a href="/pkg/compress/zlib/"><code>compress/zlib</code></a> packages
517now report
518<a href="/pkg/io/#ErrUnexpectedEOF"><code>io.ErrUnexpectedEOF</code></a> for truncated input streams, instead of
519<a href="/pkg/io/#EOF"><code>io.EOF</code></a>.
520</li>
521
522<li>
Adam Langley109d54a2016-01-09 19:10:33 -0800523The <a href="/pkg/crypto/cipher/"><code>crypto/cipher</code></a> package now
524overwrites the destination buffer in the event of a GCM decryption failure.
525This is to allow the AESNI code to avoid using a temporary buffer.
526</li>
527
528<li>
Russ Coxae9529a2015-12-14 23:16:21 -0500529The <a href="/pkg/crypto/tls/"><code>crypto/tls</code></a> package
530has a variety of minor changes.
531It now allows
532<a href="/pkg/crypto/tls/#Listen"><code>Listen</code></a>
533to succeed when the
534<a href="/pkg/crypto/tls/#Config"><code>Config</code></a>
535has a nil <code>Certificates</code>, as long as the <code>GetCertificate</code> callback is set,
536it adds support for RSA with AES-GCM cipher suites,
537and
538it adds a
539<a href="/pkg/crypto/tls/#RecordHeaderError"><code>RecordHeaderError</code></a>
540to allow clients (in particular, the <a href="/pkg/net/http/"><code>net/http</code></a> package)
541to report a better error when attempting a TLS connection to a non-TLS server.
542</li>
543
544<li>
545The <a href="/pkg/crypto/x509/"><code>crypto/x509</code></a> package
546now permits certificates to contain negative serial numbers
547(technically an error, but unfortunately common in practice),
548and it defines a new
549<a href="/pkg/crypto/x509/#InsecureAlgorithmError"><code>InsecureAlgorithmError</code></a>
550to give a better error message when rejecting a certificate
551signed with an insecure algorithm like MD5.
552</li>
553
554<li>
555The <a href="/pkg/debug/dwarf"><code>debug/dwarf</code></a> and
556<a href="/pkg/debug/elf/"><code>debug/elf</code></a> packages
557together add support for compressed DWARF sections.
558User code needs no updating: the sections are decompressed automatically when read.
559</li>
560
561<li>
562The <a href="/pkg/debug/elf/"><code>debug/elf</code></a> package
563adds support for general compressed ELF sections.
564User code needs no updating: the sections are decompressed automatically when read.
565However, compressed
Austin Clements18aefe92016-02-14 23:53:19 -0500566<a href="/pkg/debug/elf/#Section"><code>Sections</code></a> do not support random access:
Russ Coxae9529a2015-12-14 23:16:21 -0500567they have a nil <code>ReaderAt</code> field.
568</li>
569
570<li>
571The <a href="/pkg/encoding/asn1/"><code>encoding/asn1</code></a> package
572now exports
573<a href="/pkg/encoding/asn1/#pkg-constants">tag and class constants</a>
574useful for advanced parsing of ASN.1 structures.
575</li>
576
577<li>
578Also in the <a href="/pkg/encoding/asn1/"><code>encoding/asn1</code></a> package,
579<a href="/pkg/encoding/asn1/#Unmarshal"><code>Unmarshal</code></a> now rejects various non-standard integer and length encodings.
580</li>
581
582<li>
Russ Cox20d745c2016-01-06 14:32:17 -0500583The <a href="/pkg/encoding/base64"><code>encoding/base64</code></a> package's
584<a href="/pkg/encoding/base64/#Decoder"><code>Decoder</code></a> has been fixed
585to process the final bytes of its input. Previously it processed as many four-byte tokens as
Dominik Honnef7d8c8c02016-01-23 04:57:21 +0100586possible but ignored the remainder, up to three bytes.
Russ Cox20d745c2016-01-06 14:32:17 -0500587The <code>Decoder</code> therefore now handles inputs in unpadded encodings (like
588<a href="/pkg/encoding/base64/#RawURLEncoding">RawURLEncoding</a>) correctly,
589but it also rejects inputs in padded encodings that are truncated or end with invalid bytes,
590such as trailing spaces.
591</li>
592
593<li>
Russ Coxae9529a2015-12-14 23:16:21 -0500594The <a href="/pkg/encoding/json/"><code>encoding/json</code></a> package
595now checks the syntax of a
596<a href="/pkg/encoding/json/#Number"><code>Number</code></a>
597before marshaling it, requiring that it conforms to the JSON specification for numeric values.
598As in previous releases, the zero <code>Number</code> (an empty string) is marshaled as a literal 0 (zero).
599</li>
600
601<li>
602The <a href="/pkg/encoding/xml/"><code>encoding/xml</code></a> package's
603<a href="/pkg/encoding/xml/#Marshal"><code>Marshal</code></a>
604function now supports a <code>cdata</code> attribute, such as <code>chardata</code>
605but encoding its argument in one or more <code>&lt;![CDATA[ ... ]]&gt;</code> tags.
606</li>
607
608<li>
609Also in the <a href="/pkg/encoding/xml/"><code>encoding/xml</code></a> package,
610<a href="/pkg/encoding/xml/#Decoder"><code>Decoder</code></a>'s
611<a href="/pkg/encoding/xml/#Decoder.Token"><code>Token</code></a> method
612now reports an error when encountering EOF before seeing all open tags closed,
613consistent with its general requirement that tags in the input be properly matched.
614To avoid that requirement, use
615<a href="/pkg/encoding/xml/#Decoder.RawToken"><code>RawToken</code></a>.
616</li>
617
618<li>
619The <a href="/pkg/fmt/"><code>fmt</code></a> package now allows
620any integer type as an argument to
621<a href="/pkg/fmt/#Printf"><code>Printf</code></a>'s <code>*</code> width and precision specification.
622In previous releases, the argument to <code>*</code> was required to have type <code>int</code>.
623</li>
624
625<li>
626Also in the <a href="/pkg/fmt/"><code>fmt</code></a> package,
627<a href="/pkg/fmt/#Scanf"><code>Scanf</code></a> can now scan hexadecimal strings using %X, as an alias for %x.
628Both formats accept any mix of upper- and lower-case hexadecimal.
Russ Coxae9529a2015-12-14 23:16:21 -0500629</li>
630
631<li>
632The <a href="/pkg/image/"><code>image</code></a>
633and
Dominik Honnef7d8c8c02016-01-23 04:57:21 +0100634<a href="/pkg/image/color/"><code>image/color</code></a> packages
Russ Coxae9529a2015-12-14 23:16:21 -0500635add
636<a href="/pkg/image/#NYCbCrA"><code>NYCbCrA</code></a>
637and
Russ Cox01ca4da2016-01-27 11:02:45 -0500638<a href="/pkg/image/color/#NYCbCrA"><code>NYCbCrA</code></a>
Russ Coxae9529a2015-12-14 23:16:21 -0500639types, to support Y'CbCr images with non-premultiplied alpha.
640</li>
641
642<li>
643The <a href="/pkg/io/"><code>io</code></a> package's
644<a href="/pkg/io/#MultiWriter"><code>MultiWriter</code></a>
645implementation now implements a <code>WriteString</code> method,
646for use by
647<a href="/pkg/io/#WriteString"><code>WriteString</code></a>.
648</li>
649
650<li>
651In the <a href="/pkg/math/big/"><code>math/big</code></a> package,
652<a href="/pkg/math/big/#Int"><code>Int</code></a> adds
653<a href="/pkg/math/big/#Int.Append"><code>Append</code></a>
654and
655<a href="/pkg/math/big/#Int.Text"><code>Text</code></a>
656methods to give more control over printing.
657</li>
658
659<li>
660Also in the <a href="/pkg/math/big/"><code>math/big</code></a> package,
661<a href="/pkg/math/big/#Float"><code>Float</code></a> now implements
662<a href="/pkg/encoding/#TextMarshaler"><code>encoding.TextMarshaler</code></a> and
663<a href="/pkg/encoding/#TextUnmarshaler"><code>encoding.TextUnmarshaler</code></a>,
664allowing it to be serialized in a natural form by the
665<a href="/pkg/encoding/json/"><code>encoding/json</code></a> and
666<a href="/pkg/encoding/xml/"><code>encoding/xml</code></a> packages.
667</li>
668
669<li>
670Also in the <a href="/pkg/math/big/"><code>math/big</code></a> package,
671<a href="/pkg/math/big/#Float"><code>Float</code></a>'s
672<a href="/pkg/math/big/#Float.Append"><code>Append</code></a> method now supports the special precision argument -1.
673As in
674<a href="/pkg/strconv/#ParseFloat"><code>strconv.ParseFloat</code></a>,
675precision -1 means to use the smallest number of digits necessary such that
676<a href="/pkg/math/big/#Float.Parse"><code>Parse</code></a>
677reading the result into a <code>Float</code> of the same precision
678will yield the original value.
679</li>
680
681<li>
682The <a href="/pkg/math/rand/"><code>math/rand</code></a> package
683adds a
684<a href="/pkg/math/rand/#Read"><code>Read</code></a>
685function, and likewise
686<a href="/pkg/math/rand/#Rand"><code>Rand</code></a> adds a
687<a href="/pkg/math/rand/#Rand.Read"><code>Read</code></a> method.
688These make it easier to generate pseudorandom test data.
689Note that, like the rest of the package,
690these should not be used in cryptographic settings;
691for such purposes, use the <a href="/pkg/crypto/rand/"><code>crypto/rand</code></a> package instead.
692</li>
693
694<li>
695The <a href="/pkg/net/"><code>net</code></a> package's
696<a href="/pkg/net/#ParseMAC"><code>ParseMAC</code></a> function now accepts 20-byte IP-over-InfiniBand (IPoIB) link-layer addresses.
697</li>
698
699
700<li>
701Also in the <a href="/pkg/net/"><code>net</code></a> package,
702there have been a few changes to DNS lookups.
703First, the
704<a href="/pkg/net/#DNSError"><code>DNSError</code></a> error implementation now implements
705<a href="/pkg/net/#Error"><code>Error</code></a>,
706and in particular its new
707<a href="/pkg/net/#DNSError.IsTemporary"><code>IsTemporary</code></a>
708method returns true for DNS server errors.
709Second, DNS lookup functions such as
710<a href="/pkg/net/#LookupAddr"><code>LookupAddr</code></a>
711now return rooted domain names (with a trailing dot)
712on Plan 9 and Windows, to match the behavior of Go on Unix systems.
Russ Coxae9529a2015-12-14 23:16:21 -0500713</li>
714
715<li>
716The <a href="/pkg/net/http/"><code>net/http</code></a> package has
717a number of minor additions beyond the HTTP/2 support already discussed.
718First, the
Russ Cox01ca4da2016-01-27 11:02:45 -0500719<a href="/pkg/net/http/#FileServer"><code>FileServer</code></a> now sorts its generated directory listings by file name.
Russ Coxae9529a2015-12-14 23:16:21 -0500720Second, the
Russ Cox01ca4da2016-01-27 11:02:45 -0500721<a href="/pkg/net/http/#ServeFile"><code>ServeFile</code></a> function now refuses to serve a result
722if the request's URL path contains &ldquo;..&rdquo; (dot-dot) as a path element.
723Programs should typically use <code>FileServer</code> and
724<a href="/pkg/net/http/#Dir"><code>Dir</code></a>
725instead of calling <code>ServeFile</code> directly.
726Programs that need to serve file content in response to requests for URLs containing dot-dot can
727still call <a href="/pkg/net/http/#ServeContent"><code>ServeContent</code></a>.
728Third, the
729<a href="/pkg/net/http/#Client"><code>Client</code></a> now allows user code to set the
Brad Fitzpatricked52e552016-01-05 17:29:16 +0000730<code>Expect:</code> <code>100-continue</code> header (see
Russ Cox01ca4da2016-01-27 11:02:45 -0500731<a href="/pkg/net/http/#Transport"><code>Transport.ExpectContinueTimeout</code></a>).
732Fourth, there are
Brad Fitzpatrick6d617252016-01-28 20:53:41 +0000733<a href="/pkg/net/http/#pkg-constants">five new error codes</a>:
Russ Coxae9529a2015-12-14 23:16:21 -0500734<code>StatusPreconditionRequired</code> (428),
735<code>StatusTooManyRequests</code> (429),
Brad Fitzpatrick6d617252016-01-28 20:53:41 +0000736<code>StatusRequestHeaderFieldsTooLarge</code> (431), and
737<code>StatusNetworkAuthenticationRequired</code> (511) from RFC 6585,
738as well as the recently-approved
739<code>StatusUnavailableForLegalReasons</code> (451).
Russ Cox01ca4da2016-01-27 11:02:45 -0500740Fifth, the implementation and documentation of
741<a href="/pkg/net/http/#CloseNotifier"><code>CloseNotifier</code></a>
Brad Fitzpatricked52e552016-01-05 17:29:16 +0000742has been substantially changed.
Russ Cox01ca4da2016-01-27 11:02:45 -0500743The <a href="/pkg/net/http/#Hijacker"><code>Hijacker</code></a>
Brad Fitzpatricked52e552016-01-05 17:29:16 +0000744interface now works correctly on connections that have previously
745been used with <code>CloseNotifier</code>.
746The documentation now describes when <code>CloseNotifier</code>
747is expected to work.
Russ Coxae9529a2015-12-14 23:16:21 -0500748</li>
749
750<li>
751Also in the <a href="/pkg/net/http/"><code>net/http</code></a> package,
Brad Fitzpatrick32cf9852015-12-17 13:34:41 -0800752there are a few changes related to the handling of a
Russ Cox01ca4da2016-01-27 11:02:45 -0500753<a href="/pkg/net/http/#Request"><code>Request</code></a> data structure with its <code>Method</code> field set to the empty string.
Russ Coxae9529a2015-12-14 23:16:21 -0500754An empty <code>Method</code> field has always been documented as an alias for <code>"GET"</code>
755and it remains so.
756However, Go 1.6 fixes a few routines that did not treat an empty
757<code>Method</code> the same as an explicit <code>"GET"</code>.
758Most notably, in previous releases
Russ Cox01ca4da2016-01-27 11:02:45 -0500759<a href="/pkg/net/http/#Client"><code>Client</code></a> followed redirects only with
Russ Coxae9529a2015-12-14 23:16:21 -0500760<code>Method</code> set explicitly to <code>"GET"</code>;
761in Go 1.6 <code>Client</code> also follows redirects for the empty <code>Method</code>.
762Finally,
Russ Cox01ca4da2016-01-27 11:02:45 -0500763<a href="/pkg/net/http/#NewRequest"><code>NewRequest</code></a> accepts a <code>method</code> argument that has not been
Russ Coxae9529a2015-12-14 23:16:21 -0500764documented as allowed to be empty.
765In past releases, passing an empty <code>method</code> argument resulted
766in a <code>Request</code> with an empty <code>Method</code> field.
767In Go 1.6, the resulting <code>Request</code> always has an initialized
768<code>Method</code> field: if its argument is an empty string, <code>NewRequest</code>
769sets the <code>Method</code> field in the returned <code>Request</code> to <code>"GET"</code>.
770</li>
771
772<li>
773The <a href="/pkg/net/http/httptest/"><code>net/http/httptest</code></a> package's
774<a href="/pkg/net/http/httptest/#ResponseRecorder"><code>ResponseRecorder</code></a> now initializes a default Content-Type header
775using the same content-sniffing algorithm as in
776<a href="/pkg/net/http/#Server"><code>http.Server</code></a>.
777</li>
778
779<li>
780The <a href="/pkg/net/url/"><code>net/url</code></a> package's
781<a href="/pkg/net/url/#Parse"><code>Parse</code></a> is now stricter and more spec-compliant regarding the parsing
782of host names.
783For example, spaces in the host name are no longer accepted.
784</li>
785
786<li>
787Also in the <a href="/pkg/net/url/"><code>net/url</code></a> package,
788the <a href="/pkg/net/url/#Error"><code>Error</code></a> type now implements
789<a href="/pkg/net/#Error"><code>net.Error</code></a>.
790</li>
791
792<li>
793The <a href="/pkg/os/"><code>os</code></a> package's
794<a href="/pkg/os/#IsExist"><code>IsExist</code></a>,
795<a href="/pkg/os/#IsNotExist"><code>IsNotExist</code></a>,
796and
797<a href="/pkg/os/#IsPermission"><code>IsPermission</code></a>
798now return correct results when inquiring about an
799<a href="/pkg/os/#SyscallError"><code>SyscallError</code></a>.
800</li>
801
802<li>
Ian Lance Taylor2a7566252016-01-04 17:18:14 -0800803On Unix-like systems, when a write
804to <a href="/pkg/os/#pkg-variables"><code>os.Stdout</code>
805or <code>os.Stderr</code></a> (more precisely, an <code>os.File</code>
806opened for file descriptor 1 or 2) fails due to a broken pipe error,
807the program will raise a <code>SIGPIPE</code> signal.
808By default this will cause the program to exit; this may be changed by
809calling the
810<a href="/pkg/os/signal"><code>os/signal</code></a>
811<a href="/pkg/os/signal/#Notify"><code>Notify</code></a> function
812for <code>syscall.SIGPIPE</code>.
813A write to a broken pipe on a file descriptor other 1 or 2 will simply
814return <code>syscall.EPIPE</code> (possibly wrapped in
815<a href="/pkg/os#PathError"><code>os.PathError</code></a>
816and/or <a href="/pkg/os#SyscallError"><code>os.SyscallError</code></a>)
817to the caller.
818The old behavior of raising an uncatchable <code>SIGPIPE</code> signal
819after 10 consecutive writes to a broken pipe no longer occurs.
820</li>
821
822<li>
Russ Coxae9529a2015-12-14 23:16:21 -0500823In the <a href="/pkg/os/exec/"><code>os/exec</code></a> package,
824<a href="/pkg/os/exec/#Cmd"><code>Cmd</code></a>'s
825<a href="/pkg/os/exec/#Cmd.Output"><code>Output</code></a> method continues to return an
826<a href="/pkg/os/exec/#ExitError"><code>ExitError</code></a> when a command exits with an unsuccessful status.
827If standard error would otherwise have been discarded,
Dominik Honnef7d8c8c02016-01-23 04:57:21 +0100828the returned <code>ExitError</code> now holds a prefix and suffix
Russ Coxae9529a2015-12-14 23:16:21 -0500829(currently 32 kB) of the failed command's standard error output,
830for debugging or for inclusion in error messages.
831The <code>ExitError</code>'s
832<a href="/pkg/os/exec/#ExitError.String"><code>String</code></a>
833method does not show the captured standard error;
834programs must retrieve it from the data structure
835separately.
836</li>
837
838<li>
839On Windows, the <a href="/pkg/path/filepath/"><code>path/filepath</code></a> package's
840<a href="/pkg/path/filepath/#Join"><code>Join</code></a> function now correctly handles the case when the base is a relative drive path.
841For example, <code>Join(`c:`,</code> <code>`a`)</code> now
842returns <code>`c:a`</code> instead of <code>`c:\a`</code> as in past releases.
843This may affect code that expects the incorrect result.
844</li>
845
846<li>
847In the <a href="/pkg/regexp/"><code>regexp</code></a> package,
848the
849<a href="/pkg/regexp/#Regexp"><code>Regexp</code></a> type has always been safe for use by
850concurrent goroutines.
851It uses a <a href="/pkg/sync/#Mutex"><code>sync.Mutex</code></a> to protect
852a cache of scratch spaces used during regular expression searches.
853Some high-concurrency servers using the same <code>Regexp</code> from many goroutines
854have seen degraded performance due to contention on that mutex.
855To help such servers, <code>Regexp</code> now has a
856<a href="/pkg/regexp/#Regexp.Copy"><code>Copy</code></a> method,
857which makes a copy of a <code>Regexp</code> that shares most of the structure
858of the original but has its own scratch space cache.
859Two goroutines can use different copies of a <code>Regexp</code>
860without mutex contention.
861A copy does have additional space overhead, so <code>Copy</code>
862should only be used when contention has been observed.
863</li>
864
865<li>
866The <a href="/pkg/strconv/"><code>strconv</code></a> package adds
867<a href="/pkg/strconv/#IsGraphic"><code>IsGraphic</code></a>,
Ian Lance Taylorfd24e6d2016-02-03 18:56:24 -0800868similar to <a href="/pkg/strconv/#IsPrint"><code>IsPrint</code></a>.
869It also adds
Russ Coxae9529a2015-12-14 23:16:21 -0500870<a href="/pkg/strconv/#QuoteToGraphic"><code>QuoteToGraphic</code></a>,
871<a href="/pkg/strconv/#QuoteRuneToGraphic"><code>QuoteRuneToGraphic</code></a>,
872<a href="/pkg/strconv/#AppendQuoteToGraphic"><code>AppendQuoteToGraphic</code></a>,
873and
874<a href="/pkg/strconv/#AppendQuoteRuneToGraphic"><code>AppendQuoteRuneToGraphic</code></a>,
875analogous to
Ian Lance Taylorfd24e6d2016-02-03 18:56:24 -0800876<a href="/pkg/strconv/#QuoteToASCII"><code>QuoteToASCII</code></a>,
877<a href="/pkg/strconv/#QuoteRuneToASCII"><code>QuoteRuneToASCII</code></a>,
Russ Coxae9529a2015-12-14 23:16:21 -0500878and so on.
Ian Lance Taylorfd24e6d2016-02-03 18:56:24 -0800879The <code>ASCII</code> family escapes all space characters except ASCII space (U+0020).
Russ Coxae9529a2015-12-14 23:16:21 -0500880In contrast, the <code>Graphic</code> family does not escape any Unicode space characters (category Zs).
881</li>
882
883<li>
884In the <a href="/pkg/testing/"><code>testing</code></a> package,
885when a test calls
886<a href="/pkg/testing/#T.Parallel">t.Parallel</a>,
887that test is paused until all non-parallel tests complete, and then
888that test continues execution with all other parallel tests.
889Go 1.6 changes the time reported for such a test:
890previously the time counted only the parallel execution,
891but now it also counts the time from the start of testing
892until the call to <code>t.Parallel</code>.
893</li>
894
895<li>
896The <a href="/pkg/text/template/"><code>text/template</code></a> package
897contains two minor changes, in addition to the <a href="#template">major changes</a>
898described above.
899First, it adds a new
900<a href="/pkg/text/template/#ExecError"><code>ExecError</code></a> type
901returned for any error during
902<a href="/pkg/text/template/#Template.Execute"><code>Execute</code></a>
903that does not originate in a <code>Write</code> to the underlying writer.
904Callers can distinguish template usage errors from I/O errors by checking for
905<code>ExecError</code>.
906Second, the
907<a href="/pkg/text/template/#Template.Funcs"><code>Funcs</code></a> method
908now checks that the names used as keys in the
909<a href="/pkg/text/template/#FuncMap"><code>FuncMap</code></a>
910are identifiers that can appear in a template function invocation.
911If not, <code>Funcs</code> panics.
912</li>
913
914<li>
915The <a href="/pkg/time/"><code>time</code></a> package's
916<a href="/pkg/time/#Parse"><code>Parse</code></a> function has always rejected any day of month larger than 31,
917such as January 32.
918In Go 1.6, <code>Parse</code> now also rejects February 29 in non-leap years,
919February 30, February 31, April 31, June 31, September 31, and November 31.
920</li>
921
922</ul>
923