mirror of
https://github.com/golang/go
synced 2024-11-12 06:30:21 -07:00
runtime,cmd/dist,cmd/link: add cgo support on openbsd/arm
Add support for cgo on openbsd/arm.The gcc shipped with base OpenBSD armv7 is old/inadequate, so use clang by default. Change-Id: I945a26d369378952d357727718e69249411e1127 Reviewed-on: https://go-review.googlesource.com/c/154381 Run-TryBot: Joel Sing <joel@sing.id.au> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
99e4ddd053
commit
c52beb1087
2
src/cmd/dist/build.go
vendored
2
src/cmd/dist/build.go
vendored
@ -1448,7 +1448,7 @@ var cgoEnabled = map[string]bool{
|
||||
"netbsd/arm": true,
|
||||
"openbsd/386": true,
|
||||
"openbsd/amd64": true,
|
||||
"openbsd/arm": false,
|
||||
"openbsd/arm": true,
|
||||
"plan9/386": false,
|
||||
"plan9/amd64": false,
|
||||
"plan9/arm": false,
|
||||
|
7
src/cmd/dist/main.go
vendored
7
src/cmd/dist/main.go
vendored
@ -65,6 +65,13 @@ func main() {
|
||||
case "freebsd":
|
||||
// Since FreeBSD 10 gcc is no longer part of the base system.
|
||||
defaultclang = true
|
||||
case "openbsd":
|
||||
// The gcc available on OpenBSD armv7 is old/inadequate (for example, lacks
|
||||
// __sync_fetch_and_*/__sync_*_and_fetch) and will likely be removed in the
|
||||
// not-to-distant future - use clang instead.
|
||||
if runtime.GOARCH == "arm" {
|
||||
defaultclang = true
|
||||
}
|
||||
case "solaris":
|
||||
// Even on 64-bit platform, solaris uname -m prints i86pc.
|
||||
out := run("", CheckExit, "isainfo", "-n")
|
||||
|
@ -535,6 +535,12 @@ func (ctxt *Link) loadlib() {
|
||||
if *flagLibGCC == "" {
|
||||
*flagLibGCC = ctxt.findLibPathCmd("--print-libgcc-file-name", "libgcc")
|
||||
}
|
||||
if runtime.GOOS == "openbsd" && *flagLibGCC == "libgcc.a" {
|
||||
// On OpenBSD `clang --print-libgcc-file-name` returns "libgcc.a".
|
||||
// In this case we fail to load libgcc.a and can encounter link
|
||||
// errors - see if we can find libcompiler_rt.a instead.
|
||||
*flagLibGCC = ctxt.findLibPathCmd("--print-file-name=libcompiler_rt.a", "libcompiler_rt")
|
||||
}
|
||||
if *flagLibGCC != "none" {
|
||||
hostArchive(ctxt, *flagLibGCC)
|
||||
}
|
||||
|
67
src/runtime/cgo/gcc_openbsd_arm.c
Normal file
67
src/runtime/cgo/gcc_openbsd_arm.c
Normal file
@ -0,0 +1,67 @@
|
||||
// Copyright 2018 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 <pthread.h>
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
#include "libcgo.h"
|
||||
#include "libcgo_unix.h"
|
||||
|
||||
static void* threadentry(void*);
|
||||
static void (*setg_gcc)(void*);
|
||||
|
||||
void
|
||||
x_cgo_init(G *g, void (*setg)(void*))
|
||||
{
|
||||
pthread_attr_t attr;
|
||||
size_t size;
|
||||
|
||||
setg_gcc = setg;
|
||||
pthread_attr_init(&attr);
|
||||
pthread_attr_getstacksize(&attr, &size);
|
||||
g->stacklo = (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);
|
||||
pthread_sigmask(SIG_SETMASK, &ign, &oset);
|
||||
|
||||
pthread_attr_init(&attr);
|
||||
pthread_attr_getstacksize(&attr, &size);
|
||||
|
||||
// Leave stacklo=0 and set stackhi=size; mstart will do the rest.
|
||||
ts->g->stackhi = size;
|
||||
err = _cgo_try_pthread_create(&p, &attr, threadentry, ts);
|
||||
|
||||
pthread_sigmask(SIG_SETMASK, &oset, nil);
|
||||
|
||||
if (err != 0) {
|
||||
fprintf(stderr, "runtime/cgo: pthread_create failed: %s\n", strerror(err));
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
extern void crosscall_arm1(void (*fn)(void), void (*setg_gcc)(void*), void *g);
|
||||
|
||||
static void*
|
||||
threadentry(void *v)
|
||||
{
|
||||
ThreadStart ts;
|
||||
|
||||
ts = *(ThreadStart*)v;
|
||||
free(v);
|
||||
|
||||
crosscall_arm1(ts.fn, setg_gcc, (void*)ts.g);
|
||||
return nil;
|
||||
}
|
@ -371,8 +371,9 @@ TEXT runtime·closeonexec(SB),NOSPLIT,$0
|
||||
TEXT ·publicationBarrier(SB),NOSPLIT|NOFRAME,$0-0
|
||||
B runtime·armPublicationBarrier(SB)
|
||||
|
||||
// TODO(jsing): Implement.
|
||||
TEXT runtime·read_tls_fallback(SB),NOSPLIT|NOFRAME,$0
|
||||
MOVW $5, R0
|
||||
MOVW R0, (R0)
|
||||
MOVM.WP [R1, R2, R3, R12], (R13)
|
||||
MOVW $330, R12 // sys___get_tcb
|
||||
SWI $0
|
||||
MOVM.IAW (R13), [R1, R2, R3, R12]
|
||||
RET
|
||||
|
Loading…
Reference in New Issue
Block a user