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