summaryrefslogtreecommitdiff
path: root/src/pkg/runtime/cgo
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkg/runtime/cgo')
-rw-r--r--src/pkg/runtime/cgo/Makefile14
-rw-r--r--[-rwxr-xr-x]src/pkg/runtime/cgo/gcc_386.S (renamed from src/pkg/runtime/cgo/386.S)0
-rw-r--r--src/pkg/runtime/cgo/gcc_amd64.S (renamed from src/pkg/runtime/cgo/amd64.S)2
-rw-r--r--src/pkg/runtime/cgo/gcc_arm.S (renamed from src/pkg/runtime/cgo/arm.S)0
-rw-r--r--src/pkg/runtime/cgo/gcc_darwin_386.c (renamed from src/pkg/runtime/cgo/darwin_386.c)17
-rw-r--r--src/pkg/runtime/cgo/gcc_darwin_amd64.c (renamed from src/pkg/runtime/cgo/darwin_amd64.c)17
-rw-r--r--src/pkg/runtime/cgo/gcc_freebsd_386.c (renamed from src/pkg/runtime/cgo/freebsd_386.c)11
-rw-r--r--src/pkg/runtime/cgo/gcc_freebsd_amd64.c (renamed from src/pkg/runtime/cgo/freebsd_amd64.c)11
-rw-r--r--src/pkg/runtime/cgo/gcc_linux_386.c (renamed from src/pkg/runtime/cgo/linux_386.c)11
-rw-r--r--src/pkg/runtime/cgo/gcc_linux_amd64.c (renamed from src/pkg/runtime/cgo/linux_amd64.c)12
-rw-r--r--src/pkg/runtime/cgo/gcc_linux_arm.c (renamed from src/pkg/runtime/cgo/linux_arm.c)5
-rw-r--r--src/pkg/runtime/cgo/gcc_setenv.c (renamed from src/pkg/runtime/cgo/setenv.c)2
-rw-r--r--src/pkg/runtime/cgo/gcc_util.c (renamed from src/pkg/runtime/cgo/util.c)0
-rw-r--r--[-rwxr-xr-x]src/pkg/runtime/cgo/gcc_windows_386.c (renamed from src/pkg/runtime/cgo/windows_386.c)25
-rw-r--r--[-rwxr-xr-x]src/pkg/runtime/cgo/gcc_windows_amd64.c (renamed from src/pkg/runtime/cgo/windows_amd64.c)25
-rw-r--r--src/pkg/runtime/cgo/libcgo.h2
-rw-r--r--src/pkg/runtime/cgo/trigger.go20
17 files changed, 119 insertions, 55 deletions
diff --git a/src/pkg/runtime/cgo/Makefile b/src/pkg/runtime/cgo/Makefile
index 766794797..05c7ebae7 100644
--- a/src/pkg/runtime/cgo/Makefile
+++ b/src/pkg/runtime/cgo/Makefile
@@ -14,15 +14,15 @@ ifeq ($(CGO_ENABLED),1)
# Unwarranted chumminess with Make.pkg's cgo rules.
# Do not try this at home.
CGO_OFILES=\
- $(GOARCH).o\
- $(GOOS)_$(GOARCH).o\
- util.o\
+ gcc_$(GOARCH).o\
+ gcc_$(GOOS)_$(GOARCH).o\
+ gcc_util.o\
ifeq ($(GOOS),windows)
CGO_LDFLAGS=-lm -mthreads
else
CGO_LDFLAGS=-lpthread
-CGO_OFILES+=setenv.o\
+CGO_OFILES+=gcc_setenv.o\
endif
@@ -50,11 +50,11 @@ _cgo_main.c:
echo 'int main() { return 0; }' >$@
endif
-$(GOARCH).o: $(GOARCH).S
+gcc_$(GOARCH).o: gcc_$(GOARCH).S
$(HOST_CC) $(_CGO_CFLAGS_$(GOARCH)) -g -O2 -fPIC -o $@ -c $^
-$(GOOS)_$(GOARCH).o: $(GOOS)_$(GOARCH).c
+gcc_$(GOOS)_$(GOARCH).o: gcc_$(GOOS)_$(GOARCH).c
$(HOST_CC) $(_CGO_CFLAGS_$(GOARCH)) -g -O2 -fPIC -o $@ -c $^
-%.o: %.c
+gcc_%.o: gcc_%.c
$(HOST_CC) $(_CGO_CFLAGS_$(GOARCH)) -g -O2 -fPIC -o $@ -c $^
diff --git a/src/pkg/runtime/cgo/386.S b/src/pkg/runtime/cgo/gcc_386.S
index 9abab7ebd..9abab7ebd 100755..100644
--- a/src/pkg/runtime/cgo/386.S
+++ b/src/pkg/runtime/cgo/gcc_386.S
diff --git a/src/pkg/runtime/cgo/amd64.S b/src/pkg/runtime/cgo/gcc_amd64.S
index 6c1a4c8e9..8e6d506f3 100644
--- a/src/pkg/runtime/cgo/amd64.S
+++ b/src/pkg/runtime/cgo/gcc_amd64.S
@@ -5,7 +5,7 @@
/*
* Apple still insists on underscore prefixes for C function names.
*/
-#if defined(__APPLE__) || defined(_WIN32)
+#if defined(__APPLE__)
#define EXT(s) _##s
#else
#define EXT(s) s
diff --git a/src/pkg/runtime/cgo/arm.S b/src/pkg/runtime/cgo/gcc_arm.S
index 32d862984..32d862984 100644
--- a/src/pkg/runtime/cgo/arm.S
+++ b/src/pkg/runtime/cgo/gcc_arm.S
diff --git a/src/pkg/runtime/cgo/darwin_386.c b/src/pkg/runtime/cgo/gcc_darwin_386.c
index 6d4e259be..d9f25347a 100644
--- a/src/pkg/runtime/cgo/darwin_386.c
+++ b/src/pkg/runtime/cgo/gcc_darwin_386.c
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
+#include <string.h> /* for strerror */
#include <pthread.h>
#include "libcgo.h"
@@ -38,8 +39,8 @@ inittls(void)
*
* The linker and runtime hard-code these constant offsets
* from %gs where we expect to find m and g.
- * Known to ../cmd/8l/obj.c:/468
- * and to ../pkg/runtime/darwin/386/sys.s:/468
+ * Known to ../../../cmd/8l/obj.c:/468
+ * and to ../sys_darwin_386.s:/468
*
* This is truly disgusting and a bit fragile, but taking care
* of it here protects the rest of the system from damage.
@@ -100,12 +101,20 @@ inittls(void)
}
static void
-xinitcgo(void)
+xinitcgo(G *g)
{
+ pthread_attr_t attr;
+ size_t size;
+
+ pthread_attr_init(&attr);
+ pthread_attr_getstacksize(&attr, &size);
+ g->stackguard = (uintptr)&attr - size + 4096;
+ pthread_attr_destroy(&attr);
+
inittls();
}
-void (*initcgo)(void) = xinitcgo;
+void (*initcgo)(G*) = xinitcgo;
void
libcgo_sys_thread_start(ThreadStart *ts)
diff --git a/src/pkg/runtime/cgo/darwin_amd64.c b/src/pkg/runtime/cgo/gcc_darwin_amd64.c
index 3471044c0..a0b026ee2 100644
--- a/src/pkg/runtime/cgo/darwin_amd64.c
+++ b/src/pkg/runtime/cgo/gcc_darwin_amd64.c
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
+#include <string.h> /* for strerror */
#include <pthread.h>
#include "libcgo.h"
@@ -26,8 +27,8 @@ inittls(void)
*
* The linker and runtime hard-code these constant offsets
* from %gs where we expect to find m and g.
- * Known to ../cmd/6l/obj.c:/8a0
- * and to ../pkg/runtime/darwin/amd64/sys.s:/8a0
+ * Known to ../../../cmd/6l/obj.c:/8a0
+ * and to ../sys_darwin_amd64.s:/8a0
*
* As disgusting as on the 386; same justification.
*/
@@ -70,12 +71,20 @@ inittls(void)
}
void
-xinitcgo(void)
+xinitcgo(G *g)
{
+ pthread_attr_t attr;
+ size_t size;
+
+ pthread_attr_init(&attr);
+ pthread_attr_getstacksize(&attr, &size);
+ g->stackguard = (uintptr)&attr - size + 4096;
+ pthread_attr_destroy(&attr);
+
inittls();
}
-void (*initcgo) = xinitcgo;
+void (*initcgo)(G*) = xinitcgo;
void
libcgo_sys_thread_start(ThreadStart *ts)
diff --git a/src/pkg/runtime/cgo/freebsd_386.c b/src/pkg/runtime/cgo/gcc_freebsd_386.c
index ae53201b4..ad9468730 100644
--- a/src/pkg/runtime/cgo/freebsd_386.c
+++ b/src/pkg/runtime/cgo/gcc_freebsd_386.c
@@ -8,11 +8,18 @@
static void* threadentry(void*);
static void
-xinitcgo(void)
+xinitcgo(G *g)
{
+ pthread_attr_t attr;
+ size_t size;
+
+ pthread_attr_init(&attr);
+ pthread_attr_getstacksize(&attr, &size);
+ g->stackguard = (uintptr)&attr - size + 4096;
+ pthread_attr_destroy(&attr);
}
-void (*initcgo)(void) = xinitcgo;
+void (*initcgo)(G*) = xinitcgo;
void
libcgo_sys_thread_start(ThreadStart *ts)
diff --git a/src/pkg/runtime/cgo/freebsd_amd64.c b/src/pkg/runtime/cgo/gcc_freebsd_amd64.c
index 5afc1dfea..b18d1bc67 100644
--- a/src/pkg/runtime/cgo/freebsd_amd64.c
+++ b/src/pkg/runtime/cgo/gcc_freebsd_amd64.c
@@ -8,11 +8,18 @@
static void* threadentry(void*);
static void
-xinitcgo(void)
+xinitcgo(G *g)
{
+ pthread_attr_t attr;
+ size_t size;
+
+ pthread_attr_init(&attr);
+ pthread_attr_getstacksize(&attr, &size);
+ g->stackguard = (uintptr)&attr - size + 4096;
+ pthread_attr_destroy(&attr);
}
-void (*initcgo)(void) = xinitcgo;
+void (*initcgo)(G*) = xinitcgo;
void
libcgo_sys_thread_start(ThreadStart *ts)
diff --git a/src/pkg/runtime/cgo/linux_386.c b/src/pkg/runtime/cgo/gcc_linux_386.c
index e9df5ffdc..8401a75ca 100644
--- a/src/pkg/runtime/cgo/linux_386.c
+++ b/src/pkg/runtime/cgo/gcc_linux_386.c
@@ -9,11 +9,18 @@
static void *threadentry(void*);
static void
-xinitcgo(void)
+xinitcgo(G *g)
{
+ pthread_attr_t attr;
+ size_t size;
+
+ pthread_attr_init(&attr);
+ pthread_attr_getstacksize(&attr, &size);
+ g->stackguard = (uintptr)&attr - size + 4096;
+ pthread_attr_destroy(&attr);
}
-void (*initcgo) = xinitcgo;
+void (*initcgo)(G*) = xinitcgo;
void
libcgo_sys_thread_start(ThreadStart *ts)
diff --git a/src/pkg/runtime/cgo/linux_amd64.c b/src/pkg/runtime/cgo/gcc_linux_amd64.c
index d9b8b3706..6ce3333a8 100644
--- a/src/pkg/runtime/cgo/linux_amd64.c
+++ b/src/pkg/runtime/cgo/gcc_linux_amd64.c
@@ -3,16 +3,24 @@
// license that can be found in the LICENSE file.
#include <pthread.h>
+#include <string.h> // strerror
#include "libcgo.h"
static void* threadentry(void*);
void
-xinitcgo(void)
+xinitcgo(G* g)
{
+ pthread_attr_t attr;
+ size_t size;
+
+ pthread_attr_init(&attr);
+ pthread_attr_getstacksize(&attr, &size);
+ g->stackguard = (uintptr)&attr - size + 4096;
+ pthread_attr_destroy(&attr);
}
-void (*initcgo)(void) = xinitcgo;
+void (*initcgo)(G*) = xinitcgo;
void
libcgo_sys_thread_start(ThreadStart *ts)
diff --git a/src/pkg/runtime/cgo/linux_arm.c b/src/pkg/runtime/cgo/gcc_linux_arm.c
index e556c433c..8397c75bb 100644
--- a/src/pkg/runtime/cgo/linux_arm.c
+++ b/src/pkg/runtime/cgo/gcc_linux_arm.c
@@ -5,11 +5,12 @@
#include "libcgo.h"
static void
-xinitcgo(void)
+xinitcgo(G *g)
{
+ // unimplemented
}
-void (*initcgo)(void) = xinitcgo;
+void (*initcgo)(G*) = xinitcgo;
void
libcgo_sys_thread_start(ThreadStart *ts)
diff --git a/src/pkg/runtime/cgo/setenv.c b/src/pkg/runtime/cgo/gcc_setenv.c
index c911b8392..7da4ad915 100644
--- a/src/pkg/runtime/cgo/setenv.c
+++ b/src/pkg/runtime/cgo/gcc_setenv.c
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
+// +build darwin freebsd linux netbsd openbsd
+
#include "libcgo.h"
#include <stdlib.h>
diff --git a/src/pkg/runtime/cgo/util.c b/src/pkg/runtime/cgo/gcc_util.c
index e06b6f64d..e06b6f64d 100644
--- a/src/pkg/runtime/cgo/util.c
+++ b/src/pkg/runtime/cgo/gcc_util.c
diff --git a/src/pkg/runtime/cgo/windows_386.c b/src/pkg/runtime/cgo/gcc_windows_386.c
index f39309cb1..2b940d362 100755..100644
--- a/src/pkg/runtime/cgo/windows_386.c
+++ b/src/pkg/runtime/cgo/gcc_windows_386.c
@@ -8,22 +8,24 @@
static void *threadentry(void*);
-/* From what I've read 1MB is default for 32-bit Linux.
- Allocation granularity on Windows is typically 64 KB. */
+/* 1MB is default stack size for 32-bit Windows.
+ Allocation granularity on Windows is typically 64 KB.
+ The constant is also hardcoded in cmd/ld/pe.c (keep synchronized). */
#define STACKSIZE (1*1024*1024)
static void
-xinitcgo(void)
+xinitcgo(G *g)
{
+ int tmp;
+ g->stackguard = (uintptr)&tmp - STACKSIZE + 8*1024;
}
-void (*initcgo)(void) = xinitcgo;
+void (*initcgo)(G*) = xinitcgo;
void
libcgo_sys_thread_start(ThreadStart *ts)
{
- ts->g->stackguard = STACKSIZE;
- _beginthread(threadentry, STACKSIZE, ts);
+ _beginthread(threadentry, 0, ts);
}
static void*
@@ -36,20 +38,15 @@ threadentry(void *v)
free(v);
ts.g->stackbase = (uintptr)&ts;
-
- /*
- * libcgo_sys_thread_start set stackguard to stack size;
- * change to actual guard pointer.
- */
- ts.g->stackguard = (uintptr)&ts - ts.g->stackguard + 4096;
+ ts.g->stackguard = (uintptr)&ts - STACKSIZE + 8*1024;
/*
* Set specific keys in thread local storage.
*/
tls0 = (void*)LocalAlloc(LPTR, 32);
asm volatile (
- "movl %0, %%fs:0x2c\n" // MOVL tls0, 0x2c(FS)
- "movl %%fs:0x2c, %%eax\n" // MOVL 0x2c(FS), tmp
+ "movl %0, %%fs:0x14\n" // MOVL tls0, 0x14(FS)
+ "movl %%fs:0x14, %%eax\n" // MOVL 0x14(FS), tmp
"movl %1, 0(%%eax)\n" // MOVL g, 0(FS)
"movl %2, 4(%%eax)\n" // MOVL m, 4(FS)
:: "r"(tls0), "r"(ts.g), "r"(ts.m) : "%eax"
diff --git a/src/pkg/runtime/cgo/windows_amd64.c b/src/pkg/runtime/cgo/gcc_windows_amd64.c
index e8313e250..0d2f5d233 100755..100644
--- a/src/pkg/runtime/cgo/windows_amd64.c
+++ b/src/pkg/runtime/cgo/gcc_windows_amd64.c
@@ -8,22 +8,24 @@
static void *threadentry(void*);
-/* From what I've read 2MB is default for 64-bit Linux.
- Allocation granularity on Windows is typically 64 KB. */
+/* 2MB is default stack size for 64-bit Windows.
+ Allocation granularity on Windows is typically 64 KB.
+ The constant is also hardcoded in cmd/ld/pe.c (keep synchronized). */
#define STACKSIZE (2*1024*1024)
static void
-xinitcgo(void)
+xinitcgo(G *g)
{
+ int tmp;
+ g->stackguard = (uintptr)&tmp - STACKSIZE + 8*1024;
}
-void (*initcgo)(void) = xinitcgo;
+void (*initcgo)(G*) = xinitcgo;
void
libcgo_sys_thread_start(ThreadStart *ts)
{
- ts->g->stackguard = STACKSIZE;
- _beginthread(threadentry, STACKSIZE, ts);
+ _beginthread(threadentry, 0, ts);
}
static void*
@@ -36,20 +38,15 @@ threadentry(void *v)
free(v);
ts.g->stackbase = (uintptr)&ts;
-
- /*
- * libcgo_sys_thread_start set stackguard to stack size;
- * change to actual guard pointer.
- */
- ts.g->stackguard = (uintptr)&ts - ts.g->stackguard + 4096;
+ ts.g->stackguard = (uintptr)&ts - STACKSIZE + 8*1024;
/*
* Set specific keys in thread local storage.
*/
tls0 = (void*)LocalAlloc(LPTR, 64);
asm volatile (
- "movq %0, %%gs:0x58\n" // MOVL tls0, 0x58(GS)
- "movq %%gs:0x58, %%rax\n" // MOVQ 0x58(GS), tmp
+ "movq %0, %%gs:0x28\n" // MOVL tls0, 0x28(GS)
+ "movq %%gs:0x28, %%rax\n" // MOVQ 0x28(GS), tmp
"movq %1, 0(%%rax)\n" // MOVQ g, 0(GS)
"movq %2, 8(%%rax)\n" // MOVQ m, 8(GS)
:: "r"(tls0), "r"(ts.g), "r"(ts.m) : "%rax"
diff --git a/src/pkg/runtime/cgo/libcgo.h b/src/pkg/runtime/cgo/libcgo.h
index 91032959c..c31d19d76 100644
--- a/src/pkg/runtime/cgo/libcgo.h
+++ b/src/pkg/runtime/cgo/libcgo.h
@@ -42,7 +42,7 @@ struct ThreadStart
* Makes a local copy of the ThreadStart and
* calls libcgo_sys_thread_start(ts).
*/
-void (*libcgo_thread_start)(ThreadStart *ts);
+extern void (*libcgo_thread_start)(ThreadStart *ts);
/*
* Creates the new operating system thread (OS, arch dependent).
diff --git a/src/pkg/runtime/cgo/trigger.go b/src/pkg/runtime/cgo/trigger.go
new file mode 100644
index 000000000..a7788118f
--- /dev/null
+++ b/src/pkg/runtime/cgo/trigger.go
@@ -0,0 +1,20 @@
+// 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.
+
+// This tells the go tool that this package builds using cgo.
+// TODO: Once we stop using Make, this import can move into cgo.go.
+
+package cgo
+
+/*
+
+#cgo darwin LDFLAGS: -lpthread
+#cgo freebsd LDFLAGS: -lpthread
+#cgo linux LDFLAGS: -lpthread
+#cgo netbsd LDFLAGS: -lpthread
+#cgo openbsd LDFLAGS: -lpthread
+#cgo windows LDFLAGS: -lm -mthreads
+
+*/
+import "C"