mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 03:02:36 +01:00
c75c8e75b3
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
68 lines
1.9 KiB
C++
68 lines
1.9 KiB
C++
//===- MachOWriter.h --------------------------------------------*- C++ -*-===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "MachOLayoutBuilder.h"
|
|
#include "MachOObjcopy.h"
|
|
#include "Object.h"
|
|
#include "llvm/BinaryFormat/MachO.h"
|
|
#include "llvm/Object/MachO.h"
|
|
|
|
namespace llvm {
|
|
class Error;
|
|
|
|
namespace objcopy {
|
|
namespace macho {
|
|
|
|
class MachOWriter {
|
|
Object &O;
|
|
bool Is64Bit;
|
|
bool IsLittleEndian;
|
|
uint64_t PageSize;
|
|
std::unique_ptr<WritableMemoryBuffer> Buf;
|
|
raw_ostream &Out;
|
|
MachOLayoutBuilder LayoutBuilder;
|
|
|
|
size_t headerSize() const;
|
|
size_t loadCommandsSize() const;
|
|
size_t symTableSize() const;
|
|
size_t strTableSize() const;
|
|
|
|
void writeHeader();
|
|
void writeLoadCommands();
|
|
template <typename StructType>
|
|
void writeSectionInLoadCommand(const Section &Sec, uint8_t *&Out);
|
|
void writeSections();
|
|
void writeSymbolTable();
|
|
void writeStringTable();
|
|
void writeRebaseInfo();
|
|
void writeBindInfo();
|
|
void writeWeakBindInfo();
|
|
void writeLazyBindInfo();
|
|
void writeExportInfo();
|
|
void writeIndirectSymbolTable();
|
|
void writeLinkData(Optional<size_t> LCIndex, const LinkData &LD);
|
|
void writeCodeSignatureData();
|
|
void writeDataInCodeData();
|
|
void writeFunctionStartsData();
|
|
void writeTail();
|
|
|
|
public:
|
|
MachOWriter(Object &O, bool Is64Bit, bool IsLittleEndian, uint64_t PageSize,
|
|
raw_ostream &Out)
|
|
: O(O), Is64Bit(Is64Bit), IsLittleEndian(IsLittleEndian),
|
|
PageSize(PageSize), Out(Out), LayoutBuilder(O, Is64Bit, PageSize) {}
|
|
|
|
size_t totalSize() const;
|
|
Error finalize();
|
|
Error write();
|
|
};
|
|
|
|
} // end namespace macho
|
|
} // end namespace objcopy
|
|
} // end namespace llvm
|