From: Cherry Mui Date: Thu, 22 Jul 2021 22:57:52 +0000 (-0400) Subject: cmd/link: use "CC --print-prog-name" to locate tools X-Git-Tag: go1.18beta1~1106 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=eb9f090d1b543f54b319cab78027cdf2ce1a08b8;p=gostls13.git cmd/link: use "CC --print-prog-name" to locate tools When building for macOS with external linking, we currently use "xcrun" to invoke "dsymutil" and "strip" tools. That doesn't work well for cross compilation. Use "CC --print-prog-name" to find the tool path instead. Fixes #47316. Change-Id: Ib30c6494c48bfb6a505dc26fe644ef543d777076 Reviewed-on: https://go-review.googlesource.com/c/go/+/336769 Trust: Cherry Mui Run-TryBot: Cherry Mui TryBot-Result: Go Bot Reviewed-by: Than McIntosh --- diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go index 5af20b4d18..9709c2e886 100644 --- a/src/cmd/link/internal/ld/lib.go +++ b/src/cmd/link/internal/ld/lib.go @@ -1644,13 +1644,31 @@ func (ctxt *Link) hostlink() { } if combineDwarf { + // Find "dsymutils" and "strip" tools using CC --print-prog-name. + var cc []string + cc = append(cc, ctxt.extld()...) + cc = append(cc, hostlinkArchArgs(ctxt.Arch)...) + cc = append(cc, "--print-prog-name", "dsymutil") + out, err := exec.Command(cc[0], cc[1:]...).CombinedOutput() + if err != nil { + Exitf("%s: finding dsymutil failed: %v\n%s", os.Args[0], err, out) + } + dsymutilCmd := strings.TrimSuffix(string(out), "\n") + + cc[len(cc)-1] = "strip" + out, err = exec.Command(cc[0], cc[1:]...).CombinedOutput() + if err != nil { + Exitf("%s: finding strip failed: %v\n%s", os.Args[0], err, out) + } + stripCmd := strings.TrimSuffix(string(out), "\n") + dsym := filepath.Join(*flagTmpdir, "go.dwarf") - if out, err := exec.Command("xcrun", "dsymutil", "-f", *flagOutfile, "-o", dsym).CombinedOutput(); err != nil { + if out, err := exec.Command(dsymutilCmd, "-f", *flagOutfile, "-o", dsym).CombinedOutput(); err != nil { Exitf("%s: running dsymutil failed: %v\n%s", os.Args[0], err, 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. - if out, err := exec.Command("xcrun", "strip", "-S", *flagOutfile).CombinedOutput(); err != nil { + if out, err := exec.Command(stripCmd, "-S", *flagOutfile).CombinedOutput(); err != nil { Exitf("%s: running strip failed: %v\n%s", os.Args[0], err, out) } // Skip combining if `dsymutil` didn't generate a file. See #11994.