diff options
author | Cherry Mui <cherryyz@google.com> | 2021-07-22 18:57:52 -0400 |
---|---|---|
committer | Cherry Mui <cherryyz@google.com> | 2021-09-30 19:56:06 +0000 |
commit | eb9f090d1b543f54b319cab78027cdf2ce1a08b8 (patch) | |
tree | 5f779c0c06cbb4902c06c43eb249072b99bec6c3 /src/cmd/link | |
parent | 205640ed7b6b93d88351c85f0ecfb37d075f8dcf (diff) | |
download | go-eb9f090d1b543f54b319cab78027cdf2ce1a08b8.tar.gz go-eb9f090d1b543f54b319cab78027cdf2ce1a08b8.zip |
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 <cherryyz@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
Diffstat (limited to 'src/cmd/link')
-rw-r--r-- | src/cmd/link/internal/ld/lib.go | 22 |
1 files changed, 20 insertions, 2 deletions
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. |