2019-02-02 01:38:07 +01:00
|
|
|
//===- MachOWriter.h --------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
2019-02-11 09:25:19 +01:00
|
|
|
// 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
|
2019-02-02 01:38:07 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2019-08-19 23:05:31 +02:00
|
|
|
#include "MachOLayoutBuilder.h"
|
2019-02-02 01:38:07 +01:00
|
|
|
#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;
|
2019-08-19 23:05:31 +02:00
|
|
|
uint64_t PageSize;
|
2020-10-24 16:35:55 +02:00
|
|
|
std::unique_ptr<WritableMemoryBuffer> Buf;
|
|
|
|
raw_ostream &Out;
|
2019-08-19 23:05:31 +02:00
|
|
|
MachOLayoutBuilder LayoutBuilder;
|
2019-02-02 01:38:07 +01:00
|
|
|
|
|
|
|
size_t headerSize() const;
|
|
|
|
size_t loadCommandsSize() const;
|
|
|
|
size_t symTableSize() const;
|
|
|
|
size_t strTableSize() const;
|
|
|
|
|
|
|
|
void writeHeader();
|
|
|
|
void writeLoadCommands();
|
2019-06-08 03:22:54 +02:00
|
|
|
template <typename StructType>
|
|
|
|
void writeSectionInLoadCommand(const Section &Sec, uint8_t *&Out);
|
2019-02-02 01:38:07 +01:00
|
|
|
void writeSections();
|
|
|
|
void writeSymbolTable();
|
|
|
|
void writeStringTable();
|
|
|
|
void writeRebaseInfo();
|
|
|
|
void writeBindInfo();
|
|
|
|
void writeWeakBindInfo();
|
|
|
|
void writeLazyBindInfo();
|
|
|
|
void writeExportInfo();
|
2019-08-19 23:05:31 +02:00
|
|
|
void writeIndirectSymbolTable();
|
2020-06-16 03:55:59 +02:00
|
|
|
void writeLinkData(Optional<size_t> LCIndex, const LinkData &LD);
|
|
|
|
void writeCodeSignatureData();
|
2019-08-19 23:05:31 +02:00
|
|
|
void writeDataInCodeData();
|
|
|
|
void writeFunctionStartsData();
|
2019-02-02 01:38:07 +01:00
|
|
|
void writeTail();
|
|
|
|
|
|
|
|
public:
|
2019-08-19 23:05:31 +02:00
|
|
|
MachOWriter(Object &O, bool Is64Bit, bool IsLittleEndian, uint64_t PageSize,
|
2020-10-24 16:35:55 +02:00
|
|
|
raw_ostream &Out)
|
2019-08-19 23:05:31 +02:00
|
|
|
: O(O), Is64Bit(Is64Bit), IsLittleEndian(IsLittleEndian),
|
2020-10-24 16:35:55 +02:00
|
|
|
PageSize(PageSize), Out(Out), LayoutBuilder(O, Is64Bit, PageSize) {}
|
2019-02-02 01:38:07 +01:00
|
|
|
|
|
|
|
size_t totalSize() const;
|
2019-06-08 03:22:54 +02:00
|
|
|
Error finalize();
|
2019-02-02 01:38:07 +01:00
|
|
|
Error write();
|
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace macho
|
|
|
|
} // end namespace objcopy
|
|
|
|
} // end namespace llvm
|