xref: /freebsd-src/contrib/llvm-project/lld/MachO/DriverUtils.cpp (revision 81ad626541db97eb356e2c1d4a20eb2a26a766ab)
1e8d8bef9SDimitry Andric //===- DriverUtils.cpp ----------------------------------------------------===//
2e8d8bef9SDimitry Andric //
3e8d8bef9SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4e8d8bef9SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5e8d8bef9SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6e8d8bef9SDimitry Andric //
7e8d8bef9SDimitry Andric //===----------------------------------------------------------------------===//
8e8d8bef9SDimitry Andric 
9e8d8bef9SDimitry Andric #include "Config.h"
10fe6060f1SDimitry Andric #include "Driver.h"
11e8d8bef9SDimitry Andric #include "InputFiles.h"
12fe6060f1SDimitry Andric #include "ObjC.h"
13fe6060f1SDimitry Andric #include "Target.h"
14e8d8bef9SDimitry Andric 
15e8d8bef9SDimitry Andric #include "lld/Common/Args.h"
1604eeddc0SDimitry Andric #include "lld/Common/CommonLinkerContext.h"
17e8d8bef9SDimitry Andric #include "lld/Common/Reproduce.h"
18e8d8bef9SDimitry Andric #include "llvm/ADT/CachedHashString.h"
19e8d8bef9SDimitry Andric #include "llvm/ADT/DenseMap.h"
20fe6060f1SDimitry Andric #include "llvm/LTO/LTO.h"
21e8d8bef9SDimitry Andric #include "llvm/Option/Arg.h"
22e8d8bef9SDimitry Andric #include "llvm/Option/ArgList.h"
23e8d8bef9SDimitry Andric #include "llvm/Option/Option.h"
24e8d8bef9SDimitry Andric #include "llvm/Support/CommandLine.h"
25fe6060f1SDimitry Andric #include "llvm/Support/FileSystem.h"
26e8d8bef9SDimitry Andric #include "llvm/Support/Path.h"
27fe6060f1SDimitry Andric #include "llvm/TextAPI/InterfaceFile.h"
28fe6060f1SDimitry Andric #include "llvm/TextAPI/TextAPIReader.h"
29e8d8bef9SDimitry Andric 
30e8d8bef9SDimitry Andric using namespace llvm;
31e8d8bef9SDimitry Andric using namespace llvm::MachO;
32e8d8bef9SDimitry Andric using namespace llvm::opt;
33e8d8bef9SDimitry Andric using namespace llvm::sys;
34e8d8bef9SDimitry Andric using namespace lld;
35e8d8bef9SDimitry Andric using namespace lld::macho;
36e8d8bef9SDimitry Andric 
37e8d8bef9SDimitry Andric // Create prefix string literals used in Options.td
38e8d8bef9SDimitry Andric #define PREFIX(NAME, VALUE) const char *NAME[] = VALUE;
39e8d8bef9SDimitry Andric #include "Options.inc"
40e8d8bef9SDimitry Andric #undef PREFIX
41e8d8bef9SDimitry Andric 
42e8d8bef9SDimitry Andric // Create table mapping all options defined in Options.td
43fe6060f1SDimitry Andric static const OptTable::Info optInfo[] = {
44e8d8bef9SDimitry Andric #define OPTION(X1, X2, ID, KIND, GROUP, ALIAS, X7, X8, X9, X10, X11, X12)      \
45fe6060f1SDimitry Andric   {X1, X2, X10,         X11,         OPT_##ID, Option::KIND##Class,            \
46e8d8bef9SDimitry Andric    X9, X8, OPT_##GROUP, OPT_##ALIAS, X7,       X12},
47e8d8bef9SDimitry Andric #include "Options.inc"
48e8d8bef9SDimitry Andric #undef OPTION
49e8d8bef9SDimitry Andric };
50e8d8bef9SDimitry Andric 
51e8d8bef9SDimitry Andric MachOOptTable::MachOOptTable() : OptTable(optInfo) {}
52e8d8bef9SDimitry Andric 
53e8d8bef9SDimitry Andric // Set color diagnostics according to --color-diagnostics={auto,always,never}
54e8d8bef9SDimitry Andric // or --no-color-diagnostics flags.
55fe6060f1SDimitry Andric static void handleColorDiagnostics(InputArgList &args) {
56fe6060f1SDimitry Andric   const Arg *arg =
57fe6060f1SDimitry Andric       args.getLastArg(OPT_color_diagnostics, OPT_color_diagnostics_eq,
58e8d8bef9SDimitry Andric                       OPT_no_color_diagnostics);
59e8d8bef9SDimitry Andric   if (!arg)
60e8d8bef9SDimitry Andric     return;
61e8d8bef9SDimitry Andric   if (arg->getOption().getID() == OPT_color_diagnostics) {
62e8d8bef9SDimitry Andric     lld::errs().enable_colors(true);
63e8d8bef9SDimitry Andric   } else if (arg->getOption().getID() == OPT_no_color_diagnostics) {
64e8d8bef9SDimitry Andric     lld::errs().enable_colors(false);
65e8d8bef9SDimitry Andric   } else {
66e8d8bef9SDimitry Andric     StringRef s = arg->getValue();
67e8d8bef9SDimitry Andric     if (s == "always")
68e8d8bef9SDimitry Andric       lld::errs().enable_colors(true);
69e8d8bef9SDimitry Andric     else if (s == "never")
70e8d8bef9SDimitry Andric       lld::errs().enable_colors(false);
71e8d8bef9SDimitry Andric     else if (s != "auto")
72e8d8bef9SDimitry Andric       error("unknown option: --color-diagnostics=" + s);
73e8d8bef9SDimitry Andric   }
74e8d8bef9SDimitry Andric }
75e8d8bef9SDimitry Andric 
76fe6060f1SDimitry Andric InputArgList MachOOptTable::parse(ArrayRef<const char *> argv) {
77e8d8bef9SDimitry Andric   // Make InputArgList from string vectors.
78e8d8bef9SDimitry Andric   unsigned missingIndex;
79e8d8bef9SDimitry Andric   unsigned missingCount;
80e8d8bef9SDimitry Andric   SmallVector<const char *, 256> vec(argv.data(), argv.data() + argv.size());
81e8d8bef9SDimitry Andric 
82e8d8bef9SDimitry Andric   // Expand response files (arguments in the form of @<filename>)
83e8d8bef9SDimitry Andric   // and then parse the argument again.
8404eeddc0SDimitry Andric   cl::ExpandResponseFiles(saver(), cl::TokenizeGNUCommandLine, vec);
85fe6060f1SDimitry Andric   InputArgList args = ParseArgs(vec, missingIndex, missingCount);
86e8d8bef9SDimitry Andric 
87e8d8bef9SDimitry Andric   // Handle -fatal_warnings early since it converts missing argument warnings
88e8d8bef9SDimitry Andric   // to errors.
89e8d8bef9SDimitry Andric   errorHandler().fatalWarnings = args.hasArg(OPT_fatal_warnings);
90*81ad6265SDimitry Andric   errorHandler().suppressWarnings = args.hasArg(OPT_w);
91e8d8bef9SDimitry Andric 
92e8d8bef9SDimitry Andric   if (missingCount)
93e8d8bef9SDimitry Andric     error(Twine(args.getArgString(missingIndex)) + ": missing argument");
94e8d8bef9SDimitry Andric 
95e8d8bef9SDimitry Andric   handleColorDiagnostics(args);
96e8d8bef9SDimitry Andric 
97fe6060f1SDimitry Andric   for (const Arg *arg : args.filtered(OPT_UNKNOWN)) {
98e8d8bef9SDimitry Andric     std::string nearest;
99e8d8bef9SDimitry Andric     if (findNearest(arg->getAsString(args), nearest) > 1)
100e8d8bef9SDimitry Andric       error("unknown argument '" + arg->getAsString(args) + "'");
101e8d8bef9SDimitry Andric     else
102e8d8bef9SDimitry Andric       error("unknown argument '" + arg->getAsString(args) +
103e8d8bef9SDimitry Andric             "', did you mean '" + nearest + "'");
104e8d8bef9SDimitry Andric   }
105e8d8bef9SDimitry Andric   return args;
106e8d8bef9SDimitry Andric }
107e8d8bef9SDimitry Andric 
108e8d8bef9SDimitry Andric void MachOOptTable::printHelp(const char *argv0, bool showHidden) const {
109fe6060f1SDimitry Andric   OptTable::printHelp(lld::outs(),
110fe6060f1SDimitry Andric                       (std::string(argv0) + " [options] file...").c_str(),
111e8d8bef9SDimitry Andric                       "LLVM Linker", showHidden);
112e8d8bef9SDimitry Andric   lld::outs() << "\n";
113e8d8bef9SDimitry Andric }
114e8d8bef9SDimitry Andric 
115e8d8bef9SDimitry Andric static std::string rewritePath(StringRef s) {
116e8d8bef9SDimitry Andric   if (fs::exists(s))
117e8d8bef9SDimitry Andric     return relativeToRoot(s);
118e8d8bef9SDimitry Andric   return std::string(s);
119e8d8bef9SDimitry Andric }
120e8d8bef9SDimitry Andric 
121fe6060f1SDimitry Andric static std::string rewriteInputPath(StringRef s) {
122fe6060f1SDimitry Andric   // Don't bother rewriting "absolute" paths that are actually under the
123fe6060f1SDimitry Andric   // syslibroot; simply rewriting the syslibroot is sufficient.
124fe6060f1SDimitry Andric   if (rerootPath(s) == s && fs::exists(s))
125fe6060f1SDimitry Andric     return relativeToRoot(s);
126fe6060f1SDimitry Andric   return std::string(s);
127fe6060f1SDimitry Andric }
128fe6060f1SDimitry Andric 
129e8d8bef9SDimitry Andric // Reconstructs command line arguments so that so that you can re-run
130e8d8bef9SDimitry Andric // the same command with the same inputs. This is for --reproduce.
131fe6060f1SDimitry Andric std::string macho::createResponseFile(const InputArgList &args) {
132e8d8bef9SDimitry Andric   SmallString<0> data;
133e8d8bef9SDimitry Andric   raw_svector_ostream os(data);
134e8d8bef9SDimitry Andric 
135e8d8bef9SDimitry Andric   // Copy the command line to the output while rewriting paths.
136fe6060f1SDimitry Andric   for (const Arg *arg : args) {
137e8d8bef9SDimitry Andric     switch (arg->getOption().getID()) {
138e8d8bef9SDimitry Andric     case OPT_reproduce:
139e8d8bef9SDimitry Andric       break;
140e8d8bef9SDimitry Andric     case OPT_INPUT:
141fe6060f1SDimitry Andric       os << quote(rewriteInputPath(arg->getValue())) << "\n";
142e8d8bef9SDimitry Andric       break;
143e8d8bef9SDimitry Andric     case OPT_o:
144e8d8bef9SDimitry Andric       os << "-o " << quote(path::filename(arg->getValue())) << "\n";
145e8d8bef9SDimitry Andric       break;
146e8d8bef9SDimitry Andric     case OPT_filelist:
147e8d8bef9SDimitry Andric       if (Optional<MemoryBufferRef> buffer = readFile(arg->getValue()))
148e8d8bef9SDimitry Andric         for (StringRef path : args::getLines(*buffer))
149fe6060f1SDimitry Andric           os << quote(rewriteInputPath(path)) << "\n";
150e8d8bef9SDimitry Andric       break;
151e8d8bef9SDimitry Andric     case OPT_force_load:
152fe6060f1SDimitry Andric     case OPT_weak_library:
153fe6060f1SDimitry Andric       os << arg->getSpelling() << " "
154fe6060f1SDimitry Andric          << quote(rewriteInputPath(arg->getValue())) << "\n";
155fe6060f1SDimitry Andric       break;
156e8d8bef9SDimitry Andric     case OPT_F:
157e8d8bef9SDimitry Andric     case OPT_L:
158fe6060f1SDimitry Andric     case OPT_bundle_loader:
159fe6060f1SDimitry Andric     case OPT_exported_symbols_list:
160e8d8bef9SDimitry Andric     case OPT_order_file:
161fe6060f1SDimitry Andric     case OPT_rpath:
162fe6060f1SDimitry Andric     case OPT_syslibroot:
163fe6060f1SDimitry Andric     case OPT_unexported_symbols_list:
164e8d8bef9SDimitry Andric       os << arg->getSpelling() << " " << quote(rewritePath(arg->getValue()))
165e8d8bef9SDimitry Andric          << "\n";
166e8d8bef9SDimitry Andric       break;
167e8d8bef9SDimitry Andric     case OPT_sectcreate:
168e8d8bef9SDimitry Andric       os << arg->getSpelling() << " " << quote(arg->getValue(0)) << " "
169e8d8bef9SDimitry Andric          << quote(arg->getValue(1)) << " "
170e8d8bef9SDimitry Andric          << quote(rewritePath(arg->getValue(2))) << "\n";
171e8d8bef9SDimitry Andric       break;
172e8d8bef9SDimitry Andric     default:
173e8d8bef9SDimitry Andric       os << toString(*arg) << "\n";
174e8d8bef9SDimitry Andric     }
175e8d8bef9SDimitry Andric   }
176e8d8bef9SDimitry Andric   return std::string(data.str());
177e8d8bef9SDimitry Andric }
178e8d8bef9SDimitry Andric 
179fe6060f1SDimitry Andric static void searchedDylib(const Twine &path, bool found) {
180fe6060f1SDimitry Andric   if (config->printDylibSearch)
181fe6060f1SDimitry Andric     message("searched " + path + (found ? ", found " : ", not found"));
182fe6060f1SDimitry Andric   if (!found)
183fe6060f1SDimitry Andric     depTracker->logFileNotFound(path);
184fe6060f1SDimitry Andric }
185fe6060f1SDimitry Andric 
186349cc55cSDimitry Andric Optional<StringRef> macho::resolveDylibPath(StringRef dylibPath) {
187e8d8bef9SDimitry Andric   // TODO: if a tbd and dylib are both present, we should check to make sure
188e8d8bef9SDimitry Andric   // they are consistent.
189fe6060f1SDimitry Andric   SmallString<261> tbdPath = dylibPath;
190fe6060f1SDimitry Andric   path::replace_extension(tbdPath, ".tbd");
191fe6060f1SDimitry Andric   bool tbdExists = fs::exists(tbdPath);
192fe6060f1SDimitry Andric   searchedDylib(tbdPath, tbdExists);
193fe6060f1SDimitry Andric   if (tbdExists)
19404eeddc0SDimitry Andric     return saver().save(tbdPath.str());
195349cc55cSDimitry Andric 
196349cc55cSDimitry Andric   bool dylibExists = fs::exists(dylibPath);
197349cc55cSDimitry Andric   searchedDylib(dylibPath, dylibExists);
198349cc55cSDimitry Andric   if (dylibExists)
19904eeddc0SDimitry Andric     return saver().save(dylibPath);
200e8d8bef9SDimitry Andric   return {};
201e8d8bef9SDimitry Andric }
202e8d8bef9SDimitry Andric 
203e8d8bef9SDimitry Andric // It's not uncommon to have multiple attempts to load a single dylib,
204e8d8bef9SDimitry Andric // especially if it's a commonly re-exported core library.
205e8d8bef9SDimitry Andric static DenseMap<CachedHashStringRef, DylibFile *> loadedDylibs;
206e8d8bef9SDimitry Andric 
207fe6060f1SDimitry Andric DylibFile *macho::loadDylib(MemoryBufferRef mbref, DylibFile *umbrella,
208*81ad6265SDimitry Andric                             bool isBundleLoader, bool explicitlyLinked) {
209fe6060f1SDimitry Andric   CachedHashStringRef path(mbref.getBufferIdentifier());
210fe6060f1SDimitry Andric   DylibFile *&file = loadedDylibs[path];
211*81ad6265SDimitry Andric   if (file) {
212*81ad6265SDimitry Andric     if (explicitlyLinked)
213*81ad6265SDimitry Andric       file->explicitlyLinked = explicitlyLinked;
214e8d8bef9SDimitry Andric     return file;
215*81ad6265SDimitry Andric   }
216e8d8bef9SDimitry Andric 
217fe6060f1SDimitry Andric   DylibFile *newFile;
218e8d8bef9SDimitry Andric   file_magic magic = identify_magic(mbref.getBuffer());
219e8d8bef9SDimitry Andric   if (magic == file_magic::tapi_file) {
220e8d8bef9SDimitry Andric     Expected<std::unique_ptr<InterfaceFile>> result = TextAPIReader::get(mbref);
221e8d8bef9SDimitry Andric     if (!result) {
222e8d8bef9SDimitry Andric       error("could not load TAPI file at " + mbref.getBufferIdentifier() +
223e8d8bef9SDimitry Andric             ": " + toString(result.takeError()));
224fe6060f1SDimitry Andric       return nullptr;
225e8d8bef9SDimitry Andric     }
226*81ad6265SDimitry Andric     file =
227*81ad6265SDimitry Andric         make<DylibFile>(**result, umbrella, isBundleLoader, explicitlyLinked);
228fe6060f1SDimitry Andric 
229fe6060f1SDimitry Andric     // parseReexports() can recursively call loadDylib(). That's fine since
230fe6060f1SDimitry Andric     // we wrote the DylibFile we just loaded to the loadDylib cache via the
231fe6060f1SDimitry Andric     // `file` reference. But the recursive load can grow loadDylibs, so the
232fe6060f1SDimitry Andric     // `file` reference might become invalid after parseReexports() -- so copy
233fe6060f1SDimitry Andric     // the pointer it refers to before continuing.
234fe6060f1SDimitry Andric     newFile = file;
235fe6060f1SDimitry Andric     if (newFile->exportingFile)
236fe6060f1SDimitry Andric       newFile->parseReexports(**result);
237e8d8bef9SDimitry Andric   } else {
238e8d8bef9SDimitry Andric     assert(magic == file_magic::macho_dynamically_linked_shared_lib ||
239fe6060f1SDimitry Andric            magic == file_magic::macho_dynamically_linked_shared_lib_stub ||
240fe6060f1SDimitry Andric            magic == file_magic::macho_executable ||
241fe6060f1SDimitry Andric            magic == file_magic::macho_bundle);
242*81ad6265SDimitry Andric     file = make<DylibFile>(mbref, umbrella, isBundleLoader, explicitlyLinked);
243fe6060f1SDimitry Andric 
244fe6060f1SDimitry Andric     // parseLoadCommands() can also recursively call loadDylib(). See comment
245fe6060f1SDimitry Andric     // in previous block for why this means we must copy `file` here.
246fe6060f1SDimitry Andric     newFile = file;
247fe6060f1SDimitry Andric     if (newFile->exportingFile)
248fe6060f1SDimitry Andric       newFile->parseLoadCommands(mbref);
249e8d8bef9SDimitry Andric   }
250fe6060f1SDimitry Andric   return newFile;
251fe6060f1SDimitry Andric }
252fe6060f1SDimitry Andric 
253349cc55cSDimitry Andric void macho::resetLoadedDylibs() { loadedDylibs.clear(); }
254349cc55cSDimitry Andric 
255fe6060f1SDimitry Andric Optional<StringRef>
256fe6060f1SDimitry Andric macho::findPathCombination(const Twine &name,
257fe6060f1SDimitry Andric                            const std::vector<StringRef> &roots,
258fe6060f1SDimitry Andric                            ArrayRef<StringRef> extensions) {
259fe6060f1SDimitry Andric   SmallString<261> base;
260fe6060f1SDimitry Andric   for (StringRef dir : roots) {
261fe6060f1SDimitry Andric     base = dir;
262fe6060f1SDimitry Andric     path::append(base, name);
263fe6060f1SDimitry Andric     for (StringRef ext : extensions) {
264fe6060f1SDimitry Andric       Twine location = base + ext;
265fe6060f1SDimitry Andric       bool exists = fs::exists(location);
266fe6060f1SDimitry Andric       searchedDylib(location, exists);
267fe6060f1SDimitry Andric       if (exists)
26804eeddc0SDimitry Andric         return saver().save(location.str());
269fe6060f1SDimitry Andric     }
270fe6060f1SDimitry Andric   }
271fe6060f1SDimitry Andric   return {};
272fe6060f1SDimitry Andric }
273fe6060f1SDimitry Andric 
274fe6060f1SDimitry Andric StringRef macho::rerootPath(StringRef path) {
275fe6060f1SDimitry Andric   if (!path::is_absolute(path, path::Style::posix) || path.endswith(".o"))
276fe6060f1SDimitry Andric     return path;
277fe6060f1SDimitry Andric 
278fe6060f1SDimitry Andric   if (Optional<StringRef> rerootedPath =
279fe6060f1SDimitry Andric           findPathCombination(path, config->systemLibraryRoots))
280fe6060f1SDimitry Andric     return *rerootedPath;
281fe6060f1SDimitry Andric 
282fe6060f1SDimitry Andric   return path;
283fe6060f1SDimitry Andric }
284fe6060f1SDimitry Andric 
285e8d8bef9SDimitry Andric uint32_t macho::getModTime(StringRef path) {
286fe6060f1SDimitry Andric   if (config->zeroModTime)
287fe6060f1SDimitry Andric     return 0;
288fe6060f1SDimitry Andric 
289e8d8bef9SDimitry Andric   fs::file_status stat;
290e8d8bef9SDimitry Andric   if (!fs::status(path, stat))
291e8d8bef9SDimitry Andric     if (fs::exists(stat))
292e8d8bef9SDimitry Andric       return toTimeT(stat.getLastModificationTime());
293e8d8bef9SDimitry Andric 
294e8d8bef9SDimitry Andric   warn("failed to get modification time of " + path);
295e8d8bef9SDimitry Andric   return 0;
296e8d8bef9SDimitry Andric }
297e8d8bef9SDimitry Andric 
298e8d8bef9SDimitry Andric void macho::printArchiveMemberLoad(StringRef reason, const InputFile *f) {
299e8d8bef9SDimitry Andric   if (config->printEachFile)
300e8d8bef9SDimitry Andric     message(toString(f));
301e8d8bef9SDimitry Andric   if (config->printWhyLoad)
302e8d8bef9SDimitry Andric     message(reason + " forced load of " + toString(f));
303e8d8bef9SDimitry Andric }
304fe6060f1SDimitry Andric 
305fe6060f1SDimitry Andric macho::DependencyTracker::DependencyTracker(StringRef path)
306fe6060f1SDimitry Andric     : path(path), active(!path.empty()) {
307fe6060f1SDimitry Andric   if (active && fs::exists(path) && !fs::can_write(path)) {
308fe6060f1SDimitry Andric     warn("Ignoring dependency_info option since specified path is not "
309fe6060f1SDimitry Andric          "writeable.");
310fe6060f1SDimitry Andric     active = false;
311fe6060f1SDimitry Andric   }
312fe6060f1SDimitry Andric }
313fe6060f1SDimitry Andric 
314fe6060f1SDimitry Andric void macho::DependencyTracker::write(StringRef version,
315fe6060f1SDimitry Andric                                      const SetVector<InputFile *> &inputs,
316fe6060f1SDimitry Andric                                      StringRef output) {
317fe6060f1SDimitry Andric   if (!active)
318fe6060f1SDimitry Andric     return;
319fe6060f1SDimitry Andric 
320fe6060f1SDimitry Andric   std::error_code ec;
321fe6060f1SDimitry Andric   raw_fd_ostream os(path, ec, fs::OF_None);
322fe6060f1SDimitry Andric   if (ec) {
323fe6060f1SDimitry Andric     warn("Error writing dependency info to file");
324fe6060f1SDimitry Andric     return;
325fe6060f1SDimitry Andric   }
326fe6060f1SDimitry Andric 
327fe6060f1SDimitry Andric   auto addDep = [&os](DepOpCode opcode, const StringRef &path) {
328fe6060f1SDimitry Andric     // XXX: Even though DepOpCode's underlying type is uint8_t,
329fe6060f1SDimitry Andric     // this cast is still needed because Clang older than 10.x has a bug,
330fe6060f1SDimitry Andric     // where it doesn't know to cast the enum to its underlying type.
331fe6060f1SDimitry Andric     // Hence `<< DepOpCode` is ambiguous to it.
332fe6060f1SDimitry Andric     os << static_cast<uint8_t>(opcode);
333fe6060f1SDimitry Andric     os << path;
334fe6060f1SDimitry Andric     os << '\0';
335fe6060f1SDimitry Andric   };
336fe6060f1SDimitry Andric 
337fe6060f1SDimitry Andric   addDep(DepOpCode::Version, version);
338fe6060f1SDimitry Andric 
339fe6060f1SDimitry Andric   // Sort the input by its names.
340fe6060f1SDimitry Andric   std::vector<StringRef> inputNames;
341fe6060f1SDimitry Andric   inputNames.reserve(inputs.size());
342fe6060f1SDimitry Andric   for (InputFile *f : inputs)
343fe6060f1SDimitry Andric     inputNames.push_back(f->getName());
344fe6060f1SDimitry Andric   llvm::sort(inputNames);
345fe6060f1SDimitry Andric 
346fe6060f1SDimitry Andric   for (const StringRef &in : inputNames)
347fe6060f1SDimitry Andric     addDep(DepOpCode::Input, in);
348fe6060f1SDimitry Andric 
349fe6060f1SDimitry Andric   for (const std::string &f : notFounds)
350fe6060f1SDimitry Andric     addDep(DepOpCode::NotFound, f);
351fe6060f1SDimitry Andric 
352fe6060f1SDimitry Andric   addDep(DepOpCode::Output, output);
353fe6060f1SDimitry Andric }
354