llvm/lld/MachO/Writer.cpp

//===- Writer.cpp ---------------------------------------------------------===//
//
// 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 "Writer.h"
#include "ConcatOutputSection.h"
#include "Config.h"
#include "InputFiles.h"
#include "InputSection.h"
#include "MapFile.h"
#include "OutputSection.h"
#include "OutputSegment.h"
#include "SectionPriorities.h"
#include "SymbolTable.h"
#include "Symbols.h"
#include "SyntheticSections.h"
#include "Target.h"
#include "UnwindInfoSection.h"

#include "lld/Common/Arrays.h"
#include "lld/Common/CommonLinkerContext.h"
#include "llvm/BinaryFormat/MachO.h"
#include "llvm/Config/llvm-config.h"
#include "llvm/Support/LEB128.h"
#include "llvm/Support/Parallel.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/TimeProfiler.h"
#include "llvm/Support/thread.h"
#include "llvm/Support/xxhash.h"

#include <algorithm>

usingnamespacellvm;
usingnamespacellvm::MachO;
usingnamespacellvm::sys;
usingnamespacelld;
usingnamespacelld::macho;

namespace {
class LCUuid;

class Writer {};

// LC_DYLD_INFO_ONLY stores the offsets of symbol import/export information.
class LCDyldInfo final : public LoadCommand {};

class LCSubFramework final : public LoadCommand {};

class LCFunctionStarts final : public LoadCommand {};

class LCDataInCode final : public LoadCommand {};

class LCDysymtab final : public LoadCommand {};

template <class LP> class LCSegment final : public LoadCommand {};

class LCMain final : public LoadCommand {};

class LCSymtab final : public LoadCommand {};

// There are several dylib load commands that share the same structure:
//   * LC_LOAD_DYLIB
//   * LC_ID_DYLIB
//   * LC_REEXPORT_DYLIB
class LCDylib final : public LoadCommand {};

uint32_t LCDylib::instanceCount =;

class LCLoadDylinker final : public LoadCommand {};

class LCRPath final : public LoadCommand {};

class LCDyldEnv final : public LoadCommand {};

class LCMinVersion final : public LoadCommand {};

class LCBuildVersion final : public LoadCommand {};

// Stores a unique identifier for the output file based on an MD5 hash of its
// contents. In order to hash the contents, we must first write them, but
// LC_UUID itself must be part of the written contents in order for all the
// offsets to be calculated correctly. We resolve this circular paradox by
// first writing an LC_UUID with an all-zero UUID, then updating the UUID with
// its real value later.
class LCUuid final : public LoadCommand {};

template <class LP> class LCEncryptionInfo final : public LoadCommand {};

class LCCodeSignature final : public LoadCommand {};

class LCExportsTrie final : public LoadCommand {};

class LCChainedFixups final : public LoadCommand {};

} // namespace

void Writer::treatSpecialUndefineds() {}

static void prepareSymbolRelocation(Symbol *sym, const InputSection *isec,
                                    const lld::macho::Reloc &r) {}

void Writer::scanRelocations() {}

static void addNonWeakDefinition(const Defined *defined) {}

void Writer::scanSymbols() {}

// TODO: ld64 enforces the old load commands in a few other cases.
static bool useLCBuildVersion(const PlatformInfo &platformInfo) {}

template <class LP> void Writer::createLoadCommands() {}

// Sorting only can happen once all outputs have been collected. Here we sort
// segments, output sections within each segment, and input sections within each
// output segment.
static void sortSegmentsAndSections() {}

template <class LP> void Writer::createOutputSections() {}

void Writer::finalizeAddresses() {}

void Writer::finalizeLinkEditSegment() {}

void Writer::assignAddresses(OutputSegment *seg) {}

void Writer::openFile() {}

void Writer::writeSections() {}

void Writer::applyOptimizationHints() {}

// In order to utilize multiple cores, we first split the buffer into chunks,
// compute a hash for each chunk, and then compute a hash value of the hash
// values.
void Writer::writeUuid() {}

// This is step 5 of the algorithm described in the class comment of
// ChainedFixupsSection.
void Writer::buildFixupChains() {}

void Writer::writeCodeSignature() {}

void Writer::writeOutputFile() {}

template <class LP> void Writer::run() {}

template <class LP> void macho::writeResult() {}

void macho::resetWriter() {}

void macho::createSyntheticSections() {}

OutputSection *macho::firstTLVDataSection =;

template void macho::writeResult<LP64>();
template void macho::writeResult<ILP32>();