gcc/libgo
Ian Lance Taylor 9c48398f49 runtime: Fix GC bug caused by Entersyscall modifying reg.
This patch fixes a rare but serious bug.  The Go garbage
collector only examines Go stacks.  When Go code calls a
function that is not written in Go, it first calls
syscall.Entersyscall.  Entersyscall records the position of
the Go stack pointer and saves a copy of all the registers.
If the garbage collector runs while the thread is executing
the non-Go code, the garbage collector fetches the stack
pointer and registers from the saved location.

Entersyscall saves the registers using the getcontext
function.  Unfortunately I didn't consider the possibility
that Entersyscall might itself change a register before
calling getcontext.  This only matters for callee-saved
registers, as caller-saved registers would be visible on the
saved stack.  And it only matters if Entersyscall is compiled
to save and modify a callee-saved register before it calls
getcontext.  And it only matters if a garbage collection
occurs while the non-Go code is executing.  And it only
matters if the only copy of a valid Go pointer happens to be
in the callee-saved register when Entersyscall is called.
When all those conditions are true, the Go pointer might get
collected incorrectly, leading to memory corruption.

This patch tries to avoid the problem by splitting
Entersyscall into two functions.  The first is a simple
function that just calls getcontext and then calls the rest of
Entersyscall.  This should fix the problem, provided the
simple Entersyscall function does not itself modify any
callee-saved registers before calling getcontext.  That seems
to be true on the systems I checked.  But since the argument
to getcontext is an offset from a TLS variable, it won't be
true on a system which needs to save callee-saved registers in
order to get the address of a TLS variable.  I don't know why
any system would work that way, but I don't know how to rule
it out.  I think that on any such system this will have to be
implemented in assembler.  I can't put the ucontext_t
structure on the stack, because this function can not split
stacks, and the ucontext_t structure is large enough that it
could cause a stack overflow.

From-SVN: r208390
2014-03-07 05:04:37 +00:00
..
config ltmain.sh: Patch for Solaris. 2014-02-03 17:39:44 +00:00
go libgo: Update to Go 1.2.1 release. 2014-03-03 20:14:52 +00:00
runtime runtime: Fix GC bug caused by Entersyscall modifying reg. 2014-03-07 05:04:37 +00:00
testsuite gotest: Recognize PPC ELF v2 function pointers in text section. 2013-11-19 02:14:40 +00:00
aclocal.m4
config.h.in syscall: Only call varargs libc functions from C code. 2013-11-24 02:38:28 +00:00
configure libgo/configure: Test for gold with gccgo -Wl,--help, not ld --help. 2014-01-22 19:10:47 +00:00
configure.ac libgo/configure: Test for gold with gccgo -Wl,--help, not ld --help. 2014-01-22 19:10:47 +00:00
godeps.sh
LICENSE
Makefile.am re PR go/59430 (os/user FAILs on Solaris) 2014-01-08 01:08:29 +00:00
Makefile.in re PR go/59430 (os/user FAILs on Solaris) 2014-01-08 01:08:29 +00:00
MERGE libgo: Update to Go 1.2.1 release. 2014-03-03 20:14:52 +00:00
merge.sh
mksysinfo.sh mksysinfo, net: Always define F_DUPFD_CLOEXEC. 2013-11-11 21:21:50 +00:00
PATENTS
README
README.gcc

See ../README.

This is the runtime support library for the Go programming language.
This library is intended for use with the Go frontend.

The library has only been tested on GNU/Linux using glibc.  It should
not be difficult to port to other operating systems.

The library has only been tested on x86/x86_64 systems.  It should not
be difficult to port to other architectures.

Directories:

go
  A copy of the Go library from http://golang.org/, with a few
  changes for gccgo.  Notably, the reflection interface is different.

runtime
  Runtime functions, written in C, which are called directly by the
  compiler or by the library.

syscalls
  System call support.

Contributing
============

To contribute patches to the files in this directory, please see
http://golang.org/doc/gccgo_contribute.html .

The master copy of these files is hosted at
http://code.google.com/p/gofrontend .  Changes to these files require
signing a Google contributor license agreement.  If you are the
copyright holder, you will need to agree to the individual contributor
license agreement at
http://code.google.com/legal/individual-cla-v1.0.html.  This agreement
can be completed online.

If your organization is the copyright holder, the organization will
need to agree to the corporate contributor license agreement at
http://code.google.com/legal/corporate-cla-v1.0.html.

If the copyright holder for your code has already completed the
agreement in connection with another Google open source project, it
does not need to be completed again.