2020-04-02 18:54:05 +00: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"
|
2021-03-23 02:05:46 +00:00
|
|
|
#include "llvm/ADT/SetVector.h"
|
2020-11-18 17:31:47 +00:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2022-01-12 22:01:59 +00:00
|
|
|
#include "llvm/BinaryFormat/MachO.h"
|
2020-04-02 18:54:05 +00:00
|
|
|
#include "llvm/Option/OptTable.h"
|
2020-11-18 17:31:47 +00:00
|
|
|
#include "llvm/Support/MemoryBuffer.h"
|
2022-11-28 00:54:07 +00:00
|
|
|
#include <optional>
|
2020-04-02 18:54:05 +00:00
|
|
|
|
2021-03-23 02:05:46 +00:00
|
|
|
#include <set>
|
|
|
|
#include <type_traits>
|
|
|
|
|
2022-08-07 14:37:49 +00:00
|
|
|
namespace lld::macho {
|
2020-04-02 18:54:05 +00:00
|
|
|
|
2020-11-18 17:31:47 +00:00
|
|
|
class DylibFile;
|
2020-12-02 23:59:00 +00:00
|
|
|
class InputFile;
|
2020-11-18 17:31:47 +00:00
|
|
|
|
2022-12-30 07:32:59 +00:00
|
|
|
class MachOOptTable : public llvm::opt::GenericOptTable {
|
2020-04-02 18:54:05 +00:00
|
|
|
public:
|
|
|
|
MachOOptTable();
|
|
|
|
llvm::opt::InputArgList parse(ArrayRef<const char *> argv);
|
2020-06-15 19:36:32 +00:00
|
|
|
void printHelp(const char *argv0, bool showHidden) const;
|
2020-04-02 18:54:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Create enum with OPT_xxx values for each option in Options.td
|
|
|
|
enum {
|
|
|
|
OPT_INVALID = 0,
|
2023-08-04 18:19:09 +00:00
|
|
|
#define OPTION(...) LLVM_MAKE_OPT_ID(__VA_ARGS__),
|
2020-04-02 18:54:05 +00:00
|
|
|
#include "Options.inc"
|
|
|
|
#undef OPTION
|
|
|
|
};
|
|
|
|
|
2023-08-13 20:38:49 +00:00
|
|
|
void parseLCLinkerOption(llvm::SmallVectorImpl<StringRef> &LCLinkerOptions,
|
|
|
|
InputFile *f, unsigned argc, StringRef data);
|
|
|
|
void resolveLCLinkerOptions();
|
2020-12-03 21:40:04 +00:00
|
|
|
|
2020-11-29 03:38:27 +00:00
|
|
|
std::string createResponseFile(const llvm::opt::InputArgList &args);
|
|
|
|
|
2020-11-18 17:31:47 +00:00
|
|
|
// Check for both libfoo.dylib and libfoo.tbd (in that order).
|
2022-11-28 00:54:07 +00:00
|
|
|
std::optional<StringRef> resolveDylibPath(llvm::StringRef path);
|
2020-11-18 17:31:47 +00:00
|
|
|
|
2021-06-01 20:09:41 +00:00
|
|
|
DylibFile *loadDylib(llvm::MemoryBufferRef mbref, DylibFile *umbrella = nullptr,
|
2022-04-22 15:55:50 +00:00
|
|
|
bool isBundleLoader = false,
|
|
|
|
bool explicitlyLinked = false);
|
2021-10-30 23:35:30 +00:00
|
|
|
void resetLoadedDylibs();
|
2020-11-18 17:31:47 +00:00
|
|
|
|
2021-05-05 18:38:36 +00:00
|
|
|
// Search for all possible combinations of `{root}/{name}.{extension}`.
|
|
|
|
// If \p extensions are not specified, then just search for `{root}/{name}`.
|
2022-11-28 00:54:07 +00:00
|
|
|
std::optional<llvm::StringRef>
|
2021-05-05 18:38:36 +00: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 02:19:09 +00:00
|
|
|
llvm::StringRef rerootPath(llvm::StringRef path);
|
2021-05-05 18:38:36 +00:00
|
|
|
|
2020-12-01 22:45:11 +00:00
|
|
|
uint32_t getModTime(llvm::StringRef path);
|
|
|
|
|
2020-12-02 23:57:30 +00:00
|
|
|
void printArchiveMemberLoad(StringRef reason, const InputFile *);
|
2020-12-02 23:59:00 +00:00
|
|
|
|
2021-07-11 22:24:53 +00:00
|
|
|
// Map simulator platforms to their underlying device platform.
|
2022-01-12 22:01:59 +00:00
|
|
|
llvm::MachO::PlatformType removeSimulator(llvm::MachO::PlatformType platform);
|
2021-07-11 22:24:53 +00:00
|
|
|
|
2021-03-23 02:05:46 +00: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-01 18:45:38 +00: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 02:05:46 +00: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 03:39:14 +00:00
|
|
|
extern std::unique_ptr<DependencyTracker> depTracker;
|
2021-03-23 02:05:46 +00:00
|
|
|
|
2022-08-07 14:37:49 +00:00
|
|
|
} // namespace lld::macho
|
2020-04-02 18:54:05 +00:00
|
|
|
|
|
|
|
#endif
|