Using -funwind-tables is necessary to permit Go code to correctly
throw a panic through C code. This hasn't been necessary in the past
as -funwind-tables is the default on x86. However, it is not the
default for PPC AIX.
Reviewed-on: https://go-review.googlesource.com/56650
From-SVN: r251179
Libgo's implementation of math.Ldexp declared the libc "ldexp" as
taking an 'int' exponent argument, which is not quite right for 64-bit
platforms (exp arg is always int32); this could yield incorrect
results for exponent values outside the range of Minint32/Maxint32.
Fix by upating the type for the libc version of ldexp, and adding
guards to screen for out-of-range exponents.
Fixes#21323.
Reviewed-on: https://go-review.googlesource.com/54250
From-SVN: r250992
We unconditionally set _FILE_OFFSET_BITS to 64 in configure.ac, so we
should unconditionally call the statfs64 and fstatfs64 functions.
These functions should be available on all versions of GNU/Linux since 2.6.
On 64-bit systems they are aliased to statfs/fstatfs, and on 32-bit
systems they use the 64-bit data structures.
Fixesgolang/go#20922
Reviewed-on: https://go-review.googlesource.com/50635
From-SVN: r250443
If getSiginfo does not know how to determine the PC, it will call
runtime_callers. That can happen in a thread that was started by
non-Go code, in which case the TLS variable g will not be set, in
which case runtime_lock will crash.
Avoid the problem by using atomic operations for the lock. This is OK
since creating a backtrace state is fast and never blocks.
The test case is TestCgoExternalThreadSIGPROF in the runtime package
on a system that getSiginfo doesn't handle specially.
Updates golang/go#20931
Reviewed-on: https://go-review.googlesource.com/50650
From-SVN: r250439
Allocate enough stack space so that the test will work on a system
that does not support split stacks.
This test is actually not very meaningful for gccgo at present, but it
doesn't hurt to keep running it.
Updates golang/go#20931
Reviewed-on: https://go-review.googlesource.com/50630
From-SVN: r250433
PR go/81451
runtime: inline runtime_osinit
We had two identical copies of runtime_osinit. They set runtime_ncpu,
a variable that is no longer used. Removing that leaves us with two lines.
Inline those two lines in the two places the function was called.
This fixes GCC PR 81451.
Reviewed-on: https://go-review.googlesource.com/48862
From-SVN: r250326
PR go/81324
sysinfo.c: ignore ptrace_peeksiginfo_args from <linux/ptrace.h>
With some versions of glibc and GNU/Linux ptrace_pseeksiginfo_args is
defined in both <sys/ptrace.h> and <linux/ptrace.h>. We don't actually
care about the struct, so use a #define to avoid a redefinition error.
This fixes https://gcc.gnu.org/PR81324.
Reviewed-on: https://go-review.googlesource.com/49290
From-SVN: r250324
PR go/81393
syscall: don't use GETREGS/SETREGS on s390
They were removed in recent glibc.
Patch by Andreas Krebbel for GCC PR 81393.
Reviewed-on: https://go-review.googlesource.com/48231
From-SVN: r250174
On AIX:
* mmap does not allow to map an already mapped range,
* mmap range start at 0x30000000 for 32 bits processes,
* mmap range start at 0x70000000_00000000 for 64 bits processes
This is adapted from change 37845.
Issue golang/go#19200
Reviewed-on: https://go-review.googlesource.com/46772
From-SVN: r249713
Fixes required now that we #include <linux/ptrace.h> in sysinfo.c.
Patch by Andreas Krebbel.
Reviewed-on: https://go-review.googlesource.com/46839
From-SVN: r249712
Copy all the misc/cgo files from the gc toolchain into libgo/misc.
These will be used for testing purposes by later changes to the
gotools directory.
Reviewed-on: https://go-review.googlesource.com/46721
From-SVN: r249674
When C code calls a Go function, it actually calls a function
generated by cgo. That function is written in Go, and, among other
things, it calls the real Go function like this:
CgocallBack()
defer CgocallBackDone()
RealGoFunction()
The deferred CgocallBackDone function enters syscall mode as we return
to C. Typically the C function will then eventually return to Go.
However, in the case where the C function is running on a thread
created in C, it will not return to Go. For that case we will have
allocated an m struct, with an associated g struct, for the duration
of the Go code, and when the Go is complete we will return the m and g
to a free list.
That all works, but we are running in a deferred function, which means
that we have been invoked by deferreturn, and deferreturn expects to
do a bit of cleanup to record that the defer has been completed. Doing
that cleanup while using an m and g that have already been returned to
the free list is clearly a bad idea. It was kind of working because
deferreturn was holding the g pointer in a local variable, but there
were races with some other thread picking up and using the newly freed g.
It was also kind of working because of a special check in freedefer;
that check is no longer necessary.
This patch changes the special case of releasing the m and g to do the
defer cleanup in CgocallBackDone itself.
This patch also checks for the special case of a panic through
CgocallBackDone. In that special case, we don't want to release the m
and g. Since we are returning to C code that was not called by Go
code, we know that the panic is not going to be caught and we are
going to exit the program. So for that special case we keep the m and
g structs so that the rest of the panic code can use them.
Reviewed-on: https://go-review.googlesource.com/46530
From-SVN: r249611
The kickoff function for g0 can be invoked without a p, for example
from mcall(exitsyscall0) in exitsyscall after exitsyscall has cleared
the p field. The assignment gp.param = nil will invoke a write barrier.
If gp.param is not already nil, this will require a p. Avoid the problem
for a specific case that is known to be OK: when the value in gp.param
is a *g.
Reviewed-on: https://go-review.googlesource.com/46512
From-SVN: r249595
When a panic occurs while processing a deferred function that
recovered an earlier panic, we shouldn't report the recovered panic
in the panic stack trace. Stop doing so by keeping track of the panic
that triggered a defer, marking it as aborted if we see the defer again,
and discarding aborted panics when a panic is recovered. This is what
the gc runtime does.
The test for this is TestRecursivePanic in runtime/crash_test.go.
We don't run that test yet, but we will soon.
Reviewed-on: https://go-review.googlesource.com/46461
From-SVN: r249590
The CgocallbackDone function calls dropm after it calls entersyscall,
which means that dropm must not have any write barriers. Mark it
accordingly.
Reviewed-on: https://go-review.googlesource.com/46464
From-SVN: r249577
Use go:linkname to export the getm function. This makes it visible to
runtime/testdata/testprogcgo/dropm_stub.go, which uses it as part of
the TestEnsureDropM test in runtime/crash_cgo_test.go. That test is
not run today, but it will be soon.
Reviewed-on: https://go-review.googlesource.com/46462
From-SVN: r249576
In libgo system goroutines register themselves after they start.
That means that there is a small race between the goroutine being
seen by the scheduler and the scheduler knowing that the goroutine
is a system goroutine. That in turn means that runtime.NumGoroutines
can overestimate the number of goroutines at times.
This patch fixes the overestimate by counting the number of system
goroutines waiting to start, and pausing NumGoroutines until those
goroutines have all registered.
This is kind of a lot of mechanism for this not very important
problem, but I couldn't think of a better approach.
The test for this is TestNumGoroutine in runtime/proc_test.go.
The test is not currently run, but it will be soon.
Reviewed-on: https://go-review.googlesource.com/46457
From-SVN: r249565
With the gc toolchain apparently
var s *string
_ = *s
is enough to panic with a nil pointer dereference. The gccgo compiler
will simply discard the dereference, which I think is a reasonable and
acceptable optimization. Change the tests to use an exported variable
instead. The tests are not currently run, but they will be with a
later patch to gotools.
Reviewed-on: https://go-review.googlesource.com/46450
From-SVN: r249562
Because of how gccgo implements cgo calls, the code in dropm may not
have any write barriers. As a step toward implementing that, change
the gcstack, gcnextsegment, and gcnextsp fields of the g struct to
uintptr, so that assignments to them do not require write barriers.
The gcinitialsp field remains unsafe.Pointer, as on 32-bit systems
that do not support split stack it points to a heap allocated space
used for the goroutine stack.
The test for this is runtime tests like TestCgoCallbackGC, which are
not run today but will be run with a future gotools patch.
Reviewed-on: https://go-review.googlesource.com/46396
From-SVN: r249561
Calling a deferred function currently requires changing from a uintptr
to the function code to a Go function value. That is done by setting
the value of a func local variable using unsafe.Pointer. The local
variable will always be on the stack. Adjust the code that sets the
local variable to avoid generating a write barrier.
A write barrier is never needed here. Also, for deferreturn, we must
avoid write barriers entirely when called from a cgo function; that
requires more than just this, but this is a start.
The test for this is runtime tests that use the go tool; these are not
currently run, but they will be in the future.
Reviewed-on: https://go-review.googlesource.com/46455
From-SVN: r249559
The gc version of the _defer struct has a _panic field that has a
completely different meaning. We are going to want that bring that new
meaning into the gofrontend to improve panic reports with nested
panic calls. Simplify that by first renaming the existing _panic field.
Reviewed-on: https://go-review.googlesource.com/46454
From-SVN: r249558
- don't run tests that depend on SetCgoTraceback
- don't expect a '(' after the function name in a traceback
- change the expected name of nested functions in a traceback
These tests are not currently run, but they will be soon.
Reviewed-on: https://go-review.googlesource.com/46453
From-SVN: r249557
The gofrontend doesn't support the runtime.SetCgoTraceback function,
which is specifically for handling mixed Go and C tracebacks.
Use a build tag to avoid compiling the runtime/testdata/testprogcgo
files that refer to SetCgoTraceback. These files are not currently
compiled anyhow, but they will be with a future gotools patch.
Reviewed-on: https://go-review.googlesource.com/46452
From-SVN: r249556
Building this test with gccgo requires an explicit -pthread option to
be passed to the C compiler, so that it links against -lpthread.
This test is not built today, but it will be soon with a future patch.
Reviewed-on: https://go-review.googlesource.com/46451
From-SVN: r249555
The gc toolchain does the same thing, in gentraceback in
runtime/traceback.go.
The test for this is TestPanicTraceback in runtime/crash_test.go. We
don't yet run that test, but we will in a future change.
Reviewed-on: https://go-review.googlesource.com/46397
From-SVN: r249495
The test for this is TestGoNil in the runtime package, which we don't
run yet but will run with a subsequent gotools patch.
Updates golang/go#8045
Reviewed-on: https://go-review.googlesource.com/46392
From-SVN: r249494
libgo: remove old MIPS architecture names
This removes the old names for the 3 main MIPS ABIs: mipso32, mipsn32
and mipsn64. It also removes the mipso64 ABI which has no equivalent
architecture name in go. This ABI has been dead for sometime and I doubt
anyone will miss it.
Change-Id: I087b243784edf6705fdaf9c32e3233da5e387283
From-SVN: r249485
This removes the old names for the 3 main MIPS ABIs: mipso32, mipsn32
and mipsn64. It also removes the mipso64 ABI which has no equivalent
architecture name in go. This ABI has been dead for sometime and I doubt
anyone will miss it.
Reviewed-on: https://go-review.googlesource.com/46154
From-SVN: r249477
This means that the gc tools and gofrontend agree on the architecture names
for the 3 MIPS ABIs which should allow a gofrontend compiler to build go.
Reviewed-on: https://go-review.googlesource.com/46153
From-SVN: r249476