]> Cypherpunks repositories - gostls13.git/commitdiff
ld: Fixes issue 1899 ("cannot create 8.out.exe")
authorJaroslavas Počepko <jp@webmaster.ms>
Fri, 14 Oct 2011 19:37:07 +0000 (20:37 +0100)
committerHector Chu <hectorchu@gmail.com>
Fri, 14 Oct 2011 19:37:07 +0000 (20:37 +0100)
http://code.google.com/p/go/issues/detail?id=1899

R=rsc, alex.brainman, bsiegert, hectorchu, bradfitz
CC=golang-dev
https://golang.org/cl/4978047

doc/progs/run
src/cmd/ld/lib.c

index 9d56049a8855516305bd15c115131a0b14131a92..7a6a603bb893a1f481527634ab5e21ef1f61a55a 100755 (executable)
@@ -42,9 +42,13 @@ for i in \
        $GC $i
 done
 
+# Write to temporary file to avoid mingw bash bug.
+TMPFILE="/tmp/gotest3"
+
 function testit {
        $LD $1.$O
-       x=$(echo $(./$O.out $2 2>&1))  # extra echo canonicalizes
+       ./$O.out $2 2>&1 >"$TMPFILE" || true
+       x=$(echo $(cat "$TMPFILE")) # extra echo canonicalizes
        if [ "$x" != "$3" ]
        then
                echo $1 failed: '"'$x'"' is not '"'$3'"'
@@ -53,7 +57,8 @@ function testit {
 
 function testitpipe {
        $LD $1.$O
-       x=$(echo $(./$O.out | $2 2>&1))  # extra echo canonicalizes
+       ./$O.out | $2 2>&1 >"$TMPFILE" || true
+       x=$(echo $(cat "$TMPFILE")) # extra echo canonicalizes
        if [ "$x" != "$3" ]
        then
                echo $1 failed: '"'$x'"' is not '"'$3'"'
@@ -88,4 +93,4 @@ testit server1 "" ""
 testit eff_bytesize "" "1.00YB 9.09TB"
 testit eff_sequence "" "[-1 2 6 16 44]"
 
-rm -f $O.out *.$O
+rm -f $O.out $O.out.exe *.$O "$TMPFILE"
index 37379e1863393f7d7d01b5252996e8a6052a7cf6..456d41f5a142eb5335b56b26306553e783d956a8 100644 (file)
@@ -70,7 +70,12 @@ libinit(void)
        // add goroot to the end of the libdir list.
        libdir[nlibdir++] = smprint("%s/pkg/%s_%s", goroot, goos, goarch);
 
+       // Unix doesn't like it when we write to a running (or, sometimes,
+       // recently run) binary, so remove the output file before writing it.
+       // On Windows 7, remove() can force the following create() to fail.
+#ifndef _WIN32
        remove(outfile);
+#endif
        cout = create(outfile, 1, 0775);
        if(cout < 0) {
                diag("cannot create %s", outfile);