blob: 225453291a93a28304f4bfe59cf64ac1b4ca18ef [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"
15#include "Writer.h"
Rui Ueyama411c63602015-05-28 19:09:30 +000016#include "llvm/ADT/Optional.h"
17#include "llvm/ADT/STLExtras.h"
Rui Ueyama3ee0fe42015-05-31 03:55:46 +000018#include "llvm/ADT/StringSwitch.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"
23#include "llvm/Support/CommandLine.h"
24#include "llvm/Support/Debug.h"
Rui Ueyama411c63602015-05-28 19:09:30 +000025#include "llvm/Support/Path.h"
Rui Ueyama54b71da2015-05-31 19:17:12 +000026#include "llvm/Support/Process.h"
Peter Collingbourne60c16162015-06-01 20:10:10 +000027#include "llvm/Support/TargetSelect.h"
Rui Ueyama411c63602015-05-28 19:09:30 +000028#include "llvm/Support/raw_ostream.h"
Rui Ueyama2bf6a122015-06-14 21:50:50 +000029#include <algorithm>
Rui Ueyama411c63602015-05-28 19:09:30 +000030#include <memory>
31
32using namespace llvm;
Rui Ueyama84936e02015-07-07 23:39:18 +000033using namespace llvm::COFF;
Rui Ueyama54b71da2015-05-31 19:17:12 +000034using llvm::sys::Process;
Peter Collingbournebaf5f872015-06-26 19:20:09 +000035using llvm::sys::fs::OpenFlags;
Rui Ueyama711cd2d2015-05-31 21:17:10 +000036using llvm::sys::fs::file_magic;
37using llvm::sys::fs::identify_magic;
Rui Ueyama411c63602015-05-28 19:09:30 +000038
Rui Ueyama3500f662015-05-28 20:30:06 +000039namespace lld {
40namespace coff {
Rui Ueyama411c63602015-05-28 19:09:30 +000041
Rui Ueyama3500f662015-05-28 20:30:06 +000042Configuration *Config;
Rui Ueyamaa9cbbf82015-05-31 19:17:09 +000043LinkerDriver *Driver;
44
David Blaikie00818192015-06-22 22:06:48 +000045bool link(llvm::ArrayRef<const char *> Args) {
Rui Ueyamaa9cbbf82015-05-31 19:17:09 +000046 auto C = make_unique<Configuration>();
47 Config = C.get();
48 auto D = make_unique<LinkerDriver>();
49 Driver = D.get();
David Blaikieb2b1c7c2015-06-21 06:32:10 +000050 return Driver->link(Args);
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.
Rui Ueyama2bf6a122015-06-14 21:50:50 +000062ErrorOr<MemoryBufferRef> LinkerDriver::openFile(StringRef Path) {
Rui Ueyamad7c2f582015-05-31 21:04:56 +000063 auto MBOrErr = MemoryBuffer::getFile(Path);
64 if (auto EC = MBOrErr.getError())
65 return EC;
66 std::unique_ptr<MemoryBuffer> MB = std::move(MBOrErr.get());
67 MemoryBufferRef MBRef = MB->getMemBufferRef();
68 OwningMBs.push_back(std::move(MB)); // take ownership
Rui Ueyama2bf6a122015-06-14 21:50:50 +000069 return MBRef;
70}
Rui Ueyama711cd2d2015-05-31 21:17:10 +000071
Rui Ueyama2bf6a122015-06-14 21:50:50 +000072static std::unique_ptr<InputFile> createFile(MemoryBufferRef MB) {
Rui Ueyama711cd2d2015-05-31 21:17:10 +000073 // File type is detected by contents, not by file extension.
Rui Ueyama2bf6a122015-06-14 21:50:50 +000074 file_magic Magic = identify_magic(MB.getBuffer());
Rui Ueyama711cd2d2015-05-31 21:17:10 +000075 if (Magic == file_magic::archive)
Rui Ueyama2bf6a122015-06-14 21:50:50 +000076 return std::unique_ptr<InputFile>(new ArchiveFile(MB));
Peter Collingbourne60c16162015-06-01 20:10:10 +000077 if (Magic == file_magic::bitcode)
Rui Ueyama2bf6a122015-06-14 21:50:50 +000078 return std::unique_ptr<InputFile>(new BitcodeFile(MB));
Rui Ueyamaad660982015-06-07 00:20:32 +000079 if (Config->OutputFile == "")
Rui Ueyama2bf6a122015-06-14 21:50:50 +000080 Config->OutputFile = getOutputPath(MB.getBufferIdentifier());
81 return std::unique_ptr<InputFile>(new ObjectFile(MB));
Rui Ueyama411c63602015-05-28 19:09:30 +000082}
83
Rui Ueyama411c63602015-05-28 19:09:30 +000084// Parses .drectve section contents and returns a list of files
85// specified by /defaultlib.
Rui Ueyamaa9cbbf82015-05-31 19:17:09 +000086std::error_code
Rui Ueyama0d2e9992015-06-23 23:56:39 +000087LinkerDriver::parseDirectives(StringRef S) {
Rui Ueyama115d7c12015-06-07 02:55:19 +000088 auto ArgsOrErr = Parser.parse(S);
Rui Ueyama411c63602015-05-28 19:09:30 +000089 if (auto EC = ArgsOrErr.getError())
90 return EC;
David Blaikie6521ed92015-06-22 22:06:52 +000091 llvm::opt::InputArgList Args = std::move(ArgsOrErr.get());
Rui Ueyama411c63602015-05-28 19:09:30 +000092
David Blaikie6521ed92015-06-22 22:06:52 +000093 for (auto *Arg : Args) {
Rui Ueyama562daa82015-06-18 21:50:38 +000094 switch (Arg->getOption().getID()) {
95 case OPT_alternatename:
96 if (auto EC = parseAlternateName(Arg->getValue()))
Rui Ueyamad7c2f582015-05-31 21:04:56 +000097 return EC;
Rui Ueyama562daa82015-06-18 21:50:38 +000098 break;
99 case OPT_defaultlib:
100 if (Optional<StringRef> Path = findLib(Arg->getValue())) {
101 ErrorOr<MemoryBufferRef> MBOrErr = openFile(*Path);
102 if (auto EC = MBOrErr.getError())
103 return EC;
Rui Ueyama0d2e9992015-06-23 23:56:39 +0000104 Symtab.addFile(createFile(MBOrErr.get()));
Rui Ueyama562daa82015-06-18 21:50:38 +0000105 }
106 break;
107 case OPT_export: {
108 ErrorOr<Export> E = parseExport(Arg->getValue());
109 if (auto EC = E.getError())
110 return EC;
Rui Ueyama5e706b32015-07-25 21:54:50 +0000111 if (Config->Machine == I386 && E->ExtName.startswith("_"))
Rui Ueyamabbdec4f2015-07-09 22:51:41 +0000112 E->ExtName = E->ExtName.substr(1);
Rui Ueyama562daa82015-06-18 21:50:38 +0000113 Config->Exports.push_back(E.get());
114 break;
115 }
116 case OPT_failifmismatch:
117 if (auto EC = checkFailIfMismatch(Arg->getValue()))
118 return EC;
119 break;
Rui Ueyama08d5e182015-06-18 23:20:11 +0000120 case OPT_incl:
Rui Ueyama32f8e1c2015-06-26 03:44:00 +0000121 addUndefined(Arg->getValue());
Rui Ueyama08d5e182015-06-18 23:20:11 +0000122 break;
Rui Ueyamace86c992015-06-18 23:22:39 +0000123 case OPT_merge:
Rui Ueyama6600eb12015-07-04 23:37:32 +0000124 if (auto EC = parseMerge(Arg->getValue()))
125 return EC;
Rui Ueyamace86c992015-06-18 23:22:39 +0000126 break;
127 case OPT_nodefaultlib:
128 Config->NoDefaultLibs.insert(doFindLib(Arg->getValue()));
129 break;
Rui Ueyama432383172015-07-29 21:01:15 +0000130 case OPT_throwingnew:
Rui Ueyama46682632015-07-29 20:29:15 +0000131 break;
Rui Ueyama562daa82015-06-18 21:50:38 +0000132 default:
133 llvm::errs() << Arg->getSpelling() << " is not allowed in .drectve\n";
134 return make_error_code(LLDError::InvalidOption);
Rui Ueyamad7c2f582015-05-31 21:04:56 +0000135 }
136 }
Rui Ueyama411c63602015-05-28 19:09:30 +0000137 return std::error_code();
138}
139
Rui Ueyama54b71da2015-05-31 19:17:12 +0000140// Find file from search paths. You can omit ".obj", this function takes
141// care of that. Note that the returned path is not guaranteed to exist.
Rui Ueyamad21b00b2015-05-31 19:17:14 +0000142StringRef LinkerDriver::doFindFile(StringRef Filename) {
Rui Ueyama54b71da2015-05-31 19:17:12 +0000143 bool hasPathSep = (Filename.find_first_of("/\\") != StringRef::npos);
144 if (hasPathSep)
145 return Filename;
146 bool hasExt = (Filename.find('.') != StringRef::npos);
147 for (StringRef Dir : SearchPaths) {
148 SmallString<128> Path = Dir;
149 llvm::sys::path::append(Path, Filename);
150 if (llvm::sys::fs::exists(Path.str()))
151 return Alloc.save(Path.str());
152 if (!hasExt) {
153 Path.append(".obj");
154 if (llvm::sys::fs::exists(Path.str()))
155 return Alloc.save(Path.str());
156 }
157 }
158 return Filename;
159}
160
Rui Ueyamad21b00b2015-05-31 19:17:14 +0000161// Resolves a file path. This never returns the same path
162// (in that case, it returns None).
163Optional<StringRef> LinkerDriver::findFile(StringRef Filename) {
164 StringRef Path = doFindFile(Filename);
165 bool Seen = !VisitedFiles.insert(Path.lower()).second;
166 if (Seen)
167 return None;
168 return Path;
Rui Ueyama54b71da2015-05-31 19:17:12 +0000169}
170
Rui Ueyamad21b00b2015-05-31 19:17:14 +0000171// Find library file from search path.
172StringRef LinkerDriver::doFindLib(StringRef Filename) {
173 // Add ".lib" to Filename if that has no file extension.
Rui Ueyama54b71da2015-05-31 19:17:12 +0000174 bool hasExt = (Filename.find('.') != StringRef::npos);
Rui Ueyamad21b00b2015-05-31 19:17:14 +0000175 if (!hasExt)
176 Filename = Alloc.save(Filename + ".lib");
177 return doFindFile(Filename);
178}
179
180// Resolves a library path. /nodefaultlib options are taken into
181// consideration. This never returns the same path (in that case,
182// it returns None).
183Optional<StringRef> LinkerDriver::findLib(StringRef Filename) {
184 if (Config->NoDefaultLibAll)
185 return None;
186 StringRef Path = doFindLib(Filename);
187 if (Config->NoDefaultLibs.count(Path))
188 return None;
189 bool Seen = !VisitedFiles.insert(Path.lower()).second;
190 if (Seen)
191 return None;
192 return Path;
Rui Ueyama54b71da2015-05-31 19:17:12 +0000193}
194
195// Parses LIB environment which contains a list of search paths.
Rui Ueyamaf00df0a2015-06-19 22:39:48 +0000196void LinkerDriver::addLibSearchPaths() {
Rui Ueyama54b71da2015-05-31 19:17:12 +0000197 Optional<std::string> EnvOpt = Process::GetEnv("LIB");
198 if (!EnvOpt.hasValue())
Rui Ueyamaf00df0a2015-06-19 22:39:48 +0000199 return;
Rui Ueyama54b71da2015-05-31 19:17:12 +0000200 StringRef Env = Alloc.save(*EnvOpt);
201 while (!Env.empty()) {
202 StringRef Path;
203 std::tie(Path, Env) = Env.split(';');
Rui Ueyamaf00df0a2015-06-19 22:39:48 +0000204 SearchPaths.push_back(Path);
Rui Ueyama54b71da2015-05-31 19:17:12 +0000205 }
Rui Ueyama54b71da2015-05-31 19:17:12 +0000206}
207
Rui Ueyama6bf638e2015-07-02 00:04:14 +0000208Undefined *LinkerDriver::addUndefined(StringRef Name) {
209 Undefined *U = Symtab.addUndefined(Name);
Rui Ueyama18f8d2c2015-07-02 00:21:08 +0000210 Config->GCRoot.insert(U);
Rui Ueyama6bf638e2015-07-02 00:04:14 +0000211 return U;
Rui Ueyama32f8e1c2015-06-26 03:44:00 +0000212}
213
Rui Ueyama7c3e23f2015-07-09 01:25:49 +0000214// Symbol names are mangled by appending "_" prefix on x86.
215StringRef LinkerDriver::mangle(StringRef Sym) {
Rui Ueyama5e706b32015-07-25 21:54:50 +0000216 assert(Config->Machine != IMAGE_FILE_MACHINE_UNKNOWN);
217 if (Config->Machine == I386)
Rui Ueyama7c3e23f2015-07-09 01:25:49 +0000218 return Alloc.save("_" + Sym);
219 return Sym;
220}
221
Rui Ueyama45044f42015-06-29 01:03:53 +0000222// Windows specific -- find default entry point name.
223StringRef LinkerDriver::findDefaultEntry() {
224 // User-defined main functions and their corresponding entry points.
225 static const char *Entries[][2] = {
226 {"main", "mainCRTStartup"},
227 {"wmain", "wmainCRTStartup"},
228 {"WinMain", "WinMainCRTStartup"},
229 {"wWinMain", "wWinMainCRTStartup"},
230 };
231 for (auto E : Entries) {
Rui Ueyamaa50387f2015-07-14 02:58:13 +0000232 StringRef Entry = Symtab.findMangle(mangle(E[0]));
233 if (!Entry.empty() && !isa<Undefined>(Symtab.find(Entry)->Body))
Rui Ueyama7c3e23f2015-07-09 01:25:49 +0000234 return mangle(E[1]);
Rui Ueyama45044f42015-06-29 01:03:53 +0000235 }
236 return "";
237}
238
239WindowsSubsystem LinkerDriver::inferSubsystem() {
Rui Ueyama97dff9e2015-06-17 00:16:33 +0000240 if (Config->DLL)
241 return IMAGE_SUBSYSTEM_WINDOWS_GUI;
Rui Ueyama7c3e23f2015-07-09 01:25:49 +0000242 if (Symtab.find(mangle("main")) || Symtab.find(mangle("wmain")))
Rui Ueyama45044f42015-06-29 01:03:53 +0000243 return IMAGE_SUBSYSTEM_WINDOWS_CUI;
Rui Ueyama7c3e23f2015-07-09 01:25:49 +0000244 if (Symtab.find(mangle("WinMain")) || Symtab.find(mangle("wWinMain")))
Rui Ueyama45044f42015-06-29 01:03:53 +0000245 return IMAGE_SUBSYSTEM_WINDOWS_GUI;
246 return IMAGE_SUBSYSTEM_UNKNOWN;
Rui Ueyama97dff9e2015-06-17 00:16:33 +0000247}
248
Rui Ueyama5c437cd2015-07-25 21:42:33 +0000249static uint64_t getDefaultImageBase() {
250 if (Config->is64())
251 return Config->DLL ? 0x180000000 : 0x140000000;
252 return Config->DLL ? 0x10000000 : 0x400000;
253}
254
David Blaikie00818192015-06-22 22:06:48 +0000255bool LinkerDriver::link(llvm::ArrayRef<const char *> ArgsArr) {
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
Peter Collingbournebd1cb792015-06-09 21:52:48 +0000264 // If the first command line argument is "/lib", link.exe acts like lib.exe.
265 // We call our own implementation of lib.exe that understands bitcode files.
David Blaikieb2b1c7c2015-06-21 06:32:10 +0000266 if (ArgsArr.size() > 1 && StringRef(ArgsArr[1]).equals_lower("/lib"))
267 return llvm::libDriverMain(ArgsArr.slice(1)) == 0;
Peter Collingbournebd1cb792015-06-09 21:52:48 +0000268
Rui Ueyama411c63602015-05-28 19:09:30 +0000269 // Parse command line options.
Rui Ueyama9d72f092015-06-28 03:05:38 +0000270 auto ArgsOrErr = Parser.parseLINK(ArgsArr.slice(1));
Rui Ueyama411c63602015-05-28 19:09:30 +0000271 if (auto EC = ArgsOrErr.getError()) {
272 llvm::errs() << EC.message() << "\n";
273 return false;
274 }
David Blaikie6521ed92015-06-22 22:06:52 +0000275 llvm::opt::InputArgList Args = std::move(ArgsOrErr.get());
Rui Ueyama411c63602015-05-28 19:09:30 +0000276
Rui Ueyama5c726432015-05-29 16:11:52 +0000277 // Handle /help
David Blaikie6521ed92015-06-22 22:06:52 +0000278 if (Args.hasArg(OPT_help)) {
David Blaikieb2b1c7c2015-06-21 06:32:10 +0000279 printHelp(ArgsArr[0]);
Rui Ueyama5c726432015-05-29 16:11:52 +0000280 return true;
281 }
282
David Blaikie6521ed92015-06-22 22:06:52 +0000283 if (Args.filtered_begin(OPT_INPUT) == Args.filtered_end()) {
Rui Ueyama411c63602015-05-28 19:09:30 +0000284 llvm::errs() << "no input files.\n";
285 return false;
286 }
Rui Ueyama3d3e6fb2015-05-29 16:06:00 +0000287
Rui Ueyamaf00df0a2015-06-19 22:39:48 +0000288 // Construct search path list.
289 SearchPaths.push_back("");
David Blaikie6521ed92015-06-22 22:06:52 +0000290 for (auto *Arg : Args.filtered(OPT_libpath))
Rui Ueyamaf00df0a2015-06-19 22:39:48 +0000291 SearchPaths.push_back(Arg->getValue());
292 addLibSearchPaths();
293
Rui Ueyamaad660982015-06-07 00:20:32 +0000294 // Handle /out
David Blaikie6521ed92015-06-22 22:06:52 +0000295 if (auto *Arg = Args.getLastArg(OPT_out))
Rui Ueyamaad660982015-06-07 00:20:32 +0000296 Config->OutputFile = Arg->getValue();
297
Rui Ueyama3d3e6fb2015-05-29 16:06:00 +0000298 // Handle /verbose
David Blaikie6521ed92015-06-22 22:06:52 +0000299 if (Args.hasArg(OPT_verbose))
Rui Ueyama411c63602015-05-28 19:09:30 +0000300 Config->Verbose = true;
Rui Ueyama3d3e6fb2015-05-29 16:06:00 +0000301
Rui Ueyama95925fd2015-06-28 19:35:15 +0000302 // Handle /force or /force:unresolved
303 if (Args.hasArg(OPT_force) || Args.hasArg(OPT_force_unresolved))
304 Config->Force = true;
305
Rui Ueyama6600eb12015-07-04 23:37:32 +0000306 // Handle /debug
307 if (Args.hasArg(OPT_debug))
308 Config->Debug = true;
309
Rui Ueyamaa8b60452015-06-28 19:56:30 +0000310 // Handle /noentry
311 if (Args.hasArg(OPT_noentry)) {
312 if (!Args.hasArg(OPT_dll)) {
313 llvm::errs() << "/noentry must be specified with /dll\n";
314 return false;
315 }
316 Config->NoEntry = true;
317 }
318
Rui Ueyama97dff9e2015-06-17 00:16:33 +0000319 // Handle /dll
David Blaikie6521ed92015-06-22 22:06:52 +0000320 if (Args.hasArg(OPT_dll)) {
Rui Ueyama97dff9e2015-06-17 00:16:33 +0000321 Config->DLL = true;
Rui Ueyama24c5fd02015-06-18 00:12:42 +0000322 Config->ManifestID = 2;
323 }
Rui Ueyama97dff9e2015-06-17 00:16:33 +0000324
Rui Ueyama588e8322015-06-15 01:23:58 +0000325 // Handle /fixed
David Blaikie6521ed92015-06-22 22:06:52 +0000326 if (Args.hasArg(OPT_fixed)) {
327 if (Args.hasArg(OPT_dynamicbase)) {
Rui Ueyama6592ff82015-06-16 23:13:00 +0000328 llvm::errs() << "/fixed must not be specified with /dynamicbase\n";
329 return false;
330 }
Rui Ueyama588e8322015-06-15 01:23:58 +0000331 Config->Relocatable = false;
Rui Ueyama6592ff82015-06-16 23:13:00 +0000332 Config->DynamicBase = false;
333 }
Rui Ueyama588e8322015-06-15 01:23:58 +0000334
Rui Ueyama3d3e6fb2015-05-29 16:06:00 +0000335 // Handle /machine
Rui Ueyamae16a75d52015-07-08 18:14:51 +0000336 if (auto *Arg = Args.getLastArg(OPT_machine)) {
337 ErrorOr<MachineTypes> MTOrErr = getMachineType(Arg->getValue());
338 if (MTOrErr.getError())
339 return false;
Rui Ueyama5e706b32015-07-25 21:54:50 +0000340 Config->Machine = MTOrErr.get();
Rui Ueyama3d3e6fb2015-05-29 16:06:00 +0000341 }
Rui Ueyama3d3e6fb2015-05-29 16:06:00 +0000342
Rui Ueyamad21b00b2015-05-31 19:17:14 +0000343 // Handle /nodefaultlib:<filename>
David Blaikie6521ed92015-06-22 22:06:52 +0000344 for (auto *Arg : Args.filtered(OPT_nodefaultlib))
Rui Ueyamad21b00b2015-05-31 19:17:14 +0000345 Config->NoDefaultLibs.insert(doFindLib(Arg->getValue()));
346
347 // Handle /nodefaultlib
David Blaikie6521ed92015-06-22 22:06:52 +0000348 if (Args.hasArg(OPT_nodefaultlib_all))
Rui Ueyamad21b00b2015-05-31 19:17:14 +0000349 Config->NoDefaultLibAll = true;
350
Rui Ueyama804a8b62015-05-29 16:18:15 +0000351 // Handle /base
David Blaikie6521ed92015-06-22 22:06:52 +0000352 if (auto *Arg = Args.getLastArg(OPT_base)) {
Rui Ueyama804a8b62015-05-29 16:18:15 +0000353 if (auto EC = parseNumbers(Arg->getValue(), &Config->ImageBase)) {
Rui Ueyamab41b7e52015-05-29 16:21:11 +0000354 llvm::errs() << "/base: " << EC.message() << "\n";
355 return false;
356 }
357 }
358
359 // Handle /stack
David Blaikie6521ed92015-06-22 22:06:52 +0000360 if (auto *Arg = Args.getLastArg(OPT_stack)) {
Rui Ueyamab41b7e52015-05-29 16:21:11 +0000361 if (auto EC = parseNumbers(Arg->getValue(), &Config->StackReserve,
362 &Config->StackCommit)) {
363 llvm::errs() << "/stack: " << EC.message() << "\n";
Rui Ueyama804a8b62015-05-29 16:18:15 +0000364 return false;
365 }
366 }
367
Rui Ueyamac377e9a2015-05-29 16:23:40 +0000368 // Handle /heap
David Blaikie6521ed92015-06-22 22:06:52 +0000369 if (auto *Arg = Args.getLastArg(OPT_heap)) {
Rui Ueyamac377e9a2015-05-29 16:23:40 +0000370 if (auto EC = parseNumbers(Arg->getValue(), &Config->HeapReserve,
371 &Config->HeapCommit)) {
372 llvm::errs() << "/heap: " << EC.message() << "\n";
373 return false;
374 }
375 }
376
Rui Ueyamab9dcdb52015-05-29 16:28:29 +0000377 // Handle /version
David Blaikie6521ed92015-06-22 22:06:52 +0000378 if (auto *Arg = Args.getLastArg(OPT_version)) {
Rui Ueyamab9dcdb52015-05-29 16:28:29 +0000379 if (auto EC = parseVersion(Arg->getValue(), &Config->MajorImageVersion,
380 &Config->MinorImageVersion)) {
381 llvm::errs() << "/version: " << EC.message() << "\n";
382 return false;
383 }
384 }
385
Rui Ueyama15cc47e2015-05-29 16:34:31 +0000386 // Handle /subsystem
David Blaikie6521ed92015-06-22 22:06:52 +0000387 if (auto *Arg = Args.getLastArg(OPT_subsystem)) {
Rui Ueyama15cc47e2015-05-29 16:34:31 +0000388 if (auto EC = parseSubsystem(Arg->getValue(), &Config->Subsystem,
389 &Config->MajorOSVersion,
390 &Config->MinorOSVersion)) {
391 llvm::errs() << "/subsystem: " << EC.message() << "\n";
392 return false;
393 }
394 }
395
Rui Ueyama2edb35a2015-06-18 19:09:30 +0000396 // Handle /alternatename
David Blaikie6521ed92015-06-22 22:06:52 +0000397 for (auto *Arg : Args.filtered(OPT_alternatename))
Rui Ueyama2edb35a2015-06-18 19:09:30 +0000398 if (parseAlternateName(Arg->getValue()))
399 return false;
400
Rui Ueyama08d5e182015-06-18 23:20:11 +0000401 // Handle /include
David Blaikie6521ed92015-06-22 22:06:52 +0000402 for (auto *Arg : Args.filtered(OPT_incl))
Rui Ueyama32f8e1c2015-06-26 03:44:00 +0000403 addUndefined(Arg->getValue());
Rui Ueyama08d5e182015-06-18 23:20:11 +0000404
Rui Ueyamab95188c2015-06-18 20:27:09 +0000405 // Handle /implib
David Blaikie6521ed92015-06-22 22:06:52 +0000406 if (auto *Arg = Args.getLastArg(OPT_implib))
Rui Ueyamab95188c2015-06-18 20:27:09 +0000407 Config->Implib = Arg->getValue();
408
Rui Ueyamae2cbfea2015-06-07 03:17:42 +0000409 // Handle /opt
David Blaikie6521ed92015-06-22 22:06:52 +0000410 for (auto *Arg : Args.filtered(OPT_opt)) {
Rui Ueyamae2cbfea2015-06-07 03:17:42 +0000411 std::string S = StringRef(Arg->getValue()).lower();
412 if (S == "noref") {
413 Config->DoGC = false;
414 continue;
415 }
Rui Ueyamaf799ede2015-06-25 23:26:58 +0000416 if (S == "lldicf") {
Rui Ueyamaddf71fc2015-06-24 04:36:52 +0000417 Config->ICF = true;
418 continue;
419 }
Rui Ueyamae2cbfea2015-06-07 03:17:42 +0000420 if (S != "ref" && S != "icf" && S != "noicf" &&
421 S != "lbr" && S != "nolbr" &&
422 !StringRef(S).startswith("icf=")) {
423 llvm::errs() << "/opt: unknown option: " << S << "\n";
424 return false;
425 }
426 }
427
Rui Ueyama8854d8a2015-06-04 19:21:24 +0000428 // Handle /failifmismatch
David Blaikie6521ed92015-06-22 22:06:52 +0000429 for (auto *Arg : Args.filtered(OPT_failifmismatch))
Rui Ueyama75b098b2015-06-18 21:23:34 +0000430 if (checkFailIfMismatch(Arg->getValue()))
431 return false;
Rui Ueyama8854d8a2015-06-04 19:21:24 +0000432
Rui Ueyama6600eb12015-07-04 23:37:32 +0000433 // Handle /merge
434 for (auto *Arg : Args.filtered(OPT_merge))
435 if (parseMerge(Arg->getValue()))
436 return false;
437
Rui Ueyama24c5fd02015-06-18 00:12:42 +0000438 // Handle /manifest
David Blaikie6521ed92015-06-22 22:06:52 +0000439 if (auto *Arg = Args.getLastArg(OPT_manifest_colon)) {
Rui Ueyama24c5fd02015-06-18 00:12:42 +0000440 if (auto EC = parseManifest(Arg->getValue())) {
441 llvm::errs() << "/manifest: " << EC.message() << "\n";
442 return false;
443 }
444 }
445
446 // Handle /manifestuac
David Blaikie6521ed92015-06-22 22:06:52 +0000447 if (auto *Arg = Args.getLastArg(OPT_manifestuac)) {
Rui Ueyama24c5fd02015-06-18 00:12:42 +0000448 if (auto EC = parseManifestUAC(Arg->getValue())) {
449 llvm::errs() << "/manifestuac: " << EC.message() << "\n";
450 return false;
451 }
452 }
453
454 // Handle /manifestdependency
David Blaikie6521ed92015-06-22 22:06:52 +0000455 if (auto *Arg = Args.getLastArg(OPT_manifestdependency))
Rui Ueyama24c5fd02015-06-18 00:12:42 +0000456 Config->ManifestDependency = Arg->getValue();
457
458 // Handle /manifestfile
David Blaikie6521ed92015-06-22 22:06:52 +0000459 if (auto *Arg = Args.getLastArg(OPT_manifestfile))
Rui Ueyama24c5fd02015-06-18 00:12:42 +0000460 Config->ManifestFile = Arg->getValue();
461
Rui Ueyama6592ff82015-06-16 23:13:00 +0000462 // Handle miscellaneous boolean flags.
David Blaikie6521ed92015-06-22 22:06:52 +0000463 if (Args.hasArg(OPT_allowbind_no))
464 Config->AllowBind = false;
465 if (Args.hasArg(OPT_allowisolation_no))
466 Config->AllowIsolation = false;
467 if (Args.hasArg(OPT_dynamicbase_no))
468 Config->DynamicBase = false;
David Blaikie6521ed92015-06-22 22:06:52 +0000469 if (Args.hasArg(OPT_nxcompat_no))
470 Config->NxCompat = false;
471 if (Args.hasArg(OPT_tsaware_no))
472 Config->TerminalServerAware = false;
Rui Ueyama6592ff82015-06-16 23:13:00 +0000473
Rui Ueyamad21b00b2015-05-31 19:17:14 +0000474 // Create a list of input files. Files can be given as arguments
475 // for /defaultlib option.
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000476 std::vector<StringRef> Paths;
477 std::vector<MemoryBufferRef> MBs;
David Blaikie6521ed92015-06-22 22:06:52 +0000478 for (auto *Arg : Args.filtered(OPT_INPUT))
Rui Ueyamad21b00b2015-05-31 19:17:14 +0000479 if (Optional<StringRef> Path = findFile(Arg->getValue()))
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000480 Paths.push_back(*Path);
David Blaikie6521ed92015-06-22 22:06:52 +0000481 for (auto *Arg : Args.filtered(OPT_defaultlib))
Rui Ueyamad21b00b2015-05-31 19:17:14 +0000482 if (Optional<StringRef> Path = findLib(Arg->getValue()))
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000483 Paths.push_back(*Path);
484 for (StringRef Path : Paths) {
Rui Ueyama2bf6a122015-06-14 21:50:50 +0000485 ErrorOr<MemoryBufferRef> MBOrErr = openFile(Path);
486 if (auto EC = MBOrErr.getError()) {
487 llvm::errs() << "cannot open " << Path << ": " << EC.message() << "\n";
488 return false;
489 }
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000490 MBs.push_back(MBOrErr.get());
Rui Ueyama2bf6a122015-06-14 21:50:50 +0000491 }
Rui Ueyamad21b00b2015-05-31 19:17:14 +0000492
Rui Ueyama24c5fd02015-06-18 00:12:42 +0000493 // Windows specific -- Create a resource file containing a manifest file.
494 if (Config->Manifest == Configuration::Embed) {
495 auto MBOrErr = createManifestRes();
496 if (MBOrErr.getError())
497 return false;
498 std::unique_ptr<MemoryBuffer> MB = std::move(MBOrErr.get());
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000499 MBs.push_back(MB->getMemBufferRef());
Rui Ueyama24c5fd02015-06-18 00:12:42 +0000500 OwningMBs.push_back(std::move(MB)); // take ownership
501 }
502
Rui Ueyama2bf6a122015-06-14 21:50:50 +0000503 // Windows specific -- Input files can be Windows resource files (.res files).
504 // We invoke cvtres.exe to convert resource files to a regular COFF file
505 // then link the result file normally.
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000506 std::vector<MemoryBufferRef> Resources;
Rui Ueyama77731b42015-06-26 23:59:13 +0000507 auto NotResource = [](MemoryBufferRef MB) {
508 return identify_magic(MB.getBuffer()) != file_magic::windows_resource;
Rui Ueyama2bf6a122015-06-14 21:50:50 +0000509 };
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000510 auto It = std::stable_partition(MBs.begin(), MBs.end(), NotResource);
511 if (It != MBs.end()) {
512 Resources.insert(Resources.end(), It, MBs.end());
513 MBs.erase(It, MBs.end());
Rui Ueyama2bf6a122015-06-14 21:50:50 +0000514 }
515
Rui Ueyama85225b02015-07-02 03:15:15 +0000516 // Read all input files given via the command line. Note that step()
517 // doesn't read files that are specified by directive sections.
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000518 for (MemoryBufferRef MB : MBs)
Rui Ueyama0d2e9992015-06-23 23:56:39 +0000519 Symtab.addFile(createFile(MB));
Rui Ueyama85225b02015-07-02 03:15:15 +0000520 if (auto EC = Symtab.step()) {
Rui Ueyama0d2e9992015-06-23 23:56:39 +0000521 llvm::errs() << EC.message() << "\n";
522 return false;
Rui Ueyama411c63602015-05-28 19:09:30 +0000523 }
Rui Ueyama5cff6852015-05-31 03:34:08 +0000524
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000525 // Determine machine type and check if all object files are
526 // for the same CPU type. Note that this needs to be done before
527 // any call to mangle().
528 for (std::unique_ptr<InputFile> &File : Symtab.getFiles()) {
529 MachineTypes MT = File->getMachineType();
530 if (MT == IMAGE_FILE_MACHINE_UNKNOWN)
531 continue;
Rui Ueyama5e706b32015-07-25 21:54:50 +0000532 if (Config->Machine == IMAGE_FILE_MACHINE_UNKNOWN) {
533 Config->Machine = MT;
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000534 continue;
535 }
Rui Ueyama5e706b32015-07-25 21:54:50 +0000536 if (Config->Machine != MT) {
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000537 llvm::errs() << File->getShortName() << ": machine type "
Rui Ueyama5e706b32015-07-25 21:54:50 +0000538 << machineToStr(MT) << " conflicts with "
539 << machineToStr(Config->Machine) << "\n";
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000540 return false;
541 }
542 }
Rui Ueyama5e706b32015-07-25 21:54:50 +0000543 if (Config->Machine == IMAGE_FILE_MACHINE_UNKNOWN) {
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000544 llvm::errs() << "warning: /machine is not specified. x64 is assumed.\n";
Rui Ueyama5e706b32015-07-25 21:54:50 +0000545 Config->Machine = AMD64;
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000546 }
547
548 // Windows specific -- Convert Windows resource files to a COFF file.
549 if (!Resources.empty()) {
550 auto MBOrErr = convertResToCOFF(Resources);
551 if (MBOrErr.getError())
552 return false;
553 std::unique_ptr<MemoryBuffer> MB = std::move(MBOrErr.get());
554 Symtab.addFile(createFile(MB->getMemBufferRef()));
555 OwningMBs.push_back(std::move(MB)); // take ownership
556 }
557
Rui Ueyama4d545342015-07-28 03:12:00 +0000558 // Handle /largeaddressaware
559 if (Config->is64() || Args.hasArg(OPT_largeaddressaware))
560 Config->LargeAddressAware = true;
561
Rui Ueyamad68e2112015-07-28 03:15:57 +0000562 // Handle /highentropyva
563 if (Config->is64() && !Args.hasArg(OPT_highentropyva_no))
564 Config->HighEntropyVA = true;
565
Rui Ueyamabbdec4f2015-07-09 22:51:41 +0000566 // Handle /entry and /dll
567 if (auto *Arg = Args.getLastArg(OPT_entry)) {
568 Config->Entry = addUndefined(mangle(Arg->getValue()));
569 } else if (Args.hasArg(OPT_dll) && !Config->NoEntry) {
Rui Ueyama5e706b32015-07-25 21:54:50 +0000570 StringRef S = (Config->Machine == I386) ? "__DllMainCRTStartup@12"
571 : "_DllMainCRTStartup";
Rui Ueyamabbdec4f2015-07-09 22:51:41 +0000572 Config->Entry = addUndefined(S);
573 } else if (!Config->NoEntry) {
574 // Windows specific -- If entry point name is not given, we need to
575 // infer that from user-defined entry name.
Rui Ueyama45044f42015-06-29 01:03:53 +0000576 StringRef S = findDefaultEntry();
577 if (S.empty()) {
578 llvm::errs() << "entry point must be defined\n";
579 return false;
580 }
Rui Ueyama6bf638e2015-07-02 00:04:14 +0000581 Config->Entry = addUndefined(S);
Rui Ueyama85225b02015-07-02 03:15:15 +0000582 if (Config->Verbose)
583 llvm::outs() << "Entry name inferred: " << S << "\n";
Rui Ueyama45044f42015-06-29 01:03:53 +0000584 }
585
Rui Ueyamabbdec4f2015-07-09 22:51:41 +0000586 // Handle /export
587 for (auto *Arg : Args.filtered(OPT_export)) {
588 ErrorOr<Export> E = parseExport(Arg->getValue());
589 if (E.getError())
590 return false;
Rui Ueyama5e706b32015-07-25 21:54:50 +0000591 if (Config->Machine == I386 && !E->Name.startswith("_@?"))
Rui Ueyamabbdec4f2015-07-09 22:51:41 +0000592 E->Name = mangle(E->Name);
593 Config->Exports.push_back(E.get());
594 }
595
596 // Handle /def
597 if (auto *Arg = Args.getLastArg(OPT_deffile)) {
598 ErrorOr<MemoryBufferRef> MBOrErr = openFile(Arg->getValue());
599 if (auto EC = MBOrErr.getError()) {
600 llvm::errs() << "/def: " << EC.message() << "\n";
601 return false;
602 }
603 // parseModuleDefs mutates Config object.
604 if (parseModuleDefs(MBOrErr.get(), &Alloc))
605 return false;
606 }
607
Rui Ueyama6d249082015-07-13 22:31:45 +0000608 // Handle /delayload
609 for (auto *Arg : Args.filtered(OPT_delayload)) {
610 Config->DelayLoads.insert(StringRef(Arg->getValue()).lower());
Rui Ueyama5e706b32015-07-25 21:54:50 +0000611 if (Config->Machine == I386) {
Rui Ueyama6d249082015-07-13 22:31:45 +0000612 Config->DelayLoadHelper = addUndefined("___delayLoadHelper2@8");
Rui Ueyama35ccb0f2015-07-25 00:20:06 +0000613 } else {
614 Config->DelayLoadHelper = addUndefined("__delayLoadHelper2");
Rui Ueyama6d249082015-07-13 22:31:45 +0000615 }
616 }
617
Rui Ueyama5c437cd2015-07-25 21:42:33 +0000618 // Set default image base if /base is not given.
619 if (Config->ImageBase == uint64_t(-1))
620 Config->ImageBase = getDefaultImageBase();
621
Rui Ueyama3cb895c2015-07-24 22:58:44 +0000622 Symtab.addRelative(mangle("__ImageBase"), 0);
Rui Ueyama5e706b32015-07-25 21:54:50 +0000623 if (Config->Machine == I386) {
Rui Ueyamacd3f99b2015-07-24 23:51:14 +0000624 Config->SEHTable = Symtab.addRelative("___safe_se_handler_table", 0);
625 Config->SEHCount = Symtab.addAbsolute("___safe_se_handler_count", 0);
626 }
Rui Ueyama29f74c32015-07-29 16:30:31 +0000627 Config->LoadConfigUsed = mangle("_load_config_used");
Rui Ueyamabbdec4f2015-07-09 22:51:41 +0000628
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000629 // Read as much files as we can from directives sections.
Rui Ueyama85225b02015-07-02 03:15:15 +0000630 if (auto EC = Symtab.run()) {
631 llvm::errs() << EC.message() << "\n";
632 return false;
633 }
634
635 // Resolve auxiliary symbols until we get a convergence.
Rui Ueyama573bf7d2015-06-19 21:12:48 +0000636 // (Trying to resolve a symbol may trigger a Lazy symbol to load a new file.
637 // A new file may contain a directive section to add new command line options.
638 // That's why we have to repeat until converge.)
639 for (;;) {
Rui Ueyama6bf638e2015-07-02 00:04:14 +0000640 // Windows specific -- if entry point is not found,
641 // search for its mangled names.
642 if (Config->Entry)
643 Symtab.mangleMaybe(Config->Entry);
644
Rui Ueyama573bf7d2015-06-19 21:12:48 +0000645 // Windows specific -- Make sure we resolve all dllexported symbols.
Rui Ueyama6bf638e2015-07-02 00:04:14 +0000646 for (Export &E : Config->Exports) {
647 E.Sym = addUndefined(E.Name);
648 Symtab.mangleMaybe(E.Sym);
649 }
Rui Ueyama573bf7d2015-06-19 21:12:48 +0000650
651 // Add weak aliases. Weak aliases is a mechanism to give remaining
652 // undefined symbols final chance to be resolved successfully.
Rui Ueyama3d4c69c2015-07-02 02:38:59 +0000653 for (auto Pair : Config->AlternateNames) {
654 StringRef From = Pair.first;
655 StringRef To = Pair.second;
Rui Ueyama458d7442015-07-02 03:59:04 +0000656 Symbol *Sym = Symtab.find(From);
Rui Ueyama3d4c69c2015-07-02 02:38:59 +0000657 if (!Sym)
658 continue;
Rui Ueyama183f53f2015-07-06 17:45:22 +0000659 if (auto *U = dyn_cast<Undefined>(Sym->Body))
Rui Ueyama3d4c69c2015-07-02 02:38:59 +0000660 if (!U->WeakAlias)
661 U->WeakAlias = Symtab.addUndefined(To);
Rui Ueyama2edb35a2015-06-18 19:09:30 +0000662 }
Rui Ueyama573bf7d2015-06-19 21:12:48 +0000663
Rui Ueyamacd3f99b2015-07-24 23:51:14 +0000664 // Windows specific -- if __load_config_used can be resolved, resolve it.
Peter Collingbournee7107ec2015-07-31 05:33:34 +0000665 if (Symtab.find(Config->LoadConfigUsed))
666 addUndefined(Config->LoadConfigUsed);
Rui Ueyamacd3f99b2015-07-24 23:51:14 +0000667
Rui Ueyama3d4c69c2015-07-02 02:38:59 +0000668 if (Symtab.queueEmpty())
669 break;
Rui Ueyama0d2e9992015-06-23 23:56:39 +0000670 if (auto EC = Symtab.run()) {
671 llvm::errs() << EC.message() << "\n";
672 return false;
673 }
Rui Ueyama2edb35a2015-06-18 19:09:30 +0000674 }
675
Rui Ueyamaeb262ce2015-06-04 02:12:16 +0000676 // Do LTO by compiling bitcode input files to a native COFF file
677 // then link that file.
Peter Collingbourne60c16162015-06-01 20:10:10 +0000678 if (auto EC = Symtab.addCombinedLTOObject()) {
679 llvm::errs() << EC.message() << "\n";
680 return false;
681 }
682
Peter Collingbourne2612a322015-07-04 05:28:41 +0000683 // Make sure we have resolved all symbols.
684 if (Symtab.reportRemainingUndefines(/*Resolve=*/true))
685 return false;
686
Rui Ueyama3ee0fe42015-05-31 03:55:46 +0000687 // Windows specific -- if no /subsystem is given, we need to infer
688 // that from entry point name.
689 if (Config->Subsystem == IMAGE_SUBSYSTEM_UNKNOWN) {
Rui Ueyama97dff9e2015-06-17 00:16:33 +0000690 Config->Subsystem = inferSubsystem();
Rui Ueyama3ee0fe42015-05-31 03:55:46 +0000691 if (Config->Subsystem == IMAGE_SUBSYSTEM_UNKNOWN) {
692 llvm::errs() << "subsystem must be defined\n";
693 return false;
694 }
695 }
696
Rui Ueyamaff88d5a2015-07-29 20:25:40 +0000697 // Handle /safeseh.
698 if (Args.hasArg(OPT_safeseh)) {
699 for (ObjectFile *File : Symtab.ObjectFiles) {
700 if (File->SEHCompat)
701 continue;
702 llvm::errs() << "/safeseh: " << File->getName()
703 << " is not compatible with SEH\n";
704 return false;
705 }
706 }
707
Rui Ueyama151d8622015-06-17 20:40:43 +0000708 // Windows specific -- when we are creating a .dll file, we also
709 // need to create a .lib file.
Rui Ueyama8765fba2015-07-15 22:21:08 +0000710 if (!Config->Exports.empty()) {
Rui Ueyama97dff9e2015-06-17 00:16:33 +0000711 if (fixupExports())
712 return false;
Rafael Espindola4280a962015-08-05 20:03:57 +0000713 if (writeImportLibrary())
714 return false;
Rui Ueyama8765fba2015-07-15 22:21:08 +0000715 assignExportOrdinals();
716 }
Rui Ueyama97dff9e2015-06-17 00:16:33 +0000717
Rui Ueyama24c5fd02015-06-18 00:12:42 +0000718 // Windows specific -- Create a side-by-side manifest file.
719 if (Config->Manifest == Configuration::SideBySide)
720 if (createSideBySideManifest())
721 return false;
722
Rui Ueyama0fc26d22015-06-29 14:27:12 +0000723 // Create a dummy PDB file to satisfy build sytem rules.
724 if (auto *Arg = Args.getLastArg(OPT_pdb))
725 touchFile(Arg->getValue());
726
Rui Ueyama411c63602015-05-28 19:09:30 +0000727 // Write the result.
728 Writer Out(&Symtab);
Rui Ueyamaad660982015-06-07 00:20:32 +0000729 if (auto EC = Out.write(Config->OutputFile)) {
Rui Ueyama411c63602015-05-28 19:09:30 +0000730 llvm::errs() << EC.message() << "\n";
731 return false;
732 }
Peter Collingbournebe549552015-06-26 18:58:24 +0000733
Rui Ueyama016414f2015-06-28 20:07:08 +0000734 // Create a symbol map file containing symbol VAs and their names
735 // to help debugging.
Peter Collingbournebe549552015-06-26 18:58:24 +0000736 if (auto *Arg = Args.getLastArg(OPT_lldmap)) {
737 std::error_code EC;
Peter Collingbournebaf5f872015-06-26 19:20:09 +0000738 llvm::raw_fd_ostream Out(Arg->getValue(), EC, OpenFlags::F_Text);
Peter Collingbournebe549552015-06-26 18:58:24 +0000739 if (EC) {
740 llvm::errs() << EC.message() << "\n";
741 return false;
742 }
743 Symtab.printMap(Out);
744 }
Rui Ueyamaa51ce712015-07-03 05:31:35 +0000745 // Call exit to avoid calling destructors.
746 exit(0);
Rui Ueyama411c63602015-05-28 19:09:30 +0000747}
748
Rui Ueyama411c63602015-05-28 19:09:30 +0000749} // namespace coff
750} // namespace lld