Text file src/runtime/cgo/gcc_aix_ppc64.c

     1  // Copyright 2019 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  /*
     6   * On AIX, call to _cgo_topofstack and Go main are forced to be a longcall.
     7   * Without it, ld might add trampolines in the middle of .text section
     8   * to reach these functions which are normally declared in runtime package.
     9   */
    10  extern int __attribute__((longcall)) __cgo_topofstack(void);
    11  extern int __attribute__((longcall)) runtime_rt0_go(int argc, char **argv);
    12  extern void __attribute__((longcall)) _rt0_ppc64_aix_lib(void);
    13  
    14  int _cgo_topofstack(void) {
    15  	return __cgo_topofstack();
    16  }
    17  
    18  int main(int argc, char **argv) {
    19  	return runtime_rt0_go(argc, argv);
    20  }
    21  
    22  static void libinit(void) __attribute__ ((constructor));
    23  
    24  /*
    25   * libinit aims to replace .init_array section which isn't available on aix.
    26   * Using __attribute__ ((constructor)) let gcc handles this instead of
    27   * adding special code in cmd/link.
    28   * However, it will be called for every Go programs which has cgo.
    29   * Inside _rt0_ppc64_aix_lib(), runtime.isarchive is checked in order
    30   * to know if this program is a c-archive or a simple cgo program.
    31   * If it's not set, _rt0_ppc64_ax_lib() returns directly.
    32   */
    33  static void libinit() {
    34  	_rt0_ppc64_aix_lib();
    35  }
    36  

View as plain text