mirror of
https://github.com/golang/go
synced 2024-11-14 17:20:21 -07:00
cmd/go: don't print dynimport link error messages
When using the -x or -n option, we were printing the external linker error messages from producing the dynimport file. This was confusing because those linker errors are unimportant and ignored; only the linker exit status matters, and failure doesn't drop the build. Change cmd/go -x to not print the error messages, and to instead print the linker command line with a notation of whether the link succeeded or failed. Fixes #68743 Change-Id: Ie3cc58d2d6a7d33d7baa6f1273b4fb5a7deee7e5 Reviewed-on: https://go-review.googlesource.com/c/go/+/615916 Reviewed-by: Michael Matloob <matloob@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
parent
712d47ce15
commit
3587430899
@ -2244,7 +2244,6 @@ func (b *Builder) ccompile(a *Action, outfile string, flags []string, file strin
|
||||
}
|
||||
|
||||
// gccld runs the gcc linker to create an executable from a set of object files.
|
||||
// Any error output is only displayed for BuildN or BuildX.
|
||||
func (b *Builder) gccld(a *Action, objdir, outfile string, flags []string, objs []string) error {
|
||||
p := a.Package
|
||||
sh := b.Shell(a)
|
||||
@ -2256,47 +2255,18 @@ func (b *Builder) gccld(a *Action, objdir, outfile string, flags []string, objs
|
||||
}
|
||||
|
||||
cmdargs := []any{cmd, "-o", outfile, objs, flags}
|
||||
out, err := sh.runOut(base.Cwd(), b.cCompilerEnv(), cmdargs...)
|
||||
_, err := sh.runOut(base.Cwd(), b.cCompilerEnv(), cmdargs...)
|
||||
|
||||
if len(out) > 0 {
|
||||
// Filter out useless linker warnings caused by bugs outside Go.
|
||||
// See also cmd/link/internal/ld's hostlink method.
|
||||
var save [][]byte
|
||||
var skipLines int
|
||||
for _, line := range bytes.SplitAfter(out, []byte("\n")) {
|
||||
// golang.org/issue/26073 - Apple Xcode bug
|
||||
if bytes.Contains(line, []byte("ld: warning: text-based stub file")) {
|
||||
continue
|
||||
}
|
||||
|
||||
if skipLines > 0 {
|
||||
skipLines--
|
||||
continue
|
||||
}
|
||||
|
||||
// Remove duplicate main symbol with runtime/cgo on AIX.
|
||||
// With runtime/cgo, two main are available:
|
||||
// One is generated by cgo tool with {return 0;}.
|
||||
// The other one is the main calling runtime.rt0_go
|
||||
// in runtime/cgo.
|
||||
// The second can't be used by cgo programs because
|
||||
// runtime.rt0_go is unknown to them.
|
||||
// Therefore, we let ld remove this main version
|
||||
// and used the cgo generated one.
|
||||
if p.ImportPath == "runtime/cgo" && bytes.Contains(line, []byte("ld: 0711-224 WARNING: Duplicate symbol: .main")) {
|
||||
skipLines = 1
|
||||
continue
|
||||
}
|
||||
|
||||
save = append(save, line)
|
||||
}
|
||||
out = bytes.Join(save, nil)
|
||||
}
|
||||
// Note that failure is an expected outcome here, so we report output only
|
||||
// in debug mode and don't report the error.
|
||||
if cfg.BuildN || cfg.BuildX {
|
||||
sh.reportCmd("", "", out, nil)
|
||||
saw := "succeeded"
|
||||
if err != nil {
|
||||
saw = "failed"
|
||||
}
|
||||
sh.ShowCmd("", "%s # test for internal linking errors (%s)", joinUnambiguously(str.StringList(cmdargs...)), saw)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
|
21
src/cmd/go/testdata/script/cgo_undef.txt
vendored
21
src/cmd/go/testdata/script/cgo_undef.txt
vendored
@ -23,10 +23,18 @@
|
||||
cc -c -o a/b.syso b/b.c
|
||||
cc -c -o b/lib.o b/lib.c
|
||||
exec ar rc a/libb.a b/lib.o
|
||||
|
||||
go build
|
||||
! stderr 'undefined reference'
|
||||
|
||||
! go build -ldflags=-linkmode=internal
|
||||
stderr 'some packages could not be built to support internal linking.*m/c|requires external linking|does not support internal cgo'
|
||||
|
||||
# Test for issue #68743.
|
||||
go build -x m/d
|
||||
! stderr 'undefined reference'
|
||||
stderr 'test for internal linking'
|
||||
|
||||
-- go.mod --
|
||||
module m
|
||||
|
||||
@ -58,6 +66,19 @@ func Fn(i int) (int, int) {
|
||||
return a.GoFn(i), int(C.D(C.int(i)))
|
||||
}
|
||||
|
||||
-- d/d.go --
|
||||
// Package d is a copy of package c, to build with -x.
|
||||
package d
|
||||
|
||||
// static int D(int i) { return i; }
|
||||
import "C"
|
||||
|
||||
import "m/a"
|
||||
|
||||
func Fn(i int) (int, int) {
|
||||
return a.GoFn(i), int(C.D(C.int(i)))
|
||||
}
|
||||
|
||||
-- main.go --
|
||||
package main
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user