mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/link, cmd/go: delay linking of mingwex and mingw32 until very end
cmd/go links mingwex and mingw32 libraries to every package it builds. This breaks when 2 different packages call same gcc standard library function pow. gcc linker appends pow implementation to the compiled package, and names that function "pow". But when these 2 compiled packages are linked together into the final executable, linker complains, because it finds two "pow" functions with the same name. This CL stops linking of mingwex and mingw32 during package build - that leaves pow function reference unresolved. pow reference gets resolved as final executable is built, by having both internal and external linker use mingwex and mingw32 libraries. Fixes #8756 Change-Id: I50ddc79529ea5463c67118d668488345ecf069bc Reviewed-on: https://go-review.googlesource.com/26670 Run-TryBot: Alex Brainman <alex.brainman@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
b040bc9c06
commit
dfbbe06a20
5 changed files with 76 additions and 25 deletions
|
|
@ -372,6 +372,33 @@ func loadinternal(ctxt *Link, name string) {
|
|||
}
|
||||
}
|
||||
|
||||
// findLibPathCmd uses cmd command to find gcc library libname.
|
||||
// It returns library full path if found, or "none" if not found.
|
||||
func (ctxt *Link) findLibPathCmd(cmd, libname string) string {
|
||||
if *flagExtld == "" {
|
||||
*flagExtld = "gcc"
|
||||
}
|
||||
args := hostlinkArchArgs()
|
||||
args = append(args, cmd)
|
||||
if ctxt.Debugvlog != 0 {
|
||||
ctxt.Logf("%s %v\n", *flagExtld, args)
|
||||
}
|
||||
out, err := exec.Command(*flagExtld, args...).Output()
|
||||
if err != nil {
|
||||
if ctxt.Debugvlog != 0 {
|
||||
ctxt.Logf("not using a %s file because compiler failed\n%v\n%s\n", libname, err, out)
|
||||
}
|
||||
return "none"
|
||||
}
|
||||
return strings.TrimSpace(string(out))
|
||||
}
|
||||
|
||||
// findLibPath searches for library libname.
|
||||
// It returns library full path if found, or "none" if not found.
|
||||
func (ctxt *Link) findLibPath(libname string) string {
|
||||
return ctxt.findLibPathCmd("--print-file-name="+libname, libname)
|
||||
}
|
||||
|
||||
func (ctxt *Link) loadlib() {
|
||||
switch Buildmode {
|
||||
case BuildmodeCShared:
|
||||
|
|
@ -573,28 +600,27 @@ func (ctxt *Link) loadlib() {
|
|||
}
|
||||
if any {
|
||||
if *flagLibGCC == "" {
|
||||
if *flagExtld == "" {
|
||||
*flagExtld = "gcc"
|
||||
}
|
||||
args := hostlinkArchArgs()
|
||||
args = append(args, "--print-libgcc-file-name")
|
||||
if ctxt.Debugvlog != 0 {
|
||||
ctxt.Logf("%s %v\n", *flagExtld, args)
|
||||
}
|
||||
out, err := exec.Command(*flagExtld, args...).Output()
|
||||
if err != nil {
|
||||
if ctxt.Debugvlog != 0 {
|
||||
ctxt.Logf("not using a libgcc file because compiler failed\n%v\n%s\n", err, out)
|
||||
}
|
||||
*flagLibGCC = "none"
|
||||
} else {
|
||||
*flagLibGCC = strings.TrimSpace(string(out))
|
||||
}
|
||||
*flagLibGCC = ctxt.findLibPathCmd("--print-libgcc-file-name", "libgcc")
|
||||
}
|
||||
|
||||
if *flagLibGCC != "none" {
|
||||
hostArchive(ctxt, *flagLibGCC)
|
||||
}
|
||||
if HEADTYPE == obj.Hwindows {
|
||||
if p := ctxt.findLibPath("libmingwex.a"); p != "none" {
|
||||
hostArchive(ctxt, p)
|
||||
}
|
||||
if p := ctxt.findLibPath("libmingw32.a"); p != "none" {
|
||||
hostArchive(ctxt, p)
|
||||
}
|
||||
// TODO: maybe do something similar to peimporteddlls to collect all lib names
|
||||
// and try link them all to final exe just like libmingwex.a and libmingw32.a:
|
||||
/*
|
||||
for:
|
||||
#cgo windows LDFLAGS: -lmsvcrt -lm
|
||||
import:
|
||||
libmsvcrt.a libm.a
|
||||
*/
|
||||
}
|
||||
}
|
||||
} else {
|
||||
hostlinksetup()
|
||||
|
|
@ -1145,6 +1171,9 @@ func (l *Link) hostlink() {
|
|||
}
|
||||
}
|
||||
if HEADTYPE == obj.Hwindows {
|
||||
// libmingw32 and libmingwex have some inter-dependencies,
|
||||
// so must use linker groups.
|
||||
argv = append(argv, "-Wl,--start-group", "-lmingwex", "-lmingw32", "-Wl,--end-group")
|
||||
argv = append(argv, peimporteddlls()...)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue