]> Cypherpunks repositories - gostls13.git/commitdiff
runtime/cgo: move common symbol overrides into 6c-compiled code
authorRuss Cox <rsc@golang.org>
Thu, 28 Feb 2013 21:54:23 +0000 (13:54 -0800)
committerRuss Cox <rsc@golang.org>
Thu, 28 Feb 2013 21:54:23 +0000 (13:54 -0800)
There are some function pointers declared by 6c in
package runtime without initialization and then also
declared in package runtime/cgo with initialization,
so that if runtime/cgo is linked in, the function pointers
are non-nil, and otherwise they are nil. We depend on
this property for implementing non-essential cgo hooks
in package runtime.

The declarations in package runtime are 6c-compiled
and end up in .6 files. The declarations in package runtime/cgo
are gcc-compiled and end up in .o files. Since 6l links the .6
and .o files together, this all works.

However, when we switch to "external linking" mode,
6l will not see the .o files, and it would be up to the host linker
to resolve the two into a single initialized symbol.
Not all host linkers will do this (in particular OS X gcc will not).

To fix this, move the cgo declarations into 6c-compiled code,
so that they end up in .6 files, so that 6l gets them no matter what.

R=golang-dev
CC=golang-dev
https://golang.org/cl/7440045

19 files changed:
src/pkg/runtime/cgo/callbacks.c
src/pkg/runtime/cgo/gcc_darwin_386.c
src/pkg/runtime/cgo/gcc_darwin_amd64.c
src/pkg/runtime/cgo/gcc_freebsd_386.c
src/pkg/runtime/cgo/gcc_freebsd_amd64.c
src/pkg/runtime/cgo/gcc_freebsd_arm.c
src/pkg/runtime/cgo/gcc_linux_386.c
src/pkg/runtime/cgo/gcc_linux_amd64.c
src/pkg/runtime/cgo/gcc_linux_arm.c
src/pkg/runtime/cgo/gcc_netbsd_386.c
src/pkg/runtime/cgo/gcc_netbsd_amd64.c
src/pkg/runtime/cgo/gcc_netbsd_arm.c
src/pkg/runtime/cgo/gcc_openbsd_386.c
src/pkg/runtime/cgo/gcc_openbsd_amd64.c
src/pkg/runtime/cgo/gcc_setenv.c
src/pkg/runtime/cgo/gcc_util.c
src/pkg/runtime/cgo/gcc_windows_386.c
src/pkg/runtime/cgo/gcc_windows_amd64.c
src/pkg/runtime/cgo/setenv.c [new file with mode: 0644]

index cefd67de87dad808274c8958d988dd58ff27ebea..86de808fb11d0e7c17674310791b15cd52cc0544 100644 (file)
@@ -77,3 +77,19 @@ _cgo_panic(void *a, int32 n)
 {
        runtime·cgocallback((void(*)(void))_cgo_panic_internal, a, n);
 }
+
+#pragma cgo_static_import x_cgo_init
+extern void x_cgo_init(G*);
+void (*_cgo_init)(G*) = x_cgo_init;
+
+#pragma cgo_static_import x_cgo_malloc
+extern void x_cgo_malloc(void*);
+void (*_cgo_malloc)(void*) = x_cgo_malloc;
+
+#pragma cgo_static_import x_cgo_free
+extern void x_cgo_free(void*);
+void (*_cgo_free)(void*) = x_cgo_free;
+
+#pragma cgo_static_import x_cgo_thread_start
+extern void x_cgo_thread_start(void*);
+void (*_cgo_thread_start)(void*) = x_cgo_thread_start;
index fd4d7a63a998f8b0839c712cc2c2e3945f301e45..ad9fb5abf64e74bcd407be5c5d4fa73b846c8fe7 100644 (file)
@@ -115,7 +115,6 @@ x_cgo_init(G *g)
        inittls();
 }
 
-void (*_cgo_init)(G*) = x_cgo_init;
 
 void
 _cgo_sys_thread_start(ThreadStart *ts)
index c3519360a44b3a6189cab6bdb5f2c312f424b441..65d381633db8e0e37a31b6264f35cc7a97dd7e17 100644 (file)
@@ -85,7 +85,6 @@ x_cgo_init(G *g)
        inittls();
 }
 
-void (*_cgo_init)(G*) = x_cgo_init;
 
 void
 _cgo_sys_thread_start(ThreadStart *ts)
index f22d47b591e778b68202f0afe425d2006b1ca86d..7c62a1bc49bf136c0bd9bb3e2ae06b2b3664e27e 100644 (file)
@@ -23,7 +23,6 @@ x_cgo_init(G *g)
        pthread_attr_destroy(&attr);
 }
 
-void (*_cgo_init)(G*) = x_cgo_init;
 
 void
 _cgo_sys_thread_start(ThreadStart *ts)
index 27023c3a5ed33606977dc5e9f1b1996654002cb1..6be8bd251ab202ad76b6c88ccf67b9efc24f1e8d 100644 (file)
@@ -23,7 +23,6 @@ x_cgo_init(G *g)
        pthread_attr_destroy(&attr);
 }
 
-void (*_cgo_init)(G*) = x_cgo_init;
 
 void
 _cgo_sys_thread_start(ThreadStart *ts)
index 9052b630738db36590a8b0d3372cb101ea56377d..3bcb0b270119d56b0cb700e65faedffd864d6055 100644 (file)
@@ -55,10 +55,6 @@ x_cgo_save_gm(void)
        );
 }
 
-// both cgo_tls_{get,set}_gm can be called from runtime
-void (*_cgo_load_gm)(void) = x_cgo_load_gm;
-void (*_cgo_save_gm)(void) = x_cgo_save_gm;
-
 void
 x_cgo_init(G *g)
 {
@@ -72,7 +68,6 @@ x_cgo_init(G *g)
        pthread_attr_destroy(&attr);
 }
 
-void (*_cgo_init)(G*) = x_cgo_init;
 
 void
 _cgo_sys_thread_start(ThreadStart *ts)
index 0cac96f81f7c5f0af6e1bf9dd743deedb4af415f..9357a63f718b8481f29868e9bac7435f1b4f8135 100644 (file)
@@ -21,7 +21,6 @@ x_cgo_init(G *g)
        pthread_attr_destroy(&attr);
 }
 
-void (*_cgo_init)(G*) = x_cgo_init;
 
 void
 _cgo_sys_thread_start(ThreadStart *ts)
index 10981d62c51a457855bdc02251778af33bc953a4..bc76117d355de5070f50bfa8e475e6d3a73b8881 100644 (file)
@@ -21,7 +21,6 @@ x_cgo_init(G* g)
        pthread_attr_destroy(&attr);
 }
 
-void (*_cgo_init)(G*) = x_cgo_init;
 
 void
 _cgo_sys_thread_start(ThreadStart *ts)
index 93004ddcbcfa7c25412fc843ef9d850d246ebbad..46a1126ad35717c062c7c59dff9849c391f64a86 100644 (file)
@@ -55,10 +55,6 @@ x_cgo_save_gm(void)
        );
 }
 
-// both cgo_tls_{get,set}_gm can be called from runtime
-void (*_cgo_load_gm)(void) = x_cgo_load_gm;
-void (*_cgo_save_gm)(void) = x_cgo_save_gm;
-
 void
 x_cgo_init(G *g)
 {
@@ -72,7 +68,6 @@ x_cgo_init(G *g)
        pthread_attr_destroy(&attr);
 }
 
-void (*_cgo_init)(G*) = x_cgo_init;
 
 void
 _cgo_sys_thread_start(ThreadStart *ts)
index 1232541547235d300fb07cb8ad1be31ff3144a99..09b271df4fdefef6f2d1d2350bc1423eaf1f0840 100644 (file)
@@ -22,7 +22,6 @@ x_cgo_init(G *g)
        pthread_attr_destroy(&attr);
 }
 
-void (*_cgo_init)(G*) = x_cgo_init;
 
 void
 _cgo_sys_thread_start(ThreadStart *ts)
index bc2e2b9c66d40cd11a54ce94f07b1ef5f1b8c8f5..080c59ba499a82e95dc47c53574f8552d2774237 100644 (file)
@@ -22,7 +22,6 @@ x_cgo_init(G *g)
        pthread_attr_destroy(&attr);
 }
 
-void (*_cgo_init)(G*) = x_cgo_init;
 
 void
 _cgo_sys_thread_start(ThreadStart *ts)
index 1b9ba39361b7ab487b5fb198066525e36890e1fd..d93b531e7b1e81b793b8223f8491cae1341ef3b8 100644 (file)
@@ -61,10 +61,6 @@ x_cgo_save_gm(void)
        );
 }
 
-// both cgo_tls_{get,set}_gm can be called from runtime
-void (*_cgo_load_gm)(void) = x_cgo_load_gm;
-void (*_cgo_save_gm)(void) = x_cgo_save_gm;
-
 void
 x_cgo_init(G *g)
 {
@@ -78,7 +74,6 @@ x_cgo_init(G *g)
        pthread_attr_destroy(&attr);
 }
 
-void (*_cgo_init)(G*) = x_cgo_init;
 
 void
 _cgo_sys_thread_start(ThreadStart *ts)
index c0b90cce6991cc9b11f0f63c2466e6586764ee44..86c1365adc5c6c41f883f5d1a248f728cac9ebfb 100644 (file)
@@ -109,7 +109,6 @@ x_cgo_init(G *g)
        tcb_fixup(1);
 }
 
-void (*_cgo_init)(G*) = x_cgo_init;
 
 void
 _cgo_sys_thread_start(ThreadStart *ts)
index 3984480dfa80811a908d94140d4f9f84dace2bcb..d3a5e36b03fd25d026e9f3d4961adba3b0e62859 100644 (file)
@@ -109,7 +109,6 @@ x_cgo_init(G *g)
        tcb_fixup(1);
 }
 
-void (*_cgo_init)(G*) = x_cgo_init;
 
 void
 _cgo_sys_thread_start(ThreadStart *ts)
index c99853a0ffa452c55653f4577a06b7d88fd84973..a0938166d1ec3e8204b7e03cabf88a2a89988614 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright 20111 The Go Authors.  All rights reserved.
+// Copyright 2011 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.
 
@@ -14,5 +14,3 @@ x_cgo_setenv(char **arg)
 {
        setenv(arg[0], arg[1], 1);
 }
-
-void (*_cgo_setenv)(char**) = x_cgo_setenv;
index 0e289166fccdffc38eb2b66bad2d1622f7d53d47..20913d7369ca37505664ba990b97b504f7015e3a 100644 (file)
@@ -16,8 +16,6 @@ x_cgo_malloc(void *p)
        a->ret = malloc(a->n);
 }
 
-void (*_cgo_malloc)(void*) = x_cgo_malloc;
-
 /* Stub for calling free from Go */
 void
 x_cgo_free(void *p)
@@ -29,8 +27,6 @@ x_cgo_free(void *p)
        free(a->arg);
 }
 
-void (*_cgo_free)(void*) = x_cgo_free;
-
 /* Stub for creating a new thread */
 void
 x_cgo_thread_start(ThreadStart *arg)
@@ -47,5 +43,3 @@ x_cgo_thread_start(ThreadStart *arg)
 
        _cgo_sys_thread_start(ts);      /* OS-dependent half */
 }
-
-void (*_cgo_thread_start)(ThreadStart*) = x_cgo_thread_start;
index 5e9d4a94d556fb7bfa38ae3e842efeb50f5e6cef..02eab12e591d54c0af0602c6001e592f2476d9e0 100644 (file)
@@ -21,7 +21,6 @@ x_cgo_init(G *g)
        g->stackguard = (uintptr)&tmp - STACKSIZE + 8*1024;
 }
 
-void (*_cgo_init)(G*) = x_cgo_init;
 
 void
 _cgo_sys_thread_start(ThreadStart *ts)
index 386e5bbe3aa94fd702e58940c30b21437048f647..f7695a1cc2e8e64d90b64c95afc61da0771a4816 100644 (file)
@@ -21,7 +21,6 @@ x_cgo_init(G *g)
        g->stackguard = (uintptr)&tmp - STACKSIZE + 8*1024;
 }
 
-void (*_cgo_init)(G*) = x_cgo_init;
 
 void
 _cgo_sys_thread_start(ThreadStart *ts)
diff --git a/src/pkg/runtime/cgo/setenv.c b/src/pkg/runtime/cgo/setenv.c
new file mode 100644 (file)
index 0000000..4c47cdb
--- /dev/null
@@ -0,0 +1,10 @@
+// Copyright 2011 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.
+
+// +build darwin freebsd linux netbsd openbsd
+
+#pragma cgo_import_static x_cgo_setenv
+
+void x_cgo_setenv(char**);
+void (*_cgo_setenv)(char**) = x_cgo_setenv;