2020-04-03 02:54:05 +08:00
|
|
|
//===- Driver.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
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLD_MACHO_DRIVER_H
|
|
|
|
#define LLD_MACHO_DRIVER_H
|
|
|
|
|
|
|
|
#include "lld/Common/LLVM.h"
|
2020-11-19 01:31:47 +08:00
|
|
|
#include "llvm/ADT/Optional.h"
|
2021-03-23 10:05:46 +08:00
|
|
|
#include "llvm/ADT/SetVector.h"
|
2020-11-19 01:31:47 +08:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2022-01-13 06:01:59 +08:00
|
|
|
#include "llvm/BinaryFormat/MachO.h"
|
2020-04-03 02:54:05 +08:00
|
|
|
#include "llvm/Option/OptTable.h"
|
2020-11-19 01:31:47 +08:00
|
|
|
#include "llvm/Support/MemoryBuffer.h"
|
2020-04-03 02:54:05 +08:00
|
|
|
|
2021-03-23 10:05:46 +08:00
|
|
|
#include <set>
|
|
|
|
#include <type_traits>
|
|
|
|
|
2020-04-03 02:54:05 +08:00
|
|
|
namespace lld {
|
|
|
|
namespace macho {
|
|
|
|
|
2020-11-19 01:31:47 +08:00
|
|
|
class DylibFile;
|
2020-12-03 07:59:00 +08:00
|
|
|
class InputFile;
|
2020-11-19 01:31:47 +08:00
|
|
|
|
2020-04-03 02:54:05 +08:00
|
|
|
class MachOOptTable : public llvm::opt::OptTable {
|
|
|
|
public:
|
|
|
|
MachOOptTable();
|
|
|
|
llvm::opt::InputArgList parse(ArrayRef<const char *> argv);
|
2020-06-16 03:36:32 +08:00
|
|
|
void printHelp(const char *argv0, bool showHidden) const;
|
2020-04-03 02:54:05 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// Create enum with OPT_xxx values for each option in Options.td
|
|
|
|
enum {
|
|
|
|
OPT_INVALID = 0,
|
|
|
|
#define OPTION(_1, _2, ID, _4, _5, _6, _7, _8, _9, _10, _11, _12) OPT_##ID,
|
|
|
|
#include "Options.inc"
|
|
|
|
#undef OPTION
|
|
|
|
};
|
|
|
|
|
2021-04-07 02:05:15 +08:00
|
|
|
void parseLCLinkerOption(InputFile *, unsigned argc, StringRef data);
|
2020-12-04 05:40:04 +08:00
|
|
|
|
2020-11-29 11:38:27 +08:00
|
|
|
std::string createResponseFile(const llvm::opt::InputArgList &args);
|
|
|
|
|
2020-11-19 01:31:47 +08:00
|
|
|
// Check for both libfoo.dylib and libfoo.tbd (in that order).
|
2021-10-20 23:20:21 +08:00
|
|
|
llvm::Optional<StringRef> resolveDylibPath(llvm::StringRef path);
|
2020-11-19 01:31:47 +08:00
|
|
|
|
2021-06-02 04:09:41 +08:00
|
|
|
DylibFile *loadDylib(llvm::MemoryBufferRef mbref, DylibFile *umbrella = nullptr,
|
|
|
|
bool isBundleLoader = false);
|
2021-10-31 07:35:30 +08:00
|
|
|
void resetLoadedDylibs();
|
2020-11-19 01:31:47 +08:00
|
|
|
|
2021-05-06 02:38:36 +08:00
|
|
|
// Search for all possible combinations of `{root}/{name}.{extension}`.
|
|
|
|
// If \p extensions are not specified, then just search for `{root}/{name}`.
|
2021-06-19 10:19:09 +08:00
|
|
|
llvm::Optional<llvm::StringRef>
|
2021-05-06 02:38:36 +08:00
|
|
|
findPathCombination(const llvm::Twine &name,
|
|
|
|
const std::vector<llvm::StringRef> &roots,
|
|
|
|
ArrayRef<llvm::StringRef> extensions = {""});
|
|
|
|
|
|
|
|
// If -syslibroot is specified, absolute paths to non-object files may be
|
|
|
|
// rerooted.
|
2021-06-19 10:19:09 +08:00
|
|
|
llvm::StringRef rerootPath(llvm::StringRef path);
|
2021-05-06 02:38:36 +08:00
|
|
|
|
2020-12-02 06:45:11 +08:00
|
|
|
uint32_t getModTime(llvm::StringRef path);
|
|
|
|
|
2020-12-03 07:57:30 +08:00
|
|
|
void printArchiveMemberLoad(StringRef reason, const InputFile *);
|
2020-12-03 07:59:00 +08:00
|
|
|
|
2021-07-12 06:24:53 +08:00
|
|
|
// Map simulator platforms to their underlying device platform.
|
2022-01-13 06:01:59 +08:00
|
|
|
llvm::MachO::PlatformType removeSimulator(llvm::MachO::PlatformType platform);
|
2021-07-12 06:24:53 +08:00
|
|
|
|
2021-03-23 10:05:46 +08:00
|
|
|
// Helper class to export dependency info.
|
|
|
|
class DependencyTracker {
|
|
|
|
public:
|
|
|
|
explicit DependencyTracker(llvm::StringRef path);
|
|
|
|
|
|
|
|
// Adds the given path to the set of not-found files.
|
|
|
|
inline void logFileNotFound(const Twine &path) {
|
|
|
|
if (active)
|
|
|
|
notFounds.insert(path.str());
|
|
|
|
}
|
|
|
|
|
2022-02-02 02:45:38 +08:00
|
|
|
// Writes the dependencies to specified path. The content is first sorted by
|
|
|
|
// OpCode and then by the filename (in alphabetical order).
|
2021-03-23 10:05:46 +08:00
|
|
|
void write(llvm::StringRef version,
|
|
|
|
const llvm::SetVector<InputFile *> &inputs,
|
|
|
|
llvm::StringRef output);
|
|
|
|
|
|
|
|
private:
|
|
|
|
enum DepOpCode : uint8_t {
|
|
|
|
// Denotes the linker version.
|
|
|
|
Version = 0x00,
|
|
|
|
// Denotes the input files.
|
|
|
|
Input = 0x10,
|
|
|
|
// Denotes the files that do not exist(?)
|
|
|
|
NotFound = 0x11,
|
|
|
|
// Denotes the output files.
|
|
|
|
Output = 0x40,
|
|
|
|
};
|
|
|
|
|
|
|
|
const llvm::StringRef path;
|
|
|
|
bool active;
|
|
|
|
|
|
|
|
// The paths need to be alphabetically ordered.
|
|
|
|
// We need to own the paths because some of them are temporarily
|
|
|
|
// constructed.
|
|
|
|
std::set<std::string> notFounds;
|
|
|
|
};
|
|
|
|
|
2022-01-11 11:39:14 +08:00
|
|
|
extern std::unique_ptr<DependencyTracker> depTracker;
|
2021-03-23 10:05:46 +08:00
|
|
|
|
2020-04-03 02:54:05 +08:00
|
|
|
} // namespace macho
|
|
|
|
} // namespace lld
|
|
|
|
|
|
|
|
#endif
|