From: Than McIntosh Date: Tue, 28 Mar 2023 19:57:40 +0000 (+0000) Subject: Revert "cmd/link: use path from "cc --print-prog-name ar" for c-archive buildmode" X-Git-Tag: go1.21rc1~1124 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=cd25a3a416d2752cc8a61e1cad09c4fc8b549ecc;p=gostls13.git Revert "cmd/link: use path from "cc --print-prog-name ar" for c-archive buildmode" This reverts commit https://go-review.git.corp.google.com/c/go/+/479775 Reason for revert: fails with ios-arm64-corellium builder Change-Id: Iae61b994a39ff6c70af8a302f7a46de0097edf3e Reviewed-on: https://go-review.googlesource.com/c/go/+/479917 Auto-Submit: Than McIntosh Run-TryBot: Than McIntosh TryBot-Result: Gopher Robot Reviewed-by: Ian Lance Taylor --- diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go index 6500c810e0..02c6908407 100644 --- a/src/cmd/link/internal/ld/lib.go +++ b/src/cmd/link/internal/ld/lib.go @@ -1316,12 +1316,7 @@ func (ctxt *Link) archive() { exitIfErrors() if *flagExtar == "" { - const printProgName = "--print-prog-name=ar" - cc := ctxt.extld() *flagExtar = "ar" - if linkerFlagSupported(ctxt.Arch, cc[0], "", printProgName) { - *flagExtar = ctxt.findExtLinkTool("ar") - } } mayberemoveoutfile() @@ -1880,8 +1875,22 @@ func (ctxt *Link) hostlink() { if combineDwarf { // Find "dsymutils" and "strip" tools using CC --print-prog-name. - dsymutilCmd := ctxt.findExtLinkTool("dsymutil") - stripCmd := ctxt.findExtLinkTool("dsymutil") + 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(dsymutilCmd, "-f", *flagOutfile, "-o", dsym).CombinedOutput(); err != nil { @@ -2754,19 +2763,3 @@ func captureHostObj(h *Hostobj) { fmt.Fprintf(os.Stderr, "link: info: captured host object %s to %s\n", h.file, opath) } - -// findExtLinkTool invokes the external linker CC with --print-prog-name -// passing the name of the tool we're interested in, such as "strip", -// "ar", or "dsymutil", and returns the path passed back from the command. -func (ctxt *Link) findExtLinkTool(toolname string) string { - var cc []string - cc = append(cc, ctxt.extld()...) - cc = append(cc, hostlinkArchArgs(ctxt.Arch)...) - cc = append(cc, "--print-prog-name", toolname) - out, err := exec.Command(cc[0], cc[1:]...).CombinedOutput() - if err != nil { - Exitf("%s: finding %s failed: %v\n%s", os.Args[0], toolname, err, out) - } - cmdpath := strings.TrimSuffix(string(out), "\n") - return cmdpath -}