comparison lld/MachO/Driver.h @ 207:2e18cbf3894f

LLVM12
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 08 Jun 2021 06:07:14 +0900
parents 0572611fdcc8
children 5f17cb93ff66
comparison
equal deleted inserted replaced
173:0572611fdcc8 207:2e18cbf3894f
8 8
9 #ifndef LLD_MACHO_DRIVER_H 9 #ifndef LLD_MACHO_DRIVER_H
10 #define LLD_MACHO_DRIVER_H 10 #define LLD_MACHO_DRIVER_H
11 11
12 #include "lld/Common/LLVM.h" 12 #include "lld/Common/LLVM.h"
13 #include "llvm/ADT/Optional.h"
14 #include "llvm/ADT/SetVector.h"
15 #include "llvm/ADT/StringRef.h"
13 #include "llvm/Option/OptTable.h" 16 #include "llvm/Option/OptTable.h"
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
14 27
15 namespace lld { 28 namespace lld {
16 namespace macho { 29 namespace macho {
30
31 class DylibFile;
32 class InputFile;
17 33
18 class MachOOptTable : public llvm::opt::OptTable { 34 class MachOOptTable : public llvm::opt::OptTable {
19 public: 35 public:
20 MachOOptTable(); 36 MachOOptTable();
21 llvm::opt::InputArgList parse(ArrayRef<const char *> argv); 37 llvm::opt::InputArgList parse(ArrayRef<const char *> argv);
38 void printHelp(const char *argv0, bool showHidden) const;
22 }; 39 };
23 40
24 // Create enum with OPT_xxx values for each option in Options.td 41 // Create enum with OPT_xxx values for each option in Options.td
25 enum { 42 enum {
26 OPT_INVALID = 0, 43 OPT_INVALID = 0,
27 #define OPTION(_1, _2, ID, _4, _5, _6, _7, _8, _9, _10, _11, _12) OPT_##ID, 44 #define OPTION(_1, _2, ID, _4, _5, _6, _7, _8, _9, _10, _11, _12) OPT_##ID,
28 #include "Options.inc" 45 #include "Options.inc"
29 #undef OPTION 46 #undef OPTION
30 }; 47 };
31 48
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
32 } // namespace macho 124 } // namespace macho
33 } // namespace lld 125 } // namespace lld
34 126
35 #endif 127 #endif