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"
|
207
|
13 #include "llvm/ADT/Optional.h"
|
|
14 #include "llvm/ADT/SetVector.h"
|
|
15 #include "llvm/ADT/StringRef.h"
|
173
|
16 #include "llvm/Option/OptTable.h"
|
207
|
17 #include "llvm/Support/MemoryBuffer.h"
|
|
18
|
|
19 #include <set>
|
|
20 #include <type_traits>
|
|
21
|
|
22 namespace llvm {
|
|
23 namespace MachO {
|
|
24 class InterfaceFile;
|
|
25 } // namespace MachO
|
|
26 } // namespace llvm
|
173
|
27
|
|
28 namespace lld {
|
|
29 namespace macho {
|
|
30
|
207
|
31 class DylibFile;
|
|
32 class InputFile;
|
|
33
|
173
|
34 class MachOOptTable : public llvm::opt::OptTable {
|
|
35 public:
|
|
36 MachOOptTable();
|
|
37 llvm::opt::InputArgList parse(ArrayRef<const char *> argv);
|
207
|
38 void printHelp(const char *argv0, bool showHidden) const;
|
173
|
39 };
|
|
40
|
|
41 // Create enum with OPT_xxx values for each option in Options.td
|
|
42 enum {
|
|
43 OPT_INVALID = 0,
|
|
44 #define OPTION(_1, _2, ID, _4, _5, _6, _7, _8, _9, _10, _11, _12) OPT_##ID,
|
|
45 #include "Options.inc"
|
|
46 #undef OPTION
|
|
47 };
|
|
48
|
207
|
49 void parseLCLinkerOption(InputFile *, unsigned argc, StringRef data);
|
|
50
|
|
51 std::string createResponseFile(const llvm::opt::InputArgList &args);
|
|
52
|
|
53 // Check for both libfoo.dylib and libfoo.tbd (in that order).
|
|
54 llvm::Optional<std::string> resolveDylibPath(llvm::StringRef path);
|
|
55
|
|
56 DylibFile *loadDylib(llvm::MemoryBufferRef mbref, DylibFile *umbrella = nullptr,
|
|
57 bool isBundleLoader = false);
|
|
58
|
|
59 // Search for all possible combinations of `{root}/{name}.{extension}`.
|
|
60 // If \p extensions are not specified, then just search for `{root}/{name}`.
|
|
61 llvm::Optional<llvm::StringRef>
|
|
62 findPathCombination(const llvm::Twine &name,
|
|
63 const std::vector<llvm::StringRef> &roots,
|
|
64 ArrayRef<llvm::StringRef> extensions = {""});
|
|
65
|
|
66 // If -syslibroot is specified, absolute paths to non-object files may be
|
|
67 // rerooted.
|
|
68 llvm::StringRef rerootPath(llvm::StringRef path);
|
|
69
|
|
70 llvm::Optional<InputFile *> loadArchiveMember(MemoryBufferRef, uint32_t modTime,
|
|
71 StringRef archiveName,
|
|
72 bool objCOnly);
|
|
73
|
|
74 uint32_t getModTime(llvm::StringRef path);
|
|
75
|
|
76 void printArchiveMemberLoad(StringRef reason, const InputFile *);
|
|
77
|
|
78 // Helper class to export dependency info.
|
|
79 class DependencyTracker {
|
|
80 public:
|
|
81 explicit DependencyTracker(llvm::StringRef path);
|
|
82
|
|
83 // Adds the given path to the set of not-found files.
|
|
84 inline void logFileNotFound(std::string path) {
|
|
85 if (active)
|
|
86 notFounds.insert(std::move(path));
|
|
87 }
|
|
88
|
|
89 inline void logFileNotFound(const Twine &path) {
|
|
90 if (active)
|
|
91 notFounds.insert(path.str());
|
|
92 }
|
|
93
|
|
94 // Writes the dependencies to specified path.
|
|
95 // The content is sorted by its Op Code, then within each section,
|
|
96 // alphabetical order.
|
|
97 void write(llvm::StringRef version,
|
|
98 const llvm::SetVector<InputFile *> &inputs,
|
|
99 llvm::StringRef output);
|
|
100
|
|
101 private:
|
|
102 enum DepOpCode : uint8_t {
|
|
103 // Denotes the linker version.
|
|
104 Version = 0x00,
|
|
105 // Denotes the input files.
|
|
106 Input = 0x10,
|
|
107 // Denotes the files that do not exist(?)
|
|
108 NotFound = 0x11,
|
|
109 // Denotes the output files.
|
|
110 Output = 0x40,
|
|
111 };
|
|
112
|
|
113 const llvm::StringRef path;
|
|
114 bool active;
|
|
115
|
|
116 // The paths need to be alphabetically ordered.
|
|
117 // We need to own the paths because some of them are temporarily
|
|
118 // constructed.
|
|
119 std::set<std::string> notFounds;
|
|
120 };
|
|
121
|
|
122 extern DependencyTracker *depTracker;
|
|
123
|
173
|
124 } // namespace macho
|
|
125 } // namespace lld
|
|
126
|
|
127 #endif
|