diff options
author | Clément Chigot <clement.chigot@atos.net> | 2019-03-25 10:31:30 +0100 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2019-03-27 17:22:11 +0000 |
commit | 38dc177d3ac5b5a8cb6b7f9039144cbe8bd58036 (patch) | |
tree | e5fad95d9ef8d6a87ee631ac49a2ff7529a10fad /src/runtime/cgo | |
parent | 53c9c068115168ebcc1e649fa7a15a804a99d92f (diff) | |
download | go-38dc177d3ac5b5a8cb6b7f9039144cbe8bd58036.tar.gz go-38dc177d3ac5b5a8cb6b7f9039144cbe8bd58036.zip |
runtime: create library startup for aix/ppc64
As .init_array section aren't available on AIX, the Go runtime
initialization is made with gcc constructor attribute.
However, as cgo tool is building a binary in order to get imported
C symbols, Go symbols imported for this initilization must be ignored.
-Wl,-berok is mandatory otherwize ld will fail to create this binary,
_rt0_aix_ppc64_lib and runtime_rt0_go aren't defined in runtime/cgo.
These two symbols must also be ignored when creating _cgo_import.go.
Change-Id: Icf2e0282f5b50de5fa82007439a428e6147efef1
Reviewed-on: https://go-review.googlesource.com/c/go/+/169118
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/runtime/cgo')
-rw-r--r-- | src/runtime/cgo/callbacks_aix.go | 1 | ||||
-rw-r--r-- | src/runtime/cgo/cgo.go | 1 | ||||
-rw-r--r-- | src/runtime/cgo/gcc_aix_ppc64.c | 16 |
3 files changed, 18 insertions, 0 deletions
diff --git a/src/runtime/cgo/callbacks_aix.go b/src/runtime/cgo/callbacks_aix.go index 7dafb6b310..f4b6fe25fa 100644 --- a/src/runtime/cgo/callbacks_aix.go +++ b/src/runtime/cgo/callbacks_aix.go @@ -8,3 +8,4 @@ package cgo // longcall on cgo programs (cf gcc_aix_ppc64.c). //go:cgo_export_static __cgo_topofstack //go:cgo_export_static runtime.rt0_go +//go:cgo_export_static _rt0_ppc64_aix_lib diff --git a/src/runtime/cgo/cgo.go b/src/runtime/cgo/cgo.go index 241a821e4f..eb11c0e100 100644 --- a/src/runtime/cgo/cgo.go +++ b/src/runtime/cgo/cgo.go @@ -20,6 +20,7 @@ package cgo #cgo !android,linux LDFLAGS: -lpthread #cgo netbsd LDFLAGS: -lpthread #cgo openbsd LDFLAGS: -lpthread +#cgo aix LDFLAGS: -Wl,-berok #cgo CFLAGS: -Wall -Werror diff --git a/src/runtime/cgo/gcc_aix_ppc64.c b/src/runtime/cgo/gcc_aix_ppc64.c index d54c0ff32d..f4f50b89ce 100644 --- a/src/runtime/cgo/gcc_aix_ppc64.c +++ b/src/runtime/cgo/gcc_aix_ppc64.c @@ -12,6 +12,7 @@ */ extern int __attribute__((longcall)) __cgo_topofstack(void); extern int __attribute__((longcall)) runtime_rt0_go(int argc, char **argv); +extern void __attribute__((longcall)) _rt0_ppc64_aix_lib(void); int _cgo_topofstack(void) { return __cgo_topofstack(); @@ -20,3 +21,18 @@ int _cgo_topofstack(void) { int main(int argc, char **argv) { return runtime_rt0_go(argc, argv); } + +static void libinit(void) __attribute__ ((constructor)); + +/* + * libinit aims to replace .init_array section which isn't available on aix. + * Using __attribute__ ((constructor)) let gcc handles this instead of + * adding special code in cmd/link. + * However, it will be called for every Go programs which has cgo. + * Inside _rt0_ppc64_aix_lib(), runtime.isarchive is checked in order + * to know if this program is a c-archive or a simple cgo program. + * If it's not set, _rt0_ppc64_ax_lib() returns directly. + */ +static void libinit() { + _rt0_ppc64_aix_lib(); +} |