<div dir="ltr">Can we just extend llvm's mapped_file_region to support a boolean Writable flag?</div><br><div class="gmail_quote"><div dir="ltr">On Wed, Nov 15, 2017 at 8:03 AM Pavel Labath via Phabricator <<a href="mailto:reviews@reviews.llvm.org">reviews@reviews.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">labath created this revision.<br>
Herald added subscribers: krytarowski, arichardson, aprantl, emaste.<br>
<br>
We sometimes need to write to the object file we've mapped into memory,<br>
generally to apply relocations to debug info sections. We've had that<br>
ability before, but with the introduction of DataBufferLLVM, we have<br>
lost it, as the underlying llvm class (MemoryBuffer) only supports<br>
read-only mappings. The way DataBufferLLVM implemented writable buffers<br>
was through the Private=true flag, which causes the file contents to be<br>
read into a malloc()ed buffer.<br>
<br>
This wasn't a problem then, since we weren't aware of any cases where we<br>
need to relocate the debug info, and we just always set Private=false<br>
for the cases where we mmapped the full object file. This has changed in<br>
<a href="https://reviews.llvm.org/D38142" rel="noreferrer" target="_blank">https://reviews.llvm.org/D38142</a>, where needed to relocate the FreeBSD kernel, and we've flipped<br>
the private flag to true, without even realising the full impact of<br>
that. (The impact is significant slowdown in debug info loading and a<br>
huge number of dirty pages).<br>
<br>
This (not particularly elegant) commit tries to restore the performance<br>
and bring down memory usage by bringing back the private copy-on-write<br>
file mappings. It does this by falling back to the lower-level llvm<br>
primitive (mapped_file_region), which supports this type of mappings.<br>
Unfortunately, this primitive does not support non-mmapped regions, so<br>
for volatile regions I have to still use the MemoryBuffer class.<br>
<br>
I have also removed the "Private" argument to DataBufferLLVM factory<br>
functions -- what it really meant was "read-only", but we generally<br>
assume all our databuffers are writable. If we ever want to have<br>
read-only buffers, we can bring it back with an appropriate name.<br>
<br>
<br>
<a href="https://reviews.llvm.org/D40079" rel="noreferrer" target="_blank">https://reviews.llvm.org/D40079</a><br>
<br>
Files:<br>
  include/lldb/Utility/DataBufferLLVM.h<br>
  source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp<br>
  source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp<br>
  source/Utility/DataBufferLLVM.cpp<br>
<br>
</blockquote></div>