Skip to content

Commit f3ce054

Browse files
cmd/go: fixes for -compiler=gccgo -buildmode=c-shared
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Michael Hudson-Doyle <[email protected]> Reviewed-by: Russ Cox <[email protected]>
1 parent 1d1f2fb commit f3ce054

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/cmd/go/build.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -999,13 +999,22 @@ func (b *builder) action1(mode buildMode, depMode buildMode, p *Package, looksha
999999

10001000
// Install header for cgo in c-archive and c-shared modes.
10011001
if p.usesCgo() && (buildBuildmode == "c-archive" || buildBuildmode == "c-shared") {
1002+
hdrTarget := a.target[:len(a.target)-len(filepath.Ext(a.target))] + ".h"
1003+
if buildContext.Compiler == "gccgo" {
1004+
// For the header file, remove the "lib"
1005+
// added by go/build, so we generate pkg.h
1006+
// rather than libpkg.h.
1007+
dir, file := filepath.Split(hdrTarget)
1008+
file = strings.TrimPrefix(file, "lib")
1009+
hdrTarget = filepath.Join(dir, file)
1010+
}
10021011
ah := &action{
10031012
p: a.p,
10041013
deps: []*action{a.deps[0]},
10051014
f: (*builder).installHeader,
10061015
pkgdir: a.pkgdir,
10071016
objdir: a.objdir,
1008-
target: a.target[:len(a.target)-len(filepath.Ext(a.target))] + ".h",
1017+
target: hdrTarget,
10091018
}
10101019
a.deps = append(a.deps, ah)
10111020
}
@@ -2722,7 +2731,7 @@ func (tools gccgoToolchain) ld(b *builder, root *action, out string, allactions
27222731
out = out + ".o"
27232732

27242733
case "c-shared":
2725-
ldflags = append(ldflags, "-shared", "-nostdlib", "-Wl,--whole-archive", "-lgolibbegin", "-Wl,--no-whole-archive", "-lgo", "-lgcc_s", "-lgcc")
2734+
ldflags = append(ldflags, "-shared", "-nostdlib", "-Wl,--whole-archive", "-lgolibbegin", "-Wl,--no-whole-archive", "-lgo", "-lgcc_s", "-lgcc", "-lc", "-lgcc")
27262735

27272736
default:
27282737
fatalf("-buildmode=%s not supported for gccgo", ldBuildmode)

0 commit comments

Comments
 (0)