[all-commits] [llvm/llvm-project] 4f16e1: [llvm-objcopy][NFC] replace class Buffer/MemBuffer...

avl-llvm via All-commits all-commits at lists.llvm.org
Wed Mar 10 12:52:20 PST 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 4f16e177e104eb80589311dc3cc1b5355a7e41bb
      https://github.com/llvm/llvm-project/commit/4f16e177e104eb80589311dc3cc1b5355a7e41bb
  Author: Alexey Lapshin <a.v.lapshin at mail.ru>
  Date:   2021-03-10 (Wed, 10 Mar 2021)

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

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

During 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.

Differential Revision: https://reviews.llvm.org/D91028




More information about the All-commits mailing list