]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/ld, runtime/cgo: allow a symbol to be both cgo_export and cgo_import.
authorShenghou Ma <minux.ma@gmail.com>
Mon, 11 Mar 2013 06:24:51 +0000 (14:24 +0800)
committerShenghou Ma <minux.ma@gmail.com>
Mon, 11 Mar 2013 06:24:51 +0000 (14:24 +0800)
Fixes #4878.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/7420052

src/cmd/ld/go.c
src/pkg/runtime/cgo/gcc_openbsd_386.c
src/pkg/runtime/cgo/gcc_openbsd_amd64.c
src/run.bash

index 27307819fc8faa47b6e38ac1d8a8994d62a03aef..ff1f5f437be3a731c825b6247f91ab0d0217f8d5 100644 (file)
@@ -499,11 +499,16 @@ loadcgo(char *file, char *pkg, char *p, int n)
                                remote = local;
                        local = expandpkg(local, pkg);
                        s = lookup(local, 0);
+
+                       // export overrides import, for openbsd/cgo.
+                       // see issue 4878.
                        if(s->dynimplib != nil) {
-                               fprint(2, "%s: symbol is both imported and exported: %s\n", argv0, local);
-                               nerrors++;
+                               s->dynimplib = nil;
+                               s->extname = nil;
+                               s->dynimpvers = nil;
+                               s->type = 0;
                        }
-                       
+
                        if(s->cgoexport == 0) {
                                if(strcmp(f[0], "cgo_export_static") == 0)
                                        s->cgoexport |= CgoExportStatic;
index 86c1365adc5c6c41f883f5d1a248f728cac9ebfb..80be31b9c3ad24ac049fa4131667c25e74e90a0d 100644 (file)
@@ -48,9 +48,9 @@ tcb_fixup(int mainthread)
        bcopy(oldtcb, newtcb + TLS_SIZE, TCB_SIZE);
        __set_tcb(newtcb + TLS_SIZE);
 
-       // The main thread TCB is a static allocation - do not try to free it.
-       if(!mainthread)
-               free(oldtcb);
+       // NOTE(jsing, minux): we can't free oldtcb without causing double-free
+       // problem. so newtcb will be memory leaks. Get rid of this when OpenBSD
+       // has proper support for PT_TLS.
 }
 
 static void *
index d3a5e36b03fd25d026e9f3d4961adba3b0e62859..e9cc8184bdbb1f9775529bcc90d5c2ae3366cc57 100644 (file)
@@ -48,9 +48,9 @@ tcb_fixup(int mainthread)
        bcopy(oldtcb, newtcb + TLS_SIZE, TCB_SIZE);
        __set_tcb(newtcb + TLS_SIZE);
 
-       // The main thread TCB is a static allocation - do not try to free it.
-       if(!mainthread)
-               free(oldtcb);
+       // NOTE(jsing, minux): we can't free oldtcb without causing double-free
+       // problem. so newtcb will be memory leaks. Get rid of this when OpenBSD
+       // has proper support for PT_TLS.
 }
 
 static void *
index 1d54c9490722b356ebec2192aba4626a6fab8f65..f53236ae731d8f5fd851643abc8366e380bbc4f8 100755 (executable)
@@ -74,7 +74,6 @@ go run $GOROOT/test/run.go - .
 ) || exit $?
 
 [ "$CGO_ENABLED" != 1 ] ||
-[ "$GOHOSTOS" == openbsd ] || # issue 4878
 (xcd ../misc/cgo/test
 go test
 case "$GOHOSTOS-$GOARCH" in