173
|
1 //===- Driver.h -------------------------------------------------*- C++ -*-===//
|
|
2 //
|
|
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
4 // See https://llvm.org/LICENSE.txt for license information.
|
|
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
6 //
|
|
7 //===----------------------------------------------------------------------===//
|
|
8
|
|
9 #ifndef LLD_MACHO_DRIVER_H
|
|
10 #define LLD_MACHO_DRIVER_H
|
|
11
|
|
12 #include "lld/Common/LLVM.h"
|
221
|
13 #include "llvm/ADT/SetVector.h"
|
|
14 #include "llvm/ADT/StringRef.h"
|
236
|
15 #include "llvm/BinaryFormat/MachO.h"
|
173
|
16 #include "llvm/Option/OptTable.h"
|
221
|
17 #include "llvm/Support/MemoryBuffer.h"
|
252
|
18 #include <optional>
|
221
|
19
|
|
20 #include <set>
|
|
21 #include <type_traits>
|
|
22
|
236
|
23 namespace lld::macho {
|
173
|
24
|
221
|
25 class DylibFile;
|
|
26 class InputFile;
|
|
27
|
252
|
28 class MachOOptTable : public llvm::opt::GenericOptTable {
|
173
|
29 public:
|
|
30 MachOOptTable();
|
|
31 llvm::opt::InputArgList parse(ArrayRef<const char *> argv);
|
221
|
32 void printHelp(const char *argv0, bool showHidden) const;
|
173
|
33 };
|
|
34
|
|
35 // Create enum with OPT_xxx values for each option in Options.td
|
|
36 enum {
|
|
37 OPT_INVALID = 0,
|
252
|
38 #define OPTION(...) LLVM_MAKE_OPT_ID(__VA_ARGS__),
|
173
|
39 #include "Options.inc"
|
|
40 #undef OPTION
|
|
41 };
|
|
42
|
221
|
43 void parseLCLinkerOption(InputFile *, unsigned argc, StringRef data);
|
|
44
|
|
45 std::string createResponseFile(const llvm::opt::InputArgList &args);
|
|
46
|
|
47 // Check for both libfoo.dylib and libfoo.tbd (in that order).
|
252
|
48 std::optional<StringRef> resolveDylibPath(llvm::StringRef path);
|
221
|
49
|
|
50 DylibFile *loadDylib(llvm::MemoryBufferRef mbref, DylibFile *umbrella = nullptr,
|
236
|
51 bool isBundleLoader = false,
|
|
52 bool explicitlyLinked = false);
|
|
53 void resetLoadedDylibs();
|
221
|
54
|
|
55 // Search for all possible combinations of `{root}/{name}.{extension}`.
|
|
56 // If \p extensions are not specified, then just search for `{root}/{name}`.
|
252
|
57 std::optional<llvm::StringRef>
|
221
|
58 findPathCombination(const llvm::Twine &name,
|
|
59 const std::vector<llvm::StringRef> &roots,
|
|
60 ArrayRef<llvm::StringRef> extensions = {""});
|
|
61
|
|
62 // If -syslibroot is specified, absolute paths to non-object files may be
|
|
63 // rerooted.
|
|
64 llvm::StringRef rerootPath(llvm::StringRef path);
|
|
65
|
|
66 uint32_t getModTime(llvm::StringRef path);
|
|
67
|
|
68 void printArchiveMemberLoad(StringRef reason, const InputFile *);
|
|
69
|
223
|
70 // Map simulator platforms to their underlying device platform.
|
236
|
71 llvm::MachO::PlatformType removeSimulator(llvm::MachO::PlatformType platform);
|
223
|
72
|
221
|
73 // Helper class to export dependency info.
|
|
74 class DependencyTracker {
|
|
75 public:
|
|
76 explicit DependencyTracker(llvm::StringRef path);
|
|
77
|
|
78 // Adds the given path to the set of not-found files.
|
|
79 inline void logFileNotFound(const Twine &path) {
|
|
80 if (active)
|
|
81 notFounds.insert(path.str());
|
|
82 }
|
|
83
|
236
|
84 // Writes the dependencies to specified path. The content is first sorted by
|
|
85 // OpCode and then by the filename (in alphabetical order).
|
221
|
86 void write(llvm::StringRef version,
|
|
87 const llvm::SetVector<InputFile *> &inputs,
|
|
88 llvm::StringRef output);
|
|
89
|
|
90 private:
|
|
91 enum DepOpCode : uint8_t {
|
|
92 // Denotes the linker version.
|
|
93 Version = 0x00,
|
|
94 // Denotes the input files.
|
|
95 Input = 0x10,
|
|
96 // Denotes the files that do not exist(?)
|
|
97 NotFound = 0x11,
|
|
98 // Denotes the output files.
|
|
99 Output = 0x40,
|
|
100 };
|
|
101
|
|
102 const llvm::StringRef path;
|
|
103 bool active;
|
|
104
|
|
105 // The paths need to be alphabetically ordered.
|
|
106 // We need to own the paths because some of them are temporarily
|
|
107 // constructed.
|
|
108 std::set<std::string> notFounds;
|
|
109 };
|
|
110
|
236
|
111 extern std::unique_ptr<DependencyTracker> depTracker;
|
221
|
112
|
236
|
113 } // namespace lld::macho
|
173
|
114
|
|
115 #endif
|