[patch][rfc] Add pwrite to raw_stream

Sean Silva chisophugis at gmail.com
Wed Apr 8 17:25:36 PDT 2015


It stops being a "stream" when you add the ability to write at a specified
offset. It's like adding operator+= to something with "outputiterator" in
the name. Is there a reason that this has to live inside raw_ostream?

-- Sean Silva

On Wed, Apr 8, 2015 at 3:56 PM, Rafael EspĂ­ndola <rafael.espindola at gmail.com
> wrote:

> I noticed that object writer are somewhat convoluted because they have
> to write to streams with to seek or pwrite support. For that to work
> they have to do a pass over the data computing the size and only then
> write it out.
>
> That is a bit silly, as most of the time (and the ones we care about
> performance) we are writing to an actual file with seek support.
>
> When that is not the case, we can accumulate the data and write it on the
> end.
>
> For accumulating the data, raw_svector_ostream works just fine, except
> that it doesn't support seeking. Adding that is doable, but
> complicates a performance critical structure.
>
> Fortunately, adding pwrite to raw_svector_ostream is trivial.
>
> The attached patch changes ELFObjectWriter.cpp to use pwrite to update
> the one forward reference that is left at that point. Similar cleanups
> should be possible for the other object writers.
>
> The patch also adds a virtual pwrite to raw_stream and a helper class
> for creating a raw_svector_ostream when a given FD does'n support
> seeking (like a pipe).
>
> It passes check-llvm with the exception of
> CodeGen/R600/cf-stack-bug.ll which uses "2>&1" and depends on the
> order the data from stdout and stderr is mixed.
>
> The test could be fixed, but another issue is that clang is structured
> to pass a plain raw_ostream around until the last moment when it is
> wrapped in a formatted_raw_ostream. That makes it harder to detect if
> a stream supports seeking or not.
>
> So, if you guys are OK with this direction, I think the proper way to
> split/commit this is
>
> * Implement classof for raw_ostream.
> * Stop using formatted_raw_ostream when producing binaries.
> * This patch, but SeekWrapper can then take a plain raw_stream and use
> dyn_cast to see if it a fd stream. It would also not add pwrite to
> formatted_raw_ostream.
>
> Cheers,
> Rafael
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150408/173f11d0/attachment.html>


More information about the llvm-commits mailing list