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  // +build aix
     6  // +build ppc64 ppc64le
     7  
     8  /*
     9   * On AIX, call to _cgo_topofstack and Go main are forced to be a longcall.
    10   * Without it, ld might add trampolines in the middle of .text section
    11   * to reach these functions which are normally declared in runtime package.
    12   */
    13  extern int __attribute__((longcall)) __cgo_topofstack(void);
    14  extern int __attribute__((longcall)) runtime_rt0_go(int argc, char **argv);
    15  extern void __attribute__((longcall)) _rt0_ppc64_aix_lib(void);
    16  
    17  int _cgo_topofstack(void) {
    18  	return __cgo_topofstack();
    19  }
    20  
    21  int main(int argc, char **argv) {
    22  	return runtime_rt0_go(argc, argv);
    23  }
    24  
    25  static void libinit(void) __attribute__ ((constructor));
    26  
    27  /*
    28   * libinit aims to replace .init_array section which isn't available on aix.
    29   * Using __attribute__ ((constructor)) let gcc handles this instead of
    30   * adding special code in cmd/link.
    31   * However, it will be called for every Go programs which has cgo.
    32   * Inside _rt0_ppc64_aix_lib(), runtime.isarchive is checked in order
    33   * to know if this program is a c-archive or a simple cgo program.
    34   * If it's not set, _rt0_ppc64_ax_lib() returns directly.
    35   */
    36  static void libinit() {
    37  	_rt0_ppc64_aix_lib();
    38  }
    39  

View as plain text