Path: blob/main/contrib/llvm-project/lld/MachO/Driver.h
34870 views
//===- Driver.h -------------------------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef LLD_MACHO_DRIVER_H9#define LLD_MACHO_DRIVER_H1011#include "lld/Common/LLVM.h"12#include "llvm/ADT/SetVector.h"13#include "llvm/ADT/StringRef.h"14#include "llvm/BinaryFormat/MachO.h"15#include "llvm/Option/OptTable.h"16#include "llvm/Support/MemoryBuffer.h"17#include <optional>1819#include <set>20#include <type_traits>2122namespace lld::macho {2324class DylibFile;25class InputFile;2627class MachOOptTable : public llvm::opt::GenericOptTable {28public:29MachOOptTable();30llvm::opt::InputArgList parse(ArrayRef<const char *> argv);31void printHelp(const char *argv0, bool showHidden) const;32};3334// Create enum with OPT_xxx values for each option in Options.td35enum {36OPT_INVALID = 0,37#define OPTION(...) LLVM_MAKE_OPT_ID(__VA_ARGS__),38#include "Options.inc"39#undef OPTION40};4142void parseLCLinkerOption(llvm::SmallVectorImpl<StringRef> &LCLinkerOptions,43InputFile *f, unsigned argc, StringRef data);44void resolveLCLinkerOptions();4546std::string createResponseFile(const llvm::opt::InputArgList &args);4748// Check for both libfoo.dylib and libfoo.tbd (in that order).49std::optional<StringRef> resolveDylibPath(llvm::StringRef path);5051DylibFile *loadDylib(llvm::MemoryBufferRef mbref, DylibFile *umbrella = nullptr,52bool isBundleLoader = false,53bool explicitlyLinked = false);54void resetLoadedDylibs();5556// Search for all possible combinations of `{root}/{name}.{extension}`.57// If \p extensions are not specified, then just search for `{root}/{name}`.58std::optional<llvm::StringRef>59findPathCombination(const llvm::Twine &name,60const std::vector<llvm::StringRef> &roots,61ArrayRef<llvm::StringRef> extensions = {""});6263// If -syslibroot is specified, absolute paths to non-object files may be64// rerooted.65llvm::StringRef rerootPath(llvm::StringRef path);6667uint32_t getModTime(llvm::StringRef path);6869void printArchiveMemberLoad(StringRef reason, const InputFile *);7071// Map simulator platforms to their underlying device platform.72llvm::MachO::PlatformType removeSimulator(llvm::MachO::PlatformType platform);7374// Helper class to export dependency info.75class DependencyTracker {76public:77explicit DependencyTracker(llvm::StringRef path);7879// Adds the given path to the set of not-found files.80inline void logFileNotFound(const Twine &path) {81if (active)82notFounds.insert(path.str());83}8485// Writes the dependencies to specified path. The content is first sorted by86// OpCode and then by the filename (in alphabetical order).87void write(llvm::StringRef version,88const llvm::SetVector<InputFile *> &inputs,89llvm::StringRef output);9091private:92enum DepOpCode : uint8_t {93// Denotes the linker version.94Version = 0x00,95// Denotes the input files.96Input = 0x10,97// Denotes the files that do not exist(?)98NotFound = 0x11,99// Denotes the output files.100Output = 0x40,101};102103const llvm::StringRef path;104bool active;105106// The paths need to be alphabetically ordered.107// We need to own the paths because some of them are temporarily108// constructed.109std::set<std::string> notFounds;110};111112extern std::unique_ptr<DependencyTracker> depTracker;113114} // namespace lld::macho115116#endif117118119