]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: fixes for -compiler=gccgo -buildmode=c-shared
authorIan Lance Taylor <iant@golang.org>
Wed, 13 Jan 2016 05:24:49 +0000 (21:24 -0800)
committerIan Lance Taylor <iant@golang.org>
Wed, 13 Jan 2016 15:14:04 +0000 (15:14 +0000)
Install pkg.h rather than libpkg.h.

Link against -lc.

Fixes #13860.

Change-Id: I4e429426f8363712a5dbbd2655b9aab802ab2888
Reviewed-on: https://go-review.googlesource.com/18592
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Hudson-Doyle <michael.hudson@canonical.com>
Reviewed-by: Russ Cox <rsc@golang.org>
src/cmd/go/build.go

index ee20a89d86e05d826e7c95ac741c3a012b148a44..825fdac5b8fc9e8eb89e28bbbd824907d3e8a4ee 100644 (file)
@@ -999,13 +999,22 @@ func (b *builder) action1(mode buildMode, depMode buildMode, p *Package, looksha
 
                // Install header for cgo in c-archive and c-shared modes.
                if p.usesCgo() && (buildBuildmode == "c-archive" || buildBuildmode == "c-shared") {
+                       hdrTarget := a.target[:len(a.target)-len(filepath.Ext(a.target))] + ".h"
+                       if buildContext.Compiler == "gccgo" {
+                               // For the header file, remove the "lib"
+                               // added by go/build, so we generate pkg.h
+                               // rather than libpkg.h.
+                               dir, file := filepath.Split(hdrTarget)
+                               file = strings.TrimPrefix(file, "lib")
+                               hdrTarget = filepath.Join(dir, file)
+                       }
                        ah := &action{
                                p:      a.p,
                                deps:   []*action{a.deps[0]},
                                f:      (*builder).installHeader,
                                pkgdir: a.pkgdir,
                                objdir: a.objdir,
-                               target: a.target[:len(a.target)-len(filepath.Ext(a.target))] + ".h",
+                               target: hdrTarget,
                        }
                        a.deps = append(a.deps, ah)
                }
@@ -2722,7 +2731,7 @@ func (tools gccgoToolchain) ld(b *builder, root *action, out string, allactions
                out = out + ".o"
 
        case "c-shared":
-               ldflags = append(ldflags, "-shared", "-nostdlib", "-Wl,--whole-archive", "-lgolibbegin", "-Wl,--no-whole-archive", "-lgo", "-lgcc_s", "-lgcc")
+               ldflags = append(ldflags, "-shared", "-nostdlib", "-Wl,--whole-archive", "-lgolibbegin", "-Wl,--no-whole-archive", "-lgo", "-lgcc_s", "-lgcc", "-lc", "-lgcc")
 
        default:
                fatalf("-buildmode=%s not supported for gccgo", ldBuildmode)