Skip to content

Commit a9a285c

Browse files
ianlancetaylorwheatman
authored andcommitted
lib9, cmd/ld: fixes for cross-linking on a Windows host
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 golang#8723. LGTM=alex.brainman R=golang-codereviews, alex.brainman CC=golang-codereviews https://golang.org/cl/141690043
1 parent d1f5881 commit a9a285c

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/cmd/ld/lib.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ libinit(void)
144144
void
145145
errorexit(void)
146146
{
147+
if(cout >= 0) {
148+
// For rmtemp run at atexit time on Windows.
149+
close(cout);
150+
}
147151
if(nerrors) {
148152
if(cout >= 0)
149153
mayberemoveoutfile();

src/lib9/tempdir_windows.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ removeall(char *p)
7070
{
7171
WinRune *r, *r1;
7272
DWORD attr;
73-
char *q, *elem;
73+
char *q, *qt, *elem;
7474
HANDLE h;
7575
WIN32_FIND_DATAW data;
7676

@@ -91,15 +91,18 @@ removeall(char *p)
9191
do{
9292
q = toutf(data.cFileName);
9393
elem = strrchr(q, '\\');
94-
if(elem != nil) {
94+
if(elem != nil)
9595
elem++;
96-
if(strcmp(elem, ".") == 0 || strcmp(elem, "..") == 0) {
97-
free(q);
98-
continue;
99-
}
96+
else
97+
elem = q;
98+
if(strcmp(elem, ".") == 0 || strcmp(elem, "..") == 0) {
99+
free(q);
100+
continue;
100101
}
101-
removeall(q);
102-
free(q);
102+
qt = smprint("%s\\%s", p, q);
103+
free(q);
104+
removeall(qt);
105+
free(qt);
103106
}while(FindNextFileW(h, &data));
104107
FindClose(h);
105108

0 commit comments

Comments
 (0)