1 //===- DriverUtils.cpp ----------------------------------------------------===//
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains utility functions for the driver. Because there
11 // are so many small functions, we created this separate file to make
12 // Driver.cpp less cluttered.
14 //===----------------------------------------------------------------------===//
19 #include "lld/Common/ErrorHandler.h"
20 #include "lld/Common/Memory.h"
21 #include "llvm/ADT/Optional.h"
22 #include "llvm/ADT/StringSwitch.h"
23 #include "llvm/BinaryFormat/COFF.h"
24 #include "llvm/Object/COFF.h"
25 #include "llvm/Object/WindowsResource.h"
26 #include "llvm/Option/Arg.h"
27 #include "llvm/Option/ArgList.h"
28 #include "llvm/Option/Option.h"
29 #include "llvm/Support/CommandLine.h"
30 #include "llvm/Support/FileUtilities.h"
31 #include "llvm/Support/MathExtras.h"
32 #include "llvm/Support/Process.h"
33 #include "llvm/Support/Program.h"
34 #include "llvm/Support/raw_ostream.h"
35 #include "llvm/WindowsManifest/WindowsManifestMerger.h"
38 using namespace llvm::COFF;
40 using llvm::sys::Process;
46 const uint16_t SUBLANG_ENGLISH_US = 0x0409;
47 const uint16_t RT_MANIFEST = 24;
51 explicit Executor(StringRef S) : Prog(Saver.save(S)) {}
52 void add(StringRef S) { Args.push_back(Saver.save(S)); }
53 void add(std::string &S) { Args.push_back(Saver.save(S)); }
54 void add(Twine S) { Args.push_back(Saver.save(S)); }
55 void add(const char *S) { Args.push_back(Saver.save(S)); }
58 ErrorOr<std::string> ExeOrErr = sys::findProgramByName(Prog);
59 if (auto EC = ExeOrErr.getError())
60 fatal("unable to find " + Prog + " in PATH: " + EC.message());
61 StringRef Exe = Saver.save(*ExeOrErr);
62 Args.insert(Args.begin(), Exe);
64 std::vector<const char *> Vec;
65 for (StringRef S : Args)
66 Vec.push_back(S.data());
67 Vec.push_back(nullptr);
69 if (sys::ExecuteAndWait(Args[0], Vec.data()) != 0)
70 fatal("ExecuteAndWait failed: " +
71 llvm::join(Args.begin(), Args.end(), " "));
76 std::vector<StringRef> Args;
79 } // anonymous namespace
81 // Returns /machine's value.
82 MachineTypes getMachineType(StringRef S) {
83 MachineTypes MT = StringSwitch<MachineTypes>(S.lower())
84 .Cases("x64", "amd64", AMD64)
85 .Cases("x86", "i386", I386)
88 .Default(IMAGE_FILE_MACHINE_UNKNOWN);
89 if (MT != IMAGE_FILE_MACHINE_UNKNOWN)
91 fatal("unknown /machine argument: " + S);
94 StringRef machineToStr(MachineTypes MT) {
105 llvm_unreachable("unknown machine type");
109 // Parses a string in the form of "<integer>[,<integer>]".
110 void parseNumbers(StringRef Arg, uint64_t *Addr, uint64_t *Size) {
112 std::tie(S1, S2) = Arg.split(',');
113 if (S1.getAsInteger(0, *Addr))
114 fatal("invalid number: " + S1);
115 if (Size && !S2.empty() && S2.getAsInteger(0, *Size))
116 fatal("invalid number: " + S2);
119 // Parses a string in the form of "<integer>[.<integer>]".
120 // If second number is not present, Minor is set to 0.
121 void parseVersion(StringRef Arg, uint32_t *Major, uint32_t *Minor) {
123 std::tie(S1, S2) = Arg.split('.');
124 if (S1.getAsInteger(0, *Major))
125 fatal("invalid number: " + S1);
127 if (!S2.empty() && S2.getAsInteger(0, *Minor))
128 fatal("invalid number: " + S2);
131 // Parses a string in the form of "<subsystem>[,<integer>[.<integer>]]".
132 void parseSubsystem(StringRef Arg, WindowsSubsystem *Sys, uint32_t *Major,
134 StringRef SysStr, Ver;
135 std::tie(SysStr, Ver) = Arg.split(',');
136 *Sys = StringSwitch<WindowsSubsystem>(SysStr.lower())
137 .Case("boot_application", IMAGE_SUBSYSTEM_WINDOWS_BOOT_APPLICATION)
138 .Case("console", IMAGE_SUBSYSTEM_WINDOWS_CUI)
139 .Case("efi_application", IMAGE_SUBSYSTEM_EFI_APPLICATION)
140 .Case("efi_boot_service_driver", IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER)
141 .Case("efi_rom", IMAGE_SUBSYSTEM_EFI_ROM)
142 .Case("efi_runtime_driver", IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER)
143 .Case("native", IMAGE_SUBSYSTEM_NATIVE)
144 .Case("posix", IMAGE_SUBSYSTEM_POSIX_CUI)
145 .Case("windows", IMAGE_SUBSYSTEM_WINDOWS_GUI)
146 .Default(IMAGE_SUBSYSTEM_UNKNOWN);
147 if (*Sys == IMAGE_SUBSYSTEM_UNKNOWN)
148 fatal("unknown subsystem: " + SysStr);
150 parseVersion(Ver, Major, Minor);
153 // Parse a string of the form of "<from>=<to>".
154 // Results are directly written to Config.
155 void parseAlternateName(StringRef S) {
157 std::tie(From, To) = S.split('=');
158 if (From.empty() || To.empty())
159 fatal("/alternatename: invalid argument: " + S);
160 auto It = Config->AlternateNames.find(From);
161 if (It != Config->AlternateNames.end() && It->second != To)
162 fatal("/alternatename: conflicts: " + S);
163 Config->AlternateNames.insert(It, std::make_pair(From, To));
166 // Parse a string of the form of "<from>=<to>".
167 // Results are directly written to Config.
168 void parseMerge(StringRef S) {
170 std::tie(From, To) = S.split('=');
171 if (From.empty() || To.empty())
172 fatal("/merge: invalid argument: " + S);
173 auto Pair = Config->Merge.insert(std::make_pair(From, To));
174 bool Inserted = Pair.second;
176 StringRef Existing = Pair.first->second;
178 warn(S + ": already merged into " + Existing);
182 static uint32_t parseSectionAttributes(StringRef S) {
184 for (char C : S.lower()) {
187 Ret |= IMAGE_SCN_MEM_DISCARDABLE;
190 Ret |= IMAGE_SCN_MEM_EXECUTE;
193 Ret |= IMAGE_SCN_MEM_NOT_CACHED;
196 Ret |= IMAGE_SCN_MEM_NOT_PAGED;
199 Ret |= IMAGE_SCN_MEM_READ;
202 Ret |= IMAGE_SCN_MEM_SHARED;
205 Ret |= IMAGE_SCN_MEM_WRITE;
208 fatal("/section: invalid argument: " + S);
214 // Parses /section option argument.
215 void parseSection(StringRef S) {
216 StringRef Name, Attrs;
217 std::tie(Name, Attrs) = S.split(',');
218 if (Name.empty() || Attrs.empty())
219 fatal("/section: invalid argument: " + S);
220 Config->Section[Name] = parseSectionAttributes(Attrs);
223 // Parses /aligncomm option argument.
224 void parseAligncomm(StringRef S) {
225 StringRef Name, Align;
226 std::tie(Name, Align) = S.split(',');
227 if (Name.empty() || Align.empty()) {
228 error("/aligncomm: invalid argument: " + S);
232 if (Align.getAsInteger(0, V)) {
233 error("/aligncomm: invalid argument: " + S);
236 Config->AlignComm[Name] = std::max(Config->AlignComm[Name], 1 << V);
239 // Parses a string in the form of "EMBED[,=<integer>]|NO".
240 // Results are directly written to Config.
241 void parseManifest(StringRef Arg) {
242 if (Arg.equals_lower("no")) {
243 Config->Manifest = Configuration::No;
246 if (!Arg.startswith_lower("embed"))
247 fatal("invalid option " + Arg);
248 Config->Manifest = Configuration::Embed;
249 Arg = Arg.substr(strlen("embed"));
252 if (!Arg.startswith_lower(",id="))
253 fatal("invalid option " + Arg);
254 Arg = Arg.substr(strlen(",id="));
255 if (Arg.getAsInteger(0, Config->ManifestID))
256 fatal("invalid option " + Arg);
259 // Parses a string in the form of "level=<string>|uiAccess=<string>|NO".
260 // Results are directly written to Config.
261 void parseManifestUAC(StringRef Arg) {
262 if (Arg.equals_lower("no")) {
263 Config->ManifestUAC = false;
270 if (Arg.startswith_lower("level=")) {
271 Arg = Arg.substr(strlen("level="));
272 std::tie(Config->ManifestLevel, Arg) = Arg.split(" ");
275 if (Arg.startswith_lower("uiaccess=")) {
276 Arg = Arg.substr(strlen("uiaccess="));
277 std::tie(Config->ManifestUIAccess, Arg) = Arg.split(" ");
280 fatal("invalid option " + Arg);
284 // An RAII temporary file class that automatically removes a temporary file.
286 class TemporaryFile {
288 TemporaryFile(StringRef Prefix, StringRef Extn, StringRef Contents = "") {
290 if (auto EC = sys::fs::createTemporaryFile("lld-" + Prefix, Extn, S))
291 fatal("cannot create a temporary file: " + EC.message());
294 if (!Contents.empty()) {
296 raw_fd_ostream OS(Path, EC, sys::fs::F_None);
298 fatal("failed to open " + Path + ": " + EC.message());
303 TemporaryFile(TemporaryFile &&Obj) {
304 std::swap(Path, Obj.Path);
310 if (sys::fs::remove(Path))
311 fatal("failed to remove " + Path);
314 // Returns a memory buffer of this temporary file.
315 // Note that this function does not leave the file open,
316 // so it is safe to remove the file immediately after this function
317 // is called (you cannot remove an opened file on Windows.)
318 std::unique_ptr<MemoryBuffer> getMemoryBuffer() {
319 // IsVolatileSize=true forces MemoryBuffer to not use mmap().
320 return CHECK(MemoryBuffer::getFile(Path, /*FileSize=*/-1,
321 /*RequiresNullTerminator=*/false,
322 /*IsVolatileSize=*/true),
323 "could not open " + Path);
330 static std::string createDefaultXml() {
332 raw_string_ostream OS(Ret);
334 // Emit the XML. Note that we do *not* verify that the XML attributes are
335 // syntactically correct. This is intentional for link.exe compatibility.
336 OS << "<?xml version=\"1.0\" standalone=\"yes\"?>\n"
337 << "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\"\n"
338 << " manifestVersion=\"1.0\">\n";
339 if (Config->ManifestUAC) {
340 OS << " <trustInfo>\n"
342 << " <requestedPrivileges>\n"
343 << " <requestedExecutionLevel level=" << Config->ManifestLevel
344 << " uiAccess=" << Config->ManifestUIAccess << "/>\n"
345 << " </requestedPrivileges>\n"
347 << " </trustInfo>\n";
349 if (!Config->ManifestDependency.empty()) {
350 OS << " <dependency>\n"
351 << " <dependentAssembly>\n"
352 << " <assemblyIdentity " << Config->ManifestDependency << " />\n"
353 << " </dependentAssembly>\n"
354 << " </dependency>\n";
356 OS << "</assembly>\n";
360 static std::string createManifestXmlWithInternalMt(StringRef DefaultXml) {
361 std::unique_ptr<MemoryBuffer> DefaultXmlCopy =
362 MemoryBuffer::getMemBufferCopy(DefaultXml);
364 windows_manifest::WindowsManifestMerger Merger;
365 if (auto E = Merger.merge(*DefaultXmlCopy.get()))
366 fatal("internal manifest tool failed on default xml: " +
367 toString(std::move(E)));
369 for (StringRef Filename : Config->ManifestInput) {
370 std::unique_ptr<MemoryBuffer> Manifest =
371 check(MemoryBuffer::getFile(Filename));
372 if (auto E = Merger.merge(*Manifest.get()))
373 fatal("internal manifest tool failed on file " + Filename + ": " +
374 toString(std::move(E)));
377 return Merger.getMergedManifest().get()->getBuffer();
380 static std::string createManifestXmlWithExternalMt(StringRef DefaultXml) {
381 // Create the default manifest file as a temporary file.
382 TemporaryFile Default("defaultxml", "manifest");
384 raw_fd_ostream OS(Default.Path, EC, sys::fs::F_Text);
386 fatal("failed to open " + Default.Path + ": " + EC.message());
390 // Merge user-supplied manifests if they are given. Since libxml2 is not
391 // enabled, we must shell out to Microsoft's mt.exe tool.
392 TemporaryFile User("user", "manifest");
394 Executor E("mt.exe");
397 for (StringRef Filename : Config->ManifestInput) {
402 E.add("/out:" + StringRef(User.Path));
405 return CHECK(MemoryBuffer::getFile(User.Path), "could not open " + User.Path)
410 static std::string createManifestXml() {
411 std::string DefaultXml = createDefaultXml();
412 if (Config->ManifestInput.empty())
415 if (windows_manifest::isAvailable())
416 return createManifestXmlWithInternalMt(DefaultXml);
418 return createManifestXmlWithExternalMt(DefaultXml);
421 static std::unique_ptr<MemoryBuffer>
422 createMemoryBufferForManifestRes(size_t ManifestSize) {
423 size_t ResSize = alignTo(
424 object::WIN_RES_MAGIC_SIZE + object::WIN_RES_NULL_ENTRY_SIZE +
425 sizeof(object::WinResHeaderPrefix) + sizeof(object::WinResIDs) +
426 sizeof(object::WinResHeaderSuffix) + ManifestSize,
427 object::WIN_RES_DATA_ALIGNMENT);
428 return MemoryBuffer::getNewMemBuffer(ResSize,
429 Config->OutputFile + ".manifest.res");
432 static void writeResFileHeader(char *&Buf) {
433 memcpy(Buf, COFF::WinResMagic, sizeof(COFF::WinResMagic));
434 Buf += sizeof(COFF::WinResMagic);
435 memset(Buf, 0, object::WIN_RES_NULL_ENTRY_SIZE);
436 Buf += object::WIN_RES_NULL_ENTRY_SIZE;
439 static void writeResEntryHeader(char *&Buf, size_t ManifestSize) {
441 auto *Prefix = reinterpret_cast<object::WinResHeaderPrefix *>(Buf);
442 Prefix->DataSize = ManifestSize;
443 Prefix->HeaderSize = sizeof(object::WinResHeaderPrefix) +
444 sizeof(object::WinResIDs) +
445 sizeof(object::WinResHeaderSuffix);
446 Buf += sizeof(object::WinResHeaderPrefix);
448 // Write the Type/Name IDs.
449 auto *IDs = reinterpret_cast<object::WinResIDs *>(Buf);
450 IDs->setType(RT_MANIFEST);
451 IDs->setName(Config->ManifestID);
452 Buf += sizeof(object::WinResIDs);
455 auto *Suffix = reinterpret_cast<object::WinResHeaderSuffix *>(Buf);
456 Suffix->DataVersion = 0;
457 Suffix->MemoryFlags = object::WIN_RES_PURE_MOVEABLE;
458 Suffix->Language = SUBLANG_ENGLISH_US;
460 Suffix->Characteristics = 0;
461 Buf += sizeof(object::WinResHeaderSuffix);
464 // Create a resource file containing a manifest XML.
465 std::unique_ptr<MemoryBuffer> createManifestRes() {
466 std::string Manifest = createManifestXml();
468 std::unique_ptr<MemoryBuffer> Res =
469 createMemoryBufferForManifestRes(Manifest.size());
471 char *Buf = const_cast<char *>(Res->getBufferStart());
472 writeResFileHeader(Buf);
473 writeResEntryHeader(Buf, Manifest.size());
475 // Copy the manifest data into the .res file.
476 std::copy(Manifest.begin(), Manifest.end(), Buf);
480 void createSideBySideManifest() {
481 std::string Path = Config->ManifestFile;
483 Path = Config->OutputFile + ".manifest";
485 raw_fd_ostream Out(Path, EC, sys::fs::F_Text);
487 fatal("failed to create manifest: " + EC.message());
488 Out << createManifestXml();
491 // Parse a string in the form of
492 // "<name>[=<internalname>][,@ordinal[,NONAME]][,DATA][,PRIVATE]"
493 // or "<name>=<dllname>.<name>".
494 // Used for parsing /export arguments.
495 Export parseExport(StringRef Arg) {
498 std::tie(E.Name, Rest) = Arg.split(",");
502 if (E.Name.contains('=')) {
504 std::tie(X, Y) = E.Name.split("=");
506 // If "<name>=<dllname>.<name>".
507 if (Y.contains(".")) {
519 // If "<name>=<internalname>[,@ordinal[,NONAME]][,DATA][,PRIVATE]"
520 while (!Rest.empty()) {
522 std::tie(Tok, Rest) = Rest.split(",");
523 if (Tok.equals_lower("noname")) {
529 if (Tok.equals_lower("data")) {
533 if (Tok.equals_lower("constant")) {
537 if (Tok.equals_lower("private")) {
541 if (Tok.startswith("@")) {
543 if (Tok.substr(1).getAsInteger(0, Ord))
545 if (Ord <= 0 || 65535 < Ord)
555 fatal("invalid /export: " + Arg);
558 static StringRef undecorate(StringRef Sym) {
559 if (Config->Machine != I386)
561 return Sym.startswith("_") ? Sym.substr(1) : Sym;
564 // Performs error checking on all /export arguments.
565 // It also sets ordinals.
566 void fixupExports() {
567 // Symbol ordinals must be unique.
568 std::set<uint16_t> Ords;
569 for (Export &E : Config->Exports) {
572 if (!Ords.insert(E.Ordinal).second)
573 fatal("duplicate export ordinal: " + E.Name);
576 for (Export &E : Config->Exports) {
578 if (!E.ForwardTo.empty() || !Sym) {
579 E.SymbolName = E.Name;
581 if (auto *U = dyn_cast<Undefined>(Sym))
584 E.SymbolName = Sym->getName();
588 for (Export &E : Config->Exports) {
589 if (!E.ForwardTo.empty()) {
590 E.ExportName = undecorate(E.Name);
592 E.ExportName = undecorate(E.ExtName.empty() ? E.Name : E.ExtName);
597 DenseMap<StringRef, Export *> Map(Config->Exports.size());
598 std::vector<Export> V;
599 for (Export &E : Config->Exports) {
600 auto Pair = Map.insert(std::make_pair(E.ExportName, &E));
601 bool Inserted = Pair.second;
606 Export *Existing = Pair.first->second;
607 if (E == *Existing || E.Name != Existing->Name)
609 warn("duplicate /export option: " + E.Name);
611 Config->Exports = std::move(V);
614 std::sort(Config->Exports.begin(), Config->Exports.end(),
615 [](const Export &A, const Export &B) {
616 return A.ExportName < B.ExportName;
620 void assignExportOrdinals() {
621 // Assign unique ordinals if default (= 0).
623 for (Export &E : Config->Exports)
624 Max = std::max(Max, E.Ordinal);
625 for (Export &E : Config->Exports)
630 // Parses a string in the form of "key=value" and check
631 // if value matches previous values for the same key.
632 void checkFailIfMismatch(StringRef Arg) {
634 std::tie(K, V) = Arg.split('=');
635 if (K.empty() || V.empty())
636 fatal("/failifmismatch: invalid argument: " + Arg);
637 StringRef Existing = Config->MustMatch[K];
638 if (!Existing.empty() && V != Existing)
639 fatal("/failifmismatch: mismatch detected: " + Existing + " and " + V +
641 Config->MustMatch[K] = V;
644 // Convert Windows resource files (.res files) to a .obj file.
645 MemoryBufferRef convertResToCOFF(ArrayRef<MemoryBufferRef> MBs) {
646 object::WindowsResourceParser Parser;
648 for (MemoryBufferRef MB : MBs) {
649 std::unique_ptr<object::Binary> Bin = check(object::createBinary(MB));
650 object::WindowsResource *RF = dyn_cast<object::WindowsResource>(Bin.get());
652 fatal("cannot compile non-resource file as resource");
653 if (auto EC = Parser.parse(RF))
654 fatal("failed to parse .res file: " + toString(std::move(EC)));
657 Expected<std::unique_ptr<MemoryBuffer>> E =
658 llvm::object::writeWindowsResourceCOFF(Config->Machine, Parser);
660 fatal("failed to write .res to COFF: " + toString(E.takeError()));
662 MemoryBufferRef MBRef = **E;
663 make<std::unique_ptr<MemoryBuffer>>(std::move(*E)); // take ownership
667 // Run MSVC link.exe for given in-memory object files.
668 // Command line options are copied from those given to LLD.
669 // This is for the /msvclto option.
670 void runMSVCLinker(std::string Rsp, ArrayRef<StringRef> Objects) {
671 // Write the in-memory object files to disk.
672 std::vector<TemporaryFile> Temps;
673 for (StringRef S : Objects) {
674 Temps.emplace_back("lto", "obj", S);
675 Rsp += quote(Temps.back().Path) + "\n";
678 log("link.exe " + Rsp);
680 // Run MSVC link.exe.
681 Temps.emplace_back("lto", "rsp", Rsp);
682 Executor E("link.exe");
683 E.add(Twine("@" + Temps.back().Path));
689 // Create prefix string literals used in Options.td
690 #define PREFIX(NAME, VALUE) const char *const NAME[] = VALUE;
691 #include "Options.inc"
694 // Create table mapping all options defined in Options.td
695 static const llvm::opt::OptTable::Info InfoTable[] = {
696 #define OPTION(X1, X2, ID, KIND, GROUP, ALIAS, X7, X8, X9, X10, X11, X12) \
697 {X1, X2, X10, X11, OPT_##ID, llvm::opt::Option::KIND##Class, \
698 X9, X8, OPT_##GROUP, OPT_##ALIAS, X7, X12},
699 #include "Options.inc"
703 COFFOptTable::COFFOptTable() : OptTable(InfoTable, true) {}
705 static cl::TokenizerCallback getQuotingStyle(opt::InputArgList &Args) {
706 if (auto *Arg = Args.getLastArg(OPT_rsp_quoting)) {
707 StringRef S = Arg->getValue();
708 if (S != "windows" && S != "posix")
709 error("invalid response file quoting: " + S);
711 return cl::TokenizeWindowsCommandLine;
712 return cl::TokenizeGNUCommandLine;
714 // The COFF linker always defaults to Windows quoting.
715 return cl::TokenizeWindowsCommandLine;
718 // Parses a given list of options.
719 opt::InputArgList ArgParser::parse(ArrayRef<const char *> Argv) {
720 // Make InputArgList from string vectors.
721 unsigned MissingIndex;
722 unsigned MissingCount;
723 SmallVector<const char *, 256> Vec(Argv.data(), Argv.data() + Argv.size());
725 // We need to get the quoting style for response files before parsing all
726 // options so we parse here before and ignore all the options but
728 opt::InputArgList Args = Table.ParseArgs(Vec, MissingIndex, MissingCount);
730 // Expand response files (arguments in the form of @<filename>)
731 // and then parse the argument again.
732 cl::ExpandResponseFiles(Saver, getQuotingStyle(Args), Vec);
733 Args = Table.ParseArgs(Vec, MissingIndex, MissingCount);
735 // Print the real command line if response files are expanded.
736 if (Args.hasArg(OPT_verbose) && Argv.size() != Vec.size()) {
737 std::string Msg = "Command line:";
738 for (const char *S : Vec)
739 Msg += " " + std::string(S);
743 // Handle /WX early since it converts missing argument warnings to errors.
744 errorHandler().FatalWarnings = Args.hasFlag(OPT_WX, OPT_WX_no, false);
747 fatal(Twine(Args.getArgString(MissingIndex)) + ": missing argument");
748 for (auto *Arg : Args.filtered(OPT_UNKNOWN))
749 warn("ignoring unknown argument: " + Arg->getSpelling());
753 // link.exe has an interesting feature. If LINK or _LINK_ environment
754 // variables exist, their contents are handled as command line strings.
755 // So you can pass extra arguments using them.
756 opt::InputArgList ArgParser::parseLINK(std::vector<const char *> Argv) {
757 // Concatenate LINK env and command line arguments, and then parse them.
758 if (Optional<std::string> S = Process::GetEnv("LINK")) {
759 std::vector<const char *> V = tokenize(*S);
760 Argv.insert(Argv.begin(), V.begin(), V.end());
762 if (Optional<std::string> S = Process::GetEnv("_LINK_")) {
763 std::vector<const char *> V = tokenize(*S);
764 Argv.insert(Argv.begin(), V.begin(), V.end());
769 std::vector<const char *> ArgParser::tokenize(StringRef S) {
770 SmallVector<const char *, 16> Tokens;
771 cl::TokenizeWindowsCommandLine(S, Saver, Tokens);
772 return std::vector<const char *>(Tokens.begin(), Tokens.end());
775 void printHelp(const char *Argv0) {
776 COFFOptTable().PrintHelp(outs(), Argv0, "LLVM Linker", false);