[PATCH] D91028: [llvm-objcopy][NFC] replace class Buffer/MemBuffer/FileBuffer with streams.

Alexey Lapshin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 8 02:58:37 PST 2020


avl created this revision.
avl added reviewers: jhenderson, rupprecht, grimar, alexshap.
Herald added subscribers: llvm-commits, abrachet, jfb, hiraditya, sbc100, mgorny, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.
avl requested review of this revision.
Herald added subscribers: MaskRay, aheejin.

During D88827 <https://reviews.llvm.org/D88827> it was requested to remove the local implementation
of Memory/File Buffers:

// TODO: refactor the buffer classes in LLVM to enable us to use them here
// directly.

This patch uses raw_ostream instead of Buffers. Generally, using streams
could allow us to reduce memory usages. No need to load all data into the
memory - the data could be streamed through a smaller buffer.
Thus, this patch uses raw_ostream as an interface for output data:

Error executeObjcopyOnBinary(CopyConfig &Config,

  object::Binary &In,
  raw_ostream &Out);

Note 1. This patch does not change the implementation of Writers
so that data would be directly stored into raw_ostream.
This is assumed to be done later.

Note 2. It would be better if Writers would be implemented in a such way
that data could be streamed without seeking/updating. If that would be
inconvenient then raw_ostream could be replaced with raw_pwrite_stream
to have a possibility to seek back and update file headers.
This is assumed to be done later if necessary.

Note 3. Current FileOutputBuffer allows using a memory-mapped file.
The raw_fd_ostream (which could be used if data should be stored in the file)
does not allow us to use a memory-mapped file. Memory map functionality
could be implemented for raw_fd_ostream:

It is possible to add resize() method into raw_ostream.

class raw_ostream {

  void resize(uint64_t size);

}

That method, implemented for raw_fd_ostream, could create a memory-mapped file.
The streamed data would be written into that memory file then.
Thus we would be able to use memory-mapped files with raw_fd_ostream.
This is assumed to be done later if necessary.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D91028

Files:
  llvm/include/llvm/Object/MachOUniversalWriter.h
  llvm/lib/Object/MachOUniversalWriter.cpp
  llvm/tools/llvm-objcopy/Buffer.cpp
  llvm/tools/llvm-objcopy/Buffer.h
  llvm/tools/llvm-objcopy/CMakeLists.txt
  llvm/tools/llvm-objcopy/COFF/COFFObjcopy.cpp
  llvm/tools/llvm-objcopy/COFF/COFFObjcopy.h
  llvm/tools/llvm-objcopy/COFF/Reader.h
  llvm/tools/llvm-objcopy/COFF/Writer.cpp
  llvm/tools/llvm-objcopy/COFF/Writer.h
  llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
  llvm/tools/llvm-objcopy/ELF/ELFObjcopy.h
  llvm/tools/llvm-objcopy/ELF/Object.cpp
  llvm/tools/llvm-objcopy/ELF/Object.h
  llvm/tools/llvm-objcopy/MachO/MachOObjcopy.cpp
  llvm/tools/llvm-objcopy/MachO/MachOObjcopy.h
  llvm/tools/llvm-objcopy/MachO/MachOWriter.cpp
  llvm/tools/llvm-objcopy/MachO/MachOWriter.h
  llvm/tools/llvm-objcopy/Util.h
  llvm/tools/llvm-objcopy/llvm-objcopy.cpp
  llvm/tools/llvm-objcopy/wasm/WasmObjcopy.cpp
  llvm/tools/llvm-objcopy/wasm/WasmObjcopy.h
  llvm/tools/llvm-objcopy/wasm/Writer.cpp
  llvm/tools/llvm-objcopy/wasm/Writer.h

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91028.303705.patch
Type: text/x-patch
Size: 66678 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201108/755a2711/attachment-0001.bin>


More information about the llvm-commits mailing list