Skip to content

Commit 55ca6d3

Browse files
MatthieuSarterianlancetaylor
authored andcommitted
libmain: ensure initfn is called when loading a go library
AIX does not support .init_array. The alterative is to export the __go_init function and tell the linker it is an init function with the -Wl,-binitfini:__go_init option. Issue golang/go#19200 Change-Id: I4ef52a17e646f80bd37d141483ec3086c87fcf30 Reviewed-on: https://go-review.googlesource.com/37965 Reviewed-by: Ian Lance Taylor <iant@golang.org>
1 parent 29b190f commit 55ca6d3

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

libgo/runtime/go-libmain.c

+11-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@
2424
and calls exported Go functions as needed. */
2525

2626
static void die (const char *, int);
27-
static void initfn (int, char **, char **);
27+
/* .init_array section does not exist in AIX XCOFF.
28+
-Wl,-binitfini:__go_init option will be required to build go
29+
libraries and make sure __go_init is called when the library is
30+
loaded. This requires __go_init to be exported. */
31+
32+
void __go_init (int, char **, char **);
2833
static void *gostart (void *);
2934

3035
/* Used to pass arguments to the thread that runs the Go startup. */
@@ -34,6 +39,7 @@ struct args {
3439
char **argv;
3540
};
3641

42+
#ifndef _AIX
3743
/* We use .init_array so that we can get the command line arguments.
3844
This obviously assumes .init_array support; different systems may
3945
require other approaches. */
@@ -42,16 +48,17 @@ typedef void (*initarrayfn) (int, char **, char **);
4248

4349
static initarrayfn initarray[1]
4450
__attribute__ ((section (".init_array"), used)) =
45-
{ initfn };
51+
{ __go_init };
52+
#endif
4653

4754
/* This function is called at program startup time. It starts a new
4855
thread to do the actual Go startup, so that program startup is not
4956
paused waiting for the Go initialization functions. Exported cgo
5057
functions will wait for initialization to complete if
5158
necessary. */
5259

53-
static void
54-
initfn (int argc, char **argv, char** env __attribute__ ((unused)))
60+
void
61+
__go_init (int argc, char **argv, char** env __attribute__ ((unused)))
5562
{
5663
int err;
5764
pthread_attr_t attr;

0 commit comments

Comments
 (0)