]> Cypherpunks repositories - gostls13.git/commitdiff
lib9, cmd/ld: fixes for cross-linking on a Windows host
authorIan Lance Taylor <iant@golang.org>
Fri, 19 Sep 2014 00:27:26 +0000 (17:27 -0700)
committerIan Lance Taylor <iant@golang.org>
Fri, 19 Sep 2014 00:27:26 +0000 (17:27 -0700)
This fixes a couple of problems that occur when the linker
removes its temporary directory on Windows.  The linker only
creates and removes a temporary directory when doing external
linking.  Windows does not yet support external linking.
Therefore, these problems are only seen when using a
cross-compiler hosted on Windows.

In lib9, FindFirstFileW returns just the file name, not the
full path name.  Don't assume that we will find a slash.
Changed the code to work either way just in case.

In ld, Windows requires that files be closed before they are
removed, so close the output file before we might try to
remove it.

Fixes #8723.

LGTM=alex.brainman
R=golang-codereviews, alex.brainman
CC=golang-codereviews
https://golang.org/cl/141690043

src/cmd/ld/lib.c
src/lib9/tempdir_windows.c

index 651705a2e6797f2df8c467edb407709bab174a85..36f0f99de20d0aa2f396a5806aea666ead7f01b1 100644 (file)
@@ -144,6 +144,10 @@ libinit(void)
 void
 errorexit(void)
 {
+       if(cout >= 0) {
+               // For rmtemp run at atexit time on Windows.
+               close(cout);
+       }
        if(nerrors) {
                if(cout >= 0)
                        mayberemoveoutfile();
index 1a530059aece51d2350dccc43ebb9568be7879d7..4c3df7cf11ac5d76d263771edab00a510eab39b7 100644 (file)
@@ -70,7 +70,7 @@ removeall(char *p)
 {
        WinRune *r, *r1;
        DWORD attr;
-       char *q, *elem;
+       char *q, *qt, *elem;
        HANDLE h;
        WIN32_FIND_DATAW data;
        
@@ -91,15 +91,18 @@ removeall(char *p)
        do{
                q = toutf(data.cFileName);
                elem = strrchr(q, '\\');
-               if(elem != nil) {
+               if(elem != nil)
                        elem++;
-                       if(strcmp(elem, ".") == 0 || strcmp(elem, "..") == 0) {
-                               free(q);
-                               continue;
-                       }
+               else
+                       elem = q;
+               if(strcmp(elem, ".") == 0 || strcmp(elem, "..") == 0) {
+                       free(q);
+                       continue;
                }
-               removeall(q);
-               free(q);                
+               qt = smprint("%s\\%s", p, q);
+               free(q);
+               removeall(qt);
+               free(qt);
        }while(FindNextFileW(h, &data));
        FindClose(h);