From: Russ Cox Date: Fri, 1 Oct 2010 20:02:18 +0000 (-0400) Subject: Make.pkg: remove .so before installing new one X-Git-Tag: weekly.2010-10-13~75 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=f481afae53f4b5c26ea69bf062a630e932b52e04;p=gostls13.git Make.pkg: remove .so before installing new one On Linux, overwriting an mmap'ed file causes all the MAP_PRIVATE pages to get refreshed with the new content, even ones that have been modified by the process that did the mmap. One specific instance of this is that after the dynamic linker has relocated a page from a .so, overwriting the .so will un-relocate it, making the next use of one of the no-longer-relocated addresses incorrect and probably crash the program. Linux must go out of its way to break programs in this way: the pages have already been copied on write, so they're not shared with the file system cache, and it trashes them anyway. The manual says the behavior when the file gets overwritten is "undefined". Removing before copy avoids the undefined behavior. R=iant CC=golang-dev, msolo https://golang.org/cl/2333045 --- diff --git a/src/Make.pkg b/src/Make.pkg index d5ccbe0308..10454c7cc4 100644 --- a/src/Make.pkg +++ b/src/Make.pkg @@ -153,6 +153,7 @@ $(CGOTARG).so: $(GCC_OFILES) $(CGO_DEPS) $(pkgdir)/$(CGOTARG).so: $(CGOTARG).so @test -d $(QUOTED_GOROOT)/pkg && mkdir -p $(pkgdir) + rm -f "$@" cp $(CGOTARG).so "$@" ifneq ($(CGOFILES),)