aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2015-07-15 09:05:33 -0700
committerIan Lance Taylor <iant@golang.org>2015-07-23 17:49:44 +0000
commitad84f84cb4bad9b5a666a2c00d5c48a48537f03a (patch)
tree506d628cb6cf10bb5cf526af43434b77096cc13b /src
parent37a097519facb21c29af821cbdfffbf9d48c045b (diff)
downloadgo-ad84f84cb4bad9b5a666a2c00d5c48a48537f03a.tar.xz
cmd/link: don't generate .exe extension for external Windows link
On Windows, gcc -o foo will generate foo.exe. Prevent that from happening by adding a final '.' if necessary so that GCC thinks that the file already has an extension. Also remove the initial output file when doing an external link, and use mayberemoveoutfile, not os.Remove, when building an archive (otherwise we will do the wrong thing for -buildmode=c-archive -o /dev/null). I didn't add a test, as it requires using cgo and -o on Windows. Fixes #11725. Change-Id: I6ea12437bb6b4b9b8ee5c3b52d83509fa2437b2d Reviewed-on: https://go-review.googlesource.com/12243 Reviewed-by: Alex Brainman <alex.brainman@gmail.com> Reviewed-by: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src')
-rw-r--r--src/cmd/link/internal/ld/lib.go16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go
index bd0fbc567d..728e78260c 100644
--- a/src/cmd/link/internal/ld/lib.go
+++ b/src/cmd/link/internal/ld/lib.go
@@ -44,6 +44,7 @@ import (
"os"
"os/exec"
"path/filepath"
+ "runtime"
"strings"
)
@@ -836,6 +837,7 @@ func hostlinksetup() {
// change our output to temporary object file
coutbuf.f.Close()
+ mayberemoveoutfile()
p := fmt.Sprintf("%s/go.o", tmpdir)
var err error
@@ -882,7 +884,7 @@ func archive() {
return
}
- os.Remove(outfile)
+ mayberemoveoutfile()
argv := []string{"ar", "-q", "-c", "-s", outfile}
argv = append(argv, hostobjCopy()...)
argv = append(argv, fmt.Sprintf("%s/go.o", tmpdir))
@@ -984,8 +986,18 @@ func hostlink() {
argv = append(argv, fmt.Sprintf("-Wl,--build-id=0x%x", buildinfo))
}
+ // On Windows, given -o foo, GCC will append ".exe" to produce
+ // "foo.exe". We have decided that we want to honor the -o
+ // option. To make this work, we append a '.' so that GCC
+ // will decide that the file already has an extension. We
+ // only want to do this when producing a Windows output file
+ // on a Windows host.
+ outopt := outfile
+ if goos == "windows" && runtime.GOOS == "windows" && filepath.Ext(outopt) == "" {
+ outopt += "."
+ }
argv = append(argv, "-o")
- argv = append(argv, outfile)
+ argv = append(argv, outopt)
if rpath.val != "" {
argv = append(argv, fmt.Sprintf("-Wl,-rpath,%s", rpath.val))