Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/link: does not clean up host link inputs #24704

Closed
ncw opened this issue Apr 5, 2018 · 6 comments

Comments

Projects
None yet
6 participants
@ncw
Copy link
Contributor

commented Apr 5, 2018

What version of Go are you using (go version)?

go version go1.10.1 windows/amd64

Does this issue reproduce with the latest release?

Yes. Haven't tried tip.

What operating system and processor architecture are you using (go env)?

I'm running this on Windows 2016 Server, but I've see the same issue on Windows 7 too.

set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Administrator\AppData\Local\go-build
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\Users\Administrator\go
set GORACE=
set GOROOT=C:\tools\go
set GOTMPDIR=
set GOTOOLDIR=C:\tools\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\ADMINI~1\AppData\Local\Temp\2\go-build231439986=/tmp/go-build -gno
-record-gcc-switches

What did you do?

Compile this very simple cgo program - a directory called go-link-XXXXX is left behind in %TEMP%.

image

Programs which do not use cgo leave nothing behind in %TEMP%.

What did you expect to see?

I expected go to clean up after itself.

What did you see instead?

A left over directory in %TEMP%. Inside it is a single file

image

I noticed this because I left my machine running go test in a loop overnight and it filled the disk up!

@ALTree ALTree added this to the Go1.11 milestone Apr 5, 2018

@rsc

This comment has been minimized.

Copy link
Contributor

commented Apr 5, 2018

The relevant code is in src/cmd/link/internal/ld/lib.go's hostlinksetup, which does AtExit(rmtemp), and rmtemp in turn does os.RemoveAll of the temp dir. The next step is to find out why RemoveAll is not removing all. Probably Windows thinks some process still has go.o open and refuses to remove it. I hope that process is cmd/link - that is, I hope we just forgot to close the file - because that would be an easy fix.

@rsc rsc changed the title cmd/cgo: windows compiles using cgo leave behind files in %TEMP% cmd/link: does not clean up host link inputs Apr 5, 2018

@rsc rsc added the NeedsFix label Apr 5, 2018

@alexbrainman

This comment has been minimized.

Copy link
Member

commented Apr 7, 2018

@ncw my favorite type of bug, thank you. :-) I will try to debug this when I have time.

Alex

@gopherbot

This comment has been minimized.

Copy link

commented May 21, 2018

Change https://golang.org/cl/113935 mentions this issue: cmd/link: close go.o before deleting it

@gopherbot gopherbot closed this in 1174ad3 May 23, 2018

@laboger

This comment has been minimized.

Copy link
Contributor

commented May 23, 2018

The new test added here fails on linux/ppc64 (works fine on linux/ppc64le) since full linker support was never added for linux/ppc64 and cgo doesn't work there. The test should be skipped for linux/ppc64.

@ncw

This comment has been minimized.

Copy link
Contributor Author

commented May 23, 2018

Thanks for fixing this @alexbrainman - you are the windows wizard :-)

@alexbrainman

This comment has been minimized.

Copy link
Member

commented May 24, 2018

The new test added here fails on linux/ppc64 (works fine on linux/ppc64le) since full linker support was never added for linux/ppc64 and cgo doesn't work there. The test should be skipped for linux/ppc64.

This is fixed by CL 114235 now. Sorry for breaking it, but there are no try-bots configured as no-cgo.

Alex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.