]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/link: use "CC --print-prog-name" to locate tools
authorCherry Mui <cherryyz@google.com>
Thu, 22 Jul 2021 22:57:52 +0000 (18:57 -0400)
committerCherry Mui <cherryyz@google.com>
Thu, 30 Sep 2021 19:56:06 +0000 (19:56 +0000)
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>
src/cmd/link/internal/ld/lib.go

index 5af20b4d18aef1ddb72d00a93da34082898b7e29..9709c2e88613c8cacc14337d8dbab761acde1cce 100644 (file)
@@ -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.