]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/link: fix checks for supported linker flags with relative paths.
authorJames Bartlett <jamesbartlett@newrelic.com>
Wed, 3 May 2023 18:27:05 +0000 (18:27 +0000)
committerCherry Mui <cherryyz@google.com>
Fri, 12 May 2023 23:21:11 +0000 (23:21 +0000)
The existing way of checking for supported linker flags causes false negatives
when there are relative paths passed to go tool link. This fixes the issue by
calling the external linker in the current working directory, instead of
in a temporary directory.

Fixes #59952

Change-Id: I173bb8b44902f30dacefde1c202586f87667ab70
Reviewed-on: https://go-review.googlesource.com/c/go/+/491796
Run-TryBot: Cherry Mui <cherryyz@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
src/cmd/link/internal/ld/lib.go

index 0febb3081f7d144581a9ca42ac6dfe14137ff82e..54021b69f4e53426fbfda4c0ddf28f693e8c7536 100644 (file)
@@ -2006,10 +2006,11 @@ func linkerFlagSupported(arch *sys.Arch, linker, altLinker, flag string) bool {
        if altLinker != "" {
                flags = append(flags, "-fuse-ld="+altLinker)
        }
-       flags = append(flags, flag, "trivial.c")
+       trivialPath := filepath.Join(*flagTmpdir, "trivial.c")
+       outPath := filepath.Join(*flagTmpdir, "a.out")
+       flags = append(flags, "-o", outPath, flag, trivialPath)
 
        cmd := exec.Command(linker, flags...)
-       cmd.Dir = *flagTmpdir
        cmd.Env = append([]string{"LC_ALL=C"}, os.Environ()...)
        out, err := cmd.CombinedOutput()
        // GCC says "unrecognized command line option ‘-no-pie’"