Commit 1a7ad6ad by Ian Lance Taylor

cmd/go: fix -buildmode={c-archive,c-shared,pie} for gccgo

    
    The tests are misc/cgo tests that are not currently run but will be
    run soon.
    
    Reviewed-on: https://go-review.googlesource.com/47037

From-SVN: r249794
parent 14836f38
66d14d95a5a453682fe387319c80bc4fc40d96ad 8c4d6fd19f6d5dc9b41be384c60507f2236f05ec
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.
...@@ -342,16 +342,20 @@ func buildModeInit() { ...@@ -342,16 +342,20 @@ func buildModeInit() {
} }
return p return p
} }
switch platform { if gccgo {
case "darwin/arm", "darwin/arm64": codegenArg = "-fPIC"
codegenArg = "-shared" } else {
default: switch platform {
switch goos { case "darwin/arm", "darwin/arm64":
case "dragonfly", "freebsd", "linux", "netbsd", "openbsd", "solaris":
// Use -shared so that the result is
// suitable for inclusion in a PIE or
// shared library.
codegenArg = "-shared" codegenArg = "-shared"
default:
switch goos {
case "dragonfly", "freebsd", "linux", "netbsd", "openbsd", "solaris":
// Use -shared so that the result is
// suitable for inclusion in a PIE or
// shared library.
codegenArg = "-shared"
}
} }
} }
exeSuffix = ".a" exeSuffix = ".a"
...@@ -374,10 +378,14 @@ func buildModeInit() { ...@@ -374,10 +378,14 @@ func buildModeInit() {
case "default": case "default":
switch platform { switch platform {
case "android/arm", "android/arm64", "android/amd64", "android/386": case "android/arm", "android/arm64", "android/amd64", "android/386":
codegenArg = "-shared" if !gccgo {
codegenArg = "-shared"
}
ldBuildmode = "pie" ldBuildmode = "pie"
case "darwin/arm", "darwin/arm64": case "darwin/arm", "darwin/arm64":
codegenArg = "-shared" if !gccgo {
codegenArg = "-shared"
}
fallthrough fallthrough
default: default:
ldBuildmode = "exe" ldBuildmode = "exe"
...@@ -387,7 +395,7 @@ func buildModeInit() { ...@@ -387,7 +395,7 @@ func buildModeInit() {
ldBuildmode = "exe" ldBuildmode = "exe"
case "pie": case "pie":
if gccgo { if gccgo {
fatalf("-buildmode=pie not supported by gccgo") codegenArg = "-fPIE"
} else { } else {
switch platform { switch platform {
case "linux/386", "linux/amd64", "linux/arm", "linux/arm64", "linux/ppc64le", "linux/s390x", case "linux/386", "linux/amd64", "linux/arm", "linux/arm64", "linux/ppc64le", "linux/s390x",
...@@ -1053,7 +1061,7 @@ func (b *builder) action1(mode buildMode, depMode buildMode, p *Package, looksha ...@@ -1053,7 +1061,7 @@ func (b *builder) action1(mode buildMode, depMode buildMode, p *Package, looksha
// Install header for cgo in c-archive and c-shared modes. // Install header for cgo in c-archive and c-shared modes.
if p.usesCgo() && (buildBuildmode == "c-archive" || buildBuildmode == "c-shared") { if p.usesCgo() && (buildBuildmode == "c-archive" || buildBuildmode == "c-shared") {
hdrTarget := a.target[:len(a.target)-len(filepath.Ext(a.target))] + ".h" hdrTarget := a.target[:len(a.target)-len(filepath.Ext(a.target))] + ".h"
if buildContext.Compiler == "gccgo" { if buildContext.Compiler == "gccgo" && *buildO == "" {
// For the header file, remove the "lib" // For the header file, remove the "lib"
// added by go/build, so we generate pkg.h // added by go/build, so we generate pkg.h
// rather than libpkg.h. // rather than libpkg.h.
...@@ -3025,6 +3033,8 @@ func (tools gccgoToolchain) link(b *builder, root *action, out string, allaction ...@@ -3025,6 +3033,8 @@ func (tools gccgoToolchain) link(b *builder, root *action, out string, allaction
ldflags = append(ldflags, "-shared", "-nostdlib", "-Wl,--whole-archive", "-lgolibbegin", "-Wl,--no-whole-archive", "-lgo", "-lgcc_s", "-lgcc", "-lc", "-lgcc") ldflags = append(ldflags, "-shared", "-nostdlib", "-Wl,--whole-archive", "-lgolibbegin", "-Wl,--no-whole-archive", "-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")
case "pie":
ldflags = append(ldflags, "-pie")
default: default:
fatalf("-buildmode=%s not supported for gccgo", buildmode) fatalf("-buildmode=%s not supported for gccgo", buildmode)
...@@ -3100,7 +3110,7 @@ func (tools gccgoToolchain) cc(b *builder, p *Package, objdir, ofile, cfile stri ...@@ -3100,7 +3110,7 @@ func (tools gccgoToolchain) cc(b *builder, p *Package, objdir, ofile, cfile stri
// maybePIC adds -fPIC to the list of arguments if needed. // maybePIC adds -fPIC to the list of arguments if needed.
func (tools gccgoToolchain) maybePIC(args []string) []string { func (tools gccgoToolchain) maybePIC(args []string) []string {
switch buildBuildmode { switch buildBuildmode {
case "c-shared", "shared", "plugin": case "c-archive", "c-shared", "shared", "plugin":
args = append(args, "-fPIC") args = append(args, "-fPIC")
} }
return args return args
......
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