This is an archive of the discontinued LLVM Phabricator instance.

[LLD] [RFC] Don't close the memory mapping when exiting
ClosedPublic

Authored by mstorsjo on Aug 22 2018, 4:16 AM.

Details

Summary

If exiting due to an error in a multithreaded section of the code, there may be other threads still running, accessing the memory mapped area. Just remove the temporary file (on unix, just remove it, while it has got a remove-on-exit flag set on windows) and close its file descriptor, while keeping the memory mapping intact.

This implements @pcc's suggestion on fixing PR38647.

I'm a little weary about the fact that the existing comment in FileOutputBuffer.cpp says "Close the mapping before deleting the temp file, so that the removal succeeds.", while this approach taken by this patch seems to work fine (at least on windows 10). OTOH we don't actually delete the file on windows, we just close the FD.

Diff Detail

Event Timeline

mstorsjo created this revision.Aug 22 2018, 4:16 AM
ruiu accepted this revision.Aug 22 2018, 4:48 PM

LGTM

I think I like this approach more than https://reviews.llvm.org/D51096 which seems more artificial than this one. This patch should prevent crashing when exiting. If lld worked like that from beginning, we probably wouldn't have been discussing adding D51096.

This revision is now accepted and ready to land.Aug 22 2018, 4:48 PM
This revision was automatically updated to reflect the committed changes.