2011-05-02 11:55:51 -06:00
|
|
|
// Copyright 2011 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
runtime: scheduler, cgo reorganization
* Change use of m->g0 stack (aka scheduler stack).
* Provide runtime.mcall(f) to invoke f() on m->g0 stack.
* Replace scheduler loop entry with runtime.mcall(schedule).
Runtime.mcall eliminates the need for fake scheduler states that
exist just to run a bit of code on the m->g0 stack
(Grecovery, Gstackalloc).
The elimination of the scheduler as a loop that stops and
starts using gosave and gogo fixes a bad interaction with the
way cgo uses the m->g0 stack. Cgo runs external (gcc-compiled)
C functions on that stack, and then when calling back into Go,
it sets m->g0->sched.sp below the added call frames, so that
other uses of m->g0's stack will not interfere with those frames.
Unfortunately, gogo (longjmp) back to the scheduler loop at
this point would end up running scheduler with the lower
sp, which no longer points at a valid stack frame for
a call to scheduler. If scheduler then wrote any function call
arguments or local variables to where it expected the stack
frame to be, it would overwrite other data on the stack.
I realized this possibility while debugging a problem with
calling complex Go code in a Go -> C -> Go cgo callback.
This wasn't the bug I was looking for, it turns out, but I believe
it is a real bug nonetheless. Switching to runtime.mcall, which
only adds new frames to the stack and never jumps into
functions running in existing ones, fixes this bug.
* Move cgo-related code out of proc.c into cgocall.c.
* Add very large comment describing cgo call sequences.
* Simpilify, regularize cgo function implementations and names.
* Add test suite as misc/cgo/test.
Now the Go -> C path calls cgocall, which calls asmcgocall,
and the C -> Go path calls cgocallback, which calls cgocallbackg.
The shuffling, which affects mainly the callback case, moves
most of the callback implementation to cgocallback running
on the m->curg stack (not the m->g0 scheduler stack) and
only while accounted for with $GOMAXPROCS (between calls
to exitsyscall and entersyscall).
The previous callback code did not block in startcgocallback's
approximation to exitsyscall, so if, say, the garbage collector
were running, it would still barge in and start doing things
like call malloc. Similarly endcgocallback's approximation of
entersyscall did not call matchmg to kick off new OS threads
when necessary, which caused the bug in issue 1560.
Fixes #1560.
R=iant
CC=golang-dev
https://golang.org/cl/4253054
2011-03-07 08:37:42 -07:00
|
|
|
package cgotest
|
|
|
|
|
2011-05-02 11:55:51 -06:00
|
|
|
import "testing"
|
|
|
|
|
2012-10-30 14:38:01 -06:00
|
|
|
// The actual test functions are in non-_test.go files
|
2011-05-02 11:55:51 -06:00
|
|
|
// so that they can use cgo (import "C").
|
|
|
|
// These wrappers are here for gotest to find.
|
|
|
|
|
|
|
|
func TestAlign(t *testing.T) { testAlign(t) }
|
|
|
|
func TestConst(t *testing.T) { testConst(t) }
|
|
|
|
func TestEnum(t *testing.T) { testEnum(t) }
|
|
|
|
func TestAtol(t *testing.T) { testAtol(t) }
|
|
|
|
func TestErrno(t *testing.T) { testErrno(t) }
|
|
|
|
func TestMultipleAssign(t *testing.T) { testMultipleAssign(t) }
|
2012-09-19 21:20:33 -06:00
|
|
|
func TestUnsignedInt(t *testing.T) { testUnsignedInt(t) }
|
2011-05-02 11:55:51 -06:00
|
|
|
func TestCallback(t *testing.T) { testCallback(t) }
|
|
|
|
func TestCallbackGC(t *testing.T) { testCallbackGC(t) }
|
|
|
|
func TestCallbackPanic(t *testing.T) { testCallbackPanic(t) }
|
|
|
|
func TestCallbackPanicLoop(t *testing.T) { testCallbackPanicLoop(t) }
|
|
|
|
func TestCallbackPanicLocked(t *testing.T) { testCallbackPanicLocked(t) }
|
2013-10-09 09:44:47 -06:00
|
|
|
func TestPanicFromC(t *testing.T) { testPanicFromC(t) }
|
2011-05-02 11:55:51 -06:00
|
|
|
func TestZeroArgCallback(t *testing.T) { testZeroArgCallback(t) }
|
|
|
|
func TestBlocking(t *testing.T) { testBlocking(t) }
|
|
|
|
func Test1328(t *testing.T) { test1328(t) }
|
|
|
|
func TestParallelSleep(t *testing.T) { testParallelSleep(t) }
|
2011-05-02 13:38:13 -06:00
|
|
|
func TestSetEnv(t *testing.T) { testSetEnv(t) }
|
2011-08-30 11:33:16 -06:00
|
|
|
func TestHelpers(t *testing.T) { testHelpers(t) }
|
cmd/go: new cgo build procedure
This CL adds a step to the build procedure for cgo programs. It uses 'ld -r'
to combine all gcc compiled object file and generate a relocatable object file
for our ld. Additionally, this linking step will combine some static linking
gcc library into the relocatable object file, so that we can use libgcc,
libmingwex and libmingw32 without problem.
Fixes #3261.
Fixes #1741.
Added a testcase for linking in libgcc.
TODO:
1. still need to fix the INDIRECT_SYMBOL_LOCAL problem on Darwin/386.
2. still need to enable the libgcc test on Linux/ARM, because 5l can't deal
with thumb libgcc.
Tested on Darwin/amd64, Darwin/386, FreeBSD/amd64, FreeBSD/386, Linux/amd64,
Linux/386, Linux/ARM, Windows/amd64, Windows/386
R=iant, rsc, bradfitz, coldredlemur
CC=golang-dev
https://golang.org/cl/5822049
2012-08-16 13:42:34 -06:00
|
|
|
func TestLibgcc(t *testing.T) { testLibgcc(t) }
|
2012-08-29 09:42:05 -06:00
|
|
|
func Test1635(t *testing.T) { test1635(t) }
|
2012-09-02 20:12:51 -06:00
|
|
|
func TestPrintf(t *testing.T) { testPrintf(t) }
|
2012-10-09 10:55:48 -06:00
|
|
|
func Test4029(t *testing.T) { test4029(t) }
|
2012-11-21 14:04:38 -07:00
|
|
|
func TestBoolAlign(t *testing.T) { testBoolAlign(t) }
|
2012-12-17 09:26:08 -07:00
|
|
|
func Test3729(t *testing.T) { test3729(t) }
|
2013-02-01 09:34:41 -07:00
|
|
|
func Test3775(t *testing.T) { test3775(t) }
|
2013-02-20 15:48:23 -07:00
|
|
|
func TestCthread(t *testing.T) { testCthread(t) }
|
2013-03-25 15:10:28 -06:00
|
|
|
func TestCallbackCallers(t *testing.T) { testCallbackCallers(t) }
|
2013-04-09 23:15:49 -06:00
|
|
|
func Test5227(t *testing.T) { test5227(t) }
|
2013-04-10 22:41:54 -06:00
|
|
|
func TestCflags(t *testing.T) { testCflags(t) }
|
2013-05-14 22:33:29 -06:00
|
|
|
func Test5337(t *testing.T) { test5337(t) }
|
2013-05-23 23:51:07 -06:00
|
|
|
func Test5548(t *testing.T) { test5548(t) }
|
2013-06-09 08:06:29 -06:00
|
|
|
func Test5603(t *testing.T) { test5603(t) }
|
2013-07-11 14:39:39 -06:00
|
|
|
func Test3250(t *testing.T) { test3250(t) }
|
2013-07-22 11:53:20 -06:00
|
|
|
func TestCallbackStack(t *testing.T) { testCallbackStack(t) }
|
2013-08-13 10:42:21 -06:00
|
|
|
func TestFpVar(t *testing.T) { testFpVar(t) }
|
2013-09-11 07:56:38 -06:00
|
|
|
func Test4339(t *testing.T) { test4339(t) }
|
2013-09-16 12:04:55 -06:00
|
|
|
func Test6390(t *testing.T) { test6390(t) }
|
2013-09-18 23:20:02 -06:00
|
|
|
func Test5986(t *testing.T) { test5986(t) }
|
[release-branch.go1.2] cmd/cgo: stop using compiler error message text to analyze C names
««« CL 15070043 / 90a628ac54ed
cmd/cgo: stop using compiler error message text to analyze C names
The old approach to determining whether "name" was a type, constant,
or expression was to compile the C program
name;
and scan the errors and warnings generated by the compiler.
This requires looking for specific substrings in the errors and warnings,
which ties the implementation to specific compiler versions.
As compilers change their errors or drop warnings, cgo breaks.
This happens slowly but it does happen.
Clang in particular (now required on OS X) has a significant churn rate.
The new approach compiles a slightly more complex program
that is either valid C or not valid C depending on what kind of
thing "name" is. It uses only the presence or absence of an error
message on a particular line, not the error text itself. The program is:
// error if and only if name is undeclared
void f1(void) { typeof(name) *x; }
// error if and only if name is not a type
void f2(void) { name *x; }
// error if and only if name is not an integer constant
void f3(void) { enum { x = (name)*1 }; }
I had not been planning to do this until Go 1.3, because it is a
non-trivial change, but it fixes a real Xcode 5 problem in Go 1.2,
and the new code is easier to understand than the old code.
It should be significantly more robust.
Fixes #6596.
Fixes #6612.
R=golang-dev, r, james, iant
CC=golang-dev
https://golang.org/cl/15070043
»»»
R=golang-dev
CC=golang-dev
https://golang.org/cl/20060044
2013-10-31 18:05:17 -06:00
|
|
|
func TestNaming(t *testing.T) { testNaming(t) }
|
2011-08-18 10:17:09 -06:00
|
|
|
|
|
|
|
func BenchmarkCgoCall(b *testing.B) { benchCgoCall(b) }
|