Refactoring. Using streams for llvm-objcopy.


we are trying to reuse some part of llvm-objcopy.
To make it possible we want to move the main implementation of llvm-objcopy
from "tools" subdirectory into the "Object" library(D88827).
One of the problems is using custom buffer class(tools/llvm-objcopy/Buffer.h/cpp)
as an output buffer by llvm-objcopy:

Error executeObjcopyOnRawBinary(const CopyConfig &Config, MemoryBuffer &In, ***Buffer &Out***);

class Buffer {
StringRef Name;

virtual Error allocate(size_t Size) = 0;
virtual uint8_t *getBufferStart() = 0;
virtual Error commit() = 0;

There are two drawbacks of using custom Buffer class:

1. It is not good to move the custom Buffer class into the general llvm Object library.
It is better to use some standard, already existed solution.

2. Interface of class Buffer assumes that the entire buffer must be preallocated.
i.e. before writing to the output file we need to pre-allocate the space.
Such pre-allocation is not a problem if memory-mapped files are used behind Buffer.
But it could be a wasting of memory resources in other cases.
A library might be used in a wider number of scenarios than a separate tool.
So it would not be good for the library to work effectively only if memory-mapped files are used.

Sure, streaming sounds fine to me. The more this looks like the code
we already have for writing object files in LLVM, the better,
hopefully (though that code is a bit expensive, last I played with it
- MCStreamer would buffer each output section, etc, before writing the
output - so some lower-level abstraction below that which I think
we're missing - would be great to have something below MCStreamer that
was higher level than the raw_pwrite_stream it uses - that could be
shared with lld, objcopy, dwp, dsymutil, etc).

David, Thank you for the opinion. What might be the next step to make a progress with it?

Do I need to initiate proposal review, like described here - ?

Thank you, Alexey.

I don't think/hope it doesn't rise to the level of needing the proposal process.

This boils down to which has stalled
out a bit, perhaps? I'd suggest pinging it a few times/linking to this
thread if there's need for reviewers to see this discussion or want to
weigh in on the design discussion here but haven't had time, etc. If
that doesn't unblock it/there's still fundamental design
disagreements, yeah, coming back to this thread to ask for more help
would be good.