1
0
mirror of https://github.com/golang/go synced 2024-11-13 18:20:32 -07:00
Commit Graph

39710 Commits

Author SHA1 Message Date
Richard Musiol
cd5309355e syscall/js: improve type checks of js.Value's methods
Add more explicit checks if the given js.Value is of the correct type
instead of erroring on the JavaScript layer.

Change-Id: I30b18a76820fb68f6ac279bb88a57456f5bab467
Reviewed-on: https://go-review.googlesource.com/c/go/+/168886
Run-TryBot: Richard Musiol <neelance@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-03-26 09:47:28 +00:00
Brad Fitzpatrick
0ec302c49e cmd: update go.mod versions for vetall bug
Updates golang/go#30971
Updates golang/go#31040

Change-Id: I305fbddb6f79cbe3d7e29225841309ab00b1e7dd
Reviewed-on: https://go-review.googlesource.com/c/go/+/169239
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2019-03-26 03:57:49 +00:00
Keith Randall
b7b7b4d6d4 reflect: initialize ptrdata earlier in StructOf
It needs to be set before addTypeBits is called.

Fixes #31043

Change-Id: I692b4047dc17bd68202d45da41dd55d432383e59
Reviewed-on: https://go-review.googlesource.com/c/go/+/169318
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-03-26 03:54:07 +00:00
Keith Randall
17f888c5a8 reflect: fix typeptrdata
We can't use ptrdata inside of typeptrdata, because it won't be
properly initialized until typeptrdata returns.

Fixes #31039

Change-Id: Ib8c89191a7e4cce678a05d351bb6ded81ba23aae
Reviewed-on: https://go-review.googlesource.com/c/go/+/169317
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2019-03-26 03:33:13 +00:00
Matthew Dempsky
c4f87ed26f cmd/compile: fix "append outside assignment" ICE
Some special-case code paths in order.go didn't expect OCALLFUNC to
have Ninit; in particular, OAS2FUNC and ODEFER/OGO failed to call
o.init on their child OCALLFUNC node. This resulted in not all of the
AST being properly ordered.

This was noticed because order is responsible for introducing an
invariant around how OAPPEND is used, which is enforced by walk.
However, there were perhaps simpler cases (e.g., simple order of
evaluation) that were being silently miscompiled.

Fixes #31010.

Change-Id: Ib928890ab5ec2aebd8e30a030bc2b404387f9123
Reviewed-on: https://go-review.googlesource.com/c/go/+/169257
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2019-03-26 02:20:09 +00:00
Neven Sajko
270de1c110 math: use Sincos instead of Sin and Cos in Jn and Yn
Change-Id: I0da3857013f1d4e90820fb043314d78924113a27
GitHub-Last-Rev: 7c3d813c6e
GitHub-Pull-Request: golang/go#31019
Reviewed-on: https://go-review.googlesource.com/c/go/+/169078
Reviewed-by: Robert Griesemer <gri@golang.org>
2019-03-25 22:41:37 +00:00
Robert Griesemer
e4ba40030f math/big: accept non-decimal floats with Rat.SetString
This fixes an old oversight. Rat.SetString already permitted
fractions a/b where both a and b could independently specify
a base prefix. With this CL, it now also accepts non-decimal
floating-point numbers.

Fixes #29799.

Change-Id: I9cc65666a5cebb00f0202da2e4fc5654a02e3234
Reviewed-on: https://go-review.googlesource.com/c/go/+/168237
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2019-03-25 22:29:26 +00:00
Caleb Spare
a591fd08dd testing: correct two spelling/grammar issues
Change-Id: Ic7f7a34e12cc2845e0385a5a872e694d5dca7372
Reviewed-on: https://go-review.googlesource.com/c/go/+/169158
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-03-25 22:26:21 +00:00
Brad Fitzpatrick
e6df179979 cmd/dist: move GOPATH setting from init to bootstrap
CL 168697 unconditionally set GOPATH in dist, which broke the
misc-vet-vetall builder, because cmd/vet/all depends on GOPATH.

Fixes #30971

Change-Id: If6a58e054c6a4fedc2ea506a2c443348489c91f3
Reviewed-on: https://go-review.googlesource.com/c/go/+/169217
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
2019-03-25 22:11:58 +00:00
Rob Pike
50fe9461eb fmt: fix spelling mistake in example
Mea culpa. Beat Takeshi, sumimasen.

Fixes #31023.

Change-Id: Ie2f27a5867724a8a1b8c3082c3389c8fd6d1dee7
Reviewed-on: https://go-review.googlesource.com/c/go/+/168861
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-03-25 21:03:10 +00:00
Keith Randall
db16de9203 runtime: remove kindNoPointers
We already have the ptrdata field in a type, which encodes exactly
the same information that kindNoPointers does.

My problem with kindNoPointers is that it often leads to
double-negative code like:

   t.kind & kindNoPointers != 0

Much clearer is:

   t.ptrdata == 0

Update #27167

Change-Id: I92307d7f018a6bbe3daca4a4abb4225e359349b1
Reviewed-on: https://go-review.googlesource.com/c/go/+/169157
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-03-25 20:46:35 +00:00
Matt Layher
501632339f net: add missing period in conn.File documentation
Change-Id: Ie873d7ed595c91cee4c1aa6c22fa44b61b6190ff
Reviewed-on: https://go-review.googlesource.com/c/go/+/169138
Run-TryBot: Matt Layher <mdlayher@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-03-25 18:16:51 +00:00
Jay Conrod
6e7bc021ee cmd/dist: set GOPATH to internal directory during build
Since GO111MODULE=on by default, the Go command needs a location for
the module cache, even though it doesn't need to be written when
building std and cmd. If GOROOT is checked out to $HOME/go, which is
also the default location for GOPATH, this causes unnecessary problems
late in the build.

With this change, dist sets GOPATH to $GOROOT/pkg/obj/go-path. This is
next to the temporary GOCACHE, $GOROOT/pkg/obj/go-build.

Fixes #30960

Change-Id: I60771ee7f7c67ced1d2dc7c66b5885703fad1b63
Reviewed-on: https://go-review.googlesource.com/c/go/+/168697
Run-TryBot: Jay Conrod <jayconrod@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-03-25 17:58:46 +00:00
Josh Bleecher Snyder
24f846e212 runtime: skip wb call in growslice when unnecessary
Instrumenting make.bash reveals that almost half (49.54%)
of the >16 million calls to growslice for
pointer-containing slices are
growing from an empty to a non-empty slice.

In that case, there is no need to call the write barrier,
which does some work before discovering that no pointers need shading.

Change-Id: Ide741468d8dee7ad43ea0bfbea6ccdf680030a0f
Reviewed-on: https://go-review.googlesource.com/c/go/+/168959
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2019-03-25 17:11:46 +00:00
Keith Randall
2034fbab5b cmd/compile: use existing instructions instead of nops for inline marks
Instead of always inserting a nop to use as the target of an inline
mark, see if we can instead find an instruction we're issuing anyway
with the correct line number, and use that instruction. That way, we
don't need to issue a nop.

Makes cmd/go 0.3% smaller.

Update #29571

Change-Id: If6cfc93ab3352ec2c6e0878f8074a3bf0786b2f8
Reviewed-on: https://go-review.googlesource.com/c/go/+/158021
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2019-03-25 16:49:29 +00:00
Michael Fraenkel
88adc33827 context: remove dependency on reflect
Make context depend on reflectlite instead of reflect in effort to
eventually make net no longer depend on unicode tables.

With this CL we're down to just:

    net -> context -> fmt -> unicode tables

The next CL can remove context -> fmt.

Updates #30440

Change-Id: I7f5df15f975d9dc862c59aa8477c1cfd6ff4967e
Reviewed-on: https://go-review.googlesource.com/c/go/+/164239
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-03-25 16:31:40 +00:00
Vladimir Kovpak
9a8979deb0 math/rand: add example for Intn func
Change-Id: I831ffb5c3fa2872d71def8d8461f0adbd4ae2c1a
GitHub-Last-Rev: 2adfcd2d5a
GitHub-Pull-Request: golang/go#30706
Reviewed-on: https://go-review.googlesource.com/c/go/+/166426
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-03-25 16:05:37 +00:00
Hasan Ozgan
42cdc26665 database/sql: add example for DB.Prepare and Tx.Prepare
Change-Id: Ib9272a7713ed7aaf8ad54c4827be8c095763e648
Reviewed-on: https://go-review.googlesource.com/c/go/+/161677
Reviewed-by: Daniel Theophanes <kardianos@gmail.com>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-03-25 15:51:17 +00:00
sergey
cf99535e21 net/http: reduce allocs on write cookie
Pregrow buffer to reduce allocs on building cookie string.
We calc cookie name value and domain size (most distributed by value) and
add 110 extra characters allows to write most cookie attributes
without additional allocations in most cases.

name              old time/op    new time/op    delta
CookieString-4      1.65µs ± 3%    1.27µs ± 2%  -23.01%  (p=0.008 n=5+5)
ReadSetCookies-4    5.78µs ± 4%    5.67µs ± 3%     ~     (p=0.310 n=5+5)
ReadCookies-4       7.12µs ± 4%    7.04µs ± 3%     ~     (p=0.690 n=5+5)

name              old alloc/op   new alloc/op   delta
CookieString-4        360B ± 0%      144B ± 0%  -60.00%  (p=0.008 n=5+5)
ReadSetCookies-4      976B ± 0%      976B ± 0%     ~     (all equal)
ReadCookies-4       2.17kB ± 0%    2.17kB ± 0%     ~     (all equal)

name              old allocs/op  new allocs/op  delta
CookieString-4        5.00 ± 0%      1.00 ± 0%  -80.00%  (p=0.008 n=5+5)
ReadSetCookies-4      15.0 ± 0%      15.0 ± 0%     ~     (all equal)
ReadCookies-4         16.0 ± 0%      16.0 ± 0%     ~     (all equal)

Change-Id: I50defac954a135b785b3551342b00878429b3d7f
Reviewed-on: https://go-review.googlesource.com/c/go/+/163017
Reviewed-by: Volker Dobler <dr.volker.dobler@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
2019-03-25 15:21:06 +00:00
Than McIntosh
6582ee9cba test: new test for issue 30908
New test case designed to mimic the code in issue 30908, which
features duplicate but non-indentical DWARF abstract subprogram DIEs.

Updates #30908.

Change-Id: Iacb4b53e6a988e46c801cdac236cef883c553f8f
Reviewed-on: https://go-review.googlesource.com/c/go/+/168957
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Reviewed-by: David Chase <drchase@google.com>
2019-03-25 15:00:08 +00:00
Than McIntosh
fbd74a8922 test: support -ldflags for "rundir" tests, new -P option
For "rundir" tests, allow users to add in linker flags as well as
compiler flags, e.g.

// rundir -m -ldflags -w

The directive above will pass "-m" to the compiler on each package compilation
and "-w" to the linker for the final link.

In addition, if "-P" is specified with 'rundir', then for each compile
pass in "-p <X>" to set the packagepath explicitly, which is closer to
how the compiler is run by 'go build'.

Change-Id: I04720011a89d1bd8dcb4f2ccb4af1d74f6a01da1
Reviewed-on: https://go-review.googlesource.com/c/go/+/168977
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-03-25 14:59:58 +00:00
Than McIntosh
68a98d5279 cmd/compile: better handling for PAUTOHEAP in DWARF inline gen
When generating DWARF inline info records, the post-SSA code looks
through the original "pre-inline" dcl list for the function so as to
handle situations where formal params are promoted or optimized away.
This code was not properly handling the case where an output parameter
was promoted to the heap -- in this case the param node is converted
in place from class PPARAMOUT to class PAUTOHEAP. This caused
inconsistencies later on, since the variable entry in the abstract
subprogram DIE wound up as a local and not an output parameter.

Fixes #30908.

Change-Id: Ia70b89f0cf7f9b16246d95df17ad6e307228b8c7
Reviewed-on: https://go-review.googlesource.com/c/go/+/168818
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-03-25 14:03:40 +00:00
Richard Musiol
9eef964800 misc/wasm: exit with code 1 if WebAssembly.instantiate fails
go_js_wasm_exec was returning with code 0 if WebAssembly.instantiate
failed. This made failing tests show as passed.

Change-Id: Icfb2f42e9f1c3c70ca4a130a61a63cb305edff32
Reviewed-on: https://go-review.googlesource.com/c/go/+/168885
Run-TryBot: Richard Musiol <neelance@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-03-25 07:55:12 +00:00
Richard Musiol
fb9b818bbd cmd/link/internal/wasm: do not generate more than 100000 data segments
Some WebAssembly runtimes (e.g. Node.js) fail to load a wasm binary if
it has more than 100000 data segments. Do not skip zero regions any more
if the limit was reached.

Change-Id: I14c4c2aba142d1d2b887bce6d03b8c1c1746c5ec
Reviewed-on: https://go-review.googlesource.com/c/go/+/168884
Run-TryBot: Richard Musiol <neelance@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-03-25 07:54:44 +00:00
Hasan Ozgan
56e1614c47 path/filepath: add examples for Base, Dir and IsAbs
Change-Id: I7a438409748f0f9d6517a7ea1cdee6512ce3ca8a
Reviewed-on: https://go-review.googlesource.com/c/go/+/161678
Run-TryBot: Rob Pike <r@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
2019-03-25 02:57:06 +00:00
Petr Jediný
869620bbea log: expose Writer() method of the standard logger
The Go 1.12 introduced Writer() method for logger objects, but
it was not exposed as log package function for standard logger.
This commit adds such Writer() function.

Change-Id: Ia81b1524839fe05c152ecb5eaef047a076349fea
GitHub-Last-Rev: dc152ea641
GitHub-Pull-Request: golang/go#31009
Reviewed-on: https://go-review.googlesource.com/c/go/+/168920
Run-TryBot: Rob Pike <r@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
2019-03-25 01:18:56 +00:00
sergey
c7bb4533cb net/url: check for lowercase before uppercase in shouldEscape
Most chars in URLs are lowercase, so check that first.

Performance change:

String-4               7.62µs ± 1%    7.27µs ± 3%  -4.61%  (p=0.008 n=5+5)
QueryEscape/#00-4      92.6ns ± 3%    90.3ns ± 1%  -2.48%  (p=0.016 n=5+5)
QueryEscape/#01-4       515ns ± 4%     510ns ± 2%    ~     (p=0.683 n=5+5)
QueryEscape/#02-4       375ns ± 1%     343ns ± 1%  -8.52%  (p=0.008 n=5+5)
QueryEscape/#03-4       758ns ± 1%     699ns ± 1%  -7.83%  (p=0.008 n=5+5)
QueryEscape/#04-4      6.06µs ± 1%    5.74µs ± 1%  -5.38%  (p=0.008 n=5+5)
PathEscape/#00-4        140ns ± 1%     135ns ± 2%  -3.85%  (p=0.008 n=5+5)
PathEscape/#01-4        511ns ± 3%     507ns ± 3%    ~     (p=0.587 n=5+5)
PathEscape/#02-4        372ns ± 1%     342ns ± 2%  -8.22%  (p=0.008 n=5+5)
PathEscape/#03-4        747ns ± 1%     685ns ± 1%  -8.30%  (p=0.008 n=5+5)
PathEscape/#04-4       5.94µs ± 1%    5.64µs ± 3%  -4.98%  (p=0.008 n=5+5)
QueryUnescape/#00-4     111ns ± 4%     110ns ± 2%    ~     (p=0.952 n=5+5)
QueryUnescape/#01-4     390ns ± 0%     391ns ± 2%    ~     (p=0.714 n=5+5)
QueryUnescape/#02-4     297ns ± 5%     295ns ± 3%    ~     (p=0.524 n=5+5)
QueryUnescape/#03-4     543ns ± 3%     556ns ± 2%  +2.39%  (p=0.032 n=5+5)
QueryUnescape/#04-4    3.23µs ± 3%    3.22µs ± 2%    ~     (p=1.000 n=5+5)
PathUnescape/#00-4      111ns ± 1%     110ns ± 3%    ~     (p=0.881 n=5+5)
PathUnescape/#01-4      389ns ± 2%     386ns ± 2%    ~     (p=0.444 n=5+5)
PathUnescape/#02-4      297ns ± 1%     295ns ± 3%    ~     (p=0.738 n=5+5)
PathUnescape/#03-4      557ns ± 3%     553ns ± 2%    ~     (p=0.810 n=5+5)
PathUnescape/#04-4     2.94µs ± 2%    2.97µs ± 2%    ~     (p=0.222 n=5+5)

Change-Id: I7e6d64cd5f8f5218cb40f52f0015168a8674aabb
Reviewed-on: https://go-review.googlesource.com/c/go/+/168883
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-03-24 19:03:16 +00:00
Alex Brainman
7722f6d228 cmd/go: keep WINDIR during TestScript
TestScript executes PowerShell. And PowerShell appears to require
WINDIR environment variable to exists on windows-arm.

So keep WINDIR environment variable when running PowerShell.

Fixes #30711

Change-Id: I14dde6614347325a8f3caf994ea8ab05294450a5
Reviewed-on: https://go-review.googlesource.com/c/go/+/168859
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-03-24 09:15:09 +00:00
Daniel Martí
e770b5b3aa text/template: allow using -}} with many spaces
lexSpace consumed all spaces, even if the last one was part of a right
delimiter like " -}}". Thus, "3  -}}" wouldn't lex as "3" and a right
delimiter, but as "3", "-", and "}}".

To fix that, make lexSpace stop if it encounters a right delimiter.

Fixes #30948.

Change-Id: I80a5546e5809e54f6823e2bf3a57a7e8808329be
Reviewed-on: https://go-review.googlesource.com/c/go/+/168457
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
2019-03-24 09:06:14 +00:00
Richard Musiol
b434bbf197 cmd/go: add GOWASM environment variable
This change adds the environment variable GOWASM, which is a comma
separated list of experimental WebAssembly features that the compiled
WebAssembly binary is allowed to use. The default is to use no
experimental features. Initially there are no features avaiable.

More information about feature proposals can be found at
https://github.com/WebAssembly/proposals

Change-Id: I4c8dc534c99ecff8bb075dded0186ca8f8decaef
Reviewed-on: https://go-review.googlesource.com/c/go/+/168881
Run-TryBot: Richard Musiol <neelance@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-03-23 20:33:57 +00:00
Richard Musiol
2396101e05 src/cmd/internal/obj/wasm: optimize blocks in wasm binary
This change optimizes the blocks in the wasm binary by generating the
entryPointLoop only if it is used and adding an unwindExit block to
be able to use the short BrIf instruction for unwinding the stack.
These changes were suggested by the wasm-opt tool and reduce the
wasm binary size of "hello world" by 1.5%.

Change-Id: Ie52db2fa2d9b8482f9a78b7c189231750811fe97
Reviewed-on: https://go-review.googlesource.com/c/go/+/167937
Run-TryBot: Richard Musiol <neelance@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-03-23 12:34:20 +00:00
Ben Shi
a189467cda cmd/internal/obj/mips: add MADD/MSUB
This CL implements MADD&MSUB, which are mips32r2 instructions.

Change-Id: I06fe51573569baf3b71536336b34b95ccd24750b
Reviewed-on: https://go-review.googlesource.com/c/go/+/167680
Run-TryBot: Ben Shi <powerman1st@163.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-03-23 01:39:16 +00:00
Austin Clements
1257d05088 testing: fix fractional ns/op printing
CL 166717 changed the way ns/op benchmark results were printed and
inadvertently rounded all ns/op results down to an integer, even if
they were small enough to print with digits after the decimal place.
For example, prior to this change, we got output like

    BenchmarkFast-8       380491575	 3.12 ns/op

CL 166717 changed this to

    BenchmarkFast-8       380491575      3.00 ns/op

This had the further side-effect that ns/op values between 0 and 1
would not be printed at all because they would be rounded down to 0.

This CL fixes this by always recomputing the float64 value of ns/op
instead of using the int64 truncation from BenchmarkResult.NsPerOp.

Fixes #30997. Fixes #31005.

Change-Id: I21f73b9d5cc5ad41e7ff535675d07ca00051ecd7
Reviewed-on: https://go-review.googlesource.com/c/go/+/168937
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2019-03-22 21:19:22 +00:00
Dmitri Shuralyov
94563de87f cmd/go: fix the default build output name for versioned binaries
This change is a re-apply of the reverted CL 140863 with changes to
address issue #30821. Specifically, path.Split continues to be used
to split the '/'-separated import path, rather than filepath.Split.

Document the algorithm for how the default executable name is determined
in DefaultExecName.

Rename a variable returned from os.Stat from bs to fi for consistency.

CL 140863 factored out the logic to determine the default executable
name from the Package.load method into a DefaultExecName function,
and started using it in more places to avoid having to re-implement
the logic everywhere it's needed. Most previous callers already computed
the default executable name based on the import path. The load.Package
method, before CL 140863, was the exception, in that it used the p.Dir
value in GOPATH mode instead. There was a NOTE(rsc) comment that it
should be equivalent to use import path, but it was too late in Go 1.11
cycle to risk implementing that change.

This is part 1, a more conservative change for backporting to Go 1.12.2,
and it keeps the original behavior of splitting on p.Dir in GOPATH mode.
Part 2 will address the NOTE(rsc) comment and modify behavior in
Package.load to always use DefaultExecName which splits the import path
rather than directory. It is intended to be included in Go 1.13.

Fixes #27283 (again)
Updates #26869
Fixes #30821

Change-Id: Ib1ebb95acba7c85c24e3a55c40cdf48405af34f3
Reviewed-on: https://go-review.googlesource.com/c/go/+/167503
Reviewed-by: Jay Conrod <jayconrod@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2019-03-22 19:28:22 +00:00
Dmitri Shuralyov
1e83369ca0 Revert "cmd/go: fix the default build output name for versioned binaries"
This reverts CL 140863 (commit bf94fc3ae3).

Reason for revert: There was a potential problem spotted in the original
fix, which resulted in it being rolled back from release-branch.go1.12
and not included in Go 1.12.1 release. We intend to improve the fix and
include it in Go 1.12.2 instead. To make the fix easier to backport,
revert this change before re-applying the improved fix (next commit).

Change-Id: If6c785f58482d2531b5927c5ea7002f548c21c7c
Reviewed-on: https://go-review.googlesource.com/c/go/+/168402
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2019-03-22 19:22:42 +00:00
Than McIntosh
d923309a17 cmd/link: add optional sanity checking for duplicate symbols
Introduce a new linker command line option "-strictdups", which
enables sanity checking of "ok to duplicate" symbols, especially
DWARF info symbols. Acceptable values are 0 (no checking) 1 (issue
warnings) and 2 (issue a fatal error checks fail).

Currently if we read a DWARF symbol (such as "go.info.PKG.FUNCTION")
from one object file, and then encounter the same symbol later on
while reading another object file, we simply discard the second one
and move on with the link, since the two should in theory be
identical.

If as a result of a compiler bug we wind up with symbols that are not
identical, this tends to (silently) result in incorrect DWARF
generation, which may or may not be discovered depending on who is
consuming the DWARF and what's being done with it.

When this option is turned on, at the point where a duplicate
symbol is detected in the object file reader, we check to make sure
that the length/contents of the symbol are the same as the previously
read symbol, and print a descriptive warning (or error) if not.

For the time being this can be used for one-off testing to find
problems; at some point it would be nice if we can enable it by
default.

Updates #30908.

Change-Id: I64c4e07c326b4572db674ff17c93307e2eec607c
Reviewed-on: https://go-review.googlesource.com/c/go/+/168410
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2019-03-22 17:26:03 +00:00
Daniel Martí
0fbf681840 cmd/compile: reduce rulegen's for loop verbosity
A lot of the naked for loops begin like:

	for {
		v := b.Control
		if v.Op != OpConstBool {
			break
		}
		...
		return true
	}

Instead, write them out in a more compact and readable way:

	for v.Op == OpConstBool {
		...
		return true
	}

This requires the addition of two bytes.Buffer writers, as this helps us
make a decision based on future pieces of generated code. This probably
makes rulegen slightly slower, but that's not noticeable; the code
generation still takes ~3.5s on my laptop, excluding build time.

The "v := b.Control" declaration can be moved to the top of each
function. Even though the rules can modify b.Control when firing, they
also make the function return, so v can't be used again.

While at it, remove three unnecessary lines from the top of each
rewriteBlock func.

In total, this results in ~4k lines removed from the generated code, and
a slight improvement in readability.

Change-Id: I317e4c6a4842c64df506f4513375475fad2aeec5
Reviewed-on: https://go-review.googlesource.com/c/go/+/167399
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2019-03-22 15:41:51 +00:00
Richard Musiol
b06d2122ee os,syscall: implement functions related to uid, gid and pid on js/wasm
This change implements the following functions on js/wasm:
- os.Chown
- os.Fchown
- os.Lchown
- syscall.Getuid
- syscall.Getgid
- syscall.Geteuid
- syscall.Getegid
- syscall.Getgroups
- syscall.Getpid
- syscall.Getppid
- syscall.Umask

Change-Id: Icdb0fafc02c9df6e9e3573542f8499c3464dc671
Reviewed-on: https://go-review.googlesource.com/c/go/+/154157
Run-TryBot: Richard Musiol <neelance@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-03-22 15:40:37 +00:00
erifan01
d0cbf9bf53 cmd/compile: follow up intrinsifying math/bits.Add64 for arm64
This CL deals with the additional comments of CL 159017.

Change-Id: I4ad3c60c834646d58dc0c544c741b92bfe83fb8b
Reviewed-on: https://go-review.googlesource.com/c/go/+/168857
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-03-22 15:09:47 +00:00
Iskander Sharipov
9889138614 sort: replace Errorf+FailNow with Fatalf
Change-Id: I4f8d0178e780b86d1f551b367e2ddac3789be5aa
Reviewed-on: https://go-review.googlesource.com/c/go/+/168880
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-03-22 14:26:11 +00:00
Clément Chigot
cf952e9e62 cmd: enable -buildmode=pie on aix/ppc64
Change-Id: I939518462c931ba9feb125b2f299ef0706b124ce
Reviewed-on: https://go-review.googlesource.com/c/go/+/168879
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-03-22 14:24:53 +00:00
Clément Chigot
08692bed1e cmd/compile, misc/cgo: fix fortran tests on aix/ppc64
Enable pattern lib.a/shared.so.X in cgo_import_dynamic as on AIX,
archive files (.a) often have shared objects (.so) inside them.

Change-Id: I21096c75eb7fbcc7064b0b832bfa8ed862142051
Reviewed-on: https://go-review.googlesource.com/c/go/+/168877
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-03-22 13:52:59 +00:00
Clément Chigot
83d90bbc82 syscall: fix returned values of Dup2 on aix/ppc64
Change-Id: Ia78ea589cc6d58ff22f7d519399c06c5308419dd
Reviewed-on: https://go-review.googlesource.com/c/go/+/168878
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
2019-03-22 13:50:19 +00:00
Andrei Tudor Călin
4906a00cdd image/png: add Fuzz function
Add a Fuzz function to package png, under the gofuzz build
tag. This function is based on the png/png.go code, from
github.com/dvyukov/go-fuzz-corpus, modified to use direct
comparison of image bounds rather than reflect.DeepEqual.

Updates #30979
Updates #19109

Change-Id: Idb86e7ded0c2d78e6cadbeda84c7b1f35b8c579c
Reviewed-on: https://go-review.googlesource.com/c/go/+/168558
Reviewed-by: thepudds <thepudds1460@gmail.com>
Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
Run-TryBot: Dmitry Vyukov <dvyukov@google.com>
2019-03-22 09:07:09 +00:00
Tobias Klauser
9a49b17f25 misc/cgo: gofmt testdata files
Change-Id: I64e05a1f768cb57194506021bb7fdca0ad19bf1c
Reviewed-on: https://go-review.googlesource.com/c/go/+/168461
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-03-22 07:21:24 +00:00
Josh Bleecher Snyder
9f56845f2c cmd/compile: stop shadowing bool type in rewrite rules
This disrupts code instrumentation tools like go-fuzz.

Change-Id: I524f31316975096ca5e3b1203a82e91ed1b6097e
Reviewed-on: https://go-review.googlesource.com/c/go/+/168801
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-03-22 05:01:41 +00:00
Richard Musiol
99e223289b cmd/link/internal/wasm: optimize data section in wasm binary
This change optimizes the data section in the wasm binary by
omitting blocks of zeroes and instead emitting data segments
with offsets skipping the zeroes.

This optimization is inspired by the memory-packing pass of the
wasm-opt tool and reduces the wasm binary size of "hello world" by 14%.

Change-Id: Iba3043df05bf6aab4745c5f8015c0337fc218aff
Reviewed-on: https://go-review.googlesource.com/c/go/+/167801
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-03-21 23:49:38 +00:00
Nigel Tao
4dad64f5f1 image/gif: don't assume Encode src's origin is (0, 0)
When gif.Encode is given an "m image.Image" argument that isn't an
*image.Paletted, it creates a temporary *image.Paletted (called pm) that
is intended to be a copy of this image, only with fewer colors.

That creation process, and specifically the opts.Drawer.Draw call that
does the copy, incorrectly assumed that m.Bounds().Min is the zero point
(0, 0). This commit fixes that.

Fixes #30887

Change-Id: Ie03bddec359e2dcc52f18451049452105514e179
Reviewed-on: https://go-review.googlesource.com/c/go/+/168418
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
2019-03-21 22:35:59 +00:00
Cherry Zhang
f23c601bf9 cmd/compile: copy volatile values before emitting write barrier call
It is possible that a "volatile" value (one that can be clobbered
by preparing args of a call) to be used in multiple write barrier
calls. We used to copy the volatile value right before each call.
But this doesn't work if the value is used the second time, after
the first call where it is already clobbered. Copy it before
emitting any call.

Fixes #30977.

Change-Id: Iedcc91ad848d5ded547bf37a8359c125d32e994c
Reviewed-on: https://go-review.googlesource.com/c/go/+/168677
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2019-03-21 21:05:13 +00:00
Elias Naur
804a4024ec cmd/link/internal/ld: don't leave files open in a loop
Noticed by Ingo Oeser in his review of CL 168321.

Change-Id: I2f39db675a7c22b395062a11903657a9d0d1956d
Reviewed-on: https://go-review.googlesource.com/c/go/+/168560
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-03-21 20:55:09 +00:00