[llvm-dev] RFC: Adding llvm::ThinStream
Zachary Turner via llvm-dev
llvm-dev at lists.llvm.org
Wed Feb 22 15:22:41 PST 2017
On Wed, Feb 22, 2017 at 1:12 PM Chris Bieneman <beanz at apple.com> wrote:
> There are two applications for this in libObject that I think are
> (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.
> (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.
> 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).
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.
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.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the llvm-dev