llvm/lld/MachO/Driver.cpp

//===- Driver.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 "Driver.h"
#include "Config.h"
#include "ICF.h"
#include "InputFiles.h"
#include "LTO.h"
#include "MarkLive.h"
#include "ObjC.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 "Writer.h"

#include "lld/Common/Args.h"
#include "lld/Common/CommonLinkerContext.h"
#include "lld/Common/Driver.h"
#include "lld/Common/ErrorHandler.h"
#include "lld/Common/LLVM.h"
#include "lld/Common/Memory.h"
#include "lld/Common/Reproduce.h"
#include "lld/Common/Version.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/BinaryFormat/MachO.h"
#include "llvm/BinaryFormat/Magic.h"
#include "llvm/Config/llvm-config.h"
#include "llvm/LTO/LTO.h"
#include "llvm/Object/Archive.h"
#include "llvm/Option/ArgList.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Parallel.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/TarWriter.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Support/TimeProfiler.h"
#include "llvm/TargetParser/Host.h"
#include "llvm/TextAPI/Architecture.h"
#include "llvm/TextAPI/PackedVersion.h"

#include <algorithm>

usingnamespacellvm;
usingnamespacellvm::MachO;
usingnamespacellvm::object;
usingnamespacellvm::opt;
usingnamespacellvm::sys;
usingnamespacelld;
usingnamespacelld::macho;

std::unique_ptr<Configuration> macho::config;
std::unique_ptr<DependencyTracker> macho::depTracker;

static HeaderFileType getOutputType(const InputArgList &args) {}

static DenseMap<CachedHashStringRef, StringRef> resolvedLibraries;
static std::optional<StringRef> findLibrary(StringRef name) {}

static DenseMap<CachedHashStringRef, StringRef> resolvedFrameworks;
static std::optional<StringRef> findFramework(StringRef name) {}

static bool warnIfNotDirectory(StringRef option, StringRef path) {}

static std::vector<StringRef>
getSearchPaths(unsigned optionCode, InputArgList &args,
               const std::vector<StringRef> &roots,
               const SmallVector<StringRef, 2> &systemPaths) {}

static std::vector<StringRef> getSystemLibraryRoots(InputArgList &args) {}

static std::vector<StringRef>
getLibrarySearchPaths(InputArgList &args, const std::vector<StringRef> &roots) {}

static std::vector<StringRef>
getFrameworkSearchPaths(InputArgList &args,
                        const std::vector<StringRef> &roots) {}

static llvm::CachePruningPolicy getLTOCachePolicy(InputArgList &args) {}

// What caused a given library to be loaded. Only relevant for archives.
// Note that this does not tell us *how* we should load the library, i.e.
// whether we should do it lazily or eagerly (AKA force loading). The "how" is
// decided within addFile().
enum class LoadType {};

struct ArchiveFileInfo {};

static DenseMap<StringRef, ArchiveFileInfo> loadedArchives;

static void saveThinArchiveToRepro(ArchiveFile const *file) {}

static InputFile *addFile(StringRef path, LoadType loadType,
                          bool isLazy = false, bool isExplicit = true,
                          bool isBundleLoader = false,
                          bool isForceHidden = false) {}

static std::vector<StringRef> missingAutolinkWarnings;
static void addLibrary(StringRef name, bool isNeeded, bool isWeak,
                       bool isReexport, bool isHidden, bool isExplicit,
                       LoadType loadType) {}

static DenseSet<StringRef> loadedObjectFrameworks;
static void addFramework(StringRef name, bool isNeeded, bool isWeak,
                         bool isReexport, bool isExplicit, LoadType loadType) {}

// Parses LC_LINKER_OPTION contents, which can add additional command line
// flags. This directly parses the flags instead of using the standard argument
// parser to improve performance.
void macho::parseLCLinkerOption(
    llvm::SmallVectorImpl<StringRef> &LCLinkerOptions, InputFile *f,
    unsigned argc, StringRef data) {}

void macho::resolveLCLinkerOptions() {}

static void addFileList(StringRef path, bool isLazy) {}

// We expect sub-library names of the form "libfoo", which will match a dylib
// with a path of .*/libfoo.{dylib, tbd}.
// XXX ld64 seems to ignore the extension entirely when matching sub-libraries;
// I'm not sure what the use case for that is.
static bool markReexport(StringRef searchName, ArrayRef<StringRef> extensions) {}

// This function is called on startup. We need this for LTO since
// LTO calls LLVM functions to compile bitcode files to native code.
// Technically this can be delayed until we read bitcode files, but
// we don't bother to do lazily because the initialization is fast.
static void initLLVM() {}

static bool compileBitcodeFiles() {}

// Replaces common symbols with defined symbols residing in __common sections.
// This function must be called after all symbol names are resolved (i.e. after
// all InputFiles have been loaded.) As a result, later operations won't see
// any CommonSymbols.
static void replaceCommonSymbols() {}

static void initializeSectionRenameMap() {}

static inline char toLowerDash(char x) {}

static std::string lowerDash(StringRef s) {}

struct PlatformVersion {};

static PlatformVersion parsePlatformVersion(const Arg *arg) {}

// Has the side-effect of setting Config::platformInfo and
// potentially Config::secondaryPlatformInfo.
static void setPlatformVersions(StringRef archName, const ArgList &args) {}

// Has the side-effect of setting Config::target.
static TargetInfo *createTargetInfo(InputArgList &args) {}

static UndefinedSymbolTreatment
getUndefinedSymbolTreatment(const ArgList &args) {}

static ICFLevel getICFLevel(const ArgList &args) {}

static ObjCStubsMode getObjCStubsMode(const ArgList &args) {}

static void warnIfDeprecatedOption(const Option &opt) {}

static void warnIfUnimplementedOption(const Option &opt) {}

static const char *getReproduceOption(InputArgList &args) {}

// Parse options of the form "old;new".
static std::pair<StringRef, StringRef> getOldNewOptions(opt::InputArgList &args,
                                                        unsigned id) {}

// Parse options of the form "old;new[;extra]".
static std::tuple<StringRef, StringRef, StringRef>
getOldNewOptionsExtra(opt::InputArgList &args, unsigned id) {}

static void parseClangOption(StringRef opt, const Twine &msg) {}

static uint32_t parseDylibVersion(const ArgList &args, unsigned id) {}

static uint32_t parseProtection(StringRef protStr) {}

static std::vector<SectionAlign> parseSectAlign(const opt::InputArgList &args) {}

PlatformType macho::removeSimulator(PlatformType platform) {}

static bool supportsNoPie() {}

static bool shouldAdhocSignByDefault(Architecture arch, PlatformType platform) {}

MinVersions;

/// Returns true if the platform is greater than the min version.
/// Returns false if the platform does not exist.
template <std::size_t N>
static bool greaterEqMinVersion(const MinVersions<N> &minVersions,
                                bool ignoreSimulator) {}

static bool dataConstDefault(const InputArgList &args) {}

static bool shouldEmitChainedFixups(const InputArgList &args) {}

static bool shouldEmitRelativeMethodLists(const InputArgList &args) {}

void SymbolPatterns::clear() {}

void SymbolPatterns::insert(StringRef symbolName) {}

bool SymbolPatterns::matchLiteral(StringRef symbolName) const {}

bool SymbolPatterns::matchGlob(StringRef symbolName) const {}

bool SymbolPatterns::match(StringRef symbolName) const {}

static void parseSymbolPatternsFile(const Arg *arg,
                                    SymbolPatterns &symbolPatterns) {}

static void handleSymbolPatterns(InputArgList &args,
                                 SymbolPatterns &symbolPatterns,
                                 unsigned singleOptionCode,
                                 unsigned listFileOptionCode) {}

static void createFiles(const InputArgList &args) {}

static void gatherInputSections() {}

static void foldIdenticalLiterals() {}

static void addSynthenticMethnames() {}

static void referenceStubBinder() {}

static void createAliases() {}

static void handleExplicitExports() {}

static void eraseInitializerSymbols() {}

static SmallVector<StringRef, 0> getRuntimePaths(opt::InputArgList &args) {}

namespace lld {
namespace macho {
bool link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
          llvm::raw_ostream &stderrOS, bool exitEarly, bool disableOutput) {}
} // namespace macho
} // namespace lld