From fe9e1702687db062ad2f13939177e1c5f68c8e05 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Wed, 10 Jan 2018 05:12:39 +0000 Subject: [PATCH] cmd/go: add AIX support For gccgo code avoid --whole-archive and -(. Use -blibpath instead of -rpath. Reviewed-on: https://go-review.googlesource.com/86956 From-SVN: r256417 --- gcc/go/gofrontend/MERGE | 2 +- libgo/go/cmd/go/internal/work/gccgo.go | 30 ++++++++++++++++++++------ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index 92d8b94b660..f43c1daafe5 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -1,4 +1,4 @@ -98b0942497bf2896127b71d851a79959ed3197cf +8e20ba6b6c4906f2f0be4b0a1515d11e0f41fb29 The first line of this file holds the git revision number of the last merge done from the gofrontend repository. diff --git a/libgo/go/cmd/go/internal/work/gccgo.go b/libgo/go/cmd/go/internal/work/gccgo.go index 9e42842e3f7..dcb38af2ed2 100644 --- a/libgo/go/cmd/go/internal/work/gccgo.go +++ b/libgo/go/cmd/go/internal/work/gccgo.go @@ -375,9 +375,15 @@ func (tools gccgoToolchain) link(b *Builder, root *Action, out, importcfg string } } - ldflags = append(ldflags, "-Wl,--whole-archive") + wholeArchive := []string{"-Wl,--whole-archive"} + noWholeArchive := []string{"-Wl,--no-whole-archive"} + if cfg.Goos == "aix" { + wholeArchive = nil + noWholeArchive = nil + } + ldflags = append(ldflags, wholeArchive...) ldflags = append(ldflags, afiles...) - ldflags = append(ldflags, "-Wl,--no-whole-archive") + ldflags = append(ldflags, noWholeArchive...) ldflags = append(ldflags, cgoldflags...) ldflags = append(ldflags, envList("CGO_LDFLAGS", "")...) @@ -385,7 +391,9 @@ func (tools gccgoToolchain) link(b *Builder, root *Action, out, importcfg string ldflags = append(ldflags, root.Package.CgoLDFLAGS...) } - ldflags = str.StringList("-Wl,-(", ldflags, "-Wl,-)") + if cfg.Goos != "aix" { + ldflags = str.StringList("-Wl,-(", ldflags, "-Wl,-)") + } if root.buildID != "" { // On systems that normally use gold or the GNU linker, @@ -396,17 +404,24 @@ func (tools gccgoToolchain) link(b *Builder, root *Action, out, importcfg string } } + var rLibPath string + if cfg.Goos == "aix" { + rLibPath = "-Wl,-blibpath=" + } else { + rLibPath = "-Wl,-rpath=" + } for _, shlib := range shlibs { ldflags = append( ldflags, "-L"+filepath.Dir(shlib), - "-Wl,-rpath="+filepath.Dir(shlib), + rLibPath+filepath.Dir(shlib), "-l"+strings.TrimSuffix( strings.TrimPrefix(filepath.Base(shlib), "lib"), ".so")) } var realOut string + goLibBegin := str.StringList(wholeArchive, "-lgolibbegin", noWholeArchive) switch buildmode { case "exe": if usesCgo && cfg.Goos == "linux" { @@ -428,7 +443,8 @@ func (tools gccgoToolchain) link(b *Builder, root *Action, out, importcfg string // split-stack and non-split-stack code in a single -r // link, and libgo picks up non-split-stack code from // libffi. - ldflags = append(ldflags, "-Wl,-r", "-nostdlib", "-Wl,--whole-archive", "-lgolibbegin", "-Wl,--no-whole-archive") + ldflags = append(ldflags, "-Wl,-r", "-nostdlib") + ldflags = append(ldflags, goLibBegin...) if nopie := b.gccNoPie([]string{tools.linker()}); nopie != "" { ldflags = append(ldflags, nopie) @@ -443,7 +459,9 @@ func (tools gccgoToolchain) link(b *Builder, root *Action, out, importcfg string out = out + ".o" case "c-shared": - ldflags = append(ldflags, "-shared", "-nostdlib", "-Wl,--whole-archive", "-lgolibbegin", "-Wl,--no-whole-archive", "-lgo", "-lgcc_s", "-lgcc", "-lc", "-lgcc") + ldflags = append(ldflags, "-shared", "-nostdlib") + ldflags = append(ldflags, goLibBegin...) + ldflags = append(ldflags, "-lgo", "-lgcc_s", "-lgcc", "-lc", "-lgcc") case "shared": ldflags = append(ldflags, "-zdefs", "-shared", "-nostdlib", "-lgo", "-lgcc_s", "-lgcc", "-lc")