Skip to content

Commit cfd202c

Browse files
committed
cmd/link: call syscall.FlushFileBuffers on outbuf Unmap
In the windows version of OutBuf.munmap, call syscall.FlushFileBuffers after the call to syscall.FlushViewOfFile, on the theory that this will help flush all associated meta-data for the file the linker is writing. Updates #44817. Change-Id: Ibff7d05008a91eeed7634d2760153851e15e1c18 Reviewed-on: https://go-review.googlesource.com/c/go/+/406814 Reviewed-by: Cherry Mui <[email protected]> Reviewed-by: Alex Brainman <[email protected]>
1 parent db19b42 commit cfd202c

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/cmd/link/internal/ld/outbuf_windows.go

+12
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,18 @@ func (out *OutBuf) munmap() {
5959
if err != nil {
6060
Exitf("FlushViewOfFile failed: %v", err)
6161
}
62+
// Issue 44817: apparently the call below may be needed (according
63+
// to the Windows docs) in addition to the FlushViewOfFile call
64+
// above, " ... to flush all the dirty pages plus the metadata for
65+
// the file and ensure that they are physically written to disk".
66+
// Windows DOC links:
67+
//
68+
// https://docs.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-flushviewoffile
69+
// https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-flushfilebuffers
70+
err = syscall.FlushFileBuffers(syscall.Handle(out.f.Fd()))
71+
if err != nil {
72+
Exitf("FlushFileBuffers failed: %v", err)
73+
}
6274
err = syscall.UnmapViewOfFile(uintptr(unsafe.Pointer(&out.buf[0])))
6375
out.buf = nil
6476
if err != nil {

0 commit comments

Comments
 (0)