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