blob: 2a71343aa3048264eccc326fbd4ae77d6fd28ccf [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 Ueyamaa453c0a2016-03-02 19:08:05 +000017#include "lld/Driver/Driver.h"
Rui Ueyama411c63602015-05-28 19:09:30 +000018#include "llvm/ADT/Optional.h"
Peter Collingbournebd1cb792015-06-09 21:52:48 +000019#include "llvm/LibDriver/LibDriver.h"
Rui Ueyama411c63602015-05-28 19:09:30 +000020#include "llvm/Option/Arg.h"
21#include "llvm/Option/ArgList.h"
22#include "llvm/Option/Option.h"
Rui Ueyama411c63602015-05-28 19:09:30 +000023#include "llvm/Support/Debug.h"
Rui Ueyama411c63602015-05-28 19:09:30 +000024#include "llvm/Support/Path.h"
Rui Ueyama54b71da2015-05-31 19:17:12 +000025#include "llvm/Support/Process.h"
Peter Collingbourne60c16162015-06-01 20:10:10 +000026#include "llvm/Support/TargetSelect.h"
Rui Ueyama411c63602015-05-28 19:09:30 +000027#include "llvm/Support/raw_ostream.h"
Rui Ueyama2bf6a122015-06-14 21:50:50 +000028#include <algorithm>
Rui Ueyama411c63602015-05-28 19:09:30 +000029#include <memory>
30
31using namespace llvm;
Rui Ueyama84936e02015-07-07 23:39:18 +000032using namespace llvm::COFF;
Rui Ueyama54b71da2015-05-31 19:17:12 +000033using llvm::sys::Process;
Peter Collingbournebaf5f872015-06-26 19:20:09 +000034using llvm::sys::fs::OpenFlags;
Rui Ueyama711cd2d2015-05-31 21:17:10 +000035using llvm::sys::fs::file_magic;
36using llvm::sys::fs::identify_magic;
Rui Ueyama411c63602015-05-28 19:09:30 +000037
Rui Ueyama3500f662015-05-28 20:30:06 +000038namespace lld {
39namespace coff {
Rui Ueyama411c63602015-05-28 19:09:30 +000040
Rui Ueyama3500f662015-05-28 20:30:06 +000041Configuration *Config;
Rui Ueyamaa9cbbf82015-05-31 19:17:09 +000042LinkerDriver *Driver;
43
Rui Ueyama417553d2016-02-28 19:54:51 +000044bool link(llvm::ArrayRef<const char *> Args) {
Rui Ueyama570752c2015-08-18 09:13:25 +000045 Configuration C;
46 LinkerDriver D;
47 Config = &C;
48 Driver = &D;
Rui Ueyama417553d2016-02-28 19:54:51 +000049 Driver->link(Args);
50 return true;
Rui Ueyamaa9cbbf82015-05-31 19:17:09 +000051}
Rui Ueyama411c63602015-05-28 19:09:30 +000052
Rui Ueyamaad660982015-06-07 00:20:32 +000053// Drop directory components and replace extension with ".exe".
54static std::string getOutputPath(StringRef Path) {
55 auto P = Path.find_last_of("\\/");
56 StringRef S = (P == StringRef::npos) ? Path : Path.substr(P + 1);
57 return (S.substr(0, S.rfind('.')) + ".exe").str();
Rui Ueyama411c63602015-05-28 19:09:30 +000058}
59
Rui Ueyamad7c2f582015-05-31 21:04:56 +000060// Opens a file. Path has to be resolved already.
61// Newly created memory buffers are owned by this driver.
Rafael Espindolab835ae82015-08-06 14:58:50 +000062MemoryBufferRef LinkerDriver::openFile(StringRef Path) {
Rui Ueyamad7c2f582015-05-31 21:04:56 +000063 auto MBOrErr = MemoryBuffer::getFile(Path);
Rafael Espindolab835ae82015-08-06 14:58:50 +000064 error(MBOrErr, Twine("Could not open ") + Path);
65 std::unique_ptr<MemoryBuffer> &MB = *MBOrErr;
Rui Ueyamad7c2f582015-05-31 21:04:56 +000066 MemoryBufferRef MBRef = MB->getMemBufferRef();
67 OwningMBs.push_back(std::move(MB)); // take ownership
Rui Ueyama2bf6a122015-06-14 21:50:50 +000068 return MBRef;
69}
Rui Ueyama711cd2d2015-05-31 21:17:10 +000070
Rui Ueyama2bf6a122015-06-14 21:50:50 +000071static std::unique_ptr<InputFile> createFile(MemoryBufferRef MB) {
Rui Ueyama711cd2d2015-05-31 21:17:10 +000072 // File type is detected by contents, not by file extension.
Rui Ueyama2bf6a122015-06-14 21:50:50 +000073 file_magic Magic = identify_magic(MB.getBuffer());
Rui Ueyama711cd2d2015-05-31 21:17:10 +000074 if (Magic == file_magic::archive)
Rui Ueyama2bf6a122015-06-14 21:50:50 +000075 return std::unique_ptr<InputFile>(new ArchiveFile(MB));
Peter Collingbourne60c16162015-06-01 20:10:10 +000076 if (Magic == file_magic::bitcode)
Rui Ueyama2bf6a122015-06-14 21:50:50 +000077 return std::unique_ptr<InputFile>(new BitcodeFile(MB));
Rui Ueyamaad660982015-06-07 00:20:32 +000078 if (Config->OutputFile == "")
Rui Ueyama2bf6a122015-06-14 21:50:50 +000079 Config->OutputFile = getOutputPath(MB.getBufferIdentifier());
80 return std::unique_ptr<InputFile>(new ObjectFile(MB));
Rui Ueyama411c63602015-05-28 19:09:30 +000081}
82
Rui Ueyamaf10a3202015-08-31 08:43:21 +000083static bool isDecorated(StringRef Sym) {
84 return Sym.startswith("_") || Sym.startswith("@") || Sym.startswith("?");
85}
86
Rui Ueyama411c63602015-05-28 19:09:30 +000087// Parses .drectve section contents and returns a list of files
88// specified by /defaultlib.
Rafael Espindolab835ae82015-08-06 14:58:50 +000089void LinkerDriver::parseDirectives(StringRef S) {
90 llvm::opt::InputArgList Args = Parser.parse(S);
Rui Ueyama411c63602015-05-28 19:09:30 +000091
David Blaikie6521ed92015-06-22 22:06:52 +000092 for (auto *Arg : Args) {
Rui Ueyama562daa82015-06-18 21:50:38 +000093 switch (Arg->getOption().getID()) {
94 case OPT_alternatename:
Rafael Espindolab835ae82015-08-06 14:58:50 +000095 parseAlternateName(Arg->getValue());
Rui Ueyama562daa82015-06-18 21:50:38 +000096 break;
97 case OPT_defaultlib:
98 if (Optional<StringRef> Path = findLib(Arg->getValue())) {
Rafael Espindolab835ae82015-08-06 14:58:50 +000099 MemoryBufferRef MB = openFile(*Path);
100 Symtab.addFile(createFile(MB));
Rui Ueyama562daa82015-06-18 21:50:38 +0000101 }
102 break;
103 case OPT_export: {
Rafael Espindolab835ae82015-08-06 14:58:50 +0000104 Export E = parseExport(Arg->getValue());
Rui Ueyamaf10a3202015-08-31 08:43:21 +0000105 E.Directives = true;
Rafael Espindolab835ae82015-08-06 14:58:50 +0000106 Config->Exports.push_back(E);
Rui Ueyama562daa82015-06-18 21:50:38 +0000107 break;
108 }
109 case OPT_failifmismatch:
Rafael Espindolab835ae82015-08-06 14:58:50 +0000110 checkFailIfMismatch(Arg->getValue());
Rui Ueyama562daa82015-06-18 21:50:38 +0000111 break;
Rui Ueyama08d5e182015-06-18 23:20:11 +0000112 case OPT_incl:
Rui Ueyama32f8e1c2015-06-26 03:44:00 +0000113 addUndefined(Arg->getValue());
Rui Ueyama08d5e182015-06-18 23:20:11 +0000114 break;
Rui Ueyamace86c992015-06-18 23:22:39 +0000115 case OPT_merge:
Rafael Espindolab835ae82015-08-06 14:58:50 +0000116 parseMerge(Arg->getValue());
Rui Ueyamace86c992015-06-18 23:22:39 +0000117 break;
118 case OPT_nodefaultlib:
119 Config->NoDefaultLibs.insert(doFindLib(Arg->getValue()));
120 break;
Rui Ueyama3c4737d2015-08-11 16:46:08 +0000121 case OPT_editandcontinue:
Reid Kleckner9cd77ce2016-03-25 18:09:29 +0000122 case OPT_fastfail:
Rui Ueyama31e66e32015-09-03 16:20:47 +0000123 case OPT_guardsym:
Rui Ueyama432383172015-07-29 21:01:15 +0000124 case OPT_throwingnew:
Rui Ueyama46682632015-07-29 20:29:15 +0000125 break;
Rui Ueyama562daa82015-06-18 21:50:38 +0000126 default:
Rafael Espindolab835ae82015-08-06 14:58:50 +0000127 error(Twine(Arg->getSpelling()) + " is not allowed in .drectve");
Rui Ueyamad7c2f582015-05-31 21:04:56 +0000128 }
129 }
Rui Ueyama411c63602015-05-28 19:09:30 +0000130}
131
Rui Ueyama54b71da2015-05-31 19:17:12 +0000132// Find file from search paths. You can omit ".obj", this function takes
133// care of that. Note that the returned path is not guaranteed to exist.
Rui Ueyamad21b00b2015-05-31 19:17:14 +0000134StringRef LinkerDriver::doFindFile(StringRef Filename) {
Rui Ueyama54b71da2015-05-31 19:17:12 +0000135 bool hasPathSep = (Filename.find_first_of("/\\") != StringRef::npos);
136 if (hasPathSep)
137 return Filename;
138 bool hasExt = (Filename.find('.') != StringRef::npos);
139 for (StringRef Dir : SearchPaths) {
140 SmallString<128> Path = Dir;
141 llvm::sys::path::append(Path, Filename);
142 if (llvm::sys::fs::exists(Path.str()))
143 return Alloc.save(Path.str());
144 if (!hasExt) {
145 Path.append(".obj");
146 if (llvm::sys::fs::exists(Path.str()))
147 return Alloc.save(Path.str());
148 }
149 }
150 return Filename;
151}
152
Rui Ueyamad21b00b2015-05-31 19:17:14 +0000153// Resolves a file path. This never returns the same path
154// (in that case, it returns None).
155Optional<StringRef> LinkerDriver::findFile(StringRef Filename) {
156 StringRef Path = doFindFile(Filename);
157 bool Seen = !VisitedFiles.insert(Path.lower()).second;
158 if (Seen)
159 return None;
160 return Path;
Rui Ueyama54b71da2015-05-31 19:17:12 +0000161}
162
Rui Ueyamad21b00b2015-05-31 19:17:14 +0000163// Find library file from search path.
164StringRef LinkerDriver::doFindLib(StringRef Filename) {
165 // Add ".lib" to Filename if that has no file extension.
Rui Ueyama54b71da2015-05-31 19:17:12 +0000166 bool hasExt = (Filename.find('.') != StringRef::npos);
Rui Ueyamad21b00b2015-05-31 19:17:14 +0000167 if (!hasExt)
168 Filename = Alloc.save(Filename + ".lib");
169 return doFindFile(Filename);
170}
171
172// Resolves a library path. /nodefaultlib options are taken into
173// consideration. This never returns the same path (in that case,
174// it returns None).
175Optional<StringRef> LinkerDriver::findLib(StringRef Filename) {
176 if (Config->NoDefaultLibAll)
177 return None;
178 StringRef Path = doFindLib(Filename);
179 if (Config->NoDefaultLibs.count(Path))
180 return None;
181 bool Seen = !VisitedFiles.insert(Path.lower()).second;
182 if (Seen)
183 return None;
184 return Path;
Rui Ueyama54b71da2015-05-31 19:17:12 +0000185}
186
187// Parses LIB environment which contains a list of search paths.
Rui Ueyamaf00df0a2015-06-19 22:39:48 +0000188void LinkerDriver::addLibSearchPaths() {
Rui Ueyama54b71da2015-05-31 19:17:12 +0000189 Optional<std::string> EnvOpt = Process::GetEnv("LIB");
190 if (!EnvOpt.hasValue())
Rui Ueyamaf00df0a2015-06-19 22:39:48 +0000191 return;
Rui Ueyama54b71da2015-05-31 19:17:12 +0000192 StringRef Env = Alloc.save(*EnvOpt);
193 while (!Env.empty()) {
194 StringRef Path;
195 std::tie(Path, Env) = Env.split(';');
Rui Ueyamaf00df0a2015-06-19 22:39:48 +0000196 SearchPaths.push_back(Path);
Rui Ueyama54b71da2015-05-31 19:17:12 +0000197 }
Rui Ueyama54b71da2015-05-31 19:17:12 +0000198}
199
Rui Ueyama6bf638e2015-07-02 00:04:14 +0000200Undefined *LinkerDriver::addUndefined(StringRef Name) {
201 Undefined *U = Symtab.addUndefined(Name);
Rui Ueyama18f8d2c2015-07-02 00:21:08 +0000202 Config->GCRoot.insert(U);
Rui Ueyama6bf638e2015-07-02 00:04:14 +0000203 return U;
Rui Ueyama32f8e1c2015-06-26 03:44:00 +0000204}
205
Rui Ueyama7c3e23f2015-07-09 01:25:49 +0000206// Symbol names are mangled by appending "_" prefix on x86.
207StringRef LinkerDriver::mangle(StringRef Sym) {
Rui Ueyama5e706b32015-07-25 21:54:50 +0000208 assert(Config->Machine != IMAGE_FILE_MACHINE_UNKNOWN);
209 if (Config->Machine == I386)
Rui Ueyama7c3e23f2015-07-09 01:25:49 +0000210 return Alloc.save("_" + Sym);
211 return Sym;
212}
213
Rui Ueyama45044f42015-06-29 01:03:53 +0000214// Windows specific -- find default entry point name.
215StringRef LinkerDriver::findDefaultEntry() {
216 // User-defined main functions and their corresponding entry points.
217 static const char *Entries[][2] = {
218 {"main", "mainCRTStartup"},
219 {"wmain", "wmainCRTStartup"},
220 {"WinMain", "WinMainCRTStartup"},
221 {"wWinMain", "wWinMainCRTStartup"},
222 };
223 for (auto E : Entries) {
Rui Ueyamaa50387f2015-07-14 02:58:13 +0000224 StringRef Entry = Symtab.findMangle(mangle(E[0]));
225 if (!Entry.empty() && !isa<Undefined>(Symtab.find(Entry)->Body))
Rui Ueyama7c3e23f2015-07-09 01:25:49 +0000226 return mangle(E[1]);
Rui Ueyama45044f42015-06-29 01:03:53 +0000227 }
228 return "";
229}
230
231WindowsSubsystem LinkerDriver::inferSubsystem() {
Rui Ueyama97dff9e2015-06-17 00:16:33 +0000232 if (Config->DLL)
233 return IMAGE_SUBSYSTEM_WINDOWS_GUI;
Rui Ueyama611add22015-08-08 00:23:37 +0000234 if (Symtab.findUnderscore("main") || Symtab.findUnderscore("wmain"))
Rui Ueyama45044f42015-06-29 01:03:53 +0000235 return IMAGE_SUBSYSTEM_WINDOWS_CUI;
Rui Ueyama611add22015-08-08 00:23:37 +0000236 if (Symtab.findUnderscore("WinMain") || Symtab.findUnderscore("wWinMain"))
Rui Ueyama45044f42015-06-29 01:03:53 +0000237 return IMAGE_SUBSYSTEM_WINDOWS_GUI;
238 return IMAGE_SUBSYSTEM_UNKNOWN;
Rui Ueyama97dff9e2015-06-17 00:16:33 +0000239}
240
Rui Ueyama5c437cd2015-07-25 21:42:33 +0000241static uint64_t getDefaultImageBase() {
242 if (Config->is64())
243 return Config->DLL ? 0x180000000 : 0x140000000;
244 return Config->DLL ? 0x10000000 : 0x400000;
245}
246
Rafael Espindolab835ae82015-08-06 14:58:50 +0000247void LinkerDriver::link(llvm::ArrayRef<const char *> ArgsArr) {
Rui Ueyama27e470a2015-08-09 20:45:17 +0000248 // If the first command line argument is "/lib", link.exe acts like lib.exe.
249 // We call our own implementation of lib.exe that understands bitcode files.
250 if (ArgsArr.size() > 1 && StringRef(ArgsArr[1]).equals_lower("/lib")) {
251 if (llvm::libDriverMain(ArgsArr.slice(1)) != 0)
252 error("lib failed");
253 return;
254 }
255
Peter Collingbourne60c16162015-06-01 20:10:10 +0000256 // Needed for LTO.
257 llvm::InitializeAllTargetInfos();
258 llvm::InitializeAllTargets();
259 llvm::InitializeAllTargetMCs();
260 llvm::InitializeAllAsmParsers();
261 llvm::InitializeAllAsmPrinters();
262 llvm::InitializeAllDisassemblers();
263
Rui Ueyama411c63602015-05-28 19:09:30 +0000264 // Parse command line options.
Rafael Espindolab835ae82015-08-06 14:58:50 +0000265 llvm::opt::InputArgList Args = Parser.parseLINK(ArgsArr.slice(1));
Rui Ueyama411c63602015-05-28 19:09:30 +0000266
Rui Ueyama5c726432015-05-29 16:11:52 +0000267 // Handle /help
David Blaikie6521ed92015-06-22 22:06:52 +0000268 if (Args.hasArg(OPT_help)) {
David Blaikieb2b1c7c2015-06-21 06:32:10 +0000269 printHelp(ArgsArr[0]);
Rafael Espindolab835ae82015-08-06 14:58:50 +0000270 return;
Rui Ueyama5c726432015-05-29 16:11:52 +0000271 }
272
Rafael Espindolab835ae82015-08-06 14:58:50 +0000273 if (Args.filtered_begin(OPT_INPUT) == Args.filtered_end())
274 error("no input files.");
Rui Ueyama3d3e6fb2015-05-29 16:06:00 +0000275
Rui Ueyamaf00df0a2015-06-19 22:39:48 +0000276 // Construct search path list.
277 SearchPaths.push_back("");
David Blaikie6521ed92015-06-22 22:06:52 +0000278 for (auto *Arg : Args.filtered(OPT_libpath))
Rui Ueyamaf00df0a2015-06-19 22:39:48 +0000279 SearchPaths.push_back(Arg->getValue());
280 addLibSearchPaths();
281
Rui Ueyamaad660982015-06-07 00:20:32 +0000282 // Handle /out
David Blaikie6521ed92015-06-22 22:06:52 +0000283 if (auto *Arg = Args.getLastArg(OPT_out))
Rui Ueyamaad660982015-06-07 00:20:32 +0000284 Config->OutputFile = Arg->getValue();
285
Rui Ueyama3d3e6fb2015-05-29 16:06:00 +0000286 // Handle /verbose
David Blaikie6521ed92015-06-22 22:06:52 +0000287 if (Args.hasArg(OPT_verbose))
Rui Ueyama411c63602015-05-28 19:09:30 +0000288 Config->Verbose = true;
Rui Ueyama3d3e6fb2015-05-29 16:06:00 +0000289
Rui Ueyama95925fd2015-06-28 19:35:15 +0000290 // Handle /force or /force:unresolved
291 if (Args.hasArg(OPT_force) || Args.hasArg(OPT_force_unresolved))
292 Config->Force = true;
293
Rui Ueyama6600eb12015-07-04 23:37:32 +0000294 // Handle /debug
295 if (Args.hasArg(OPT_debug))
296 Config->Debug = true;
297
Rui Ueyamaa8b60452015-06-28 19:56:30 +0000298 // Handle /noentry
299 if (Args.hasArg(OPT_noentry)) {
Rafael Espindolab835ae82015-08-06 14:58:50 +0000300 if (!Args.hasArg(OPT_dll))
301 error("/noentry must be specified with /dll");
Rui Ueyamaa8b60452015-06-28 19:56:30 +0000302 Config->NoEntry = true;
303 }
304
Rui Ueyama97dff9e2015-06-17 00:16:33 +0000305 // Handle /dll
David Blaikie6521ed92015-06-22 22:06:52 +0000306 if (Args.hasArg(OPT_dll)) {
Rui Ueyama97dff9e2015-06-17 00:16:33 +0000307 Config->DLL = true;
Rui Ueyama24c5fd02015-06-18 00:12:42 +0000308 Config->ManifestID = 2;
309 }
Rui Ueyama97dff9e2015-06-17 00:16:33 +0000310
Rui Ueyama588e8322015-06-15 01:23:58 +0000311 // Handle /fixed
David Blaikie6521ed92015-06-22 22:06:52 +0000312 if (Args.hasArg(OPT_fixed)) {
Rafael Espindolab835ae82015-08-06 14:58:50 +0000313 if (Args.hasArg(OPT_dynamicbase))
314 error("/fixed must not be specified with /dynamicbase");
Rui Ueyama588e8322015-06-15 01:23:58 +0000315 Config->Relocatable = false;
Rui Ueyama6592ff82015-06-16 23:13:00 +0000316 Config->DynamicBase = false;
317 }
Rui Ueyama588e8322015-06-15 01:23:58 +0000318
Rui Ueyama3d3e6fb2015-05-29 16:06:00 +0000319 // Handle /machine
Rafael Espindolab835ae82015-08-06 14:58:50 +0000320 if (auto *Arg = Args.getLastArg(OPT_machine))
321 Config->Machine = getMachineType(Arg->getValue());
Rui Ueyama3d3e6fb2015-05-29 16:06:00 +0000322
Rui Ueyamad21b00b2015-05-31 19:17:14 +0000323 // Handle /nodefaultlib:<filename>
David Blaikie6521ed92015-06-22 22:06:52 +0000324 for (auto *Arg : Args.filtered(OPT_nodefaultlib))
Rui Ueyamad21b00b2015-05-31 19:17:14 +0000325 Config->NoDefaultLibs.insert(doFindLib(Arg->getValue()));
326
327 // Handle /nodefaultlib
David Blaikie6521ed92015-06-22 22:06:52 +0000328 if (Args.hasArg(OPT_nodefaultlib_all))
Rui Ueyamad21b00b2015-05-31 19:17:14 +0000329 Config->NoDefaultLibAll = true;
330
Rui Ueyama804a8b62015-05-29 16:18:15 +0000331 // Handle /base
Rafael Espindolab835ae82015-08-06 14:58:50 +0000332 if (auto *Arg = Args.getLastArg(OPT_base))
333 parseNumbers(Arg->getValue(), &Config->ImageBase);
Rui Ueyamab41b7e52015-05-29 16:21:11 +0000334
335 // Handle /stack
Rafael Espindolab835ae82015-08-06 14:58:50 +0000336 if (auto *Arg = Args.getLastArg(OPT_stack))
337 parseNumbers(Arg->getValue(), &Config->StackReserve, &Config->StackCommit);
Rui Ueyama804a8b62015-05-29 16:18:15 +0000338
Rui Ueyamac377e9a2015-05-29 16:23:40 +0000339 // Handle /heap
Rafael Espindolab835ae82015-08-06 14:58:50 +0000340 if (auto *Arg = Args.getLastArg(OPT_heap))
341 parseNumbers(Arg->getValue(), &Config->HeapReserve, &Config->HeapCommit);
Rui Ueyamac377e9a2015-05-29 16:23:40 +0000342
Rui Ueyamab9dcdb52015-05-29 16:28:29 +0000343 // Handle /version
Rafael Espindolab835ae82015-08-06 14:58:50 +0000344 if (auto *Arg = Args.getLastArg(OPT_version))
345 parseVersion(Arg->getValue(), &Config->MajorImageVersion,
346 &Config->MinorImageVersion);
Rui Ueyamab9dcdb52015-05-29 16:28:29 +0000347
Rui Ueyama15cc47e2015-05-29 16:34:31 +0000348 // Handle /subsystem
Rafael Espindolab835ae82015-08-06 14:58:50 +0000349 if (auto *Arg = Args.getLastArg(OPT_subsystem))
350 parseSubsystem(Arg->getValue(), &Config->Subsystem, &Config->MajorOSVersion,
351 &Config->MinorOSVersion);
Rui Ueyama15cc47e2015-05-29 16:34:31 +0000352
Rui Ueyama2edb35a2015-06-18 19:09:30 +0000353 // Handle /alternatename
David Blaikie6521ed92015-06-22 22:06:52 +0000354 for (auto *Arg : Args.filtered(OPT_alternatename))
Rafael Espindolab835ae82015-08-06 14:58:50 +0000355 parseAlternateName(Arg->getValue());
Rui Ueyama2edb35a2015-06-18 19:09:30 +0000356
Rui Ueyama08d5e182015-06-18 23:20:11 +0000357 // Handle /include
David Blaikie6521ed92015-06-22 22:06:52 +0000358 for (auto *Arg : Args.filtered(OPT_incl))
Rui Ueyama32f8e1c2015-06-26 03:44:00 +0000359 addUndefined(Arg->getValue());
Rui Ueyama08d5e182015-06-18 23:20:11 +0000360
Rui Ueyamab95188c2015-06-18 20:27:09 +0000361 // Handle /implib
David Blaikie6521ed92015-06-22 22:06:52 +0000362 if (auto *Arg = Args.getLastArg(OPT_implib))
Rui Ueyamab95188c2015-06-18 20:27:09 +0000363 Config->Implib = Arg->getValue();
364
Rui Ueyamae2cbfea2015-06-07 03:17:42 +0000365 // Handle /opt
David Blaikie6521ed92015-06-22 22:06:52 +0000366 for (auto *Arg : Args.filtered(OPT_opt)) {
Rui Ueyama75656ee2015-10-19 19:40:43 +0000367 std::string Str = StringRef(Arg->getValue()).lower();
368 SmallVector<StringRef, 1> Vec;
369 StringRef(Str).split(Vec, ',');
370 for (StringRef S : Vec) {
371 if (S == "noref") {
372 Config->DoGC = false;
373 Config->DoICF = false;
374 continue;
375 }
376 if (S == "icf" || StringRef(S).startswith("icf=")) {
377 Config->DoICF = true;
378 continue;
379 }
380 if (S == "noicf") {
381 Config->DoICF = false;
382 continue;
383 }
384 if (StringRef(S).startswith("lldlto=")) {
385 StringRef OptLevel = StringRef(S).substr(7);
386 if (OptLevel.getAsInteger(10, Config->LTOOptLevel) ||
387 Config->LTOOptLevel > 3)
388 error("/opt:lldlto: invalid optimization level: " + OptLevel);
389 continue;
390 }
391 if (StringRef(S).startswith("lldltojobs=")) {
392 StringRef Jobs = StringRef(S).substr(11);
393 if (Jobs.getAsInteger(10, Config->LTOJobs) || Config->LTOJobs == 0)
394 error("/opt:lldltojobs: invalid job count: " + Jobs);
395 continue;
396 }
397 if (S != "ref" && S != "lbr" && S != "nolbr")
398 error(Twine("/opt: unknown option: ") + S);
Rui Ueyamae2cbfea2015-06-07 03:17:42 +0000399 }
Rui Ueyamae2cbfea2015-06-07 03:17:42 +0000400 }
401
Rui Ueyama8854d8a2015-06-04 19:21:24 +0000402 // Handle /failifmismatch
David Blaikie6521ed92015-06-22 22:06:52 +0000403 for (auto *Arg : Args.filtered(OPT_failifmismatch))
Rafael Espindolab835ae82015-08-06 14:58:50 +0000404 checkFailIfMismatch(Arg->getValue());
Rui Ueyama8854d8a2015-06-04 19:21:24 +0000405
Rui Ueyama6600eb12015-07-04 23:37:32 +0000406 // Handle /merge
407 for (auto *Arg : Args.filtered(OPT_merge))
Rafael Espindolab835ae82015-08-06 14:58:50 +0000408 parseMerge(Arg->getValue());
Rui Ueyama6600eb12015-07-04 23:37:32 +0000409
Rui Ueyama24c5fd02015-06-18 00:12:42 +0000410 // Handle /manifest
Rafael Espindolab835ae82015-08-06 14:58:50 +0000411 if (auto *Arg = Args.getLastArg(OPT_manifest_colon))
412 parseManifest(Arg->getValue());
Rui Ueyama24c5fd02015-06-18 00:12:42 +0000413
414 // Handle /manifestuac
Rafael Espindolab835ae82015-08-06 14:58:50 +0000415 if (auto *Arg = Args.getLastArg(OPT_manifestuac))
416 parseManifestUAC(Arg->getValue());
Rui Ueyama24c5fd02015-06-18 00:12:42 +0000417
418 // Handle /manifestdependency
David Blaikie6521ed92015-06-22 22:06:52 +0000419 if (auto *Arg = Args.getLastArg(OPT_manifestdependency))
Rui Ueyama24c5fd02015-06-18 00:12:42 +0000420 Config->ManifestDependency = Arg->getValue();
421
422 // Handle /manifestfile
David Blaikie6521ed92015-06-22 22:06:52 +0000423 if (auto *Arg = Args.getLastArg(OPT_manifestfile))
Rui Ueyama24c5fd02015-06-18 00:12:42 +0000424 Config->ManifestFile = Arg->getValue();
425
Rui Ueyama6592ff82015-06-16 23:13:00 +0000426 // Handle miscellaneous boolean flags.
David Blaikie6521ed92015-06-22 22:06:52 +0000427 if (Args.hasArg(OPT_allowbind_no))
428 Config->AllowBind = false;
429 if (Args.hasArg(OPT_allowisolation_no))
430 Config->AllowIsolation = false;
431 if (Args.hasArg(OPT_dynamicbase_no))
432 Config->DynamicBase = false;
David Blaikie6521ed92015-06-22 22:06:52 +0000433 if (Args.hasArg(OPT_nxcompat_no))
434 Config->NxCompat = false;
435 if (Args.hasArg(OPT_tsaware_no))
436 Config->TerminalServerAware = false;
Rui Ueyama96401732015-09-21 23:43:31 +0000437 if (Args.hasArg(OPT_nosymtab))
438 Config->WriteSymtab = false;
Rui Ueyama6592ff82015-06-16 23:13:00 +0000439
Rui Ueyamad21b00b2015-05-31 19:17:14 +0000440 // Create a list of input files. Files can be given as arguments
441 // for /defaultlib option.
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000442 std::vector<StringRef> Paths;
443 std::vector<MemoryBufferRef> MBs;
David Blaikie6521ed92015-06-22 22:06:52 +0000444 for (auto *Arg : Args.filtered(OPT_INPUT))
Rui Ueyamad21b00b2015-05-31 19:17:14 +0000445 if (Optional<StringRef> Path = findFile(Arg->getValue()))
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000446 Paths.push_back(*Path);
David Blaikie6521ed92015-06-22 22:06:52 +0000447 for (auto *Arg : Args.filtered(OPT_defaultlib))
Rui Ueyamad21b00b2015-05-31 19:17:14 +0000448 if (Optional<StringRef> Path = findLib(Arg->getValue()))
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000449 Paths.push_back(*Path);
Rafael Espindolab835ae82015-08-06 14:58:50 +0000450 for (StringRef Path : Paths)
451 MBs.push_back(openFile(Path));
Rui Ueyamad21b00b2015-05-31 19:17:14 +0000452
Rui Ueyama24c5fd02015-06-18 00:12:42 +0000453 // Windows specific -- Create a resource file containing a manifest file.
454 if (Config->Manifest == Configuration::Embed) {
Rafael Espindolab835ae82015-08-06 14:58:50 +0000455 std::unique_ptr<MemoryBuffer> MB = createManifestRes();
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000456 MBs.push_back(MB->getMemBufferRef());
Rui Ueyama24c5fd02015-06-18 00:12:42 +0000457 OwningMBs.push_back(std::move(MB)); // take ownership
458 }
459
Rui Ueyama2bf6a122015-06-14 21:50:50 +0000460 // Windows specific -- Input files can be Windows resource files (.res files).
461 // We invoke cvtres.exe to convert resource files to a regular COFF file
462 // then link the result file normally.
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000463 std::vector<MemoryBufferRef> Resources;
Rui Ueyama77731b42015-06-26 23:59:13 +0000464 auto NotResource = [](MemoryBufferRef MB) {
465 return identify_magic(MB.getBuffer()) != file_magic::windows_resource;
Rui Ueyama2bf6a122015-06-14 21:50:50 +0000466 };
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000467 auto It = std::stable_partition(MBs.begin(), MBs.end(), NotResource);
468 if (It != MBs.end()) {
469 Resources.insert(Resources.end(), It, MBs.end());
470 MBs.erase(It, MBs.end());
Rui Ueyama2bf6a122015-06-14 21:50:50 +0000471 }
472
Rui Ueyama85225b02015-07-02 03:15:15 +0000473 // Read all input files given via the command line. Note that step()
474 // doesn't read files that are specified by directive sections.
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000475 for (MemoryBufferRef MB : MBs)
Rui Ueyama0d2e9992015-06-23 23:56:39 +0000476 Symtab.addFile(createFile(MB));
Rafael Espindolab835ae82015-08-06 14:58:50 +0000477 Symtab.step();
Rui Ueyama5cff6852015-05-31 03:34:08 +0000478
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000479 // Determine machine type and check if all object files are
480 // for the same CPU type. Note that this needs to be done before
481 // any call to mangle().
482 for (std::unique_ptr<InputFile> &File : Symtab.getFiles()) {
483 MachineTypes MT = File->getMachineType();
484 if (MT == IMAGE_FILE_MACHINE_UNKNOWN)
485 continue;
Rui Ueyama5e706b32015-07-25 21:54:50 +0000486 if (Config->Machine == IMAGE_FILE_MACHINE_UNKNOWN) {
487 Config->Machine = MT;
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000488 continue;
489 }
Rafael Espindolab835ae82015-08-06 14:58:50 +0000490 if (Config->Machine != MT)
491 error(Twine(File->getShortName()) + ": machine type " + machineToStr(MT) +
492 " conflicts with " + machineToStr(Config->Machine));
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000493 }
Rui Ueyama5e706b32015-07-25 21:54:50 +0000494 if (Config->Machine == IMAGE_FILE_MACHINE_UNKNOWN) {
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000495 llvm::errs() << "warning: /machine is not specified. x64 is assumed.\n";
Rui Ueyama5e706b32015-07-25 21:54:50 +0000496 Config->Machine = AMD64;
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000497 }
498
499 // Windows specific -- Convert Windows resource files to a COFF file.
500 if (!Resources.empty()) {
Rafael Espindolab835ae82015-08-06 14:58:50 +0000501 std::unique_ptr<MemoryBuffer> MB = convertResToCOFF(Resources);
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000502 Symtab.addFile(createFile(MB->getMemBufferRef()));
503 OwningMBs.push_back(std::move(MB)); // take ownership
504 }
505
Rui Ueyama4d545342015-07-28 03:12:00 +0000506 // Handle /largeaddressaware
507 if (Config->is64() || Args.hasArg(OPT_largeaddressaware))
508 Config->LargeAddressAware = true;
509
Rui Ueyamad68e2112015-07-28 03:15:57 +0000510 // Handle /highentropyva
511 if (Config->is64() && !Args.hasArg(OPT_highentropyva_no))
512 Config->HighEntropyVA = true;
513
Rui Ueyamabbdec4f2015-07-09 22:51:41 +0000514 // Handle /entry and /dll
515 if (auto *Arg = Args.getLastArg(OPT_entry)) {
516 Config->Entry = addUndefined(mangle(Arg->getValue()));
517 } else if (Args.hasArg(OPT_dll) && !Config->NoEntry) {
Rui Ueyama5e706b32015-07-25 21:54:50 +0000518 StringRef S = (Config->Machine == I386) ? "__DllMainCRTStartup@12"
519 : "_DllMainCRTStartup";
Rui Ueyamabbdec4f2015-07-09 22:51:41 +0000520 Config->Entry = addUndefined(S);
521 } else if (!Config->NoEntry) {
522 // Windows specific -- If entry point name is not given, we need to
523 // infer that from user-defined entry name.
Rui Ueyama45044f42015-06-29 01:03:53 +0000524 StringRef S = findDefaultEntry();
Rafael Espindolab835ae82015-08-06 14:58:50 +0000525 if (S.empty())
526 error("entry point must be defined");
Rui Ueyama6bf638e2015-07-02 00:04:14 +0000527 Config->Entry = addUndefined(S);
Rui Ueyama85225b02015-07-02 03:15:15 +0000528 if (Config->Verbose)
529 llvm::outs() << "Entry name inferred: " << S << "\n";
Rui Ueyama45044f42015-06-29 01:03:53 +0000530 }
531
Rui Ueyamabbdec4f2015-07-09 22:51:41 +0000532 // Handle /export
533 for (auto *Arg : Args.filtered(OPT_export)) {
Rafael Espindolab835ae82015-08-06 14:58:50 +0000534 Export E = parseExport(Arg->getValue());
Rui Ueyamaf10a3202015-08-31 08:43:21 +0000535 if (Config->Machine == I386) {
536 if (!isDecorated(E.Name))
537 E.Name = Alloc.save("_" + E.Name);
538 if (!E.ExtName.empty() && !isDecorated(E.ExtName))
539 E.ExtName = Alloc.save("_" + E.ExtName);
540 }
Rafael Espindolab835ae82015-08-06 14:58:50 +0000541 Config->Exports.push_back(E);
Rui Ueyamabbdec4f2015-07-09 22:51:41 +0000542 }
543
544 // Handle /def
545 if (auto *Arg = Args.getLastArg(OPT_deffile)) {
Rafael Espindolab835ae82015-08-06 14:58:50 +0000546 MemoryBufferRef MB = openFile(Arg->getValue());
Rui Ueyamabbdec4f2015-07-09 22:51:41 +0000547 // parseModuleDefs mutates Config object.
Rafael Espindolab835ae82015-08-06 14:58:50 +0000548 parseModuleDefs(MB, &Alloc);
Rui Ueyamabbdec4f2015-07-09 22:51:41 +0000549 }
550
Rui Ueyama6d249082015-07-13 22:31:45 +0000551 // Handle /delayload
552 for (auto *Arg : Args.filtered(OPT_delayload)) {
553 Config->DelayLoads.insert(StringRef(Arg->getValue()).lower());
Rui Ueyama5e706b32015-07-25 21:54:50 +0000554 if (Config->Machine == I386) {
Rui Ueyama6d249082015-07-13 22:31:45 +0000555 Config->DelayLoadHelper = addUndefined("___delayLoadHelper2@8");
Rui Ueyama35ccb0f2015-07-25 00:20:06 +0000556 } else {
557 Config->DelayLoadHelper = addUndefined("__delayLoadHelper2");
Rui Ueyama6d249082015-07-13 22:31:45 +0000558 }
559 }
560
Rui Ueyama5c437cd2015-07-25 21:42:33 +0000561 // Set default image base if /base is not given.
562 if (Config->ImageBase == uint64_t(-1))
563 Config->ImageBase = getDefaultImageBase();
564
Rui Ueyama3cb895c2015-07-24 22:58:44 +0000565 Symtab.addRelative(mangle("__ImageBase"), 0);
Rui Ueyama5e706b32015-07-25 21:54:50 +0000566 if (Config->Machine == I386) {
Rui Ueyamacd3f99b2015-07-24 23:51:14 +0000567 Config->SEHTable = Symtab.addRelative("___safe_se_handler_table", 0);
568 Config->SEHCount = Symtab.addAbsolute("___safe_se_handler_count", 0);
569 }
Rui Ueyamabbdec4f2015-07-09 22:51:41 +0000570
Rui Ueyama107db552015-08-09 21:01:06 +0000571 // We do not support /guard:cf (control flow protection) yet.
572 // Define CFG symbols anyway so that we can link MSVC 2015 CRT.
573 Symtab.addAbsolute(mangle("__guard_fids_table"), 0);
574 Symtab.addAbsolute(mangle("__guard_fids_count"), 0);
575 Symtab.addAbsolute(mangle("__guard_flags"), 0x100);
576
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000577 // Read as much files as we can from directives sections.
Rafael Espindolab835ae82015-08-06 14:58:50 +0000578 Symtab.run();
Rui Ueyama85225b02015-07-02 03:15:15 +0000579
580 // Resolve auxiliary symbols until we get a convergence.
Rui Ueyama573bf7d2015-06-19 21:12:48 +0000581 // (Trying to resolve a symbol may trigger a Lazy symbol to load a new file.
582 // A new file may contain a directive section to add new command line options.
583 // That's why we have to repeat until converge.)
584 for (;;) {
Rui Ueyama6bf638e2015-07-02 00:04:14 +0000585 // Windows specific -- if entry point is not found,
586 // search for its mangled names.
587 if (Config->Entry)
588 Symtab.mangleMaybe(Config->Entry);
589
Rui Ueyama573bf7d2015-06-19 21:12:48 +0000590 // Windows specific -- Make sure we resolve all dllexported symbols.
Rui Ueyama6bf638e2015-07-02 00:04:14 +0000591 for (Export &E : Config->Exports) {
Rui Ueyama84425d72016-01-09 01:22:00 +0000592 if (!E.ForwardTo.empty())
593 continue;
Rui Ueyama6bf638e2015-07-02 00:04:14 +0000594 E.Sym = addUndefined(E.Name);
Rui Ueyamaf10a3202015-08-31 08:43:21 +0000595 if (!E.Directives)
596 Symtab.mangleMaybe(E.Sym);
Rui Ueyama6bf638e2015-07-02 00:04:14 +0000597 }
Rui Ueyama573bf7d2015-06-19 21:12:48 +0000598
599 // Add weak aliases. Weak aliases is a mechanism to give remaining
600 // undefined symbols final chance to be resolved successfully.
Rui Ueyama3d4c69c2015-07-02 02:38:59 +0000601 for (auto Pair : Config->AlternateNames) {
602 StringRef From = Pair.first;
603 StringRef To = Pair.second;
Rui Ueyama458d7442015-07-02 03:59:04 +0000604 Symbol *Sym = Symtab.find(From);
Rui Ueyama3d4c69c2015-07-02 02:38:59 +0000605 if (!Sym)
606 continue;
Rui Ueyama183f53f2015-07-06 17:45:22 +0000607 if (auto *U = dyn_cast<Undefined>(Sym->Body))
Rui Ueyama3d4c69c2015-07-02 02:38:59 +0000608 if (!U->WeakAlias)
609 U->WeakAlias = Symtab.addUndefined(To);
Rui Ueyama2edb35a2015-06-18 19:09:30 +0000610 }
Rui Ueyama573bf7d2015-06-19 21:12:48 +0000611
Rui Ueyamacd3f99b2015-07-24 23:51:14 +0000612 // Windows specific -- if __load_config_used can be resolved, resolve it.
Rui Ueyama8ebdc8c2015-08-07 22:43:53 +0000613 if (Symtab.findUnderscore("_load_config_used"))
614 addUndefined(mangle("_load_config_used"));
Rui Ueyamacd3f99b2015-07-24 23:51:14 +0000615
Rui Ueyama3d4c69c2015-07-02 02:38:59 +0000616 if (Symtab.queueEmpty())
617 break;
Rafael Espindolab835ae82015-08-06 14:58:50 +0000618 Symtab.run();
Rui Ueyama2edb35a2015-06-18 19:09:30 +0000619 }
620
Peter Collingbournedf5783b2015-08-28 22:16:09 +0000621 // Do LTO by compiling bitcode input files to a set of native COFF files then
622 // link those files.
623 Symtab.addCombinedLTOObjects();
Peter Collingbourne60c16162015-06-01 20:10:10 +0000624
Peter Collingbourne2612a322015-07-04 05:28:41 +0000625 // Make sure we have resolved all symbols.
Rafael Espindolab835ae82015-08-06 14:58:50 +0000626 Symtab.reportRemainingUndefines(/*Resolve=*/true);
Peter Collingbourne2612a322015-07-04 05:28:41 +0000627
Rui Ueyama3ee0fe42015-05-31 03:55:46 +0000628 // Windows specific -- if no /subsystem is given, we need to infer
629 // that from entry point name.
630 if (Config->Subsystem == IMAGE_SUBSYSTEM_UNKNOWN) {
Rui Ueyama97dff9e2015-06-17 00:16:33 +0000631 Config->Subsystem = inferSubsystem();
Rafael Espindolab835ae82015-08-06 14:58:50 +0000632 if (Config->Subsystem == IMAGE_SUBSYSTEM_UNKNOWN)
633 error("subsystem must be defined");
Rui Ueyama3ee0fe42015-05-31 03:55:46 +0000634 }
635
Rui Ueyamaff88d5a2015-07-29 20:25:40 +0000636 // Handle /safeseh.
Rui Ueyama13563d82015-09-15 00:33:11 +0000637 if (Args.hasArg(OPT_safeseh))
638 for (ObjectFile *File : Symtab.ObjectFiles)
639 if (!File->SEHCompat)
640 error("/safeseh: " + File->getName() + " is not compatible with SEH");
Rui Ueyamaff88d5a2015-07-29 20:25:40 +0000641
Rui Ueyama151d8622015-06-17 20:40:43 +0000642 // Windows specific -- when we are creating a .dll file, we also
643 // need to create a .lib file.
Rui Ueyama100ffac2015-09-01 09:15:58 +0000644 if (!Config->Exports.empty() || Config->DLL) {
Rafael Espindolab835ae82015-08-06 14:58:50 +0000645 fixupExports();
646 writeImportLibrary();
Rui Ueyama8765fba2015-07-15 22:21:08 +0000647 assignExportOrdinals();
648 }
Rui Ueyama97dff9e2015-06-17 00:16:33 +0000649
Rui Ueyama24c5fd02015-06-18 00:12:42 +0000650 // Windows specific -- Create a side-by-side manifest file.
651 if (Config->Manifest == Configuration::SideBySide)
Rafael Espindolab835ae82015-08-06 14:58:50 +0000652 createSideBySideManifest();
Rui Ueyama24c5fd02015-06-18 00:12:42 +0000653
Rui Ueyama0fc26d22015-06-29 14:27:12 +0000654 // Create a dummy PDB file to satisfy build sytem rules.
655 if (auto *Arg = Args.getLastArg(OPT_pdb))
Rui Ueyamae7378242015-12-04 23:11:05 +0000656 createPDB(Arg->getValue());
Rui Ueyama0fc26d22015-06-29 14:27:12 +0000657
Rui Ueyamaa5f0f752015-09-19 21:36:28 +0000658 // Identify unreferenced COMDAT sections.
659 if (Config->DoGC)
660 markLive(Symtab.getChunks());
661
662 // Identify identical COMDAT sections to merge them.
663 if (Config->DoICF)
664 doICF(Symtab.getChunks());
665
Rui Ueyama411c63602015-05-28 19:09:30 +0000666 // Write the result.
Rafael Espindolab835ae82015-08-06 14:58:50 +0000667 writeResult(&Symtab);
Peter Collingbournebe549552015-06-26 18:58:24 +0000668
Rui Ueyama016414f2015-06-28 20:07:08 +0000669 // Create a symbol map file containing symbol VAs and their names
670 // to help debugging.
Peter Collingbournebe549552015-06-26 18:58:24 +0000671 if (auto *Arg = Args.getLastArg(OPT_lldmap)) {
672 std::error_code EC;
Peter Collingbournebaf5f872015-06-26 19:20:09 +0000673 llvm::raw_fd_ostream Out(Arg->getValue(), EC, OpenFlags::F_Text);
Rafael Espindolab835ae82015-08-06 14:58:50 +0000674 error(EC, "Could not create the symbol map");
Peter Collingbournebe549552015-06-26 18:58:24 +0000675 Symtab.printMap(Out);
676 }
Rui Ueyamaa51ce712015-07-03 05:31:35 +0000677 // Call exit to avoid calling destructors.
678 exit(0);
Rui Ueyama411c63602015-05-28 19:09:30 +0000679}
680
Rui Ueyama411c63602015-05-28 19:09:30 +0000681} // namespace coff
682} // namespace lld