Commit fe9e1702 by Ian Lance Taylor

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
parent 76e723a3
98b0942497bf2896127b71d851a79959ed3197cf 8e20ba6b6c4906f2f0be4b0a1515d11e0f41fb29
The first line of this file holds the git revision number of the last The first line of this file holds the git revision number of the last
merge done from the gofrontend repository. merge done from the gofrontend repository.
...@@ -375,9 +375,15 @@ func (tools gccgoToolchain) link(b *Builder, root *Action, out, importcfg string ...@@ -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, afiles...)
ldflags = append(ldflags, "-Wl,--no-whole-archive") ldflags = append(ldflags, noWholeArchive...)
ldflags = append(ldflags, cgoldflags...) ldflags = append(ldflags, cgoldflags...)
ldflags = append(ldflags, envList("CGO_LDFLAGS", "")...) ldflags = append(ldflags, envList("CGO_LDFLAGS", "")...)
...@@ -385,7 +391,9 @@ func (tools gccgoToolchain) link(b *Builder, root *Action, out, importcfg string ...@@ -385,7 +391,9 @@ func (tools gccgoToolchain) link(b *Builder, root *Action, out, importcfg string
ldflags = append(ldflags, root.Package.CgoLDFLAGS...) 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 != "" { if root.buildID != "" {
// On systems that normally use gold or the GNU linker, // 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 ...@@ -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 { for _, shlib := range shlibs {
ldflags = append( ldflags = append(
ldflags, ldflags,
"-L"+filepath.Dir(shlib), "-L"+filepath.Dir(shlib),
"-Wl,-rpath="+filepath.Dir(shlib), rLibPath+filepath.Dir(shlib),
"-l"+strings.TrimSuffix( "-l"+strings.TrimSuffix(
strings.TrimPrefix(filepath.Base(shlib), "lib"), strings.TrimPrefix(filepath.Base(shlib), "lib"),
".so")) ".so"))
} }
var realOut string var realOut string
goLibBegin := str.StringList(wholeArchive, "-lgolibbegin", noWholeArchive)
switch buildmode { switch buildmode {
case "exe": case "exe":
if usesCgo && cfg.Goos == "linux" { if usesCgo && cfg.Goos == "linux" {
...@@ -428,7 +443,8 @@ func (tools gccgoToolchain) link(b *Builder, root *Action, out, importcfg string ...@@ -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 // split-stack and non-split-stack code in a single -r
// link, and libgo picks up non-split-stack code from // link, and libgo picks up non-split-stack code from
// libffi. // 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 != "" { if nopie := b.gccNoPie([]string{tools.linker()}); nopie != "" {
ldflags = append(ldflags, nopie) ldflags = append(ldflags, nopie)
...@@ -443,7 +459,9 @@ func (tools gccgoToolchain) link(b *Builder, root *Action, out, importcfg string ...@@ -443,7 +459,9 @@ func (tools gccgoToolchain) link(b *Builder, root *Action, out, importcfg string
out = out + ".o" out = out + ".o"
case "c-shared": 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": case "shared":
ldflags = append(ldflags, "-zdefs", "-shared", "-nostdlib", "-lgo", "-lgcc_s", "-lgcc", "-lc") ldflags = append(ldflags, "-zdefs", "-shared", "-nostdlib", "-lgo", "-lgcc_s", "-lgcc", "-lc")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment