From a428387e978919a9885b2b7d8a1682feba851d1b Mon Sep 17 00:00:00 2001 From: Cherry Mui Date: Fri, 26 Jan 2024 12:08:00 -0500 Subject: [PATCH] cmd/link: print failed external command invocation When the invocation of the external linker, dsymutil or strip command fails, print the command we invoked. For #65292. Change-Id: Icdb5f9ee942ebda4276f6373c3fbbf5222088d0b Reviewed-on: https://go-review.googlesource.com/c/go/+/558856 LUCI-TryBot-Result: Go LUCI Reviewed-by: Bryan Mills --- src/cmd/link/internal/ld/lib.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go index 0219beeb10..df83896100 100644 --- a/src/cmd/link/internal/ld/lib.go +++ b/src/cmd/link/internal/ld/lib.go @@ -1874,9 +1874,10 @@ func (ctxt *Link) hostlink() { ctxt.Logf("\n") } - out, err := exec.Command(argv[0], argv[1:]...).CombinedOutput() + cmd := exec.Command(argv[0], argv[1:]...) + out, err := cmd.CombinedOutput() if err != nil { - Exitf("running %s failed: %v\n%s", argv[0], err, out) + Exitf("running %s failed: %v\n%s\n%s", argv[0], err, cmd, out) } // Filter out useless linker warnings caused by bugs outside Go. @@ -1959,7 +1960,7 @@ func (ctxt *Link) hostlink() { ctxt.Logf("\n") } if out, err := cmd.CombinedOutput(); err != nil { - Exitf("%s: running dsymutil failed: %v\n%s", os.Args[0], err, out) + Exitf("%s: running dsymutil failed: %v\n%s\n%s", os.Args[0], err, cmd, out) } // Remove STAB (symbolic debugging) symbols after we are done with them (by dsymutil). // They contain temporary file paths and make the build not reproducible. @@ -1978,8 +1979,9 @@ func (ctxt *Link) hostlink() { } ctxt.Logf("\n") } - if out, err := exec.Command(stripCmd, stripArgs...).CombinedOutput(); err != nil { - Exitf("%s: running strip failed: %v\n%s", os.Args[0], err, out) + cmd = exec.Command(stripCmd, stripArgs...) + if out, err := cmd.CombinedOutput(); err != nil { + Exitf("%s: running strip failed: %v\n%s\n%s", os.Args[0], err, cmd, out) } // Skip combining if `dsymutil` didn't generate a file. See #11994. if _, err := os.Stat(dsym); os.IsNotExist(err) {