1
0
mirror of https://github.com/golang/go synced 2024-11-12 08:10:21 -07:00

runtime/cgo: move common symbol overrides into 6c-compiled code

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
This commit is contained in:
Russ Cox 2013-02-28 13:54:23 -08:00
parent 7ae41e8010
commit 5bffa3b88e
19 changed files with 27 additions and 36 deletions

View 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;

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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;

View 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;

View 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)

View 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)

View File

@ -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;