]> Cypherpunks repositories - gostls13.git/log
gostls13.git
10 years agoruntime: get rid of copyable check - all G frames are copyable.
Keith Randall [Thu, 11 Sep 2014 20:46:58 +0000 (13:46 -0700)]
runtime: get rid of copyable check - all G frames are copyable.

Just go ahead and do it, if something is wrong we'll throw.

Also rip out cc-generated arg ptr maps, they are useless now.

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/133690045

10 years agoruntime: make Gosched nosplit
Russ Cox [Thu, 11 Sep 2014 20:33:01 +0000 (16:33 -0400)]
runtime: make Gosched nosplit

Replacing gosched with Gosched broke some builds because
some of the call sites are at times when the stack cannot be grown.

TBR=khr
CC=golang-codereviews
https://golang.org/cl/142000043

10 years agoruntime: move gosched to Go, to add stack frame information
Russ Cox [Thu, 11 Sep 2014 20:22:21 +0000 (16:22 -0400)]
runtime: move gosched to Go, to add stack frame information

LGTM=khr
R=khr
CC=golang-codereviews
https://golang.org/cl/134520044

10 years agogo/printer, gofmt: don't align map entries for irregular inputs
Robert Griesemer [Thu, 11 Sep 2014 19:57:51 +0000 (12:57 -0700)]
go/printer, gofmt: don't align map entries for irregular inputs

Details: Until now, when we saw a key:value pair that fit onto
a single line, we assumed that it should be formatted with a
vtab after the ':' for alignment of its value. This leads to
odd behavior if there are more than one such pair on a line.
This CL changes the behavior such that alignment is only used
for the first pair on a line. This preserves existing behavior
(in the std lib we have composite literals where the last line
contains multiple entries and the first entry's value is aligned
with the values on previous lines), and resolves this issue.

No impact on formatting of std lib, go.tools, go.exp, go.net.

Fixes #8685.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/139430043

10 years agotest: return errors earlier in run.go
Josh Bleecher Snyder [Thu, 11 Sep 2014 19:47:17 +0000 (12:47 -0700)]
test: return errors earlier in run.go

Fixes #8184.

LGTM=bradfitz
R=bradfitz
CC=golang-codereviews
https://golang.org/cl/137510043

10 years agocmd/gc: emit write barriers
Russ Cox [Thu, 11 Sep 2014 16:17:45 +0000 (12:17 -0400)]
cmd/gc: emit write barriers

A write *p = x that needs a write barrier (not all do)
now turns into runtime.writebarrierptr(p, x)
or one of the other variants.

The write barrier implementations are trivial.
The goal here is to emit the calls in the correct places
and to incur the cost of those function calls in the Go 1.4 cycle.

Performance on the Go 1 benchmark suite below.
Remember, the goal is to slow things down (and be correct).

We will look into optimizations in separate CLs, as part of
the process of comparing Go 1.3 against tip in order to make
sure Go 1.4 runs at least as fast as Go 1.3.

benchmark                          old ns/op      new ns/op      delta
BenchmarkBinaryTree17              3118336716     3452876110     +10.73%
BenchmarkFannkuch11                3184497677     3211552284     +0.85%
BenchmarkFmtFprintfEmpty           89.9           107            +19.02%
BenchmarkFmtFprintfString          236            287            +21.61%
BenchmarkFmtFprintfInt             246            278            +13.01%
BenchmarkFmtFprintfIntInt          395            458            +15.95%
BenchmarkFmtFprintfPrefixedInt     343            378            +10.20%
BenchmarkFmtFprintfFloat           477            525            +10.06%
BenchmarkFmtManyArgs               1446           1707           +18.05%
BenchmarkGobDecode                 14398047       14685958       +2.00%
BenchmarkGobEncode                 12557718       12947104       +3.10%
BenchmarkGzip                      453462345      472413285      +4.18%
BenchmarkGunzip                    114226016      115127398      +0.79%
BenchmarkHTTPClientServer          114689         112122         -2.24%
BenchmarkJSONEncode                24914536       26135942       +4.90%
BenchmarkJSONDecode                86832877       103620289      +19.33%
BenchmarkMandelbrot200             4833452        4898780        +1.35%
BenchmarkGoParse                   4317976        4835474        +11.98%
BenchmarkRegexpMatchEasy0_32       150            166            +10.67%
BenchmarkRegexpMatchEasy0_1K       393            402            +2.29%
BenchmarkRegexpMatchEasy1_32       125            142            +13.60%
BenchmarkRegexpMatchEasy1_1K       1010           1236           +22.38%
BenchmarkRegexpMatchMedium_32      232            301            +29.74%
BenchmarkRegexpMatchMedium_1K      76963          102721         +33.47%
BenchmarkRegexpMatchHard_32        3833           5463           +42.53%
BenchmarkRegexpMatchHard_1K        119668         161614         +35.05%
BenchmarkRevcomp                   763449047      706768534      -7.42%
BenchmarkTemplate                  124954724      134834549      +7.91%
BenchmarkTimeParse                 517            511            -1.16%
BenchmarkTimeFormat                501            514            +2.59%

benchmark                         old MB/s     new MB/s     speedup
BenchmarkGobDecode                53.31        52.26        0.98x
BenchmarkGobEncode                61.12        59.28        0.97x
BenchmarkGzip                     42.79        41.08        0.96x
BenchmarkGunzip                   169.88       168.55       0.99x
BenchmarkJSONEncode               77.89        74.25        0.95x
BenchmarkJSONDecode               22.35        18.73        0.84x
BenchmarkGoParse                  13.41        11.98        0.89x
BenchmarkRegexpMatchEasy0_32      213.30       191.72       0.90x
BenchmarkRegexpMatchEasy0_1K      2603.92      2542.74      0.98x
BenchmarkRegexpMatchEasy1_32      254.00       224.93       0.89x
BenchmarkRegexpMatchEasy1_1K      1013.53      827.98       0.82x
BenchmarkRegexpMatchMedium_32     4.30         3.31         0.77x
BenchmarkRegexpMatchMedium_1K     13.30        9.97         0.75x
BenchmarkRegexpMatchHard_32       8.35         5.86         0.70x
BenchmarkRegexpMatchHard_1K       8.56         6.34         0.74x
BenchmarkRevcomp                  332.92       359.62       1.08x
BenchmarkTemplate                 15.53        14.39        0.93x

LGTM=rlh
R=rlh
CC=dvyukov, golang-codereviews, iant, khr, r
https://golang.org/cl/136380043

10 years agoruntime: allow crash from gsignal stack
Russ Cox [Thu, 11 Sep 2014 16:08:30 +0000 (12:08 -0400)]
runtime: allow crash from gsignal stack

The uses of onM in dopanic/startpanic are okay even from the signal stack.

Fixes #8666.

LGTM=khr
R=khr
CC=golang-codereviews
https://golang.org/cl/134710043

10 years agonet: fix inconsistent behavior across platforms in SetKeepAlivePeriod
Mikio Hara [Thu, 11 Sep 2014 08:56:58 +0000 (17:56 +0900)]
net: fix inconsistent behavior across platforms in SetKeepAlivePeriod

The previous implementation used per-socket TCP keepalive options
wrong. For example, it used another level socket option to control
TCP and it didn't use TCP_KEEPINTVL option when possible.

Fixes #8683.
Fixes #8701.
Update #8679

LGTM=iant
R=golang-codereviews, iant
CC=golang-codereviews
https://golang.org/cl/136480043

10 years agoruntime: add timing test for iterate/delete map idiom.
Keith Randall [Thu, 11 Sep 2014 05:54:07 +0000 (22:54 -0700)]
runtime: add timing test for iterate/delete map idiom.

LGTM=bradfitz, iant
R=iant, bradfitz
CC=golang-codereviews
https://golang.org/cl/140510043

10 years agoreflect: use runtime's memmove instead of its own
Keith Randall [Wed, 10 Sep 2014 19:37:28 +0000 (12:37 -0700)]
reflect: use runtime's memmove instead of its own

They will both need write barriers at some point.
But until then, no reason why we shouldn't share.

LGTM=rsc
R=golang-codereviews, rsc
CC=golang-codereviews
https://golang.org/cl/141330043

10 years agoruntime: stop plan9/amd64 build from crashing
Anthony Martin [Wed, 10 Sep 2014 13:25:05 +0000 (06:25 -0700)]
runtime: stop plan9/amd64 build from crashing

LGTM=iant
R=rsc, 0intro, alex.brainman, iant
CC=golang-codereviews
https://golang.org/cl/140460044

10 years agoruntime: cleanup openbsd semasleep implementation
Matthew Dempsky [Wed, 10 Sep 2014 00:41:48 +0000 (17:41 -0700)]
runtime: cleanup openbsd semasleep implementation

The previous implementation had several subtle issues.  It's not
clear if any of these could actually be causing the flakiness
problems on openbsd/386, but fixing them should only help.

1. thrsleep() is implemented internally as unlock, then test *abort
(if abort != nil), then tsleep().  Under the current code, that makes
it theoretically possible that semasleep()/thrsleep() could release
waitsemalock, then a racing semawakeup() could acquire the lock,
increment waitsemacount, and call thrwakeup()/wakeup() before
thrsleep() reaches tsleep().  (In practice, OpenBSD's big kernel lock
seems unlikely to let this actually happen.)

The proper way to avoid this is to pass &waitsemacount as the abort
pointer to thrsleep so thrsleep knows to re-check it before going to
sleep, and to wakeup if it's non-zero.  Then we avoid any races.
(I actually suspect openbsd's sema{sleep,wakeup}() could be further
simplified using cas/xadd instead of locks, but I don't want to be
more intrusive than necessary so late in the 1.4 release cycle.)

2. semasleep() takes a relative sleep duration, but thrsleep() needs
an absolute sleep deadline.  Instead of recomputing the deadline each
iteration, compute it once up front and use (*Timespec)(nil) to signify
no deadline.  Ensures we retry properly if there's a spurious wakeup.

3. Instead of assuming if thrsleep() woke up and waitsemacount wasn't
available that we must have hit the deadline, check that the system
call returned EWOULDBLOCK.

4. Instead of assuming that 64-bit systems are little-endian, compute
timediv() using a temporary int32 nsec and then assign it to tv_nsec.

LGTM=iant
R=jsing, iant
CC=golang-codereviews
https://golang.org/cl/137960043

10 years agoruntime: call rfork on scheduler stack on Plan 9
Anthony Martin [Wed, 10 Sep 2014 00:19:01 +0000 (17:19 -0700)]
runtime: call rfork on scheduler stack on Plan 9

A race exists between the parent and child processes after a fork.
The child needs to access the new M pointer passed as an argument
but the parent may have already returned and clobbered it.

Previously, we avoided this by saving the necessary data into
registers before the rfork system call but this isn't guaranteed
to work because Plan 9 makes no promises about the register state
after a system call. Only the 386 kernel seems to save them.
For amd64 and arm, this method won't work.

We eliminate the race by allocating stack space for the scheduler
goroutines (g0) in the per-process copy-on-write stack segment and
by only calling rfork on the scheduler stack.

LGTM=aram, 0intro, rsc
R=aram, 0intro, mischief, rsc
CC=golang-codereviews
https://golang.org/cl/110680044

10 years agoruntime: more cleanups
Keith Randall [Tue, 9 Sep 2014 21:32:53 +0000 (14:32 -0700)]
runtime: more cleanups

Move timenow thunk into time.s
Move declarations for generic c/asm services into stubs.go

LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/137360043

10 years agoruntime: map iterators: always use intrabucket randomess
Keith Randall [Tue, 9 Sep 2014 21:22:58 +0000 (14:22 -0700)]
runtime: map iterators: always use intrabucket randomess

Fixes #8688

LGTM=rsc
R=golang-codereviews, bradfitz, rsc, khr
CC=golang-codereviews
https://golang.org/cl/135660043

10 years agoruntime: fix plan9/amd64 build?
Russ Cox [Tue, 9 Sep 2014 21:16:31 +0000 (17:16 -0400)]
runtime: fix plan9/amd64 build?

The only thing I can see that is really Plan 9-specific
is that the stack pointer used for signal handling used
to have more mapped memory above it.
Specifically it used to have at most 88 bytes (StackTop),
so change the allocation of a 40-byte frame to a 128-byte frame.

No idea if this will work, but worth a try.

Note that "fix" here means get it back to timing out
instead of crashing.

TBR=iant
CC=golang-codereviews
https://golang.org/cl/142840043

10 years agoruntime: fix windows/386 build
Russ Cox [Tue, 9 Sep 2014 21:12:05 +0000 (17:12 -0400)]
runtime: fix windows/386 build

The difference between the old and the new (from earlier) code
is that we set stackguard = stack.lo + StackGuard, while the old
code set stackguard = stack.lo. That 512 bytes appears to be
the difference between the profileloop function running and not running.

We don't know how big the system stack is, but it is likely MUCH bigger than 4k.
Give Go/C 8k.

TBR=iant
CC=golang-codereviews
https://golang.org/cl/140440044

10 years agoruntime: avoid read overrun in heapdump
Russ Cox [Tue, 9 Sep 2014 19:38:55 +0000 (15:38 -0400)]
runtime: avoid read overrun in heapdump

Start the stack a few words below the actual top, so that
if something tries to read goexit's caller PC from the stack,
it won't fault on a bad memory address.
Today, heapdump does that.
Maybe tomorrow, traceback or something else will do that.
Make it not a bug.

TBR=khr
R=khr
CC=golang-codereviews
https://golang.org/cl/136450043

10 years agotesting: read coverage counters atomically
Rob Pike [Tue, 9 Sep 2014 19:31:07 +0000 (12:31 -0700)]
testing: read coverage counters atomically
For -mode=atomic, we need to read the counters
using an atomic load to avoid a race. Not worth worrying
about when -mode=atomic is set during generation
of the profile, so we use atomic loads always.

Fixes #8630.

LGTM=rsc
R=dvyukov, rsc
CC=golang-codereviews
https://golang.org/cl/141800043

10 years agofmt: fix allocation test
Rob Pike [Tue, 9 Sep 2014 18:45:46 +0000 (11:45 -0700)]
fmt: fix allocation test
With new interface allocation rules, the old counts were wrong and
so was the commentary.

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/142760044

10 years agostrconv: fix documentation for CanBackquote.
Rob Pike [Tue, 9 Sep 2014 18:45:36 +0000 (11:45 -0700)]
strconv: fix documentation for CanBackquote.
Space is not a control character.

Fixes #8571.

LGTM=iant
R=golang-codereviews, iant
CC=golang-codereviews
https://golang.org/cl/137380043

10 years agoruntime: fix build failures after CL 137410043
Russ Cox [Tue, 9 Sep 2014 18:02:37 +0000 (14:02 -0400)]
runtime: fix build failures after CL 137410043

No promise about correctness, but they do build.

TBR=khr
CC=golang-codereviews
https://golang.org/cl/143720043

10 years agoruntime: assume precisestack, copystack, StackCopyAlways, ScanStackByFrames
Russ Cox [Tue, 9 Sep 2014 17:39:57 +0000 (13:39 -0400)]
runtime: assume precisestack, copystack, StackCopyAlways, ScanStackByFrames

Commit to stack copying for stack growth.

We're carrying around a surprising amount of cruft from older schemes.
I am confident that precise stack scans and stack copying are here to stay.

Delete fallback code for when precise stack info is disabled.
Delete fallback code for when copying stacks is disabled.
Delete fallback code for when StackCopyAlways is disabled.
Delete Stktop chain - there is only one stack segment now.
Delete M.moreargp, M.moreargsize, M.moreframesize, M.cret.
Delete G.writenbuf (unrelated, just dead).
Delete runtime.lessstack, runtime.oldstack.
Delete many amd64 morestack variants.
Delete initialization of morestack frame/arg sizes (shortens split prologue!).

Replace G's stackguard/stackbase/stack0/stacksize/
syscallstack/syscallguard/forkstackguard with simple stack
bounds (lo, hi).

Update liblink, runtime/cgo for adjustments to G.

LGTM=khr
R=khr, bradfitz
CC=golang-codereviews, iant, r
https://golang.org/cl/137410043

10 years agoundo CL 140110043 / 17b5fc2aa130
Alex Brainman [Tue, 9 Sep 2014 06:05:00 +0000 (16:05 +1000)]
undo CL 140110043 / 17b5fc2aa130

I have found better approach, then longer wait.
See CL 134360043 for details.

««« original CL description
runtime/pprof: adjust cpuHogger so that tests pass on windows builders

LGTM=rsc
R=dvyukov, rsc
CC=golang-codereviews
https://golang.org/cl/140110043

»»»

LGTM=dave
R=golang-codereviews, dave, dvyukov
CC=golang-codereviews
https://golang.org/cl/133500043

10 years agoruntime: merge mallocgc, gomallocgc
Russ Cox [Tue, 9 Sep 2014 05:08:34 +0000 (01:08 -0400)]
runtime: merge mallocgc, gomallocgc

I assumed they were the same when I wrote
cgocallback.go earlier today. Merge them
to eliminate confusion.

I can't tell what gomallocgc did before with
a nil type but without FlagNoScan.
I created a call like that in cgocallback.go
this morning, translating from a C file.
It was supposed to do what the C version did,
namely treat the block conservatively.
Now it will.

LGTM=khr
R=khr
CC=golang-codereviews
https://golang.org/cl/141810043

10 years agoruntime: let stack copier update Panic structs for us
Russ Cox [Tue, 9 Sep 2014 01:02:36 +0000 (21:02 -0400)]
runtime: let stack copier update Panic structs for us

It already is updating parts of them; we're just getting lucky
retraversing them and not finding much to do.
Change argp to a pointer so that it will be updated too.
Existing tests break if you apply the change to adjustpanics
without also updating the type of argp.

LGTM=khr
R=khr
CC=golang-codereviews
https://golang.org/cl/139380043

10 years agosyscall: keep Windows syscall pointers live too
Brad Fitzpatrick [Tue, 9 Sep 2014 00:47:12 +0000 (17:47 -0700)]
syscall: keep Windows syscall pointers live too

Like https://golang.org/cl/139360044

LGTM=rsc, alex.brainman
R=alex.brainman, rsc
CC=golang-codereviews
https://golang.org/cl/138250043

10 years agoruntime: on bigger maps, start iterator at a random bucket.
Keith Randall [Tue, 9 Sep 2014 00:42:21 +0000 (17:42 -0700)]
runtime: on bigger maps, start iterator at a random bucket.

This change brings the iter/delete pattern down to O(n lgn) from O(n^2).

Fixes #8412.

before:
BenchmarkMapPop100    50000      32498 ns/op
BenchmarkMapPop1000      500    3244851 ns/op
BenchmarkMapPop10000        5  270276855 ns/op

after:
BenchmarkMapPop100   100000      16169 ns/op
BenchmarkMapPop1000     5000     300416 ns/op
BenchmarkMapPop10000      300    5990814 ns/op

LGTM=iant
R=golang-codereviews, iant, khr
CC=golang-codereviews
https://golang.org/cl/141270043

10 years agosyscall: fix comment in mkall_windows.bat
Brad Fitzpatrick [Tue, 9 Sep 2014 00:40:32 +0000 (17:40 -0700)]
syscall: fix comment in mkall_windows.bat

src/pkg -> src

LGTM=alex.brainman
R=alex.brainman
CC=golang-codereviews
https://golang.org/cl/139400043

10 years agoruntime: enable StackCopyAlways
Russ Cox [Tue, 9 Sep 2014 00:37:28 +0000 (20:37 -0400)]
runtime: enable StackCopyAlways

It worked at CL 134660043 on the builders,
so I believe it will stick this time.

LGTM=bradfitz
R=khr, bradfitz
CC=golang-codereviews
https://golang.org/cl/141280043

10 years agoA+C: John Olds (individual CLA)
Andrew Gerrand [Mon, 8 Sep 2014 23:12:21 +0000 (09:12 +1000)]
A+C: John Olds (individual CLA)

Generated by a+c.

LGTM=jtolds, jbd
R=gobot, jbd, jtolds
CC=golang-codereviews
https://golang.org/cl/137300043

10 years agoruntime: note the double-releasem isn't an error.
Keith Randall [Mon, 8 Sep 2014 22:42:48 +0000 (15:42 -0700)]
runtime: note the double-releasem isn't an error.

LGTM=bradfitz
R=dave, bradfitz
CC=golang-codereviews
https://golang.org/cl/136390043

10 years agonet: don't set wrong option for controlling tcp keepalive on openbsd
Mikio Hara [Mon, 8 Sep 2014 22:22:11 +0000 (07:22 +0900)]
net: don't set wrong option for controlling tcp keepalive on openbsd

Fixes #8679.

LGTM=iant
R=golang-codereviews, iant
CC=golang-codereviews
https://golang.org/cl/141730043

10 years agoruntime: turn off StackCopyAlways
Russ Cox [Mon, 8 Sep 2014 22:07:50 +0000 (18:07 -0400)]
runtime: turn off StackCopyAlways

windows/amd64 failure:
http://build.golang.org/log/1ded5e3ef4bd1226f976e3180772f87e6c918255

# ..\misc\cgo\testso
runtime: copystack: locals size info only for syscall.Syscall
fatal error: split stack not allowed

runtime stack:
runtime.throw(0xa64cc7)
        c:/go/src/runtime/panic.go:395 +0xad fp=0x6fde0 sp=0x6fdb0
runtime.newstack()
        c:/go/src/runtime/stack.c:1001 +0x750 fp=0x6ff20 sp=0x6fde0
runtime.morestack()
        c:/go/src/runtime/asm_amd64.s:306 +0x73 fp=0x6ff28 sp=0x6ff20

goroutine 1 [stack growth, locked to thread]:
runtime.freedefer(0xc0820ce120)
        c:/go/src/runtime/panic.go:162 fp=0xc08201b1a0 sp=0xc08201b198
runtime.deferreturn(0xa69420)
        c:/go/src/runtime/panic.go:211 +0xa8 fp=0xc08201b1e8 sp=0xc08201b1a0
runtime.cgocall_errno(0x498c00, 0xc08201b228, 0x0)
        c:/go/src/runtime/cgocall.go:134 +0x10e fp=0xc08201b210 sp=0xc08201b1e8
syscall.Syscall(0x7786b1d0, 0x2, 0xc0820c85b0, 0xc08201b2d8, 0x0, 0x0, 0x0, 0x0)
        c:/go/src/runtime/syscall_windows.c:74 +0x3c fp=0xc08201b260 sp=0xc08201b210
syscall.findFirstFile1(0xc0820c85b0, 0xc08201b2d8, 0x500000000000000, 0x0, 0x0)
        c:/go/src/syscall/zsyscall_windows.go:340 +0x76 fp=0xc08201b2b0 sp=0xc08201b260
syscall.FindFirstFile(0xc0820c85b0, 0xc08210c500, 0xc0820c85b0, 0x0, 0x0)
        c:/go/src/syscall/syscall_windows.go:907 +0x6a fp=0xc08201b530 sp=0xc08201b2b0
os.openDir(0xc0820b2e40, 0x33, 0x0, 0x0, 0x0)
        c:/go/src/os/file_windows.go:96 +0x110 fp=0xc08201b5e0 sp=0xc08201b530
os.OpenFile(0xc0820b2e40, 0x33, 0x0, 0x0, 0x41, 0x0, 0x0)
        c:/go/src/os/file_windows.go:143 +0x1e9 fp=0xc08201b650 sp=0xc08201b5e0

TBR=khr
CC=golang-codereviews
https://golang.org/cl/138230043

10 years agoruntime: mark endcgo go:nosplit
Russ Cox [Mon, 8 Sep 2014 22:07:33 +0000 (18:07 -0400)]
runtime: mark endcgo go:nosplit

Should help windows/amd64.

TBR=khr
CC=golang-codereviews
https://golang.org/cl/134660043

10 years agogo/parser: fix (pathological) corner case
Robert Griesemer [Mon, 8 Sep 2014 21:54:00 +0000 (14:54 -0700)]
go/parser: fix (pathological) corner case

Inside a control clause (if ... {}), composite
literals starting with a type name must be parenthesized.
A composite literal used in the array length expression
of an array composite literal is already parenthesized.
Not a valid program, but syntactically is should
be accepted.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/142760043

10 years agoruntime: mark freedefer and deferclass go:nosplit
Russ Cox [Mon, 8 Sep 2014 21:37:49 +0000 (17:37 -0400)]
runtime: mark freedefer and deferclass go:nosplit

This should make deferreturn nosplit all the way down,
which should fix the current windows/amd64 failure.
If not, I will change StackCopyAlways back to 0.

TBR=khr
CC=golang-codereviews
https://golang.org/cl/135600043

10 years agodoc: amend installation instructions
Andrew Gerrand [Mon, 8 Sep 2014 21:35:44 +0000 (07:35 +1000)]
doc: amend installation instructions

Fixes #8674.

LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/139320044

10 years agoruntime: enable StackCopyAlways
Russ Cox [Mon, 8 Sep 2014 21:23:40 +0000 (17:23 -0400)]
runtime: enable StackCopyAlways

Let's see how close we are to this being ready.
Will roll back if it breaks any builds in non-trivial ways.

LGTM=r, khr
R=iant, khr, r
CC=golang-codereviews
https://golang.org/cl/138200043

10 years agoruntime: undo stray edit from CL 140380043
Russ Cox [Mon, 8 Sep 2014 21:01:40 +0000 (17:01 -0400)]
runtime: undo stray edit from CL 140380043

Was having serious editor problems on Windows.

TBR=brainman, iant
CC=golang-codereviews
https://golang.org/cl/137370043

10 years agosyscall: keep allocated C string live across call to Syscall
Russ Cox [Mon, 8 Sep 2014 20:59:59 +0000 (16:59 -0400)]
syscall: keep allocated C string live across call to Syscall

Given:

        p := alloc()
        fn_taking_ptr(p)

p is NOT recorded as live at the call to fn_taking_ptr:
it's not needed by the code following the call.
p was passed to fn_taking_ptr, and fn_taking_ptr must keep
it alive as long as it needs it.
In practice, fn_taking_ptr will keep its own arguments live
for as long as the function is executing.

But if instead you have:

        p := alloc()
        i := uintptr(unsafe.Pointer(p))
        fn_taking_int(i)

p is STILL NOT recorded as live at the call to fn_taking_int:
it's not needed by the code following the call.
fn_taking_int is responsible for keeping its own arguments
live, but fn_taking_int is written to take an integer, so even
though fn_taking_int does keep its argument live, that argument
does not keep the allocated memory live, because the garbage
collector does not dereference integers.

The shorter form:

        p := alloc()
        fn_taking_int(uintptr(unsafe.Pointer(p)))

and the even shorter form:

        fn_taking_int(uintptr(unsafe.Pointer(alloc())))

are both the same as the 3-line form above.

syscall.Syscall is like fn_taking_int: it is written to take a list
of integers, and yet those integers are sometimes pointers.
If there is no other copy of those pointers being kept live,
the memory they point at may be garbage collected during
the call to syscall.Syscall.

This is happening on Solaris: for whatever reason, the timing
is such that the garbage collector manages to free the string
argument to the open(2) system call before the system call
has been invoked.

Change the system call wrappers to insert explicit references
that will keep the allocations alive in the original frame
(and therefore preserve the memory) until after syscall.Syscall
has returned.

Should fix Solaris flakiness.

This is not a problem for cgo, because cgo wrappers have
correctly typed arguments.

LGTM=iant, khr, aram, rlh
R=iant, khr, bradfitz, aram, rlh
CC=dvyukov, golang-codereviews, r
https://golang.org/cl/139360044

10 years agoruntime: run sighandler on g0 stack on windows
Russ Cox [Mon, 8 Sep 2014 20:56:46 +0000 (16:56 -0400)]
runtime: run sighandler on g0 stack on windows

The sighander has been run at the bottom of the
currently executing goroutine stack, but it's in C,
and we don't want C on our ordinary goroutine stacks.
Worse, it does a lot of stuff, and it might need more
stack space. There is scary code in traceback_windows.go
that talks about stack splits during sighandler.
Moving sighandler to g0 will eliminate the possibility
of stack splits and such, and then we can delete
traceback_windows.go entirely. Win win.

On the builder, all.bat passes with GOARCH=amd64
and all.bat gets most of the way with GOARCH=386
except for a DLL-loading test that I think is unrelated.

Fixes windows build.

TBR=brainman, iant
CC=golang-codereviews
https://golang.org/cl/140380043

10 years agoruntime: merge panic1.go back into panic.go
Keith Randall [Mon, 8 Sep 2014 19:33:08 +0000 (12:33 -0700)]
runtime: merge panic1.go back into panic.go

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/139370043

10 years agoliblink, runtime: diagnose and fix C code running on Go stack
Russ Cox [Mon, 8 Sep 2014 18:05:23 +0000 (14:05 -0400)]
liblink, runtime: diagnose and fix C code running on Go stack

This CL contains compiler+runtime changes that detect C code
running on Go (not g0, not gsignal) stacks, and it contains
corrections for what it detected.

The detection works by changing the C prologue to use a different
stack guard word in the G than Go prologue does. On the g0 and
gsignal stacks, that stack guard word is set to the usual
stack guard value. But on ordinary Go stacks, that stack
guard word is set to ^0, which will make any stack split
check fail. The C prologue then calls morestackc instead
of morestack, and morestackc aborts the program with
a message about running C code on a Go stack.

This check catches all C code running on the Go stack
except NOSPLIT code. The NOSPLIT code is allowed,
so the check is complete. Since it is a dynamic check,
the code must execute to be caught. But unlike the static
checks we've been using in cmd/ld, the dynamic check
works with function pointers and other indirect calls.
For example it caught sigpanic being pushed onto Go
stacks in the signal handlers.

Fixes #8667.

LGTM=khr, iant
R=golang-codereviews, khr, iant
CC=golang-codereviews, r
https://golang.org/cl/133700043

10 years agoruntime: a few cleanups.
Keith Randall [Mon, 8 Sep 2014 17:14:41 +0000 (10:14 -0700)]
runtime: a few cleanups.

LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/134630043

10 years agoandroidtest.bash: adjustment for move from src/pkg to src
David Crawshaw [Mon, 8 Sep 2014 14:07:26 +0000 (10:07 -0400)]
androidtest.bash: adjustment for move from src/pkg to src

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/142740043

10 years agocmd/cc: fix undefined behaviour warning in bv.c
Dave Cheney [Mon, 8 Sep 2014 06:06:41 +0000 (16:06 +1000)]
cmd/cc: fix undefined behaviour warning in bv.c

Fixes warning

# _/home/dfc/go/misc/cgo/test/backdoor
/home/dfc/go/src/cmd/cc/bv.c:43:11: runtime error: left shift of 1 by 31 places cannot be represented in type 'int'

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/136330043

10 years agocmd/gc: fix undefined behaviour warning in subr.c
Dave Cheney [Mon, 8 Sep 2014 05:36:21 +0000 (15:36 +1000)]
cmd/gc: fix undefined behaviour warning in subr.c

Fixes warning

/home/dfc/go/src/cmd/gc/subr.c:3469:8: runtime error: negation of -9223372036854775808 cannot be represented in type 'int64' (aka 'long'); cast to an unsigned type to negate this value to itself

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/141220043

10 years agodoc/go1.4.txt: src/pkg directory is gone.
Rob Pike [Mon, 8 Sep 2014 04:55:02 +0000 (21:55 -0700)]
doc/go1.4.txt: src/pkg directory is gone.

CC=golang-codereviews
https://golang.org/cl/139310043

10 years agobuild: more adjustments for move from src/pkg to src
Russ Cox [Mon, 8 Sep 2014 04:22:40 +0000 (00:22 -0400)]
build: more adjustments for move from src/pkg to src

These were missed in CL 134570043.

Fixes nacl, solaris builds.

TBR=r
CC=golang-codereviews
https://golang.org/cl/136320043

10 years agobuild: move package sources from src/pkg to src
Russ Cox [Mon, 8 Sep 2014 04:08:51 +0000 (00:08 -0400)]
build: move package sources from src/pkg to src

Preparation was in CL 134570043.
This CL contains only the effect of 'hg mv src/pkg/* src'.
For more about the move, see golang.org/s/go14nopkg.

10 years agobuild: adjustments for move from src/pkg to src
Russ Cox [Mon, 8 Sep 2014 04:06:45 +0000 (00:06 -0400)]
build: adjustments for move from src/pkg to src

This CL adjusts code referring to src/pkg to refer to src.

Immediately after submitting this CL, I will submit
a change doing 'hg mv src/pkg/* src'.
That change will be too large to review with Rietveld
but will contain only the 'hg mv'.

This CL will break the build.
The followup 'hg mv' will fix it.

For more about the move, see golang.org/s/go14nopkg.

LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/134570043

10 years agodoc: add a few http items to go1.4.txt
Brad Fitzpatrick [Mon, 8 Sep 2014 03:52:22 +0000 (20:52 -0700)]
doc: add a few http items to go1.4.txt

CC=golang-codereviews
https://golang.org/cl/132670045

10 years agonet/http: add Transport.DialTLS hook
Brad Fitzpatrick [Mon, 8 Sep 2014 03:48:40 +0000 (20:48 -0700)]
net/http: add Transport.DialTLS hook

Per discussions out of https://golang.org/cl/128930043/
and golang-nuts threads and with agl.

Fixes #8522

LGTM=agl, adg
R=agl, c, adg
CC=c, golang-codereviews
https://golang.org/cl/137940043

10 years agoruntime: implement time.now in assembly on plan9, solaris, windows
Russ Cox [Mon, 8 Sep 2014 03:40:59 +0000 (23:40 -0400)]
runtime: implement time.now in assembly on plan9, solaris, windows

These all used a C implementation that contained 64-bit divide by 1000000000.
On 32-bit systems that ends up in the 64-bit C divide support, which makes
other calls and ends up using a fair amount of stack. We could convert them
to Go but then they'd still end up in software 64-bit divide code. That would
be okay, because Go code can split the stack, but it's still unnecessary.

Write time·now in assembly, just like on all the other systems, and use the
actual hardware support for 64/32 -> 64/32 division. This cuts the software
routines out entirely.

The actual code to do the division is copied and pasted from the sys_darwin_*.s files.

LGTM=alex.brainman
R=golang-codereviews, alex.brainman
CC=aram, golang-codereviews, iant, khr, r
https://golang.org/cl/136300043

10 years agonet/http/httptest: delete TestIssue7264
Russ Cox [Mon, 8 Sep 2014 03:40:27 +0000 (23:40 -0400)]
net/http/httptest: delete TestIssue7264

Now it's failing on Windows:

panic: httptest: failed to listen on a port: listen tcp 127.0.0.1:0:
listen: An operation on a socket could not be performed because the
system lacked sufficient buffer space or because a queue was full.

Since we can't seem to understand what the test is trying to test,
and because it is causing problems on multiple systems,
delete it.

Fixes #7264.

TBR=bradfitz
CC=brainman, golang-codereviews
https://golang.org/cl/141210043

10 years agoruntime: fix semacquire->acquireSudog->malloc->gogc->semacquire loop
Russ Cox [Mon, 8 Sep 2014 03:16:12 +0000 (23:16 -0400)]
runtime: fix semacquire->acquireSudog->malloc->gogc->semacquire loop

This is what broke the build at
http://build.golang.org/log/d9c6d334be16cbab85e99fddc6b4ba034319bd4e

LGTM=iant
R=golang-codereviews, iant
CC=dvyukov, golang-codereviews, khr, r
https://golang.org/cl/135580043

10 years agonet/http/httptest: fix deadlock in TestIssue7264
Russ Cox [Mon, 8 Sep 2014 00:13:35 +0000 (20:13 -0400)]
net/http/httptest: fix deadlock in TestIssue7264

I am seeing deadlocks waiting on <-inHandler.
It seems to me that there is no guarantee that the
handler actually runs, if the client does

        write header
        close connection

fast enough. The server might see the EOF on the
connection before it manages to invoke the handler.

This change fixes the deadlock, but it may make
the test not actually test anything. Not sure.

LGTM=bradfitz
R=bradfitz, dvyukov
CC=golang-codereviews
https://golang.org/cl/140970043

10 years agoruntime: save g to TLS more aggressively
Russ Cox [Sun, 7 Sep 2014 23:47:40 +0000 (19:47 -0400)]
runtime: save g to TLS more aggressively

This is one of those "how did this ever work?" bugs.
The current build failures are happening because
a fault comes up while executing on m->curg on a
system-created thread using an m obtained from needm,
but TLS is set to m->g0, not m->curg. On fault,
sigtramp starts executing, assumes r10 (g) might be
incorrect, reloads it from TLS, and gets m->g0, not
m->curg. Then sighandler dutifully pushes a call to
sigpanic onto the stack and returns to it.
We're now executing on the m->curg stack but with
g=m->g0. Sigpanic does a stack split check, sees that
the SP is not in range (50% chance depending on relative
ordering of m->g0's and m->curg's stacks), and then
calls morestack. Morestack sees that g=m->g0 and
crashes the program.

The fix is to replace every change of g in asm_arm.s
with a call to a function that both updates g and
saves the updated g to TLS.

Why did it start happening? That's unclear.
Unfortunately there were other bugs in the initial
checkin that mask exactly which of a sequence of
CLs started the behavior where sigpanic would end
up tripping the stack split.

Fixes arm build.
Fixes #8675.

LGTM=iant
R=golang-codereviews, iant
CC=dave, golang-codereviews, khr, minux, r
https://golang.org/cl/135570043

10 years agocrypto/tls: print unexpected error in test
Russ Cox [Sun, 7 Sep 2014 13:07:19 +0000 (09:07 -0400)]
crypto/tls: print unexpected error in test

Maybe will help us understand Solaris build failure.

TBR=aram
CC=golang-codereviews
https://golang.org/cl/139290043

10 years agoliblink: fix arm wrapper prologue
Russ Cox [Sun, 7 Sep 2014 12:59:20 +0000 (08:59 -0400)]
liblink: fix arm wrapper prologue

Fixes arm build.

TBR=khr
CC=golang-codereviews
https://golang.org/cl/132700043

10 years agobuild: fix windows make.bat
Russ Cox [Sun, 7 Sep 2014 11:31:53 +0000 (07:31 -0400)]
build: fix windows make.bat

The Unix make.bash builds cmd/dist from *.c.
make.bat apparently does not.

TBR=r
CC=golang-codereviews
https://golang.org/cl/137280043

10 years agocmd/dist: remove goc2c
Russ Cox [Sun, 7 Sep 2014 11:23:49 +0000 (07:23 -0400)]
cmd/dist: remove goc2c

After the three pending CLs listed below, there will be no more .goc files.

134580043 runtime: move stubs.goc code into runtime.c
133670043 runtime: fix windows syscalls for copying stacks
141180043 runtime: eliminate Go -> C -> block paths for Solaris

LGTM=bradfitz
R=golang-codereviews, bradfitz, dave
CC=golang-codereviews, iant, r
https://golang.org/cl/132680043

10 years agoruntime: fix nacl/amd64p32 build
Russ Cox [Sun, 7 Sep 2014 11:23:18 +0000 (07:23 -0400)]
runtime: fix nacl/amd64p32 build

Update #8675
Fixes nacl/amd64p32 build.

TBR=khr
CC=golang-codereviews
https://golang.org/cl/141140045

10 years agoruntime: fix windows syscalls for copying stacks
Russ Cox [Sun, 7 Sep 2014 01:19:24 +0000 (21:19 -0400)]
runtime: fix windows syscalls for copying stacks

Syscall and everything it calls must be nosplit:
we cannot split a stack once Syscall has been invoked,
because we don't know which of its arguments are
pointers.

LGTM=khr, r, alex.brainman
R=dvyukov, iant, khr, r, bradfitz, alex.brainman
CC=golang-codereviews
https://golang.org/cl/133670043

10 years agoruntime: eliminate Go -> C -> block paths for Solaris
Russ Cox [Sun, 7 Sep 2014 01:16:35 +0000 (21:16 -0400)]
runtime: eliminate Go -> C -> block paths for Solaris

LGTM=aram, r
R=golang-codereviews, aram, r
CC=golang-codereviews, iant, khr
https://golang.org/cl/141180043

10 years agoruntime: increase stack split limit again
Russ Cox [Sun, 7 Sep 2014 01:16:13 +0000 (21:16 -0400)]
runtime: increase stack split limit again

Increase NOSPLIT reservation from 192 to 384 bytes.
The problem is that the non-Unix systems (Solaris and Windows)
just can't make system calls in a small amount of space,
and then worse they do things that are complex enough
to warrant calling runtime.throw on failure.
We don't have time to rewrite the code to use less stack.

I'm not happy about this, but it's still a small amount.

The good news is that we're doing this to get to only
using copying stacks for stack growth. Once that is true,
we can drop the default stack size from 8k to 4k, which
should more than make up for the bytes we're losing here.

LGTM=r
R=iant, r, bradfitz, aram.h
CC=golang-codereviews
https://golang.org/cl/140350043

10 years agomisc/makerelease: make goimports-safe
Russ Cox [Sun, 7 Sep 2014 01:10:06 +0000 (21:10 -0400)]
misc/makerelease: make goimports-safe

LGTM=bradfitz
R=adg, bradfitz, minux
CC=golang-codereviews
https://golang.org/cl/140310045

10 years agocmd/yacc: move cmd/yacc/expr to cmd/yacc/testdata/expr
Russ Cox [Sat, 6 Sep 2014 19:27:52 +0000 (15:27 -0400)]
cmd/yacc: move cmd/yacc/expr to cmd/yacc/testdata/expr

This will keep the go command from trying to build it
when the cmd/ tree is no longer a special case.

Also update doc.go to refer to the correct location.
(It was incorrect even before this CL.)

LGTM=r
R=iant, r
CC=golang-codereviews
https://golang.org/cl/134560043

10 years agoruntime/cgo: use just #include "textflag.h"
Russ Cox [Sat, 6 Sep 2014 19:27:39 +0000 (15:27 -0400)]
runtime/cgo: use just #include "textflag.h"

This will withstand the src/pkg/ to src/ move.

LGTM=r
R=iant, r
CC=golang-codereviews
https://golang.org/cl/134530044

10 years agoruntime: move stubs.goc code into runtime.c
Russ Cox [Sat, 6 Sep 2014 19:27:26 +0000 (15:27 -0400)]
runtime: move stubs.goc code into runtime.c

Now that the calling conventions are the same,
there's no danger to using plain C for these.

LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=dvyukov, golang-codereviews, iant, khr, r
https://golang.org/cl/134580043

10 years agoliblink: fix arm build errors
Russ Cox [Sat, 6 Sep 2014 18:53:44 +0000 (14:53 -0400)]
liblink: fix arm build errors

This was supposed to be in CL 135490044
but got lost in a transfer from machine to machine.

TBR=khr
R=khr
CC=golang-codereviews
https://golang.org/cl/135560043

10 years agoruntime, syscall: rewrite syscall_solaris.goc in Go
Aram Hăvărneanu [Sat, 6 Sep 2014 17:35:46 +0000 (19:35 +0200)]
runtime, syscall: rewrite syscall_solaris.goc in Go

LGTM=dave, rsc
R=khr, dvyukov, dave, gobot, rsc
CC=golang-codereviews, rsc
https://golang.org/cl/133220044

10 years agoruntime: fix panic/wrapper/recover math
Russ Cox [Sat, 6 Sep 2014 17:19:08 +0000 (13:19 -0400)]
runtime: fix panic/wrapper/recover math

The gp->panicwrap adjustment is just fatally flawed.
Now that there is a Panic.argp field, update that instead.
That can be done on entry only, so that unwinding doesn't
need to worry about undoing anything. The wrappers
emit a few more instructions in the prologue but everything
else in the system gets much simpler.

It also fixes (without trying) a broken test I never checked in.

Fixes #7491.

LGTM=khr
R=khr
CC=dvyukov, golang-codereviews, iant, r
https://golang.org/cl/135490044

10 years agoruntime: badreflectcall runs on the G stack - convert to Go.
Keith Randall [Sat, 6 Sep 2014 17:12:47 +0000 (10:12 -0700)]
runtime: badreflectcall runs on the G stack - convert to Go.

LGTM=iant
R=golang-codereviews, iant
CC=golang-codereviews
https://golang.org/cl/136260043

10 years agoruntime: get rid of other Go->C calls in test exports.
Keith Randall [Sat, 6 Sep 2014 17:07:23 +0000 (10:07 -0700)]
runtime: get rid of other Go->C calls in test exports.

testSchedLocal* tests need to malloc now because their
stack frames are too big to fit on the G0 stack.

LGTM=iant
R=golang-codereviews, iant, khr
CC=golang-codereviews
https://golang.org/cl/133660043

10 years agoruntime: move gostringw and gogobytes test stubs to Go.
Keith Randall [Fri, 5 Sep 2014 22:01:09 +0000 (15:01 -0700)]
runtime: move gostringw and gogobytes test stubs to Go.

LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/141150043

10 years agoruntime: run getgcmask on the M stack.
Keith Randall [Fri, 5 Sep 2014 21:59:31 +0000 (14:59 -0700)]
runtime: run getgcmask on the M stack.

LGTM=rsc
R=rsc, khr
CC=golang-codereviews
https://golang.org/cl/132660043

10 years agoruntime: disable StackCopyAlways
Russ Cox [Fri, 5 Sep 2014 21:00:32 +0000 (17:00 -0400)]
runtime: disable StackCopyAlways

I forgot to clear this before submitting.

TBR=khr
CC=golang-codereviews
https://golang.org/cl/132640044

10 years agoruntime: use reflect.call during panic instead of newstackcall
Russ Cox [Fri, 5 Sep 2014 20:51:45 +0000 (16:51 -0400)]
runtime: use reflect.call during panic instead of newstackcall

newstackcall creates a new stack segment, and we want to
be able to throw away all that code.

LGTM=khr
R=khr, iant
CC=dvyukov, golang-codereviews, r
https://golang.org/cl/139270043

10 years agomisc/cgo/test: make issue5548 test pickier
Russ Cox [Fri, 5 Sep 2014 18:59:09 +0000 (14:59 -0400)]
misc/cgo/test: make issue5548 test pickier

If there is doubt about passing arguments correctly
(as there is in this test), there should be doubt about
getting the results back intact too. Using 0 and 1
(especially 0 for success) makes it easy to get a PASS
accidentally when the return value is not actually
being propagated. Use less common values.

LGTM=iant
R=golang-codereviews, iant
CC=golang-codereviews, r
https://golang.org/cl/141110043

10 years agoruntime: handle nil ptr load/store in arm software floating point
Russ Cox [Fri, 5 Sep 2014 18:58:54 +0000 (14:58 -0400)]
runtime: handle nil ptr load/store in arm software floating point

We cannot let a real panic start there, because there is C code
on the stack, and worse, there is an assembly frame with a
saved copy of the registers and we have no idea which ones
are pointers.

Instead, detect the nil ptr load/store and return out of the C
and assembly into a stub that will start the call to sigpanic.

Fixes GOARM=5 build.

LGTM=iant
R=golang-codereviews, iant
CC=dave, golang-codereviews, minux, r
https://golang.org/cl/138130043

10 years agoruntime: clean up sigqueue.go
Russ Cox [Fri, 5 Sep 2014 18:38:29 +0000 (14:38 -0400)]
runtime: clean up sigqueue.go

Minor changes to make logic clearer.
Observed while working on the conversion.

LGTM=iant, dvyukov
R=dvyukov, iant
CC=golang-codereviews
https://golang.org/cl/140250043

10 years agonet: temporarily skip TestAcceptIgnoreSomeErrors
Alex Brainman [Fri, 5 Sep 2014 15:48:21 +0000 (08:48 -0700)]
net: temporarily skip TestAcceptIgnoreSomeErrors

Update #8662

LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/138120043

10 years agoruntime: convert panic/recover to Go
Keith Randall [Fri, 5 Sep 2014 14:04:16 +0000 (10:04 -0400)]
runtime: convert panic/recover to Go

created panic1.go just so diffs were available.
After this CL is in, I'd like to move panic.go -> defer.go
and panic1.go -> panic.go.

LGTM=rsc
R=rsc, khr
CC=golang-codereviews
https://golang.org/cl/133530045

10 years agoruntime: use cas loop to coordinate with sigprof
Russ Cox [Fri, 5 Sep 2014 03:14:21 +0000 (23:14 -0400)]
runtime: use cas loop to coordinate with sigprof

sigprof and setcpuprofilerate coordinate the enabling/disabling
of the handler using a Mutex. This has always been a bit dodgy:
setcpuprofilerate must be careful to turn off signals before acquiring
the lock to avoid a deadlock.

Now the lock implementations use onM, and onM isn't okay on the
signal stack. We know how to make it okay, but it's more work than
is probably worth doing.

Since this is super-dodgy anyway, replace the lock with a simple
cas loop. It is only contended if setcpuprofilerate is being called,
and that doesn't happen frequently enough to care about the
raw speed or about using futexes/semaphores.

TBR to fix freebsd/amd64 and dragonfly/amd64 builds.
Happy to make changes in a follow-up CL.

TBR=dvyukov
CC=golang-codereviews
https://golang.org/cl/141080044

10 years agosyscall: in linux/arm Syscall, zero R3, R4, R5
Russ Cox [Fri, 5 Sep 2014 03:12:10 +0000 (23:12 -0400)]
syscall: in linux/arm Syscall, zero R3, R4, R5

The general kernel system call interface
takes 6 arguments: R0, R1, R2, R3, R4, R5.

Syscall is for calls that only need 3.
The amd64 and 386 versions zero the extra arg registers,
but the arm version does not.

func utimensat calls Syscall with 3 arguments.
The kernel expects a 4th argument.
That turns out to be whatever is in R3 at the time of the call.
CL 137160043 changed various pieces of code and apparently
changed the value left in R3 at the time of utimensat's Syscall.
This causes the kernel to return EINVAL.

Change linux/arm Syscall to zero R3, R4, R5, so that calls will
behave deterministically, even if they pass too few arguments.

Arguably, utimensat could be fixed too, but the predictable
zeroing is certainly worth doing, and once done utimensat's
use of Syscall is fine.

Fixes arm build.

TBR=bradfitz
CC=golang-codereviews
https://golang.org/cl/141080043

10 years agoruntime: use new #include "textflag.h"
Russ Cox [Fri, 5 Sep 2014 03:05:18 +0000 (23:05 -0400)]
runtime: use new #include "textflag.h"

I did this just to clean things up, but it will be important
when we drop the pkg directory later.

LGTM=bradfitz
R=r, bradfitz
CC=golang-codereviews
https://golang.org/cl/132600043

10 years agoruntime: do not stop traceback at onM
Russ Cox [Fri, 5 Sep 2014 02:48:08 +0000 (22:48 -0400)]
runtime: do not stop traceback at onM

Behavior before this CL:

1. If onM is called on a g0 stack, it just calls the given function.

2. If onM is called on a gsignal stack, it calls badonm.

3. If onM is called on a curg stack, it switches to the g0 stack
and then calls the function.

In cases 1 and 2, if the program then crashes (and badonm always does),
we want to see what called onM, but the traceback stops at onM.
In case 3, the traceback must stop at onM, because the g0
stack we are renting really does stop at onM.

The current code stops the traceback at onM to handle 3,
at the cost of making 1 and 2 crash with incomplete traces.

Change traceback to scan past onM but in case 3 make it look
like on the rented g0 stack, onM was called from mstart.
The traceback already knows that mstart is a top-of-stack function.

Alternate fix at CL 132610043 but I think this one is cleaner.
This CL makes 3 the exception, while that CL makes 1 and 2 the exception.

Submitting TBR to try to get better stack traces out of the
freebsd/amd64 builder, but happy to make changes in a
followup CL.

TBR=khr
R=khr
CC=golang-codereviews
https://golang.org/cl/133620043

10 years agocmd/dist: another attempt at textflag.h
Russ Cox [Fri, 5 Sep 2014 01:56:11 +0000 (21:56 -0400)]
cmd/dist: another attempt at textflag.h

The old change worked fine in my client, but my client
must not have been in a completely clean state.

TBR=r
CC=golang-codereviews
https://golang.org/cl/138100043

10 years agocmd/dist: make textflag.h available in runtime, avoid android/linux conflicts
Russ Cox [Fri, 5 Sep 2014 01:22:18 +0000 (21:22 -0400)]
cmd/dist: make textflag.h available in runtime, avoid android/linux conflicts

1) cmd/dist was copying textflag.h to the build include directory,
but only after compiling package runtime. So other packages could
use it, just not runtime. Copy earlier, so that runtime can use it too.

2) We decided for android that anything marked linux is also included
in the build. The generated linux-specific files in cmd/dist must therefore
have explicit +build !android tags, or else you can't have simultaneous
linux/arm and android/arm builds in a single client. The tag was already
there for at least one file, but it was missing from many others.

LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/134500043

10 years agoruntime: mark sysAlloc nosplit
Russ Cox [Fri, 5 Sep 2014 01:12:48 +0000 (21:12 -0400)]
runtime: mark sysAlloc nosplit

sysAlloc is the only mem function called from Go.

LGTM=iant, khr
R=golang-codereviews, khr, 0intro, iant
CC=dvyukov, golang-codereviews, r
https://golang.org/cl/139210043

10 years agoruntime: more C to Go conversion adjustments
Russ Cox [Fri, 5 Sep 2014 01:12:31 +0000 (21:12 -0400)]
runtime: more C to Go conversion adjustments

Mostly NOSPLIT additions.
Had to rewrite atomic_arm.c in Go because it calls lock,
and lock is too complex.

With this CL, I find no Go -> C calls that can split the stack
on any system except Solaris and Windows.

Solaris and Windows need more work and will be done separately.

LGTM=iant, dave
R=golang-codereviews, bradfitz, iant, dave
CC=dvyukov, golang-codereviews, khr, r
https://golang.org/cl/137160043

10 years agocmd/api: don't depend on os/user or USER to check api
Brad Fitzpatrick [Fri, 5 Sep 2014 00:13:22 +0000 (17:13 -0700)]
cmd/api: don't depend on os/user or USER to check api

The -nocgo builder failed because it has cgo disabled
as well as no USER environment variable:
http://build.golang.org/log/2250abb82f5022b72a12997b8ff89fcdeff094c9

# Checking API compatibility.
Error getting current user: user: Current not implemented on linux/amd64
exit status 1

Don't require the environment variable here.

LGTM=minux
R=dave, adg, minux
CC=golang-codereviews
https://golang.org/cl/140290043

10 years agogo/parser: fix "zero day" parse error
Robert Griesemer [Thu, 4 Sep 2014 22:18:32 +0000 (15:18 -0700)]
go/parser: fix "zero day" parse error

(a b string, ok bool) is not a valid signature

Fixes #8656.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/137140043

10 years agoruntime: make more functions safe for Go
Russ Cox [Thu, 4 Sep 2014 19:53:45 +0000 (15:53 -0400)]
runtime: make more functions safe for Go

Convert no-op race functions.
Everything else is tiny and gets NOSPLITs.

After this, all that is left on darwin is sysAlloc, panic, and gothrow (all pending).
There may be system-specific calls in other builds.

LGTM=iant
R=golang-codereviews, iant
CC=dvyukov, golang-codereviews, khr, r
https://golang.org/cl/140240044

10 years agoruntime: convert cgocall to Go
Dmitriy Vyukov [Thu, 4 Sep 2014 18:40:40 +0000 (14:40 -0400)]
runtime: convert cgocall to Go

LGTM=khr, rsc
R=golang-codereviews, khr, rsc
CC=golang-codereviews
https://golang.org/cl/131670043

10 years agoruntime: use C for readgstatus, goroutine status values
Russ Cox [Thu, 4 Sep 2014 18:19:50 +0000 (14:19 -0400)]
runtime: use C for readgstatus, goroutine status values

When this code was written, there was no way for Go to
reuse the C function and enum values. Now there is.

LGTM=bradfitz
R=rlh, bradfitz
CC=dvyukov, golang-codereviews, iant, khr, r
https://golang.org/cl/139150045

10 years agoruntime: reconvert sigqueue.goc from C to Go
Russ Cox [Thu, 4 Sep 2014 17:51:12 +0000 (13:51 -0400)]
runtime: reconvert sigqueue.goc from C to Go

The original conversion in CL 132090043 cut up
the function in an attempt to avoid converting most
of the code to Go. This contorts the control flow.

While debugging the onM signal stack bug,
I reconverted sigqueue.goc in its entirety.
This restores the original control flow, which is
much easier to understand.

The current conversion is correct, it's just complex
and will be hard to maintain. The new one is as
readable as the original code.

I uploaded sigqueue.goc as the initial copy of
sigqueue.go in the CL, so if you view the diffs
of sigqueue.go comparing against patch set 2 [sic]
it will show the actual starting point.

For example:
https://golang.org/cl/136160043/diff2/20001:60001/src/pkg/runtime/sigqueue.go

LGTM=dvyukov, iant
R=golang-codereviews, dvyukov, iant
CC=golang-codereviews, khr, r
https://golang.org/cl/136160043

10 years agogo/parser: initialize file set even in only some tests are run
Robert Griesemer [Thu, 4 Sep 2014 17:43:03 +0000 (10:43 -0700)]
go/parser: initialize file set even in only some tests are run

Without this fix, some tests crashed (e.g. go test -run Invalid).

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/133580043