This is an archive of the discontinued LLVM Phabricator instance.

FileOutputBuffer: handle mmap(2) failure
ClosedPublic

Authored by ruiu on Jan 18 2019, 4:50 PM.

Details

Summary

If the underlying filesystem does not support mmap system call,
FileOutputBuffer may fail when it attempts to mmap an output temporary
file. This patch handles such situation.

Unfortunately, it looks like it is very hard to test this functionality
without a filesystem that doesn't support mmap using llvm-lit. I tested
this locally by passing an invalid parameter to mmap so that it fails and
falls back to the in-memory buffer. Maybe that's all what we can do.
I believe it is reasonable to submit this without a test.

Diff Detail

Repository
rL LLVM

Event Timeline

ruiu created this revision.Jan 18 2019, 4:50 PM
sbc100 accepted this revision.Jan 18 2019, 5:18 PM

Nice!

When I was thinking about doing this I also had a hard time envisioning how to test (Presumably it would require some kind of mock for fs::mapped_file_region).

I wonder if there are other places where this fallback is already performed at a higher level that we could presumably now remove some code? It seems like other tools such as clang were already handling the lack of mmap since the bug reporter didn't hit an issue until link time.

This revision is now accepted and ready to land.Jan 18 2019, 5:18 PM
ruiu added a comment.Jan 22 2019, 1:49 PM

I wonder if there are other places where this fallback is already performed at a higher level that we could presumably now remove some code? It seems like other tools such as clang were already handling the lack of mmap since the bug reporter didn't hit an issue until link time.

I don't think testing whether this fallback will be triggered or not can be done at a higher level prior to actually creating a file and call mmap(2) on the file, as the condition of the failure depends on the filesystem. Even on the same system and possibly with the same pathname, it may or may not fail, depending on the filesystem of the destination directory.

This revision was automatically updated to reflect the committed changes.

I wonder if there are other places where this fallback is already performed at a higher level that we could presumably now remove some code? It seems like other tools such as clang were already handling the lack of mmap since the bug reporter didn't hit an issue until link time.

I don't think testing whether this fallback will be triggered or not can be done at a higher level prior to actually creating a file and call mmap(2) on the file, as the condition of the failure depends on the filesystem. Even on the same system and possibly with the same pathname, it may or may not fail, depending on the filesystem of the destination directory.

Perhaps one way to test this would be allow an implementation of fs (or just mapped_file_region) to be injected at runtime so that a unit test could run with mock fs. That would require a bunch of refactoring to allow for such dependency injection and I'm not sure how much precedent these is in llvm for such things.