[lld][WebAssembly] Add `--table-base` setting
[llvm-project.git] / lld / MachO / Driver.h
blob82cd1880ecab1b03d9ef569e915a249c642026de
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 //===----------------------------------------------------------------------===//
9 #ifndef LLD_MACHO_DRIVER_H
10 #define LLD_MACHO_DRIVER_H
12 #include "lld/Common/LLVM.h"
13 #include "llvm/ADT/SetVector.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/BinaryFormat/MachO.h"
16 #include "llvm/Option/OptTable.h"
17 #include "llvm/Support/MemoryBuffer.h"
18 #include <optional>
20 #include <set>
21 #include <type_traits>
23 namespace lld::macho {
25 class DylibFile;
26 class InputFile;
28 class MachOOptTable : public llvm::opt::GenericOptTable {
29 public:
30 MachOOptTable();
31 llvm::opt::InputArgList parse(ArrayRef<const char *> argv);
32 void printHelp(const char *argv0, bool showHidden) const;
35 // Create enum with OPT_xxx values for each option in Options.td
36 enum {
37 OPT_INVALID = 0,
38 #define OPTION(...) LLVM_MAKE_OPT_ID(__VA_ARGS__),
39 #include "Options.inc"
40 #undef OPTION
43 void parseLCLinkerOption(llvm::SmallVectorImpl<StringRef> &LCLinkerOptions,
44 InputFile *f, unsigned argc, StringRef data);
45 void resolveLCLinkerOptions();
47 std::string createResponseFile(const llvm::opt::InputArgList &args);
49 // Check for both libfoo.dylib and libfoo.tbd (in that order).
50 std::optional<StringRef> resolveDylibPath(llvm::StringRef path);
52 DylibFile *loadDylib(llvm::MemoryBufferRef mbref, DylibFile *umbrella = nullptr,
53 bool isBundleLoader = false,
54 bool explicitlyLinked = false);
55 void resetLoadedDylibs();
57 // Search for all possible combinations of `{root}/{name}.{extension}`.
58 // If \p extensions are not specified, then just search for `{root}/{name}`.
59 std::optional<llvm::StringRef>
60 findPathCombination(const llvm::Twine &name,
61 const std::vector<llvm::StringRef> &roots,
62 ArrayRef<llvm::StringRef> extensions = {""});
64 // If -syslibroot is specified, absolute paths to non-object files may be
65 // rerooted.
66 llvm::StringRef rerootPath(llvm::StringRef path);
68 uint32_t getModTime(llvm::StringRef path);
70 void printArchiveMemberLoad(StringRef reason, const InputFile *);
72 // Map simulator platforms to their underlying device platform.
73 llvm::MachO::PlatformType removeSimulator(llvm::MachO::PlatformType platform);
75 // Helper class to export dependency info.
76 class DependencyTracker {
77 public:
78 explicit DependencyTracker(llvm::StringRef path);
80 // Adds the given path to the set of not-found files.
81 inline void logFileNotFound(const Twine &path) {
82 if (active)
83 notFounds.insert(path.str());
86 // Writes the dependencies to specified path. The content is first sorted by
87 // OpCode and then by the filename (in alphabetical order).
88 void write(llvm::StringRef version,
89 const llvm::SetVector<InputFile *> &inputs,
90 llvm::StringRef output);
92 private:
93 enum DepOpCode : uint8_t {
94 // Denotes the linker version.
95 Version = 0x00,
96 // Denotes the input files.
97 Input = 0x10,
98 // Denotes the files that do not exist(?)
99 NotFound = 0x11,
100 // Denotes the output files.
101 Output = 0x40,
104 const llvm::StringRef path;
105 bool active;
107 // The paths need to be alphabetically ordered.
108 // We need to own the paths because some of them are temporarily
109 // constructed.
110 std::set<std::string> notFounds;
113 extern std::unique_ptr<DependencyTracker> depTracker;
115 } // namespace lld::macho
117 #endif