]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: pass -X64 to ar on aix/ppc64
authorClément Chigot <clement.chigot@atos.net>
Thu, 28 Feb 2019 08:55:27 +0000 (09:55 +0100)
committerIan Lance Taylor <iant@golang.org>
Tue, 5 Mar 2019 02:09:48 +0000 (02:09 +0000)
On aix/ppc64, ar tool must always have -X64 argument if it aims to
create 64 bits archives.

This commit also adds the -D flag handler when calling ar with
gccgotoolchain, to match gccgo version.

Change-Id: I1f5750f8f64a7073780d283567f0b60fc7fa5b97
Reviewed-on: https://go-review.googlesource.com/c/go/+/164417
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/go/internal/work/gccgo.go

index 053d32dc0b8cb4cb03b6d848431ce2af545cacd5..0ba690fd62caf7d3710c621139c6defe13367dc9 100644 (file)
@@ -203,11 +203,14 @@ func (tools gccgoToolchain) pack(b *Builder, a *Action, afile string, ofiles []s
        if cfg.Goos == "aix" && cfg.Goarch == "ppc64" {
                // AIX puts both 32-bit and 64-bit objects in the same archive.
                // Tell the AIX "ar" command to only care about 64-bit objects.
-               // AIX "ar" command does not know D option.
                arArgs = []string{"-X64"}
        }
-
-       return b.run(a, p.Dir, p.ImportPath, nil, tools.ar(), arArgs, "rc", mkAbs(objdir, afile), absOfiles)
+       absAfile := mkAbs(objdir, afile)
+       // Try with D modifier first, then without if that fails.
+       if b.run(a, p.Dir, p.ImportPath, nil, tools.ar(), arArgs, "rcD", absAfile, absOfiles) != nil {
+               return b.run(a, p.Dir, p.ImportPath, nil, tools.ar(), arArgs, "rc", absAfile, absOfiles)
+       }
+       return nil
 }
 
 func (tools gccgoToolchain) link(b *Builder, root *Action, out, importcfg string, allactions []*Action, buildmode, desc string) error {
@@ -249,6 +252,13 @@ func (tools gccgoToolchain) link(b *Builder, root *Action, out, importcfg string
                return nil
        }
 
+       var arArgs []string
+       if cfg.Goos == "aix" && cfg.Goarch == "ppc64" {
+               // AIX puts both 32-bit and 64-bit objects in the same archive.
+               // Tell the AIX "ar" command to only care about 64-bit objects.
+               arArgs = []string{"-X64"}
+       }
+
        newID := 0
        readAndRemoveCgoFlags := func(archive string) (string, error) {
                newID++
@@ -266,11 +276,11 @@ func (tools gccgoToolchain) link(b *Builder, root *Action, out, importcfg string
                                return "", nil
                        }
                }
-               err := b.run(root, root.Objdir, desc, nil, tools.ar(), "x", newArchive, "_cgo_flags")
+               err := b.run(root, root.Objdir, desc, nil, tools.ar(), arArgs, "x", newArchive, "_cgo_flags")
                if err != nil {
                        return "", err
                }
-               err = b.run(root, ".", desc, nil, tools.ar(), "d", newArchive, "_cgo_flags")
+               err = b.run(root, ".", desc, nil, tools.ar(), arArgs, "d", newArchive, "_cgo_flags")
                if err != nil {
                        return "", err
                }
@@ -487,7 +497,7 @@ func (tools gccgoToolchain) link(b *Builder, root *Action, out, importcfg string
 
        switch buildmode {
        case "c-archive":
-               if err := b.run(root, ".", desc, nil, tools.ar(), "rc", realOut, out); err != nil {
+               if err := b.run(root, ".", desc, nil, tools.ar(), arArgs, "rc", realOut, out); err != nil {
                        return err
                }
        }