xref: /freebsd-src/contrib/llvm-project/lld/MachO/DriverUtils.cpp (revision 972a253a57b6f144b0e4a3e2080a2a0076ec55a0)
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);
9081ad6265SDimitry 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:
153*972a253aSDimitry Andric     case OPT_load_hidden:
154fe6060f1SDimitry Andric       os << arg->getSpelling() << " "
155fe6060f1SDimitry Andric          << quote(rewriteInputPath(arg->getValue())) << "\n";
156fe6060f1SDimitry Andric       break;
157e8d8bef9SDimitry Andric     case OPT_F:
158e8d8bef9SDimitry Andric     case OPT_L:
159fe6060f1SDimitry Andric     case OPT_bundle_loader:
160fe6060f1SDimitry Andric     case OPT_exported_symbols_list:
161e8d8bef9SDimitry Andric     case OPT_order_file:
162fe6060f1SDimitry Andric     case OPT_rpath:
163fe6060f1SDimitry Andric     case OPT_syslibroot:
164fe6060f1SDimitry Andric     case OPT_unexported_symbols_list:
165e8d8bef9SDimitry Andric       os << arg->getSpelling() << " " << quote(rewritePath(arg->getValue()))
166e8d8bef9SDimitry Andric          << "\n";
167e8d8bef9SDimitry Andric       break;
168e8d8bef9SDimitry Andric     case OPT_sectcreate:
169e8d8bef9SDimitry Andric       os << arg->getSpelling() << " " << quote(arg->getValue(0)) << " "
170e8d8bef9SDimitry Andric          << quote(arg->getValue(1)) << " "
171e8d8bef9SDimitry Andric          << quote(rewritePath(arg->getValue(2))) << "\n";
172e8d8bef9SDimitry Andric       break;
173e8d8bef9SDimitry Andric     default:
174e8d8bef9SDimitry Andric       os << toString(*arg) << "\n";
175e8d8bef9SDimitry Andric     }
176e8d8bef9SDimitry Andric   }
177e8d8bef9SDimitry Andric   return std::string(data.str());
178e8d8bef9SDimitry Andric }
179e8d8bef9SDimitry Andric 
180fe6060f1SDimitry Andric static void searchedDylib(const Twine &path, bool found) {
181fe6060f1SDimitry Andric   if (config->printDylibSearch)
182fe6060f1SDimitry Andric     message("searched " + path + (found ? ", found " : ", not found"));
183fe6060f1SDimitry Andric   if (!found)
184fe6060f1SDimitry Andric     depTracker->logFileNotFound(path);
185fe6060f1SDimitry Andric }
186fe6060f1SDimitry Andric 
187349cc55cSDimitry Andric Optional<StringRef> macho::resolveDylibPath(StringRef dylibPath) {
188e8d8bef9SDimitry Andric   // TODO: if a tbd and dylib are both present, we should check to make sure
189e8d8bef9SDimitry Andric   // they are consistent.
190fe6060f1SDimitry Andric   SmallString<261> tbdPath = dylibPath;
191fe6060f1SDimitry Andric   path::replace_extension(tbdPath, ".tbd");
192fe6060f1SDimitry Andric   bool tbdExists = fs::exists(tbdPath);
193fe6060f1SDimitry Andric   searchedDylib(tbdPath, tbdExists);
194fe6060f1SDimitry Andric   if (tbdExists)
19504eeddc0SDimitry Andric     return saver().save(tbdPath.str());
196349cc55cSDimitry Andric 
197349cc55cSDimitry Andric   bool dylibExists = fs::exists(dylibPath);
198349cc55cSDimitry Andric   searchedDylib(dylibPath, dylibExists);
199349cc55cSDimitry Andric   if (dylibExists)
20004eeddc0SDimitry Andric     return saver().save(dylibPath);
201e8d8bef9SDimitry Andric   return {};
202e8d8bef9SDimitry Andric }
203e8d8bef9SDimitry Andric 
204e8d8bef9SDimitry Andric // It's not uncommon to have multiple attempts to load a single dylib,
205e8d8bef9SDimitry Andric // especially if it's a commonly re-exported core library.
206e8d8bef9SDimitry Andric static DenseMap<CachedHashStringRef, DylibFile *> loadedDylibs;
207e8d8bef9SDimitry Andric 
208fe6060f1SDimitry Andric DylibFile *macho::loadDylib(MemoryBufferRef mbref, DylibFile *umbrella,
20981ad6265SDimitry Andric                             bool isBundleLoader, bool explicitlyLinked) {
210fe6060f1SDimitry Andric   CachedHashStringRef path(mbref.getBufferIdentifier());
211fe6060f1SDimitry Andric   DylibFile *&file = loadedDylibs[path];
21281ad6265SDimitry Andric   if (file) {
21381ad6265SDimitry Andric     if (explicitlyLinked)
21481ad6265SDimitry Andric       file->explicitlyLinked = explicitlyLinked;
215e8d8bef9SDimitry Andric     return file;
21681ad6265SDimitry Andric   }
217e8d8bef9SDimitry Andric 
218fe6060f1SDimitry Andric   DylibFile *newFile;
219e8d8bef9SDimitry Andric   file_magic magic = identify_magic(mbref.getBuffer());
220e8d8bef9SDimitry Andric   if (magic == file_magic::tapi_file) {
221e8d8bef9SDimitry Andric     Expected<std::unique_ptr<InterfaceFile>> result = TextAPIReader::get(mbref);
222e8d8bef9SDimitry Andric     if (!result) {
223e8d8bef9SDimitry Andric       error("could not load TAPI file at " + mbref.getBufferIdentifier() +
224e8d8bef9SDimitry Andric             ": " + toString(result.takeError()));
225fe6060f1SDimitry Andric       return nullptr;
226e8d8bef9SDimitry Andric     }
22781ad6265SDimitry Andric     file =
22881ad6265SDimitry Andric         make<DylibFile>(**result, umbrella, isBundleLoader, explicitlyLinked);
229fe6060f1SDimitry Andric 
230fe6060f1SDimitry Andric     // parseReexports() can recursively call loadDylib(). That's fine since
231fe6060f1SDimitry Andric     // we wrote the DylibFile we just loaded to the loadDylib cache via the
232fe6060f1SDimitry Andric     // `file` reference. But the recursive load can grow loadDylibs, so the
233fe6060f1SDimitry Andric     // `file` reference might become invalid after parseReexports() -- so copy
234fe6060f1SDimitry Andric     // the pointer it refers to before continuing.
235fe6060f1SDimitry Andric     newFile = file;
236fe6060f1SDimitry Andric     if (newFile->exportingFile)
237fe6060f1SDimitry Andric       newFile->parseReexports(**result);
238e8d8bef9SDimitry Andric   } else {
239e8d8bef9SDimitry Andric     assert(magic == file_magic::macho_dynamically_linked_shared_lib ||
240fe6060f1SDimitry Andric            magic == file_magic::macho_dynamically_linked_shared_lib_stub ||
241fe6060f1SDimitry Andric            magic == file_magic::macho_executable ||
242fe6060f1SDimitry Andric            magic == file_magic::macho_bundle);
24381ad6265SDimitry Andric     file = make<DylibFile>(mbref, umbrella, isBundleLoader, explicitlyLinked);
244fe6060f1SDimitry Andric 
245fe6060f1SDimitry Andric     // parseLoadCommands() can also recursively call loadDylib(). See comment
246fe6060f1SDimitry Andric     // in previous block for why this means we must copy `file` here.
247fe6060f1SDimitry Andric     newFile = file;
248fe6060f1SDimitry Andric     if (newFile->exportingFile)
249fe6060f1SDimitry Andric       newFile->parseLoadCommands(mbref);
250e8d8bef9SDimitry Andric   }
251fe6060f1SDimitry Andric   return newFile;
252fe6060f1SDimitry Andric }
253fe6060f1SDimitry Andric 
254349cc55cSDimitry Andric void macho::resetLoadedDylibs() { loadedDylibs.clear(); }
255349cc55cSDimitry Andric 
256fe6060f1SDimitry Andric Optional<StringRef>
257fe6060f1SDimitry Andric macho::findPathCombination(const Twine &name,
258fe6060f1SDimitry Andric                            const std::vector<StringRef> &roots,
259fe6060f1SDimitry Andric                            ArrayRef<StringRef> extensions) {
260fe6060f1SDimitry Andric   SmallString<261> base;
261fe6060f1SDimitry Andric   for (StringRef dir : roots) {
262fe6060f1SDimitry Andric     base = dir;
263fe6060f1SDimitry Andric     path::append(base, name);
264fe6060f1SDimitry Andric     for (StringRef ext : extensions) {
265fe6060f1SDimitry Andric       Twine location = base + ext;
266fe6060f1SDimitry Andric       bool exists = fs::exists(location);
267fe6060f1SDimitry Andric       searchedDylib(location, exists);
268fe6060f1SDimitry Andric       if (exists)
26904eeddc0SDimitry Andric         return saver().save(location.str());
270fe6060f1SDimitry Andric     }
271fe6060f1SDimitry Andric   }
272fe6060f1SDimitry Andric   return {};
273fe6060f1SDimitry Andric }
274fe6060f1SDimitry Andric 
275fe6060f1SDimitry Andric StringRef macho::rerootPath(StringRef path) {
276fe6060f1SDimitry Andric   if (!path::is_absolute(path, path::Style::posix) || path.endswith(".o"))
277fe6060f1SDimitry Andric     return path;
278fe6060f1SDimitry Andric 
279fe6060f1SDimitry Andric   if (Optional<StringRef> rerootedPath =
280fe6060f1SDimitry Andric           findPathCombination(path, config->systemLibraryRoots))
281fe6060f1SDimitry Andric     return *rerootedPath;
282fe6060f1SDimitry Andric 
283fe6060f1SDimitry Andric   return path;
284fe6060f1SDimitry Andric }
285fe6060f1SDimitry Andric 
286e8d8bef9SDimitry Andric uint32_t macho::getModTime(StringRef path) {
287fe6060f1SDimitry Andric   if (config->zeroModTime)
288fe6060f1SDimitry Andric     return 0;
289fe6060f1SDimitry Andric 
290e8d8bef9SDimitry Andric   fs::file_status stat;
291e8d8bef9SDimitry Andric   if (!fs::status(path, stat))
292e8d8bef9SDimitry Andric     if (fs::exists(stat))
293e8d8bef9SDimitry Andric       return toTimeT(stat.getLastModificationTime());
294e8d8bef9SDimitry Andric 
295e8d8bef9SDimitry Andric   warn("failed to get modification time of " + path);
296e8d8bef9SDimitry Andric   return 0;
297e8d8bef9SDimitry Andric }
298e8d8bef9SDimitry Andric 
299e8d8bef9SDimitry Andric void macho::printArchiveMemberLoad(StringRef reason, const InputFile *f) {
300e8d8bef9SDimitry Andric   if (config->printEachFile)
301e8d8bef9SDimitry Andric     message(toString(f));
302e8d8bef9SDimitry Andric   if (config->printWhyLoad)
303e8d8bef9SDimitry Andric     message(reason + " forced load of " + toString(f));
304e8d8bef9SDimitry Andric }
305fe6060f1SDimitry Andric 
306fe6060f1SDimitry Andric macho::DependencyTracker::DependencyTracker(StringRef path)
307fe6060f1SDimitry Andric     : path(path), active(!path.empty()) {
308fe6060f1SDimitry Andric   if (active && fs::exists(path) && !fs::can_write(path)) {
309fe6060f1SDimitry Andric     warn("Ignoring dependency_info option since specified path is not "
310fe6060f1SDimitry Andric          "writeable.");
311fe6060f1SDimitry Andric     active = false;
312fe6060f1SDimitry Andric   }
313fe6060f1SDimitry Andric }
314fe6060f1SDimitry Andric 
315fe6060f1SDimitry Andric void macho::DependencyTracker::write(StringRef version,
316fe6060f1SDimitry Andric                                      const SetVector<InputFile *> &inputs,
317fe6060f1SDimitry Andric                                      StringRef output) {
318fe6060f1SDimitry Andric   if (!active)
319fe6060f1SDimitry Andric     return;
320fe6060f1SDimitry Andric 
321fe6060f1SDimitry Andric   std::error_code ec;
322fe6060f1SDimitry Andric   raw_fd_ostream os(path, ec, fs::OF_None);
323fe6060f1SDimitry Andric   if (ec) {
324fe6060f1SDimitry Andric     warn("Error writing dependency info to file");
325fe6060f1SDimitry Andric     return;
326fe6060f1SDimitry Andric   }
327fe6060f1SDimitry Andric 
328fe6060f1SDimitry Andric   auto addDep = [&os](DepOpCode opcode, const StringRef &path) {
329fe6060f1SDimitry Andric     // XXX: Even though DepOpCode's underlying type is uint8_t,
330fe6060f1SDimitry Andric     // this cast is still needed because Clang older than 10.x has a bug,
331fe6060f1SDimitry Andric     // where it doesn't know to cast the enum to its underlying type.
332fe6060f1SDimitry Andric     // Hence `<< DepOpCode` is ambiguous to it.
333fe6060f1SDimitry Andric     os << static_cast<uint8_t>(opcode);
334fe6060f1SDimitry Andric     os << path;
335fe6060f1SDimitry Andric     os << '\0';
336fe6060f1SDimitry Andric   };
337fe6060f1SDimitry Andric 
338fe6060f1SDimitry Andric   addDep(DepOpCode::Version, version);
339fe6060f1SDimitry Andric 
340fe6060f1SDimitry Andric   // Sort the input by its names.
341fe6060f1SDimitry Andric   std::vector<StringRef> inputNames;
342fe6060f1SDimitry Andric   inputNames.reserve(inputs.size());
343fe6060f1SDimitry Andric   for (InputFile *f : inputs)
344fe6060f1SDimitry Andric     inputNames.push_back(f->getName());
345fe6060f1SDimitry Andric   llvm::sort(inputNames);
346fe6060f1SDimitry Andric 
347fe6060f1SDimitry Andric   for (const StringRef &in : inputNames)
348fe6060f1SDimitry Andric     addDep(DepOpCode::Input, in);
349fe6060f1SDimitry Andric 
350fe6060f1SDimitry Andric   for (const std::string &f : notFounds)
351fe6060f1SDimitry Andric     addDep(DepOpCode::NotFound, f);
352fe6060f1SDimitry Andric 
353fe6060f1SDimitry Andric   addDep(DepOpCode::Output, output);
354fe6060f1SDimitry Andric }
355