]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: don't print dynimport link error messages
authorIan Lance Taylor <iant@golang.org>
Thu, 26 Sep 2024 04:03:54 +0000 (21:03 -0700)
committerGopher Robot <gobot@golang.org>
Thu, 26 Sep 2024 20:34:56 +0000 (20:34 +0000)
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>

src/cmd/go/internal/work/exec.go
src/cmd/go/testdata/script/cgo_undef.txt

index 5b17ef48111098a30ee11d8d262c85f878df5710..2447c289c8e3580089aa3335fb0d09cae184fed9 100644 (file)
@@ -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...)
-
-       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
-                       }
+       _, err := sh.runOut(base.Cwd(), b.cCompilerEnv(), cmdargs...)
 
-                       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
 }
 
index 30034fbac14fb62b146a222698967476837b62ac..8e84f1d6b5bf80915d766acae114d6e7727e8f09 100644 (file)
 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