Skip to content

Commit 998cc2a

Browse files
4a6f656cbradfitz
authored andcommitted
cmd,runtime: enable cgo for openbsd/arm64
Updates #31656. Change-Id: Ide6f829282fcdf20c67998b766a201a6a92c3035 Reviewed-on: https://go-review.googlesource.com/c/go/+/174132 Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 98c5a56 commit 998cc2a

File tree

3 files changed

+75
-3
lines changed

3 files changed

+75
-3
lines changed

src/cmd/dist/build.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1514,7 +1514,7 @@ var cgoEnabled = map[string]bool{
15141514
"openbsd/386": true,
15151515
"openbsd/amd64": true,
15161516
"openbsd/arm": true,
1517-
"openbsd/arm64": false,
1517+
"openbsd/arm64": true,
15181518
"plan9/386": false,
15191519
"plan9/amd64": false,
15201520
"plan9/arm": false,

src/cmd/nm/nm_cgo_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,20 @@ import (
1313

1414
func canInternalLink() bool {
1515
switch runtime.GOOS {
16+
case "aix":
17+
return false
1618
case "dragonfly":
1719
return false
1820
case "linux":
1921
switch runtime.GOARCH {
2022
case "arm64", "mips64", "mips64le", "mips", "mipsle", "ppc64", "ppc64le":
2123
return false
2224
}
23-
case "aix":
24-
return false
25+
case "openbsd":
26+
switch runtime.GOARCH {
27+
case "arm64":
28+
return false
29+
}
2530
}
2631
return true
2732
}

src/runtime/cgo/gcc_openbsd_arm64.c

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Copyright 2019 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
#include <sys/types.h>
6+
#include <pthread.h>
7+
#include <signal.h>
8+
#include <string.h>
9+
#include "libcgo.h"
10+
#include "libcgo_unix.h"
11+
12+
static void* threadentry(void*);
13+
static void (*setg_gcc)(void*);
14+
15+
void
16+
x_cgo_init(G *g, void (*setg)(void*))
17+
{
18+
pthread_attr_t attr;
19+
size_t size;
20+
21+
setg_gcc = setg;
22+
pthread_attr_init(&attr);
23+
pthread_attr_getstacksize(&attr, &size);
24+
g->stacklo = (uintptr)&attr - size + 4096;
25+
pthread_attr_destroy(&attr);
26+
}
27+
28+
void
29+
_cgo_sys_thread_start(ThreadStart *ts)
30+
{
31+
pthread_attr_t attr;
32+
sigset_t ign, oset;
33+
pthread_t p;
34+
size_t size;
35+
int err;
36+
37+
sigfillset(&ign);
38+
pthread_sigmask(SIG_SETMASK, &ign, &oset);
39+
40+
pthread_attr_init(&attr);
41+
pthread_attr_getstacksize(&attr, &size);
42+
43+
// Leave stacklo=0 and set stackhi=size; mstart will do the rest.
44+
ts->g->stackhi = size;
45+
err = _cgo_try_pthread_create(&p, &attr, threadentry, ts);
46+
47+
pthread_sigmask(SIG_SETMASK, &oset, nil);
48+
49+
if (err != 0) {
50+
fprintf(stderr, "runtime/cgo: pthread_create failed: %s\n", strerror(err));
51+
abort();
52+
}
53+
}
54+
55+
extern void crosscall1(void (*fn)(void), void (*setg_gcc)(void*), void *g);
56+
57+
static void*
58+
threadentry(void *v)
59+
{
60+
ThreadStart ts;
61+
62+
ts = *(ThreadStart*)v;
63+
free(v);
64+
65+
crosscall1(ts.fn, setg_gcc, (void*)ts.g);
66+
return nil;
67+
}

0 commit comments

Comments
 (0)