]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: call syscall.FlushFileBuffers on outbuf Unmap
authorThan McIntosh <thanm@google.com>
Tue, 17 May 2022 12:17:38 +0000 (08:17 -0400)
committerThan McIntosh <thanm@google.com>
Tue, 31 May 2022 11:37:38 +0000 (11:37 +0000)
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 <cherryyz@google.com>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
src/cmd/link/internal/ld/outbuf_windows.go

index 915c72bef3eeaabffe3120896f4cf627256eaa59..a568a17011db3152680795000388877167dfe8be 100644 (file)
@@ -59,6 +59,18 @@ func (out *OutBuf) munmap() {
        if err != nil {
                Exitf("FlushViewOfFile failed: %v", err)
        }
+       // Issue 44817: apparently the call below may be needed (according
+       // to the Windows docs) in addition to the FlushViewOfFile call
+       // above, " ... to flush all the dirty pages plus the metadata for
+       // the file and ensure that they are physically written to disk".
+       // Windows DOC links:
+       //
+       // https://docs.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-flushviewoffile
+       // https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-flushfilebuffers
+       err = syscall.FlushFileBuffers(syscall.Handle(out.f.Fd()))
+       if err != nil {
+               Exitf("FlushFileBuffers failed: %v", err)
+       }
        err = syscall.UnmapViewOfFile(uintptr(unsafe.Pointer(&out.buf[0])))
        out.buf = nil
        if err != nil {