Commit 960d7082 authored by Shenghou Ma's avatar Shenghou Ma

cmd/ld, runtime/cgo: allow a symbol to be both cgo_export and cgo_import.

Fixes #4878.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/7420052
parent 72dd0145
...@@ -499,11 +499,16 @@ loadcgo(char *file, char *pkg, char *p, int n) ...@@ -499,11 +499,16 @@ loadcgo(char *file, char *pkg, char *p, int n)
remote = local; remote = local;
local = expandpkg(local, pkg); local = expandpkg(local, pkg);
s = lookup(local, 0); s = lookup(local, 0);
// export overrides import, for openbsd/cgo.
// see issue 4878.
if(s->dynimplib != nil) { if(s->dynimplib != nil) {
fprint(2, "%s: symbol is both imported and exported: %s\n", argv0, local); s->dynimplib = nil;
nerrors++; s->extname = nil;
s->dynimpvers = nil;
s->type = 0;
} }
if(s->cgoexport == 0) { if(s->cgoexport == 0) {
if(strcmp(f[0], "cgo_export_static") == 0) if(strcmp(f[0], "cgo_export_static") == 0)
s->cgoexport |= CgoExportStatic; s->cgoexport |= CgoExportStatic;
......
...@@ -48,9 +48,9 @@ tcb_fixup(int mainthread) ...@@ -48,9 +48,9 @@ tcb_fixup(int mainthread)
bcopy(oldtcb, newtcb + TLS_SIZE, TCB_SIZE); bcopy(oldtcb, newtcb + TLS_SIZE, TCB_SIZE);
__set_tcb(newtcb + TLS_SIZE); __set_tcb(newtcb + TLS_SIZE);
// The main thread TCB is a static allocation - do not try to free it. // NOTE(jsing, minux): we can't free oldtcb without causing double-free
if(!mainthread) // problem. so newtcb will be memory leaks. Get rid of this when OpenBSD
free(oldtcb); // has proper support for PT_TLS.
} }
static void * static void *
......
...@@ -48,9 +48,9 @@ tcb_fixup(int mainthread) ...@@ -48,9 +48,9 @@ tcb_fixup(int mainthread)
bcopy(oldtcb, newtcb + TLS_SIZE, TCB_SIZE); bcopy(oldtcb, newtcb + TLS_SIZE, TCB_SIZE);
__set_tcb(newtcb + TLS_SIZE); __set_tcb(newtcb + TLS_SIZE);
// The main thread TCB is a static allocation - do not try to free it. // NOTE(jsing, minux): we can't free oldtcb without causing double-free
if(!mainthread) // problem. so newtcb will be memory leaks. Get rid of this when OpenBSD
free(oldtcb); // has proper support for PT_TLS.
} }
static void * static void *
......
...@@ -74,7 +74,6 @@ go run $GOROOT/test/run.go - . ...@@ -74,7 +74,6 @@ go run $GOROOT/test/run.go - .
) || exit $? ) || exit $?
[ "$CGO_ENABLED" != 1 ] || [ "$CGO_ENABLED" != 1 ] ||
[ "$GOHOSTOS" == openbsd ] || # issue 4878
(xcd ../misc/cgo/test (xcd ../misc/cgo/test
go test go test
case "$GOHOSTOS-$GOARCH" in case "$GOHOSTOS-$GOARCH" in
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment