This is an archive of the discontinued LLVM Phabricator instance.

FileOutputBuffer: support non-mmap'able file.
ClosedPublic

Authored by ruiu on Dec 20 2016, 5:54 PM.

Details

Summary

Previously, FileOutputBuffer didn't work for non-mmap'able files, so
you cannot use that class for /dev/null for example. This patch fixes
the issue.

Now, before mmap'ing a file, it checks whether a given file is a regular
file or not. If it is a regular file, it uses mmap as before. If not, it
creates an internal buffer and write that buffer contents on commit().

This patch enables "-o /dev/null" for LLD. Previouly, it failed.

Diff Detail

Repository
rL LLVM

Event Timeline

ruiu updated this revision to Diff 82187.Dec 20 2016, 5:54 PM
ruiu retitled this revision from to FileOutputBuffer: support non-mmap'able file..
ruiu updated this object.
ruiu added a reviewer: rafael.
ruiu added a subscriber: llvm-commits.
grimar added a subscriber: grimar.Dec 20 2016, 11:27 PM
grimar added inline comments.
llvm/lib/Support/FileOutputBuffer.cpp
159 ↗(On Diff #82187)

llvm::make_unique may be ?

ruiu added inline comments.Dec 21 2016, 12:43 AM
llvm/lib/Support/FileOutputBuffer.cpp
159 ↗(On Diff #82187)

Why?

grimar added inline comments.Dec 21 2016, 1:13 AM
llvm/lib/Support/FileOutputBuffer.cpp
159 ↗(On Diff #82187)

That should be shorter and avoids using "new".

It is generally also consistent with recomendations to use std::make_shared instead of std::shared_ptr(new X) which is preffered because of different reasons usually (single allocation of T and control block in most of implementations for example).

ruiu added inline comments.Dec 21 2016, 1:23 AM
llvm/lib/Support/FileOutputBuffer.cpp
159 ↗(On Diff #82187)

Ah, there's a reason why we can't use make_unique. The FileOutputBuffer ctor is private, so we need to instantiate it from this function. This function is a member of that class, so it can call the ctor. However, make_unique is not, so it can't.

This revision was automatically updated to reflect the committed changes.