]> Cypherpunks repositories - gostls13.git/commitdiff
cgo: enable cgo on dragonfly
authorAulus Egnatius Varialus <varialus@gmail.com>
Wed, 4 Sep 2013 22:19:21 +0000 (15:19 -0700)
committerIan Lance Taylor <iant@golang.org>
Wed, 4 Sep 2013 22:19:21 +0000 (15:19 -0700)
Enable cgo for dragonfly/386 and dragonfly/amd64.

R=golang-dev, jsing, iant, bradfitz
CC=golang-dev
https://golang.org/cl/13247046

13 files changed:
misc/cgo/test/cthread_unix.c
misc/cgo/testso/cgoso.go
src/cmd/6l/obj.c
src/cmd/ld/lib.c
src/pkg/go/build/build.go
src/pkg/os/user/lookup_unix.go
src/pkg/runtime/cgo/cgo.go
src/pkg/runtime/cgo/dragonfly.c [new file with mode: 0644]
src/pkg/runtime/cgo/gcc_dragonfly_386.c [new file with mode: 0644]
src/pkg/runtime/cgo/gcc_dragonfly_amd64.c [new file with mode: 0644]
src/pkg/runtime/cgo/gcc_setenv.c
src/pkg/runtime/cgo/setenv.c
src/run.bash

index 998bc00cb78d7733fe99863316006736a1bc8ba0..3f39c15e0e8fd3d9469f54818813f65f9dce2ded 100644 (file)
@@ -2,7 +2,7 @@
 // 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
+// +build darwin dragonfly freebsd linux netbsd openbsd
 
 #include <pthread.h>
 #include "_cgo_export.h"
index 0f800afb17e9fc85256adf617dbf9613823fc2de..ba6218348cab5271569801700e521b6881284c5d 100644 (file)
@@ -8,6 +8,7 @@ package cgosotest
 // intentionally write the same LDFLAGS differently
 // to test correct handling of LDFLAGS.
 #cgo linux LDFLAGS: -L. -lcgosotest
+#cgo dragonfly LDFLAGS: -L. -l cgosotest
 #cgo freebsd LDFLAGS: -L. -l cgosotest
 #cgo openbsd LDFLAGS: -L. -l cgosotest
 #cgo netbsd LDFLAGS: -L. libcgosotest.so
index b972c535b95969b108ee15695ffba64ce001aa7b..12ca0f63501ea0dff83e4bcb6eee77979a673273 100644 (file)
@@ -152,6 +152,7 @@ main(int argc, char *argv[])
                        sysfatal("cannot use -linkmode=external with -H %s", headstr(HEADTYPE));
                break;
        case Hdarwin:
+       case Hdragonfly:
        case Hfreebsd:
        case Hlinux:
        case Hnetbsd:
index 7639615b48374a5e63ee1938f9783d586d309960..0d67ae999b2165dffaafb82a7a5f14801d6f81b7 100644 (file)
@@ -582,6 +582,16 @@ ldhostobj(void (*ld)(Biobuf*, char*, int64, char*), Biobuf *f, char *pkg, int64
                }
        }
 
+       // DragonFly declares errno with __thread, which results in a symbol
+       // type of R_386_TLS_GD or R_X86_64_TLSGD. The Go linker does not
+       // currently know how to handle TLS relocations, hence we have to
+       // force external linking for any libraries that link in code that
+       // uses errno. This can be removed if the Go linker ever supports
+       // these relocation types.
+       if(HEADTYPE == Hdragonfly)
+       if(strcmp(pkg, "net") == 0 || strcmp(pkg, "os/user") == 0)
+               isinternal = 0;
+
        if(!isinternal)
                externalobj = 1;
 
index ecea22456e25694a43e53dded934bcd434eafcba..043351a950ec452942d62895cb40a1b3275219e6 100644 (file)
@@ -258,21 +258,23 @@ func (ctxt *Context) SrcDirs() []string {
 var Default Context = defaultContext()
 
 var cgoEnabled = map[string]bool{
-       "darwin/386":    true,
-       "darwin/amd64":  true,
-       "freebsd/386":   true,
-       "freebsd/amd64": true,
-       "freebsd/arm":   true,
-       "linux/386":     true,
-       "linux/amd64":   true,
-       "linux/arm":     true,
-       "netbsd/386":    true,
-       "netbsd/amd64":  true,
-       "netbsd/arm":    true,
-       "openbsd/386":   true,
-       "openbsd/amd64": true,
-       "windows/386":   true,
-       "windows/amd64": true,
+       "darwin/386":      true,
+       "darwin/amd64":    true,
+       "dragonfly/386":   true,
+       "dragonfly/amd64": true,
+       "freebsd/386":     true,
+       "freebsd/amd64":   true,
+       "freebsd/arm":     true,
+       "linux/386":       true,
+       "linux/amd64":     true,
+       "linux/arm":       true,
+       "netbsd/386":      true,
+       "netbsd/amd64":    true,
+       "netbsd/arm":      true,
+       "openbsd/386":     true,
+       "openbsd/amd64":   true,
+       "windows/386":     true,
+       "windows/amd64":   true,
 }
 
 func defaultContext() Context {
index 6095422638d67dc8d4e034b56f8198f91bdd5767..e709f7e521bb084ec0c026d319c4fe714bf10a2b 100644 (file)
@@ -2,7 +2,7 @@
 // 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
+// +build darwin dragonfly freebsd linux netbsd openbsd
 // +build cgo
 
 package user
index e0d53866830f8f8888d653db3a8b096a5486b1df..258b6fba103b0713758661e4899e69a96c859419 100644 (file)
@@ -12,6 +12,7 @@ package cgo
 /*
 
 #cgo darwin LDFLAGS: -lpthread
+#cgo dragonfly LDFLAGS: -lpthread
 #cgo freebsd LDFLAGS: -lpthread
 #cgo linux LDFLAGS: -lpthread
 #cgo netbsd LDFLAGS: -lpthread
diff --git a/src/pkg/runtime/cgo/dragonfly.c b/src/pkg/runtime/cgo/dragonfly.c
new file mode 100644 (file)
index 0000000..acf53e2
--- /dev/null
@@ -0,0 +1,13 @@
+// Copyright 2010 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.
+
+// Supply environ and __progname, because we don't
+// link against the standard DragonFly crt0.o and the
+// libc dynamic library needs them.
+
+char *environ[1];
+char *__progname;
+
+#pragma dynexport environ environ
+#pragma dynexport __progname __progname
diff --git a/src/pkg/runtime/cgo/gcc_dragonfly_386.c b/src/pkg/runtime/cgo/gcc_dragonfly_386.c
new file mode 100644 (file)
index 0000000..6797824
--- /dev/null
@@ -0,0 +1,77 @@
+// Copyright 2009 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.
+
+#include <sys/types.h>
+#include <sys/signalvar.h>
+#include <pthread.h>
+#include <signal.h>
+#include <string.h>
+#include "libcgo.h"
+
+static void* threadentry(void*);
+static void (*setmg_gcc)(void*, void*);
+
+void
+x_cgo_init(G *g, void (*setmg)(void*, void*))
+{
+       pthread_attr_t attr;
+       size_t size;
+
+       setmg_gcc = setmg;
+       pthread_attr_init(&attr);
+       pthread_attr_getstacksize(&attr, &size);
+       g->stackguard = (uintptr)&attr - size + 4096;
+       pthread_attr_destroy(&attr);
+}
+
+
+void
+_cgo_sys_thread_start(ThreadStart *ts)
+{
+       pthread_attr_t attr;
+       sigset_t ign, oset;
+       pthread_t p;
+       size_t size;
+       int err;
+
+       SIGFILLSET(ign);
+       sigprocmask(SIG_SETMASK, &ign, &oset);
+
+       pthread_attr_init(&attr);
+       pthread_attr_getstacksize(&attr, &size);
+       ts->g->stackguard = size;
+       err = pthread_create(&p, &attr, threadentry, ts);
+
+       sigprocmask(SIG_SETMASK, &oset, nil);
+
+       if (err != 0) {
+               fprintf(stderr, "runtime/cgo: pthread_create failed: %s\n", strerror(err));
+               abort();
+       }
+}
+
+static void*
+threadentry(void *v)
+{
+       ThreadStart ts;
+
+       ts = *(ThreadStart*)v;
+       free(v);
+
+       ts.g->stackbase = (uintptr)&ts;
+
+       /*
+        * _cgo_sys_thread_start set stackguard to stack size;
+        * change to actual guard pointer.
+        */
+       ts.g->stackguard = (uintptr)&ts - ts.g->stackguard + 4096;
+
+       /*
+        * Set specific keys.
+        */
+       setmg_gcc((void*)ts.m, (void*)ts.g);
+
+       crosscall_386(ts.fn);
+       return nil;
+}
diff --git a/src/pkg/runtime/cgo/gcc_dragonfly_amd64.c b/src/pkg/runtime/cgo/gcc_dragonfly_amd64.c
new file mode 100644 (file)
index 0000000..eb342a2
--- /dev/null
@@ -0,0 +1,77 @@
+// Copyright 2009 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.
+
+#include <sys/types.h>
+#include <sys/signalvar.h>
+#include <pthread.h>
+#include <signal.h>
+#include <string.h>
+#include "libcgo.h"
+
+static void* threadentry(void*);
+static void (*setmg_gcc)(void*, void*);
+
+void
+x_cgo_init(G *g, void (*setmg)(void*, void*))
+{
+       pthread_attr_t attr;
+       size_t size;
+
+       setmg_gcc = setmg;
+       pthread_attr_init(&attr);
+       pthread_attr_getstacksize(&attr, &size);
+       g->stackguard = (uintptr)&attr - size + 4096;
+       pthread_attr_destroy(&attr);
+}
+
+void
+_cgo_sys_thread_start(ThreadStart *ts)
+{
+       pthread_attr_t attr;
+       sigset_t ign, oset;
+       pthread_t p;
+       size_t size;
+       int err;
+
+       SIGFILLSET(ign);
+       sigprocmask(SIG_SETMASK, &ign, &oset);
+
+       pthread_attr_init(&attr);
+       pthread_attr_getstacksize(&attr, &size);
+
+       ts->g->stackguard = size;
+       err = pthread_create(&p, &attr, threadentry, ts);
+
+       sigprocmask(SIG_SETMASK, &oset, nil);
+
+       if (err != 0) {
+               fprintf(stderr, "runtime/cgo: pthread_create failed: %s\n", strerror(err));
+               abort();
+       }
+}
+
+static void*
+threadentry(void *v)
+{
+       ThreadStart ts;
+
+       ts = *(ThreadStart*)v;
+       free(v);
+
+       ts.g->stackbase = (uintptr)&ts;
+
+       /*
+        * _cgo_sys_thread_start set stackguard to stack size;
+        * change to actual guard pointer.
+        */
+       ts.g->stackguard = (uintptr)&ts - ts.g->stackguard + 4096;
+
+       /*
+        * Set specific keys.
+        */
+       setmg_gcc((void*)ts.m, (void*)ts.g);
+
+       crosscall_amd64(ts.fn);
+       return nil;
+}
index a0938166d1ec3e8204b7e03cabf88a2a89988614..8b128b94651ecf096f43899f4556d014e54f3168 100644 (file)
@@ -2,7 +2,7 @@
 // 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
+// +build darwin dragonfly freebsd linux netbsd openbsd
 
 #include "libcgo.h"
 
index 4c47cdb0025040a5a993a84ad19be5c6c894f9eb..2d03db09f10f4197947a35b6955ab79e1131ed4b 100644 (file)
@@ -2,7 +2,7 @@
 // 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
+// +build darwin dragonfly freebsd linux netbsd openbsd
 
 #pragma cgo_import_static x_cgo_setenv
 
index 9af3f95b074aa3eb0afa963d31a44c6243faef9e..6adb7f63de1a7e8e5c779d913cce44ed07bd6330 100755 (executable)
@@ -104,7 +104,8 @@ go run $GOROOT/test/run.go - . || exit 1
 [ "$CGO_ENABLED" != 1 ] ||
 (xcd ../misc/cgo/test
 go test -ldflags '-linkmode=auto' || exit 1
-go test -ldflags '-linkmode=internal' || exit 1
+# linkmode=internal fails on dragonfly since errno is a TLS relocation.
+[ "$GOHOSTOS" == dragonfly ] || go test -ldflags '-linkmode=internal' || exit 1
 case "$GOHOSTOS-$GOARCH" in
 openbsd-386 | openbsd-amd64)
        # test linkmode=external, but __thread not supported, so skip testtls.
@@ -118,7 +119,7 @@ darwin-386 | darwin-amd64)
        *) go test -ldflags '-linkmode=external'  || exit 1;;
        esac
        ;;
-freebsd-386 | freebsd-amd64 | linux-386 | linux-amd64 | linux-arm | netbsd-386 | netbsd-amd64)
+dragonfly-386 | dragonfly-amd64 | freebsd-386 | freebsd-amd64 | linux-386 | linux-amd64 | linux-arm | netbsd-386 | netbsd-amd64)
        go test -ldflags '-linkmode=external' || exit 1
        go test -ldflags '-linkmode=auto' ../testtls || exit 1
        go test -ldflags '-linkmode=external' ../testtls || exit 1