]> Cypherpunks repositories - gostls13.git/commitdiff
misc/cgo: enable testso and testsovar on aix/ppc64
authorClément Chigot <clement.chigot@atos.net>
Tue, 26 Mar 2019 14:00:00 +0000 (15:00 +0100)
committerIan Lance Taylor <iant@golang.org>
Wed, 27 Mar 2019 17:21:28 +0000 (17:21 +0000)
On AIX, shared objects must be wrapped under an archive file.

For testso, creating libcgosotest with an extern symbol isn't
AIX-friendly. By default, ld will block such behavior. Rather than
forcing ld to work as on Linux and using the run-time linking,
goCallback became a function pointer which is set by setCallback().

Updates #30565

Change-Id: I455ab32faddd41f1b0c84cc9e503788044ad49b2
Reviewed-on: https://go-review.googlesource.com/c/go/+/169020
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
misc/cgo/testso/so_test.go
misc/cgo/testso/testdata/cgoso.c
misc/cgo/testso/testdata/cgoso.go
misc/cgo/testso/testdata/cgoso_c.c
misc/cgo/testso/testdata/cgoso_unix.go
misc/cgo/testsovar/so_test.go
misc/cgo/testsovar/testdata/cgoso.go

index 68388caa90375f00cdc30688c4f4c05ab2a89159..9c7f2724390080226bedddc2403cb2e4146a43f1 100644 (file)
@@ -28,9 +28,6 @@ func requireTestSOSupported(t *testing.T) {
                if runtime.GOOS == "linux" {
                        t.Skip("External linking not implemented on aix/ppc64 (issue #8912).")
                }
-               if runtime.GOOS == "aix" {
-                       t.Skip("Using shared object isn't yet available on aix/ppc64 (issue #30565)")
-               }
        case "mips64le", "mips64":
                t.Skip("External linking not implemented on mips64.")
        }
@@ -85,6 +82,8 @@ func TestSO(t *testing.T) {
        case "windows":
                ext = "dll"
                args = append(args, "-DEXPORT_DLL")
+       case "aix":
+               ext = "so.1"
        }
        sofname := "libcgosotest." + ext
        args = append(args, "-o", sofname, "cgoso_c.c")
@@ -98,6 +97,16 @@ func TestSO(t *testing.T) {
        }
        t.Logf("%s:\n%s", strings.Join(cmd.Args, " "), out)
 
+       if runtime.GOOS == "aix" {
+               // Shared object must be wrapped by an archive
+               cmd = exec.Command("ar", "-X64", "-q", "libcgosotest.a", "libcgosotest.so.1")
+               cmd.Dir = modRoot
+               out, err = cmd.CombinedOutput()
+               if err != nil {
+                       t.Fatalf("%s: %s\n%s", strings.Join(cmd.Args, " "), err, out)
+               }
+       }
+
        cmd = exec.Command("go", "build", "-o", "main.exe", "main.go")
        cmd.Dir = modRoot
        cmd.Env = append(os.Environ(), "GOPATH="+GOPATH)
index 917f472d3684bc9f7bd90ea0ab28150027291161..612e5d335a9809b68c90ac6ec8c54e6e9c6bee48 100644 (file)
@@ -4,7 +4,7 @@
 
 #include "_cgo_export.h"
 
-#ifdef WIN32
+#if defined(WIN32) || defined(_AIX)
 extern void setCallback(void *);
 void init() {
        setCallback(goCallback);
index 29814fa43aeafe3f0250ef216b2301c29359735a..bba5de331212f2506e630e5c484cc1cc0aa905fc 100644 (file)
@@ -15,6 +15,7 @@ package cgosotest
 #cgo netbsd LDFLAGS: -L. libcgosotest.so
 #cgo darwin LDFLAGS: -L. libcgosotest.dylib
 #cgo windows LDFLAGS: -L. libcgosotest.dll
+#cgo aix LDFLAGS: -L. -l cgosotest
 
 void init(void);
 void sofunc(void);
index 7a38022b54736e1c51b48d36b48323c4ea6ecd2a..e5015ed5e8ce414730d7b86357eb005c9859f391 100644 (file)
@@ -14,6 +14,15 @@ __declspec(dllexport) void setCallback(void *f)
        goCallback = (void (*)())f;
 }
 __declspec(dllexport) void sofunc(void);
+#elif defined(_AIX)
+// AIX doesn't allow the creation of a shared object with an
+// undefined symbol. It's possible to bypass this problem by
+// using -Wl,-G and -Wl,-brtl option which allows run-time linking.
+// However, that's not how most of AIX shared object works.
+// Therefore, it's better to consider goCallback as a pointer and
+// to set up during an init function.
+void (*goCallback)(void);
+void setCallback(void *f) { goCallback = f; }
 #else
 extern void goCallback(void);
 void setCallback(void *f) { (void)f; }
index 49cdeaa2f59d899fe11f1a7efcec1cbb9d9839fd..1860694f1ed4ed42c120062edfdfd1ad885ae33c 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build dragonfly freebsd linux netbsd solaris
+// +build aix dragonfly freebsd linux netbsd solaris
 
 package cgosotest
 
index 68388caa90375f00cdc30688c4f4c05ab2a89159..9c7f2724390080226bedddc2403cb2e4146a43f1 100644 (file)
@@ -28,9 +28,6 @@ func requireTestSOSupported(t *testing.T) {
                if runtime.GOOS == "linux" {
                        t.Skip("External linking not implemented on aix/ppc64 (issue #8912).")
                }
-               if runtime.GOOS == "aix" {
-                       t.Skip("Using shared object isn't yet available on aix/ppc64 (issue #30565)")
-               }
        case "mips64le", "mips64":
                t.Skip("External linking not implemented on mips64.")
        }
@@ -85,6 +82,8 @@ func TestSO(t *testing.T) {
        case "windows":
                ext = "dll"
                args = append(args, "-DEXPORT_DLL")
+       case "aix":
+               ext = "so.1"
        }
        sofname := "libcgosotest." + ext
        args = append(args, "-o", sofname, "cgoso_c.c")
@@ -98,6 +97,16 @@ func TestSO(t *testing.T) {
        }
        t.Logf("%s:\n%s", strings.Join(cmd.Args, " "), out)
 
+       if runtime.GOOS == "aix" {
+               // Shared object must be wrapped by an archive
+               cmd = exec.Command("ar", "-X64", "-q", "libcgosotest.a", "libcgosotest.so.1")
+               cmd.Dir = modRoot
+               out, err = cmd.CombinedOutput()
+               if err != nil {
+                       t.Fatalf("%s: %s\n%s", strings.Join(cmd.Args, " "), err, out)
+               }
+       }
+
        cmd = exec.Command("go", "build", "-o", "main.exe", "main.go")
        cmd.Dir = modRoot
        cmd.Env = append(os.Environ(), "GOPATH="+GOPATH)
index 88d44c2c6ee29b1a3e7de66fc29dcc636609bc4b..9c7f95e92ea454e68ff238aa6bf18ee2732e3a94 100644 (file)
@@ -19,6 +19,7 @@ package cgosotest
 #cgo netbsd LDFLAGS: -L. libcgosotest.so
 #cgo darwin LDFLAGS: -L. libcgosotest.dylib
 #cgo windows LDFLAGS: -L. libcgosotest.dll
+#cgo aix LDFLAGS: -L. -l cgosotest
 
 #include "cgoso_c.h"