Commit Graph

356 Commits

Author SHA1 Message Date
Ian Lance Taylor e0f69f36ea libgo: change build procedure to use build tags
Previously the libgo Makefile explicitly listed the set of files to
    compile for each package.  For packages that use build tags, this
    required a lot of awkward automake conditionals in the Makefile.
    
    This CL changes the build to look at the build tags in the files.
    The new shell script libgo/match.sh does the matching.  This required
    adjusting a lot of build tags, and removing some files that are never
    used.  I verified that the exact same sets of files are compiled on
    amd64 GNU/Linux.  I also tested the build on i386 Solaris.
    
    Writing match.sh revealed some bugs in the build tag handling that
    already exists, in a slightly different form, in the gotest shell
    script.  This CL fixes those problems as well.
    
    The old code used automake conditionals to handle systems that were
    missing strerror_r and wait4.  Rather than deal with those in Go, those
    functions are now implemented in runtime/go-nosys.c when necessary, so
    the Go code can simply assume that they exist.
    
    The os testsuite looked for dir_unix.go, which was never built for gccgo
    and has now been removed.  I changed the testsuite to look for dir.go
    instead.
    
    Reviewed-on: https://go-review.googlesource.com/25546

From-SVN: r239189
2016-08-06 00:36:33 +00:00
Ian Lance Taylor e91f59b919 runtime: fix incorrectly commented out code in heapdump.c
Reviewed-on: https://go-review.googlesource.com/25490

From-SVN: r239144
2016-08-04 17:21:23 +00:00
Ian Lance Taylor 22b955cca5 libgo: update to go1.7rc3
Reviewed-on: https://go-review.googlesource.com/25150

From-SVN: r238662
2016-07-22 18:15:38 +00:00
Ian Lance Taylor bb72703282 runtime: Use atomic load for in entersyscall.
Reportedly fixes PPC64 deadlock.
    
    From a comment by Gabriel Russell.
    
    Fixes golang/go#15051.
    
    Reviewed-on: https://go-review.googlesource.com/21450

From-SVN: r234694
2016-04-02 00:47:53 +00:00
Ian Lance Taylor 4501d9ad44 runtime: lock M during cgo call
cgo should lock the M.
    
    
    See also https://golang.org/cl/18882 .
    
    Reviewed-on: https://go-review.googlesource.com/18883

From-SVN: r233670
2016-02-24 15:03:04 +00:00
Ian Lance Taylor 43414a5dd3 libgo: Update to final Go 1.6 release.
Reviewed-on: https://go-review.googlesource.com/19592

From-SVN: r233515
2016-02-18 05:56:46 +00:00
Ian Lance Taylor 54c9c975f1 runtime: For c-archive/c-shared, install signal handlers synchronously.
This is a port of https://golang.org/cl/18150 to the gccgo runtime.
    
    The previous behaviour of installing the signal handlers in a separate
    thread meant that Go initialization raced with non-Go initialization if
    the non-Go initialization also wanted to install signal handlers.  Make
    installing signal handlers synchronous so that the process-wide behavior
    is predictable.
    
    Reviewed-on: https://go-review.googlesource.com/19494

From-SVN: r233393
2016-02-12 22:10:09 +00:00
Ian Lance Taylor de24ed7803 re PR go/69511 (G.gcstack_size uses uintptr instead of size_t)
PR go/69511
    runtime: change G gcstack_size field to size_t
    
    Because its address is passed to __splitstack_find, which expects size_t*.
    
    From Dominik Vogt in GCC PR 69511.
    
    Reviewed-on: https://go-review.googlesource.com/19429

From-SVN: r233260
2016-02-10 02:16:04 +00:00
Ian Lance Taylor cc240aa7d1 re PR go/69357 (libgo refers to _end in a non-weak way)
PR go/69537
    runtime: Don't refer to _end symbol in shared library.
    
    Fixes GCC PR 69357.
    
    Reviewed-on: https://go-review.googlesource.com/19362

From-SVN: r233235
2016-02-09 00:34:55 +00:00
Ian Lance Taylor f98dd1a338 libgo: Update to go1.6rc1.
Reviewed-on: https://go-review.googlesource.com/19200

From-SVN: r233110
2016-02-03 21:58:02 +00:00
Ian Lance Taylor 06caa02ccf compiler, runtime: mark stub methods, ignore them in runtime.Caller.
This fixes the long-standing bug in which the testing package misreports
    the file/line of an error.
    
    Reviewed-on: https://go-review.googlesource.com/19179

From-SVN: r233098
2016-02-03 06:54:41 +00:00
Ian Lance Taylor ae026741df re PR go/61303 (gccgo: segfault, regression since 4.8.2)
PR go/61303
    runtime: don't overallocate in select code
    
    If we've already allocated an fd_set, don't allocate another one.
    
    Also, don't bother to read from rdwake if it wasn't returned in select.
    
    Fixes https://gcc.gnu.org/PR61303.
    
    Reviewed-on: https://go-review.googlesource.com/17243

From-SVN: r230922
2015-11-26 00:24:21 +00:00
Ian Lance Taylor 8c61286797 re PR go/68496 ([libgo] reflect test fails on Linux x86-64)
PR go/68496
    reflect: Allocate space for FFI functions returning a zero-sized type.
    
    The libffi library does not understand zero-sized types.  We represent
    them as a struct with a single field of type void.  If such a type is
    returned from a function, libffi will copy 1 byte of data.  Allocate
    space for that byte, although we won't use it.
    
    Fixes https://gcc.gnu.org/PR68496.

    Reviewed-on: https://go-review.googlesource.com/17175

From-SVN: r230776
2015-11-23 21:17:45 +00:00
Ian Lance Taylor bbbe8b338b re PR go/66574 (Time is provided in millisecond precision instead of nanoseconds as described in go documentation)
PR go/66574
    runtime: Use clock_gettime to get current time.
    
    Fetch the current time in nanoseconds, not microseconds, by using
    clock_gettime rather than gettimeofday.
    
    Update golang/go#11222.
    
    Fixes https://gcc.gnu.org/PR66574.
    
    Reviewed-on: https://go-review.googlesource.com/17156

From-SVN: r230694
2015-11-21 01:27:44 +00:00
Ian Lance Taylor 9da92cbda9 libgo: Solaris portability fixes.
Only build net/hook_cloexec.go on GNU/Linux and FreeBSD, because those
    are the only systems with accept4.
    
    Add syscall/libcall_bsd.go to define sendfile for *BSD and Solaris.
    
    Revert tcpsockopt_solaris.go back to the earlier version, so that it
    works on Solaris 10.
    
    Always pass the address of a Pid_t value to TIOCGPGRP and TIOCSPGRP.
    
    Include <unistd.h> in runtime/go-varargs.c.
    
    Reviewed-on: https://go-review.googlesource.com/16719

From-SVN: r229880
2015-11-06 19:15:45 +00:00
Ian Lance Taylor 2b193803d7 runtime: If no split stacks, allocate stacks using mmap on 64-bit systems.
When not using split stacks, libgo allocate large stacks for each
    goroutine.  On a 64-bit system, libgo allocates a maximum of 128G for
    the Go heap, and allocates 4M for each stack.  When the stacks are
    allocated from the Go heap, the result is that a program can only create
    32K goroutines, which is not enough for an active Go server.  This patch
    changes libgo to allocate the stacks using mmap directly, rather than
    allocating them out of the Go heap.  This change is only done for 64-bit
    systems when not using split stacks.  When using split stacks, the
    stacks are allocated using mmap directly anyhow.  On a 32-bit system,
    there is no maximum size for the Go heap, or, rather, the maximum size
    is the available address space anyhow.
    
    Reviewed-on: https://go-review.googlesource.com/16531

From-SVN: r229636
2015-10-31 23:48:19 +00:00
Ian Lance Taylor af146490bb runtime: Remove now unnecessary pad field from ParFor.
It is not needed due to the removal of the ctx field.
    
    Reviewed-on: https://go-review.googlesource.com/16525

From-SVN: r229616
2015-10-31 00:59:47 +00:00
Ian Lance Taylor f4a513a98e compiler, reflect, runtime: remove zero field from type descriptor
Type descriptors picked up a zero field because the gc map
    implementation used it.  However, it's since been dropped by the gc
    library.  It was never used by gccgo.  Drop it now in preparation for
    upgrading to the Go 1.5 library.
    
    Reviewed-on: https://go-review.googlesource.com/16486

From-SVN: r229546
2015-10-29 18:14:50 +00:00
Ian Lance Taylor 730f6d1425 compiler, runtime: change type hash/equal to Go funcs
Change the type descriptor hash and equal functions from C code pointers
    to Go func values.  This permits them to be set to a Go function
    closure.  This is in preparation for the Go 1.5, so that we can use a
    closure for the hash/equal functions returned by the new reflect.ArrayOf
    function.
    
    Reviewed-on: https://go-review.googlesource.com/16485

From-SVN: r229541
2015-10-29 17:14:51 +00:00
Ian Lance Taylor 0786e1fe86 re PR go/67874 (fd_unix.go does not build when there is fcntl64 and no fcntl syscall)
PR go/67874
    net, runtime: Call C library fcntl function rather than syscall.Syscall.
    
    Not all systems define a fcntl syscall; some only have fcntl64.
    
    Fixes GCC PR go/67874.
    
    Reviewed-on: https://go-review.googlesource.com/15497

From-SVN: r228576
2015-10-07 17:22:08 +00:00
Ian Lance Taylor 055db850c6 runtime: Fix recent lfstack change on Solaris.
Reviewed-on: https://go-review.googlesource.com/14922

From-SVN: r228087
2015-09-24 13:33:20 +00:00
Ian Lance Taylor 46efdbbc01 runtime: rewrite lfstack packing/unpacking to look more like that in Go
Reviewed-on: https://go-review.googlesource.com/13037

From-SVN: r228057
2015-09-23 17:07:15 +00:00
Ian Lance Taylor 7e56d66864 runtime: Ignore stack sizes when deciding when to GC.
This restores https://golang.org/cl/6081043 which was lost accidentally
    when updating a new version of libgo in https://golang.org/cl/22440043 .
    
    Reviewed-on: https://go-review.googlesource.com/14569

From-SVN: r227784
2015-09-15 12:32:31 +00:00
Ian Lance Taylor 5dbd3b8045 libgo/runtime: return 0, not NULL, from main
Reviewed-on: https://go-review.googlesource.com/13421

From-SVN: r227673
2015-09-11 03:12:28 +00:00
Ian Lance Taylor f48495834f runtime: initialize variable to avoid compiler warning
Reviewed-on: https://go-review.googlesource.com/13095

From-SVN: r226543
2015-08-04 03:39:21 +00:00
Ian Lance Taylor 3d6d2a63b2 re PR go/67101 (mprof.goc:408:5: error: calling ‘__builtin_frame_address’ with a nonzero argument is unsafe [-Werror=frame-address])
PR go/67101

    runtime: Remove call to __builtin_frame_address.
    
    __builtin_frame_address was only supposed to use nonzero arguments
    for debugging purposes.  Calling it with nonzero arguments can have
    unpredictable results and uses are now marked unsafe when
    -Wframe-address is enabled.
    
    Reviewed-on: https://go-review.googlesource.com/13063

From-SVN: r226525
2015-08-03 17:54:50 +00:00
Ian Lance Taylor 67a546ab45 compiler,runtime: Determine if allocations need new pointers in runtime.
As the removed comment states, if the package being compiled played
    certain tricks with pointers that looked like integers, the compiler
    might allocate space for new pointers unnecessarily.  Since the type
    information on the heap is now precise, this logic can be moved to the
    runtime.
    
    Reviewed-on: https://go-review.googlesource.com/11581

From-SVN: r225757
2015-07-14 01:22:25 +00:00
Ian Lance Taylor 5ea73ae3b8 libgo: Use __USING_SJLJ_EXCEPTIONS__ rather than configure test.
From Eric Botcazou.

From-SVN: r223231
2015-05-16 00:17:46 +00:00
Ian Lance Taylor b1b0e90567 runtime: Fix runtime/pprof test when libgo is not optimized.
When libgo is not optimized the static function profilealloc
in malloc.goc shows up in the stack trace.  Rename it to
runtime_profilealloc so that runtime/pprof.printStackRecord
ignores it.

From-SVN: r223006
2015-05-11 16:19:23 +00:00
Ian Lance Taylor bd9e8f7e4a re PR go/66016 (Accessing nil Func's name results in crash)
PR go/66016
runtime: Don't crash in Func.Name if the Func is nil.

Related to Go issue 10696

From-SVN: r222816
2015-05-05 16:38:57 +00:00
Ian Lance Taylor 081564faed runtime: Support -buildmode=c-shared.
These changes permit using the go tool from the upcoming Go
1.5 release with -buildmode=c-archive to build gccgo code into
an archive file that can be linked with a C program.

From-SVN: r222594
2015-04-29 21:31:53 +00:00
Ian Lance Taylor 46f120ca7b re PR go/65798 (runtime.Caller returns ok=true when return data is invalid)
PR go/65798
runtime: In Caller don't return ok == true if PC == 0.

GCC PR 65798 reports that this can happen in some cases.

From-SVN: r222204
2015-04-17 21:59:10 +00:00
Ian Lance Taylor 5fdb119fd5 re PR go/64999 (s390x libgo test failure in TestMemoryProfiler)
PR go/64999
	PR go/65180
runtime: Adjust libbacktrace PC value to what runtime.Callers expects.

From Lynn Boger.

From-SVN: r222196
2015-04-17 19:29:28 +00:00
Ian Lance Taylor 90e00f872d re PR go/65755 (incorrect reflection of struct fields with gccgo)
PR go/65755
compiler, runtime, reflect: Use reflection string for type comparisons.

Change the runtime and reflect libraries to always use only
the type reflection string to determine whether two types are
equal.  It previously used the PkgPath and Name values for a
type name, but that required a PkgPath that did not match the
gc compiler.

Change the compiler to use the same PkgPath value as the gc
compiler in all cases.

Change the compiler to put the receiver type in the reflection
string for a type defined inside a method.

From-SVN: r222194
2015-04-17 18:19:44 +00:00
Ian Lance Taylor 2ee920291d Remove some files that were accidentally committed in 2014.
From-SVN: r221802
2015-03-31 19:47:23 +00:00
Ian Lance Taylor dc4d494ae9 re PR go/65349 (go tool crashes, can't compile go code on 32bit linux systems)
PR go/65349
runtime: Don't crash if explicitly freeing small map.

From-SVN: r221292
2015-03-09 23:43:16 +00:00
Ian Lance Taylor 4729d7726b re PR go/65349 (go tool crashes, can't compile go code on 32bit linux systems)
PR go/65349
runtime: Don't call malloc from __go_file_line callback.

When crashing, we call runtime_printcreatedby which calls
__go_file_line which used to call the Go malloc.  If we are
crashing due to a signal due to heap corruption of some sort,
the GO malloc lock might already be held, leading to a crash
within a crash.  Avoid that by assuming that the libbacktrace
strings will stick around, as we already do in go-callers.c.

From-SVN: r221291
2015-03-09 23:40:58 +00:00
Ian Lance Taylor 8c5c44aa7e runtime: Add memprofilerate to GODEBUG
Add memprofilerate as a value recognized
in the GODEBUG env var.  The value provided
is used as the new setting for
runtime.MemProfileRate, allowing the user
to adjust memory profiling.

From-SVN: r220470
2015-02-06 05:03:22 +00:00
Ian Lance Taylor e0a0c2f4c6 re PR go/64595 (go programs abort when debug info is stripped)
PR go/64595
runtime: Don't crash in runtime_callers if no debug info available.

From-SVN: r220057
2015-01-23 19:49:53 +00:00
Ian Lance Taylor cea526b81c runtime: No special case for 386 complex in FFI support.
All supported libgo 386 targets now have complex support in
libffi.

From Uros Bizjak.

From-SVN: r219877
2015-01-20 04:18:12 +00:00
Ian Lance Taylor 0f59f5c120 runtime: Add __sparc__ case for SETCONTEXT_CLOBBERS_TLS.
The glibc setcontext incorrectly modifies %g7 on SPARC.

From Richard Henderson.

From-SVN: r219778
2015-01-16 23:23:31 +00:00
Richard Henderson 38bf819a5f compiler, reflect, runtime: Use static chain for closures.
Change from using __go_set_closure to passing the closure
value in the static chain field.  Uses new backend support for
setting the closure chain in a call from C via
__builtin_call_with_static_chain.  Uses new support in libffi
for Go closures.

The old architecture specific support for reflect.MakeFunc is
removed, replaced by the libffi support.

All work done by Richard Henderson.

	* go-gcc.cc (Gcc_backend::call_expression): Add chain_expr argument.
	(Gcc_backend::static_chain_variable): New method.

From-SVN: r219776
2015-01-16 22:58:53 +00:00
Ian Lance Taylor cb054b6341 runtime: Use a struct, not void, for an empty struct for libffi.
A recent libffi upgrade caused the reflect test to fail on
386.  The problem case is a function that returns an empty
struct--a struct with no fields.  The libffi library does not
recognize the existence of empty structs, presumably since
they can't happen in C.  To work around this, the Go interface
to the libffi library changes an empty struct to void.  This
normally works fine, but with the new libffi upgrade it fails
for a function that returns an empty struct.  On 386 a
function that returns a struct is expected to pop the hidden
pointer when it returns.  So when we convert an empty struct
to void, libffi is calling a function that pops the hidden
pointer but does not expect that to happen.

In the older version of libffi, this didn't matter, because
the libffi code for 386 used a frame pointer, so the fact that
the stack pointer was wonky when the function returned was
ignored as the stack pointer was immediately replaced by the
saved frame pointer.  In the newer version of libffi, the 386
code is more efficient and does not use a frame pointer, and
therefore it matters whether libffi expects the function to
pop the hidden pointer or not.

This patch changes libgo to convert an empty to a struct with
a single field of type void.  This seems to be enough to get
the test cases working again.

Of course the real fix would be to change libffi to handle
empty types, but as libffi uses size == 0 as a marker for an
uninitialized type, that would be a non-trivial change.

From-SVN: r219701
2015-01-16 02:54:13 +00:00
Ian Lance Taylor f8d9fa9e80 libgo, compiler: Upgrade libgo to Go 1.4, except for runtime.
This upgrades all of libgo other than the runtime package to
the Go 1.4 release.  In Go 1.4 much of the runtime was
rewritten into Go.  Merging that code will take more time and
will not change the API, so I'm putting it off for now.

There are a few runtime changes anyhow, to accomodate other
packages that rely on minor modifications to the runtime
support.

The compiler changes slightly to add a one-bit flag to each
type descriptor kind that is stored directly in an interface,
which for gccgo is currently only pointer types.  Another
one-bit flag (gcprog) is reserved because it is used by the gc
compiler, but gccgo does not currently use it.

There is another error check in the compiler since I ran
across it during testing.

gotools/:
	* Makefile.am (go_cmd_go_files): Sort entries.  Add generate.go.
	* Makefile.in: Rebuild.

From-SVN: r219627
2015-01-15 00:27:56 +00:00
Ian Lance Taylor 24fa8749bb re PR go/61871 (FAIL: regexp from libgo testsuite on non-split stack targets)
PR go/61871
runtime: Increase stack size on 64-bit non-split-stack systems.

From Uros Bizjak.

From-SVN: r219192
2015-01-05 16:13:06 +00:00
Ian Lance Taylor bca4b95c4a runtime: Remove undefined references to runtime_race*.
From-SVN: r219049
2014-12-23 20:33:53 +00:00
Ian Lance Taylor 9ac18f8c2a re PR go/61258 (gccgo: assertion failure go-map-delete.c:37 [GoSmith])
PR go/61258
runtime: Don't crash when deleting zero-sized key.

From-SVN: r218702
2014-12-13 01:58:46 +00:00
Ian Lance Taylor c31fc2f424 runtime: Clear stack pointers for extra G's.
Fix an unusual C to Go callback case.  Newly created C threads
call into Go code, forcing the Go code to allocate new M and G
structures.  While executing Go code, the stack is split.  The
Go code then returns.  Returning from a Go callback is treated
as entering a system call, so the G gcstack field is set to
point to the Go stack.  In this case, though, we were called
from a newly created C thread, so we drop the extra M and G
structures.  The C thread then exits.

Then a new C thread calls into Go code, reusing the previously
created M and G.  The Go code requires a larger stack frame,
causing the old stack segment to be unmapped and a new stack
segment allocated.  At this point the gcstack field is
pointing to the old stack segment.

Then a garbage collection occurs.  The garbage collector sees
that the gcstack field is not nil, so it scans it as the first
stack segment.  Unfortunately it points to memory that was
unmapped.  So the program crashes.

The fix is simple: when handling extra G structures created
for callbacks from new C threads, clear the gcstack field.

From-SVN: r218699
2014-12-13 00:52:20 +00:00
Dominik Vogt 4ad4ebfeae runtime: Use stckf unconditionally on s390.
2014-11-05  Dominik Vogt  <vogt@linux.vnet.ibm.com>

* libgo/runtime/runtime.c (runtime_cputicks): s390: use stckf
unconditionally

From-SVN: r217195
2014-11-06 17:00:13 +00:00
Ian Lance Taylor 1fec5f5274 libgo: add s390 support
From Dominik Vogt.

* libgo/go/syscall/libcall_linux_s390.go: New file for s390 support.
* libgo/go/syscall/syscall_linux_s390.go: Ditto.
* libgo/go/syscall/libcall_linux_s390x.go: New file for s390x support.
* libgo/go/syscall/syscall_linux_s390x.go: Ditto.
* libgo/go/runtime/pprof/pprof.go (printStackRecord): Support s390 and
s390x.
* libgo/runtime/runtime.c (runtime_cputicks): Add support for s390 and
s390x
* libgo/mksysinfo.sh: Ditto.
(upcase_fields): New helper function

* libgo/go/debug/elf/file.go (applyRelocations): Implement relocations
on s390x.
(applyRelocationsS390x): Ditto.
(DWARF): Ditto.
* libgo/go/debug/elf/elf.go (R_390): New constants for S390 relocations.
(r390Strings): Ditto.
(String): Helper function for S390 relocations.
(GoString): Ditto.

* libgo/go/reflect/makefuncgo_s390.go: New file.
(S390MakeFuncStubGo): Implementation of s390 abi.
* libgo/go/reflect/makefuncgo_s390x.go: New file.
(S390xMakeFuncStubGo): Implementation of s390x abi.
* libgo/go/reflect/makefunc_s390.c: New file.
(makeFuncStub): s390 and s390x specific implementation of function.
* libgo/go/reflect/makefunc.go
(MakeFunc): Add support for s390 and s390x.
(makeMethodValue): Ditto.
(makeValueMethod): Ditto.
* libgo/Makefile.am (go_reflect_makefunc_s_file): Ditto.
(go_reflect_makefunc_file): Ditto.
* libgo/go/reflect/makefunc_dummy.c: Ditto.
* libgo/runtime/runtime.h (__go_makefunc_can_recover): Export prototype
for use in makefunc_s390.c.
(__go_makefunc_returning): Ditto.

* libgo/go/syscall/exec_linux.go (forkAndExecInChild): Fix order of the
arguments of the clone system call for s390[x].

* libgo/configure.ac (is_s390): New variable.
(is_s390x): Ditto
(LIBGO_IS_S390): Ditto.
(LIBGO_IS_S390X): Ditto.
(GOARCH): Support s390 and s390x.
* libgo/go/go/build/build.go (cgoEnabled): Ditto.
* libgo/go/go/build/syslist.go (goarchList): Ditto.

From-SVN: r217106
2014-11-04 22:39:30 +00:00
Ian Lance Taylor 50a504654d libgo: Update to Go 1.3.3 release.
From-SVN: r216746
2014-10-27 16:57:33 +00:00
Ian Lance Taylor 0f2aeaa817 compiler, runtime: Add type information to single object allocation.
From-SVN: r216490
2014-10-20 19:12:44 +00:00
Ian Lance Taylor 6c4ee063a5 runtime: Don't create threads with a small stack.
We want to create goroutines with a small stack, at least on
systems where split stacks are supported.  We don't need to
create threads with a small stack.

From-SVN: r216353
2014-10-16 22:39:45 +00:00
Ian Lance Taylor 19d4baed57 re PR go/60406 (recover.go: test13reflect2 test failure)
PR go/60406
runtime: Check callers in can_recover if return address	doesn't match.

Also use __builtin_extract_return_address and tighten up the
checks in FFI code.

Fixes PR 60406.

From-SVN: r216003
2014-10-08 14:03:13 +00:00
Ian Lance Taylor 60d9e9fc19 runtime: Check for CPU_COUNT itself, don't check glibc version.
Fixes issue 38.

From-SVN: r215832
2014-10-03 05:04:59 +00:00
Ian Lance Taylor 76deefd0cd runtime: Mark runtime_goexit function as noinline.
If the compiler inlines this function into kickoff, it may reuse
the TLS block address to load g. However, this is not necessarily
correct, as the call to g->entry in kickoff may cause the TLS
address to change. If the wrong value is loaded for g->status in
runtime_goexit, it may cause a runtime panic.

By marking the function as noinline we prevent the compiler from
reusing the TLS address.

From-SVN: r215484
2014-09-22 21:14:43 +00:00
Ian Lance Taylor f0c1b5671a runtime: Restore copyright notice accidentally removed from mgc0.c.
From-SVN: r215423
2014-09-20 20:42:59 +00:00
Ian Lance Taylor a7188cc650 runtime: Use correct size for unsafe.Pointer GC instructions.
From-SVN: r214965
2014-09-05 14:43:24 +00:00
Chris Manghane f1d2ac4f84 compiler: Add precise type information on the heap.
* go-gcc.cc (Gcc_backend::implicit_variable): Remove init
	parameter.  Add is_hidden parameter.
	(Gcc_backend::implicit_variable_set_init): New method.
	(Gcc_backend::implicit_variable_reference): New method.

From-SVN: r214894
2014-09-03 22:56:09 +00:00
Ian Lance Taylor ab36d98dd2 runtime: Don't get confused if m changes during runtime_gc.
From-SVN: r214048
2014-08-15 22:16:55 +00:00
Ian Lance Taylor 798c183f7f compiler, runtime: Fix unexpected GC interfering with closure passing.
The Go frontend passes closures through to functions using the
functions __go_set_closure and __go_get_closure.  The
expectation is that there are no function calls between
set_closure and get_closure.  However, it turns out that there
can be function calls if some of the function arguments
require type conversion to an interface type.  Converting to
an interface type can allocate memory, and that can in turn
trigger a garbage collection, and that can in turn call pool
cleanup functions that may call __go_set_closure.  So the
called function can see the wrong closure value, which is bad.

This patch fixes the problem in two different ways.  First, we
move all type conversions in function arguments into temporary
variables so that they can not appear before the call to
__go_set_closure.  (This required shifting the flatten phase
after the simplify_thunk phase, since the latter expects to
work with unconverted argument types.)  Second, we fix the
memory allocation function to preserve the closure value
across any possible garbage collection.

A test case is the libgo database/sql check run with the
environment variable GOGC set to 1.

From-SVN: r213932
2014-08-13 22:31:44 +00:00
Ian Lance Taylor d79fe5971a runtime: Add casts to mincore call to compile on Solaris.
Based on patch from Rainer Orth.

From-SVN: r213599
2014-08-04 17:54:09 +00:00
Ian Lance Taylor dc14e88e07 re PR other/61895 (libbacktrace crashes with bus error with empty file argv[0])
PR other/61895

runtime: Ignore small argv[0] file for backtrace.

Reportedly in some cases Docker starts processes with argv[0]
pointing to an empty file.  That would cause libgo to pass
that empty file to libbacktrace, which would then fail to do
any backtraces.  Everything should work fine if libbacktrace
falls back to /proc/self/exe.

This patch to libgo works around the problem by ignoring
argv[0] if it is a small file, or if stat fails.  This is not
a perfect fix but it's an unusual problem.

From-SVN: r213513
2014-08-02 00:54:15 +00:00
Ian Lance Taylor 1c2afaca89 runtime: also disable split stacks for runtime_snprintf function under Clang
From-SVN: r212862
2014-07-20 09:24:16 +00:00
Ian Lance Taylor dffa732835 reflect, runtime: Use libffi closures to implement reflect.MakeFunc.
Keep using the existing 386 and amd64 code on those archs,
since it is more efficient.

From-SVN: r212853
2014-07-19 21:36:26 +00:00
Ian Lance Taylor 00d86ac99f libgo: Update to Go 1.3 release.
From-SVN: r212837
2014-07-19 08:53:52 +00:00
Ian Lance Taylor 2fa39ad859 runtime: Merge master revision 19185.
This revision renames several files in the runtime directory
from .c to .goc.

From-SVN: r212472
2014-07-12 00:01:09 +00:00
Ian Lance Taylor c14e64d4ca runtime: Rename iface.goc to go-iface.goc.
Rename in order to avoid confusion with the new
runtime/iface.goc file in the Go library master sources.

From-SVN: r212447
2014-07-11 00:39:03 +00:00
Ian Lance Taylor 2802d48b30 runtime: Drop reflectFlags tests.
The flags were used by the reflect package in the past, but
not for a couple of years now.

From-SVN: r212446
2014-07-11 00:26:25 +00:00
Ian Lance Taylor 9490fda67a re PR go/61620 (FAIL: go.test/test/fixedbugs/bug242.go execution, -O2 -g)
PR go/61620

runtime: Don't free tiny blocks in map deletion.

The memory allocator now has a special case for tiny blocks
(smaller than 16 bytes) and they can not be explicitly freed.

From-SVN: r212233
2014-07-02 14:23:45 +00:00
Ian Lance Taylor 2abacbaec7 re PR go/52583 (Several new go testsuite failues on Solaris)
PR go/52583
runtime: Stop backtrace at a few recognized functions.

On x86_64 Solaris the makecontext function does not properly
indicate that it is at the top of the stack.  Attempting to
unwind the stack past a call to makecontext tends to crash.
This patch changes libgo to look for certain functions that
are always found at the top of the stack, and to stop
unwinding when it reaches one of those functions.  There is
never anything interesting past these functions--that is,
there is never any code written by the user.

From-SVN: r211640
2014-06-13 13:56:14 +00:00
Ian Lance Taylor eec40eac83 re PR go/61498 (Many 64-bit Go tests SEGV in scanblock)
PR go/61498
runtime: Always set gcnext_sp to pointer-aligned address.

The gcnext_sp field is only used on systems that do not use
split stacks.  It marks the bottom of the stack for the
garbage collector.  This change makes sure that the stack
bottom is always aligned to a pointer value.

Previously the garbage collector would align all the addresses
that it scanned, but it now expects them to be aligned before
scanning.

From-SVN: r211639
2014-06-13 13:50:13 +00:00
Ian Lance Taylor 816002df70 runtime: Initialize variable to avoid compiler warning.
From-SVN: r211394
2014-06-10 00:36:38 +00:00
Ian Lance Taylor 6736ef96ea libgo: Merge to master revision 19184.
The next revision, 19185, renames several runtime files, and
will be handled in a separate change.

From-SVN: r211328
2014-06-06 22:37:27 +00:00
Ian Lance Taylor bae90c989c libgo: Merge from revision 18783:00cce3a34d7e of master library.
This revision was committed January 7, 2014.  The next
revision deleted runtime/mfinal.c.  That will be done in a
subsequent merge.

This merge changes type descriptors to add a zero field,
pointing to a zero value for that type.  This is implemented
as a common variable.

	* go-gcc.cc (Gcc_backend::implicit_variable): Add is_common and
	alignment parameters.  Permit init parameter to be NULL.

From-SVN: r211249
2014-06-04 23:15:33 +00:00
Ian Lance Taylor 7480a39b77 runtime: Use _mm_pause rather than __builtin_ia32_pause.
Based on a patch from Peter Collingbourne.

From-SVN: r211081
2014-05-30 13:53:58 +00:00
Ian Lance Taylor d76a1885bd runtime: disable split stacks for runtime_printf function under Clang
LLVM's code generator does not currently support split stacks for vararg
functions, so we disable split stacks for the only function that uses this
feature under Clang. This appears to be OK as long as:
- this function only calls non-inlined, internal-linkage (hence no dynamic
  loader) functions compiled with split stacks (i.e. go_vprintf), which can
  allocate more stack space as required;
- this function itself does not occupy more than BACKOFF bytes of stack space
  (see libgcc/config/i386/morestack.S).
These conditions are currently known to be satisfied by Clang on x86-32 and
x86-64. Note that signal handlers receive slightly less stack space than they
would normally do if they happen to be called while this function is being
run. If this turns out to be a problem we could consider increasing BACKOFF.

From-SVN: r211037
2014-05-29 00:03:30 +00:00
Ian Lance Taylor 93c521ea9c runtime: fix misc gcc-isms and undefined behavior
This includes the use of __complex and __builtin_ functions where
unprefixed entities would suffice, and the use of a union for
bit-casting between types.

From-SVN: r211036
2014-05-28 23:10:47 +00:00
Ian Lance Taylor 25e4b0497b libgo/runtime: fix unused-result warning
Result of runtime_write is ignored, causing
an unused-result result warning (error in my
case, with -Werror=unused-result).

From-SVN: r210987
2014-05-27 22:01:21 +00:00
Ian Lance Taylor 9490b8da72 re PR go/60931 (libgo has issues when page size is not 4k)
PR go/60931

runtime: Fix garbage collector issue with non 4kB system page size

The go garbage collector tracks memory in terms of 4kB pages.
Most of the code checks getpagesize() at runtime and does the
right thing.

On a 64kB ppc64 box I see SEGVs in long running processes
which has been diagnosed as a bug in scavengelist.
scavengelist does a madvise(MADV_DONTNEED) without rounding
the arguments to the system page size.  A strace of one of the
failures shows the problem:

madvise(0xc211030000, 4096, MADV_DONTNEED) = 0

The kernel rounds the length up to 64kB and we mark 60kB of
valid data as no longer needed.

Round start up to a system page and end down before calling
madvise.

From-SVN: r209777
2014-04-25 04:29:07 +00:00
Ian Lance Taylor 73cc28d4e7 libgo: Remove Solaris 8 & 9 support.
From Rainer Orth.

From-SVN: r209448
2014-04-16 20:33:57 +00:00
Chris Manghane 7035307e8f Sync to current external repository.
user:        Ian Lance Taylor <iant@golang.org>
date:        Thu Apr 10 09:25:24 2014 -0700
files:       go/expressions.cc
description:
compiler: add checks for constant overflow

Prevent extremely large constants from eating all of memory.


user:        Chris Manghane <cmang@golang.org>
date:        Mon Apr 07 16:57:09 2014 -0700
files:       go/gogo-tree.cc go/gogo.cc go/gogo.h go/statements.cc
description:
compiler: Use backend interface for variable initialization.


user:        Chris Manghane <cmang@golang.org>
date:        Thu Apr 03 19:56:05 2014 -0700
files:       go/backend.h go/gogo-tree.cc go/gogo.cc go/gogo.h
description:
compiler: Use backend interface to build function code.


changeset:   1269:6e30875d539e
user:        Chris Manghane <cmang@golang.org>
date:        Wed Apr 02 13:16:00 2014 -0700
files:       go/backend.h go/gogo-tree.cc go/gogo.cc go/gogo.h
description:
compiler: Use backend interface for building function defer wrappers.


user:        Chris Manghane <cmang@golang.org>
date:        Mon Mar 31 12:42:49 2014 -0700
files:       go/expressions.cc go/gogo-tree.cc go/gogo.cc go/gogo.h
description:
compiler: Use backend interface for memory allocation.


user:        Chris Manghane <cmang@golang.org>
date:        Thu Mar 27 14:22:49 2014 -0700
files:       go/backend.h go/expressions.cc go/expressions.h
description:
compiler: Use backend interface for fixed array construction.


user:        Chris Manghane <cmang@golang.org>
date:        Mon Mar 17 21:25:04 2014 -0700
files:       go/expressions.cc
description:
compiler: Check for loops in self-referential array types. Fixes issue 7525.


user:        Chris Manghane <cmang@golang.org>
date:        Mon Mar 17 14:31:59 2014 -0700
files:       go/gogo.cc go/parse.cc
description:
compiler: Don't declare blank labels. Fixes issue 7539.


user:        Chris Manghane <cmang@golang.org>
date:        Mon Mar 17 13:12:32 2014 -0700
files:       go/backend.h go/expressions.cc go/expressions.h go/runtime.def
description:
compiler: Use backend interface for call expressions.


user:        Chris Manghane <cmang@golang.org>
date:        Wed Mar 12 13:34:27 2014 -0700
files:       go/expressions.cc go/expressions.h go/gogo-tree.cc go/statements.cc
description:
compiler: Use backend interface map construction.


user:        Chris Manghane <cmang@golang.org>
date:        Tue Mar 11 12:53:06 2014 -0700
files:       go/backend.h go/expressions.cc go/gogo-tree.cc go/gogo.h
description:
compiler: Use backend interface for string expressions.


user:        Chris Manghane <cmang@golang.org>
date:        Sat Mar 08 15:56:59 2014 -0800
files:       go/backend.h go/expressions.cc go/expressions.h
description:
compiler: Use backend interface for array and string indexing.


user:        Chris Manghane <cmang@golang.org>
date:        Fri Mar 07 16:02:18 2014 -0800
files:       go/expressions.cc
description:
compiler: Use backend interface for constant expressions.


user:        Chris Manghane <cmang@golang.org>
date:        Thu Mar 06 16:00:18 2014 -0800
files:       go/expressions.cc
description:
compiler: Use backend interface for struct construction.


user:        Chris Manghane <cmang@golang.org>
date:        Wed Mar 05 13:09:37 2014 -0800
files:       go/expressions.cc
description:
compiler: Use backend interface for type conversions.


user:        Chris Manghane <cmang@golang.org>
date:        Tue Mar 04 07:03:47 2014 -0800
files:       go/expressions.cc go/expressions.h go/gogo-tree.cc go/gogo.h go/runtime.def libgo/runtime/chan.c
description:
compiler: Use backend interface for channel receive.


user:        Chris Manghane <cmang@golang.org>
date:        Mon Mar 03 15:18:57 2014 -0800
files:       go/backend.h go/expressions.cc go/runtime.def
description:
compiler: Use backend interface for builtin calls.


user:        Chris Manghane <cmang@golang.org>
date:        Mon Mar 03 07:44:35 2014 -0800
files:       go/expressions.cc go/expressions.h go/types.cc go/types.h
description:
compiler: Use backend interface for string info.


user:        Chris Manghane <cmang@golang.org>
date:        Fri Feb 28 10:45:55 2014 -0800
files:       go/expressions.cc go/expressions.h go/gogo-tree.cc go/statements.cc
description:
compiler: Use backend interface for map indexing.


user:        Chris Manghane <cmang@golang.org>
date:        Wed Feb 26 14:13:10 2014 -0800
files:       go/expressions.cc go/expressions.h
description:
compiler: Use backend interface for slice value expressions.


user:        Chris Manghane <cmang@golang.org>
date:        Wed Feb 26 13:12:19 2014 -0800
files:       go/backend.h go/expressions.cc go/expressions.h go/gogo-tree.cc go/runtime.def go/statements.cc
description:
compiler: Use backend interface for interface values.


user:        Chris Manghane <cmang@golang.org>
date:        Mon Feb 24 12:30:13 2014 -0800
files:       go/expressions.cc go/expressions.h go/parse.cc go/statements.cc
description:
compiler: Change Heap_composite_expression to Heap_expression.


user:        Chris Manghane <cmang@golang.org>
date:        Thu Feb 20 19:47:06 2014 -0800
files:       go/expressions.cc go/expressions.h go/gogo-tree.cc go/gogo.cc go/gogo.h go/types.cc go/types.h
description:
compiler: Use backend interface for interface method table expressions.


user:        Chris Manghane <cmang@golang.org>
date:        Mon Feb 03 14:36:20 2014 -0800
files:       go/expressions.cc go/expressions.h
description:
compiler: Add compound expressions to the frontend.


	* go-gcc.cc: Include "convert.h".
	(Gcc_backend::string_constant_expression): New function.
	(Gcc_backend::real_part_expression): Likewise.
	(Gcc_backend::imag_part_expression): Likewise.
	(Gcc_backend::complex_expression): Likewise.
	(Gcc_backend::constructor_expression): Likewise.
	(Gcc_backend::array_constructor_expression): Likewise.
	(Gcc_backend::pointer_offset_expression): Likewise.
	(Gcc_backend::array_index_expression): Likewise.
	(Gcc_backend::call_expression): Likewise.
	(Gcc_backend::exception_handler_statement): Likewise.
	(Gcc_backend::function_defer_statement): Likewise.
	(Gcc_backend::function_set_parameters): Likewise.
	(Gcc_backend::function_set_body): Likewise.
	(Gcc_backend::convert_expression): Handle various type
	conversions.

From-SVN: r209393
2014-04-14 22:43:47 +00:00
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
Ian Lance Taylor a10d35a8ba libgo: Update to Go 1.2.1 release.
From-SVN: r208286
2014-03-03 20:14:52 +00:00
Ian Lance Taylor 91d6f071fb runtime: Use a better heap location on arm64 systems.
Before this, the heap location used on a 64-bit system was not
available to user-space on arm64, so the "32-bit" strategy ended up
being used.  So use somewhere that is available, and for bonus points
is far away from where the kernel allocates address space by default.

From-SVN: r207977
2014-02-21 03:24:03 +00:00
Ian Lance Taylor 6fbfce7841 re PR go/59866 (gccgo gc work buffer is misaligned)
PR go/59866
runtime: Force work variable in mgc0 to be aligned on 8-byte boundary.

From-SVN: r206738
2014-01-17 22:43:03 +00:00
Ian Lance Taylor abd471378c runtime: fix 32-bit malloc for pointers >= 0x80000000
The spans array is allocated in runtime_mallocinit.  On a
32-bit system the number of entries in the spans array is
MaxArena32 / PageSize, which (2U << 30) / (1 << 12) == (1 << 19).
So we are allocating an array that can hold 19 bits for an
index that can hold 20 bits.  According to the comment in the
function, this is intentional: we only allocate enough spans
(and bitmaps) for a 2G arena, because allocating more would
probably be wasteful.

But since the span index is simply the upper 20 bits of the
memory address, this scheme only works if memory addresses are
limited to the low 2G of memory.  That would be OK if we were
careful to enforce it, but we're not.  What we are careful to
enforce, in functions like runtime_MHeap_SysAlloc, is that we
always return addresses between the heap's arena_start and
arena_start + MaxArena32.

We generally get away with it because we start allocating just
after the program end, so we only run into trouble with
programs that allocate a lot of memory, enough to get past
address 0x80000000.

This changes the code that computes a span index to subtract
arena_start on 32-bit systems just as we currently do on
64-bit systems.

From-SVN: r206501
2014-01-09 23:16:56 +00:00
Ian Lance Taylor 2da4a7611b re PR go/59433 (Many 64-bit Go tests SEGV on Solaris)
PR go/59433
net: Don't use stack space for fd_sets when using select.

From-SVN: r206411
2014-01-08 00:42:45 +00:00
Ian Lance Taylor 9596ecdf8c runtime: Remove unused runtime_cpuid variables.
From-SVN: r206353
2014-01-06 03:01:58 +00:00
Ian Lance Taylor 1635eab367 runtime: Fix defer of unlock thread at program startup.
Don't free stack allocated defer block.  Also ensure we have a
Go context in a few more places before freeing the block.

From-SVN: r205940
2013-12-12 20:13:58 +00:00
Ian Lance Taylor 547a416879 compiler, reflect, runtime: Implement method values in reflect.
From-SVN: r205913
2013-12-12 01:08:52 +00:00
Ian Lance Taylor b1d137cf58 reflect, runtime: Let reflect.MakeFunc functions call recover.
From-SVN: r205908
2013-12-11 23:43:16 +00:00
Ian Lance Taylor dccd3a9b62 re PR go/59408 (Many Go tests FAIL with notesleep not on g0)
PR go/59408
runtime: Don't require g != m->g0 in sema notesleep.

From-SVN: r205756
2013-12-06 18:26:27 +00:00
Ian Lance Taylor 50312b2ff0 runtime: Use pthread_sigmask instead of sigprocmask.
From-SVN: r205652
2013-12-04 01:35:53 +00:00
Ian Lance Taylor e8d8443d22 runtime: Fix prototype and one use of runtime_traceback.
From Richard Biener.

From-SVN: r205634
2013-12-03 14:51:07 +00:00
Ian Lance Taylor 2583109c81 libgo: Avoid some cases of getting callers recursively.
Avoids hanging inside older versions of glibc that do not
support recurive calls to dl_iterate_phdr.

From-SVN: r205561
2013-12-01 01:40:16 +00:00
Ian Lance Taylor 763d87526f runtime: Fix handling of surrogate pairs in string([]rune).
From-SVN: r205422
2013-11-26 23:27:29 +00:00
Ian Lance Taylor 6b05faddf0 syscall: Only call varargs libc functions from C code.
From-SVN: r205321
2013-11-24 02:38:28 +00:00
Ian Lance Taylor 92495ff691 runtime: Update for change to libbacktrace library.
From-SVN: r205031
2013-11-19 15:02:27 +00:00
Ian Lance Taylor 41674b9fe4 reflect: Handle calls to functions that take or return empty structs
Fixes issue 6761

This simple change seems to work fine, slightly to my surprise.

This includes the tests I submitted to the main Go repository at
https://codereview.appspot.com/26570046

From-SVN: r205001
2013-11-19 02:30:03 +00:00