blob: 4d375c3af0dc96d215438fec99184d42d9f966ba [file] [log] [blame]
Rui Ueyama411c63602015-05-28 19:09:30 +00001//===- Driver.cpp ---------------------------------------------------------===//
2//
3// The LLVM Linker
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "Config.h"
11#include "Driver.h"
Rui Ueyama562daa82015-06-18 21:50:38 +000012#include "Error.h"
Rui Ueyama411c63602015-05-28 19:09:30 +000013#include "InputFiles.h"
Rui Ueyama411c63602015-05-28 19:09:30 +000014#include "SymbolTable.h"
Rui Ueyama685c41c2015-08-05 23:43:53 +000015#include "Symbols.h"
Rui Ueyama411c63602015-05-28 19:09:30 +000016#include "Writer.h"
Rui Ueyama411c63602015-05-28 19:09:30 +000017#include "llvm/ADT/Optional.h"
Peter Collingbournebd1cb792015-06-09 21:52:48 +000018#include "llvm/LibDriver/LibDriver.h"
Rui Ueyama411c63602015-05-28 19:09:30 +000019#include "llvm/Option/Arg.h"
20#include "llvm/Option/ArgList.h"
21#include "llvm/Option/Option.h"
Rui Ueyama411c63602015-05-28 19:09:30 +000022#include "llvm/Support/Debug.h"
Rui Ueyama411c63602015-05-28 19:09:30 +000023#include "llvm/Support/Path.h"
Rui Ueyama54b71da2015-05-31 19:17:12 +000024#include "llvm/Support/Process.h"
Peter Collingbourne60c16162015-06-01 20:10:10 +000025#include "llvm/Support/TargetSelect.h"
Rui Ueyama411c63602015-05-28 19:09:30 +000026#include "llvm/Support/raw_ostream.h"
Rui Ueyama2bf6a122015-06-14 21:50:50 +000027#include <algorithm>
Rui Ueyama411c63602015-05-28 19:09:30 +000028#include <memory>
29
30using namespace llvm;
Rui Ueyama84936e02015-07-07 23:39:18 +000031using namespace llvm::COFF;
Rui Ueyama54b71da2015-05-31 19:17:12 +000032using llvm::sys::Process;
Peter Collingbournebaf5f872015-06-26 19:20:09 +000033using llvm::sys::fs::OpenFlags;
Rui Ueyama711cd2d2015-05-31 21:17:10 +000034using llvm::sys::fs::file_magic;
35using llvm::sys::fs::identify_magic;
Rui Ueyama411c63602015-05-28 19:09:30 +000036
Rui Ueyama3500f662015-05-28 20:30:06 +000037namespace lld {
38namespace coff {
Rui Ueyama411c63602015-05-28 19:09:30 +000039
Rui Ueyama3500f662015-05-28 20:30:06 +000040Configuration *Config;
Rui Ueyamaa9cbbf82015-05-31 19:17:09 +000041LinkerDriver *Driver;
42
Rafael Espindolab835ae82015-08-06 14:58:50 +000043void link(llvm::ArrayRef<const char *> Args) {
Rui Ueyama570752c2015-08-18 09:13:25 +000044 Configuration C;
45 LinkerDriver D;
46 Config = &C;
47 Driver = &D;
David Blaikieb2b1c7c2015-06-21 06:32:10 +000048 return Driver->link(Args);
Rui Ueyamaa9cbbf82015-05-31 19:17:09 +000049}
Rui Ueyama411c63602015-05-28 19:09:30 +000050
Rui Ueyamaad660982015-06-07 00:20:32 +000051// Drop directory components and replace extension with ".exe".
52static std::string getOutputPath(StringRef Path) {
53 auto P = Path.find_last_of("\\/");
54 StringRef S = (P == StringRef::npos) ? Path : Path.substr(P + 1);
55 return (S.substr(0, S.rfind('.')) + ".exe").str();
Rui Ueyama411c63602015-05-28 19:09:30 +000056}
57
Rui Ueyamad7c2f582015-05-31 21:04:56 +000058// Opens a file. Path has to be resolved already.
59// Newly created memory buffers are owned by this driver.
Rafael Espindolab835ae82015-08-06 14:58:50 +000060MemoryBufferRef LinkerDriver::openFile(StringRef Path) {
Rui Ueyamad7c2f582015-05-31 21:04:56 +000061 auto MBOrErr = MemoryBuffer::getFile(Path);
Rafael Espindolab835ae82015-08-06 14:58:50 +000062 error(MBOrErr, Twine("Could not open ") + Path);
63 std::unique_ptr<MemoryBuffer> &MB = *MBOrErr;
Rui Ueyamad7c2f582015-05-31 21:04:56 +000064 MemoryBufferRef MBRef = MB->getMemBufferRef();
65 OwningMBs.push_back(std::move(MB)); // take ownership
Rui Ueyama2bf6a122015-06-14 21:50:50 +000066 return MBRef;
67}
Rui Ueyama711cd2d2015-05-31 21:17:10 +000068
Rui Ueyama2bf6a122015-06-14 21:50:50 +000069static std::unique_ptr<InputFile> createFile(MemoryBufferRef MB) {
Rui Ueyama711cd2d2015-05-31 21:17:10 +000070 // File type is detected by contents, not by file extension.
Rui Ueyama2bf6a122015-06-14 21:50:50 +000071 file_magic Magic = identify_magic(MB.getBuffer());
Rui Ueyama711cd2d2015-05-31 21:17:10 +000072 if (Magic == file_magic::archive)
Rui Ueyama2bf6a122015-06-14 21:50:50 +000073 return std::unique_ptr<InputFile>(new ArchiveFile(MB));
Peter Collingbourne60c16162015-06-01 20:10:10 +000074 if (Magic == file_magic::bitcode)
Rui Ueyama2bf6a122015-06-14 21:50:50 +000075 return std::unique_ptr<InputFile>(new BitcodeFile(MB));
Rui Ueyamaad660982015-06-07 00:20:32 +000076 if (Config->OutputFile == "")
Rui Ueyama2bf6a122015-06-14 21:50:50 +000077 Config->OutputFile = getOutputPath(MB.getBufferIdentifier());
78 return std::unique_ptr<InputFile>(new ObjectFile(MB));
Rui Ueyama411c63602015-05-28 19:09:30 +000079}
80
Rui Ueyamaf10a3202015-08-31 08:43:21 +000081static bool isDecorated(StringRef Sym) {
82 return Sym.startswith("_") || Sym.startswith("@") || Sym.startswith("?");
83}
84
Rui Ueyama411c63602015-05-28 19:09:30 +000085// Parses .drectve section contents and returns a list of files
86// specified by /defaultlib.
Rafael Espindolab835ae82015-08-06 14:58:50 +000087void LinkerDriver::parseDirectives(StringRef S) {
88 llvm::opt::InputArgList Args = Parser.parse(S);
Rui Ueyama411c63602015-05-28 19:09:30 +000089
David Blaikie6521ed92015-06-22 22:06:52 +000090 for (auto *Arg : Args) {
Rui Ueyama562daa82015-06-18 21:50:38 +000091 switch (Arg->getOption().getID()) {
92 case OPT_alternatename:
Rafael Espindolab835ae82015-08-06 14:58:50 +000093 parseAlternateName(Arg->getValue());
Rui Ueyama562daa82015-06-18 21:50:38 +000094 break;
95 case OPT_defaultlib:
96 if (Optional<StringRef> Path = findLib(Arg->getValue())) {
Rafael Espindolab835ae82015-08-06 14:58:50 +000097 MemoryBufferRef MB = openFile(*Path);
98 Symtab.addFile(createFile(MB));
Rui Ueyama562daa82015-06-18 21:50:38 +000099 }
100 break;
101 case OPT_export: {
Rafael Espindolab835ae82015-08-06 14:58:50 +0000102 Export E = parseExport(Arg->getValue());
Rui Ueyamaf10a3202015-08-31 08:43:21 +0000103 E.Directives = true;
Rafael Espindolab835ae82015-08-06 14:58:50 +0000104 Config->Exports.push_back(E);
Rui Ueyama562daa82015-06-18 21:50:38 +0000105 break;
106 }
107 case OPT_failifmismatch:
Rafael Espindolab835ae82015-08-06 14:58:50 +0000108 checkFailIfMismatch(Arg->getValue());
Rui Ueyama562daa82015-06-18 21:50:38 +0000109 break;
Rui Ueyama08d5e182015-06-18 23:20:11 +0000110 case OPT_incl:
Rui Ueyama32f8e1c2015-06-26 03:44:00 +0000111 addUndefined(Arg->getValue());
Rui Ueyama08d5e182015-06-18 23:20:11 +0000112 break;
Rui Ueyamace86c992015-06-18 23:22:39 +0000113 case OPT_merge:
Rafael Espindolab835ae82015-08-06 14:58:50 +0000114 parseMerge(Arg->getValue());
Rui Ueyamace86c992015-06-18 23:22:39 +0000115 break;
116 case OPT_nodefaultlib:
117 Config->NoDefaultLibs.insert(doFindLib(Arg->getValue()));
118 break;
Rui Ueyama3c4737d2015-08-11 16:46:08 +0000119 case OPT_editandcontinue:
Rui Ueyama31e66e32015-09-03 16:20:47 +0000120 case OPT_guardsym:
Rui Ueyama432383172015-07-29 21:01:15 +0000121 case OPT_throwingnew:
Rui Ueyama46682632015-07-29 20:29:15 +0000122 break;
Rui Ueyama562daa82015-06-18 21:50:38 +0000123 default:
Rafael Espindolab835ae82015-08-06 14:58:50 +0000124 error(Twine(Arg->getSpelling()) + " is not allowed in .drectve");
Rui Ueyamad7c2f582015-05-31 21:04:56 +0000125 }
126 }
Rui Ueyama411c63602015-05-28 19:09:30 +0000127}
128
Rui Ueyama54b71da2015-05-31 19:17:12 +0000129// Find file from search paths. You can omit ".obj", this function takes
130// care of that. Note that the returned path is not guaranteed to exist.
Rui Ueyamad21b00b2015-05-31 19:17:14 +0000131StringRef LinkerDriver::doFindFile(StringRef Filename) {
Rui Ueyama54b71da2015-05-31 19:17:12 +0000132 bool hasPathSep = (Filename.find_first_of("/\\") != StringRef::npos);
133 if (hasPathSep)
134 return Filename;
135 bool hasExt = (Filename.find('.') != StringRef::npos);
136 for (StringRef Dir : SearchPaths) {
137 SmallString<128> Path = Dir;
138 llvm::sys::path::append(Path, Filename);
139 if (llvm::sys::fs::exists(Path.str()))
140 return Alloc.save(Path.str());
141 if (!hasExt) {
142 Path.append(".obj");
143 if (llvm::sys::fs::exists(Path.str()))
144 return Alloc.save(Path.str());
145 }
146 }
147 return Filename;
148}
149
Rui Ueyamad21b00b2015-05-31 19:17:14 +0000150// Resolves a file path. This never returns the same path
151// (in that case, it returns None).
152Optional<StringRef> LinkerDriver::findFile(StringRef Filename) {
153 StringRef Path = doFindFile(Filename);
154 bool Seen = !VisitedFiles.insert(Path.lower()).second;
155 if (Seen)
156 return None;
157 return Path;
Rui Ueyama54b71da2015-05-31 19:17:12 +0000158}
159
Rui Ueyamad21b00b2015-05-31 19:17:14 +0000160// Find library file from search path.
161StringRef LinkerDriver::doFindLib(StringRef Filename) {
162 // Add ".lib" to Filename if that has no file extension.
Rui Ueyama54b71da2015-05-31 19:17:12 +0000163 bool hasExt = (Filename.find('.') != StringRef::npos);
Rui Ueyamad21b00b2015-05-31 19:17:14 +0000164 if (!hasExt)
165 Filename = Alloc.save(Filename + ".lib");
166 return doFindFile(Filename);
167}
168
169// Resolves a library path. /nodefaultlib options are taken into
170// consideration. This never returns the same path (in that case,
171// it returns None).
172Optional<StringRef> LinkerDriver::findLib(StringRef Filename) {
173 if (Config->NoDefaultLibAll)
174 return None;
175 StringRef Path = doFindLib(Filename);
176 if (Config->NoDefaultLibs.count(Path))
177 return None;
178 bool Seen = !VisitedFiles.insert(Path.lower()).second;
179 if (Seen)
180 return None;
181 return Path;
Rui Ueyama54b71da2015-05-31 19:17:12 +0000182}
183
184// Parses LIB environment which contains a list of search paths.
Rui Ueyamaf00df0a2015-06-19 22:39:48 +0000185void LinkerDriver::addLibSearchPaths() {
Rui Ueyama54b71da2015-05-31 19:17:12 +0000186 Optional<std::string> EnvOpt = Process::GetEnv("LIB");
187 if (!EnvOpt.hasValue())
Rui Ueyamaf00df0a2015-06-19 22:39:48 +0000188 return;
Rui Ueyama54b71da2015-05-31 19:17:12 +0000189 StringRef Env = Alloc.save(*EnvOpt);
190 while (!Env.empty()) {
191 StringRef Path;
192 std::tie(Path, Env) = Env.split(';');
Rui Ueyamaf00df0a2015-06-19 22:39:48 +0000193 SearchPaths.push_back(Path);
Rui Ueyama54b71da2015-05-31 19:17:12 +0000194 }
Rui Ueyama54b71da2015-05-31 19:17:12 +0000195}
196
Rui Ueyama6bf638e2015-07-02 00:04:14 +0000197Undefined *LinkerDriver::addUndefined(StringRef Name) {
198 Undefined *U = Symtab.addUndefined(Name);
Rui Ueyama18f8d2c2015-07-02 00:21:08 +0000199 Config->GCRoot.insert(U);
Rui Ueyama6bf638e2015-07-02 00:04:14 +0000200 return U;
Rui Ueyama32f8e1c2015-06-26 03:44:00 +0000201}
202
Rui Ueyama7c3e23f2015-07-09 01:25:49 +0000203// Symbol names are mangled by appending "_" prefix on x86.
204StringRef LinkerDriver::mangle(StringRef Sym) {
Rui Ueyama5e706b32015-07-25 21:54:50 +0000205 assert(Config->Machine != IMAGE_FILE_MACHINE_UNKNOWN);
206 if (Config->Machine == I386)
Rui Ueyama7c3e23f2015-07-09 01:25:49 +0000207 return Alloc.save("_" + Sym);
208 return Sym;
209}
210
Rui Ueyama45044f42015-06-29 01:03:53 +0000211// Windows specific -- find default entry point name.
212StringRef LinkerDriver::findDefaultEntry() {
213 // User-defined main functions and their corresponding entry points.
214 static const char *Entries[][2] = {
215 {"main", "mainCRTStartup"},
216 {"wmain", "wmainCRTStartup"},
217 {"WinMain", "WinMainCRTStartup"},
218 {"wWinMain", "wWinMainCRTStartup"},
219 };
220 for (auto E : Entries) {
Rui Ueyamaa50387f2015-07-14 02:58:13 +0000221 StringRef Entry = Symtab.findMangle(mangle(E[0]));
222 if (!Entry.empty() && !isa<Undefined>(Symtab.find(Entry)->Body))
Rui Ueyama7c3e23f2015-07-09 01:25:49 +0000223 return mangle(E[1]);
Rui Ueyama45044f42015-06-29 01:03:53 +0000224 }
225 return "";
226}
227
228WindowsSubsystem LinkerDriver::inferSubsystem() {
Rui Ueyama97dff9e2015-06-17 00:16:33 +0000229 if (Config->DLL)
230 return IMAGE_SUBSYSTEM_WINDOWS_GUI;
Rui Ueyama611add22015-08-08 00:23:37 +0000231 if (Symtab.findUnderscore("main") || Symtab.findUnderscore("wmain"))
Rui Ueyama45044f42015-06-29 01:03:53 +0000232 return IMAGE_SUBSYSTEM_WINDOWS_CUI;
Rui Ueyama611add22015-08-08 00:23:37 +0000233 if (Symtab.findUnderscore("WinMain") || Symtab.findUnderscore("wWinMain"))
Rui Ueyama45044f42015-06-29 01:03:53 +0000234 return IMAGE_SUBSYSTEM_WINDOWS_GUI;
235 return IMAGE_SUBSYSTEM_UNKNOWN;
Rui Ueyama97dff9e2015-06-17 00:16:33 +0000236}
237
Rui Ueyama5c437cd2015-07-25 21:42:33 +0000238static uint64_t getDefaultImageBase() {
239 if (Config->is64())
240 return Config->DLL ? 0x180000000 : 0x140000000;
241 return Config->DLL ? 0x10000000 : 0x400000;
242}
243
Rafael Espindolab835ae82015-08-06 14:58:50 +0000244void LinkerDriver::link(llvm::ArrayRef<const char *> ArgsArr) {
Rui Ueyama27e470a2015-08-09 20:45:17 +0000245 // If the first command line argument is "/lib", link.exe acts like lib.exe.
246 // We call our own implementation of lib.exe that understands bitcode files.
247 if (ArgsArr.size() > 1 && StringRef(ArgsArr[1]).equals_lower("/lib")) {
248 if (llvm::libDriverMain(ArgsArr.slice(1)) != 0)
249 error("lib failed");
250 return;
251 }
252
Peter Collingbourne60c16162015-06-01 20:10:10 +0000253 // Needed for LTO.
254 llvm::InitializeAllTargetInfos();
255 llvm::InitializeAllTargets();
256 llvm::InitializeAllTargetMCs();
257 llvm::InitializeAllAsmParsers();
258 llvm::InitializeAllAsmPrinters();
259 llvm::InitializeAllDisassemblers();
260
Rui Ueyama411c63602015-05-28 19:09:30 +0000261 // Parse command line options.
Rafael Espindolab835ae82015-08-06 14:58:50 +0000262 llvm::opt::InputArgList Args = Parser.parseLINK(ArgsArr.slice(1));
Rui Ueyama411c63602015-05-28 19:09:30 +0000263
Rui Ueyama5c726432015-05-29 16:11:52 +0000264 // Handle /help
David Blaikie6521ed92015-06-22 22:06:52 +0000265 if (Args.hasArg(OPT_help)) {
David Blaikieb2b1c7c2015-06-21 06:32:10 +0000266 printHelp(ArgsArr[0]);
Rafael Espindolab835ae82015-08-06 14:58:50 +0000267 return;
Rui Ueyama5c726432015-05-29 16:11:52 +0000268 }
269
Rafael Espindolab835ae82015-08-06 14:58:50 +0000270 if (Args.filtered_begin(OPT_INPUT) == Args.filtered_end())
271 error("no input files.");
Rui Ueyama3d3e6fb2015-05-29 16:06:00 +0000272
Rui Ueyamaf00df0a2015-06-19 22:39:48 +0000273 // Construct search path list.
274 SearchPaths.push_back("");
David Blaikie6521ed92015-06-22 22:06:52 +0000275 for (auto *Arg : Args.filtered(OPT_libpath))
Rui Ueyamaf00df0a2015-06-19 22:39:48 +0000276 SearchPaths.push_back(Arg->getValue());
277 addLibSearchPaths();
278
Rui Ueyamaad660982015-06-07 00:20:32 +0000279 // Handle /out
David Blaikie6521ed92015-06-22 22:06:52 +0000280 if (auto *Arg = Args.getLastArg(OPT_out))
Rui Ueyamaad660982015-06-07 00:20:32 +0000281 Config->OutputFile = Arg->getValue();
282
Rui Ueyama3d3e6fb2015-05-29 16:06:00 +0000283 // Handle /verbose
David Blaikie6521ed92015-06-22 22:06:52 +0000284 if (Args.hasArg(OPT_verbose))
Rui Ueyama411c63602015-05-28 19:09:30 +0000285 Config->Verbose = true;
Rui Ueyama3d3e6fb2015-05-29 16:06:00 +0000286
Rui Ueyama95925fd2015-06-28 19:35:15 +0000287 // Handle /force or /force:unresolved
288 if (Args.hasArg(OPT_force) || Args.hasArg(OPT_force_unresolved))
289 Config->Force = true;
290
Rui Ueyama6600eb12015-07-04 23:37:32 +0000291 // Handle /debug
292 if (Args.hasArg(OPT_debug))
293 Config->Debug = true;
294
Rui Ueyamaa8b60452015-06-28 19:56:30 +0000295 // Handle /noentry
296 if (Args.hasArg(OPT_noentry)) {
Rafael Espindolab835ae82015-08-06 14:58:50 +0000297 if (!Args.hasArg(OPT_dll))
298 error("/noentry must be specified with /dll");
Rui Ueyamaa8b60452015-06-28 19:56:30 +0000299 Config->NoEntry = true;
300 }
301
Rui Ueyama97dff9e2015-06-17 00:16:33 +0000302 // Handle /dll
David Blaikie6521ed92015-06-22 22:06:52 +0000303 if (Args.hasArg(OPT_dll)) {
Rui Ueyama97dff9e2015-06-17 00:16:33 +0000304 Config->DLL = true;
Rui Ueyama24c5fd02015-06-18 00:12:42 +0000305 Config->ManifestID = 2;
306 }
Rui Ueyama97dff9e2015-06-17 00:16:33 +0000307
Rui Ueyama588e8322015-06-15 01:23:58 +0000308 // Handle /fixed
David Blaikie6521ed92015-06-22 22:06:52 +0000309 if (Args.hasArg(OPT_fixed)) {
Rafael Espindolab835ae82015-08-06 14:58:50 +0000310 if (Args.hasArg(OPT_dynamicbase))
311 error("/fixed must not be specified with /dynamicbase");
Rui Ueyama588e8322015-06-15 01:23:58 +0000312 Config->Relocatable = false;
Rui Ueyama6592ff82015-06-16 23:13:00 +0000313 Config->DynamicBase = false;
314 }
Rui Ueyama588e8322015-06-15 01:23:58 +0000315
Rui Ueyama3d3e6fb2015-05-29 16:06:00 +0000316 // Handle /machine
Rafael Espindolab835ae82015-08-06 14:58:50 +0000317 if (auto *Arg = Args.getLastArg(OPT_machine))
318 Config->Machine = getMachineType(Arg->getValue());
Rui Ueyama3d3e6fb2015-05-29 16:06:00 +0000319
Rui Ueyamad21b00b2015-05-31 19:17:14 +0000320 // Handle /nodefaultlib:<filename>
David Blaikie6521ed92015-06-22 22:06:52 +0000321 for (auto *Arg : Args.filtered(OPT_nodefaultlib))
Rui Ueyamad21b00b2015-05-31 19:17:14 +0000322 Config->NoDefaultLibs.insert(doFindLib(Arg->getValue()));
323
324 // Handle /nodefaultlib
David Blaikie6521ed92015-06-22 22:06:52 +0000325 if (Args.hasArg(OPT_nodefaultlib_all))
Rui Ueyamad21b00b2015-05-31 19:17:14 +0000326 Config->NoDefaultLibAll = true;
327
Rui Ueyama804a8b62015-05-29 16:18:15 +0000328 // Handle /base
Rafael Espindolab835ae82015-08-06 14:58:50 +0000329 if (auto *Arg = Args.getLastArg(OPT_base))
330 parseNumbers(Arg->getValue(), &Config->ImageBase);
Rui Ueyamab41b7e52015-05-29 16:21:11 +0000331
332 // Handle /stack
Rafael Espindolab835ae82015-08-06 14:58:50 +0000333 if (auto *Arg = Args.getLastArg(OPT_stack))
334 parseNumbers(Arg->getValue(), &Config->StackReserve, &Config->StackCommit);
Rui Ueyama804a8b62015-05-29 16:18:15 +0000335
Rui Ueyamac377e9a2015-05-29 16:23:40 +0000336 // Handle /heap
Rafael Espindolab835ae82015-08-06 14:58:50 +0000337 if (auto *Arg = Args.getLastArg(OPT_heap))
338 parseNumbers(Arg->getValue(), &Config->HeapReserve, &Config->HeapCommit);
Rui Ueyamac377e9a2015-05-29 16:23:40 +0000339
Rui Ueyamab9dcdb52015-05-29 16:28:29 +0000340 // Handle /version
Rafael Espindolab835ae82015-08-06 14:58:50 +0000341 if (auto *Arg = Args.getLastArg(OPT_version))
342 parseVersion(Arg->getValue(), &Config->MajorImageVersion,
343 &Config->MinorImageVersion);
Rui Ueyamab9dcdb52015-05-29 16:28:29 +0000344
Rui Ueyama15cc47e2015-05-29 16:34:31 +0000345 // Handle /subsystem
Rafael Espindolab835ae82015-08-06 14:58:50 +0000346 if (auto *Arg = Args.getLastArg(OPT_subsystem))
347 parseSubsystem(Arg->getValue(), &Config->Subsystem, &Config->MajorOSVersion,
348 &Config->MinorOSVersion);
Rui Ueyama15cc47e2015-05-29 16:34:31 +0000349
Rui Ueyama2edb35a2015-06-18 19:09:30 +0000350 // Handle /alternatename
David Blaikie6521ed92015-06-22 22:06:52 +0000351 for (auto *Arg : Args.filtered(OPT_alternatename))
Rafael Espindolab835ae82015-08-06 14:58:50 +0000352 parseAlternateName(Arg->getValue());
Rui Ueyama2edb35a2015-06-18 19:09:30 +0000353
Rui Ueyama08d5e182015-06-18 23:20:11 +0000354 // Handle /include
David Blaikie6521ed92015-06-22 22:06:52 +0000355 for (auto *Arg : Args.filtered(OPT_incl))
Rui Ueyama32f8e1c2015-06-26 03:44:00 +0000356 addUndefined(Arg->getValue());
Rui Ueyama08d5e182015-06-18 23:20:11 +0000357
Rui Ueyamab95188c2015-06-18 20:27:09 +0000358 // Handle /implib
David Blaikie6521ed92015-06-22 22:06:52 +0000359 if (auto *Arg = Args.getLastArg(OPT_implib))
Rui Ueyamab95188c2015-06-18 20:27:09 +0000360 Config->Implib = Arg->getValue();
361
Rui Ueyamae2cbfea2015-06-07 03:17:42 +0000362 // Handle /opt
David Blaikie6521ed92015-06-22 22:06:52 +0000363 for (auto *Arg : Args.filtered(OPT_opt)) {
Rui Ueyamae2cbfea2015-06-07 03:17:42 +0000364 std::string S = StringRef(Arg->getValue()).lower();
365 if (S == "noref") {
366 Config->DoGC = false;
Rui Ueyamab02a3202015-09-16 16:41:38 +0000367 Config->DoICF = false;
Rui Ueyamae2cbfea2015-06-07 03:17:42 +0000368 continue;
369 }
Rui Ueyamac04d5db2015-09-16 16:33:57 +0000370 if (S == "icf" || StringRef(S).startswith("icf=")) {
371 Config->DoICF = true;
Rui Ueyamaddf71fc2015-06-24 04:36:52 +0000372 continue;
373 }
Rui Ueyama3b153e62015-09-16 21:30:55 +0000374 if (S == "noicf") {
375 Config->DoICF = false;
376 continue;
377 }
Peter Collingbourne526ff152015-08-14 04:47:07 +0000378 if (StringRef(S).startswith("lldlto=")) {
379 StringRef OptLevel = StringRef(S).substr(7);
380 if (OptLevel.getAsInteger(10, Config->LTOOptLevel) ||
Peter Collingbournedf5783b2015-08-28 22:16:09 +0000381 Config->LTOOptLevel > 3)
Peter Collingbourne526ff152015-08-14 04:47:07 +0000382 error("/opt:lldlto: invalid optimization level: " + OptLevel);
Peter Collingbournedf5783b2015-08-28 22:16:09 +0000383 continue;
384 }
385 if (StringRef(S).startswith("lldltojobs=")) {
386 StringRef Jobs = StringRef(S).substr(11);
387 if (Jobs.getAsInteger(10, Config->LTOJobs) || Config->LTOJobs == 0)
388 error("/opt:lldltojobs: invalid job count: " + Jobs);
Peter Collingbourne526ff152015-08-14 04:47:07 +0000389 continue;
390 }
Rui Ueyama3b153e62015-09-16 21:30:55 +0000391 if (S != "ref" && S != "lbr" && S != "nolbr")
Rafael Espindolab835ae82015-08-06 14:58:50 +0000392 error(Twine("/opt: unknown option: ") + S);
Rui Ueyamae2cbfea2015-06-07 03:17:42 +0000393 }
394
Rui Ueyama8854d8a2015-06-04 19:21:24 +0000395 // Handle /failifmismatch
David Blaikie6521ed92015-06-22 22:06:52 +0000396 for (auto *Arg : Args.filtered(OPT_failifmismatch))
Rafael Espindolab835ae82015-08-06 14:58:50 +0000397 checkFailIfMismatch(Arg->getValue());
Rui Ueyama8854d8a2015-06-04 19:21:24 +0000398
Rui Ueyama6600eb12015-07-04 23:37:32 +0000399 // Handle /merge
400 for (auto *Arg : Args.filtered(OPT_merge))
Rafael Espindolab835ae82015-08-06 14:58:50 +0000401 parseMerge(Arg->getValue());
Rui Ueyama6600eb12015-07-04 23:37:32 +0000402
Rui Ueyama24c5fd02015-06-18 00:12:42 +0000403 // Handle /manifest
Rafael Espindolab835ae82015-08-06 14:58:50 +0000404 if (auto *Arg = Args.getLastArg(OPT_manifest_colon))
405 parseManifest(Arg->getValue());
Rui Ueyama24c5fd02015-06-18 00:12:42 +0000406
407 // Handle /manifestuac
Rafael Espindolab835ae82015-08-06 14:58:50 +0000408 if (auto *Arg = Args.getLastArg(OPT_manifestuac))
409 parseManifestUAC(Arg->getValue());
Rui Ueyama24c5fd02015-06-18 00:12:42 +0000410
411 // Handle /manifestdependency
David Blaikie6521ed92015-06-22 22:06:52 +0000412 if (auto *Arg = Args.getLastArg(OPT_manifestdependency))
Rui Ueyama24c5fd02015-06-18 00:12:42 +0000413 Config->ManifestDependency = Arg->getValue();
414
415 // Handle /manifestfile
David Blaikie6521ed92015-06-22 22:06:52 +0000416 if (auto *Arg = Args.getLastArg(OPT_manifestfile))
Rui Ueyama24c5fd02015-06-18 00:12:42 +0000417 Config->ManifestFile = Arg->getValue();
418
Rui Ueyama6592ff82015-06-16 23:13:00 +0000419 // Handle miscellaneous boolean flags.
David Blaikie6521ed92015-06-22 22:06:52 +0000420 if (Args.hasArg(OPT_allowbind_no))
421 Config->AllowBind = false;
422 if (Args.hasArg(OPT_allowisolation_no))
423 Config->AllowIsolation = false;
424 if (Args.hasArg(OPT_dynamicbase_no))
425 Config->DynamicBase = false;
David Blaikie6521ed92015-06-22 22:06:52 +0000426 if (Args.hasArg(OPT_nxcompat_no))
427 Config->NxCompat = false;
428 if (Args.hasArg(OPT_tsaware_no))
429 Config->TerminalServerAware = false;
Rui Ueyama96401732015-09-21 23:43:31 +0000430 if (Args.hasArg(OPT_nosymtab))
431 Config->WriteSymtab = false;
Rui Ueyama6592ff82015-06-16 23:13:00 +0000432
Rui Ueyamad21b00b2015-05-31 19:17:14 +0000433 // Create a list of input files. Files can be given as arguments
434 // for /defaultlib option.
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000435 std::vector<StringRef> Paths;
436 std::vector<MemoryBufferRef> MBs;
David Blaikie6521ed92015-06-22 22:06:52 +0000437 for (auto *Arg : Args.filtered(OPT_INPUT))
Rui Ueyamad21b00b2015-05-31 19:17:14 +0000438 if (Optional<StringRef> Path = findFile(Arg->getValue()))
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000439 Paths.push_back(*Path);
David Blaikie6521ed92015-06-22 22:06:52 +0000440 for (auto *Arg : Args.filtered(OPT_defaultlib))
Rui Ueyamad21b00b2015-05-31 19:17:14 +0000441 if (Optional<StringRef> Path = findLib(Arg->getValue()))
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000442 Paths.push_back(*Path);
Rafael Espindolab835ae82015-08-06 14:58:50 +0000443 for (StringRef Path : Paths)
444 MBs.push_back(openFile(Path));
Rui Ueyamad21b00b2015-05-31 19:17:14 +0000445
Rui Ueyama24c5fd02015-06-18 00:12:42 +0000446 // Windows specific -- Create a resource file containing a manifest file.
447 if (Config->Manifest == Configuration::Embed) {
Rafael Espindolab835ae82015-08-06 14:58:50 +0000448 std::unique_ptr<MemoryBuffer> MB = createManifestRes();
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000449 MBs.push_back(MB->getMemBufferRef());
Rui Ueyama24c5fd02015-06-18 00:12:42 +0000450 OwningMBs.push_back(std::move(MB)); // take ownership
451 }
452
Rui Ueyama2bf6a122015-06-14 21:50:50 +0000453 // Windows specific -- Input files can be Windows resource files (.res files).
454 // We invoke cvtres.exe to convert resource files to a regular COFF file
455 // then link the result file normally.
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000456 std::vector<MemoryBufferRef> Resources;
Rui Ueyama77731b42015-06-26 23:59:13 +0000457 auto NotResource = [](MemoryBufferRef MB) {
458 return identify_magic(MB.getBuffer()) != file_magic::windows_resource;
Rui Ueyama2bf6a122015-06-14 21:50:50 +0000459 };
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000460 auto It = std::stable_partition(MBs.begin(), MBs.end(), NotResource);
461 if (It != MBs.end()) {
462 Resources.insert(Resources.end(), It, MBs.end());
463 MBs.erase(It, MBs.end());
Rui Ueyama2bf6a122015-06-14 21:50:50 +0000464 }
465
Rui Ueyama85225b02015-07-02 03:15:15 +0000466 // Read all input files given via the command line. Note that step()
467 // doesn't read files that are specified by directive sections.
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000468 for (MemoryBufferRef MB : MBs)
Rui Ueyama0d2e9992015-06-23 23:56:39 +0000469 Symtab.addFile(createFile(MB));
Rafael Espindolab835ae82015-08-06 14:58:50 +0000470 Symtab.step();
Rui Ueyama5cff6852015-05-31 03:34:08 +0000471
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000472 // Determine machine type and check if all object files are
473 // for the same CPU type. Note that this needs to be done before
474 // any call to mangle().
475 for (std::unique_ptr<InputFile> &File : Symtab.getFiles()) {
476 MachineTypes MT = File->getMachineType();
477 if (MT == IMAGE_FILE_MACHINE_UNKNOWN)
478 continue;
Rui Ueyama5e706b32015-07-25 21:54:50 +0000479 if (Config->Machine == IMAGE_FILE_MACHINE_UNKNOWN) {
480 Config->Machine = MT;
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000481 continue;
482 }
Rafael Espindolab835ae82015-08-06 14:58:50 +0000483 if (Config->Machine != MT)
484 error(Twine(File->getShortName()) + ": machine type " + machineToStr(MT) +
485 " conflicts with " + machineToStr(Config->Machine));
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000486 }
Rui Ueyama5e706b32015-07-25 21:54:50 +0000487 if (Config->Machine == IMAGE_FILE_MACHINE_UNKNOWN) {
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000488 llvm::errs() << "warning: /machine is not specified. x64 is assumed.\n";
Rui Ueyama5e706b32015-07-25 21:54:50 +0000489 Config->Machine = AMD64;
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000490 }
491
492 // Windows specific -- Convert Windows resource files to a COFF file.
493 if (!Resources.empty()) {
Rafael Espindolab835ae82015-08-06 14:58:50 +0000494 std::unique_ptr<MemoryBuffer> MB = convertResToCOFF(Resources);
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000495 Symtab.addFile(createFile(MB->getMemBufferRef()));
496 OwningMBs.push_back(std::move(MB)); // take ownership
497 }
498
Rui Ueyama4d545342015-07-28 03:12:00 +0000499 // Handle /largeaddressaware
500 if (Config->is64() || Args.hasArg(OPT_largeaddressaware))
501 Config->LargeAddressAware = true;
502
Rui Ueyamad68e2112015-07-28 03:15:57 +0000503 // Handle /highentropyva
504 if (Config->is64() && !Args.hasArg(OPT_highentropyva_no))
505 Config->HighEntropyVA = true;
506
Rui Ueyamabbdec4f2015-07-09 22:51:41 +0000507 // Handle /entry and /dll
508 if (auto *Arg = Args.getLastArg(OPT_entry)) {
509 Config->Entry = addUndefined(mangle(Arg->getValue()));
510 } else if (Args.hasArg(OPT_dll) && !Config->NoEntry) {
Rui Ueyama5e706b32015-07-25 21:54:50 +0000511 StringRef S = (Config->Machine == I386) ? "__DllMainCRTStartup@12"
512 : "_DllMainCRTStartup";
Rui Ueyamabbdec4f2015-07-09 22:51:41 +0000513 Config->Entry = addUndefined(S);
514 } else if (!Config->NoEntry) {
515 // Windows specific -- If entry point name is not given, we need to
516 // infer that from user-defined entry name.
Rui Ueyama45044f42015-06-29 01:03:53 +0000517 StringRef S = findDefaultEntry();
Rafael Espindolab835ae82015-08-06 14:58:50 +0000518 if (S.empty())
519 error("entry point must be defined");
Rui Ueyama6bf638e2015-07-02 00:04:14 +0000520 Config->Entry = addUndefined(S);
Rui Ueyama85225b02015-07-02 03:15:15 +0000521 if (Config->Verbose)
522 llvm::outs() << "Entry name inferred: " << S << "\n";
Rui Ueyama45044f42015-06-29 01:03:53 +0000523 }
524
Rui Ueyamabbdec4f2015-07-09 22:51:41 +0000525 // Handle /export
526 for (auto *Arg : Args.filtered(OPT_export)) {
Rafael Espindolab835ae82015-08-06 14:58:50 +0000527 Export E = parseExport(Arg->getValue());
Rui Ueyamaf10a3202015-08-31 08:43:21 +0000528 if (Config->Machine == I386) {
529 if (!isDecorated(E.Name))
530 E.Name = Alloc.save("_" + E.Name);
531 if (!E.ExtName.empty() && !isDecorated(E.ExtName))
532 E.ExtName = Alloc.save("_" + E.ExtName);
533 }
Rafael Espindolab835ae82015-08-06 14:58:50 +0000534 Config->Exports.push_back(E);
Rui Ueyamabbdec4f2015-07-09 22:51:41 +0000535 }
536
537 // Handle /def
538 if (auto *Arg = Args.getLastArg(OPT_deffile)) {
Rafael Espindolab835ae82015-08-06 14:58:50 +0000539 MemoryBufferRef MB = openFile(Arg->getValue());
Rui Ueyamabbdec4f2015-07-09 22:51:41 +0000540 // parseModuleDefs mutates Config object.
Rafael Espindolab835ae82015-08-06 14:58:50 +0000541 parseModuleDefs(MB, &Alloc);
Rui Ueyamabbdec4f2015-07-09 22:51:41 +0000542 }
543
Rui Ueyama6d249082015-07-13 22:31:45 +0000544 // Handle /delayload
545 for (auto *Arg : Args.filtered(OPT_delayload)) {
546 Config->DelayLoads.insert(StringRef(Arg->getValue()).lower());
Rui Ueyama5e706b32015-07-25 21:54:50 +0000547 if (Config->Machine == I386) {
Rui Ueyama6d249082015-07-13 22:31:45 +0000548 Config->DelayLoadHelper = addUndefined("___delayLoadHelper2@8");
Rui Ueyama35ccb0f2015-07-25 00:20:06 +0000549 } else {
550 Config->DelayLoadHelper = addUndefined("__delayLoadHelper2");
Rui Ueyama6d249082015-07-13 22:31:45 +0000551 }
552 }
553
Rui Ueyama5c437cd2015-07-25 21:42:33 +0000554 // Set default image base if /base is not given.
555 if (Config->ImageBase == uint64_t(-1))
556 Config->ImageBase = getDefaultImageBase();
557
Rui Ueyama3cb895c2015-07-24 22:58:44 +0000558 Symtab.addRelative(mangle("__ImageBase"), 0);
Rui Ueyama5e706b32015-07-25 21:54:50 +0000559 if (Config->Machine == I386) {
Rui Ueyamacd3f99b2015-07-24 23:51:14 +0000560 Config->SEHTable = Symtab.addRelative("___safe_se_handler_table", 0);
561 Config->SEHCount = Symtab.addAbsolute("___safe_se_handler_count", 0);
562 }
Rui Ueyamabbdec4f2015-07-09 22:51:41 +0000563
Rui Ueyama107db552015-08-09 21:01:06 +0000564 // We do not support /guard:cf (control flow protection) yet.
565 // Define CFG symbols anyway so that we can link MSVC 2015 CRT.
566 Symtab.addAbsolute(mangle("__guard_fids_table"), 0);
567 Symtab.addAbsolute(mangle("__guard_fids_count"), 0);
568 Symtab.addAbsolute(mangle("__guard_flags"), 0x100);
569
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000570 // Read as much files as we can from directives sections.
Rafael Espindolab835ae82015-08-06 14:58:50 +0000571 Symtab.run();
Rui Ueyama85225b02015-07-02 03:15:15 +0000572
573 // Resolve auxiliary symbols until we get a convergence.
Rui Ueyama573bf7d2015-06-19 21:12:48 +0000574 // (Trying to resolve a symbol may trigger a Lazy symbol to load a new file.
575 // A new file may contain a directive section to add new command line options.
576 // That's why we have to repeat until converge.)
577 for (;;) {
Rui Ueyama6bf638e2015-07-02 00:04:14 +0000578 // Windows specific -- if entry point is not found,
579 // search for its mangled names.
580 if (Config->Entry)
581 Symtab.mangleMaybe(Config->Entry);
582
Rui Ueyama573bf7d2015-06-19 21:12:48 +0000583 // Windows specific -- Make sure we resolve all dllexported symbols.
Rui Ueyama6bf638e2015-07-02 00:04:14 +0000584 for (Export &E : Config->Exports) {
585 E.Sym = addUndefined(E.Name);
Rui Ueyamaf10a3202015-08-31 08:43:21 +0000586 if (!E.Directives)
587 Symtab.mangleMaybe(E.Sym);
Rui Ueyama6bf638e2015-07-02 00:04:14 +0000588 }
Rui Ueyama573bf7d2015-06-19 21:12:48 +0000589
590 // Add weak aliases. Weak aliases is a mechanism to give remaining
591 // undefined symbols final chance to be resolved successfully.
Rui Ueyama3d4c69c2015-07-02 02:38:59 +0000592 for (auto Pair : Config->AlternateNames) {
593 StringRef From = Pair.first;
594 StringRef To = Pair.second;
Rui Ueyama458d7442015-07-02 03:59:04 +0000595 Symbol *Sym = Symtab.find(From);
Rui Ueyama3d4c69c2015-07-02 02:38:59 +0000596 if (!Sym)
597 continue;
Rui Ueyama183f53f2015-07-06 17:45:22 +0000598 if (auto *U = dyn_cast<Undefined>(Sym->Body))
Rui Ueyama3d4c69c2015-07-02 02:38:59 +0000599 if (!U->WeakAlias)
600 U->WeakAlias = Symtab.addUndefined(To);
Rui Ueyama2edb35a2015-06-18 19:09:30 +0000601 }
Rui Ueyama573bf7d2015-06-19 21:12:48 +0000602
Rui Ueyamacd3f99b2015-07-24 23:51:14 +0000603 // Windows specific -- if __load_config_used can be resolved, resolve it.
Rui Ueyama8ebdc8c2015-08-07 22:43:53 +0000604 if (Symtab.findUnderscore("_load_config_used"))
605 addUndefined(mangle("_load_config_used"));
Rui Ueyamacd3f99b2015-07-24 23:51:14 +0000606
Rui Ueyama3d4c69c2015-07-02 02:38:59 +0000607 if (Symtab.queueEmpty())
608 break;
Rafael Espindolab835ae82015-08-06 14:58:50 +0000609 Symtab.run();
Rui Ueyama2edb35a2015-06-18 19:09:30 +0000610 }
611
Peter Collingbournedf5783b2015-08-28 22:16:09 +0000612 // Do LTO by compiling bitcode input files to a set of native COFF files then
613 // link those files.
614 Symtab.addCombinedLTOObjects();
Peter Collingbourne60c16162015-06-01 20:10:10 +0000615
Peter Collingbourne2612a322015-07-04 05:28:41 +0000616 // Make sure we have resolved all symbols.
Rafael Espindolab835ae82015-08-06 14:58:50 +0000617 Symtab.reportRemainingUndefines(/*Resolve=*/true);
Peter Collingbourne2612a322015-07-04 05:28:41 +0000618
Rui Ueyama3ee0fe42015-05-31 03:55:46 +0000619 // Windows specific -- if no /subsystem is given, we need to infer
620 // that from entry point name.
621 if (Config->Subsystem == IMAGE_SUBSYSTEM_UNKNOWN) {
Rui Ueyama97dff9e2015-06-17 00:16:33 +0000622 Config->Subsystem = inferSubsystem();
Rafael Espindolab835ae82015-08-06 14:58:50 +0000623 if (Config->Subsystem == IMAGE_SUBSYSTEM_UNKNOWN)
624 error("subsystem must be defined");
Rui Ueyama3ee0fe42015-05-31 03:55:46 +0000625 }
626
Rui Ueyamaff88d5a2015-07-29 20:25:40 +0000627 // Handle /safeseh.
Rui Ueyama13563d82015-09-15 00:33:11 +0000628 if (Args.hasArg(OPT_safeseh))
629 for (ObjectFile *File : Symtab.ObjectFiles)
630 if (!File->SEHCompat)
631 error("/safeseh: " + File->getName() + " is not compatible with SEH");
Rui Ueyamaff88d5a2015-07-29 20:25:40 +0000632
Rui Ueyama151d8622015-06-17 20:40:43 +0000633 // Windows specific -- when we are creating a .dll file, we also
634 // need to create a .lib file.
Rui Ueyama100ffac2015-09-01 09:15:58 +0000635 if (!Config->Exports.empty() || Config->DLL) {
Rafael Espindolab835ae82015-08-06 14:58:50 +0000636 fixupExports();
637 writeImportLibrary();
Rui Ueyama8765fba2015-07-15 22:21:08 +0000638 assignExportOrdinals();
639 }
Rui Ueyama97dff9e2015-06-17 00:16:33 +0000640
Rui Ueyama24c5fd02015-06-18 00:12:42 +0000641 // Windows specific -- Create a side-by-side manifest file.
642 if (Config->Manifest == Configuration::SideBySide)
Rafael Espindolab835ae82015-08-06 14:58:50 +0000643 createSideBySideManifest();
Rui Ueyama24c5fd02015-06-18 00:12:42 +0000644
Rui Ueyama0fc26d22015-06-29 14:27:12 +0000645 // Create a dummy PDB file to satisfy build sytem rules.
646 if (auto *Arg = Args.getLastArg(OPT_pdb))
647 touchFile(Arg->getValue());
648
Rui Ueyamaa5f0f752015-09-19 21:36:28 +0000649 // Identify unreferenced COMDAT sections.
650 if (Config->DoGC)
651 markLive(Symtab.getChunks());
652
653 // Identify identical COMDAT sections to merge them.
654 if (Config->DoICF)
655 doICF(Symtab.getChunks());
656
Rui Ueyama411c63602015-05-28 19:09:30 +0000657 // Write the result.
Rafael Espindolab835ae82015-08-06 14:58:50 +0000658 writeResult(&Symtab);
Peter Collingbournebe549552015-06-26 18:58:24 +0000659
Rui Ueyama016414f2015-06-28 20:07:08 +0000660 // Create a symbol map file containing symbol VAs and their names
661 // to help debugging.
Peter Collingbournebe549552015-06-26 18:58:24 +0000662 if (auto *Arg = Args.getLastArg(OPT_lldmap)) {
663 std::error_code EC;
Peter Collingbournebaf5f872015-06-26 19:20:09 +0000664 llvm::raw_fd_ostream Out(Arg->getValue(), EC, OpenFlags::F_Text);
Rafael Espindolab835ae82015-08-06 14:58:50 +0000665 error(EC, "Could not create the symbol map");
Peter Collingbournebe549552015-06-26 18:58:24 +0000666 Symtab.printMap(Out);
667 }
Rui Ueyamaa51ce712015-07-03 05:31:35 +0000668 // Call exit to avoid calling destructors.
669 exit(0);
Rui Ueyama411c63602015-05-28 19:09:30 +0000670}
671
Rui Ueyama411c63602015-05-28 19:09:30 +0000672} // namespace coff
673} // namespace lld