github.com/mdempsky/go@v0.0.0-20151201204031-5dd372bd1e70/misc/cgo/test/issue1635.go (about)

     1  // Copyright 2012 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  package cgotest
     6  
     7  /*
     8  // Mac OS X's gcc will generate scattered relocation 2/1 for
     9  // this function on Darwin/386, and 8l couldn't handle it.
    10  // this example is in issue 1635
    11  #include <stdio.h>
    12  void scatter() {
    13  	void *p = scatter;
    14  	printf("scatter = %p\n", p);
    15  }
    16  
    17  // Adding this explicit extern declaration makes this a test for
    18  // https://gcc.gnu.org/PR68072 aka https://golang.org/issue/13344 .
    19  // It used to cause a cgo error when building with GCC 6.
    20  extern int hola;
    21  
    22  // this example is in issue 3253
    23  int hola = 0;
    24  int testHola() { return hola; }
    25  */
    26  import "C"
    27  
    28  import "testing"
    29  
    30  func test1635(t *testing.T) {
    31  	C.scatter()
    32  	if v := C.hola; v != 0 {
    33  		t.Fatalf("C.hola is %d, should be 0", v)
    34  	}
    35  	if v := C.testHola(); v != 0 {
    36  		t.Fatalf("C.testHola() is %d, should be 0", v)
    37  	}
    38  }