<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Wed, Feb 22, 2017 at 1:12 PM Chris Bieneman <<a href="mailto:beanz@apple.com">beanz@apple.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class="gmail_msg">There are two applications for this in libObject that I think are interesting.<div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">(1) Enabling reading binaries that are incomplete or not in contiguous memory. This is the biggest reason why LLDB has its own object parsers instead of using libObject, so we need to have a solution to this problem in order to get rid of LLDB's object file readers.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">(2) Enabling lightweight rewriting of parts of object files. We want to implement strip in LLVM on top of libObject, and today we can't because libObject has no mechanism for modifying object files. One of the things that has come up during discussions of how to handle writing was the idea of breaking object files up into a list of buffers, where each buffer corresponds to a structural part of the file. Then if you rewrite the data in one part of the file, you can just replace the buffer in the list.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">This is particularly interesting for tools like strip, where you could parse the file into a list of buffers, then just remove a few of the buffers, and re-emit (*hand wave* *hand wave*, I know there's a lot more to it than that, I like oversimplifying things).</div></div></blockquote><div><br></div><div>This second one might just work out of the box, or at the very least should be really easy.  I already have one implementation of BinaryStream called BinaryItemStream that stores an ArrayRef<T>.  It's useful when you want to dump out a bunch of records, but don't know how many you're going to have or how many bytes you're going to need until you've generated them all, so it requires doing a separate allocation for each record.  </div><div><br></div><div>So you build up a vector<T*> , and you can add / remove from the middle or whatever, and when you're done, you just create a BinaryItemStream from it, then wrap it in a BinaryStreamReader and you can just slam it out to disk in like one line.</div></div></div>